]> Git Repo - qemu.git/commitdiff
libvhost-user: prevent over-running max RAM slots
authorRaphael Norwitz <[email protected]>
Mon, 17 Jan 2022 04:12:34 +0000 (04:12 +0000)
committerMichael S. Tsirkin <[email protected]>
Fri, 4 Feb 2022 14:07:43 +0000 (09:07 -0500)
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 <[email protected]>
Signed-off-by: Raphael Norwitz <[email protected]>
Message-Id: <20220117041050[email protected]>
Reviewed-by: Michael S. Tsirkin <[email protected]>
Signed-off-by: Michael S. Tsirkin <[email protected]>
Reviewed-by: David Hildenbrand <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
subprojects/libvhost-user/libvhost-user.c

index 3f4d7221ca614e91dd56165f5d2e8257cdab9021..2a1fa00a44e17e594b4aab74108e02dc480453f5 100644 (file)
@@ -705,6 +705,14 @@ vu_add_mem_reg(VuDev *dev, VhostUserMsg *vmsg) {
         return false;
     }
 
+    if (dev->nregions == VHOST_USER_MAX_RAM_SLOTS) {
+        close(vmsg->fds[0]);
+        vu_panic(dev, "failing attempt to hot add memory via "
+                      "VHOST_USER_ADD_MEM_REG message because the backend has "
+                      "no free ram slots available");
+        return false;
+    }
+
     /*
      * If we are in postcopy mode and we receive a u64 payload with a 0 value
      * we know all the postcopy client bases have been received, and we
This page took 0.025597 seconds and 4 git commands to generate.