Skip to content

Commit 3df00eb

Browse files
myunghojgregkh
authored andcommitted
Bluetooth: Fix decrementing reference count twice in releasing socket
commit e20a2e9 upstream. When releasing socket, it is possible to enter hci_sock_release() and hci_sock_dev_event(HCI_DEV_UNREG) at the same time in different thread. The reference count of hdev should be decremented only once from one of them but if storing hdev to local variable in hci_sock_release() before detached from socket and setting to NULL in hci_sock_dev_event(), hci_dev_put(hdev) is unexpectedly called twice. This is resolved by referencing hdev from socket after bt_sock_unlink() in hci_sock_release(). Reported-by: [email protected] Signed-off-by: Myungho Jung <[email protected]> Signed-off-by: Marcel Holtmann <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 86384a1 commit 3df00eb

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

net/bluetooth/hci_sock.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -826,8 +826,6 @@ static int hci_sock_release(struct socket *sock)
826826
if (!sk)
827827
return 0;
828828

829-
hdev = hci_pi(sk)->hdev;
830-
831829
switch (hci_pi(sk)->channel) {
832830
case HCI_CHANNEL_MONITOR:
833831
atomic_dec(&monitor_promisc);
@@ -849,6 +847,7 @@ static int hci_sock_release(struct socket *sock)
849847

850848
bt_sock_unlink(&hci_sk_list, sk);
851849

850+
hdev = hci_pi(sk)->hdev;
852851
if (hdev) {
853852
if (hci_pi(sk)->channel == HCI_CHANNEL_USER) {
854853
/* When releasing a user channel exclusive access,

0 commit comments

Comments
 (0)