-
Notifications
You must be signed in to change notification settings - Fork 126
fix(starry-mm): mprotect returns ENOMEM on unmapped holes within the range #918
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 1 commit
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 |
|---|---|---|
|
|
@@ -450,8 +450,16 @@ pub fn sys_mprotect(addr: usize, length: usize, prot: u32) -> AxResult<isize> { | |
| let mut aspace = aspace_arc.lock(); | ||
| let length = align_up_4k(length); | ||
| let start_addr = VirtAddr::from(addr); | ||
| // man 2 mprotect: addresses without a mapping → ENOMEM. | ||
| if aspace.find_area(start_addr).is_none() { | ||
| // man 2 mprotect: if any page in [addr, addr+len) lacks a mapping → ENOMEM. | ||
| // Linux validates the whole range, not just the first page: an unmapped hole | ||
| // in the middle of `[mapped][hole][mapped]` must fail instead of silently | ||
| // protecting only the mapped fragments. `can_access_range` with an empty | ||
| // access mask is a pure contiguous-coverage check (every area's flags | ||
| // trivially contain the empty set), so it returns false on the first gap. | ||
| // We pre-check and leave the mapping untouched on failure, i.e. report | ||
| // ENOMEM atomically without any half-applied protection — the errno real | ||
| // programs test for. | ||
| if !aspace.can_access_range(start_addr, length, MappingFlags::empty()) { | ||
|
Contributor
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. ✅
Contributor
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. ✅ |
||
| return Err(AxError::NoMemory); | ||
| } | ||
| if permission_flags.contains(MmapProt::WRITE) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.