From: "Marc-André Lureau" <marcandre.lureau@redhat.com>
To: qemu-devel@nongnu.org
Subject: [GIT PULL 12/15] hw/display/virtio-gpu: cap submit_3d command buffer allocation
Date: Fri, 17 Jul 2026 15:52:51 +0400 [thread overview]
Message-ID: <20260717-fix-v1-12-cb9f7d49dc52@redhat.com> (raw)
In-Reply-To: <20260717-fix-v1-0-cb9f7d49dc52@redhat.com>
Both virgl_cmd_submit_3d() and rutabaga_cmd_submit_3d() pass the
guest-controlled cs.size directly to malloc() without bounds checking. A
malicious guest can set cs.size to an arbitrarily large value, causing
an OOM abort that crashes the QEMU process.
Checking cs.size against the descriptor payload length (iov_size) is not
sufficient: indirect descriptor tables can repeat entries aliasing the
same guest-physical range, inflating iov_size() to nearly 4 GiB while
referring to only a small amount of unique memory.
Instead, cap cs.size at 4 MiB. With 4 KiB pages and QEMU's
VIRTQUEUE_MAX_SIZE (1024) mapped-iov limit, the Linux virtio driver
cannot carry more than ~4 MiB of inline command data, so legitimate
submissions are unaffected.
Fixes: 9d9e152136bd ("virtio-gpu: add 3d mode and virgl rendering support.")
Fixes: 1dcc6adbc168 ("gfxstream + rutabaga: add initial support for gfxstream")
Fixes: d52c454aadc ("contrib: add vhost-user-gpu")
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3776
Reported-by: admin@fluentlogic.org
Reviewed-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
contrib/vhost-user-gpu/vugpu.h | 9 +++++++++
include/hw/virtio/virtio-gpu.h | 9 +++++++++
contrib/vhost-user-gpu/virgl.c | 7 +++++++
hw/display/virtio-gpu-rutabaga.c | 8 ++++++++
hw/display/virtio-gpu-virgl.c | 8 ++++++++
5 files changed, 41 insertions(+)
diff --git a/contrib/vhost-user-gpu/vugpu.h b/contrib/vhost-user-gpu/vugpu.h
index 654c392fbbf..2374eb90cb9 100644
--- a/contrib/vhost-user-gpu/vugpu.h
+++ b/contrib/vhost-user-gpu/vugpu.h
@@ -22,6 +22,7 @@
#include "qemu/queue.h"
#include "qemu/iov.h"
#include "qemu/bswap.h"
+#include "qemu/units.h"
#include "vugbm.h"
typedef enum VhostUserGpuRequest {
@@ -163,6 +164,14 @@ struct virtio_gpu_ctrl_command {
QTAILQ_ENTRY(virtio_gpu_ctrl_command) next;
};
+/*
+ * With 4 KiB pages and QEMU's VIRTQUEUE_MAX_SIZE (1024) mapped-iov
+ * limit, the largest inline command is ~4 MiB. Cap submit_3d
+ * allocations to this value to prevent a malicious guest from
+ * triggering an OOM abort via an inflated cs.size field.
+ */
+#define VIRTIO_GPU_MAX_CMD_SUBMIT_SIZE (4 * MiB)
+
#define VUGPU_FILL_CMD(out) do { \
size_t vugpufillcmd_s_ = \
iov_to_buf(cmd->elem.out_sg, cmd->elem.out_num, 0, \
diff --git a/include/hw/virtio/virtio-gpu.h b/include/hw/virtio/virtio-gpu.h
index f69fc194627..b9bad27c97a 100644
--- a/include/hw/virtio/virtio-gpu.h
+++ b/include/hw/virtio/virtio-gpu.h
@@ -15,6 +15,7 @@
#define HW_VIRTIO_GPU_H
#include "qemu/queue.h"
+#include "qemu/units.h"
#include "ui/qemu-pixman.h"
#include "ui/console.h"
#include "hw/virtio/virtio.h"
@@ -299,6 +300,14 @@ struct VirtIOGPURutabaga {
struct rutabaga *rutabaga;
};
+/*
+ * With 4 KiB pages and QEMU's VIRTQUEUE_MAX_SIZE (1024) mapped-iov
+ * limit, the largest inline command is ~4 MiB. Cap submit_3d
+ * allocations to this value to prevent a malicious guest from
+ * triggering an OOM abort via an inflated cs.size field.
+ */
+#define VIRTIO_GPU_MAX_CMD_SUBMIT_SIZE (4 * MiB)
+
#define VIRTIO_GPU_FILL_CMD(out) do { \
size_t virtiogpufillcmd_s_ = \
iov_to_buf(cmd->elem.out_sg, cmd->elem.out_num, 0, \
diff --git a/contrib/vhost-user-gpu/virgl.c b/contrib/vhost-user-gpu/virgl.c
index 51da0e3667f..550fd03bf5c 100644
--- a/contrib/vhost-user-gpu/virgl.c
+++ b/contrib/vhost-user-gpu/virgl.c
@@ -202,6 +202,13 @@ virgl_cmd_submit_3d(VuGpu *g,
VUGPU_FILL_CMD(cs);
+ if (cs.size > VIRTIO_GPU_MAX_CMD_SUBMIT_SIZE) {
+ g_critical("%s: command buffer too large (%u)",
+ __func__, cs.size);
+ cmd->error = VIRTIO_GPU_RESP_ERR_INVALID_PARAMETER;
+ return;
+ }
+
buf = g_malloc(cs.size);
s = iov_to_buf(cmd->elem.out_sg, cmd->elem.out_num,
sizeof(cs), buf, cs.size);
diff --git a/hw/display/virtio-gpu-rutabaga.c b/hw/display/virtio-gpu-rutabaga.c
index 6ff12639012..4d7d7b24592 100644
--- a/hw/display/virtio-gpu-rutabaga.c
+++ b/hw/display/virtio-gpu-rutabaga.c
@@ -351,6 +351,14 @@ rutabaga_cmd_submit_3d(VirtIOGPU *g,
VIRTIO_GPU_FILL_CMD(cs);
trace_virtio_gpu_cmd_ctx_submit(cs.hdr.ctx_id, cs.size);
+ if (cs.size > VIRTIO_GPU_MAX_CMD_SUBMIT_SIZE) {
+ qemu_log_mask(LOG_GUEST_ERROR,
+ "%s: command buffer too large (%u)\n",
+ __func__, cs.size);
+ cmd->error = VIRTIO_GPU_RESP_ERR_INVALID_PARAMETER;
+ return;
+ }
+
buf = g_new0(uint8_t, cs.size);
s = iov_to_buf(cmd->elem.out_sg, cmd->elem.out_num,
sizeof(cs), buf, cs.size);
diff --git a/hw/display/virtio-gpu-virgl.c b/hw/display/virtio-gpu-virgl.c
index 60c78af06a4..d9e5b011049 100644
--- a/hw/display/virtio-gpu-virgl.c
+++ b/hw/display/virtio-gpu-virgl.c
@@ -607,6 +607,14 @@ static void virgl_cmd_submit_3d(VirtIOGPU *g,
VIRTIO_GPU_FILL_CMD(cs);
trace_virtio_gpu_cmd_ctx_submit(cs.hdr.ctx_id, cs.size);
+ if (cs.size > VIRTIO_GPU_MAX_CMD_SUBMIT_SIZE) {
+ qemu_log_mask(LOG_GUEST_ERROR,
+ "%s: command buffer too large (%u)\n",
+ __func__, cs.size);
+ cmd->error = VIRTIO_GPU_RESP_ERR_INVALID_PARAMETER;
+ return;
+ }
+
buf = g_malloc(cs.size);
s = iov_to_buf(cmd->elem.out_sg, cmd->elem.out_num,
sizeof(cs), buf, cs.size);
--
2.55.0
next prev parent reply other threads:[~2026-07-17 11:55 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-17 11:52 [GIT PULL 00/15] Various UI/security-related fixes for 11.1 Marc-André Lureau
2026-07-17 11:52 ` [GIT PULL 01/15] i386/tdx: fix uninitialized variable warning in tdx_check_features Marc-André Lureau
2026-07-17 11:52 ` [GIT PULL 02/15] ui/vnc: fix OOB write in vnc_refresh_lossy_rect Marc-André Lureau
2026-07-17 11:52 ` [GIT PULL 03/15] ui/vnc: validate color shifts in SetPixelFormat Marc-André Lureau
2026-07-17 11:52 ` [GIT PULL 04/15] ui/vnc: use RFB wire types for client message handlers Marc-André Lureau
2026-07-17 11:52 ` [GIT PULL 05/15] ui/input-barrier: fix off-by-one in keycode bounds check Marc-André Lureau
2026-07-17 11:52 ` [GIT PULL 06/15] ui/gtk: Narrow DMA-BUF critical section Marc-André Lureau
2026-07-17 11:52 ` [GIT PULL 07/15] ui/vnc: fix out-of-bounds write in lossy refresh dirty marking Marc-André Lureau
2026-07-21 8:17 ` Peter Maydell
2026-07-21 8:23 ` Marc-André Lureau
2026-07-21 8:34 ` Peter Maydell
2026-07-17 11:52 ` [GIT PULL 08/15] ui/vnc: validate SetPixelFormat field ranges Marc-André Lureau
2026-07-17 11:52 ` [GIT PULL 09/15] hw/display/virtio-gpu: fix dmabuf_fd leak on remap failure Marc-André Lureau
2026-07-17 11:52 ` [GIT PULL 10/15] hw/display/qxl: fix TOCTOU in cursor chunk data_size handling Marc-André Lureau
2026-07-17 11:52 ` [GIT PULL 11/15] hw/display/virtio-gpu: validate stride against width on scanout Marc-André Lureau
2026-07-17 11:52 ` Marc-André Lureau [this message]
2026-07-17 11:52 ` [GIT PULL 13/15] hw/display/virtio-gpu: handle migration iov allocation failure Marc-André Lureau
2026-07-17 11:52 ` [GIT PULL 14/15] hw/display/virtio-gpu: reject strides exceeding INT_MAX Marc-André Lureau
2026-07-17 11:52 ` [GIT PULL 15/15] hw/display/virtio-gpu: Check pixman_image_create_bits() results Marc-André Lureau
2026-07-19 7:31 ` [GIT PULL 00/15] Various UI/security-related fixes for 11.1 Michael Tokarev
2026-07-19 7:33 ` Michael Tokarev
2026-07-19 7:50 ` Akihiko Odaki
2026-07-19 8:07 ` Marc-André Lureau
2026-07-19 11:41 ` Akihiko Odaki
2026-07-20 9:59 ` Stefan Hajnoczi
2026-07-20 11:27 ` Michael Tokarev
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=20260717-fix-v1-12-cb9f7d49dc52@redhat.com \
--to=marcandre.lureau@redhat.com \
--cc=qemu-devel@nongnu.org \
/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.