Skip to contentSkip to conversation

virtio-gpu: reject requests with short/truncated control headers

PATCH Superseded Ankur Saini 3 participants 4 messages Jul 28

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 virtio-gpu: reject requests with short/truncated control headers

A control request shorter than virtio_gpu_ctrl_hdr can leave cmd_hdr partially initialized. If the supplied bytes set the fence flag, stale fence metadata may later be returned to the guest.

Validate the common header length before dispatch. Clear cmd_hdr and complete malformed requests with ERR_INVALID_PARAMETER so stale fields cannot reach the response.

Fixes: CVE-2026-18054
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4094

---
A control request shorter than virtio_gpu_ctrl_hdr can leave cmd_hdr partially initialized. If the supplied bytes set the fence flag, stale fence metadata may later be returned to the guest.

Validate the common header length before dispatch. Clear cmd_hdr and complete malformed requests with ERR_INVALID_PARAMETER so stale fields cannot reach the response.

---
 hw/display/virtio-gpu.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
hw/display/virtio-gpu.c +8 -2
index 4d46a4eb10..15a845eff6 100644
@@ -1105,8 +1105,14 @@ void virtio_gpu_process_cmdq(VirtIOGPU *g)
             break;
         }
 
-        /* process command */
-        vgc->process_cmd(g, cmd);
+        if (unlikely(iov_size(cmd->elem.out_sg, cmd->elem.out_num) <
+                     sizeof(cmd->cmd_hdr))) {
+            memset(&cmd->cmd_hdr, 0, sizeof(cmd->cmd_hdr));
+            virtio_gpu_ctrl_response_nodata(
+                g, cmd, VIRTIO_GPU_RESP_ERR_INVALID_PARAMETER);
+        } else {
+            vgc->process_cmd(g, cmd);
+        }
 
         /* command suspended */
         if (!cmd->finished && !(cmd->cmd_hdr.flags & VIRTIO_GPU_FLAG_FENCE)) {

---
base-commit: 299e7557ed15a9a325620698add379a3ce2d1d95
change-id: 20260728-virtio-gpu-short-header-476aa1dae4f7

Best regards,

Signature · 1 line
Ankur Saini <[email protected]>
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Ankur Saini

A control request shorter than virtio_gpu_ctrl_hdr can leave cmd_hdr partially initialized. If the supplied bytes set the fence flag, stale fence metadata may later be returned to the guest.

Quoted 8 lines

Validate the common header length before dispatch. Clear cmd_hdr and complete malformed requests with ERR_INVALID_PARAMETER so stale fields cannot reach the response.

Fixes: CVE-2026-18054
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4094

Quoted 43 lines

---
A control request shorter than virtio_gpu_ctrl_hdr can leave cmd_hdr partially initialized. If the supplied bytes set the fence flag, stale fence metadata may later be returned to the guest.

Validate the common header length before dispatch. Clear cmd_hdr and complete malformed requests with ERR_INVALID_PARAMETER so stale fields cannot reach the response.

---
 hw/display/virtio-gpu.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
hw/display/virtio-gpu.c +8 -3
index 4d46a4eb10..15a845eff6 100644
@@ -1105,8 +1105,14 @@ void virtio_gpu_process_cmdq(VirtIOGPU *g)
             break;
         }
 
-        /* process command */
-        vgc->process_cmd(g, cmd);
+        if (unlikely(iov_size(cmd->elem.out_sg, cmd->elem.out_num) <
+                     sizeof(cmd->cmd_hdr))) {
+            memset(&cmd->cmd_hdr, 0, sizeof(cmd->cmd_hdr));
+            virtio_gpu_ctrl_response_nodata(
+                g, cmd, VIRTIO_GPU_RESP_ERR_INVALID_PARAMETER);
+        } else {
+            vgc->process_cmd(g, cmd);
+        }
 
         /* command suspended */
         if (!cmd->finished && !(cmd->cmd_hdr.flags & VIRTIO_GPU_FLAG_FENCE)) {
 
---

base-commit: 299e7557ed15a9a325620698add379a3ce2d1d95
change-id: 20260728-virtio-gpu-short-header-476aa1dae4f7

Best regards,
--
Ankur Saini <[email protected]>

Signature · 1 line
Marc-André Lureau
Reviewed-by on v1 1/1
#2 lore raw
In reply to Ankur Saini
Quoted 4 lines · Ankur Saini

A control request shorter than virtio_gpu_ctrl_hdr can leave cmd_hdr partially initialized. If the supplied bytes set the fence flag, stale fence metadata may later be returned to the guest.

Quoted 8 lines

Validate the common header length before dispatch. Clear cmd_hdr and complete malformed requests with ERR_INVALID_PARAMETER so stale fields cannot reach the response.

Fixes: CVE-2026-18054
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4094

Please also fix vhost-user-gpu.

Regards,
Akihiko Odaki

Quoted 39 lines

---
A control request shorter than virtio_gpu_ctrl_hdr can leave cmd_hdr partially initialized. If the supplied bytes set the fence flag, stale fence metadata may later be returned to the guest.

Validate the common header length before dispatch. Clear cmd_hdr and complete malformed requests with ERR_INVALID_PARAMETER so stale fields cannot reach the response.

---
  hw/display/virtio-gpu.c | 10 ++++++++--
  1 file changed, 8 insertions(+), 2 deletions(-)
hw/display/virtio-gpu.c +8 -3
index 4d46a4eb10..15a845eff6 100644
@@ -1105,8 +1105,14 @@ void virtio_gpu_process_cmdq(VirtIOGPU *g)
              break;
          }
 
-        /* process command */
-        vgc->process_cmd(g, cmd);
+        if (unlikely(iov_size(cmd->elem.out_sg, cmd->elem.out_num) <
+                     sizeof(cmd->cmd_hdr))) {
+            memset(&cmd->cmd_hdr, 0, sizeof(cmd->cmd_hdr));
+            virtio_gpu_ctrl_response_nodata(
+                g, cmd, VIRTIO_GPU_RESP_ERR_INVALID_PARAMETER);
+        } else {
+            vgc->process_cmd(g, cmd);
+        }
 
          /* command suspended */
          if (!cmd->finished && !(cmd->cmd_hdr.flags & VIRTIO_GPU_FLAG_FENCE)) {
 
---

base-commit: 299e7557ed15a9a325620698add379a3ce2d1d95
change-id: 20260728-virtio-gpu-short-header-476aa1dae4f7

Best regards,

#3 lore raw

Thanks. I found the similar path in contrib/vhost-user-gpu and will include a minimal fix for that in v2.

Quoted 63 lines · Akihiko Odaki
Quoted 4 lines · Ankur Saini

A control request shorter than virtio_gpu_ctrl_hdr can leave cmd_hdr partially initialized. If the supplied bytes set the fence flag, stale fence metadata may later be returned to the guest.

Quoted 8 lines

Validate the common header length before dispatch. Clear cmd_hdr and complete malformed requests with ERR_INVALID_PARAMETER so stale fields cannot reach the response.

Fixes: CVE-2026-18054
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4094

Please also fix vhost-user-gpu.

Regards,
Akihiko Odaki

Quoted 23 lines

---
A control request shorter than virtio_gpu_ctrl_hdr can leave cmd_hdr partially initialized. If the supplied bytes set the fence flag, stale fence metadata may later be returned to the guest.

Validate the common header length before dispatch. Clear cmd_hdr and complete malformed requests with ERR_INVALID_PARAMETER so stale fields cannot reach the response.

---
  hw/display/virtio-gpu.c | 10 ++++++++--
  1 file changed, 8 insertions(+), 2 deletions(-)
hw/display/virtio-gpu.c +1 -2
index 4d46a4eb10..15a845eff6 100644
@@ -1105,8 +1105,14 @@ void virtio_gpu_process_cmdq(VirtIOGPU *g)
              break;
          }
 
-        /* process command */
-        vgc->process_cmd(g, cmd);
+        if (unlikely(iov_size(cmd->elem.out_sg, cmd->elem.out_num) <

hw/display/virtio-gpu.c void virtio_gpu_process_cmdq(VirtIOGPU *g) · line 1118

Quoted 10 lines
hw/display/virtio-gpu.c +7 -0
+                     sizeof(cmd->cmd_hdr))) {
+            memset(&cmd->cmd_hdr, 0, sizeof(cmd->cmd_hdr));
+            virtio_gpu_ctrl_response_nodata(
+                g, cmd, VIRTIO_GPU_RESP_ERR_INVALID_PARAMETER);
+        } else {
+            vgc->process_cmd(g, cmd);
+        }
 
          /* command suspended */
          if (!cmd->finished && !(cmd->cmd_hdr.flags &

VIRTIO_GPU_FLAG_FENCE)) {

Quoted 6 lines

---
base-commit: 299e7557ed15a9a325620698add379a3ce2d1d95
change-id: 20260728-virtio-gpu-short-header-476aa1dae4f7

Best regards,