Skip to content

Commit 2910431

Browse files
lrh2000Vudentz
authored andcommitted
Bluetooth: Refcnt drop must be placed last in hci_conn_unlink
If hci_conn_put(conn->parent) reduces conn->parent's reference count to zero, it can immediately deallocate conn->parent. At the same time, conn->link->list has its head in conn->parent, causing use-after-free problems in the latter list_del_rcu(&conn->link->list). This problem can be easily solved by reordering the two operations, i.e., first performing the list removal with list_del_rcu and then decreasing the refcnt with hci_conn_put. Reported-by: Luiz Augusto von Dentz <[email protected]> Closes: https://lore.kernel.org/linux-bluetooth/CABBYNZ+1kce8_RJrLNOXd_8=Mdpb=2bx4Nto-hFORk=qiOkoCg@mail.gmail.com/ 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]>
1 parent ca1fd42 commit 2910431

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

net/bluetooth/hci_conn.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,12 +1102,12 @@ static void hci_conn_unlink(struct hci_conn *conn)
11021102
if (!conn->link)
11031103
return;
11041104

1105-
hci_conn_put(conn->parent);
1106-
conn->parent = NULL;
1107-
11081105
list_del_rcu(&conn->link->list);
11091106
synchronize_rcu();
11101107

1108+
hci_conn_put(conn->parent);
1109+
conn->parent = NULL;
1110+
11111111
kfree(conn->link);
11121112
conn->link = NULL;
11131113
}

0 commit comments

Comments
 (0)