Skip to content

Commit

Permalink
Merge pull request #62 from kawasin73/ioctlflags
Browse files Browse the repository at this point in the history
Make IoctlFlags robust to unknown flags
  • Loading branch information
kawasin73 authored Jan 12, 2024
2 parents 9f1631b + afdc3c1 commit 7f1385f
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "userfaultfd"
version = "0.7.0"
version = "0.8.0"
authors = ["The Wasmtime Project Developers"]
edition = "2018"
license = "MIT OR Apache-2.0"
Expand Down
3 changes: 1 addition & 2 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,7 @@ impl UffdBuilder {
unsafe {
raw::api(uffd.fd, &mut api as *mut raw::uffdio_api)?;
}
let supported =
IoctlFlags::from_bits(api.ioctls).ok_or(Error::UnrecognizedIoctls(api.ioctls))?;
let supported = IoctlFlags::from_bits_retain(api.ioctls);
if !supported.contains(self.req_ioctls) {
Err(Error::UnsupportedIoctls(supported))
} else {
Expand Down
4 changes: 0 additions & 4 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ pub enum Error {
#[error("Unrecognized event in uffd_msg: {0}")]
UnrecognizedEvent(u8),

/// An unrecognized ioctl bit was set in the result of API initialization or registration.
#[error("Unrecognized ioctl flags: {0}")]
UnrecognizedIoctls(u64),

/// Requested ioctls were not available when initializing the API.
#[error("Requested ioctls unsupported; supported: {0:?}")]
UnsupportedIoctls(IoctlFlags),
Expand Down
5 changes: 4 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ impl Uffd {
unsafe {
raw::register(self.as_raw_fd(), &mut register as *mut raw::uffdio_register)?;
}
IoctlFlags::from_bits(register.ioctls).ok_or(Error::UnrecognizedIoctls(register.ioctls))
Ok(IoctlFlags::from_bits_retain(register.ioctls))
}

/// Unregister a memory address range from the userfaultfd object.
Expand Down Expand Up @@ -377,6 +377,9 @@ bitflags! {
#[cfg(feature = "linux5_7")]
const WRITE_PROTECT = 1 << raw::_UFFDIO_WRITEPROTECT;
const API = 1 << raw::_UFFDIO_API;

/// Unknown ioctls flags are allowed to be robust to future kernel changes.
const _ = !0;
}
}

Expand Down

0 comments on commit 7f1385f

Please sign in to comment.