All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Marc-André Lureau" <marcandre.lureau@redhat.com>
To: qemu-devel@nongnu.org
Cc: stefanha@redhat.com, "Michael S. Tsirkin" <mst@redhat.com>,
	"Stefano Garzarella" <sgarzare@redhat.com>,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>,
	"Alex Bennée" <alex.bennee@linaro.org>,
	"Akihiko Odaki" <odaki@rsg.ci.i.u-tokyo.ac.jp>,
	"Dmitry Osipenko" <dmitry.osipenko@collabora.com>
Subject: [GIT PULL 6/9] virtio-gpu: reject requests with short/truncated control headers
Date: Tue, 04 Aug 2026 11:18:55 +0400	[thread overview]
Message-ID: <20260804-fix-v1-6-0c2be5390809@redhat.com> (raw)
In-Reply-To: <20260804-fix-v1-0-0c2be5390809@redhat.com>

From: Ankur Saini <ankur98saini@gmail.com>

A short control request can leave command data partially initialized.
For the common header, guest-controlled flags can then cause stale fence
metadata to be returned to the guest.

The command fill helpers detect a short copy but only log and return.
For the common header this leaves the request without any completion;
for type-specific commands the caller still completes the request but
reports VIRTIO_GPU_RESP_OK_NODATA, masking the error. Make
VIRTIO_GPU_FILL_CMD() clear the partially copied object and complete the
request with ERR_INVALID_PARAMETER. Make VUGPU_FILL_CMD() report the same
error through the existing vhost-user-gpu dispatcher. This also rejects
truncated type-specific commands.

The vhost-user-gpu common header is copied outside VUGPU_FILL_CMD(), so
clear it and complete the request directly when that copy is short.

Fixes: CVE-2026-66021
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4094
Reported-by: Ankur Saini <ankur98saini@gmail.com>
Suggested-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
Signed-off-by: Ankur Saini <ankur98saini@gmail.com>
Reviewed-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-ID: <20260803-virtio-gpu-short-header-v3-1-936c1daa8e61@gmail.com>
---
 contrib/vhost-user-gpu/vugpu.h          |  1 +
 include/hw/virtio/virtio-gpu.h          |  3 +++
 contrib/vhost-user-gpu/vhost-user-gpu.c | 21 ++++++++++++---------
 3 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/contrib/vhost-user-gpu/vugpu.h b/contrib/vhost-user-gpu/vugpu.h
index 2374eb90cb9b..aaf2870cb24d 100644
--- a/contrib/vhost-user-gpu/vugpu.h
+++ b/contrib/vhost-user-gpu/vugpu.h
@@ -179,6 +179,7 @@ struct virtio_gpu_ctrl_command {
         if (vugpufillcmd_s_ != sizeof(out)) {                   \
             g_critical("%s: command size incorrect %zu vs %zu", \
                        __func__, vugpufillcmd_s_, sizeof(out)); \
+            cmd->error = VIRTIO_GPU_RESP_ERR_INVALID_PARAMETER; \
             return;                                             \
         }                                                       \
     } while (0)
diff --git a/include/hw/virtio/virtio-gpu.h b/include/hw/virtio/virtio-gpu.h
index 2f60c72078b3..f965defa6b25 100644
--- a/include/hw/virtio/virtio-gpu.h
+++ b/include/hw/virtio/virtio-gpu.h
@@ -315,6 +315,9 @@ struct VirtIOGPURutabaga {
             qemu_log_mask(LOG_GUEST_ERROR,                              \
                           "%s: command size incorrect %zu vs %zu\n",    \
                           __func__, virtiogpufillcmd_s_, sizeof(out));  \
+            memset(&out, 0, sizeof(out));                               \
+            virtio_gpu_ctrl_response_nodata(                            \
+                g, cmd, VIRTIO_GPU_RESP_ERR_INVALID_PARAMETER);         \
             return;                                                     \
         }                                                               \
     } while (0)
diff --git a/contrib/vhost-user-gpu/vhost-user-gpu.c b/contrib/vhost-user-gpu/vhost-user-gpu.c
index ee9858c397ce..786488150932 100644
--- a/contrib/vhost-user-gpu/vhost-user-gpu.c
+++ b/contrib/vhost-user-gpu/vhost-user-gpu.c
@@ -930,16 +930,19 @@ vg_handle_ctrl(VuDev *dev, int qidx)
         if (len != sizeof(cmd->cmd_hdr)) {
             g_warning("%s: command size incorrect %zu vs %zu\n",
                       __func__, len, sizeof(cmd->cmd_hdr));
-        }
-
-        virtio_gpu_ctrl_hdr_bswap(&cmd->cmd_hdr);
-        g_debug("%d %s\n", cmd->cmd_hdr.type,
-                vg_cmd_to_string(cmd->cmd_hdr.type));
-
-        if (vg->virgl) {
-            vg_virgl_process_cmd(vg, cmd);
+            memset(&cmd->cmd_hdr, 0, sizeof(cmd->cmd_hdr));
+            vg_ctrl_response_nodata(
+                vg, cmd, VIRTIO_GPU_RESP_ERR_INVALID_PARAMETER);
         } else {
-            vg_process_cmd(vg, cmd);
+            virtio_gpu_ctrl_hdr_bswap(&cmd->cmd_hdr);
+            g_debug("%d %s\n", cmd->cmd_hdr.type,
+                    vg_cmd_to_string(cmd->cmd_hdr.type));
+
+            if (vg->virgl) {
+                vg_virgl_process_cmd(vg, cmd);
+            } else {
+                vg_process_cmd(vg, cmd);
+            }
         }
 
         if (cmd->state != VG_CMD_STATE_FINISHED) {

-- 
2.55.0



  parent reply	other threads:[~2026-08-04  7:21 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-04  7:18 [GIT PULL 0/9] Fixes for 11.1-rc Marc-André Lureau
2026-08-04  7:18 ` [GIT PULL 1/9] hw/display/virtio-gpu: validate blob iov size Marc-André Lureau
2026-08-04  7:18 ` [GIT PULL 2/9] hw/display/vga: fix panning_buf OOB after text/graphics switch Marc-André Lureau
2026-08-04  7:18 ` [GIT PULL 3/9] vhost-user-gpu: fix integer overflow in buffer allocation Marc-André Lureau
2026-08-04  7:18 ` [GIT PULL 4/9] hw/display/virtio-gpu: fix offset wraparound in scanout_blob_to_fb Marc-André Lureau
2026-08-04  7:18 ` [GIT PULL 5/9] hw/display/virtio-gpu: drop redundant node->value NULL checks Marc-André Lureau
2026-08-04  7:18 ` Marc-André Lureau [this message]
2026-08-04  7:18 ` [GIT PULL 7/9] hw/display/virtio-gpu: Always reject invalid scanout bounds Marc-André Lureau
2026-08-04  7:18 ` [GIT PULL 8/9] hw/display/virtio-gpu: Unmap DMA regions on reset Marc-André Lureau
2026-08-04  7:18 ` [GIT PULL 9/9] qapi/dump: add allowed-by-guest feature to win-dmp Marc-André Lureau
2026-08-04 19:07 ` [GIT PULL 0/9] Fixes for 11.1-rc Marc-André Lureau
2026-08-04 19:21 ` [GIT PULL v2 " Marc-André Lureau
2026-08-04 19:21   ` [GIT PULL v2 1/9] hw/display/virtio-gpu: validate blob iov size Marc-André Lureau
2026-08-04 19:21   ` [GIT PULL v2 2/9] hw/display/vga: fix panning_buf OOB after text/graphics switch Marc-André Lureau
2026-08-04 19:21   ` [GIT PULL v2 3/9] vhost-user-gpu: fix integer overflow in buffer allocation Marc-André Lureau
2026-08-04 19:21   ` [GIT PULL v2 4/9] hw/display/virtio-gpu: fix offset wraparound in scanout_blob_to_fb Marc-André Lureau
2026-08-04 19:21   ` [GIT PULL v2 5/9] hw/display/virtio-gpu: drop redundant node->value NULL checks Marc-André Lureau
2026-08-04 19:21   ` [GIT PULL v2 6/9] virtio-gpu: reject requests with short/truncated control headers Marc-André Lureau
2026-08-04 19:21   ` [GIT PULL v2 7/9] hw/display/virtio-gpu: Always reject invalid scanout bounds Marc-André Lureau
2026-08-04 19:21   ` [GIT PULL v2 8/9] hw/display/virtio-gpu: Unmap DMA regions on reset Marc-André Lureau
2026-08-04 19:21   ` [GIT PULL v2 9/9] qapi/dump: add allowed-by-guest feature to win-dmp Marc-André Lureau
2026-08-05  0:55   ` [GIT PULL v2 0/9] Fixes for 11.1-rc 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=20260804-fix-v1-6-0c2be5390809@redhat.com \
    --to=marcandre.lureau@redhat.com \
    --cc=alex.bennee@linaro.org \
    --cc=dmitry.osipenko@collabora.com \
    --cc=mst@redhat.com \
    --cc=odaki@rsg.ci.i.u-tokyo.ac.jp \
    --cc=qemu-devel@nongnu.org \
    --cc=sgarzare@redhat.com \
    --cc=stefanha@redhat.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.