From: Ilia Snezhkov via B4 Relay <devnull+iasnezhkov.gmail.com@kernel.org>
To: broonie@kernel.org, lgirdwood@gmail.com
Cc: perex@perex.cz, tiwai@suse.com, matthias.bgg@gmail.com,
angelogioacchino.delregno@collabora.com,
linux-sound@vger.kernel.org, linux-mediatek@lists.infradead.org,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org
Subject: [PATCH v2 2/2] ASoC: mediatek: mtk-btcvsd: bound bt_sram_addr[] writes in mtk_btcvsd_write_to_bt()
Date: Thu, 26 Nov 2026 00:53:16 +0000 [thread overview]
Message-ID: <20261126005314.71606-3-iasnezhkov@gmail.com> (raw)
In-Reply-To: <20261126005314.71606-1-iasnezhkov@gmail.com>
From: Ilia Snezhkov <iasnezhkov@gmail.com>
bt->tx->buffer_info.bt_sram_addr[] has a fixed capacity of 20 entries,
but mtk_btcvsd_write_to_bt() unconditionally increments num_valid_addr
and writes bt_sram_addr[next_idx] whenever a new SRAM offset is seen.
If more than 20 distinct SRAM offsets are ever observed (for instance
during BT subsystem resets or corrupted register reads), this writes
out of bounds past bt_sram_addr[19] into adjacent fields of
struct mtk_btcvsd_snd_hw_info and surrounding memory.
Check next_idx against ARRAY_SIZE(bt->tx->buffer_info.bt_sram_addr)
under tx_lock before storing the address and advancing num_valid_addr.
Found and drafted with an AI coding assistant while bringing up MT6789.
Fixes: 4bd8597dc36c ("ASoC: mediatek: add btcvsd driver")
Signed-off-by: Ilia Snezhkov <iasnezhkov@gmail.com>
---
sound/soc/mediatek/common/mtk-btcvsd.c | 19 +++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)
diff --git a/sound/soc/mediatek/common/mtk-btcvsd.c b/sound/soc/mediatek/common/mtk-btcvsd.c
index 752856a..362d608 100644
--- a/sound/soc/mediatek/common/mtk-btcvsd.c
+++ b/sound/soc/mediatek/common/mtk-btcvsd.c
@@ -466,15 +466,22 @@ static int mtk_btcvsd_write_to_bt(struct mtk_btcvsd_snd *bt,
}
if (new_ap_addr_tx) {
unsigned int next_idx;
+ bool stored = false;
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;
+ next_idx = bt->tx->buffer_info.num_valid_addr;
+ if (next_idx < ARRAY_SIZE(bt->tx->buffer_info.bt_sram_addr)) {
+ bt->tx->buffer_info.bt_sram_addr[next_idx] = ap_addr_tx;
+ bt->tx->buffer_info.num_valid_addr = next_idx + 1;
+ stored = true;
+ }
}
- dev_info(bt->dev, "%s(), new ap_addr_tx = 0x%lx, num_valid_addr %d\n",
- __func__, ap_addr_tx,
- bt->tx->buffer_info.num_valid_addr);
+ if (stored)
+ dev_info(bt->dev, "%s(), new ap_addr_tx = 0x%lx, num_valid_addr %u\n",
+ __func__, ap_addr_tx, next_idx + 1);
+ else
+ dev_warn_once(bt->dev, "%s(), bt_sram_addr table full\n",
+ __func__);
}
if (bt->tx->mute)
--
2.54.0 (Apple Git-157)
prev parent reply other threads:[~2026-11-26 0:53 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-26 0:53 [PATCH v2 0/2] ASoC: mediatek: mtk-btcvsd: fix 0xdeadfeed check and bt_sram_addr bounds Ilia Snezhkov via B4 Relay
2026-11-26 0:53 ` [PATCH v2 1/2] ASoC: mediatek: mtk-btcvsd: check bt_reg_pkt_w for 0xdeadfeed in btcvsd_tx_clean_buffer() Ilia Snezhkov via B4 Relay
2026-11-26 0:53 ` Ilia Snezhkov via B4 Relay [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=20261126005314.71606-3-iasnezhkov@gmail.com \
--to=devnull+iasnezhkov.gmail.com@kernel.org \
--cc=angelogioacchino.delregno@collabora.com \
--cc=broonie@kernel.org \
--cc=iasnezhkov@gmail.com \
--cc=lgirdwood@gmail.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=linux-sound@vger.kernel.org \
--cc=matthias.bgg@gmail.com \
--cc=perex@perex.cz \
--cc=tiwai@suse.com \
/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
all inboxes | Powered by JetHome®