[PATCH] ASoC: intel: atom: SST: sync the DSP threaded IRQ against the PCM close path (uaf of sst_runtime_stream and snd_pcm_runtime)
From: Hanxiang Xu
Date: Tue Dec 01 2026 - 21:43:50 EST
The SST PCM close path frees the platform sst_runtime_stream
(sst_media_close()) and the snd_pcm_runtime
(snd_pcm_detach_substream()) without any barrier against the DSP
threaded IRQ handler. process_fw_async_msg() gates the slot callback
only on STREAM_INIT, so a message processed while sst_free_stream()
has already switched the slot to STREAM_UN_INIT - but not yet cleared
period_elapsed/pcm_substream, which happens only after the
FREE_STREAM firmware round trip returns - still fires
sst_period_elapsed() on objects the close path frees right under it.
The suspend paths already use synchronize_irq(ctx->irq_num) for the
same purpose; the close path never does, and neither the component
.sync_stop nor card->sync_irq exists for this hardware.
Gate the PERIOD_ELAPSED handler on STREAM_RUNNING, drain the threaded
IRQ in sst_close_pcm_stream(), and clear
substream->runtime->private_data before kfree(stream).
Also reproduced on 7.4.0-rc5: 68 slab-use-after-free reports in
sst_period_elapsed()/sst_get_stream_status() with a KASAN kernel
(negative control clean).
Cc: <stable@xxxxxxxxxxxxxxx>
Signed-off-by: Hanxiang Xu <xuhx@xxxxxxxxxxx>
---
3 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/sound/soc/intel/atom/sst-mfld-platform-pcm.c b/sound/soc/intel/atom/sst-mfld-platform-pcm.c
index 8c0e4c1..b280132 100644
--- a/sound/soc/intel/atom/sst-mfld-platform-pcm.c
+++ b/sound/soc/intel/atom/sst-mfld-platform-pcm.c
@@ -362,6 +362,7 @@
if (str_id)
stream->ops->close(sst->dev, str_id);
module_put(sst->dev->driver->owner);
+ substream->runtime->private_data = NULL;
kfree(stream);
}
diff --git a/sound/soc/intel/atom/sst/sst_drv_interface.c b/sound/soc/intel/atom/sst/sst_drv_interface.c
index 2646c46..612f59c 100644
--- a/sound/soc/intel/atom/sst/sst_drv_interface.c
+++ b/sound/soc/intel/atom/sst/sst_drv_interface.c
@@ -443,6 +443,7 @@
stream->status = STREAM_UN_INIT;
stream->period_elapsed = NULL;
ctx->stream_cnt--;
+ synchronize_irq(ctx->irq_num);
if (retval)
dev_err(ctx->dev, "free stream returned err %d\n", retval);
diff --git a/sound/soc/intel/atom/sst/sst_ipc.c b/sound/soc/intel/atom/sst/sst_ipc.c
index 6c19ab6..77dff41 100644
--- a/sound/soc/intel/atom/sst/sst_ipc.c
+++ b/sound/soc/intel/atom/sst/sst_ipc.c
@@ -268,8 +268,9 @@
"Period elapsed rcvd for pipe id 0x%x\n",
pipe_id);
stream = &sst_drv_ctx->streams[str_id];
- /* If stream is dropped, skip processing this message*/
- if (stream->status == STREAM_INIT)
+ /* Only a running stream owns valid slot callbacks; STREAM_INIT
+ * (dropped) and STREAM_UN_INIT (closed) must not fire them */
+ if (stream->status != STREAM_RUNNING)
break;
if (stream->period_elapsed)
stream->period_elapsed(stream->pcm_substream);
--
2.43.0