From: sashiko-bot@kernel.org
To: "Seojin An" <love09010224@uos.ac.kr>
Cc: virtualization@lists.linux.dev,
"Michael S. Tsirkin" <mst@redhat.com>,
"Eugenio Perez" <eperezma@redhat.com>
Subject: Re: [PATCH] virtio_ring: reject unrepresentable split indirect tables
Date: Thu, 26 Nov 2026 08:10:42 +0000 [thread overview]
Message-ID: <sashiko-outbox-234986@kernel.org> (raw)
In-Reply-To: <20261126080209.2898344-1-love09010224@uos.ac.kr>
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
next prev parent reply other threads:[~2026-11-26 8:10 UTC|newest]
Thread overview: 9+ 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 [this message]
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
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=sashiko-outbox-234986@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=eperezma@redhat.com \
--cc=love09010224@uos.ac.kr \
--cc=mst@redhat.com \
--cc=sashiko-reviews@lists.linux.dev \
--cc=virtualization@lists.linux.dev \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox