Bluetooth: btmtk: firmware debug event routing and WMT FUNC_CTRL status fixes
Subsystems (3)
PATCH 2/3 Bluetooth: btmtk: fix wrong status for short WMT FUNC_CTRL events
In reply to Chris LuA 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.
--- drivers/bluetooth/btmtk.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/bluetooth/btmtk.c +6 -1
@@ -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
PATCH 3/3 Bluetooth: btmtksdio, btmtkuart: validate WMT event length before struct access
In reply to Chris Lubtmtksdio.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.
--- drivers/bluetooth/btmtksdio.c | 20 +++++++++++++++++++- drivers/bluetooth/btmtkuart.c | 20 +++++++++++++++++++- 2 files changed, 38 insertions(+), 2 deletions(-)
drivers/bluetooth/btmtksdio.c +19 -1
@@ -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
@@ -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
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. There are no code changes since that submission; resending it alongside the two related fixes below.
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.
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 | 8 +++++++- drivers/bluetooth/btmtksdio.c | 20 +++++++++++++++++++- drivers/bluetooth/btmtkuart.c | 19 ++++++++++++++++++- 3 files changed, 44 insertions(+), 3 deletions(-)
--
2.45.2
PATCH 1/3 Bluetooth: btmtk: Route firmware debug event to the diag channel
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.
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.
--- drivers/bluetooth/btmtk.c | 1 + drivers/bluetooth/btmtksdio.c | 1 + 2 files changed, 2 insertions(+)
drivers/bluetooth/btmtk.c +1 -0
@@ -1076,6 +1076,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 +1 -0
@@ -460,6 +460,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
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/1162820/
---Test result---
Test Summary:
CheckPatch PASS 1.75 seconds VerifyFixes PASS 0.10 seconds VerifySignedoff PASS 0.09 seconds GitLint FAIL 0.75 seconds SubjectPrefix PASS 0.28 seconds BuildKernel PASS 20.38 seconds CheckAllWarning PASS 22.26 seconds CheckSparse PASS 24.03 seconds BuildKernel32 PASS 20.12 seconds CheckKernelLLVM PASS 19.95 seconds TestRunnerSetup PASS 484.80 seconds IncrementalBuild PASS 24.85 seconds
Details
##############################
Test: GitLint - FAIL
Desc: Run gitlint
Output:
[3/3] Bluetooth: btmtksdio, btmtkuart: validate WMT event length before struct access
1: T1 Title exceeds max length (85>80): "[3/3] Bluetooth: btmtksdio, btmtkuart: validate WMT event length before struct access"
https://github.com/bluez/bluetooth-next/pull/753
---
Regards,
Linux Bluetooth
Luiz Augusto von Dentz
maintainerHi Chris,
Quoted 32 lines · Chris Lu
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. There are no code changes since that submission; resending it alongside the two related fixes below.
Patches 2-3 fix how
btmtk_usb_hci_wmt_sync()(and itsbtmtksdio.c/btmtkuart.ccounterparts) interpret a WMTFUNC_CTRLevent 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 bye3ac0d9f1a20) but defaulted to the wrong result.
- Patch 3 applies the same fix tobtmtksdio.candbtmtkuart.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 thatbtmtk.calready has (skb_pull_data()before touchingwmt_evt->whdr.op), since these two files were unconditionally dereferencing that field with no length validation at all.Chris Lu (3):
Bluetooth: btmtk: Route firmware debug event to the diag channel
Bluetooth: btmtk: fix wrong status for short WMTFUNC_CTRLevents
Bluetooth: btmtksdio, btmtkuart: validate WMT event length before
struct access
Quoted 7 lines
drivers/bluetooth/btmtk.c | 8 +++++++- drivers/bluetooth/btmtksdio.c | 20 +++++++++++++++++++- drivers/bluetooth/btmtkuart.c | 19 ++++++++++++++++++- 3 files changed, 44 insertions(+), 3 deletions(-)--
2.45.2
Sashiko flagged a problem regarding the usage of ACL connection handle without masking the PB field:
https://sashiko.dev/#/patchset/20260911104234.2276126-1-chris.lu%40mediatek.com
If the HCI fragmentation doesn't apply to these handles, please add a comment regarding it; otherwise, users like Sashiko will keep flagging it going forward.
Signature · 1 line
Luiz Augusto von Dentz
Hi Luiz,
Quoted 57 lines · Luiz Augusto von Dentz
Hi Chris,
Quoted 41 lines · Chris Lu
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. There are no code changes since that submission; resending it alongside the two related fixes below.Patches 2-3 fix how
btmtk_usb_hci_wmt_sync()(and itsbtmtksdio.c/btmtkuart.ccounterparts) interpret a WMTFUNC_CTRLevent 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 bye3ac0d9f1a20) but defaulted to the wrong result.
- Patch 3 applies the same fix tobtmtksdio.candbtmtkuart.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 thatbtmtk.calready has (skb_pull_data()before touchingwmt_evt->whdr.op), since these two files were unconditionally dereferencing that field with no length validation at all.Chris Lu (3):
Bluetooth: btmtk: Route firmware debug event to the diag channel
Bluetooth: btmtk: fix wrong status for short WMTFUNC_CTRLevents
Bluetooth: btmtksdio, btmtkuart: validate WMT event length before struct accessQuoted 7 lines
drivers/bluetooth/btmtk.c | 8 +++++++-
drivers/bluetooth/btmtksdio.c| 20 +++++++++++++++++++-drivers/bluetooth/btmtkuart.c| 19 ++++++++++++++++++-3 files changed, 44 insertions(+), 3 deletions(-)--
2.45.2Sashiko flagged a problem regarding the usage of ACL connection handle
without masking the PB field:
Quoted 9 lines
If the HCI fragmentation doesn't apply to these handles, please add a comment regarding it; otherwise, users like Sashiko will keep flagging
it going forward.
Confirmed with MediaTek internally: 0x0efd (and the other three vendor-reserved handles already handled in this switch: 0xfc6f, 0x05ff, 0x05fe) is not a real connection handle -- it's used to multiplex firmware debug/dump data onto the ACL channel. This event is always sent as a single, complete ACL_START packet, so HCI fragmentation (and thus a matching ACL_CONT case, 0x1efd) never applies to it.
Added a comment above the switch statement in both btmtk.c and btmtksdio.c explaining this for all four handles, so it's clear going forward. Will include it in the next version.
Thanks for catching this.
BRs,
Chris Lu