Skip to contentSkip to conversation

ALSA: pcm_dmaengine: Run complete cb only if runtime check passes

PATCH In review Misael Lopez Cruz 2 participants 2 messages Jul 15, 2015

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

PATCH 1/1 ALSA: pcm_dmaengine: Run complete cb only if runtime check passes

The DMA complete callback uses substream's runtime data, so make sure the runtime check passes before going forward.

The callback could run while the stream is closing or after it's already closed. By then, the substream's runtime data might already been freed and cause NULL pointer dereferences.

---
 sound/core/pcm_dmaengine.c |    7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
sound/core/pcm_dmaengine.c +6 -1
index fba365a..061a8f7 100644
@@ -133,7 +133,12 @@ EXPORT_SYMBOL_GPL(snd_dmaengine_pcm_set_config_from_dai_data);
 static void dmaengine_pcm_dma_complete(void *arg)
 {
 	struct snd_pcm_substream *substream = arg;
-	struct dmaengine_pcm_runtime_data *prtd = substream_to_prtd(substream);
+	struct dmaengine_pcm_runtime_data *prtd;
+
+	if (PCM_RUNTIME_CHECK(substream))
+		return;
+
+	prtd = substream_to_prtd(substream);
 
 	prtd->pos += snd_pcm_lib_period_bytes(substream);
 	if (prtd->pos >= snd_pcm_lib_buffer_bytes(substream))
Signature · 1 line
1.7.9.5
#1 lore raw
Quoted 6 lines · Misael Lopez Cruz

The DMA complete callback uses substream's runtime data, so make sure the runtime check passes before going forward.

The callback could run while the stream is closing or after it's already closed. By then, the substream's runtime data might already been freed and cause NULL pointer dereferences.

If the callback runs after the stream has been closed that's a bug in the DMAengine driver. This patch does not fix the issue, the sub-stream itself might have been freed as well, so things will still crash.

To fix a potential race condition that can happen if one cpu is running the callback handlers and the stream is closed from another see this thread: http://www.spinics.net/lists/dmaengine/msg05126.html

- Lars

Quoted 26 lines
---
  sound/core/pcm_dmaengine.c |    7 ++++++-
  1 file changed, 6 insertions(+), 1 deletion(-)
sound/core/pcm_dmaengine.c +6 -1
index fba365a..061a8f7 100644
@@ -133,7 +133,12 @@ EXPORT_SYMBOL_GPL(snd_dmaengine_pcm_set_config_from_dai_data);
  static void dmaengine_pcm_dma_complete(void *arg)
  {
  	struct snd_pcm_substream *substream = arg;
-	struct dmaengine_pcm_runtime_data *prtd = substream_to_prtd(substream);
+	struct dmaengine_pcm_runtime_data *prtd;
+
+	if (PCM_RUNTIME_CHECK(substream))
+		return;
+
+	prtd = substream_to_prtd(substream);
 
  	prtd->pos += snd_pcm_lib_period_bytes(substream);
  	if (prtd->pos >= snd_pcm_lib_buffer_bytes(substream))