[PATCH v2 3/3] Bluetooth: hci_sync: Disable connection works before draining

From: Jeremy Dean Clifton

Date: Mon Nov 16 2026 - 21:36:09 EST


A connection delayed work whose timer was armed before
hci_dev_close_sync() can expire while drain_workqueue() runs.
delayed_work_timer_fn() then queues it on the draining workqueue and
triggers the "cannot queue ... on wq" warning. hci_conn_drop() can also
queue disc_work from another context during the drain.

Disable the per-connection delayed works under hdev->lock before
draining. A disabled work is cancelled and any later attempt to queue
it fails, so neither the timers nor hci_conn_drop() can queue it. The
connections are deleted by hci_conn_hash_flush() below, so nothing
needs to re-enable the works.

Fixes: 76727c02c1e1 ("Bluetooth: Call drain_workqueue() before resetting state")
Reported-by: syzbot+5897b3c764f5989ea942@xxxxxxxxxxxxxxxxxxxxxxxxx
Closes: https://syzkaller.appspot.com/bug?extid=5897b3c764f5989ea942
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Jeremy Dean Clifton <deaner92@xxxxxxxxx>
---
net/bluetooth/hci_sync.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)

diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c
index 931494348325..3fe179d649d0 100644
--- a/net/bluetooth/hci_sync.c
+++ b/net/bluetooth/hci_sync.c
@@ -6012,6 +6012,7 @@ static int hci_dev_shutdown(struct hci_dev *hdev)

int hci_dev_close_sync(struct hci_dev *hdev)
{
+ struct hci_conn *conn;
bool auto_off;
int err = 0;

@@ -6079,6 +6080,22 @@ int hci_dev_close_sync(struct hci_dev *hdev)
cancel_delayed_work_sync(&adv_instance->rpa_expired_cb);
}

+ /* A delayed work whose timer was armed before close would queue
+ * itself while the workqueue is draining. Disable the connection
+ * works so that hci_conn_drop() and the timers can no longer queue
+ * them. The connections are deleted below, so nothing re-enables
+ * them. HCI_UP is clear, so no new connection can be added after
+ * this walk.
+ */
+ hci_dev_lock(hdev);
+ list_for_each_entry(conn, &hdev->conn_hash.list, list) {
+ disable_delayed_work(&conn->disc_work);
+ disable_delayed_work(&conn->auto_accept_work);
+ disable_delayed_work(&conn->idle_work);
+ disable_delayed_work(&conn->le_conn_timeout);
+ }
+ hci_dev_unlock(hdev);
+
/* Avoid potential lockdep warnings from the *_flush() calls by
* ensuring the workqueue is empty up front.
*/
--
2.43.0