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

* Re: [PATCH] virtio_ring: reject unrepresentable split indirect tables
  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:22 ` Michael S. Tsirkin
  2 siblings, 0 replies; 9+ messages in thread
From: sashiko-bot @ 2026-11-26  8:10 UTC (permalink / raw)
  To: Seojin An; +Cc: virtualization, Michael S. Tsirkin, Eugenio Perez

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] virtio_ring: DMA mapping leak in virtqueue_add_split() at
  total_sg == 65536
--

commit f02f3f32e75945fa59c0806b58f447abf08594d4
Author: Seojin An <love09010224@uos.ac.kr>

virtio_ring: reject unrepresentable split indirect tables

This commit rejects split indirect descriptor tables in virtqueue_add_split()
when total_sg exceeds 65,536, preventing 16-bit descriptor index wrapping.

> 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);
>  	}

[Severity: Medium]
Can total_sg == (1U << 16) still wrap i to 0 after the final descriptor and
leak all 65,536 DMA mappings on the unmap_release path?

alloc_indirect_split() sets extra[i].next = i + 1 (where next is u16), so for
total_sg == 65536, extra[65535].next wraps to 0.  After mapping all 65,536 SG
entries, virtqueue_add_desc_split() returns that 0 into i.  If
vring_map_single() then fails when mapping the 1 MiB indirect descriptor
table, unmap_release sees err_idx == 0 and i == 0 and breaks out of the
cleanup loop on the first iteration without unmapping any of the SG entries:

drivers/virtio/virtio_ring.c:virtqueue_add_split() {
	...
unmap_release:
	err_idx = i;

	if (indirect)
		i = 0;
	else
		i = head;

	for (n = 0; n < total_sg; n++) {
		if (i == err_idx)
			break;

		i = vring_unmap_one_split(vq, &extra[i]);
	}
	...
}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261126080209.2898344-1-love09010224@uos.ac.kr?part=1

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

* Re: [PATCH] virtio_ring: reject unrepresentable split indirect tables
  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:22 ` Michael S. Tsirkin
  2 siblings, 1 reply; 9+ messages in thread
From: Eugenio Perez Martin @ 2026-11-26  8:14 UTC (permalink / raw)
  To: Seojin An
  Cc: Michael S. Tsirkin, Jason Wang, Xuan Zhuo, virtualization,
	security

On Thu, Nov 26, 2026 at 9:02 AM Seojin An <love09010224@uos.ac.kr> wrote:
>
> 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.
> +                */

Seems like the same code path in the packed vqs also needs this check?

Also, a question for everybody: is it really too late to forbid
indirect tables bigger than the queue size? It is not guaranteed that
the device will be able to handle it anyway, should we just add a if
(total_sg > vq.split.vring.num) return -E2BIG?

> +               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	[flat|nested] 9+ messages in thread

* Re: [PATCH] virtio_ring: reject unrepresentable split indirect tables
  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:22 ` Michael S. Tsirkin
  2 siblings, 0 replies; 9+ messages in thread
From: Michael S. Tsirkin @ 2026-11-26  8:22 UTC (permalink / raw)
  To: Seojin An
  Cc: Jason Wang, Eugenio Pérez, Xuan Zhuo, virtualization,
	security

On Thu, Nov 26, 2026 at 05:02:09PM +0900, Seojin An wrote:
> 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>


Sorry I don't get what all this is doing and how does it have to do
anything with security?  Drivers mustn't submit requests with more s/gs
than the vq size. Fix it there pls.

> ---
>  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	[flat|nested] 9+ messages in thread

* Re: [PATCH] virtio_ring: reject unrepresentable split indirect tables
  2026-11-26  8:14 ` Eugenio Perez Martin
@ 2026-11-26  8:24   ` Michael S. Tsirkin
  2026-11-26  8:41     ` Eugenio Perez Martin
  0 siblings, 1 reply; 9+ messages in thread
From: Michael S. Tsirkin @ 2026-11-26  8:24 UTC (permalink / raw)
  To: Eugenio Perez Martin
  Cc: Seojin An, Jason Wang, Xuan Zhuo, virtualization, security

On Thu, Nov 26, 2026 at 09:14:36AM +0100, Eugenio Perez Martin wrote:
> On Thu, Nov 26, 2026 at 9:02 AM Seojin An <love09010224@uos.ac.kr> wrote:
> >
> > 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.
> > +                */
> 
> Seems like the same code path in the packed vqs also needs this check?
> 
> Also, a question for everybody: is it really too late to forbid
> indirect tables bigger than the queue size? It is not guaranteed that
> the device will be able to handle it anyway, should we just add a if
> (total_sg > vq.split.vring.num) return -E2BIG?

It's not too late in that the spec forbids it.  But a bunch of drivers
are broken, so for now the best place for this check is in the driver.

> > +               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	[flat|nested] 9+ messages in thread

* Re: [PATCH] virtio_ring: reject unrepresentable split indirect tables
  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:28       ` Michael S. Tsirkin
  0 siblings, 2 replies; 9+ messages in thread
From: Eugenio Perez Martin @ 2026-11-26  8:41 UTC (permalink / raw)
  To: Michael S. Tsirkin
  Cc: Seojin An, Jason Wang, Xuan Zhuo, virtualization, security

On Thu, Nov 26, 2026 at 9:24 AM Michael S. Tsirkin <mst@redhat.com> wrote:
>
> On Thu, Nov 26, 2026 at 09:14:36AM +0100, Eugenio Perez Martin wrote:
> > On Thu, Nov 26, 2026 at 9:02 AM Seojin An <love09010224@uos.ac.kr> wrote:
> > >
> > > 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.
> > > +                */
> >
> > Seems like the same code path in the packed vqs also needs this check?
> >
> > Also, a question for everybody: is it really too late to forbid
> > indirect tables bigger than the queue size? It is not guaranteed that
> > the device will be able to handle it anyway, should we just add a if
> > (total_sg > vq.split.vring.num) return -E2BIG?
>
> It's not too late in that the spec forbids it.  But a bunch of drivers
> are broken, so for now the best place for this check is in the driver.
>

Doesn't it make sense to add in virtio_ring as hardening? Fewer places
where we can miss the check.

> > > +               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	[flat|nested] 9+ messages in thread

* Re: [PATCH] virtio_ring: reject unrepresentable split indirect tables
  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
  1 sibling, 1 reply; 9+ messages in thread
From: Seojin An @ 2026-11-26 11:24 UTC (permalink / raw)
  To: Eugenio Perez Martin
  Cc: Michael S . Tsirkin, Jason Wang, Xuan Zhuo, virtualization,
	security

Thanks. Before I post v2, I want to confirm how broadly the core should
enforce this.

One option is a common check that rejects total_sg greater than Queue Size
for both split and packed queues. That would catch cases where a driver misses
the check, but it may also reject requests that existing drivers issue today.

The other option is the narrower split representation guard from my v1. My
original check used total_sg > 65536, but it needs to reject exactly 65536 as
well. At that count the split cleanup cursor wraps to zero, so a failure while
mapping the indirect table leaves the data SG mappings behind. Packed
indirect tables do not use that cursor.

If you have a different core-side approach in mind, please let me know.

The current virtio-gpu v2 draft enforces Queue Size in the driver
independently. For the core, would you prefer the common split-and-packed
Queue-Size check, the narrow split guard, or no core change for now? Once
that is clear, I will post the corresponding core v2.

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

* Re: [PATCH] virtio_ring: reject unrepresentable split indirect tables
  2026-11-26  8:41     ` Eugenio Perez Martin
  2026-11-26 11:24       ` Seojin An
@ 2026-11-26 11:28       ` Michael S. Tsirkin
  1 sibling, 0 replies; 9+ messages in thread
From: Michael S. Tsirkin @ 2026-11-26 11:28 UTC (permalink / raw)
  To: Eugenio Perez Martin
  Cc: Seojin An, Jason Wang, Xuan Zhuo, virtualization, security

On Thu, Nov 26, 2026 at 09:41:31AM +0100, Eugenio Perez Martin wrote:
> On Thu, Nov 26, 2026 at 9:24 AM Michael S. Tsirkin <mst@redhat.com> wrote:
> >
> > On Thu, Nov 26, 2026 at 09:14:36AM +0100, Eugenio Perez Martin wrote:
> > > On Thu, Nov 26, 2026 at 9:02 AM Seojin An <love09010224@uos.ac.kr> wrote:
> > > >
> > > > 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.
> > > > +                */
> > >
> > > Seems like the same code path in the packed vqs also needs this check?
> > >
> > > Also, a question for everybody: is it really too late to forbid
> > > indirect tables bigger than the queue size? It is not guaranteed that
> > > the device will be able to handle it anyway, should we just add a if
> > > (total_sg > vq.split.vring.num) return -E2BIG?
> >
> > It's not too late in that the spec forbids it.  But a bunch of drivers
> > are broken, so for now the best place for this check is in the driver.
> >
> 
> Doesn't it make sense to add in virtio_ring as hardening? Fewer places
> where we can miss the check.


We can't because we don't know what will break.


> 
> > > > +               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	[flat|nested] 9+ messages in thread

* Re: [PATCH] virtio_ring: reject unrepresentable split indirect tables
  2026-11-26 11:24       ` Seojin An
@ 2026-11-26 11:36         ` Michael S. Tsirkin
  0 siblings, 0 replies; 9+ messages in thread
From: Michael S. Tsirkin @ 2026-11-26 11:36 UTC (permalink / raw)
  To: Seojin An
  Cc: Eugenio Perez Martin, Jason Wang, Xuan Zhuo, virtualization,
	security

On Thu, Nov 26, 2026 at 08:24:10PM +0900, Seojin An wrote:
> Thanks. Before I post v2, I want to confirm how broadly the core should
> enforce this.
> 
> One option is a common check that rejects total_sg greater than Queue Size
> for both split and packed queues. That would catch cases where a driver misses
> the check, but it may also reject requests that existing drivers issue today.
> 
> The other option is the narrower split representation guard from my v1. My
> original check used total_sg > 65536, but it needs to reject exactly 65536 as
> well. At that count the split cleanup cursor wraps to zero, so a failure while
> mapping the indirect table leaves the data SG mappings behind. Packed
> indirect tables do not use that cursor.
> 
> If you have a different core-side approach in mind, please let me know.
> 
> The current virtio-gpu v2 draft enforces Queue Size in the driver
> independently. For the core, would you prefer the common split-and-packed
> Queue-Size check, the narrow split guard, or no core change for now? Once
> that is clear, I will post the corresponding core v2.

Let's go with no core change for now.

-- 
MST


^ permalink raw reply	[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