ASoC: intel: atom: SST: log the byte-stream message header before handing it to the dispatch queue (UAF)
From: 徐晗翔
Date: Tue Dec 01 2026 - 07:22:56 EST
sst_send_byte_stream_mrfld() (sound/soc/intel/atom/sst/sst_stream.c)
hands its struct ipc_post to the dispatch queue with
sst_add_to_dispatch_list_and_post() and then keeps dereferencing its
local msg pointer in a dev_dbg() -- but ownership was transferred at
hand-off: sst_post_message_mrfld() unconditionally kfree()s the message
it dequeues (sst_ipc.c:174-175), and it does so synchronously on the
hand-off call when the IPCX register is free. With dynamic debug
enabled for this callsite (or any build where dev_dbg evaluates its
arguments), every byte-control/mixer parameter write to the SST DSP is
a use-after-free read of the freed header. When the IPCX register is
busy the message stays queued and is freed by the done-interrupt
workqueue (sst_process_pending_msg, sst.c:193) or a concurrent sender,
so the read races that free instead.
The sibling constructor sst_prepare_and_post_msg() (sst_pvt.c) logs the
same header *before* posting -- this callsite is the odd one out.
Verified statically against mainline 7.3 (the audited file is
byte-identical to the tested tree, also exists in 7.4 rc5): the ownership transfer, the
kfree-after-unlock at sst_ipc.c:173-175 in both the free-busy and
free-idle paths, and the post-hand-off dev_dbg at sst_stream.c:204-205.
No dynamic reproducer is attached: reaching this code requires LPE
audio (Merrifield/Baytrail/Cherrytrail) hardware with the SST firmware
running, which QEMU cannot emulate; every mixer/byte-control .put of
the SST driver funnels through sst_fill_and_send_cmd() ->
sst_send_byte_stream() -> this function, so the read triggers on
routine volume/mute/parameter changes once the debug callsite is
enabled (echo 'file sst_stream.c line 204 +p' >
/sys/kernel/debug/dynamic_debug/control). Impact is an
information-disclosure-flavored UAF read (4 bytes of a freed slab
object printed to the log; KASAN/KFENCE report it as
slab-use-after-free), not a write primitive.
The detailed description:
* Test environment / affected version (still exist in 7.4 rc5)
Analysis against Linux 7.3.0 (vanilla mainline tree; the audited
file sound/soc/intel/atom/sst/sst_stream.c is byte-identical between
the analysis tree and 7.3). The pattern predates 7.3; line numbers
below are from 7.3. Dynamic reproduction requires Merrifield/
Baytrail/Cherrytrail SST hardware, which the reporting environment
cannot provide; the defect and fix are purely source-level.
* Mechanism
- sst_add_to_dispatch_list_and_post() (sst_pvt.c:362-371) appends
msg to sst->ipc_dispatch_list under ipc_spin_lock, releases it and
calls sst->ops->post_message(sst, NULL, false);
- sst_post_message_mrfld() (sst_ipc.c:116-177): when the IPCX busy
bit is clear it dequeues the message (list_del at :158), posts it,
releases ipc_spin_lock (:173) and kfree()s msg->mailbox_data and
msg (:174-175) before returning -- so after
sst_add_to_dispatch_list_and_post() returns, the caller's msg
pointer is already dangling;
- when the busy bit is set the message stays queued (:149-153) and
is freed later by sst_process_pending_msg() (queued by the
done-interrupt at sst.c:73) or by any concurrent sender, racing
the caller's read;
- sst_send_byte_stream_mrfld() (sst_stream.c:203-205) nonetheless
evaluates msg->mrfld_header.p.header_low_payload after the
hand-off.
* Trigger model
Any SST mixer/byte-control write (volume, mute, DSP parameters --
all funnel through sst_fill_and_send_cmd() at
sound/soc/intel/atom/sst-atom-controls.c) with the dynamic-debug
callsite enabled, or a kernel built with DEBUG. No special
privileges beyond access to the sound card device nodes. KASAN
classifies it as slab-use-after-free (read).
* Fix (full patch below)
Log the header before the hand-off (matching what
sst_prepare_and_post_msg() already does at sst_pvt.c:218-219) and
never touch msg after sst_add_to_dispatch_list_and_post(). The
patch is written against 7.4 rc5.
* Patch
--- a/sound/soc/intel/atom/sst/sst_stream.c
+++ b/sound/soc/intel/atom/sst/sst_stream.c
@@ -200,9 +200,12 @@
}
}
- sst_add_to_dispatch_list_and_post(sst_drv_ctx, msg);
dev_dbg(sst_drv_ctx->dev, "msg->mrfld_header.p.header_low_payload:%d",
msg->mrfld_header.p.header_low_payload);
+ sst_add_to_dispatch_list_and_post(sst_drv_ctx, msg);
if (bytes_block) {
ret = sst_wait_timeout(sst_drv_ctx, block);
Please keep me in Cc; I am not subscribed to the lists.
Regards,
Hanxiang Xu
xuhx@xxxxxxxxxxx