From: sashiko-bot@kernel.org
To: "Takashi Iwai" <tiwai@suse.de>, linux-sound@vger.kernel.org
Subject: Re: [PATCH 1/2] ALSA: pcm: Cover buffer access gate in all read/write ioctls
Date: Wed, 25 Nov 2026 07:16:06 +0000 [thread overview]
Message-ID: <sashiko-outbox-232763@kernel.org> (raw)
In-Reply-To: <20261125065034.1470697-2-tiwai@suse.de>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] ALSA: pcm: missing writer() error check in __snd_pcm_lib_xfer()
- [High] ALSA: pcm: missing buffer_accessing gate in
__snd_pcm_lib_xfer() callers
--
commit a0ca0563533dec8be3f120c69e7d751e0b7fb94c
Author: Takashi Iwai <tiwai@suse.de>
ALSA: pcm: Cover buffer access gate in all read/write ioctls
This commit acquires the PCM buffer access gate in the native and compat
interleaved read/write ioctls and removes the inner
snd_pcm_buffer_access_get() and snd_pcm_buffer_access_put() calls from
__snd_pcm_lib_xfer().
> diff --git a/sound/core/pcm_lib.c b/sound/core/pcm_lib.c
> index 3b66677c037a6..50bd5f32d2f8d 100644
> --- a/sound/core/pcm_lib.c
> +++ b/sound/core/pcm_lib.c
> @@ -2377,9 +2377,6 @@ snd_pcm_sframes_t __snd_pcm_lib_xfer(struct snd_pcm_substream *substream,
> err = -EINVAL;
> goto _end_unlock;
> }
> - err = snd_pcm_buffer_access_get(runtime);
> - if (err < 0)
> - goto _end_unlock;
> snd_pcm_stream_unlock_irq(substream);
> if (!is_playback)
> snd_pcm_dma_buffer_sync(substream, SNDRV_DMA_SYNC_CPU);
> @@ -2388,9 +2385,6 @@ snd_pcm_sframes_t __snd_pcm_lib_xfer(struct snd_pcm_substream *substream,
> if (is_playback)
> snd_pcm_dma_buffer_sync(substream, SNDRV_DMA_SYNC_DEVICE);
> snd_pcm_stream_lock_irq(substream);
> - snd_pcm_buffer_access_put(runtime);
> - if (err < 0)
> - goto _end_unlock;
> err = pcm_accessible_state(substream);
> if (err < 0)
> goto _end_unlock;
[Severity: High]
Does removing "if (err < 0) goto _end_unlock;" here drop the error check
for writer()? Because err is immediately overwritten by
pcm_accessible_state(substream), a failure from writer() (such as -EFAULT
during user copy) is lost whenever the stream remains in an accessible
state, causing __snd_pcm_lib_xfer() to advance appl_ptr and report a
successful transfer.
[Severity: High]
Also, can dropping snd_pcm_buffer_access_get() and
snd_pcm_buffer_access_put() from __snd_pcm_lib_xfer() leave callers
outside pcm_native.c and pcm_compat.c with runtime->buffer_accessing at 0
while the stream lock is dropped?
Callers such as snd_pcm_oss_write3(), snd_pcm_oss_read3(),
snd_pcm_oss_writev3(), snd_pcm_oss_readv3(), and snd_pcm_oss_sync() in
sound/core/oss/pcm_oss.c, as well as u_audio_playback() ->
snd_pcm_kernel_write() in drivers/usb/gadget/function/u_uac1_legacy.c,
enter __snd_pcm_lib_xfer() without SND_PCM_BUFFER_ACQUIRE():
CPU0 CPU1
u_audio_playback()
snd_pcm_kernel_write()
__snd_pcm_lib_xfer()
snd_pcm_stream_unlock_irq()
snd_pcm_hw_free()
snd_pcm_buffer_access_lock()
snd_pcm_lib_free_pages()
writer()
... <-- use-after-free on runtime->dma_area
For OSS streams, a concurrent SNDCTL_DSP_RESET followed by prepare on the
same descriptor can similarly bypass snd_pcm_buffer_access_lock() while
writer() and snd_pcm_dma_buffer_sync() run unlocked.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261125065034.1470697-1-tiwai@suse.de?part=1
next prev parent reply other threads:[~2026-11-25 7:16 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 6:50 [PATCH 0/2] ALSA: pcm: Yet a couple of more fixes for 7.5 Takashi Iwai
2026-11-25 6:50 ` [PATCH 1/2] ALSA: pcm: Cover buffer access gate in all read/write ioctls Takashi Iwai
2026-11-25 7:16 ` sashiko-bot [this message]
2026-11-25 6:50 ` [PATCH 2/2] ALSA: pcm: Prevent PCM hw_params & co during mmap on OSS, too 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=sashiko-outbox-232763@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=tiwai@suse.de \
/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