[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 4/5] libvhost-user: prevent over-running max RAM slots
From: |
Raphael Norwitz |
Subject: |
[PATCH v2 4/5] libvhost-user: prevent over-running max RAM slots |
Date: |
Thu, 6 Jan 2022 06:47:35 +0000 |
When VHOST_USER_PROTOCOL_F_CONFIGURE_MEM_SLOTS support was added to
libvhost-user, no guardrails were added to protect against QEMU
attempting to hot-add too many RAM slots to a VM with a libvhost-user
based backed attached.
This change adds the missing error handling by introducing a check on
the number of RAM slots the device has available before proceeding to
process the VHOST_USER_ADD_MEM_REG message.
Suggested-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Raphael Norwitz <raphael.norwitz@nutanix.com>
---
subprojects/libvhost-user/libvhost-user.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/subprojects/libvhost-user/libvhost-user.c
b/subprojects/libvhost-user/libvhost-user.c
index 77ddc96ddf..0fe3aa155b 100644
--- a/subprojects/libvhost-user/libvhost-user.c
+++ b/subprojects/libvhost-user/libvhost-user.c
@@ -690,6 +690,11 @@ vu_add_mem_reg(VuDev *dev, VhostUserMsg *vmsg) {
VuDevRegion *dev_region = &dev->regions[dev->nregions];
void *mmap_addr;
+ if (dev->nregions == VHOST_USER_MAX_RAM_SLOTS) {
+ vu_panic(dev, "No free ram slots available");
+ return false;
+ }
+
if (vmsg->fd_num != 1 ||
vmsg->size != sizeof(vmsg->payload.memreg)) {
vu_panic(dev, "VHOST_USER_REM_MEM_REG received multiple regions");
--
2.20.1
- Re: [PATCH v2 1/5] libvhost-user: Add vu_rem_mem_reg input validation, (continued)
[PATCH v2 2/5] libvhost-user: Add vu_add_mem_reg input validation, Raphael Norwitz, 2022/01/06
[PATCH v2 3/5] libvhost-user: Simplify VHOST_USER_REM_MEM_REG, Raphael Norwitz, 2022/01/06
[PATCH v2 5/5] libvhost-user: handle removal of identical regions, Raphael Norwitz, 2022/01/06
[PATCH v2 4/5] libvhost-user: prevent over-running max RAM slots,
Raphael Norwitz <=
Re: [PATCH v2 0/5] Clean up error handling in libvhost-user memory mapping, David Hildenbrand, 2022/01/10
Re: [PATCH v2 0/5] Clean up error handling in libvhost-user memory mapping, Stefan Hajnoczi, 2022/01/10