From: "Michael S. Tsirkin" <mst@redhat.com>
To: Eugenio Perez Martin <eperezma@redhat.com>
Cc: Seojin An <love09010224@uos.ac.kr>,
Jason Wang <jasowangio@gmail.com>,
Xuan Zhuo <xuanzhuo@linux.alibaba.com>,
virtualization@lists.linux.dev, security@kernel.org
Subject: Re: [PATCH] virtio_ring: reject unrepresentable split indirect tables
Date: Thu, 26 Nov 2026 06:28:58 -0500 [thread overview]
Message-ID: <20261126062833-mutt-send-email-mst@kernel.org> (raw)
In-Reply-To: <CAJaqyWcJe+sSudFs8aNvzLn5YR1wvCYTDRT3AhdPgfMQTRLCzQ@mail.gmail.com>
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
> > > >
> >
next prev parent reply other threads:[~2026-11-26 11:29 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2026-11-30 8:51 ` Eugenio Perez Martin
2026-11-30 11:55 ` Michael S. Tsirkin
2026-11-26 8:22 ` Michael S. Tsirkin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261126062833-mutt-send-email-mst@kernel.org \
--to=mst@redhat.com \
--cc=eperezma@redhat.com \
--cc=jasowangio@gmail.com \
--cc=love09010224@uos.ac.kr \
--cc=security@kernel.org \
--cc=virtualization@lists.linux.dev \
--cc=xuanzhuo@linux.alibaba.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.