[PATCH 1/3] ALSA: pcm: Remove is_oss_stream() bypass of mmap_count check
From: Ahmed Abdelmoemen
Date: Wed Dec 02 2026 - 09:01:50 EST
hw_params_state_check() skips the mmap_count guard for OSS streams via
the is_oss_stream() condition. This lets hw_params run while userspace
holds a live VM_PFNMAP mapping obtained through /dev/dsp.
remap_pfn_range() mappings (VM_PFNMAP) carry no page reference counts,
so the kernel cannot revoke them when hw_params reconfigures or
reallocates the DMA buffer. The buffer can be cleared or freed while
userspace retains read/write access to it.
Removing the bypass restores the intended safety invariant: an OSS
caller holding a mapping gets -EBADFD on reconfiguration, the same as a
native PCM stream. Reconfiguring the buffer under an active mapping is
never safe regardless of stream type.
Fixes: 92ee3c60ec9f ("ALSA: pcm: Fix races among concurrent hw_params and hw_free calls")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Ahmed Abdelmoemen <ahmedabdelmoumen05@xxxxxxxxx>
---
sound/core/pcm_native.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
index 897975e43..d77045aba 100644
--- a/sound/core/pcm_native.c
+++ b/sound/core/pcm_native.c
@@ -784,8 +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) &&
- atomic_read(&substream->mmap_count))
+ if (check_mmap && atomic_read(&substream->mmap_count))
return -EBADFD;
return 0;
default:
--
2.43.0