* [PATCH v4] Bluetooth: fix memory leak in error path of hci_alloc_dev()
@ 2026-05-31 18:53 Bharath Reddy
2026-05-31 19:32 ` [v4] " bluez.test.bot
0 siblings, 1 reply; 2+ messages in thread
From: Bharath Reddy @ 2026-05-31 18:53 UTC (permalink / raw)
To: marcel, luiz.dentz
Cc: linux-bluetooth, linux-kernel, syzkaller-bugs, Bharath Reddy,
syzbot+535ecc844591e50588a5
Early failures in Bluetooth HCI UART configuration leak SRCU percpu
memory.
When device initialization fails before hci_register_dev() completes,
the HCI_UNREGISTER flag is never set. As a result, when the device
reference count reaches zero, bt_host_release() evaluates this flag as
false and falls back to a direct kfree(hdev).
Because hci_release_dev() is bypassed, the SRCU struct initialized
early in hci_alloc_dev() is never cleaned up, resulting in a leak of
percpu memory.
Fix the leak by explicitly calling cleanup_srcu_struct() in the
fallback (unregistered) branch of bt_host_release() before freeing
the device.
Reported-by: syzbot+535ecc844591e50588a5@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=535ecc844591e50588a5
Tested-by: syzbot+535ecc844591e50588a5@syzkaller.appspotmail.com
Fixes: 1d6123102e9f ("Bluetooth: hci_core: Fix use-after-free in vhci_flush()")
Signed-off-by: Bharath Reddy <kbreddy.rpbc@gmail.com>
---
Changes in v4:
- Include patch version history.
Changes in v3:
- Added missing curly braces to the if/else block in bt_host_release()
to resolve a checkpatch.pl warning.
- Added Fixes and Closes tags.
Changes in v2:
- Fixed a NULL pointer dereference caused by v1.
- Moved cleanup_srcu_struct() to the fallback (unregistered) branch
of bt_host_release() instead of unconditionally calling hci_release_dev().
Changes in v1:
- Initial patch (failed because it bypassed the HCI_UNREGISTER check).
net/bluetooth/hci_sysfs.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/net/bluetooth/hci_sysfs.c b/net/bluetooth/hci_sysfs.c
index 041ce9adc378..8957ce7c21b7 100644
--- a/net/bluetooth/hci_sysfs.c
+++ b/net/bluetooth/hci_sysfs.c
@@ -83,10 +83,12 @@ static void bt_host_release(struct device *dev)
{
struct hci_dev *hdev = to_hci_dev(dev);
- if (hci_dev_test_flag(hdev, HCI_UNREGISTER))
+ if (hci_dev_test_flag(hdev, HCI_UNREGISTER)) {
hci_release_dev(hdev);
- else
+ } else {
+ cleanup_srcu_struct(&hdev->srcu);
kfree(hdev);
+ }
module_put(THIS_MODULE);
}
--
2.34.1
^ permalink raw reply related [flat|nested] 2+ messages in thread* RE: [v4] Bluetooth: fix memory leak in error path of hci_alloc_dev()
2026-05-31 18:53 [PATCH v4] Bluetooth: fix memory leak in error path of hci_alloc_dev() Bharath Reddy
@ 2026-05-31 19:32 ` bluez.test.bot
0 siblings, 0 replies; 2+ messages in thread
From: bluez.test.bot @ 2026-05-31 19:32 UTC (permalink / raw)
To: linux-bluetooth, kbreddy.rpbc
[-- Attachment #1: Type: text/plain, Size: 2659 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=1103659
---Test result---
Test Summary:
CheckPatch PASS 0.75 seconds
VerifyFixes PASS 0.14 seconds
VerifySignedoff PASS 0.14 seconds
GitLint FAIL 0.34 seconds
SubjectPrefix PASS 0.14 seconds
BuildKernel PASS 24.71 seconds
CheckAllWarning PASS 27.34 seconds
CheckSparse PASS 26.77 seconds
BuildKernel32 PASS 24.39 seconds
TestRunnerSetup PASS 521.61 seconds
TestRunner_l2cap-tester PASS 58.27 seconds
TestRunner_iso-tester PASS 71.09 seconds
TestRunner_bnep-tester PASS 19.01 seconds
TestRunner_mgmt-tester FAIL 210.04 seconds
TestRunner_rfcomm-tester PASS 25.47 seconds
TestRunner_sco-tester PASS 32.52 seconds
TestRunner_ioctl-tester PASS 25.65 seconds
TestRunner_mesh-tester FAIL 25.96 seconds
TestRunner_smp-tester PASS 23.39 seconds
TestRunner_userchan-tester PASS 19.79 seconds
TestRunner_6lowpan-tester PASS 22.57 seconds
IncrementalBuild PASS 23.69 seconds
Details
##############################
Test: GitLint - FAIL
Desc: Run gitlint
Output:
[v4] Bluetooth: fix memory leak in error path of hci_alloc_dev()
27: B2 Line has trailing whitespace: " - Added missing curly braces to the if/else block in bt_host_release() "
32: B2 Line has trailing whitespace: " - Fixed a NULL pointer dereference caused by v1. "
33: B2 Line has trailing whitespace: " - Moved cleanup_srcu_struct() to the fallback (unregistered) branch "
##############################
Test: TestRunner_mgmt-tester - FAIL
Desc: Run mgmt-tester with test-runner
Output:
Total: 494, Passed: 489 (99.0%), Failed: 1, Not Run: 4
Failed Test Cases
Read Exp Feature - Success Failed 0.246 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.303 seconds
Mesh - Send cancel - 2 Timed out 1.995 seconds
https://github.com/bluez/bluetooth-next/pull/261
---
Regards,
Linux Bluetooth
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-05-31 19:32 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-31 18:53 [PATCH v4] Bluetooth: fix memory leak in error path of hci_alloc_dev() Bharath Reddy
2026-05-31 19:32 ` [v4] " bluez.test.bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox