* [PATCH] Bluetooth: hci_sock: Serialize dead-device detachment
@ 2026-10-04 16:24 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:24 UTC (permalink / raw)
To: Marcel Holtmann, Luiz Augusto von Dentz, Tetsuo Handa
Cc: linux-bluetooth, linux-kernel, Chengfeng Ye, stable
Rebinding an HCI socket after its controller is unregistered can race
monitor control replay and crash the kernel. hci_sock_bind() clears
hci_pi(sk)->hdev and drops the device reference under only the socket
lock, whereas send_monitor_control_replay() holds hci_sk_list.lock for
reading.
Replay can observe a non-NULL hdev, then bind can clear it and drop the
last reference before create_monitor_ctrl_open() reads hdev->id. This
can cause a NULL pointer dereference if the pointer is reloaded, or a
use-after-free if the old pointer is retained.
The kernel reported:
KASAN: null-ptr-deref in range [0x0000000000000068-0x000000000000006f]
RIP: 0010:create_monitor_ctrl_open+0x579/0x800
Call Trace:
hci_sock_bind+0xd96/0x1190
__sys_bind+0x166/0x200
__x64_sys_bind+0x6d/0xb0
do_syscall_64+0xdd/0x4a0
entry_SYSCALL_64_after_hwframe+0x77/0x7f
The same missing serialization lets hci_send_to_sock() select a socket
for the old device and queue its frame after bind has detached the socket
or installed a new binding.
Take hci_sk_list.lock for writing when clearing the device pointer and
resetting the socket state. This waits for existing replay and delivery
readers to finish before detachment and prevents later readers from
using the old binding. Keep hci_dev_put() outside the critical section
because the final device release can sleep.
Fixes: e04480920d1e ("Bluetooth: defer cleanup of resources in hci_unregister_dev()")
Cc: stable@vger.kernel.org
Assisted-by: GPT-6 Astra
Signed-off-by: Chengfeng Ye <nicoyip.dev@gmail.com>
---
net/bluetooth/hci_sock.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
index 6d56c77741e1..81068b585764 100644
--- a/net/bluetooth/hci_sock.c
+++ b/net/bluetooth/hci_sock.c
@@ -1223,8 +1223,10 @@ static int hci_sock_bind(struct socket *sock, struct sockaddr_unsized *addr,
*/
hdev = hci_pi(sk)->hdev;
if (hdev && hci_dev_test_flag(hdev, HCI_UNREGISTER)) {
+ write_lock(&hci_sk_list.lock);
hci_pi(sk)->hdev = NULL;
sk->sk_state = BT_OPEN;
+ write_unlock(&hci_sk_list.lock);
hci_dev_put(hdev);
}
hdev = NULL;
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* RE: Bluetooth: hci_sock: Serialize dead-device detachment
2026-10-04 16:24 [PATCH] Bluetooth: hci_sock: Serialize dead-device detachment 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/1179168/
---Test result---
Test Summary:
CheckPatch PASS 0.53 seconds
VerifyFixes PASS 0.11 seconds
VerifySignedoff PASS 0.11 seconds
GitLint PASS 0.47 seconds
SubjectPrefix PASS 0.10 seconds
BuildKernel PASS 17.93 seconds
CheckAllWarning PASS 21.07 seconds
CheckSparse PASS 22.36 seconds
BuildKernel32 PASS 18.78 seconds
CheckKernelLLVM PASS 20.96 seconds
TestRunnerSetup PASS 461.36 seconds
TestRunner_l2cap-tester PASS 12.94 seconds
TestRunner_iso-tester PASS 8.82 seconds
TestRunner_bnep-tester PASS 2.76 seconds
TestRunner_mgmt-tester PASS 54.49 seconds
TestRunner_rfcomm-tester PASS 3.97 seconds
TestRunner_sco-tester PASS 4.95 seconds
TestRunner_ioctl-tester PASS 4.09 seconds
TestRunner_mesh-tester FAIL 7.91 seconds
TestRunner_smp-tester PASS 3.91 seconds
TestRunner_userchan-tester PASS 2.80 seconds
TestRunner_6lowpan-tester PASS 3.96 seconds
IncrementalBuild PASS 18.58 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.709 seconds
Mesh - Send cancel - 2 Timed out 2.000 seconds
https://github.com/bluez/bluetooth-next/pull/855
---
Regards,
Linux Bluetooth
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Bluetooth: hci_sock: Serialize dead-device detachment
2026-10-04 16:24 [PATCH] Bluetooth: hci_sock: Serialize dead-device detachment 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, penguin-kernel, 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:24:42 +0800 you wrote:
> Rebinding an HCI socket after its controller is unregistered can race
> monitor control replay and crash the kernel. hci_sock_bind() clears
> hci_pi(sk)->hdev and drops the device reference under only the socket
> lock, whereas send_monitor_control_replay() holds hci_sk_list.lock for
> reading.
>
> Replay can observe a non-NULL hdev, then bind can clear it and drop the
> last reference before create_monitor_ctrl_open() reads hdev->id. This
> can cause a NULL pointer dereference if the pointer is reloaded, or a
> use-after-free if the old pointer is retained.
>
> [...]
Here is the summary with links:
- Bluetooth: hci_sock: Serialize dead-device detachment
https://git.kernel.org/bluetooth/bluetooth-next/c/381a0925c556
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:24 [PATCH] Bluetooth: hci_sock: Serialize dead-device detachment 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.