Re: [PATCH] Bluetooth: hci_sync: fix race in hci_cmd_sync_dequeue_once

From: Markus Elfring

Date: Sun Sep 28 2025 - 07:52:22 EST


> 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".

You may occasionally put more than 55 characters into text lines
of such a change description.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.17-rc7#n658


> Fix this by holding cmd_sync_work_lock across both
> lookup and cancel, so that the entry cannot be removed
> concurrently.

> +++ b/net/bluetooth/hci_sync.c
> @@ -862,12 +862,13 @@ bool hci_cmd_sync_dequeue_once(struct hci_dev *hdev,


* How do you think about to add any tags (like “Fixes” and “Cc”) accordingly?

* Under which circumstances would you become interested to apply a call
like “scoped_guard(mutex, &hdev->cmd_sync_work_lock)”?
https://elixir.bootlin.com/linux/v6.17-rc7/source/include/linux/mutex.h#L228


Regards,
Markus