Bluetooth: btmtk: validate WMT event SKB length before struct access
Subsystems (3)
PATCH v3 1/1 Bluetooth: btmtk: validate WMT event SKB length before struct access
From: Tristan Madani <[email protected]>
btmtk_usb_hci_wmt_sync() casts the WMT event response SKB data to struct btmtk_hci_wmt_evt (7 bytes) and struct btmtk_hci_wmt_evt_funcc (9 bytes) without first checking that the SKB contains enough data. A short firmware response causes out-of-bounds reads from SKB tailroom.
Add length validation before each struct access to prevent OOB reads from malformed WMT event responses.
--- drivers/bluetooth/btmtk.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
drivers/bluetooth/btmtk.c +10 -0
@@ -695,6 +695,12 @@ static int btmtk_usb_hci_wmt_sync(struct hci_dev *hdev,if (data->evt_skb ==NULL ) goto err_free_wc; +/* Validate SKB length before accessing WMT event structs */ +if (data->evt_skb->len <sizeof (*wmt_evt)) { + err = -EINVAL ; + goto err_free_skb; + } +/* Parse and handle the return WMT event */ wmt_evt = (struct btmtk_hci_wmt_evt *)data->evt_skb->data;if (wmt_evt->whdr.op != hdr->op) {
@@ -712,6 +718,10 @@ static int btmtk_usb_hci_wmt_sync(struct hci_dev *hdev, status =BTMTK_WMT_PATCH_DONE ;break ;case BTMTK_WMT_FUNC_CTRL : +if (data->evt_skb->len <sizeof (*wmt_evt_funcc)) { + err = -EINVAL ; + goto err_free_skb; + } 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 ;
Signature · 1 line
2.47.3
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/project/bluetooth/list/?series=1082459
---Test result---
Test Summary:
CheckPatch PASS 0.55 seconds GitLint PASS 0.20 seconds SubjectPrefix PASS 0.06 seconds BuildKernel PASS 25.96 seconds CheckAllWarning PASS 28.76 seconds CheckSparse PASS 27.37 seconds BuildKernel32 PASS 25.48 seconds TestRunnerSetup PASS 564.82 seconds IncrementalBuild PASS 24.17 seconds
https://github.com/bluez/bluetooth-next/pull/98
---
Regards,
Linux Bluetooth
Luiz Augusto von Dentz
maintainerHi Tristan,
Quoted 23 lines · Tristan Madani
From: Tristan Madani <[email protected]>
btmtk_usb_hci_wmt_sync()casts the WMT event response SKB data to structbtmtk_hci_wmt_evt(7 bytes) and structbtmtk_hci_wmt_evt_funcc(9 bytes) without first checking that the SKB contains enough data. A short firmware response causes out-of-bounds reads from SKB tailroom.Add length validation before each struct access to prevent OOB reads from malformed WMT event responses.
Fixes d019930b0049 ("Bluetooth: btmtk: move btusb_mtk_hci_wmt_sync to btmtk.c")Signed-off-by Tristan Madani <[email protected]>--- drivers/bluetooth/btmtk.c | 10 ++++++++++ 1 file changed, 10 insertions(+)drivers/bluetooth/btmtk.c +0
-0
drivers/bluetooth/btmtk.c static int btmtk_usb_hci_wmt_sync(struct hci_dev *hdev, · line 702
Quoted 8 lines
drivers/bluetooth/btmtk.c +5
-0@@ -695,6 +695,12 @@ static int btmtk_usb_hci_wmt_sync(struct hci_dev *hdev,if (data->evt_skb ==NULL ) goto err_free_wc; +/* Validate SKB length before accessing WMT event structs */ +if (data->evt_skb->len <sizeof (*wmt_evt)) { + err = -EINVAL ; + goto err_free_skb; + }
Can't we just use skb_pull_data instead?
drivers/bluetooth/btmtk.c static int btmtk_usb_hci_wmt_sync(struct hci_dev *hdev, · line 724
Quoted 12 lines
drivers/bluetooth/btmtk.c +5
-0+/* Parse and handle the return WMT event */ wmt_evt = (struct btmtk_hci_wmt_evt *)data->evt_skb->data;if (wmt_evt->whdr.op != hdr->op) {@@ -712,6 +718,10 @@ static int btmtk_usb_hci_wmt_sync(struct hci_dev *hdev, status =BTMTK_WMT_PATCH_DONE ;break ;case BTMTK_WMT_FUNC_CTRL : +if (data->evt_skb->len <sizeof (*wmt_evt_funcc)) { + err = -EINVAL ; + goto err_free_skb; + }
Ditto.
Quoted 6 lines
drivers/bluetooth/btmtk.c +0
-1wmt_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.47.3
https://sashiko.dev/#/patchset/20260417102919.2549352-1-tristmd%40gmail.com
We should probably check if the comments above are valid and have them fixed.
Signature · 1 line
Luiz Augusto von Dentz