Skip to contentSkip to conversation

ALSA: pcm: oss: Fix race at SNDCTL_DSP_SYNC

PATCH In review Zubin Mithra 3 participants 4 messages Oct 6, 2022 – Jan 10, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

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
index f88de74da1eb..de6f94bee50b 100644
@@ -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
maintainer
#1 lore raw
Quoted 22 lines · Zubin Mithra

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.

Quoted 6 lines

---
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.

Now queued up, thanks.

greg k-h

#2 lore raw
Quoted 30 lines · Greg KH
Quoted 22 lines · Zubin Mithra

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.

Quoted 6 lines

---
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.

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

maintainer
#3 lore raw
Quoted 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 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.

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