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 10/13] vfio-user: vfio_user_device_io_device_feature: prevent buffer overflow
Date: Tue, 21 Jul 2026 19:05:15 +0200	[thread overview]
Message-ID: <20260721170518.4160785-11-clg@redhat.com> (raw)
In-Reply-To: <20260721170518.4160785-1-clg@redhat.com>

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

This isn't in practise a problem since feature->argsz is not
externally provided, it's a good hardening step nonetheless.

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

diff --git a/hw/vfio-user/device.c b/hw/vfio-user/device.c
index 3d0dbe840649b7b678b79afd3dbc7f9caaeb947b..353fa5ee21e34a88bcd0eff9de40d9757387a616 100644
--- a/hw/vfio-user/device.c
+++ b/hw/vfio-user/device.c
@@ -79,9 +79,14 @@ vfio_user_device_io_device_feature(VFIODevice *vbasedev,
                                    struct vfio_device_feature *feature)
 {
     g_autofree VFIOUserDeviceFeature *msgp = NULL;
-    int size = sizeof(VFIOUserHdr) + feature->argsz;
     VFIOUserProxy *proxy = vbasedev->proxy;
     Error *local_err = NULL;
+    int size;
+
+    if (__builtin_add_overflow(feature->argsz, sizeof(VFIOUserHdr), &size)) {
+        error_printf("vfio_user_device_io_device_feature argsz too large\n");
+        return -E2BIG;
+    }
 
     msgp = g_malloc0(size);
 
-- 
2.55.0



  parent reply	other threads:[~2026-07-21 17:06 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 ` [PULL 08/13] vfio-user: vfio_user_get_region_info: prevent excessive malloc Cédric Le Goater
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 ` Cédric Le Goater [this message]
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-11-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.