Bluetooth: Fix race condition in hci_release_sock()
authorDan Carpenter <dan.carpenter@oracle.com>
Wed, 15 Jan 2020 17:49:04 +0000 (20:49 +0300)
committerJohan Hedberg <johan.hedberg@intel.com>
Sun, 26 Jan 2020 08:34:17 +0000 (10:34 +0200)
commit11eb85ec42dc8c7a7ec519b90ccf2eeae9409de8
treea88ca07a4de1b08600afabe48fb8b92b15b5cc28
parent18f81241b74fb49d576c83fbbab9a0b6e3bb20d4
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: syzbot+eba992608adf3d796bcc@syzkaller.appspotmail.com
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
net/bluetooth/hci_sock.c