ALSA: pcm: oss: Fix race at SNDCTL_DSP_SYNC
Subsystems (2)
PATCH 1/1 ALSA: pcm: oss: Fix race at SNDCTL_DSP_SYNC
From: Takashi Iwai <[email protected]>
commit 8423f0b6d513b259fdab9c9bf4aaa6188d054c2d upstream.
There is a small race window at snd_pcm_oss_sync() that is called from OSS PCM SNDCTL_DSP_SYNC ioctl; namely the function calls snd_pcm_oss_make_ready() at first, then takes the params_lock mutex for the rest. When the stream is set up again by another thread between them, it leads to inconsistency, and may result in unexpected results such as NULL dereference of OSS buffer as a fuzzer spotted recently.
The fix is simply to cover snd_pcm_oss_make_ready() call into the same params_lock mutex with snd_pcm_oss_make_ready_locked() variant.
---
Note:
* 8423f0b6d513 is present in linux-5.15.y and linux-5.4.y; missing in linux-5.10.y.
* Backport addresses conflict due to surrounding context.
* Tests run: build and boot.
sound/core/oss/pcm_oss.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
sound/core/oss/pcm_oss.c +3 -2
@@ -1662,13 +1662,14 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file) runtime = substream->runtime;if (atomic_read (&substream->mmap_count)) goto __direct; -if ((err =snd_pcm_oss_make_ready (substream)) <0 ) -return err;atomic_inc (&runtime->oss.rw_ref);if (mutex_lock_interruptible (&runtime->oss.params_lock)) {atomic_dec (&runtime->oss.rw_ref);return -ERESTARTSYS ; } + err =snd_pcm_oss_make_ready_locked (substream); +if (err <0 ) + goto unlock; format =snd_pcm_oss_format_from (runtime->oss.format); width =snd_pcm_format_physical_width (format);if (runtime->oss.buffer_used >0 ) {
Signature · 1 line
2.38.0.rc1.362.ged0d419d3c-goog
Greg KH
maintainerQuoted 22 lines · Zubin Mithra
From: Takashi Iwai <[email protected]>
commit
8423f0b6d513b259fdab9c9bf4aaa6188d054c2dupstream.There is a small race window at
snd_pcm_oss_sync()that is called from OSS PCMSNDCTL_DSP_SYNCioctl; namely the function callssnd_pcm_oss_make_ready()at first, then takes theparams_lockmutex for the rest. When the stream is set up again by another thread between them, it leads to inconsistency, and may result in unexpected results such as NULL dereference of OSS buffer as a fuzzer spotted recently.The fix is simply to cover
snd_pcm_oss_make_ready()call into the sameparams_lockmutex withsnd_pcm_oss_make_ready_locked()variant.Reported-and-tested-by butt3rflyh4ck <[email protected]>Reviewed-by Jaroslav Kysela <[email protected]>Cc <[email protected]>Link https://lore.kernel.org/r/CAFcO6XN7JDM4xSXGhtusQfS2mSBcx50VJKwQpCq=WeLt57aaZA@mail.gmail.com open hereSigned-off-by Takashi Iwai <[email protected]>Signed-off-by Zubin Mithra <[email protected]>
Quoted 6 lines
---
Note:
*8423f0b6d513is present in linux-5.15.y and linux-5.4.y; missing in linux-5.10.y.
* Backport addresses conflict due to surrounding context.
* Tests run: build and boot.
Now queued up, thanks.
greg k-h
Quoted 30 lines · Greg KH
Quoted 22 lines · Zubin Mithra
From: Takashi Iwai <[email protected]>
commit
8423f0b6d513b259fdab9c9bf4aaa6188d054c2dupstream.There is a small race window at
snd_pcm_oss_sync()that is called from OSS PCMSNDCTL_DSP_SYNCioctl; namely the function callssnd_pcm_oss_make_ready()at first, then takes theparams_lockmutex for the rest. When the stream is set up again by another thread between them, it leads to inconsistency, and may result in unexpected results such as NULL dereference of OSS buffer as a fuzzer spotted recently.The fix is simply to cover
snd_pcm_oss_make_ready()call into the sameparams_lockmutex withsnd_pcm_oss_make_ready_locked()variant.Reported-and-tested-by butt3rflyh4ck <[email protected]>Reviewed-by Jaroslav Kysela <[email protected]>Cc <[email protected]>Link https://lore.kernel.org/r/CAFcO6XN7JDM4xSXGhtusQfS2mSBcx50VJKwQpCq=WeLt57aaZA@mail.gmail.com open hereSigned-off-by Takashi Iwai <[email protected]>Signed-off-by Zubin Mithra <[email protected]>Quoted 6 lines
---
Note:
*8423f0b6d513is present in linux-5.15.y and linux-5.4.y; missing in linux-5.10.y.
* Backport addresses conflict due to surrounding context.
* Tests run: build and boot.
Quoted 3 lines
Now queued up, thanks.
greg k-h
This patch applies cleanly on 4.14 LTS as well. Can we have this patch in 4.14? I have tested for build and boot. Thanks
Greg KH
maintainerQuoted 33 lines · On Tue, Jan 10, 2023 at 01:40:59PM +0530, [email protected] wrote:
Quoted 30 lines · Greg KH
Quoted 28 lines · Zubin Mithra
From: Takashi Iwai <[email protected]>
commit
8423f0b6d513b259fdab9c9bf4aaa6188d054c2dupstream.There is a small race window at
snd_pcm_oss_sync()that is called from OSS PCMSNDCTL_DSP_SYNCioctl; namely the function callssnd_pcm_oss_make_ready()at first, then takes theparams_lockmutex for the rest. When the stream is set up again by another thread between them, it leads to inconsistency, and may result in unexpected results such as NULL dereference of OSS buffer as a fuzzer spotted recently.The fix is simply to cover
snd_pcm_oss_make_ready()call into the sameparams_lockmutex withsnd_pcm_oss_make_ready_locked()variant.Reported-and-tested-by butt3rflyh4ck <[email protected]>Reviewed-by Jaroslav Kysela <[email protected]>Cc <[email protected]>Link https://lore.kernel.org/r/CAFcO6XN7JDM4xSXGhtusQfS2mSBcx50VJKwQpCq=WeLt57aaZA@mail.gmail.com open hereSigned-off-by Takashi Iwai <[email protected]>Signed-off-by Zubin Mithra <[email protected]>---
Note:
*8423f0b6d513is present in linux-5.15.y and linux-5.4.y; missing in linux-5.10.y.
* Backport addresses conflict due to surrounding context.
* Tests run: build and boot.
Quoted 6 lines
Quoted 3 lines
Now queued up, thanks.
greg k-h
This patch applies cleanly on 4.14 LTS as well. Can we have this patch in 4.14? I have tested for build and boot.
Can you provide a working patch for this for 4.14.y and 4.19.y that you have tested the sound works properly with this patch applied? Booting doesn't invoke sound usually :)
thanks,
greg k-h