mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
misc: Check that get_slice() returned a big enough slice
This should be guaranteed by GuestMemory and GuestMemoryRegion, but those traits are currently safe, so add checks to guard against incorrect implementations of them. Signed-off-by: Demi Marie Obenour <demiobenour@gmail.com>
This commit is contained in:
committed by
Rob Bradford
parent
969a3b57a3
commit
2be304b392
@@ -174,12 +174,15 @@ impl BalloonEpollHandler {
|
||||
range_len: usize,
|
||||
advice: libc::c_int,
|
||||
) -> result::Result<(), Error> {
|
||||
let hva = memory
|
||||
.get_host_address(range_base)
|
||||
let slice = memory
|
||||
.get_slice(range_base, range_len)
|
||||
.map_err(Error::GuestMemory)?;
|
||||
assert!(slice.len() >= range_len);
|
||||
let res =
|
||||
// SAFETY: Need unsafe to do syscall madvise
|
||||
unsafe { libc::madvise(hva as *mut libc::c_void, range_len as libc::size_t, advice) };
|
||||
// SAFETY: FFI call with valid arguments, guaranteed by VolatileSlice
|
||||
unsafe {
|
||||
libc::madvise(slice.ptr_guard_mut().as_ptr() as *mut libc::c_void,
|
||||
range_len as libc::size_t, advice) };
|
||||
if res != 0 {
|
||||
return Err(Error::MadviseFail(io::Error::last_os_error()));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user