Skip to content

Commit 4ce61d1

Browse files
Satyam SharmaDavid S. Miller
authored andcommitted
[BLUETOOTH]: Fix locking in hci_sock_dev_event().
We presently use lock_sock() to acquire a lock on a socket in hci_sock_dev_event(), but this goes BUG because lock_sock() can sleep and we're already holding a read-write spinlock at that point. So, we must use the non-sleeping BH version, bh_lock_sock(). However, hci_sock_dev_event() is called from user context and hence using simply bh_lock_sock() will deadlock against a concurrent softirq that tries to acquire a lock on the same socket. Hence, disabling BH's before acquiring the socket lock and enable them afterwards, is the proper solution to fix socket locking in hci_sock_dev_event(). Signed-off-by: Satyam Sharma <[email protected]> Signed-off-by: Marcel Holtmann <[email protected]> Signed-off-by: Jiri Kosina <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 689d794 commit 4ce61d1

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

net/bluetooth/hci_sock.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,8 @@ static int hci_sock_dev_event(struct notifier_block *this, unsigned long event,
665665
/* Detach sockets from device */
666666
read_lock(&hci_sk_list.lock);
667667
sk_for_each(sk, node, &hci_sk_list.head) {
668-
lock_sock(sk);
668+
local_bh_disable();
669+
bh_lock_sock_nested(sk);
669670
if (hci_pi(sk)->hdev == hdev) {
670671
hci_pi(sk)->hdev = NULL;
671672
sk->sk_err = EPIPE;
@@ -674,7 +675,8 @@ static int hci_sock_dev_event(struct notifier_block *this, unsigned long event,
674675

675676
hci_dev_put(hdev);
676677
}
677-
release_sock(sk);
678+
bh_unlock_sock(sk);
679+
local_bh_enable();
678680
}
679681
read_unlock(&hci_sk_list.lock);
680682
}

0 commit comments

Comments
 (0)