Linux virtualization list
 help / color / mirror / Atom feed
* [PATCH] virtio_ring: reject unrepresentable split indirect tables
@ 2026-11-26  8:02 Seojin An
  2026-11-26  8:10 ` sashiko-bot
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Seojin An @ 2026-11-26  8:02 UTC (permalink / raw)
  To: Michael S. Tsirkin, Jason Wang, Eugenio Pérez
  Cc: Xuan Zhuo, virtualization, security

Split descriptors store the next index as u16. alloc_indirect_split() can
allocate a larger table, but virtqueue_add_split() feeds the truncated next
value back into its construction index. With more than 65,536 SG entries,
the index wraps and later entries replace descriptors at the start of the
table. The device then consumes a chain different from the caller's SG
sequence.

Reject split indirect tables whose entry count exceeds the representable
index range. Keep the existing compatibility policy that permits
representable indirect chains longer than Queue Size, and leave packed
indirect descriptors unchanged.

A virtio-gpu render client can reach this condition with a vmalloc-backed
EXECBUFFER. In a no-vIOMMU QEMU/virgl guest, the resulting command
substitution provided guest physical read/write and initial-namespace
uid/euid 0. The virtio-gpu producer needs its own Queue-Size check because
its current queue error path warns about an add failure but advances
pending state and reports success.

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

Fixes: 9fa29b9df32b ("virtio: indirect ring entries (VIRTIO_RING_F_INDIRECT_DESC)")
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/virtio/virtio_ring.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
index f683a2d6a2002..ad9e52584fb52 100644
--- a/drivers/virtio/virtio_ring.c
+++ b/drivers/virtio/virtio_ring.c
@@ -686,9 +686,19 @@ static inline int virtqueue_add_split(struct vring_virtqueue *vq,
 
 	head = vq->free_head;
 
-	if (virtqueue_use_indirect(vq, total_sg))
+	if (virtqueue_use_indirect(vq, total_sg)) {
+		/*
+		 * The core historically permits an indirect chain to exceed the
+		 * queue size.  Preserve that policy, but do not let its 16-bit
+		 * split descriptor links wrap within the allocated table.
+		 */
+		if (unlikely(total_sg > (1U << 16))) {
+			END_USE(vq);
+			return -E2BIG;
+		}
+
 		desc = alloc_indirect_split(vq, total_sg, gfp);
-	else {
+	} else {
 		desc = NULL;
 		WARN_ON_ONCE(total_sg > vq->split.vring.num && !vq->indirect);
 	}

base-commit: 40212b29a6f718d4e7fb3275cede181cb8e137cf
-- 
2.43.0


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

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

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-26  8:02 [PATCH] virtio_ring: reject unrepresentable split indirect tables Seojin An
2026-11-26  8:10 ` sashiko-bot
2026-11-26  8:14 ` Eugenio Perez Martin
2026-11-26  8:24   ` Michael S. Tsirkin
2026-11-26  8:41     ` Eugenio Perez Martin
2026-11-26 11:24       ` Seojin An
2026-11-26 11:36         ` Michael S. Tsirkin
2026-11-26 11:28       ` Michael S. Tsirkin
2026-11-26  8:22 ` Michael S. Tsirkin

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