Linux virtualization list
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Yuho Choi" <oss.patchbox@gmail.com>
Cc: "Michael S. Tsirkin" <mst@redhat.com>,
	"Eugenio Perez" <eperezma@redhat.com>,
	virtualization@lists.linux.dev
Subject: Re: [PATCH v1] ALSA: virtio: reset device before deleting virtqueues
Date: Fri, 11 Sep 2026 03:24:24 +0000	[thread overview]
Message-ID: <20260911032424.A2B411F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260911031121.1542502-1-oss.patchbox@gmail.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

Pre-existing issues:
- [High] The driver permanently leaks DMA mappings for unused virtqueue buffers because they are not detached before virtqueue deletion.
- [High] Prematurely cancelling and freeing pending control messages before resetting the device leads to hardware Use-After-Free, list corruption, and double frees.
--

commit a186967d39bb57120371bc04edb4ff625893e99e
Author: Yuho Choi <oss.patchbox@gmail.com>

ALSA: virtio: reset device before deleting virtqueues

This commit moves virtio_reset_device() before del_vqs() in driver
remove and freeze paths. This prevents the hardware from accessing
virtqueue memory after it has been freed.

> diff --git a/sound/virtio/virtio_card.c b/sound/virtio/virtio_card.c
> index 647190f4d5afc..6f35276416fed 100644
> --- a/sound/virtio/virtio_card.c
> +++ b/sound/virtio/virtio_card.c
> @@ -354,8 +354,8 @@ static void virtsnd_remove(struct virtio_device *vdev)
>  	if (snd->card)
>  		snd_card_free(snd->card);
>  
> -	vdev->config->del_vqs(vdev);
>  	virtio_reset_device(vdev);
> +	vdev->config->del_vqs(vdev);

[Severity: High]
This is a pre-existing issue, but does this permanently leak DMA mappings for
unused virtqueue buffers because they are not detached before the virtqueues
are deleted?

System suspend/resume or driver unbinding will call virtsnd_freeze() or
virtsnd_remove(), which deletes the virtqueues without first detaching unused
buffers via virtqueue_detach_unused_buf().

Repeated suspend/resume cycles could continuously leak DMA mappings (such as
pending event buffers and PCM buffers) until the DMA space is exhausted.

>  
>  	for (i = 0; snd->substreams && i < snd->nsubstreams; ++i) {
>  		struct virtio_pcm_substream *vss = &snd->substreams[i];

[ ... ]

> @@ -383,8 +383,8 @@ static int virtsnd_freeze(struct virtio_device *vdev)
>  	virtsnd_disable_event_vq(snd);
>  	virtsnd_ctl_msg_cancel_all(snd);

[Severity: High]
This is a pre-existing issue, but does prematurely cancelling and freeing
pending control messages here (and similarly in virtsnd_remove) before
resetting the device leave a window where the hardware can DMA to freed
memory?

For messages sent with nowait = true, virtsnd_ctl_msg_cancel_all() drops the
refcount to 0, immediately freeing the memory while the message is still
actively queued in the hardware virtqueue.

The device could then DMA write into the freed memory, or trigger an
interrupt where virtsnd_ctl_notify_cb() retrieves the freed pointer and calls
virtsnd_ctl_msg_complete() on it again, causing a double free.

>  
> -	vdev->config->del_vqs(vdev);
>  	virtio_reset_device(vdev);
> +	vdev->config->del_vqs(vdev);
>  
>  	for (i = 0; i < snd->nsubstreams; ++i)
>  		cancel_work_sync(&snd->substreams[i].elapsed_period);

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260911031121.1542502-1-oss.patchbox@gmail.com?part=1

  reply	other threads:[~2026-09-11  3:24 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-11  3:11 [PATCH v1] ALSA: virtio: reset device before deleting virtqueues Yuho Choi
2026-09-11  3:24 ` sashiko-bot [this message]
2026-09-13  7:12 ` Takashi Iwai

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=20260911032424.A2B411F000FF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=eperezma@redhat.com \
    --cc=mst@redhat.com \
    --cc=oss.patchbox@gmail.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