Re: [PATCH v2] ALSA: pcm_oss: reject buffer reconfiguration while the stream is mmapped
From: Takashi Iwai
Date: Wed Nov 18 2026 - 08:47:15 EST
On Wed, 18 Nov 2026 14:19:45 +0100,
Dmitriy Chumachenko wrote:
>
> During fuzz testing, the following issue was discovered.
>
> WARNING: CPU: 2 PID: 1734 at sound/core/pcm_native.c:3835
> snd_pcm_mmap_data_fault+0x47f/0x530 sound/core/pcm_native.c:3835
>
> Modules linked in:
> CPU: 2 PID: 1734 Comm: syz.1.352 Not tainted 6.1.187-syzkaller-00593-g063a81552262 #0
> RIP: 0010:snd_pcm_mmap_data_fault+0x47f/0x530 sound/core/pcm_native.c:3835
>
> Call Trace:
> <TASK>
> __do_fault+0x10d/0x480 mm/memory.c:4280
> do_cow_fault mm/memory.c:4661 [inline]
> do_fault+0xa7a/0x1100 mm/memory.c:4762
> handle_pte_fault mm/memory.c:5031 [inline]
> __handle_mm_fault+0xdf3/0x2e40 mm/memory.c:5173
> handle_mm_fault+0x2da/0xa60 mm/memory.c:5294
> do_user_addr_fault+0x4aa/0x1050 arch/x86/mm/fault.c:1338
> handle_page_fault arch/x86/mm/fault.c:1429 [inline]
> exc_page_fault+0x98/0x1b0 arch/x86/mm/fault.c:1482
> asm_exc_page_fault+0x22/0x30 arch/x86/include/asm/idtentry.h:608
>
> snd_pcm_oss_change_params() frees and reallocates the substream buffer,
> and several OSS entry points reach it while the data area may already be
> mmapped: snd_pcm_oss_mmap() and the SNDCTL_DSP_GETOSPACE/GETISPACE ioctls
> (snd_pcm_oss_get_space()).
>
> For OSS streams snd_pcm_hw_params() skips the mmap_count guard
> (!is_oss_stream), so the buffer is torn down under a live mapping. If the
> reallocation then fails, the substream is left with runtime->dma_area ==
> NULL, and the next page fault on the stale mapping reaches
> snd_pcm_mmap_data_fault() with no buffer, hitting the WARN_ON_ONCE().
>
> Reject the reconfiguration in snd_pcm_oss_change_params_locked() when the
> stream is already mmapped; this covers all callers (read/write already
> bail out earlier on a non-zero mmap_count). The core WARN_ON_ONCE() is
> left in place.
>
> Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
> Signed-off-by: Dmitriy Chumachenko <Dmitry.Chumachenko@xxxxxxxxxxxxxxx>
Well, if we want to restrict the hw_params with mmap completely, it's
easier just drop the exception for OSS in the PCM core, instead:
--- a/sound/core/pcm_native.c
+++ b/sound/core/pcm_native.c
@@ -778,7 +778,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;
But, there must be some reason for this explicitly allowance for OSS
(maybe some apps like the old game need it), and the above (and your)
change would break it.
So, if we really want to guarantee the compatibility for old existing
applications, we need some other ways to check the buffer reallocation
instead (e.g. disallow the buffer byte size change). Though, I'm not
sure whether it's worth...
thanks,
Takashi