Skip to content

Commit

Permalink
ALSA: pcm: Fix stream lock usage in snd_pcm_period_elapsed()
Browse files Browse the repository at this point in the history
If the nullity check for `substream->runtime` is outside of the lock
region, it is possible to have a null runtime in the critical section
if snd_pcm_detach_substream is called right before the lock.

Signed-off-by: paulhsia <paulhsia@chromium.org>
Link: https://lore.kernel.org/r/20191112171715.128727-2-paulhsia@chromium.org
Signed-off-by: Takashi Iwai <tiwai@suse.de>
  • Loading branch information
paulhsia authored and Takashi Iwai committed Nov 13, 2019
1 parent 5286993 commit f5cdc9d
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions sound/core/pcm_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -1782,11 +1782,14 @@ void snd_pcm_period_elapsed(struct snd_pcm_substream *substream)
struct snd_pcm_runtime *runtime;
unsigned long flags;

if (PCM_RUNTIME_CHECK(substream))
if (snd_BUG_ON(!substream))
return;
runtime = substream->runtime;

snd_pcm_stream_lock_irqsave(substream, flags);
if (PCM_RUNTIME_CHECK(substream))
goto _unlock;
runtime = substream->runtime;

if (!snd_pcm_running(substream) ||
snd_pcm_update_hw_ptr0(substream, 1) < 0)
goto _end;
Expand All @@ -1797,6 +1800,7 @@ void snd_pcm_period_elapsed(struct snd_pcm_substream *substream)
#endif
_end:
kill_fasync(&runtime->fasync, SIGIO, POLL_IN);
_unlock:
snd_pcm_stream_unlock_irqrestore(substream, flags);
}
EXPORT_SYMBOL(snd_pcm_period_elapsed);
Expand Down

0 comments on commit f5cdc9d

Please sign in to comment.