From: "Michael S. Tsirkin" <mst@redhat.com>
To: Roi L <roeilev321_@outlook.com>
Cc: "Jason Wang" <jasowangio@gmail.com>,
"Xuan Zhuo" <xuanzhuo@linux.alibaba.com>,
"Eugenio Pérez" <eperezma@redhat.com>,
virtualization@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] virtio: virtio_ring: prevent potential null dereference on per-desc state
Date: Tue, 4 Aug 2026 16:57:24 -0400 [thread overview]
Message-ID: <20260804165355-mutt-send-email-mst@kernel.org> (raw)
In-Reply-To: <SN6PR05MB5806027A02B2C001C8E600FDDDD42@SN6PR05MB5806.namprd05.prod.outlook.com>
On Tue, Aug 04, 2026 at 10:21:00PM +0300, Roi L wrote:
> When accessing the per-descriptor state structure, we could overflow
> desc_state[] because id can be accessed by the host and the guest
> at the same time, as described by the packed implementation.
it is validated:
id = vring_read_packed_desc_id(vq, last_used);
*len = vring_read_packed_desc_len(vq, last_used);
if (unlikely(id >= num)) {
BAD_RING(vq, "id %u out of range\n", id);
return NULL;
}
> 'commit 32fe1de5c124 ("virtio_ring: Add READ_ONCE annotations for device-writable fields")'
>
> The commit mentions these are legitimate races, so I assume id might
> get corrupted? "id" is actually just ""last_used"" in some contexts,
> and at the path where last_used gets manipulated, KCSAN reports these races.
>
> I'm not sure if this is the right approach though, maybe we should handle it
> differently other than just return?
>
> Signed-off-by: Roi L <roeilev321_@outlook.com>
I don't understand what all this means.
> ---
> drivers/virtio/virtio_ring.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
> index b438dc2ce1b8..1d99b75f3bd7 100644
> --- a/drivers/virtio/virtio_ring.c
> +++ b/drivers/virtio/virtio_ring.c
> @@ -2025,6 +2025,8 @@ static void detach_buf_packed_in_order(struct vring_virtqueue *vq,
> unsigned int i, curr;
>
> state = &vq->packed.desc_state[id];
> + if (unlikely(!state))
> + return;
I don't see how it can be null even if id is out of range.
> /* Clear data ptr. */
> state->data = NULL;
> --
> 2.55.0
prev parent reply other threads:[~2026-08-04 20:57 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-04 19:21 Roi L
2026-08-04 20:57 ` Michael S. Tsirkin [this message]
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=20260804165355-mutt-send-email-mst@kernel.org \
--to=mst@redhat.com \
--cc=eperezma@redhat.com \
--cc=jasowangio@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=roeilev321_@outlook.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®