* [PATCH 1/2] ALSA: pcm: Cover buffer access gate in all read/write ioctls
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 ` Takashi Iwai
2026-11-25 7:16 ` sashiko-bot
2026-11-25 6:50 ` [PATCH 2/2] ALSA: pcm: Prevent PCM hw_params & co during mmap on OSS, too Takashi Iwai
1 sibling, 1 reply; 4+ messages in thread
From: Takashi Iwai @ 2026-11-25 6:50 UTC (permalink / raw)
To: linux-sound
We haven't applied the buffer access gate in interleaved read/write
because it doesn't involve with the runtime attribute access before
the actual snd_pcm_lib_read/write calls. However, there can be a
slight race during those ioctls between the PCM state check and
read/write calls, which may trigger a kernel WARNING() for the NULL
runtime->dma_area check in pcm_sanity_check().
For addressing it, in this patch, all read/write ioctls are assured to
take the buffer access get via SND_PCM_BUFFER_ACQUIRE() call for
avoiding the unexpected PCM state change during the whole operation.
Meanwhile, this change makes the snd_pcm_buffer_access_get() and
_put() calls in __snd_pcm_lib_xfer() (which is the main body of
pcm_lib_read() and pcm_lib_write()) superfluous, so those are dropped,
too.
Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
sound/core/pcm_compat.c | 3 +++
sound/core/pcm_lib.c | 6 ------
sound/core/pcm_native.c | 3 +++
3 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
index c5931fdfe1f5..924fd269dace 100644
--- a/sound/core/pcm_compat.c
+++ b/sound/core/pcm_compat.c
@@ -293,6 +293,9 @@ static int snd_pcm_ioctl_xferi_compat(struct snd_pcm_substream *substream,
return -ENOTTY;
if (substream->stream != dir)
return -EINVAL;
+ SND_PCM_BUFFER_ACQUIRE(substream->runtime, lock);
+ if (SND_PCM_BUFFER_ACQUIRE_ERR(lock))
+ return -EBUSY;
if (snd_pcm_get_state(substream) == SNDRV_PCM_STATE_OPEN)
return -EBADFD;
diff --git a/sound/core/pcm_lib.c b/sound/core/pcm_lib.c
index 3b66677c037a..50bd5f32d2f8 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;
diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
index 897975e43a9b..9e4a82d4ee82 100644
--- a/sound/core/pcm_native.c
+++ b/sound/core/pcm_native.c
@@ -3418,6 +3418,9 @@ static int snd_pcm_xferi_frames_ioctl(struct snd_pcm_substream *substream,
struct snd_xferi xferi;
snd_pcm_sframes_t result;
+ SND_PCM_BUFFER_ACQUIRE(substream->runtime, lock);
+ if (SND_PCM_BUFFER_ACQUIRE_ERR(lock))
+ return -EBUSY;
if (snd_pcm_get_state(substream) == SNDRV_PCM_STATE_OPEN)
return -EBADFD;
if (put_user(0, &_xferi->result))
--
2.53.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] ALSA: pcm: Prevent PCM hw_params & co during mmap on OSS, too
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 6:50 ` Takashi Iwai
1 sibling, 0 replies; 4+ messages in thread
From: Takashi Iwai @ 2026-11-25 6:50 UTC (permalink / raw)
To: linux-sound
In the OSS emulation mode, we allowed the PCM hw_params, hw_refine and
hw_free even when the buffer is mmapped as an exception. This is
supposed to be a workaround for some old applications, but this
exception is rather harmful as the mmapped pages can be invalidated by
the concurrent hw_free and hw_params.
As the need of OSS emulation with mmap must be very very low (almost
negligible) now, let's remove the exception and prohibits the PCM
parameter changes during the mmap just like the normal ALSA
applications, too.
Link: https://lore.kernel.org/20261118131945.27592-1-Dmitry.Chumachenko@cyberprotect.ru
Cc: Dmitriy Chumachenko <Dmitry.Chumachenko@cyberprotect.ru>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
sound/core/pcm_native.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
index 9e4a82d4ee82..01abf09ec017 100644
--- a/sound/core/pcm_native.c
+++ b/sound/core/pcm_native.c
@@ -784,7 +784,7 @@ static int hw_params_state_check(struct snd_pcm_substream *substream,
case SNDRV_PCM_STATE_OPEN:
case SNDRV_PCM_STATE_SETUP:
case SNDRV_PCM_STATE_PREPARED:
- if (check_mmap && !is_oss_stream(substream) &&
+ if (check_mmap &&
atomic_read(&substream->mmap_count))
return -EBADFD;
return 0;
--
2.53.0
^ permalink raw reply related [flat|nested] 4+ messages in thread