From: sashiko-bot@kernel.org
To: "Joonho Lee" <mynameisjune111@gmail.com>, linux-sound@vger.kernel.org
Cc: virtualization@lists.linux.dev,
"Michael S. Tsirkin" <mst@redhat.com>,
"Eugenio Perez" <eperezma@redhat.com>
Subject: Re: [PATCH v19 07/12] ALSA: virtio: validate indirect capture appl_ptr accounting
Date: Fri, 06 Nov 2026 18:19:53 +0000 [thread overview]
Message-ID: <sashiko-outbox-202010@kernel.org> (raw)
In-Reply-To: <20261106161838.94308-8-mynameisjune111@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] ALSA: virtio: sub-byte frame truncation in
virtsnd_pcm_capture_ack_validate()
--
commit 6d8079ee9be8b0bc45d98d37834441cf9aa4b749
Author: Joonho Lee <mynameisjune111@gmail.com>
ALSA: virtio: validate indirect capture appl_ptr accounting
This commit retains references to PCM DMA pages (or uses a driver-owned
buffer on NOMMU), validates full-period capture responses, seeds the RX
ring once per prepare, and validates capture appl_ptr accounting before
invoking the indirect transfer helper.
> diff --git a/sound/virtio/virtio_pcm_ops.c b/sound/virtio/virtio_pcm_ops.c
> index 343700ec50476..6a8752997d092 100644
> --- a/sound/virtio/virtio_pcm_ops.c
> +++ b/sound/virtio/virtio_pcm_ops.c
[ ... ]
> @@ -599,6 +619,69 @@ struct virtsnd_pcm_transfer {
> int error;
> };
>
> +/* Caller holds @vss->lock and the PCM stream lock. */
> +static int virtsnd_pcm_capture_ack_validate(struct virtio_pcm_substream *vss,
> + struct snd_pcm_runtime *runtime,
> + bool *skip_transfer)
> +{
[ ... ]
> + /* The RX ring reserves its full size; only the excess is unread data. */
> + unread_bytes = (s64)rec->hw_ready + (s64)rec->sw_ready -
> + (s64)rec->sw_buffer_size;
> + if (unread_bytes < 0 || unread_bytes > (s64)hw_queue_size)
> + return -EPIPE;
> +
> + appl_bytes = frames_to_bytes(runtime, (snd_pcm_uframes_t)appl_diff);
> + if ((u64)appl_bytes > (u64)unread_bytes)
> + return -EPIPE;
> +
> + return 0;
> +}
[Severity: Medium]
Can frames_to_bytes() truncate sub-byte frame deltas here and let an
unaligned appl_ptr advance bypass validation?
virtsnd_pcm_hw_params() permits sub-byte frame formats such as 1-channel
SNDRV_PCM_FORMAT_IMA_ADPCM (4-bit frames, runtime->min_align == 2) when
the period size is a whole number of bytes. If userspace advances
appl_ptr by an odd number of frames via SNDRV_PCM_IOCTL_SYNC_PTR (for
example, 1 frame when unread_bytes is 0), frames_to_bytes() truncates
appl_bytes down, passing the unread_bytes check.
snd_pcm_indirect_capture_transfer() then sets rec->appl_ptr to the
unaligned appl_ptr while subtracting the truncated byte count from
rec->sw_ready, pushing appl_ptr past hw_ptr and permanently leaking
rec->sw_ready accounting so RX descriptors stop being requeued.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261106161838.94308-1-mynameisjune111@gmail.com?part=7
next prev parent reply other threads:[~2026-11-06 18:19 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-06 16:18 [PATCH v19 00/12] ALSA: virtio: fix capture accounting Joonho Lee
2026-11-06 16:18 ` [PATCH v19 01/12] ALSA: pcm: mark stop-threshold accesses for capture policy sampling Joonho Lee
2026-11-06 16:28 ` sashiko-bot
2026-11-06 16:18 ` [PATCH v19 02/12] ALSA: pcm: report partial progress under the stream lock Joonho Lee
2026-11-06 16:30 ` sashiko-bot
2026-11-06 16:18 ` [PATCH v19 03/12] ALSA: pcm: add an optional reset operation " Joonho Lee
2026-11-06 16:35 ` sashiko-bot
2026-11-06 16:18 ` [PATCH v19 04/12] ALSA: virtio: Propagate PCM send failures through ACK Joonho Lee
2026-11-06 17:01 ` sashiko-bot
2026-11-06 16:18 ` [PATCH v19 05/12] ALSA: virtio: Recover PCM state after a failed start Joonho Lee
2026-11-06 17:26 ` sashiko-bot
2026-11-06 16:18 ` [PATCH v19 06/12] ALSA: virtio: Retain queued messages through device reset Joonho Lee
2026-11-06 17:48 ` sashiko-bot
2026-11-06 16:18 ` [PATCH v19 07/12] ALSA: virtio: validate indirect capture appl_ptr accounting Joonho Lee
2026-11-06 18:19 ` sashiko-bot [this message]
2026-11-06 16:18 ` [PATCH v19 08/12] ALSA: virtio: Keep control payloads alive through DMA completion Joonho Lee
2026-11-06 18:29 ` sashiko-bot
2026-11-06 16:18 ` [PATCH v19 09/12] ALSA: virtio: wait through signals for PCM teardown Joonho Lee
2026-11-06 18:45 ` sashiko-bot
2026-11-06 16:18 ` [PATCH v19 10/12] ALSA: virtio: serialize staged capture lifecycle and defer paused XRUNs Joonho Lee
2026-11-06 19:01 ` sashiko-bot
2026-11-06 16:18 ` [PATCH v19 11/12] ALSA: virtio: prioritize staged capture period work Joonho Lee
2026-11-06 19:04 ` sashiko-bot
2026-11-06 16:18 ` [PATCH v19 12/12] docs: describe virtio-sound capture options Joonho Lee
2026-11-06 19:14 ` sashiko-bot
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-202010@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=eperezma@redhat.com \
--cc=linux-sound@vger.kernel.org \
--cc=mst@redhat.com \
--cc=mynameisjune111@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 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.