-
Notifications
You must be signed in to change notification settings - Fork 2
fix(uffd): register guest memory with WRITE_PROTECT in addition to MISSING #12
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,7 +14,7 @@ use std::sync::{Arc, Mutex}; | |
|
|
||
| use semver::Version; | ||
| use serde::{Deserialize, Serialize}; | ||
| use userfaultfd::{FeatureFlags, Uffd, UffdBuilder}; | ||
| use userfaultfd::{FeatureFlags, RegisterMode, Uffd, UffdBuilder}; | ||
| use vmm_sys_util::sock_ctrl_msg::ScmSocket; | ||
|
|
||
| #[cfg(target_arch = "aarch64")] | ||
|
|
@@ -553,9 +553,23 @@ fn guest_memory_from_uffd( | |
| .create() | ||
| .map_err(GuestMemoryFromUffdError::Create)?; | ||
|
|
||
| // Register every region for both MISSING and WRITE_PROTECT faults. | ||
| // | ||
| // MISSING is needed so the orchestrator's UFFD handler is woken up the first time the guest | ||
| // touches a page that has not yet been populated from the snapshot's memory file. | ||
| // | ||
| // WRITE_PROTECT is needed so the handler can keep pages it serves in a write-protected state | ||
| // (via UFFDIO_COPY_MODE_WP) and observe subsequent writes as new faults — the standard CoW | ||
| // tracking pattern that lets the orchestrator know which pages got dirtied after restore. | ||
| // Without WRITE_PROTECT registration, UFFDIO_COPY with MODE_WP fails synchronously with | ||
| // EINVAL on the very first read fault, breaking the snapshot resume path. | ||
| for mem_region in guest_memory.iter() { | ||
| uffd.register(mem_region.as_ptr().cast(), mem_region.size() as _) | ||
| .map_err(GuestMemoryFromUffdError::Register)?; | ||
| uffd.register_with_mode( | ||
| mem_region.as_ptr().cast(), | ||
| mem_region.size() as _, | ||
| RegisterMode::MISSING | RegisterMode::WRITE_PROTECT, | ||
| ) | ||
| .map_err(GuestMemoryFromUffdError::Register)?; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. UFFD WRITE_PROTECT registration breaks aarch64 on kernels below 6.10High Severity Unconditionally registering with Reviewed by Cursor Bugbot for commit 32330a4. Configure here. |
||
| } | ||
|
|
||
| send_uffd_handshake(mem_uds_path, &backend_mappings, &uffd)?; | ||
|
|
||


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing WP feature negotiation during UFFDIO_API handshake
Medium Severity
The code registers regions with
RegisterMode::WRITE_PROTECTbut never negotiatesFeatureFlags::PAGEFAULT_FLAG_WPduring theUFFDIO_APIhandshake. The Linux man page states the user needs to check availability ofUFFD_FEATURE_PAGEFAULT_FLAG_WPviaUFFDIO_APIbefore using write-protect mode. Adding this torequire_featureswould also provide an early, clear failure on platforms that lack WP support instead of a less informative error at registration time.Reviewed by Cursor Bugbot for commit 32330a4. Configure here.