Bluetooth: hci_event: validate HCI event packet Parameter Total Length
Subsystems (2)
PATCH 1/1 Bluetooth: hci_event: validate HCI event packet Parameter Total Length
There is a BUG: KMSAN: uninit-value in hci_cmd_complete_evt() due to a malformed HCI event packet received from userspace.
The existing code in hci_event_packet() checks that the buffer is large enough to contain the event header, and checks that the hdr's Event Code is valid, but does not check the hdr's Parameter Total Length. So, syzbot’s event packet passes through and uses the un-init values in hci_event_func() => hci_cmd_complete_evt().
--- net/bluetooth/hci_event.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
net/bluetooth/hci_event.c +8 -1
@@ -7565,7 +7565,7 @@ void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb)hci_req_complete_t req_complete =NULL ;hci_req_complete_skb_t req_complete_skb =NULL ;struct sk_buff *orig_skb =NULL ; -u8 status =0 , event, req_evt =0 ; +u8 status =0 , event, req_evt =0 , len;u16 opcode =HCI_OP_NOP ;if (skb->len <sizeof (*hdr)) {
@@ -7585,6 +7585,13 @@ void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb) goto done; } + len = hdr->plen; +if (len != skb->len -HCI_EVENT_HDR_SIZE ) { +bt_dev_warn (hdev,"Unexpected HCI Parameter Length 0x%2.2x" , + len); + goto done; + } +/* Only match event if command OGF is not for LE */ if (hdev->req_skb && hci_opcode_ogf(hci_skb_opcode(hdev->req_skb)) != 0x08 &&
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/project/bluetooth/list/?series=1014723
---Test result---
Test Summary:
CheckPatch PENDING 0.33 seconds GitLint PENDING 0.43 seconds SubjectPrefix PASS 0.07 seconds BuildKernel PASS 22.80 seconds CheckAllWarning PASS 25.23 seconds CheckSparse WARNING 28.22 seconds BuildKernel32 PASS 23.38 seconds TestRunnerSetup PASS 462.08 seconds TestRunner_l2cap-tester PASS 24.04 seconds TestRunner_iso-tester FAIL 32.30 seconds TestRunner_bnep-tester PASS 6.20 seconds TestRunner_mgmt-tester FAIL 120.11 seconds TestRunner_rfcomm-tester PASS 9.40 seconds TestRunner_sco-tester PASS 14.44 seconds TestRunner_ioctl-tester PASS 10.10 seconds TestRunner_mesh-tester FAIL 12.41 seconds TestRunner_smp-tester PASS 8.51 seconds TestRunner_userchan-tester PASS 6.43 seconds IncrementalBuild PENDING 1.01 seconds
Details
##############################
Test: CheckPatch - PENDING
Desc: Run checkpatch.pl script Output:
##############################
Test: GitLint - PENDING
Desc: Run gitlint
Output:
##############################
Test: CheckSparse - WARNING
Desc: Run sparse tool with linux kernel
Output:net/bluetooth/hci_event.c: note: in included file (through include/net/bluetooth/hci_core.h):
##############################
Test: TestRunner_iso-tester - FAIL
Desc: Run iso-tester with test-runner
Output:
No test result found
##############################
Test: TestRunner_mgmt-tester - FAIL
Desc: Run mgmt-tester with test-runner
Output:
Total: 490, Passed: 484 (98.8%), Failed: 2, Not Run: 4
Failed Test Cases
Read Exp Feature - Success Failed 0.111 seconds LL Privacy - Start Discovery 1 (Disable RL) Failed 0.173 seconds
##############################
Test: TestRunner_mesh-tester - FAIL
Desc: Run mesh-tester with test-runner Output:
Total: 10, Passed: 8 (80.0%), Failed: 2, Not Run: 0
Failed Test Cases
Mesh - Send cancel - 1 Timed out 2.767 seconds Mesh - Send cancel - 2 Timed out 1.999 seconds
##############################
Test: IncrementalBuild - PENDING
Desc: Incremental build with the patches in the series Output:
---
Regards,
Linux Bluetooth
Quoted 49 lines · Raphael Pinsonneault-Thibeault
There is a BUG: KMSAN: uninit-value in
hci_cmd_complete_evt()due to a malformed HCI event packet received from userspace.The existing code in
hci_event_packet()checks that the buffer is large enough to contain the event header, and checks that the hdr's Event Code is valid, but does not check the hdr's Parameter Total Length. So, syzbot’s event packet passes through and uses the un-init values inhci_event_func()=>hci_cmd_complete_evt().Reported-by [email protected]Tested-by [email protected]Fixes a9de9248064bf ("[Bluetooth] Switch from OGF+OCF to using only opcodes")Signed-off-by Raphael Pinsonneault-Thibeault <[email protected]>--- net/bluetooth/hci_event.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)net/bluetooth/hci_event.c +8
-1@@ -7565,7 +7565,7 @@ void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb)hci_req_complete_t req_complete =NULL ;hci_req_complete_skb_t req_complete_skb =NULL ;struct sk_buff *orig_skb =NULL ; -u8 status =0 , event, req_evt =0 ; +u8 status =0 , event, req_evt =0 , len;u16 opcode =HCI_OP_NOP ;if (skb->len <sizeof (*hdr)) {@@ -7585,6 +7585,13 @@ void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb) goto done; } + len = hdr->plen; +if (len != skb->len -HCI_EVENT_HDR_SIZE ) { +bt_dev_warn (hdev,"Unexpected HCI Parameter Length 0x%2.2x" , + len); + goto done; + } +/* Only match event if command OGF is not for LE */ if (hdev->req_skb && hci_opcode_ogf(hci_skb_opcode(hdev->req_skb)) != 0x08 &&Signature · 1 line
2.43.0
Hi,
This is the friendly patch-bot of Greg Kroah-Hartman. You have sent him a patch that has triggered this response. He used to manually respond to these common problems, but in order to save his sanity (he kept writing the same thing over and over, yet to different people), I was created. Hopefully you will not take offence and will fix the problem in your patch and resubmit it so that it can be accepted into the Linux kernel tree.
You are receiving this message because of the following common error(s) as indicated below:
- You have marked a patch with a "Fixes:" tag for a commit that is in an older released kernel, yet you do not have a cc: stable line in the signed-off-by area at all, which means that the patch will not be applied to any older kernel releases. To properly fix this, please follow the documented rules in the Documentation/process/stable-kernel-rules.rst file for how to resolve this.
If you wish to discuss this problem further, or you have questions about how to resolve this issue, please feel free to respond to this email and Greg will reply once he has dug out from the pending patches received from other developers.
thanks,
greg k-h's patch email bot
Luiz Augusto von Dentz
maintainerHi Raphael,
Quoted 9 lines · Raphael Pinsonneault-Thibeault
There is a BUG: KMSAN: uninit-value in
hci_cmd_complete_evt()due to a malformed HCI event packet received from userspace.The existing code in
hci_event_packet()checks that the buffer is large enough to contain the event header, and checks that the hdr's Event Code is valid, but does not check the hdr's Parameter Total Length. So, syzbot’s event packet passes through and uses the un-init values inhci_event_func()=>hci_cmd_complete_evt().
It does checks the length:
if (skb->len < ev->min_len) {
bt_dev_err(hdev, "unexpected event 0x%2.2x length: %u < %u",
event, skb->len, ev->min_len);
return;
}Quoted 23 lines
Reported-by [email protected]Tested-by [email protected]Fixes a9de9248064bf ("[Bluetooth] Switch from OGF+OCF to using only opcodes")Signed-off-by Raphael Pinsonneault-Thibeault <[email protected]>--- net/bluetooth/hci_event.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)net/bluetooth/hci_event.c +1
-1@@ -7565,7 +7565,7 @@ void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb)hci_req_complete_t req_complete =NULL ;hci_req_complete_skb_t req_complete_skb =NULL ;struct sk_buff *orig_skb =NULL ; -u8 status =0 , event, req_evt =0 ; +u8 status =0 , event, req_evt =0 , len;u16 opcode =HCI_OP_NOP ;if (skb->len <sizeof (*hdr)) {
net/bluetooth/hci_event.c void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb) · line 7593
Quoted 9 lines
net/bluetooth/hci_event.c +6
-0@@ -7585,6 +7585,13 @@ void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb) goto done; } + len = hdr->plen; +if (len != skb->len -HCI_EVENT_HDR_SIZE ) { +bt_dev_warn (hdev,"Unexpected HCI Parameter Length 0x%2.2x" , + len); + goto done; + }
Looks like a big hammer for a uninitialized value, which I assume is from the following code:
if (i == ARRAY_SIZE(hci_cc_table)) {
/* Unknown opcode, assume byte 0 contains the status, so
* that e.g. __hci_cmd_sync() properly returns errors
* for vendor specific commands send by HCI drivers.
* If a vendor doesn't actually follow this convention we may
* need to introduce a vendor CC table in order to properly set
* the status.
*/
*status = skb->data[0];
}
That one is accessing skb->data without first checking it like hci_cc_skb_pull like all other event handlers are doing, if that is really the case then something like the following should make it go away:
net/bluetooth/hci_event.c +0 -0
@@ -4219,6 +4219,13 @@ static void hci_cmd_complete_evt(struct hci_dev
*hdev, void *data,
}
if (i == ARRAY_SIZE(hci_cc_table)) {+ if (!skb->len) {
+ bt_dev_err(hdev, "unexpected cc 0x%4.4x with no status",
+ *opcode);
+ *status = HCI_ERROR_UNSPECIFIED;
+ return;
+ }
+
/* Unknown opcode, assume byte 0 contains the status, so
* that e.g. __hci_cmd_sync() properly returns errors
* for vendor specific commands send by HCI drivers.
Quoted 7 lines
net/bluetooth/hci_event.c +1
-1+/* Only match event if command OGF is not for LE */ if (hdev->req_skb && hci_opcode_ogf(hci_skb_opcode(hdev->req_skb)) != 0x08 && --2.43.0
Signature · 1 line
Luiz Augusto von Dentz
PATCH v2 1/1 Bluetooth: hci_event: validate skb length for unknown CC opcode
In hci_cmd_complete_evt(), if the command complete event has an unknown opcode, we assume the first byte of the remaining skb->data contains the return status. However, parameter data has previously been pulled in hci_event_func(), which may leave the skb empty. If so, using skb->data[0] for the return status uses un-init memory.
The fix is to check skb->len before using skb->data.
---
changes in v2:
- check skb->len before accessing skb->data in hci_cmd_complete_evt().
- remove v1’s changes
- update commit message and Fixes tag
Thank you for the response Luiz. I didn’t want to spam you or the ML with another reply since you were very clear.
net/bluetooth/hci_event.c | 7 +++++++ 1 file changed, 7 insertions(+)
net/bluetooth/hci_event.c +7 -0
@@ -4211,6 +4211,13 @@ static void hci_cmd_complete_evt(struct hci_dev *hdev, void *data, }if (i ==ARRAY_SIZE (hci_cc_table)) { +if (!skb->len) { +bt_dev_err (hdev,"Unexpected cc 0x%4.4x with no status" , + *opcode); + *status =HCI_ERROR_UNSPECIFIED ; +return ; + } +/* Unknown opcode, assume byte 0 contains the status, so * that e.g. __hci_cmd_sync() properly returns errors * for vendor specific commands send by HCI drivers.
Signature · 1 line
2.43.0
RE: [v2] Bluetooth: hci_event: validate skb length for unknown CC opcode
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=1015551
---Test result---
Test Summary:
CheckPatch PENDING 0.29 seconds GitLint PENDING 0.27 seconds SubjectPrefix PASS 0.11 seconds BuildKernel PASS 25.09 seconds CheckAllWarning PASS 27.18 seconds CheckSparse WARNING 30.91 seconds BuildKernel32 PASS 24.74 seconds TestRunnerSetup PASS 494.84 seconds TestRunner_l2cap-tester PASS 23.99 seconds TestRunner_iso-tester PASS 84.28 seconds TestRunner_bnep-tester PASS 6.12 seconds TestRunner_mgmt-tester FAIL 115.41 seconds TestRunner_rfcomm-tester PASS 9.33 seconds TestRunner_sco-tester PASS 14.49 seconds TestRunner_ioctl-tester PASS 9.86 seconds TestRunner_mesh-tester FAIL 11.47 seconds TestRunner_smp-tester PASS 8.52 seconds TestRunner_userchan-tester PASS 6.49 seconds IncrementalBuild PENDING 0.83 seconds
Details
##############################
Test: CheckPatch - PENDING
Desc: Run checkpatch.pl script Output:
##############################
Test: GitLint - PENDING
Desc: Run gitlint
Output:
##############################
Test: CheckSparse - WARNING
Desc: Run sparse tool with linux kernel
Output:net/bluetooth/hci_event.c: note: in included file (through include/net/bluetooth/hci_core.h):
##############################
Test: TestRunner_mgmt-tester - FAIL
Desc: Run mgmt-tester with test-runner
Output:
Total: 490, Passed: 484 (98.8%), Failed: 2, Not Run: 4
Failed Test Cases
Read Exp Feature - Success Failed 0.105 seconds LL Privacy - Set Flags 2 (Enable RL) Failed 0.158 seconds
##############################
Test: TestRunner_mesh-tester - FAIL
Desc: Run mesh-tester with test-runner Output:
Total: 10, Passed: 8 (80.0%), Failed: 2, Not Run: 0
Failed Test Cases
Mesh - Send cancel - 1 Timed out 2.025 seconds Mesh - Send cancel - 2 Timed out 1.995 seconds
##############################
Test: IncrementalBuild - PENDING
Desc: Incremental build with the patches in the series Output:
---
Regards,
Linux Bluetooth
Re: [PATCH v2] Bluetooth: hci_event: validate skb length for unknown CC opcode
In reply to Raphael Pinsonneault-ThibeaultThis 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 9 lines · On Fri, 24 Oct 2025 12:29:10 -0400 you wrote:
In
hci_cmd_complete_evt(), if the command complete event has an unknown opcode, we assume the first byte of the remainingskb->datacontains the return status. However, parameter data has previously been pulled inhci_event_func(), which may leave the skb empty. If so, using skb->data[0] for the return status uses un-init memory.The fix is to check
skb->lenbefore usingskb->data.[...]
Here is the summary with links:
- [v2] Bluetooth: hci_event: validate skb length for unknown CC opcode
https://git.kernel.org/bluetooth/bluetooth-next/c/a91f1b634866
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html