* [PATCH] Bluetooth: hci_sync: Fix command skb lifetime during scan setup
@ 2026-10-04 16:26 Chengfeng Ye
2026-10-04 18:49 ` bluez.test.bot
2026-10-06 14:30 ` [PATCH] " patchwork-bot+bluetooth
0 siblings, 2 replies; 3+ messages in thread
From: Chengfeng Ye @ 2026-10-04 16:26 UTC (permalink / raw)
To: Marcel Holtmann, Luiz Augusto von Dentz
Cc: linux-bluetooth, linux-kernel, Chengfeng Ye, stable
During PA sync scan setup, hci_le_set_ext_scan_param_sync() gets the
address used for the PA_LINK lookup from hci_sent_cmd_data(). The
returned pointer borrows storage from sent_cmd or req_skb, without
holding a reference to either skb.
The scan worker runs on req_workqueue while hci_cmd_work() runs on the
separate device workqueue. After the scan worker loads sent_cmd, the
command worker can free and replace it before hci_sent_cmd_data()
dereferences the skb. The command payload can also be freed between
returning from the helper and comparing the address. The connection
lookup's RCU critical section does not protect the command skb.
KASAN reported:
BUG: KASAN: slab-use-after-free in hci_sent_cmd_data+0x27c/0x2f0
Workqueue: hci0 hci_cmd_sync_work
Call Trace:
hci_sent_cmd_data+0x27c/0x2f0
hci_le_set_scan_param_sync+0x43a/0x850
hci_passive_scan_sync+0xb09/0x1460
hci_update_passive_scan_sync+0x47c/0x6e0
hci_le_pa_create_sync+0x200/0xa70
hci_cmd_sync_work+0x13c/0x290
Allocated by task 95:
skb_clone+0x13f/0x340
hci_cmd_work+0x2a9/0x7e0
Freed by task 95:
kmem_cache_free+0xba/0x3a0
hci_cmd_work+0x29c/0x7e0
Use hdev->lock to serialize the address snapshot with sent_cmd
replacement. Protect req_skb replacement and completion cleanup with
the same lock because the helper falls back to that skb. Copy the
address before releasing the lock and use the copy for the existing
RCU-protected connection lookup. Release the mutex before sending or
waiting for commands, preserving the lookup and completion ordering.
Fixes: 22cbf4f84c00 ("Bluetooth: hci_sync: Use QoS to determine which PHY to scan")
Cc: stable@vger.kernel.org
Assisted-by: GPT-6 Astra
Signed-off-by: Chengfeng Ye <nicoyip.dev@gmail.com>
---
net/bluetooth/hci_core.c | 4 ++++
net/bluetooth/hci_sync.c | 10 +++++++++-
2 files changed, 13 insertions(+), 1 deletion(-)
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 2076689eb302..74d9865e08c2 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -4115,9 +4115,11 @@ static int hci_send_cmd_sync(struct hci_dev *hdev, struct sk_buff *skb)
bt_dev_dbg(hdev, "skb %p", skb);
+ hci_dev_lock(hdev);
kfree_skb(hdev->sent_cmd);
hdev->sent_cmd = skb_clone(skb, GFP_KERNEL);
+ hci_dev_unlock(hdev);
if (!hdev->sent_cmd) {
skb_queue_head(&hdev->cmd_q, skb);
queue_work(hdev->workqueue, &hdev->cmd_work);
@@ -4138,8 +4140,10 @@ static int hci_send_cmd_sync(struct hci_dev *hdev, struct sk_buff *skb)
if (READ_ONCE(hdev->req_status) == HCI_REQ_PEND &&
!hci_dev_test_and_set_flag(hdev, HCI_CMD_PENDING)) {
+ hci_dev_lock(hdev);
kfree_skb(hdev->req_skb);
hdev->req_skb = skb_get(hdev->sent_cmd);
+ hci_dev_unlock(hdev);
}
return err;
diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c
index c01c8b58d9e8..a92a81846e9d 100644
--- a/net/bluetooth/hci_sync.c
+++ b/net/bluetooth/hci_sync.c
@@ -32,8 +32,10 @@ static void hci_cmd_sync_complete(struct hci_dev *hdev, u8 result, u16 opcode,
WRITE_ONCE(hdev->req_status, HCI_REQ_DONE);
/* Free the request command so it is not used as response */
+ hci_dev_lock(hdev);
kfree_skb(hdev->req_skb);
hdev->req_skb = NULL;
+ hci_dev_unlock(hdev);
if (skb) {
struct sock *sk = hci_skb_sk(skb);
@@ -3064,15 +3066,21 @@ static int hci_le_set_ext_scan_param_sync(struct hci_dev *hdev, u8 type,
*/
if (hci_dev_test_flag(hdev, HCI_PA_SYNC)) {
struct hci_cp_le_add_to_accept_list *sent;
+ bdaddr_t bdaddr;
+ hci_dev_lock(hdev);
sent = hci_sent_cmd_data(hdev, HCI_OP_LE_ADD_TO_ACCEPT_LIST);
+ if (sent)
+ bacpy(&bdaddr, &sent->bdaddr);
+ hci_dev_unlock(hdev);
+
if (sent) {
struct hci_conn *conn;
rcu_read_lock();
conn = hci_conn_hash_lookup_ba(hdev, PA_LINK,
- &sent->bdaddr);
+ &bdaddr);
if (conn) {
struct bt_iso_qos *qos = &conn->iso_qos;
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread* RE: Bluetooth: hci_sync: Fix command skb lifetime during scan setup
2026-10-04 16:26 [PATCH] Bluetooth: hci_sync: Fix command skb lifetime during scan setup Chengfeng Ye
@ 2026-10-04 18:49 ` bluez.test.bot
2026-10-06 14:30 ` [PATCH] " patchwork-bot+bluetooth
1 sibling, 0 replies; 3+ messages in thread
From: bluez.test.bot @ 2026-10-04 18:49 UTC (permalink / raw)
To: linux-bluetooth, nicoyip.dev
[-- Attachment #1: Type: text/plain, Size: 1957 bytes --]
This is automated email and please do not reply to this email!
Dear submitter,
Thank you for submitting the patches to the linux bluetooth mailing list.
This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/series/1179171/
---Test result---
Test Summary:
CheckPatch PASS 0.62 seconds
VerifyFixes PASS 0.09 seconds
VerifySignedoff PASS 0.09 seconds
GitLint PASS 0.24 seconds
SubjectPrefix PASS 0.09 seconds
BuildKernel PASS 18.41 seconds
CheckAllWarning PASS 21.25 seconds
CheckSparse PASS 21.98 seconds
BuildKernel32 PASS 18.26 seconds
CheckKernelLLVM PASS 20.64 seconds
TestRunnerSetup PASS 442.44 seconds
TestRunner_l2cap-tester PASS 12.86 seconds
TestRunner_iso-tester PASS 8.80 seconds
TestRunner_bnep-tester PASS 2.69 seconds
TestRunner_mgmt-tester PASS 54.09 seconds
TestRunner_rfcomm-tester PASS 3.94 seconds
TestRunner_sco-tester PASS 4.87 seconds
TestRunner_ioctl-tester PASS 3.99 seconds
TestRunner_mesh-tester FAIL 8.09 seconds
TestRunner_smp-tester PASS 3.91 seconds
TestRunner_userchan-tester PASS 2.78 seconds
TestRunner_6lowpan-tester PASS 3.94 seconds
IncrementalBuild PASS 20.61 seconds
Details
##############################
Test: TestRunner_mesh-tester - FAIL
Desc: Run mesh-tester with test-runner
Output:
Total: 10, Passed: 8 (80.0%), Failed: 2, Not Run: 0
Failed Test Cases
Mesh - Send cancel - 1 Timed out 2.698 seconds
Mesh - Send cancel - 2 Timed out 1.999 seconds
https://github.com/bluez/bluetooth-next/pull/858
---
Regards,
Linux Bluetooth
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Bluetooth: hci_sync: Fix command skb lifetime during scan setup
2026-10-04 16:26 [PATCH] Bluetooth: hci_sync: Fix command skb lifetime during scan setup Chengfeng Ye
2026-10-04 18:49 ` bluez.test.bot
@ 2026-10-06 14:30 ` patchwork-bot+bluetooth
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+bluetooth @ 2026-10-06 14:30 UTC (permalink / raw)
To: Chengfeng Ye; +Cc: marcel, luiz.dentz, linux-bluetooth, linux-kernel, stable
Hello:
This patch was applied to bluetooth/bluetooth-next.git (master)
by Luiz Augusto von Dentz <luiz.von.dentz@intel.com>:
On Mon, 5 Oct 2026 00:26:12 +0800 you wrote:
> During PA sync scan setup, hci_le_set_ext_scan_param_sync() gets the
> address used for the PA_LINK lookup from hci_sent_cmd_data(). The
> returned pointer borrows storage from sent_cmd or req_skb, without
> holding a reference to either skb.
>
> The scan worker runs on req_workqueue while hci_cmd_work() runs on the
> separate device workqueue. After the scan worker loads sent_cmd, the
> command worker can free and replace it before hci_sent_cmd_data()
> dereferences the skb. The command payload can also be freed between
> returning from the helper and comparing the address. The connection
> lookup's RCU critical section does not protect the command skb.
>
> [...]
Here is the summary with links:
- Bluetooth: hci_sync: Fix command skb lifetime during scan setup
https://git.kernel.org/bluetooth/bluetooth-next/c/9af12272061d
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-10-06 14:30 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-04 16:26 [PATCH] Bluetooth: hci_sync: Fix command skb lifetime during scan setup Chengfeng Ye
2026-10-04 18:49 ` bluez.test.bot
2026-10-06 14:30 ` [PATCH] " patchwork-bot+bluetooth
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.