Skip to content

Commit 8015ef9

Browse files
tiwaigregkh
authored andcommitted
ALSA: pcm: oss: Fix race at SNDCTL_DSP_SYNC
commit 8423f0b 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. 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 Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Takashi Iwai <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent ad5ef76 commit 8015ef9

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

sound/core/oss/pcm_oss.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1664,14 +1664,14 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
16641664
runtime = substream->runtime;
16651665
if (atomic_read(&substream->mmap_count))
16661666
goto __direct;
1667-
err = snd_pcm_oss_make_ready(substream);
1668-
if (err < 0)
1669-
return err;
16701667
atomic_inc(&runtime->oss.rw_ref);
16711668
if (mutex_lock_interruptible(&runtime->oss.params_lock)) {
16721669
atomic_dec(&runtime->oss.rw_ref);
16731670
return -ERESTARTSYS;
16741671
}
1672+
err = snd_pcm_oss_make_ready_locked(substream);
1673+
if (err < 0)
1674+
goto unlock;
16751675
format = snd_pcm_oss_format_from(runtime->oss.format);
16761676
width = snd_pcm_format_physical_width(format);
16771677
if (runtime->oss.buffer_used > 0) {

0 commit comments

Comments
 (0)