Skip to content

Commit 8423f0b

Browse files
committed
ALSA: pcm: oss: Fix race at SNDCTL_DSP_SYNC
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]>
1 parent 414d38b commit 8423f0b

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
@@ -1672,14 +1672,14 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
16721672
runtime = substream->runtime;
16731673
if (atomic_read(&substream->mmap_count))
16741674
goto __direct;
1675-
err = snd_pcm_oss_make_ready(substream);
1676-
if (err < 0)
1677-
return err;
16781675
atomic_inc(&runtime->oss.rw_ref);
16791676
if (mutex_lock_interruptible(&runtime->oss.params_lock)) {
16801677
atomic_dec(&runtime->oss.rw_ref);
16811678
return -ERESTARTSYS;
16821679
}
1680+
err = snd_pcm_oss_make_ready_locked(substream);
1681+
if (err < 0)
1682+
goto unlock;
16831683
format = snd_pcm_oss_format_from(runtime->oss.format);
16841684
width = snd_pcm_format_physical_width(format);
16851685
if (runtime->oss.buffer_used > 0) {

0 commit comments

Comments
 (0)