Skip to content

Commit 5f641f0

Browse files
committed
Bluetooth: hci_conn: Fix UAF Write in __hci_acl_create_connection_sync
This fixes the UAF on __hci_acl_create_connection_sync caused by connection abortion, it uses the same logic as to LE_LINK which uses hci_cmd_sync_cancel to prevent the callback to run if the connection is abort prematurely. Reported-by: [email protected] Fixes: 4534009 ("Bluetooth: hci_conn: Only do ACL connections sequentially") Signed-off-by: Luiz Augusto von Dentz <[email protected]>
1 parent bf98fee commit 5f641f0

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

include/net/bluetooth/hci_sync.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,5 +139,4 @@ int hci_le_big_terminate_sync(struct hci_dev *hdev, u8 handle);
139139

140140
int hci_le_pa_terminate_sync(struct hci_dev *hdev, u16 handle);
141141

142-
int hci_acl_create_connection_sync(struct hci_dev *hdev,
143-
struct hci_conn *conn);
142+
int hci_connect_acl_sync(struct hci_dev *hdev, struct hci_conn *conn);

net/bluetooth/hci_conn.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1645,7 +1645,7 @@ struct hci_conn *hci_connect_acl(struct hci_dev *hdev, bdaddr_t *dst,
16451645
acl->auth_type = auth_type;
16461646
acl->conn_timeout = timeout;
16471647

1648-
err = hci_acl_create_connection_sync(hdev, acl);
1648+
err = hci_connect_acl_sync(hdev, acl);
16491649
if (err) {
16501650
hci_conn_del(acl);
16511651
return ERR_PTR(err);
@@ -2942,6 +2942,7 @@ int hci_abort_conn(struct hci_conn *conn, u8 reason)
29422942
*/
29432943
if (conn->state == BT_CONNECT && hdev->req_status == HCI_REQ_PEND) {
29442944
switch (hci_skb_event(hdev->sent_cmd)) {
2945+
case HCI_EV_CONN_COMPLETE:
29452946
case HCI_EV_LE_CONN_COMPLETE:
29462947
case HCI_EV_LE_ENHANCED_CONN_COMPLETE:
29472948
case HCI_EVT_LE_CIS_ESTABLISHED:

net/bluetooth/hci_sync.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6493,13 +6493,18 @@ int hci_update_adv_data(struct hci_dev *hdev, u8 instance)
64936493
UINT_PTR(instance), NULL);
64946494
}
64956495

6496-
static int __hci_acl_create_connection_sync(struct hci_dev *hdev, void *data)
6496+
static int hci_acl_create_conn_sync(struct hci_dev *hdev, void *data)
64976497
{
6498-
struct hci_conn *conn = data;
6498+
struct hci_conn *conn;
6499+
u16 handle = PTR_UINT(data);
64996500
struct inquiry_entry *ie;
65006501
struct hci_cp_create_conn cp;
65016502
int err;
65026503

6504+
conn = hci_conn_hash_lookup_handle(hdev, handle);
6505+
if (!conn)
6506+
return 0;
6507+
65036508
/* Many controllers disallow HCI Create Connection while it is doing
65046509
* HCI Inquiry. So we cancel the Inquiry first before issuing HCI Create
65056510
* Connection. This may cause the MGMT discovering state to become false
@@ -6556,9 +6561,8 @@ static int __hci_acl_create_connection_sync(struct hci_dev *hdev, void *data)
65566561
return err;
65576562
}
65586563

6559-
int hci_acl_create_connection_sync(struct hci_dev *hdev,
6560-
struct hci_conn *conn)
6564+
int hci_connect_acl_sync(struct hci_dev *hdev, struct hci_conn *conn)
65616565
{
6562-
return hci_cmd_sync_queue(hdev, __hci_acl_create_connection_sync,
6563-
conn, NULL);
6566+
return hci_cmd_sync_queue(hdev, hci_acl_create_conn_sync,
6567+
UINT_PTR(conn->handle), NULL);
65646568
}

0 commit comments

Comments
 (0)