[<prev] [next>] [day] [month] [year] [list]
Message-ID: <20250929053017.148216-1-zzzccc427@163.com>
Date: Mon, 29 Sep 2025 05:30:17 +0000
From: Cen Zhang <zzzccc427@....com>
To: Luiz Augusto von Dentz <luiz.dentz@...il.com>,
pav@....fi
Cc: linux-kernel@...r.kernel.org,
linux-bluetooth@...r.kernel.org,
Cen Zhang <zzzccc427@....com>
Subject: [PATCH v2] 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.
Reported-by: Cen Zhang <zzzccc427@....com>
Signed-off-by: Cen Zhang <zzzccc427@....com>
---
v2:
- Add missing unlock when entry == NULL (suggested by Pauli Virtanen).
---
net/bluetooth/hci_sync.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c
index b6f888d83..23a7fbec3 100644
--- a/net/bluetooth/hci_sync.c
+++ b/net/bluetooth/hci_sync.c
@@ -862,12 +862,15 @@ bool hci_cmd_sync_dequeue_once(struct hci_dev *hdev,
void *data, hci_cmd_sync_work_destroy_t destroy)
{
struct hci_cmd_sync_work_entry *entry;
-
- entry = hci_cmd_sync_lookup_entry(hdev, func, data, destroy);
- if (!entry)
+ mutex_lock(&hdev->cmd_sync_work_lock);
+ entry = _hci_cmd_sync_lookup_entry(hdev, func, data, destroy);
+ if (!entry){
+ mutex_unlock(&hdev->cmd_sync_work_lock);
return false;
+ }
- hci_cmd_sync_cancel_entry(hdev, entry);
+ _hci_cmd_sync_cancel_entry(hdev, entry, -ECANCELED);
+ mutex_unlock(&hdev->cmd_sync_work_lock);
return true;
}
--
2.43.0
Powered by blists - more mailing lists