Linux Sound subsystem development
 help / color / mirror / Atom feed
* [PATCH -next 1/2] ALSA: pcm: oss: Restore params flag after failed reconfiguration
@ 2026-11-16  6:48 Ye Weihua
  2026-11-16  6:48 ` [PATCH -next 2/2] ALSA: pcm: oss: Clear params flag only after successful setup Ye Weihua
  2026-11-16 15:31 ` [PATCH -next 1/2] ALSA: pcm: oss: Restore params flag after failed reconfiguration Takashi Iwai
  0 siblings, 2 replies; 3+ messages in thread
From: Ye Weihua @ 2026-11-16  6:48 UTC (permalink / raw)
  To: Takashi Iwai, Jaroslav Kysela; +Cc: linux-sound, stable, Ye Weihua

snd_pcm_runtime_buffer_set_silence() may fail with -EBUSY when a
concurrent PCM transfer is accessing the buffer.  The error path
releases runtime->oss.buffer and clears the plugins, but leaves
runtime->oss.params cleared as well.  A subsequent small read/write
then skips the reconfiguration and dereferences the released buffer:

  Unable to handle kernel NULL pointer dereference at virtual address
  0000000000000000
  pc : __arch_copy_from_user+0x78/0x23c
  lr : snd_pcm_oss_write+0x10c/0x340 [snd_pcm_oss]

Restore runtime->oss.params on the error path so that the next OSS
operation reconfigures and reallocates the buffer.

Fixes: 47c27c9c9c72 ("ALSA: pcm: Improve the fix for race of buffer access at PCM OSS layer")
Cc: stable@vger.kernel.org
Signed-off-by: Ye Weihua <yeweihua4@huawei.com>
---
 sound/core/oss/pcm_oss.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
index 2d99df900f76..29812b0d1318 100644
--- a/sound/core/oss/pcm_oss.c
+++ b/sound/core/oss/pcm_oss.c
@@ -1082,12 +1082,14 @@ static int snd_pcm_oss_change_params_locked(struct snd_pcm_substream *substream)
 
 	runtime->oss.period_frames = snd_pcm_alsa_frames(substream, oss_period_size);
 
 	err = 0;
 failure:
-	if (err)
+	if (err) {
+		runtime->oss.params = 1;
 		snd_pcm_oss_release_buffers(substream);
+	}
 	kfree(sw_params);
 	kfree(params);
 	kfree(sparams);
 	return err;
 }
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH -next 2/2] ALSA: pcm: oss: Clear params flag only after successful setup
  2026-11-16  6:48 [PATCH -next 1/2] ALSA: pcm: oss: Restore params flag after failed reconfiguration Ye Weihua
@ 2026-11-16  6:48 ` Ye Weihua
  2026-11-16 15:31 ` [PATCH -next 1/2] ALSA: pcm: oss: Restore params flag after failed reconfiguration Takashi Iwai
  1 sibling, 0 replies; 3+ messages in thread
From: Ye Weihua @ 2026-11-16  6:48 UTC (permalink / raw)
  To: Takashi Iwai, Jaroslav Kysela; +Cc: linux-sound, stable, Ye Weihua

runtime->oss.params is cleared before the initial silence setup has
completed, so the flag claims a complete configuration while the
buffer setup is still in progress.  The error path now restores the
flag, so this is not fatal, but clear it only after the whole
reconfiguration has succeeded.

Move the assignment after snd_pcm_runtime_buffer_set_silence().

Signed-off-by: Ye Weihua <yeweihua4@huawei.com>
---
 sound/core/oss/pcm_oss.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
index 29812b0d1318..2fc52fe2cb52 100644
--- a/sound/core/oss/pcm_oss.c
+++ b/sound/core/oss/pcm_oss.c
@@ -1071,16 +1071,16 @@ static int snd_pcm_oss_change_params_locked(struct snd_pcm_substream *substream)
 	if (!runtime->oss.buffer) {
 		err = -ENOMEM;
 		goto failure;
 	}
 
-	runtime->oss.params = 0;
 	runtime->oss.prepare = 1;
 	runtime->oss.buffer_used = 0;
 	err = snd_pcm_runtime_buffer_set_silence(runtime);
 	if (err < 0)
 		goto failure;
+	runtime->oss.params = 0;
 
 	runtime->oss.period_frames = snd_pcm_alsa_frames(substream, oss_period_size);
 
 	err = 0;
 failure:
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH -next 1/2] ALSA: pcm: oss: Restore params flag after failed reconfiguration
  2026-11-16  6:48 [PATCH -next 1/2] ALSA: pcm: oss: Restore params flag after failed reconfiguration Ye Weihua
  2026-11-16  6:48 ` [PATCH -next 2/2] ALSA: pcm: oss: Clear params flag only after successful setup Ye Weihua
@ 2026-11-16 15:31 ` Takashi Iwai
  1 sibling, 0 replies; 3+ messages in thread
From: Takashi Iwai @ 2026-11-16 15:31 UTC (permalink / raw)
  To: Ye Weihua; +Cc: Takashi Iwai, Jaroslav Kysela, linux-sound, stable

On Mon, 16 Nov 2026 07:48:49 +0100,
Ye Weihua wrote:
> 
> snd_pcm_runtime_buffer_set_silence() may fail with -EBUSY when a
> concurrent PCM transfer is accessing the buffer.  The error path
> releases runtime->oss.buffer and clears the plugins, but leaves
> runtime->oss.params cleared as well.  A subsequent small read/write
> then skips the reconfiguration and dereferences the released buffer:
> 
>   Unable to handle kernel NULL pointer dereference at virtual address
>   0000000000000000
>   pc : __arch_copy_from_user+0x78/0x23c
>   lr : snd_pcm_oss_write+0x10c/0x340 [snd_pcm_oss]
> 
> Restore runtime->oss.params on the error path so that the next OSS
> operation reconfigures and reallocates the buffer.
> 
> Fixes: 47c27c9c9c72 ("ALSA: pcm: Improve the fix for race of buffer access at PCM OSS layer")
> Cc: stable@vger.kernel.org
> Signed-off-by: Ye Weihua <yeweihua4@huawei.com>

Applied both patches now.  Thanks.


Takashi

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-16 15:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-16  6:48 [PATCH -next 1/2] ALSA: pcm: oss: Restore params flag after failed reconfiguration Ye Weihua
2026-11-16  6:48 ` [PATCH -next 2/2] ALSA: pcm: oss: Clear params flag only after successful setup Ye Weihua
2026-11-16 15:31 ` [PATCH -next 1/2] ALSA: pcm: oss: Restore params flag after failed reconfiguration Takashi Iwai

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox