Bluetooth: fix null ptr deref on hci_sync_conn_complete_evt
authorSoenke Huster <soenke.huster@eknoes.de>
Fri, 14 Jan 2022 16:44:02 +0000 (17:44 +0100)
committerLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Fri, 14 Jan 2022 20:20:49 +0000 (12:20 -0800)
This event is just specified 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>
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
net/bluetooth/hci_event.c

index 05997dff566628d42b8827051d54ded938c4c6c2..681c623aa38063fe18b5f524224ba5849f4f0b5c 100644 (file)
@@ -4661,6 +4661,19 @@ 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;
 
+       switch (ev->link_type) {
+       case SCO_LINK:
+       case ESCO_LINK:
+               break;
+       default:
+               /* As per Core 5.3 Vol 4 Part E 7.7.35 (p.2219), Link_Type
+                * for HCI_Synchronous_Connection_Complete is limited to
+                * either SCO or eSCO
+                */
+               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);