Commit 6c8fcc83 authored by paulhsia's avatar paulhsia Committed by Kleber Sacilotto de Souza

ALSA: pcm: Fix stream lock usage in snd_pcm_period_elapsed()

BugLink: https://bugs.launchpad.net/bugs/1858489

[ Upstream commit f5cdc9d4 ]

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: default avatarpaulhsia <paulhsia@chromium.org>
Link: https://lore.kernel.org/r/20191112171715.128727-2-paulhsia@chromium.orgSigned-off-by: default avatarTakashi Iwai <tiwai@suse.de>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
Signed-off-by: default avatarConnor Kuehl <connor.kuehl@canonical.com>
Signed-off-by: default avatarKleber Sacilotto de Souza <kleber.souza@canonical.com>
parent 9451add4
...@@ -1877,11 +1877,14 @@ void snd_pcm_period_elapsed(struct snd_pcm_substream *substream) ...@@ -1877,11 +1877,14 @@ void snd_pcm_period_elapsed(struct snd_pcm_substream *substream)
struct snd_pcm_runtime *runtime; struct snd_pcm_runtime *runtime;
unsigned long flags; unsigned long flags;
if (PCM_RUNTIME_CHECK(substream)) if (snd_BUG_ON(!substream))
return; return;
runtime = substream->runtime;
snd_pcm_stream_lock_irqsave(substream, flags); snd_pcm_stream_lock_irqsave(substream, flags);
if (PCM_RUNTIME_CHECK(substream))
goto _unlock;
runtime = substream->runtime;
if (!snd_pcm_running(substream) || if (!snd_pcm_running(substream) ||
snd_pcm_update_hw_ptr0(substream, 1) < 0) snd_pcm_update_hw_ptr0(substream, 1) < 0)
goto _end; goto _end;
...@@ -1892,6 +1895,7 @@ void snd_pcm_period_elapsed(struct snd_pcm_substream *substream) ...@@ -1892,6 +1895,7 @@ void snd_pcm_period_elapsed(struct snd_pcm_substream *substream)
#endif #endif
_end: _end:
kill_fasync(&runtime->fasync, SIGIO, POLL_IN); kill_fasync(&runtime->fasync, SIGIO, POLL_IN);
_unlock:
snd_pcm_stream_unlock_irqrestore(substream, flags); snd_pcm_stream_unlock_irqrestore(substream, flags);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment