Skip to content

Commit e20a2e9

Browse files
myunghojholtmann
authored andcommitted
Bluetooth: Fix decrementing reference count twice in releasing socket
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]>
1 parent 017a01c commit e20a2e9

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
@@ -831,8 +831,6 @@ static int hci_sock_release(struct socket *sock)
831831
if (!sk)
832832
return 0;
833833

834-
hdev = hci_pi(sk)->hdev;
835-
836834
switch (hci_pi(sk)->channel) {
837835
case HCI_CHANNEL_MONITOR:
838836
atomic_dec(&monitor_promisc);
@@ -854,6 +852,7 @@ static int hci_sock_release(struct socket *sock)
854852

855853
bt_sock_unlink(&hci_sk_list, sk);
856854

855+
hdev = hci_pi(sk)->hdev;
857856
if (hdev) {
858857
if (hci_pi(sk)->channel == HCI_CHANNEL_USER) {
859858
/* When releasing a user channel exclusive access,

0 commit comments

Comments
 (0)