Commit 5f0cbed64c for qemu.org
commit 5f0cbed64c0fe153b58331c223f0afbf84f299c7
Author: Thanos Makatos <thanos.makatos@nutanix.com>
Date: Tue Jul 21 12:26:58 2026 +0000
vfio-user: vfio_user_device_io_device_feature: prevent buffer overflow
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>
diff --git a/hw/vfio-user/device.c b/hw/vfio-user/device.c
index 3d0dbe8406..353fa5ee21 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);