path: root/net/bluetooth/hci_sock.c
diff options
authorMyungho Jung <>2019-02-02 16:56:36 -0800
committerMarcel Holtmann <>2019-02-04 15:43:46 +0100
commite20a2e9c42c9e4002d9e338d74e7819e88d77162 (patch)
tree6eb84aa6bbd338c29e827c6d6ff0d3f115f4c653 /net/bluetooth/hci_sock.c
parent017a01ccfbc5a35aed83acbf2ee2735f8c3efe8a (diff)
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: Signed-off-by: Myungho Jung <> Signed-off-by: Marcel Holtmann <>
Diffstat (limited to 'net/bluetooth/hci_sock.c')
1 files changed, 1 insertions, 2 deletions
diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
index 1506e1632394..d4e2a166ae17 100644
--- a/net/bluetooth/hci_sock.c
+++ b/net/bluetooth/hci_sock.c
@@ -831,8 +831,6 @@ static int hci_sock_release(struct socket *sock)
if (!sk)
return 0;
- hdev = hci_pi(sk)->hdev;
switch (hci_pi(sk)->channel) {
@@ -854,6 +852,7 @@ static int hci_sock_release(struct socket *sock)
bt_sock_unlink(&hci_sk_list, sk);
+ hdev = hci_pi(sk)->hdev;
if (hdev) {
if (hci_pi(sk)->channel == HCI_CHANNEL_USER) {
/* When releasing a user channel exclusive access,