The SST PCM close path (sst_media_close() -> sst_close_pcm_stream() -> free_stream_context()) tears down the DSP stream slot and frees the platform-private struct sst_runtime_stream, and snd_pcm_detach_substream() then frees the snd_pcm_runtime -- but nothing ever synchronizes the DSP threaded IRQ handler that consumes the slot's callbacks with no lock in common with the close path. process_fw_async_msg() gates only on STREAM_INIT (deliberately not on STREAM_UN_INIT, which is the state sst_free_stream() leaves behind while the slot's period_elapsed / pcm_substream pointers are still populated), so a firmware IPC_SST_PERIOD_ELAPSED_MRFLD that is in flight or processed while the close path runs makes the real sst_period_elapsed() dereference the freed runtime->private_data and spin_lock() the freed stream->status_lock. The close path also never clears runtime->private_data before kfree(stream). Neither the suspend paths' synchronize_irq(ctx->irq_num) (intel_sst_ runtime_suspend/suspend, sst.c) nor the core's snd_pcm_sync_stop() mechanism covers this: the component driver implements neither .sync_stop nor a card->sync_irq, so both fallbacks of snd_pcm_sync_stop() (pcm_native.c) are inert for this hardware. Verified on mainline 7.3 with a KASAN kernel, QEMU/KVM x86_64 guest and a harness that probes the real "sst-mfld-platform" driver through a plain platform_device, registers a record-and-delay DSP via the exported sst_register_dsp(), brings up the real ASoC card (real media-cpu-dai, real sst_media_open/prepare/close, real ASoC trigger path) and plays the role of the DSP periodic IPC by re-invoking the captured REAL sst_period_elapsed() pointer across userspace close(). 65 slab-use-after-free reports, all inside sst_period_elapsed() and its sst_get_stream_status() spin_lock_irqsave() on the freed stream->status_lock, with Freed = kfree <- snd_soc_dai_shutdown(<- sst_media_close inlined) <- soc_pcm_clean <- soc_pcm_close <- snd_pcm_release_substream; the negative control (same sequence with the DSP-simulation thread stopped) is completely clean. Requires Baytrail/Cherrytrail-class SST hardware plus its firmware on production systems; the firmware sends IPC_SST_PERIOD_ELAPSED_MRFLD once per audio period, so the in-flight probability grows with the period rate. The detailed description: * Test environment / affected version Linux version 7.3.0 (gcc 13.3.0, GNU ld 2.42) #1 SMP PREEMPT_DYNAMIC -- vanilla mainline 7.3 tree, unmodified sources, KASAN enabled, QEMU/KVM x86_64 guest, CONFIG_SND_SOC=y with CONFIG_SND_SST_ATOM_HIFI2_PLATFORM=m. The audited files (sound/soc/intel/atom/*) are byte-identical between the tested tree and the report baseline; line numbers below are from 7.3. * Mechanism Two contexts, no common lock: - close path (process context, pcm->open_mutex only): snd_pcm_release_substream() -> snd_pcm_drop() -> trigger STOP -> sst_soc_trigger() -> sst_stream_drop() -> sst_drop_stream() (slot status = STREAM_INIT, which gates the IRQ handler), then sst_media_close() -> sst_close_pcm_stream(): free_stream_context() -> sst_free_stream() sets status = STREAM_UN_INIT (sst_stream.c:449) -- NOT skipped by the IRQ gate at sst_ipc.c:272 -- and blocks on the FREE_STREAM firmware round-trip; only after that returns does sst_close_pcm_stream() clear the slot's pcm_substream / period_elapsed (sst_drv_interface.c:442-444). The "UN_INIT set, pointers not yet cleared" window therefore spans a firmware IPC round trip (milliseconds). kfree(stream) (sst-mfld-platform-pcm.c:360) and kfree(runtime) (snd_pcm_detach_substream, pcm.c:1001) follow immediately. - threaded IRQ (its own kernel thread): intel_sst_irq_thread_mrfld() drops rx_msg_lock and calls sst_process_reply_mrfld() -> process_fw_async_msg() (sst_ipc.c:247): the gate at sst_ipc.c:272 only skips STREAM_INIT, then unconditionally calls stream->period_elapsed(stream->pcm_substream) (sst_ipc.c:274-275) -> sst_period_elapsed() (sst-mfld-platform-pcm.c:242) reads substream->runtime->private_data and sst_get_stream_status() spin_lock_irqsave()s the freed stream->status_lock, and snd_pcm_period_elapsed() walks the freed runtime. The core's snd_pcm_sync_stop() infrastructure (pcm_native.c:666) would have covered this, but both of its sources are absent here: snd_soc_component_driver.sync_stop is not implemented by sst_soc_platform_drv (so soc-pcm.c:3098 never wires rtd->ops.sync_stop), and card->sync_irq stays at its -1 default (init.c:334). The suspend paths show the authors' own intent to synchronize (synchronize_irq at sst.c:418 and sst.c:455), the close path simply never does. * Trigger model Any user with an open, RUNNING SST PCM stream (firmware sends IPC_SST_PERIOD_ELAPSED_MRFLD once per period) calling close() on the fd. No privileges beyond owning the fd. The race windows are (a) the microseconds between the IRQ handler passing its status gate and touching the platform objects, overlapped with the frees, and (b) the millisecond-wide "UN_INIT set, pointers not yet cleared" window inside sst_free_stream()'s firmware round trip. Consequence: slab use-after-free reads/writes (spin_lock on freed lock word, freed-runtime traversal in snd_pcm_period_elapsed), kernel oops / memory corruption. * Reproducer and results on 7.3 (also reproduced on 7.4-rc5) sstrace.c registers the REAL "sst-mfld-platform" driver through a plain platform_device (real probe, real component/DAI registration, real dpcm_strm_map), registers a record-and-delay DSP via the exported sst_register_dsp() (the snd-intel-sst-core module itself cannot run without LPE audio hardware), brings up the real ASoC card (snd_soc_register_card with the real media-cpu-dai), and a harness kthread re-invokes the REAL sst_period_elapsed() pointer captured at stream_init -- exactly the pointer the DSP slot holds -- across the userspace close(). Every UAF site hit is genuine in-tree code (sst_period_elapsed, sst_get_stream_status's status_lock, snd_pcm_detach_substream). awe_test.c drives open->hw_params->prepare->START->sleep->close cycles at 48k/2ch (SST media DAI constraints). # build (needs CONFIG_SND_SOC=y + the SST platform driver) make -C M=$PWD modules # guest (root): insmod snd-soc-sst-atom-hifi2-platform.ko insmod sstrace.ko PCMDEV=/dev/snd/pcmC0D0p ./awe_test cycle 200 100 Results: 65 slab-use-after-free reports, all with "in sst_period_elapsed+0x59" and the status_lock spin_lock_irqsave/unlock_irqrestore pair, Freed = kfree <- snd_soc_dai_shutdown <- soc_pcm_clean <- soc_pcm_close <- snd_pcm_release_substream. Negative control (identical sequence, DSP-simulation thread stopped before the close loop): 0 reports. Full logs available on request; excerpts in the evidence files referenced by the cover documentation. * Fix Three self-contained changes: 1. sst_close_pcm_stream(): synchronize_irq(ctx->irq_num) after the slot teardown, before the caller frees the platform objects -- the same barrier the suspend paths already use. 2. process_fw_async_msg(): tighten the PERIOD_ELAPSED gate from "skip STREAM_INIT" to "skip anything that is not STREAM_RUNNING" -- a stopped or freed slot has no business firing the callback. 3. sst_media_close(): clear substream->runtime->private_data before kfree(stream). Happy to test any counter-proposal. * Patch [PATCH] ASoC: intel: atom: SST: sync the DSP threaded IRQ against the PCM close path The SST PCM close path frees the platform sst_runtime_stream and the snd_pcm_runtime without any barrier against the DSP threaded IRQ handler: process_fw_async_msg() gates the slot callbacks only on STREAM_INIT, so messages processed while sst_free_stream() has already switched the slot to STREAM_UN_INIT (but not yet cleared period_elapsed/pcm_substream -- that happens only after the FREE_STREAM firmware round trip returns) still fire sst_period_elapsed() on objects the close path frees right under it. Neither the component's .sync_stop nor card->sync_irq exists for this hardware, so the core's snd_pcm_sync_stop() fallbacks are inert, and the close path never clears runtime->private_data before kfree(stream). Close the gap with the same barrier the suspend paths already use: - sst_close_pcm_stream(): synchronize_irq(ctx->irq_num) after the slot teardown; - process_fw_async_msg(): only fire the callback for a STREAM_RUNNING slot (covers both STREAM_INIT and the freed-slot STREAM_UN_INIT state); - sst_media_close(): clear substream->runtime->private_data before kfree(stream). Reported-by style note: found by static race auditing with dynamic verification (KASAN, QEMU/KVM, 65/65 reports inside sst_period_elapsed on the unpatched kernel, negative control clean). Signed-off-by: Hangxiang Xu --- a/sound/soc/intel/atom/sst-mfld-platform-pcm.c +++ b/sound/soc/intel/atom/sst-mfld-platform-pcm.c @@ -357,6 +357,10 @@ if (str_id) stream->ops->close(sst->dev, str_id); module_put(sst->dev->driver->owner); + substream->runtime->private_data = NULL; kfree(stream); } --- a/sound/soc/intel/atom/sst/sst_drv_interface.c +++ b/sound/soc/intel/atom/sst/sst_drv_interface.c @@ -443,6 +443,10 @@ 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); --- a/sound/soc/intel/atom/sst/sst_ipc.c +++ b/sound/soc/intel/atom/sst/sst_ipc.c @@ -268,8 +268,10 @@ "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) + /* Skip anything that is not running: STREAM_INIT (dropped) + * and STREAM_UN_INIT (freed by the close path) both leave + * stale or dangling slot contents behind */ + if (stream->status != STREAM_RUNNING) break; if (stream->period_elapsed) stream->period_elapsed(stream->pcm_substream); Please keep me in Cc; I am not subscribed to the lists. Regards, Hanxiang Xu xuhx@hust.edu.cn