Skip to content

Commit e2cb6b8

Browse files
f0rm2l1ngregkh
authored andcommitted
bluetooth: eliminate the potential race condition when removing the HCI controller
There is a possible race condition vulnerability between issuing a HCI command and removing the cont. Specifically, functions hci_req_sync() and hci_dev_do_close() can race each other like below: thread-A in hci_req_sync() | thread-B in hci_dev_do_close() | hci_req_sync_lock(hdev); test_bit(HCI_UP, &hdev->flags); | ... | test_and_clear_bit(HCI_UP, &hdev->flags) hci_req_sync_lock(hdev); | | In this commit we alter the sequence in function hci_req_sync(). Hence, the thread-A cannot issue th. Signed-off-by: Lin Ma <[email protected]> Cc: Marcel Holtmann <[email protected]> Fixes: 7c6a329 ("[Bluetooth] Fix regression from using default link policy") Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 9204ff9 commit e2cb6b8

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

net/bluetooth/hci_request.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -272,12 +272,16 @@ int hci_req_sync(struct hci_dev *hdev, int (*req)(struct hci_request *req,
272272
{
273273
int ret;
274274

275-
if (!test_bit(HCI_UP, &hdev->flags))
276-
return -ENETDOWN;
277-
278275
/* Serialize all requests */
279276
hci_req_sync_lock(hdev);
280-
ret = __hci_req_sync(hdev, req, opt, timeout, hci_status);
277+
/* check the state after obtaing the lock to protect the HCI_UP
278+
* against any races from hci_dev_do_close when the controller
279+
* gets removed.
280+
*/
281+
if (test_bit(HCI_UP, &hdev->flags))
282+
ret = __hci_req_sync(hdev, req, opt, timeout, hci_status);
283+
else
284+
ret = -ENETDOWN;
281285
hci_req_sync_unlock(hdev);
282286

283287
return ret;

0 commit comments

Comments
 (0)