[PATCH] ASoC: mediatek: mtk-btcvsd: guard against 0xdeadfeed in btcvsd_tx_clean_buffer()

From: Ilia Snezhkov via B4 Relay

Date: Wed Nov 25 2026 - 18:48:52 EST


From: Ilia Snezhkov <iasnezhkov@xxxxxxxxx>

mtk_btcvsd_read_from_bt() and mtk_btcvsd_write_to_bt() both reject the
0xdeadfeed sentinel returned by the BT connsys SRAM pointer register
when BT SRAM is unpowered or resetting, and check the SRAM address
before dereferencing it. btcvsd_tx_clean_buffer(), however, casts each
stored bt_sram_addr[] entry straight to a pointer and writes mute frames
through mtk_btcvsd_snd_data_transfer() without checking for 0xdeadfeed
or NULL.

If an invalid or reset SRAM address is recorded or cleared concurrently
around hw_free / mute transitions, btcvsd_tx_clean_buffer() dereferences
an invalid address in atomic context under tx_lock.

Skip any bt_sram_addr[] slot holding 0xdeadfeed or 0 before transferring
mute data.

Found and drafted with an AI coding assistant while bringing up MT6789.

Fixes: 4bd8597dc36c ("ASoC: mediatek: add btcvsd driver")
Fixes: d067b3378a78 ("ASoC: mediatek: mtk-btcvsd: Add checks for write and read of mtk_btcvsd_snd")
Signed-off-by: Ilia Snezhkov <iasnezhkov@xxxxxxxxx>
---
sound/soc/mediatek/common/mtk-btcvsd.c | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/sound/soc/mediatek/common/mtk-btcvsd.c b/sound/soc/mediatek/common/mtk-btcvsd.c
index 19329dd..1f52567 100644
--- a/sound/soc/mediatek/common/mtk-btcvsd.c
+++ b/sound/soc/mediatek/common/mtk-btcvsd.c
@@ -341,6 +341,10 @@ static int btcvsd_tx_clean_buffer(struct mtk_btcvsd_snd *bt)
dev_info(bt->dev, "%s(), clean addr 0x%lx\n", __func__,
bt->tx->buffer_info.bt_sram_addr[i]);

+ if (bt->tx->buffer_info.bt_sram_addr[i] == 0xdeadfeed ||
+ !bt->tx->buffer_info.bt_sram_addr[i])
+ continue;
+
dst = (void *)bt->tx->buffer_info.bt_sram_addr[i];

mtk_btcvsd_snd_data_transfer(BT_SCO_DIRECT_ARM2BT,
--
2.54.0 (Apple Git-157)