From: Takashi Iwai <tiwai@suse.de>
To: linux-sound@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH 3/4] ALSA: pcm: Protect delay DMA sync in forward and rewind, too
Date: Tue, 13 Oct 2026 14:05:24 +0200 [thread overview]
Message-ID: <20261013120528.52586-4-tiwai@suse.de> (raw)
In-Reply-To: <20261013120528.52586-1-tiwai@suse.de>
Like the previous fix for snd_pcm_delay() (in the commit 50f413b83b31
"ALSA: pcm: Protect delay DMA sync against concurrent HW_FREE"), the
snd_pcm_dma_buffer_sync() call in snd_pcm_forward() and
snd_pcm_rewind() needs the similar protection against the concurrent
hw_free action for avoiding potential UAFs.
Fixes: a25684a95646 ("ALSA: memalloc: Support for non-contiguous page allocation")
Reported-by: Sashiko <sashiko-bot@kernel.org>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
sound/core/pcm_native.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
index f774358629bb..c1bad92a4e9f 100644
--- a/sound/core/pcm_native.c
+++ b/sound/core/pcm_native.c
@@ -3078,11 +3078,15 @@ static snd_pcm_sframes_t rewind_appl_ptr(struct snd_pcm_substream *substream,
static snd_pcm_sframes_t snd_pcm_rewind(struct snd_pcm_substream *substream,
snd_pcm_uframes_t frames)
{
+ struct snd_pcm_runtime *runtime = substream->runtime;
snd_pcm_sframes_t ret;
if (frames == 0)
return 0;
+ /* Keep the DMA buffer alive through the sync below. */
+ if (!atomic_inc_unless_negative(&runtime->buffer_accessing))
+ return -EBUSY;
scoped_guard(pcm_stream_lock_irq, substream) {
ret = do_pcm_hwsync(substream);
if (!ret)
@@ -3091,17 +3095,22 @@ static snd_pcm_sframes_t snd_pcm_rewind(struct snd_pcm_substream *substream,
}
if (ret >= 0)
snd_pcm_dma_buffer_sync(substream, SNDRV_DMA_SYNC_DEVICE);
+ atomic_dec(&runtime->buffer_accessing);
return ret;
}
static snd_pcm_sframes_t snd_pcm_forward(struct snd_pcm_substream *substream,
snd_pcm_uframes_t frames)
{
+ struct snd_pcm_runtime *runtime = substream->runtime;
snd_pcm_sframes_t ret;
if (frames == 0)
return 0;
+ /* Keep the DMA buffer alive through the sync below. */
+ if (!atomic_inc_unless_negative(&runtime->buffer_accessing))
+ return -EBUSY;
scoped_guard(pcm_stream_lock_irq, substream) {
ret = do_pcm_hwsync(substream);
if (!ret)
@@ -3110,6 +3119,7 @@ static snd_pcm_sframes_t snd_pcm_forward(struct snd_pcm_substream *substream,
}
if (ret >= 0)
snd_pcm_dma_buffer_sync(substream, SNDRV_DMA_SYNC_DEVICE);
+ atomic_dec(&runtime->buffer_accessing);
return ret;
}
--
2.55.0
next prev parent reply other threads:[~2026-10-13 12:05 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-13 12:05 [PATCH 0/4] ALSA: yet more fixes for Sashiko bug reports Takashi Iwai
2026-10-13 12:05 ` [PATCH 1/4] ALSA: jack: Fix kctl free at error in snd_jack_kctl_new() Takashi Iwai
2026-10-13 12:05 ` [PATCH 2/4] ALSA: usb-audio: Use fixed control index for us16x08 mixer elements Takashi Iwai
2026-10-14 6:13 ` Takashi Iwai
2026-10-13 12:05 ` Takashi Iwai [this message]
2026-10-13 12:05 ` [PATCH 4/4] ALSA: line6: Use kzalloc() for PCM buffer allocation 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=20261013120528.52586-4-tiwai@suse.de \
--to=tiwai@suse.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
/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®