Skip to content

Bluetooth: Fix work queued while hci_dev_close_sync() drains

Jeremy Dean Clifton linux-bluetooth lkml 1 version Applied

Status from this message: This series was applied to bluetooth/bluetooth-next.git (master)

Get series with b4
b4 am [email protected]

Versions newest first

  1. v2 Latest3 patches 1 replyApplied 3/3

Changes in v2 from the cover letter

- Drop the hci_conn_drop() change.
- Add patches 1 and 2.
- Disable the connection works before the drain (patch 3).
- Fixes tag changed from 525daaea459f to 76727c02c1e1.

Patches in v2 All 3 applied

#Subject and filesSizeRepliesApplied
1/3Bluetooth: hci_conn: Free the unset handle when adding a connection failsnet/bluetooth/hci_conn.c+6 -11 replyApplied
2/3Bluetooth: hci_conn: Refuse new connections once HCI_UP is clearednet/bluetooth/hci_conn.c+9 -00 repliesApplied
3/3Bluetooth: hci_sync: Disable connection works before drainingnet/bluetooth/hci_sync.c+17 -00 repliesApplied

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v2 yet.

Read the v2 thread

Cover letter [PATCH v2 0/3] Bluetooth: Fix work queued while hci_dev_close_sync() drains

syzbot reports "workqueue: cannot queue hci_conn_timeout on wq hci0" from hci_conn_drop() while hci_dev_close_sync() runs drain_workqueue().

v1 made hci_conn_drop() skip queueing disc_work while HCI_CMD_DRAIN_WORKQUEUE is set. Sashiko pointed out that this misses two cases: a connection delayed work whose timer was armed before close can still fire during the drain, and a connection created after hci_conn_hash_flush() is never deleted.

v2 drops the hci_conn_drop() change and fixes the cause instead:

- Patch 1 frees the unset handle when __hci_conn_add() fails. The leak already exists on the -ECONNREFUSED and -ENOMEM paths, and patch 2 adds another error return. Sashiko found it while reviewing patch 2.
- Patch 2 makes __hci_conn_add() refuse new connections once HCI_UP is cleared, and asserts that hdev->lock is held. I checked every caller and all of them hold the lock.
- Patch 3 disables the per-connection delayed works before drain_workqueue(), so neither the timers nor hci_conn_drop() can queue them during the drain. It depends on patch 2: without it, a connection added after the walk could still queue its works.

Testing: built on arm64 against bluetooth-next (da3cc02). With KASAN and lockdep enabled, the syzbot C reproducer was run under QEMU/HVF (2 vCPUs), one fresh boot per run:

without this series: 7/12 runs hit "workqueue: cannot queue
hci_conn_timeout on wq hci0"
with this series: 0/12 runs, no other warnings, KASAN or
lockdep reports

Sashiko reviewed the series locally with no critical, high or medium findings.

Claude (Opus 5.5) helped analyze the race, draft the patches and audit the __hci_conn_add() callers for hdev->lock. Sashiko reviewed v1 and this series.

Changes in v2:
- Drop the hci_conn_drop() change.
- Add patches 1 and 2.
- Disable the connection works before the drain (patch 3).
- Fixes tag changed from 525daaea459f to 76727c02c1e1.

v1: https://lore.kernel.org/all/[email protected]/

Jeremy Dean Clifton (3):
Bluetooth: hci_conn: Free the unset handle when adding a connection
fails
Bluetooth: hci_conn: Refuse new connections once HCI_UP is cleared
Bluetooth: hci_sync: Disable connection works before draining

 net/bluetooth/hci_conn.c | 16 +++++++++++++++-
 net/bluetooth/hci_sync.c | 17 +++++++++++++++++
 2 files changed, 32 insertions(+), 1 deletion(-)
Signature · 1 line
2.43.0