Linux virtualization list
 help / color / mirror / Atom feed
* [PATCH] drm/virtio: bound execbuffer commands to control queue size
@ 2026-11-26  8:00 Seojin An
  2026-11-26  8:22 ` sashiko-bot
  0 siblings, 1 reply; 4+ messages in thread
From: Seojin An @ 2026-11-26  8:00 UTC (permalink / raw)
  To: David Airlie, Gerd Hoffmann, Dmitry Osipenko
  Cc: Gurchetan Singh, Chia-I Wu, dri-devel, virtualization, security

DRM_IOCTL_VIRTGPU_EXECBUFFER accepts a user-controlled command size and
stores the command in vmalloc memory. virtio-gpu maps each command page to
one SG entry, then adds a request and response entry before submitting the
chain to the control virtqueue.

With indirect descriptors negotiated, the driver accounts for the chain as
one free ring descriptor. An unprivileged render client can therefore
submit more SG entries than the device Queue Size. A sufficiently large
command also exceeds the u16 index range of a split indirect table, causing
the final SG entries to replace the request and first command descriptors
after the next index wraps.

Reject commands whose page count plus the fixed request and response
exceeds the actual control Queue Size. Perform the check before command
copy, object reservation, fence allocation or queue publication.

This also avoids relying on the current queue error path:
virtio_gpu_queue_ctrl_sgs() only warns when virtqueue_add_sgs() fails, then
advances sequence and pending-command state and returns success.

In a no-vIOMMU QEMU/virgl guest, the malformed chain let a render client
substitute RESOURCE_ATTACH_BACKING, obtain guest physical read/write and
gain initial-namespace uid/euid 0. On a 256-entry control queue, 254
command pages continue to complete and 255 pages now return E2BIG.

AI tools assisted the source audit, reproducer construction and patch
drafting.

Fixes: 5edbb5608256 ("drm/virtio: fix ring free check")
Reported-by: Hyeonjun Hong <hyeonjunhong330@gmail.com>
Reported-by: GEONWOO HAN <gunwoo9643@uos.ac.kr>
Cc: stable@vger.kernel.org
Signed-off-by: Seojin An <love09010224@uos.ac.kr>
---
 drivers/gpu/drm/virtio/virtgpu_submit.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/drivers/gpu/drm/virtio/virtgpu_submit.c b/drivers/gpu/drm/virtio/virtgpu_submit.c
index 6580ece658704..9aff7f8d5195f 100644
--- a/drivers/gpu/drm/virtio/virtgpu_submit.c
+++ b/drivers/gpu/drm/virtio/virtgpu_submit.c
@@ -482,6 +482,8 @@ int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data,
 	u64 fence_ctx = vgdev->fence_drv.context;
 	struct drm_virtgpu_execbuffer *exbuf = data;
 	struct virtio_gpu_submit submit;
+	u64 command_sgs;
+	unsigned int max_sgs;
 	u32 ring_idx = 0;
 	int ret = -EINVAL;
 
@@ -491,6 +493,17 @@ int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data,
 	if (exbuf->flags & ~VIRTGPU_EXECBUF_FLAGS)
 		return ret;
 
+	/*
+	 * The command contributes one SG entry per vmalloc page in addition
+	 * to the fixed request and response entries.  Virtio requires both
+	 * direct and indirect descriptor chains to fit the device queue.
+	 * Reject oversized commands before copying or queueing them.
+	 */
+	max_sgs = virtqueue_get_vring_size(vgdev->ctrlq.vq);
+	command_sgs = DIV_ROUND_UP((u64)exbuf->size, PAGE_SIZE);
+	if (max_sgs < 2 || command_sgs > max_sgs - 2)
+		return -E2BIG;
+
 	if (exbuf->flags & VIRTGPU_EXECBUF_RING_IDX) {
 		if (exbuf->ring_idx >= vfpriv->num_rings)
 			return ret;

base-commit: 479e381e77dcde0dfcc9d51e89ff3273da199804
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-26 14:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-26  8:00 [PATCH] drm/virtio: bound execbuffer commands to control queue size Seojin An
2026-11-26  8:22 ` sashiko-bot
2026-11-26 14:38   ` [PATCH v2] " Seojin An
2026-11-26 14:47     ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox