From: "Michael S. Tsirkin" <mst@redhat.com>
To: zhangjiao2 <zhangjiao2@cmss.chinamobile.com>
Cc: eperezma@redhat.com, jasowangio@gmail.com,
xuanzhuo@linux.alibaba.com, graf@amazon.com,
linux-kernel@vger.kernel.org, trivial@kernel.org
Subject: Re: [PATCH] virtio_ring: Initialize id field in packed indirect descriptors
Date: Mon, 2 Nov 2026 12:51:12 -0500 [thread overview]
Message-ID: <20261102124927-mutt-send-email-mst@kernel.org> (raw)
In-Reply-To: <20261029072511.851-1-zhangjiao2@cmss.chinamobile.com>
On Thu, Oct 29, 2026 at 03:25:10PM +0800, zhangjiao2 wrote:
> From: zhang jiao <zhangjiao2@cmss.chinamobile.com>
>
> The virtqueue_add_indirect_packed() function fills an indirect
> descriptor table with addr, len, and flags for each entry, but does
> not initialize the id field of struct vring_packed_desc. The table is
> allocated via kmalloc() (not kzalloc) and then DMA-mapped with
> DMA_TO_DEVICE, making the uninitialized 2-byte id field of each
> descriptor readable by the device.
>
> This leaks kernel heap memory to the device for every packed indirect
> descriptor entry. A malicious or compromised device could extract heap
> contents by reading the id fields from the DMA-mapped indirect
> descriptor tables. This affects all virtio devices that use packed
> virtqueues with indirect descriptors, which is the common configuration
> for modern virtio devices.
>
> Fix this by explicitly initializing desc[i].id to zero in the
> descriptor filling loop. The id field is unused in indirect descriptor
> table entries per the virtio specification (only the head descriptor in
> the main ring uses id for buffer identification), so setting it to zero
> is semantically correct.
>
> This matches the split ring path where all four fields of struct
> vring_desc (addr, len, flags, next) are explicitly written in
> virtqueue_add_desc_split().
>
> Signed-off-by: zhang jiao <zhangjiao2@cmss.chinamobile.com>
This is defnitely not trivial material.
Pls report to the proper list in the future.
> ---
> drivers/virtio/virtio_ring.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
> index 5c169fbb418a..42883b01fab0 100644
> --- a/drivers/virtio/virtio_ring.c
> +++ b/drivers/virtio/virtio_ring.c
> @@ -1571,6 +1571,11 @@ static int virtqueue_add_indirect_packed(struct vring_virtqueue *vq,
> 0 : VRING_DESC_F_WRITE);
> desc[i].addr = cpu_to_le64(addr);
> desc[i].len = cpu_to_le32(len);
> + /* The id field is unused in indirect descriptors but
> + * must be initialized to prevent leaking kernel heap
> + * memory to the device through the DMA-mapped table.
> + */
> + desc[i].id = 0;
>
> if (unlikely(vq->use_map_api)) {
> extra[i].addr = premapped ? DMA_MAPPING_ERROR : addr;
> --
> 2.33.0
>
>
prev parent reply other threads:[~2026-11-02 17:51 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-29 7:25 zhangjiao2
2026-11-02 17:51 ` 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=20261102124927-mutt-send-email-mst@kernel.org \
--to=mst@redhat.com \
--cc=eperezma@redhat.com \
--cc=graf@amazon.com \
--cc=jasowangio@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=trivial@kernel.org \
--cc=xuanzhuo@linux.alibaba.com \
--cc=zhangjiao2@cmss.chinamobile.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®