exec: check the range in the address_space_unmap routine
Quoted 30 lines · Peter Maydell
Quoted 29 lines · Dima Stepanov
In case of the virtio-blk communication, can get the following assertion for the specifically crafted virtio packet:
qemu-system-x86_64: exec.c:3725:address_space_unmap: Assertion `mr != NULL' failed.
This assertion is triggered if the length of the first descriptor in the block request chain (block command descriptor) is more than block command size. In this case the hw/block/virtio-blk.c:virtio_blk_handle_request() routine calls theiov_discard_front()function and the iov base and size are changed. As a result the address can not be found during theaddress_space_unmap()call.The fix is to check the whole address range in the
address_space_unmapfunction.Signed-off-by Dima Stepanov <[email protected]>--- exec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)exec.c +0
-1@@ -3717,7 +3717,7 @@ void *address_space_map(AddressSpace *as,void address_space_unmap (AddressSpace *as,void *buffer,hwaddr len,int is_write,hwaddr access_len) { -if (buffer != bounce.buffer) {
Quoted 8 lines
exec.c void *address_space_map(AddressSpace *as, · line 3722
Quoted 3 lines
exec.c +1
-0+if ((buffer < bounce.buffer) || (buffer + access_len > bounce.buffer + bounce.len)) {MemoryRegion *mr;ram_addr_t addr1;A quick look at the
xen_invalidate_map_cache_entry()implementation suggests that it also assumes that the address passed toaddress_space_unmap()must be the same address that was originally handed out viaaddress_space_map().
Hard to say for me, if it is needed or not, since we have no xen reproducer for this issue. Right now we are making some fuzzing for the virtio-blk devices and hit these asserts which are good to fix.
Quoted 4 lines
So I think we either need to also change the Xen code, or we need to fix this at the virtio level by having it keep track of the buffer it was handed so it can unmap it.
Maybe a fix at virtio level will be better in general, what do you think?
Thanks, Dima.
Quoted 3 lines
thanks
-- PMM