mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-01 23:03:54 -06:00
libvhost-user: Add vu_rem_mem_reg input validation
Today if multiple FDs are sent from the VMM to the backend in a VHOST_USER_REM_MEM_REG message, one FD will be unmapped and the remaining FDs will be leaked. Therefore if multiple FDs are sent we report an error and fail the operation, closing all FDs in the message. Likewise in case the VMM sends a message with a size less than that of a memory region descriptor, we add a check to gracefully report an error and fail the operation rather than crashing. Signed-off-by: Raphael Norwitz <raphael.norwitz@nutanix.com> Message-Id: <20220117041050.19718-2-raphael.norwitz@nutanix.com> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Reviewed-by: David Hildenbrand <david@redhat.com>
This commit is contained in:
parent
408ca92634
commit
316ee11144
2 changed files with 17 additions and 0 deletions
|
@ -801,6 +801,21 @@ vu_rem_mem_reg(VuDev *dev, VhostUserMsg *vmsg) {
|
|||
VuDevRegion shadow_regions[VHOST_USER_MAX_RAM_SLOTS] = {};
|
||||
VhostUserMemoryRegion m = vmsg->payload.memreg.region, *msg_region = &m;
|
||||
|
||||
if (vmsg->fd_num != 1) {
|
||||
vmsg_close_fds(vmsg);
|
||||
vu_panic(dev, "VHOST_USER_REM_MEM_REG received %d fds - only 1 fd "
|
||||
"should be sent for this message type", vmsg->fd_num);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (vmsg->size < VHOST_USER_MEM_REG_SIZE) {
|
||||
close(vmsg->fds[0]);
|
||||
vu_panic(dev, "VHOST_USER_REM_MEM_REG requires a message size of at "
|
||||
"least %d bytes and only %d bytes were received",
|
||||
VHOST_USER_MEM_REG_SIZE, vmsg->size);
|
||||
return false;
|
||||
}
|
||||
|
||||
DPRINT("Removing region:\n");
|
||||
DPRINT(" guest_phys_addr: 0x%016"PRIx64"\n",
|
||||
msg_region->guest_phys_addr);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue