Skip to content

Commit 11eb85e

Browse files
Dan CarpenterJohan Hedberg
authored andcommitted
Bluetooth: Fix race condition in hci_release_sock()
Syzbot managed to trigger a use after free "KASAN: use-after-free Write in hci_sock_bind". I have reviewed the code manually and one possibly cause I have found is that we are not holding lock_sock(sk) when we do the hci_dev_put(hdev) in hci_sock_release(). My theory is that the bind and the release are racing against each other which results in this use after free. Reported-by: [email protected] Signed-off-by: Dan Carpenter <[email protected]> Signed-off-by: Johan Hedberg <[email protected]>
1 parent 18f8124 commit 11eb85e

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

net/bluetooth/hci_sock.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,8 @@ static int hci_sock_release(struct socket *sock)
839839
if (!sk)
840840
return 0;
841841

842+
lock_sock(sk);
843+
842844
switch (hci_pi(sk)->channel) {
843845
case HCI_CHANNEL_MONITOR:
844846
atomic_dec(&monitor_promisc);
@@ -886,6 +888,7 @@ static int hci_sock_release(struct socket *sock)
886888
skb_queue_purge(&sk->sk_receive_queue);
887889
skb_queue_purge(&sk->sk_write_queue);
888890

891+
release_sock(sk);
889892
sock_put(sk);
890893
return 0;
891894
}

0 commit comments

Comments
 (0)