Skip to content

Commit ca1fd42

Browse files
lrh2000Vudentz
authored andcommitted
Bluetooth: Fix potential double free caused by hci_conn_unlink
The hci_conn_unlink function is being called by hci_conn_del, which means it should not call hci_conn_del with the input parameter conn again. If it does, conn may have already been released when hci_conn_unlink returns, leading to potential UAF and double-free issues. This patch resolves the problem by modifying hci_conn_unlink to release only conn's child links when necessary, but never release conn itself. Reported-by: [email protected] Closes: https://lore.kernel.org/linux-bluetooth/[email protected]/ Fixes: 0614974 ("Bluetooth: hci_conn: Add support for linking multiple hcon") Signed-off-by: Ruihan Li <[email protected]> Signed-off-by: Luiz Augusto von Dentz <[email protected]> Reported-by: [email protected] Reported-by: Luiz Augusto von Dentz <[email protected]> Reported-by: [email protected]
1 parent 9025944 commit ca1fd42

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

net/bluetooth/hci_conn.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,8 +1083,18 @@ static void hci_conn_unlink(struct hci_conn *conn)
10831083
if (!conn->parent) {
10841084
struct hci_link *link, *t;
10851085

1086-
list_for_each_entry_safe(link, t, &conn->link_list, list)
1087-
hci_conn_unlink(link->conn);
1086+
list_for_each_entry_safe(link, t, &conn->link_list, list) {
1087+
struct hci_conn *child = link->conn;
1088+
1089+
hci_conn_unlink(child);
1090+
1091+
/* Due to race, SCO connection might be not established
1092+
* yet at this point. Delete it now, otherwise it is
1093+
* possible for it to be stuck and can't be deleted.
1094+
*/
1095+
if (child->handle == HCI_CONN_HANDLE_UNSET)
1096+
hci_conn_del(child);
1097+
}
10881098

10891099
return;
10901100
}
@@ -1100,13 +1110,6 @@ static void hci_conn_unlink(struct hci_conn *conn)
11001110

11011111
kfree(conn->link);
11021112
conn->link = NULL;
1103-
1104-
/* Due to race, SCO connection might be not established
1105-
* yet at this point. Delete it now, otherwise it is
1106-
* possible for it to be stuck and can't be deleted.
1107-
*/
1108-
if (conn->handle == HCI_CONN_HANDLE_UNSET)
1109-
hci_conn_del(conn);
11101113
}
11111114

11121115
int hci_conn_del(struct hci_conn *conn)

0 commit comments

Comments
 (0)