All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Cédric Le Goater" <clg@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Thanos Makatos" <thanos.makatos@nutanix.com>,
	"Cédric Le Goater" <clg@redhat.com>
Subject: [PULL 08/13] vfio-user: vfio_user_get_region_info: prevent excessive malloc
Date: Tue, 21 Jul 2026 19:05:13 +0200	[thread overview]
Message-ID: <20260721170518.4160785-9-clg@redhat.com> (raw)
In-Reply-To: <20260721170518.4160785-1-clg@redhat.com>

From: Thanos Makatos <thanos.makatos@nutanix.com>

If the vfio-user server responds with a value larger than max_xfer_size
vfio_device_get_region_info() blindly uses it in the next loop in
g_realloc. An value larger than max_xfer_size is anyway rejected by the
check at the beginning of vfio_user_get_region_info(), however that only
happens _after_ the g_realloc, and if that value is excessively large it
can cause g_realloc to fail, so check it here.

Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com>
Fixes: 667866d66620 ("vfio-user: implement VFIO_USER_DEVICE_GET_REGION_INFO")
Reviewed-by: Cédric Le Goater <clg@redhat.com>
Link: https://lore.kernel.org/qemu-devel/20260721122643.30985-5-thanos.makatos@nutanix.com
Signed-off-by: Cédric Le Goater <clg@redhat.com>
---
 hw/vfio-user/device.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/hw/vfio-user/device.c b/hw/vfio-user/device.c
index 3d12e8b2a20eb96fb1a8a944070d13bf0e049b67..008e5cf6877c84c3d0cf33f25a6ac9a4cf231e06 100644
--- a/hw/vfio-user/device.c
+++ b/hw/vfio-user/device.c
@@ -170,6 +170,16 @@ static int vfio_user_get_region_info(VFIOUserProxy *proxy,
         return -EINVAL;
     }
 
+    /*
+     * The server can respond with a larger argsz in the reply to request a
+     * larger buffer on the next iteration via vfio_device_get_region_info().
+     * Reject values that would trigger an oversized realloc.
+     */
+    if (msgp->argsz > proxy->max_xfer_size) {
+        error_printf("vfio_user_get_region_info reply argsz too large\n");
+        return -E2BIG;
+    }
+
     memcpy(info, &msgp->argsz, info->argsz);
 
     /*
-- 
2.55.0



  parent reply	other threads:[~2026-07-21 17:07 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-21 17:05 [PULL 00/13] vfio queue Cédric Le Goater
2026-07-21 17:05 ` [PULL 01/13] vfio/igd: Clear saved BDSM in legacy VBIOS ROM at load time Cédric Le Goater
2026-07-21 17:05 ` [PULL 02/13] vfio/region: Clarify dma-buf failure messages Cédric Le Goater
2026-07-21 17:05 ` [PULL 03/13] vfio/pci: don't narrow a failed config read to a plausible value Cédric Le Goater
2026-07-21 17:05 ` [PULL 04/13] vfio/pci: reject invalid PCI_INTERRUPT_PIN values Cédric Le Goater
2026-07-21 17:05 ` [PULL 05/13] vfio-user: vfio_user_get_region_info: prevent buffer overflow Cédric Le Goater
2026-07-21 17:05 ` [PULL 06/13] vfio-user: vfio_user_get_region_info: respect max_xfer_size Cédric Le Goater
2026-07-21 17:05 ` [PULL 07/13] vfio-user: vfio_user_get_region_info: reject unreasonably short struct Cédric Le Goater
2026-07-21 17:05 ` Cédric Le Goater [this message]
2026-07-21 17:05 ` [PULL 09/13] vfio-user: vfio_user_device_io_get_region_info: fix capability check Cédric Le Goater
2026-07-21 17:05 ` [PULL 10/13] vfio-user: vfio_user_device_io_device_feature: prevent buffer overflow Cédric Le Goater
2026-07-21 17:05 ` [PULL 11/13] vfio-user: vfio_user_device_io_device_feature: prevent excessive malloc Cédric Le Goater
2026-07-21 17:05 ` [PULL 12/13] vfio-user: vfio_user_device_io_set_irqs: prevent buffer overflow Cédric Le Goater
2026-07-21 17:05 ` [PULL 13/13] vfio-user: vfio_user_device_io_set_irqs: prevent excessive malloc Cédric Le Goater
2026-07-22 17:58 ` [PULL 00/13] vfio queue Stefan Hajnoczi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260721170518.4160785-9-clg@redhat.com \
    --to=clg@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=thanos.makatos@nutanix.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.