diff mbox series

Bluetooth: fix null ptr deref on hci_sync_conn_complete_evt

Message ID 20220113090553.40362-1-soenke.huster@eknoes.de (mailing list archive)
State Superseded
Headers show
Series Bluetooth: fix null ptr deref on hci_sync_conn_complete_evt | expand

Checks

Context Check Description
tedd_an/checkpatch success Checkpatch PASS
tedd_an/gitlint fail Bluetooth: fix null ptr deref on hci_sync_conn_complete_evt 11: B2 Line has trailing whitespace: "I found this null pointer dereference while fuzzing bluetooth-next. " 12: B2 Line has trailing whitespace: "On the described behaviour, a null ptr deref in line 4723 happens, as " 14: B2 Line has trailing whitespace: "all other values are reserved for future use. Checking that mitigates a null "
tedd_an/buildkernel success Build Kernel PASS
tedd_an/incremental_build success Pass
tedd_an/testrunnersetup success Test Runner Setup PASS
tedd_an/testrunnerl2cap-tester success Total: 40, Passed: 40 (100.0%), Failed: 0, Not Run: 0
tedd_an/testrunnerbnep-tester success Total: 1, Passed: 1 (100.0%), Failed: 0, Not Run: 0
tedd_an/testrunnermgmt-tester success Total: 493, Passed: 493 (100.0%), Failed: 0, Not Run: 0
tedd_an/testrunnerrfcomm-tester success Total: 9, Passed: 9 (100.0%), Failed: 0, Not Run: 0
tedd_an/testrunnersco-tester fail Total: 12, Passed: 10 (83.3%), Failed: 2, Not Run: 0
tedd_an/testrunnersmp-tester success Total: 8, Passed: 8 (100.0%), Failed: 0, Not Run: 0
tedd_an/testrunneruserchan-tester success Total: 4, Passed: 4 (100.0%), Failed: 0, Not Run: 0

Commit Message

Soenke Huster Jan. 13, 2022, 9:05 a.m. UTC
This event is specified just for SCO and eSCO link types.
On the reception of a HCI_Synchronous_Connection_Complete for a BDADDR
of an existing LE connection, LE link type and a status that triggers the
second case of the packet processing a NULL pointer dereference happens,
as conn->link is NULL.

Signed-off-by: Soenke Huster <soenke.huster@eknoes.de>
---
I found this null pointer dereference while fuzzing bluetooth-next. 
On the described behaviour, a null ptr deref in line 4723 happens, as 
conn->link is NULL. According to the Core spec, Link_Type must be SCO or eSCO,
all other values are reserved for future use. Checking that mitigates a null 
pointer dereference.

 net/bluetooth/hci_event.c | 5 +++++
 1 file changed, 5 insertions(+)
diff mbox series

Patch

diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index fc30f4c03d29..fc3f29d195d2 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -4661,6 +4661,11 @@  static void hci_sync_conn_complete_evt(struct hci_dev *hdev, void *data,
 	struct hci_ev_sync_conn_complete *ev = data;
 	struct hci_conn *conn;
 
+	if (ev->link_type != SCO_LINK || ev->link_type != ESCO_LINK) {
+		bt_dev_err(hdev, "Ignoring connect complete event for invalid link type");
+		return;
+	}
+
 	bt_dev_dbg(hdev, "status 0x%2.2x", ev->status);
 
 	hci_dev_lock(hdev);