From: sashiko-bot@kernel.org
To: "Ilia Snezhkov" <iasnezhkov@gmail.com>
Cc: linux-sound@vger.kernel.org
Subject: Re: [PATCH] ASoC: mediatek: mtk-btcvsd: guard against 0xdeadfeed in btcvsd_tx_clean_buffer()
Date: Wed, 25 Nov 2026 23:56:37 +0000 [thread overview]
Message-ID: <sashiko-outbox-234420@kernel.org> (raw)
In-Reply-To: <20261125234830.94895-1-iasnezhkov@gmail.com>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] ASoC: mediatek: ineffective 0xdeadfeed check in
btcvsd_tx_clean_buffer()
- [Low] ASoC: mediatek: unrelated Fixes trailer d067b3378a78 in commit
message
--
commit ed1dbfaac1e6a9adfd651ed2d3dd40c2aaf8a20b
Author: Ilia Snezhkov <iasnezhkov@gmail.com>
> ASoC: mediatek: mtk-btcvsd: guard against 0xdeadfeed in btcvsd_tx_clean_buffer()
>
> 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@gmail.com>
[Severity: Low]
Should the second Fixes: tag for d067b3378a78 ("ASoC: mediatek: mtk-btcvsd:
Add checks for write and read of mtk_btcvsd_snd") be dropped? That commit
only changed mtk_pcm_btcvsd_copy() to propagate return values from
mtk_btcvsd_snd_write() and mtk_btcvsd_snd_read(), and did not touch
btcvsd_tx_clean_buffer() or 0xdeadfeed handling.
> diff --git a/sound/soc/mediatek/common/mtk-btcvsd.c b/sound/soc/mediatek/common/mtk-btcvsd.c
> index 19329dd7c0d75..1f525673c463b 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,
[Severity: Medium]
Can bt->tx->buffer_info.bt_sram_addr[i] ever equal 0xdeadfeed here?
mtk_btcvsd_write_to_bt() is the only place that populates bt_sram_addr[], and
it checks the raw 32-bit register value connsys_addr_tx against 0xdeadfeed
before storing the translated virtual address ap_addr_tx:
sound/soc/mediatek/common/mtk-btcvsd.c:mtk_btcvsd_write_to_bt() {
...
connsys_addr_tx = *bt->bt_reg_pkt_w;
ap_addr_tx = (unsigned long)bt->bt_sram_bank2_base +
(connsys_addr_tx & 0xFFFF);
if (connsys_addr_tx == 0xdeadfeed) {
/* bt return 0xdeadfeed if read register during bt sleep */
dev_warn(bt->dev, "%s(), connsys_addr_tx == 0xdeadfeed\n",
__func__);
return -EIO;
}
...
scoped_guard(spinlock_irqsave, &bt->tx_lock) {
bt->tx->buffer_info.num_valid_addr++;
next_idx = bt->tx->buffer_info.num_valid_addr - 1;
bt->tx->buffer_info.bt_sram_addr[next_idx] = ap_addr_tx;
}
...
}
Because bt_sram_addr[] caches previously computed virtual addresses
(bt_sram_bank2_base + (connsys_addr_tx & 0xFFFF)), an entry never holds
0xdeadfeed, and the cached entries do not change to 0xdeadfeed if BT connsys
enters sleep or resets before mtk_pcm_btcvsd_hw_free() ->
btcvsd_tx_clean_buffer() runs. As a result, btcvsd_tx_clean_buffer() will
still write mute frames to BT SRAM while BT connsys is asleep unless it
checks the live hardware register *bt->bt_reg_pkt_w == 0xdeadfeed.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261125234830.94895-1-iasnezhkov@gmail.com?part=1
prev parent reply other threads:[~2026-11-25 23:56 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 23:48 [PATCH] ASoC: mediatek: mtk-btcvsd: guard against 0xdeadfeed in btcvsd_tx_clean_buffer() Ilia Snezhkov via B4 Relay
2026-11-25 23:56 ` sashiko-bot [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-234420@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=iasnezhkov@gmail.com \
--cc=linux-sound@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox