From: Zheng Shuhao <viennaoffh@gmail.com>
To: linux-bluetooth@vger.kernel.org
Cc: marcel@holtmann.org, luiz.dentz@gmail.com, linux-kernel@vger.kernel.org
Subject: [PATCH] Bluetooth: hci_sync: invoke destroy callbacks outside lock
Date: Sat, 21 Nov 2026 20:01:20 +0800 [thread overview]
Message-ID: <20261121120121.576-1-viennaoffh@gmail.com> (raw)
hci_cmd_sync_clear() cancels queued command-sync entries while holding
cmd_sync_work_lock. Cancellation invokes entry->destroy(), and
add_ext_adv_params_complete() takes hdev->lock. In the opposite direction,
le_conn_complete_evt() holds hdev->lock while hci_update_passive_scan()
queues work and acquires cmd_sync_work_lock. This creates the circular
locking dependency reported by lockdep during controller teardown.
Detach the queued entries to a local list under cmd_sync_work_lock, then
run the cancellation callbacks after releasing the mutex. This keeps
queue updates serialized without invoking callbacks under the mutex.
Testing:
- Lockdep-enabled QEMU baseline: reproducer completed twice and emitted
the circular-locking warning once.
- Patched QEMU kernel: reproducer completed five times with no such
warning.
- Bluetooth ECDH and SMP self-tests passed in both kernels.
- Both kernels built; baseline build logged a timestamp clock-skew
warning. checkpatch.pl --strict reported no errors or warnings.
Fixes: 1c66bee492a5 ("Bluetooth: Fix race condition in hci_cmd_sync_clear")
Reported-by: syzbot+fc55a609cd9deea4ea37@syzkaller.appspotmail.com
Link: https://syzkaller.appspot.com/bug?extid=fc55a609cd9deea4ea37
Signed-off-by: Zheng Shuhao <viennaoffh@gmail.com>
diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c
index ea2014e74..65b8aa4ad 100644
--- a/net/bluetooth/hci_sync.c
+++ b/net/bluetooth/hci_sync.c
@@ -683,6 +683,7 @@ static void _hci_cmd_sync_cancel_entry(struct hci_dev *hdev,
void hci_cmd_sync_clear(struct hci_dev *hdev)
{
+ LIST_HEAD(cancel_list);
struct hci_cmd_sync_work_entry *entry, *tmp;
/* cmd_work is disabled, the pending request can only time out */
@@ -690,10 +691,13 @@ void hci_cmd_sync_clear(struct hci_dev *hdev)
cancel_work_sync(&hdev->cmd_sync_work);
cancel_work_sync(&hdev->reenable_adv_work);
+ /* Run destroy callbacks without holding cmd_sync_work_lock. */
mutex_lock(&hdev->cmd_sync_work_lock);
- list_for_each_entry_safe(entry, tmp, &hdev->cmd_sync_work_list, list)
- _hci_cmd_sync_cancel_entry(hdev, entry, -ECANCELED);
+ list_splice_init(&hdev->cmd_sync_work_list, &cancel_list);
mutex_unlock(&hdev->cmd_sync_work_lock);
+
+ list_for_each_entry_safe(entry, tmp, &cancel_list, list)
+ _hci_cmd_sync_cancel_entry(hdev, entry, -ECANCELED);
}
void hci_cmd_sync_cancel(struct hci_dev *hdev, int err)
reply other threads:[~2026-11-21 12:01 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261121120121.576-1-viennaoffh@gmail.com \
--to=viennaoffh@gmail.com \
--cc=linux-bluetooth@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luiz.dentz@gmail.com \
--cc=marcel@holtmann.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®