Skip to contentSkip to conversation

Bluetooth: btmtk: firmware debug event routing and WMT FUNC_CTRL status fixes

PATCH In review Chris Lu 3 participants 6 messages Sep 14

Subsystems (3)
lore
Share & tools
lore

Chris Lu

author
#0 lore raw

v2 cover Bluetooth: btmtk: firmware debug event routing and WMT FUNC_CTRL status fixes

This series bundles three independent MediaTek Bluetooth driver fixes:

Patch 1 is a resend of a fix submitted on 25 Aug 2026 ("Bluetooth: btmtk: Route firmware debug event to the diag channel") that received no review feedback at the time.

Patches 2-3 fix how btmtk_usb_hci_wmt_sync() (and its btmtksdio.c / btmtkuart.c counterparts) interpret a WMT FUNC_CTRL event that carries only the WMT header and no trailing 2-byte status word. Such an event is a normal firmware ack for a plain enable/disable request, with the result carried in the header's own flag byte, not a failure as the current code assumes:

- Patch 2 fixes this for btmtk.c, where a bounds check already existed (added by e3ac0d9f1a20) but defaulted to the wrong result.
- Patch 3 applies the same fix to btmtksdio.c and btmtkuart.c, which never had a bounds check for this event at all and read 2 bytes past the end of the received SKB whenever firmware sent the short form. While there, it also adds the missing base WMT header length check that btmtk.c already has (skb_pull_data() before touching wmt_evt->whdr.op), since these two files were unconditionally dereferencing that field with no length validation at all.

Changes since v1:
- Patch 1: review asked whether the exact match on the ACL handle (0x2efd) could miss a continuation fragment (0x1efd) if the firmware debug event ever spans multiple ACL packets. Confirmed with MTK internally that this event's wire format is fixed at a single ACL_START packet, so a comment was added above the switch in both btmtk.c and btmtksdio.c explaining that HCI fragmentation does not apply to this handle (and the other vendor-reserved ones already handled there).
- Patches 2, 3: no changes.

Chris Lu (3):
Bluetooth: btmtk: Route firmware debug event to the diag channel
Bluetooth: btmtk: fix wrong status for short WMT FUNC_CTRL events
Bluetooth: btmtksdio, btmtkuart: validate WMT event length before
struct access

 drivers/bluetooth/btmtk.c     | 15 ++++++++++++++-
 drivers/bluetooth/btmtksdio.c | 28 +++++++++++++++++++++++++++-
 drivers/bluetooth/btmtkuart.c | 20 +++++++++++++++++++-
 3 files changed, 60 insertions(+), 3 deletions(-)

--
2.45.2

author
#4 lore raw

PATCH v2 3/3 Bluetooth: btmtksdio, btmtkuart: validate WMT event length before struct access

btmtksdio.c and btmtkuart.c cast a received WMT event straight to struct btmtk_hci_wmt_evt and read its op/flag fields without checking the event is long enough to contain them, unlike btmtk.c. The FUNC_CTRL case then further casts to struct btmtk_hci_wmt_evt_funcc and reads its 2-byte status field, again without a length check. Firmware that sends a short or malformed WMT event makes both drivers read past the end of the received SKB.

Mirror btmtk.c: validate the base WMT header with skb_pull_data() before touching any of its fields, and when a FUNC_CTRL event turns out to be the short, header-only form (a plain enable/disable ack with no status word), decode the result from the header's own flag byte instead (0 = success, otherwise failure).

Verified setup on MT7920, MT7921, MT7922 and MT7925: no regression.

Fixes 9aebfd4a2200 ("Bluetooth: mediatek: add support for MediaTek MT7663S and MT7668S SDIO devices")
Fixes e0b67035a90b ("Bluetooth: mediatek: update the common setup between MT7622 and other devices")
Assisted-by Claude:claude-opus-5

---
v2: No changes.

 drivers/bluetooth/btmtksdio.c | 20 +++++++++++++++++++-
 drivers/bluetooth/btmtkuart.c | 20 +++++++++++++++++++-
 2 files changed, 38 insertions(+), 2 deletions(-)
drivers/bluetooth/btmtksdio.c +19 -1
index fe4ca9395aa3..a8ebcd0c005c 100644
@@ -217,7 +217,14 @@ static int mtk_hci_wmt_sync(struct hci_dev *hdev,
 	}
 
 	/* Parse and handle the return WMT event */
-	wmt_evt = (struct btmtk_hci_wmt_evt *)bdev->evt_skb->data;
+	wmt_evt = skb_pull_data(bdev->evt_skb, sizeof(*wmt_evt));
+	if (!wmt_evt) {
+		bt_dev_err(hdev, "WMT event too short (%u bytes)",
+			   bdev->evt_skb->len);
+		err = -EINVAL;
+		goto err_free_skb;
+	}
+
 	if (wmt_evt->whdr.op != hdr->op) {
 		bt_dev_err(hdev, "Wrong op received %d expected %d",
 			   wmt_evt->whdr.op, hdr->op);
@@ -233,6 +240,17 @@ static int mtk_hci_wmt_sync(struct hci_dev *hdev,
 			status = BTMTK_WMT_PATCH_DONE;
 		break;
 	case BTMTK_WMT_FUNC_CTRL:
+		if (!skb_pull_data(bdev->evt_skb,
+				   sizeof(wmt_evt_funcc->status))) {
+			/* A plain enable/disable request is acked with just
+			 * the WMT header and no trailing status word; the
+			 * result is carried in the header's own flag byte.
+			 */
+			status = wmt_evt->whdr.flag ? BTMTK_WMT_ON_UNDONE :
+						       BTMTK_WMT_ON_DONE;
+			break;
+		}
+
 		wmt_evt_funcc = (struct btmtk_hci_wmt_evt_funcc *)wmt_evt;
 		if (be16_to_cpu(wmt_evt_funcc->status) == 0x404)
 			status = BTMTK_WMT_ON_DONE;
drivers/bluetooth/btmtkuart.c +19 -1
index 27aa48ff3ac2..4af6fbbbd302 100644
@@ -151,7 +151,14 @@ static int mtk_hci_wmt_sync(struct hci_dev *hdev,
 	}
 
 	/* Parse and handle the return WMT event */
-	wmt_evt = (struct btmtk_hci_wmt_evt *)bdev->evt_skb->data;
+	wmt_evt = skb_pull_data(bdev->evt_skb, sizeof(*wmt_evt));
+	if (!wmt_evt) {
+		bt_dev_err(hdev, "WMT event too short (%u bytes)",
+			   bdev->evt_skb->len);
+		err = -EINVAL;
+		goto err_free_wc;
+	}
+
 	if (wmt_evt->whdr.op != hdr->op) {
 		bt_dev_err(hdev, "Wrong op received %d expected %d",
 			   wmt_evt->whdr.op, hdr->op);
@@ -167,6 +174,17 @@ static int mtk_hci_wmt_sync(struct hci_dev *hdev,
 			status = BTMTK_WMT_PATCH_DONE;
 		break;
 	case BTMTK_WMT_FUNC_CTRL:
+		if (!skb_pull_data(bdev->evt_skb,
+				   sizeof(wmt_evt_funcc->status))) {
+			/* A plain enable/disable request is acked with just
+			 * the WMT header and no trailing status word; the
+			 * result is carried in the header's own flag byte.
+			 */
+			status = wmt_evt->whdr.flag ? BTMTK_WMT_ON_UNDONE :
+						       BTMTK_WMT_ON_DONE;
+			break;
+		}
+
 		wmt_evt_funcc = (struct btmtk_hci_wmt_evt_funcc *)wmt_evt;
 		if (be16_to_cpu(wmt_evt_funcc->status) == 0x404)
 			status = BTMTK_WMT_ON_DONE;

--
2.45.2

author
#3 lore raw

PATCH v2 2/3 Bluetooth: btmtk: fix wrong status for short WMT FUNC_CTRL events

In reply to Chris Lu

A too-short BTMTK_WMT_FUNC_CTRL event (WMT header only, no trailing 2-byte status word) is always treated as BTMTK_WMT_ON_UNDONE. This short form is how firmware acks a plain enable/disable request, and the actual result is carried in the header's own flag byte (0 = success), not a separate status word. Decode it from there instead of assuming failure.

Verified setup on MT7920, MT7921, MT7922 and MT7925: no regression.

Fixes e3ac0d9f1a20 ("Bluetooth: btmtk: accept too short WMT FUNC_CTRL events")
Assisted-by Claude:claude-opus-5

---
v2: No changes.

 drivers/bluetooth/btmtk.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/bluetooth/btmtk.c +6 -1
index 660ed5b02841..03b99826b52c 100644
@@ -791,7 +791,12 @@ static int btmtk_usb_hci_wmt_sync(struct hci_dev *hdev,
 	case BTMTK_WMT_FUNC_CTRL:
 		if (!skb_pull_data(data->evt_skb,
 				   sizeof(wmt_evt_funcc->status))) {
-			status = BTMTK_WMT_ON_UNDONE;
+			/* A plain enable/disable request is acked with just
+			 * the WMT header and no trailing status word; the
+			 * result is carried in the header's own flag byte.
+			 */
+			status = wmt_evt->whdr.flag ? BTMTK_WMT_ON_UNDONE :
+						       BTMTK_WMT_ON_DONE;
 			break;
 		}
 

--
2.45.2

author
#1 lore raw

PATCH v2 1/3 Bluetooth: btmtk: Route firmware debug event to the diag channel

In reply to Chris Lu

MediaTek controllers may emit a firmware debug event on the ACL channel using the reserved handle 0x0efd, which shows up in the ACL header as 0x2efd once the start fragment flag is included.

Neither btmtk_usb_recv_acl() nor btmtksdio_recv_acl() recognizes it, so the packet is passed to the HCI core, which has no connection with that handle and complains:

Bluetooth: hci0: ACL packet for unknown connection handle 3837

Handle it the same way as the existing firmware debug logging packets and forward it to the diagnostic channel instead.

Confirmed with MTK internally that this event's wire format is fixed:
firmware always sends it as a single ACL_START packet and never splits it into a continuation (ACL_CONT, which would show up as 0x1efd). Add a comment above the switch spelling that out for this and the other vendor-reserved handles already handled here (0xfc6f, 0x05ff, 0x05fe), so review tooling doesn't keep flagging the apparent lack of a matching continuation case.

Verified on MT7922: under the condition that triggers this firmware debug event, it is now routed to the diag channel instead of reaching the host as an unknown ACL packet.

---
v2: Confirmed with MTK that this event's wire format is fixed at a
single ACL_START packet; added a comment above the switch in btmtk.c and btmtksdio.c explaining that HCI fragmentation does not apply here, addressing review feedback on v1.

 drivers/bluetooth/btmtk.c     | 8 ++++++++
 drivers/bluetooth/btmtksdio.c | 8 ++++++++
 2 files changed, 16 insertions(+)
drivers/bluetooth/btmtk.c +8 -0
index 660ed5b02841..ddf50ab9533e 100644
@@ -1055,6 +1055,13 @@ int btmtk_usb_recv_acl(struct hci_dev *hdev, struct sk_buff *skb)
 	struct btmtk_data *data = hci_get_priv(hdev);
 	u16 handle = le16_to_cpu(hci_acl_hdr(skb)->handle);
 
+	/* The handles below are vendor-reserved values MTK firmware uses to
+	 * tag out-of-band debug/dump data on the ACL channel rather than a
+	 * real connection. Each is always sent as a single, complete
+	 * ACL_START packet, so unlike genuine connection data they never
+	 * arrive fragmented (e.g. 0x2efd is never followed by an ACL_CONT
+	 * continuation, 0x1efd).
+	 */
 	switch (handle) {
 	case 0xfc6f:		/* Firmware dump from device */
 		/* When the firmware hangs, the device can no longer
@@ -1076,6 +1083,7 @@ int btmtk_usb_recv_acl(struct hci_dev *hdev, struct sk_buff *skb)
 		fallthrough;
 	case 0x05ff:		/* Firmware debug logging 1 */
 	case 0x05fe:		/* Firmware debug logging 2 */
+	case 0x2efd:		/* Firmware debug event */
 		return hci_recv_diag(hdev, skb);
 	}
 
drivers/bluetooth/btmtksdio.c +8 -0
index fe4ca9395aa3..46cb143a99c6 100644
@@ -451,6 +451,13 @@ static int btmtksdio_recv_acl(struct hci_dev *hdev, struct sk_buff *skb)
 	struct btmtksdio_dev *bdev = hci_get_drvdata(hdev);
 	u16 handle = le16_to_cpu(hci_acl_hdr(skb)->handle);
 
+	/* The handles below are vendor-reserved values MTK firmware uses to
+	 * tag out-of-band debug/dump data on the ACL channel rather than a
+	 * real connection. Each is always sent as a single, complete
+	 * ACL_START packet, so unlike genuine connection data they never
+	 * arrive fragmented (e.g. 0x2efd is never followed by an ACL_CONT
+	 * continuation, 0x1efd).
+	 */
 	switch (handle) {
 	case 0xfc6f:
 		/* Firmware dump from device: when the firmware hangs, the
@@ -460,6 +467,7 @@ static int btmtksdio_recv_acl(struct hci_dev *hdev, struct sk_buff *skb)
 		fallthrough;
 	case 0x05ff:
 	case 0x05fe:
+	case 0x2efd:		/* Firmware debug event */
 		/* Firmware debug logging */
 		return hci_recv_diag(hdev, skb);
 	}

--
2.45.2

#2 lore raw

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/series/1164217/

---Test result---

Test Summary:

CheckPatch                    PASS      1.85 seconds
VerifyFixes                   PASS      0.07 seconds
VerifySignedoff               PASS      0.07 seconds
GitLint                       FAIL      0.66 seconds
SubjectPrefix                 PASS      0.21 seconds
BuildKernel                   PASS      22.19 seconds
CheckAllWarning               PASS      25.34 seconds
CheckSparse                   PASS      28.47 seconds
BuildKernel32                 PASS      23.14 seconds
CheckKernelLLVM               PASS      24.55 seconds
TestRunnerSetup               PASS      571.14 seconds
IncrementalBuild              PASS      25.67 seconds

Details
##############################
Test: GitLint - FAIL
Desc: Run gitlint
Output:
[v2,3/3] Bluetooth: btmtksdio, btmtkuart: validate WMT event length before struct access

1: T1 Title exceeds max length (88>80): "[v2,3/3] Bluetooth: btmtksdio, btmtkuart: validate WMT event length before struct access"

https://github.com/bluez/bluetooth-next/pull/763

---
Regards,
Linux Bluetooth

#5 lore raw
In reply to Chris Lu
This series was applied to bluetooth/bluetooth-next.git (master) by Luiz Augusto von Dentz <[email protected]>:

Hello:

This series was applied to bluetooth/bluetooth-next.git (master) by Luiz Augusto von Dentz <[email protected]>:

Quoted 6 lines · On Mon, 14 Sep 2026 14:56:51 +0800 you wrote:

This series bundles three independent MediaTek Bluetooth driver fixes:

Patch 1 is a resend of a fix submitted on 25 Aug 2026 ("Bluetooth: btmtk: Route firmware debug event to the diag channel") that received no review feedback at the time.

Quoted 8 lines

Patches 2-3 fix how btmtk_usb_hci_wmt_sync() (and its btmtksdio.c / btmtkuart.c counterparts) interpret a WMT FUNC_CTRL event that carries only the WMT header and no trailing 2-byte status word. Such an event is a normal firmware ack for a plain enable/disable request, with the result carried in the header's own flag byte, not a failure as the current code assumes:

[...]

Here is the summary with links:
- [v2,1/3] Bluetooth: btmtk: Route firmware debug event to the diag channel (no matching commit)
- [v2,2/3] Bluetooth: btmtk: fix wrong status for short WMT FUNC_CTRL events
https://git.kernel.org/bluetooth/bluetooth-next/c/8fcc7afecb81
- [v2,3/3] Bluetooth: btmtksdio, btmtkuart: validate WMT event length before struct access (no matching commit)

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html