* [PATCH 0/2] Bluetooth: btmtksdio: Fix SKB handling in the TX path
@ 2026-08-17 9:53 Chris Lu
2026-08-17 9:53 ` [PATCH 1/2] Bluetooth: btmtksdio: Take exclusive ownership of the SKB before TX Chris Lu
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Chris Lu @ 2026-08-17 9:53 UTC (permalink / raw)
To: Marcel Holtmann, Johan Hedberg, Luiz Von Dentz
Cc: Sean Wang, Will Lee, SS Wu, linux-bluetooth, linux-kernel,
linux-mediatek, Chris Lu
btmtksdio_tx_packet() rounds the SDIO transfer size up to the 256 byte
block size, but never grows the SKB accordingly, so the host controller
reads up to 255 bytes of uninitialised memory and sends it to the device,
and can read past the end of the buffer as well.
Patch 2 fixes that by padding the SKB with zeros. The padding is written
behind skb->tail, which is only safe once the driver owns the data
buffer, so patch 1 replaces the open-coded headroom check with
skb_cow_head() first. Patch 1 on its own changes no observable
behaviour, but it is a hard prerequisite, so both patches carry the same
Fixes: tag.
Both patches were previously part of a larger MT7928 series [1]. They
are unrelated to MT7928 and to the USB driver, so they are sent
separately here. The remaining parts of that series will follow as
separate topic branches.
Tested on a Chromebook with MT7921S: Bluetooth power on, then A2DP
connect and stream continuously for one hour without failure. The padding
added by patch 2 covers every packet whose length is not a multiple of
the block size, and the reallocation added by patch 1 covers every HCI
command, which hci_send_cmd_sync() always clones into hdev->sent_cmd.
[1] https://lore.kernel.org/linux-bluetooth/20260717072133.2858136-1-chris.lu@mediatek.com/
Chris Lu (2):
Bluetooth: btmtksdio: Take exclusive ownership of the SKB before TX
Bluetooth: btmtksdio: Fix out-of-bounds DMA read in the TX path
drivers/bluetooth/btmtksdio.c | 33 ++++++++++++++++++++++++---------
1 file changed, 24 insertions(+), 9 deletions(-)
--
2.45.2
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/2] Bluetooth: btmtksdio: Take exclusive ownership of the SKB before TX
2026-08-17 9:53 [PATCH 0/2] Bluetooth: btmtksdio: Fix SKB handling in the TX path Chris Lu
@ 2026-08-17 9:53 ` Chris Lu
2026-08-17 9:53 ` [PATCH 2/2] Bluetooth: btmtksdio: Fix out-of-bounds DMA read in the TX path Chris Lu
2026-08-17 19:45 ` [PATCH 0/2] Bluetooth: btmtksdio: Fix SKB handling " patchwork-bot+bluetooth
2 siblings, 0 replies; 4+ messages in thread
From: Chris Lu @ 2026-08-17 9:53 UTC (permalink / raw)
To: Marcel Holtmann, Johan Hedberg, Luiz Von Dentz
Cc: Sean Wang, Will Lee, SS Wu, linux-bluetooth, linux-kernel,
linux-mediatek, Chris Lu
btmtksdio_tx_packet() prepends the MediaTek SDIO header with skb_push()
and writes into that space after only checking the headroom size. On a
cloned SKB that headroom belongs to a buffer shared with the other owner,
which the driver has no right to write to.
Cloned SKBs do reach this path: hci_send_cmd_sync() keeps a clone of every
HCI command in hdev->sent_cmd before handing the SKB to the driver, and
l2cap_ertm_send() clones SKBs for retransmission.
Replace the open-coded headroom check with skb_cow_head(), which both
guarantees the headroom and reallocates a private buffer when the SKB is
cloned. The cost is one reallocation and copy per cloned packet, the usual
price of this pattern in network drivers.
This has no observable effect on its own, as the driver only writes in
front of skb->data where no other owner looks. It is a prerequisite for
"Bluetooth: btmtksdio: Fix out-of-bounds DMA read in the TX path", which
writes padding behind skb->tail, and carries the same Fixes: tag so that
both are backported together.
Fixes: 9aebfd4a2200 ("Bluetooth: mediatek: add support for MediaTek MT7663S and MT7668S SDIO devices")
Signed-off-by: Chris Lu <chris.lu@mediatek.com>
Assisted-by: Claude:claude-opus-5
---
drivers/bluetooth/btmtksdio.c | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)
diff --git a/drivers/bluetooth/btmtksdio.c b/drivers/bluetooth/btmtksdio.c
index 67d055d5f197..bcbbcf8ecc24 100644
--- a/drivers/bluetooth/btmtksdio.c
+++ b/drivers/bluetooth/btmtksdio.c
@@ -274,13 +274,12 @@ static int btmtksdio_tx_packet(struct btmtksdio_dev *bdev,
struct mtkbtsdio_hdr *sdio_hdr;
int err;
- /* Make sure that there are enough rooms for SDIO header */
- if (unlikely(skb_headroom(skb) < sizeof(*sdio_hdr))) {
- err = pskb_expand_head(skb, sizeof(*sdio_hdr), 0,
- GFP_ATOMIC);
- if (err < 0)
- return err;
- }
+ /* Make sure that the data buffer is not shared with anyone else and
+ * that there is enough room for the SDIO header
+ */
+ err = skb_cow_head(skb, sizeof(*sdio_hdr));
+ if (err < 0)
+ return err;
/* Prepend MediaTek SDIO Specific Header */
skb_push(skb, sizeof(*sdio_hdr));
--
2.45.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] Bluetooth: btmtksdio: Fix out-of-bounds DMA read in the TX path
2026-08-17 9:53 [PATCH 0/2] Bluetooth: btmtksdio: Fix SKB handling in the TX path Chris Lu
2026-08-17 9:53 ` [PATCH 1/2] Bluetooth: btmtksdio: Take exclusive ownership of the SKB before TX Chris Lu
@ 2026-08-17 9:53 ` Chris Lu
2026-08-17 19:45 ` [PATCH 0/2] Bluetooth: btmtksdio: Fix SKB handling " patchwork-bot+bluetooth
2 siblings, 0 replies; 4+ messages in thread
From: Chris Lu @ 2026-08-17 9:53 UTC (permalink / raw)
To: Marcel Holtmann, Johan Hedberg, Luiz Von Dentz
Cc: Sean Wang, Will Lee, SS Wu, linux-bluetooth, linux-kernel,
linux-mediatek, Chris Lu
btmtksdio_tx_packet() rounds the transfer size up to the SDIO block size
of 256 bytes, but hands the host controller the SKB buffer as is:
err = sdio_writesb(bdev->func, MTK_REG_CTDR, skb->data,
round_up(skb->len, MTK_SDIO_BLOCK_SIZE));
Only skb->len bytes hold packet data, so the controller reads up to 255
bytes of uninitialised memory and sends it to the device over the SDIO
bus. Depending on how much tailroom slack the SKB allocation happens to
carry, that read can also extend past the end of the buffer.
Compute the padded length up front, ensure the SKB has tailroom for it,
and zero-fill the padding with skb_put_zero(). skb->len then covers the
padding, so sdio_writesb() no longer needs to round up. byte_tx keeps
counting the header and the payload only, and the error path restores the
SKB so that the caller can requeue it.
Writing behind skb->tail is only safe because the driver owns the buffer,
which "Bluetooth: btmtksdio: Take exclusive ownership of the SKB before
TX" ensures.
Fixes: 9aebfd4a2200 ("Bluetooth: mediatek: add support for MediaTek MT7663S and MT7668S SDIO devices")
Signed-off-by: Chris Lu <chris.lu@mediatek.com>
Assisted-by: Claude:claude-opus-5
---
drivers/bluetooth/btmtksdio.c | 26 +++++++++++++++++++++-----
1 file changed, 21 insertions(+), 5 deletions(-)
diff --git a/drivers/bluetooth/btmtksdio.c b/drivers/bluetooth/btmtksdio.c
index bcbbcf8ecc24..b7f0be7fc42a 100644
--- a/drivers/bluetooth/btmtksdio.c
+++ b/drivers/bluetooth/btmtksdio.c
@@ -272,6 +272,7 @@ static int btmtksdio_tx_packet(struct btmtksdio_dev *bdev,
struct sk_buff *skb)
{
struct mtkbtsdio_hdr *sdio_hdr;
+ unsigned int len, pad_len;
int err;
/* Make sure that the data buffer is not shared with anyone else and
@@ -281,6 +282,18 @@ static int btmtksdio_tx_packet(struct btmtksdio_dev *bdev,
if (err < 0)
return err;
+ /* The transfer is rounded up to the SDIO block size, so the buffer
+ * has to provide tailroom for the padding as well
+ */
+ len = skb->len + sizeof(*sdio_hdr);
+ pad_len = round_up(len, MTK_SDIO_BLOCK_SIZE) - len;
+
+ if (unlikely(skb_tailroom(skb) < pad_len)) {
+ err = pskb_expand_head(skb, 0, pad_len, GFP_ATOMIC);
+ if (err < 0)
+ return err;
+ }
+
/* Prepend MediaTek SDIO Specific Header */
skb_push(skb, sizeof(*sdio_hdr));
@@ -289,19 +302,22 @@ static int btmtksdio_tx_packet(struct btmtksdio_dev *bdev,
sdio_hdr->reserved = cpu_to_le16(0);
sdio_hdr->bt_type = hci_skb_pkt_type(skb);
+ /* Zero the padding so that no uninitialised memory is sent out */
+ skb_put_zero(skb, pad_len);
+
clear_bit(BTMTKSDIO_HW_TX_READY, &bdev->tx_state);
- err = sdio_writesb(bdev->func, MTK_REG_CTDR, skb->data,
- round_up(skb->len, MTK_SDIO_BLOCK_SIZE));
+ err = sdio_writesb(bdev->func, MTK_REG_CTDR, skb->data, skb->len);
if (err < 0)
- goto err_skb_pull;
+ goto err_skb_restore;
- bdev->hdev->stat.byte_tx += skb->len;
+ bdev->hdev->stat.byte_tx += len;
kfree_skb(skb);
return 0;
-err_skb_pull:
+err_skb_restore:
+ skb_trim(skb, len);
skb_pull(skb, sizeof(*sdio_hdr));
return err;
--
2.45.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 0/2] Bluetooth: btmtksdio: Fix SKB handling in the TX path
2026-08-17 9:53 [PATCH 0/2] Bluetooth: btmtksdio: Fix SKB handling in the TX path Chris Lu
2026-08-17 9:53 ` [PATCH 1/2] Bluetooth: btmtksdio: Take exclusive ownership of the SKB before TX Chris Lu
2026-08-17 9:53 ` [PATCH 2/2] Bluetooth: btmtksdio: Fix out-of-bounds DMA read in the TX path Chris Lu
@ 2026-08-17 19:45 ` patchwork-bot+bluetooth
2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+bluetooth @ 2026-08-17 19:45 UTC (permalink / raw)
To: Chris Lu
Cc: marcel, johan.hedberg, luiz.dentz, sean.wang, will-cy.Lee, ss.wu,
linux-bluetooth, linux-kernel, linux-mediatek
Hello:
This series was applied to bluetooth/bluetooth-next.git (master)
by Luiz Augusto von Dentz <luiz.von.dentz@intel.com>:
On Mon, 17 Aug 2026 17:53:30 +0800 you wrote:
> btmtksdio_tx_packet() rounds the SDIO transfer size up to the 256 byte
> block size, but never grows the SKB accordingly, so the host controller
> reads up to 255 bytes of uninitialised memory and sends it to the device,
> and can read past the end of the buffer as well.
>
> Patch 2 fixes that by padding the SKB with zeros. The padding is written
> behind skb->tail, which is only safe once the driver owns the data
> buffer, so patch 1 replaces the open-coded headroom check with
> skb_cow_head() first. Patch 1 on its own changes no observable
> behaviour, but it is a hard prerequisite, so both patches carry the same
> Fixes: tag.
>
> [...]
Here is the summary with links:
- [1/2] Bluetooth: btmtksdio: Take exclusive ownership of the SKB before TX
https://git.kernel.org/bluetooth/bluetooth-next/c/951d9f743029
- [2/2] Bluetooth: btmtksdio: Fix out-of-bounds DMA read in the TX path
https://git.kernel.org/bluetooth/bluetooth-next/c/262cb784c96c
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-08-17 19:46 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-17 9:53 [PATCH 0/2] Bluetooth: btmtksdio: Fix SKB handling in the TX path Chris Lu
2026-08-17 9:53 ` [PATCH 1/2] Bluetooth: btmtksdio: Take exclusive ownership of the SKB before TX Chris Lu
2026-08-17 9:53 ` [PATCH 2/2] Bluetooth: btmtksdio: Fix out-of-bounds DMA read in the TX path Chris Lu
2026-08-17 19:45 ` [PATCH 0/2] Bluetooth: btmtksdio: Fix SKB handling " patchwork-bot+bluetooth
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox