Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make IoctlFlags robust to unknown flags #62

Merged
merged 1 commit into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading