Bluetooth: hci_sock: validate event length before filtering
Subsystems (3)
PATCH 1/1 Bluetooth: hci_sock: validate event length before filtering
is_filtered_packet() reads the event code from skb->data[0] without first checking that the skb is nonempty. When an opcode filter is configured, it also reads the command opcode at offsets 3 or 4 without checking that a Command Complete or Command Status event is long enough.
hci_send_to_sock() invokes the filter before hci_event_packet() validates the event header. A malformed event supplied by a controller or a vhci device can therefore cause an out-of-bounds read.
Keep the unmasked event code for the opcode checks. The masked value is needed for the 64-bit event bitmap, but using it to identify command events aliases event codes above 0x3f. In particular, Synchronous Train Complete (0x4f) was treated as Command Status (0x0f) even though its payload has no opcode.
Reject actual command events that are too short for the field being inspected. A truncated command event cannot match a configured opcode.
--- net/bluetooth/hci_sock.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)
net/bluetooth/hci_sock.c +14 -3
@@ -164,6 +164,7 @@ static bool is_filtered_packet(struct sock *sk, struct sk_buff *skb) {struct hci_filter *flt;int flt_type, flt_event; +u8 event;/* Apply filter */ flt = &hci_pi (sk)->filter;
@@ -177,7 +178,11 @@ static bool is_filtered_packet(struct sock *sk, struct sk_buff *skb)if (hci_skb_pkt_type (skb) !=HCI_EVENT_PKT )return false; - flt_event = (*(__u8 *)skb->data &HCI_FLT_EVENT_BITS ); +if (skb->len <1 ) +return true; + + event = *(__u8 *)skb->data; + flt_event = event &HCI_FLT_EVENT_BITS ;if (!hci_test_bit (flt_event, &flt->event_mask))return true;
@@ -186,11 +191,17 @@ static bool is_filtered_packet(struct sock *sk, struct sk_buff *skb)if (!flt->opcode)return false; -if (flt_event ==HCI_EV_CMD_COMPLETE && +if (event ==HCI_EV_CMD_COMPLETE && skb->len <5 ) +return true; + +if (event ==HCI_EV_CMD_COMPLETE && flt->opcode !=get_unaligned ((__le16 *)(skb->data +3 )))return true; -if (flt_event ==HCI_EV_CMD_STATUS && +if (event ==HCI_EV_CMD_STATUS && skb->len <6 ) +return true; + +if (event ==HCI_EV_CMD_STATUS && flt->opcode !=get_unaligned ((__le16 *)(skb->data +4 )))return true;
Signature · 1 line
2.43.0
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/1165735/
---Test result---
Test Summary:
CheckPatch PASS 1.40 seconds VerifyFixes PASS 0.09 seconds VerifySignedoff PASS 0.09 seconds GitLint PASS 0.24 seconds SubjectPrefix PASS 0.09 seconds BuildKernel PASS 19.67 seconds CheckAllWarning PASS 24.44 seconds CheckSparse PASS 24.92 seconds BuildKernel32 PASS 21.20 seconds CheckKernelLLVM PASS 20.79 seconds TestRunnerSetup PASS 504.73 seconds TestRunner_l2cap-tester FAIL 10.09 seconds TestRunner_iso-tester FAIL 5.83 seconds TestRunner_bnep-tester FAIL 5.90 seconds TestRunner_mgmt-tester FAIL 5.89 seconds TestRunner_rfcomm-tester FAIL 5.68 seconds TestRunner_sco-tester FAIL 5.88 seconds TestRunner_ioctl-tester FAIL 5.70 seconds TestRunner_mesh-tester FAIL 5.76 seconds TestRunner_smp-tester FAIL 5.70 seconds TestRunner_userchan-tester FAIL 5.90 seconds TestRunner_6lowpan-tester FAIL 5.81 seconds IncrementalBuild PASS 19.58 seconds
Details
##############################
Test: TestRunner_l2cap-tester - FAIL
Desc: Run l2cap-tester with test-runner Output:
No test result found
##############################
Test: TestRunner_iso-tester - FAIL
Desc: Run iso-tester with test-runner Output:
No test result found
##############################
Test: TestRunner_bnep-tester - FAIL
Desc: Run bnep-tester with test-runner Output:
No test result found
##############################
Test: TestRunner_mgmt-tester - FAIL
Desc: Run mgmt-tester with test-runner Output:
No test result found
##############################
Test: TestRunner_rfcomm-tester - FAIL
Desc: Run rfcomm-tester with test-runner Output:
No test result found
##############################
Test: TestRunner_sco-tester - FAIL
Desc: Run sco-tester with test-runner Output:
No test result found
##############################
Test: TestRunner_ioctl-tester - FAIL
Desc: Run ioctl-tester with test-runner Output:
No test result found
##############################
Test: TestRunner_mesh-tester - FAIL
Desc: Run mesh-tester with test-runner Output:
No test result found
##############################
Test: TestRunner_smp-tester - FAIL
Desc: Run smp-tester with test-runner Output:
No test result found
##############################
Test: TestRunner_userchan-tester - FAIL
Desc: Run userchan-tester with test-runner Output:
No test result found
##############################
Test: TestRunner_6lowpan-tester - FAIL
Desc: Run 6lowpan-tester with test-runner Output:
No test result found
https://github.com/bluez/bluetooth-next/pull/775
---
Regards,
Linux Bluetooth
This patch was applied to bluetooth/bluetooth-next.git (master) by Luiz Augusto von Dentz <[email protected]>:
Hello:
This patch was applied to bluetooth/bluetooth-next.git (master) by Luiz Augusto von Dentz <[email protected]>:
Quoted 10 lines · On Tue, 15 Sep 2026 13:03:07 -0300 you wrote:
is_filtered_packet()reads the event code from skb->data[0] without first checking that the skb is nonempty. When an opcode filter is configured, it also reads the command opcode at offsets 3 or 4 without checking that a Command Complete or Command Status event is long enough.
hci_send_to_sock()invokes the filter beforehci_event_packet()validates the event header. A malformed event supplied by a controller or a vhci device can therefore cause an out-of-bounds read.[...]
Here is the summary with links:
- Bluetooth: hci_sock: validate event length before filtering
https://git.kernel.org/bluetooth/bluetooth-next/c/b0a6cf99afd5
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html