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: syzbot+690b90b14f14f43f4688@syzkaller.appspotmail.com Closes: https://lore.kernel.org/linux-bluetooth/000000000000484a8205faafe216@google.com/ Fixes: 0614974 ("Bluetooth: hci_conn: Add support for linking multiple hcon") Signed-off-by: Ruihan Li <lrh2000@pku.edu.cn> Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com> Reported-by: syzbot+690b90b14f14f43f4688@syzkaller.appspotmail.com Reported-by: Luiz Augusto von Dentz <luiz.dentz@gmail.com> Reported-by: syzbot+8bb72f86fc823817bc5d@syzkaller.appspotmail.com
1 parent 9025944 commit ca1fd42

1 file changed

Lines changed: 12 additions & 9 deletions

File tree

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)