rust-vmm / vm-memory

Virtual machine's guest memory crate
Apache License 2.0
305 stars 98 forks source link

MmapRegion::build fails when the backing object is a device #195

Closed slp closed 2 years ago

slp commented 2 years ago

Currently mmap::check_file_offset attempts to validate the backing object by checking, among other things, its size to confirm the mapping will fit on it. This check is implemented by using std::fs::metadata to obtain the file size, but this approach doesn't work when the backing object is a block or char device, as the returned value is always zero.

This was discovered when virtiofsd users noticed that adding a memory object in QEMU backed by a device (i.e. /dev/kvmfr0) would cause the daemon to fail with Waiting for daemon failed: HandleRequest(ReqHandlerError(Custom { kind: Other, error: MappingPastEof })) (issue 46).