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 <[email protected]> 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 <[email protected]> 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 <[email protected]>
> > > > Reported-by: GEONWOO HAN <[email protected]>
> > > > Cc: [email protected]
> > > > Signed-off-by: Seojin An <[email protected]>
> > > > ---
> > > > 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
> > > >
> >