* [PATCH] Bluetooth: hci_sysfs: Fix NULL pointer dereference in device_del()
@ 2026-09-04 12:24 syzbot
2026-09-04 14:27 ` bluez.test.bot
2026-09-04 16:56 ` [PATCH] " patchwork-bot+bluetooth
0 siblings, 2 replies; 3+ messages in thread
From: syzbot @ 2026-09-04 12:24 UTC (permalink / raw)
To: syzkaller-bugs, Krystian Kaniewski, linux-bluetooth,
Luiz Augusto von Dentz, Marcel Holtmann, Dmitry Antipov
Cc: linux-kernel, syzbot
From: Krystian Kaniewski <krystianmkaniewski@gmail.com>
A NULL pointer dereference in klist_put() occurs when a child device (such
as a BNEP network device in bnep_session) is concurrently being
unregistered while hci_conn_del_sysfs() reparents child devices.
This is caused by a race condition between hci_conn_del_sysfs() and
concurrent child device unregistration (e.g. bnep_session calling
unregister_netdev()). During device unregistration, device_del() snapshots
a non-NULL parent pointer. Concurrently, hci_conn_del_sysfs() finds the
child device using device_find_any_child() and calls device_move() to
reparent it to NULL, which removes the node from its parent's klist and
clears knode_parent. Subsequently, device_del() calls
klist_del(&dev->p->knode_parent) using the stale parent snapshot, causing
klist_put() to dereference knode_klist(n)->put on an already removed node,
resulting in a NULL pointer dereference.
This race was introduced by commit 27aabf27fd01 ("Bluetooth: fix
use-after-free in device_for_each_child()"), which replaced
device_find_child(..., __match_tty) with device_find_any_child() in
hci_conn_del_sysfs(). That change was intended to avoid a use-after-free
where conn->dev outlived its parent hdev->dev when child devices held
references to conn->dev, because conn->dev only held a reference to
hdev->dev while registered in sysfs.
Fix the issue properly by taking an explicit reference to the parent device
with get_device(&hdev->dev) in hci_conn_init_sysfs() and dropping it with
put_device(parent) in bt_link_release() when the conn device is freed. This
ensures that hdev->dev remains valid for the entire lifecycle of conn->dev,
resolving the underlying use-after-free. With the parent reference held
properly, restore the __match_tty filter in hci_conn_del_sysfs() so that
device_move() is only invoked on persistent RFCOMM TTY devices as
originally intended, eliminating the race condition with unregistering
network devices.
Fixes: 27aabf27fd01 ("Bluetooth: fix use-after-free in device_for_each_child()")
Assisted-by: Gemini:gemini-3.7-flash syzbot
Reported-by: syzbot+6df45dd3d03e1a9aca96@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=6df45dd3d03e1a9aca96
Link: https://syzkaller.appspot.com/ai_job?id=f1c0e740-db21-40af-a9ff-84db0fd8b8bd
Signed-off-by: Krystian Kaniewski <krystianmkaniewski@gmail.com>
---
diff --git a/net/bluetooth/hci_sysfs.c b/net/bluetooth/hci_sysfs.c
index 8957ce7c2..c2065abf7 100644
--- a/net/bluetooth/hci_sysfs.c
+++ b/net/bluetooth/hci_sysfs.c
@@ -13,7 +13,10 @@ static const struct class bt_class = {
static void bt_link_release(struct device *dev)
{
struct hci_conn *conn = to_hci_conn(dev);
+ struct device *parent = dev->parent;
+
kfree(conn);
+ put_device(parent);
}
static const struct device_type bt_link = {
@@ -21,6 +24,16 @@ static const struct device_type bt_link = {
.release = bt_link_release,
};
+/*
+ * The rfcomm tty device will possibly retain even when conn
+ * is down, and sysfs doesn't support move zombie device,
+ * so we should move the device before conn device is destroyed.
+ */
+static int __match_tty(struct device *dev, const void *data)
+{
+ return !strncmp(dev_name(dev), "rfcomm", 6);
+}
+
void hci_conn_init_sysfs(struct hci_conn *conn)
{
struct hci_dev *hdev = conn->hdev;
@@ -29,7 +42,7 @@ void hci_conn_init_sysfs(struct hci_conn *conn)
conn->dev.type = &bt_link;
conn->dev.class = &bt_class;
- conn->dev.parent = &hdev->dev;
+ conn->dev.parent = get_device(&hdev->dev);
device_initialize(&conn->dev);
}
@@ -69,7 +82,7 @@ void hci_conn_del_sysfs(struct hci_conn *conn)
while (1) {
struct device *dev;
- dev = device_find_any_child(&conn->dev);
+ dev = device_find_child(&conn->dev, NULL, __match_tty);
if (!dev)
break;
device_move(dev, NULL, DPM_ORDER_DEV_LAST);
base-commit: cee9395acd8043be0644b25c34bfa86623f2b935
--
See https://goo.gle/syzbot-ai-patches for information about AI-generated patches.
The person who has signed off on the patch is responsible for
addressing comments.
syzbot engineers can be reached at syzkaller@googlegroups.com.
^ permalink raw reply related [flat|nested] 3+ messages in thread* RE: Bluetooth: hci_sysfs: Fix NULL pointer dereference in device_del()
2026-09-04 12:24 [PATCH] Bluetooth: hci_sysfs: Fix NULL pointer dereference in device_del() syzbot
@ 2026-09-04 14:27 ` bluez.test.bot
2026-09-04 16:56 ` [PATCH] " patchwork-bot+bluetooth
1 sibling, 0 replies; 3+ messages in thread
From: bluez.test.bot @ 2026-09-04 14:27 UTC (permalink / raw)
To: linux-bluetooth, syzbot
[-- Attachment #1: Type: text/plain, Size: 2390 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/project/bluetooth/list/?series=1158014
---Test result---
Test Summary:
CheckPatch PASS 0.65 seconds
VerifyFixes PASS 0.11 seconds
VerifySignedoff PASS 0.11 seconds
GitLint PASS 0.27 seconds
SubjectPrefix PASS 0.14 seconds
BuildKernel PASS 25.18 seconds
CheckAllWarning PASS 27.84 seconds
CheckSparse PASS 26.18 seconds
BuildKernel32 PASS 24.60 seconds
CheckKernelLLVM SKIP 0.00 seconds
TestRunnerSetup PASS 443.05 seconds
TestRunner_l2cap-tester PASS 68.34 seconds
TestRunner_iso-tester PASS 120.15 seconds
TestRunner_bnep-tester PASS 18.43 seconds
TestRunner_mgmt-tester FAIL 228.15 seconds
TestRunner_rfcomm-tester PASS 25.11 seconds
TestRunner_sco-tester PASS 31.71 seconds
TestRunner_ioctl-tester PASS 25.97 seconds
TestRunner_mesh-tester FAIL 25.05 seconds
TestRunner_smp-tester PASS 22.84 seconds
TestRunner_userchan-tester PASS 19.23 seconds
TestRunner_6lowpan-tester PASS 22.58 seconds
IncrementalBuild PASS 23.17 seconds
Details
##############################
Test: CheckKernelLLVM - SKIP
Desc: Build kernel with LLVM + context analysis
Output:
Clang not found
##############################
Test: TestRunner_mgmt-tester - FAIL
Desc: Run mgmt-tester with test-runner
Output:
Total: 501, Passed: 496 (99.0%), Failed: 1, Not Run: 4
Failed Test Cases
Read Exp Feature - Success Failed 0.256 seconds
##############################
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.028 seconds
Mesh - Send cancel - 2 Timed out 1.984 seconds
https://github.com/bluez/bluetooth-next/pull/706
---
Regards,
Linux Bluetooth
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Bluetooth: hci_sysfs: Fix NULL pointer dereference in device_del()
2026-09-04 12:24 [PATCH] Bluetooth: hci_sysfs: Fix NULL pointer dereference in device_del() syzbot
2026-09-04 14:27 ` bluez.test.bot
@ 2026-09-04 16:56 ` patchwork-bot+bluetooth
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+bluetooth @ 2026-09-04 16:56 UTC (permalink / raw)
To: syzbot
Cc: syzkaller-bugs, krystianmkaniewski, linux-bluetooth, luiz.dentz,
marcel, dmantipov, linux-kernel, syzbot
Hello:
This patch was applied to bluetooth/bluetooth-next.git (master)
by Luiz Augusto von Dentz <luiz.von.dentz@intel.com>:
On Fri, 4 Sep 2026 12:24:22 +0000 (UTC) you wrote:
> From: Krystian Kaniewski <krystianmkaniewski@gmail.com>
>
> A NULL pointer dereference in klist_put() occurs when a child device (such
> as a BNEP network device in bnep_session) is concurrently being
> unregistered while hci_conn_del_sysfs() reparents child devices.
>
> This is caused by a race condition between hci_conn_del_sysfs() and
> concurrent child device unregistration (e.g. bnep_session calling
> unregister_netdev()). During device unregistration, device_del() snapshots
> a non-NULL parent pointer. Concurrently, hci_conn_del_sysfs() finds the
> child device using device_find_any_child() and calls device_move() to
> reparent it to NULL, which removes the node from its parent's klist and
> clears knode_parent. Subsequently, device_del() calls
> klist_del(&dev->p->knode_parent) using the stale parent snapshot, causing
> klist_put() to dereference knode_klist(n)->put on an already removed node,
> resulting in a NULL pointer dereference.
>
> [...]
Here is the summary with links:
- Bluetooth: hci_sysfs: Fix NULL pointer dereference in device_del()
https://git.kernel.org/bluetooth/bluetooth-next/c/21c3501e5f46
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-09-04 16:57 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-04 12:24 [PATCH] Bluetooth: hci_sysfs: Fix NULL pointer dereference in device_del() syzbot
2026-09-04 14:27 ` bluez.test.bot
2026-09-04 16:56 ` [PATCH] " patchwork-bot+bluetooth
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox