Validate Guest Address Ranges for Overlapping Regions in map_region#1464
Validate Guest Address Ranges for Overlapping Regions in map_region#1464Richard-Durkee wants to merge 1 commit into
Conversation
644165f to
bb16213
Compare
ludfjig
left a comment
There was a problem hiding this comment.
thanks for your contribution!
I think we can drop the validation in MultiUseSandbox::map_region entirely and rely on the check inside HyperlightVm::map_region, then reorder so the call happens before the snapshot reset:
unsafe { self.vm.map_region(rgn) }.map_err(HyperlightVmError::MapRegion)?;
self.snapshot = None;
self.mem_mgr.mapped_rgns += 1;The same pattern can probably applies to map_file_cow too I think. What do you think about this?
3075ff3 to
f2c4072
Compare
Thanks for the feedback! This makes sense to me. I just pushed again and included these suggestions. Please let me know if there are any other changes you'd like. |
Looks great! Just one minor thing I just realized the page-table "tail" of compacted snapshots are not mapped into the vm, so the could be less than #[cfg(not(unshared_snapshot_mem))]
let snap_end = snap_start + snapshot.guest_mapped_size();
#[cfg(unshared_snapshot_mem)]
let snap_end = snap_start + snapshot.mem_size();should do it. Thanks! |
f2c4072 to
cfd33a6
Compare
Closes hyperlight-dev#1289 Signed-off-by: Richard Durkee <Richard-Durkee@users.noreply.github.com>
cfd33a6 to
fa24c67
Compare
Add overlap validation to
HyperlightVm::map_regionto enforce the safety contract documented onVirtualMachine::map_memory, which requires non-overlapping regions.Checks the new region against existing dynamically mapped regions (
mmap_regions), the snapshot region (starting atBASE_ADDRESS), and the scratch region (at the top of the guest physical address space).Adds
Overlappingvariant toMapRegionErrorwith a descriptive message showing both the new and conflicting ranges.Also adds early validation at the
MultiUseSandbox::map_regionlevel to reject invalid input before side effects (snapshot reset) occur.Tested on KVM (
c8i.2xlargewith nested virtualization enabled).Closes #1289