Skip to content

Commit 09b0cd1

Browse files
Cen ZhangVudentz
authored andcommitted
Bluetooth: hci_sync: fix race in hci_cmd_sync_dequeue_once
hci_cmd_sync_dequeue_once() does lookup and then cancel the entry under two separate lock sections. Meanwhile, hci_cmd_sync_work() can also delete the same entry, leading to double list_del() and "UAF". Fix this by holding cmd_sync_work_lock across both lookup and cancel, so that the entry cannot be removed concurrently. Fixes: 505ea2b ("Bluetooth: hci_sync: Add helper functions to manipulate cmd_sync queue") Reported-by: Cen Zhang <zzzccc427@163.com> Signed-off-by: Cen Zhang <zzzccc427@163.com> Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
1 parent 1ab6658 commit 09b0cd1

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

net/bluetooth/hci_sync.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -863,11 +863,17 @@ bool hci_cmd_sync_dequeue_once(struct hci_dev *hdev,
863863
{
864864
struct hci_cmd_sync_work_entry *entry;
865865

866-
entry = hci_cmd_sync_lookup_entry(hdev, func, data, destroy);
867-
if (!entry)
866+
mutex_lock(&hdev->cmd_sync_work_lock);
867+
868+
entry = _hci_cmd_sync_lookup_entry(hdev, func, data, destroy);
869+
if (!entry) {
870+
mutex_unlock(&hdev->cmd_sync_work_lock);
868871
return false;
872+
}
869873

870-
hci_cmd_sync_cancel_entry(hdev, entry);
874+
_hci_cmd_sync_cancel_entry(hdev, entry, -ECANCELED);
875+
876+
mutex_unlock(&hdev->cmd_sync_work_lock);
871877

872878
return true;
873879
}

0 commit comments

Comments
 (0)