qemu/backends
Laurent Vivier 6a4def76fb backends/rng: cap request size to avoid oversized allocation
rng_backend_request_entropy() uses the requested size to allocate
a buffer with g_malloc(). With virtio-rng, this size comes from
guest-supplied descriptor lengths. A malicious guest can set a very
large descriptor length, causing QEMU to attempt a multi-gigabyte
allocation and abort.

Cap the allocation to 64 KiB. The virtio-rng queue size is
hardcoded to 8 entries, the EGD backend protocol limits requests
to 255 bytes, the Linux kernel hwrng framework requests at most
SMP_CACHE_BYTES per call (64 bytes on x86_64), and the Windows
viorng driver uses a 4 KiB buffer. The worst legitimate case is
8 x 4 KiB = 32 KiB, so 64 KiB is well above any legitimate use.

Fixes: 1441703965 ("virtio-rng: use virtqueue_get_avail_bytes, fix migration")
Cc: qemu-stable@nongnu.org
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/3983
Reported-by: dong ling <dongling226655@outlook.com>
Signed-off-by: Laurent Vivier <lvivier@redhat.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Message-ID: <20260715141300.2295392-1-lvivier@redhat.com>
(cherry picked from commit 70074cc48f)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
2026-07-31 11:08:41 +03:00
..
tpm Fix const qualifier build errors with recent glibc 2026-01-07 16:31:43 +03:00
confidential-guest-support.c system: Move 'exec/confidential-guest-support.h' to system/ 2024-12-20 17:44:56 +01:00
cryptodev-builtin.c cryptodev-builtin: Limit the maximum size 2026-02-06 00:47:22 +03:00
cryptodev-hmp-cmds.c qapi: Move include/qapi/qmp/ to include/qobject/ 2025-02-10 15:33:16 +01:00
cryptodev-lkcf.c cryptodev: Fix error handling in cryptodev_lkcf_execute_task() 2025-03-19 07:53:11 +01:00
cryptodev-vhost-user.c backends/cryptodev-vhost-user: Fix local_error leaks 2025-01-13 17:16:04 +01:00
cryptodev-vhost.c cryptodev/vhost: allocate CryptoDevBackendVhost using g_mem0() 2025-02-21 07:18:42 -05:00
cryptodev.c qom: Use object_get_container() 2025-01-09 18:16:24 +01:00
dbus-vmstate.c backends: Constify VMState 2023-12-30 07:38:06 +11:00
dbus-vmstate1.xml docs: move D-Bus VMState documentation to source XML 2021-12-21 10:50:21 +04:00
host_iommu_device.c include: Rename sysemu/ -> system/ 2024-12-20 17:44:56 +01:00
hostmem-epc.c memory: add RAM_PRIVATE 2025-01-29 11:43:04 -03:00
hostmem-file.c memory: add RAM_PRIVATE 2025-01-29 11:43:04 -03:00
hostmem-memfd.c hostmem-memfd: preserve for cpr 2025-01-29 11:43:04 -03:00
hostmem-ram.c memory: add RAM_PRIVATE 2025-01-29 11:43:04 -03:00
hostmem-shm.c hostmem/shm: Allow shm memory backend serve as shared memory for coco-VMs 2025-11-14 14:28:58 +03:00
hostmem.c include: Rename sysemu/ -> system/ 2024-12-20 17:44:56 +01:00
iommufd.c vfio: Remove reports of DMA mapping errors in backends 2025-02-11 14:15:19 +01:00
Kconfig backends: Initial support for SPDM socket support 2024-07-22 20:15:42 -04:00
meson.build backends: Initial support for SPDM socket support 2024-07-22 20:15:42 -04:00
rng-builtin.c include: Rename sysemu/ -> system/ 2024-12-20 17:44:56 +01:00
rng-egd.c include: Rename sysemu/ -> system/ 2024-12-20 17:44:56 +01:00
rng-random.c include: Rename sysemu/ -> system/ 2024-12-20 17:44:56 +01:00
rng.c backends/rng: cap request size to avoid oversized allocation 2026-07-31 11:08:41 +03:00
spdm-socket.c include: Rename sysemu/ -> system/ 2024-12-20 17:44:56 +01:00
trace-events vfio/iommufd: Implement VFIOIOMMUClass::query_dirty_bitmap support 2024-07-23 17:14:52 +02:00
trace.h trace: switch position of headers to what Meson requires 2020-08-21 06:18:24 -04:00
vhost-user.c include: Rename sysemu/ -> system/ 2024-12-20 17:44:56 +01:00