Skip to content

Commit 1cc18c2

Browse files
pskrgagVudentz
authored andcommitted
bluetooth/hci: disallow setting handle bigger than HCI_CONN_HANDLE_MAX
Syzbot hit warning in hci_conn_del() caused by freeing handle that was not allocated using ida allocator. This is caused by handle bigger than HCI_CONN_HANDLE_MAX passed by hci_le_big_sync_established_evt(), which makes code think it's unset connection. Add same check for handle upper bound as in hci_conn_set_handle() to prevent warning. Link: https://syzkaller.appspot.com/bug?extid=b2545b087a01a7319474 Reported-by: [email protected] Fixes: 181a42e ("Bluetooth: Make handle of hci_conn be unique") Signed-off-by: Pavel Skripkin <[email protected]> Signed-off-by: Luiz Augusto von Dentz <[email protected]>
1 parent 596b6f0 commit 1cc18c2

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

net/bluetooth/hci_conn.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -899,8 +899,8 @@ static int hci_conn_hash_alloc_unset(struct hci_dev *hdev)
899899
U16_MAX, GFP_ATOMIC);
900900
}
901901

902-
struct hci_conn *hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst,
903-
u8 role, u16 handle)
902+
static struct hci_conn *__hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst,
903+
u8 role, u16 handle)
904904
{
905905
struct hci_conn *conn;
906906

@@ -1041,7 +1041,16 @@ struct hci_conn *hci_conn_add_unset(struct hci_dev *hdev, int type,
10411041
if (unlikely(handle < 0))
10421042
return ERR_PTR(-ECONNREFUSED);
10431043

1044-
return hci_conn_add(hdev, type, dst, role, handle);
1044+
return __hci_conn_add(hdev, type, dst, role, handle);
1045+
}
1046+
1047+
struct hci_conn *hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst,
1048+
u8 role, u16 handle)
1049+
{
1050+
if (handle > HCI_CONN_HANDLE_MAX)
1051+
return ERR_PTR(-EINVAL);
1052+
1053+
return __hci_conn_add(hdev, type, dst, role, handle);
10451054
}
10461055

10471056
static void hci_conn_cleanup_child(struct hci_conn *conn, u8 reason)

0 commit comments

Comments
 (0)