Skip to content

Commit

Permalink
Bluetooth: Fix race condition in hci_release_sock()
Browse files Browse the repository at this point in the history
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: syzbot+eba992608adf3d796bcc@syzkaller.appspotmail.com
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
  • Loading branch information
Dan Carpenter authored and Johan Hedberg committed Jan 26, 2020
1 parent 18f8124 commit 11eb85e
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions net/bluetooth/hci_sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,8 @@ static int hci_sock_release(struct socket *sock)
if (!sk)
return 0;

lock_sock(sk);

switch (hci_pi(sk)->channel) {
case HCI_CHANNEL_MONITOR:
atomic_dec(&monitor_promisc);
Expand Down Expand Up @@ -886,6 +888,7 @@ static int hci_sock_release(struct socket *sock)
skb_queue_purge(&sk->sk_receive_queue);
skb_queue_purge(&sk->sk_write_queue);

release_sock(sk);
sock_put(sk);
return 0;
}
Expand Down

0 comments on commit 11eb85e

Please sign in to comment.