vm-virtio: checked_descriptor: Add unit test for one past memory end

Submit a descriptor whose buffer extends exactly one byte past the
end of guest RAM and verify CheckedDescriptorIter rejects it, with
failed_addr returning the descriptor's start address.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
This commit is contained in:
Anatol Belski
2026-05-15 01:27:25 +02:00
committed by Rob Bradford
parent c271a20573
commit acda9b1380

View File

@@ -362,4 +362,19 @@ mod unit_tests {
assert_eq!(desc.addr().0, addr);
assert_eq!(desc.len(), LEN);
}
#[test]
fn rejects_descriptor_one_past_memory_end() {
// A descriptor whose buffer extends one byte past the end of guest
// RAM must be rejected.
const MEM_SIZE: usize = 128 * 1024;
const LEN: u32 = 256;
let addr = (MEM_SIZE as u64) - LEN as u64 + 1;
let (_mem, mem_atomic, mut queue) = setup_vq(MEM_SIZE, addr, LEN, 0);
let mem_guard = mem_atomic.memory();
let mut chain = queue.pop_descriptor_chain(mem_guard).unwrap();
let mut it = chain.checked_iter(None);
let result = it.next().expect("must yield an item");
assert_eq!(result.unwrap_err(), GuestAddress(addr));
}
}