1
0
Fork 0
mirror of https://passt.top/passt synced 2025-05-22 17:25:35 +02:00

vu_common: Tighten vu_packet_check_range()

This function verifies that the given packet is within the mmap()ed memory
region of the vhost-user device.  We can do better, however.  The packet
should be not only within the mmap()ed range, but specifically in the
subsection of that range set aside for shared buffers, which starts at
dev_region->mmap_offset within there.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
This commit is contained in:
David Gibson 2025-03-17 20:24:14 +11:00 committed by Stefano Brivio
parent 32f6212551
commit 4592719a74

View file

@ -37,10 +37,10 @@ int vu_packet_check_range(void *buf, const char *ptr, size_t len)
for (dev_region = buf; dev_region->mmap_addr; dev_region++) {
/* NOLINTNEXTLINE(performance-no-int-to-ptr) */
char *m = (char *)(uintptr_t)dev_region->mmap_addr;
char *m = (char *)(uintptr_t)dev_region->mmap_addr +
dev_region->mmap_offset;
if (m <= ptr &&
ptr + len <= m + dev_region->mmap_offset + dev_region->size)
if (m <= ptr && ptr + len <= m + dev_region->size)
return 0;
}