* [PATCH v2] ALSA: pcm_oss: reject buffer reconfiguration while the stream is mmapped
@ 2026-11-18 13:19 Dmitriy Chumachenko
2026-11-18 13:47 ` Takashi Iwai
0 siblings, 1 reply; 2+ messages in thread
From: Dmitriy Chumachenko @ 2026-11-18 13:19 UTC (permalink / raw)
To: Jaroslav Kysela
Cc: Takashi Iwai, Greg Kroah-Hartman, Sasha Levin,
Oswald Buddenhagen, Mehul Rao, Ji'an Zhou, Norbert Szetei,
alsa-devel, linux-kernel, lvc-project, Dmitriy Chumachenko
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@cyberprotect.ru>
---
v2: Fix the root cause in the OSS layer instead of silencing the core
warning. v1 dropped the WARN_ON_ONCE() in snd_pcm_mmap_data_fault();
v2 refuses to reconfigure (and free) the buffer while a data mapping
is active, which is what left dma_area NULL.
sound/core/oss/pcm_oss.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
index 2dbc27831eb3..4ce9ecaa6ab1 100644
--- a/sound/core/oss/pcm_oss.c
+++ b/sound/core/oss/pcm_oss.c
@@ -861,6 +861,8 @@ static int snd_pcm_oss_change_params_locked(struct snd_pcm_substream *substream)
if (!runtime->oss.params)
return 0;
+ if (atomic_read(&substream->mmap_count))
+ return -EBADFD;
sw_params = kzalloc_obj(*sw_params);
params = kmalloc_obj(*params);
sparams = kmalloc_obj(*sparams);
--
2.49.0
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH v2] ALSA: pcm_oss: reject buffer reconfiguration while the stream is mmapped
2026-11-18 13:19 [PATCH v2] ALSA: pcm_oss: reject buffer reconfiguration while the stream is mmapped Dmitriy Chumachenko
@ 2026-11-18 13:47 ` Takashi Iwai
0 siblings, 0 replies; 2+ messages in thread
From: Takashi Iwai @ 2026-11-18 13:47 UTC (permalink / raw)
To: Dmitriy Chumachenko
Cc: Jaroslav Kysela, Takashi Iwai, Greg Kroah-Hartman, Sasha Levin,
Oswald Buddenhagen, Mehul Rao, Ji'an Zhou, Norbert Szetei,
alsa-devel, linux-kernel, lvc-project
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@cyberprotect.ru>
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-18 13:47 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-18 13:19 [PATCH v2] ALSA: pcm_oss: reject buffer reconfiguration while the stream is mmapped Dmitriy Chumachenko
2026-11-18 13:47 ` Takashi Iwai
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®