]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
Bluetooth: fix memory leak in error path of hci_alloc_dev()
authorBharath Reddy <kbreddy.rpbc@gmail.com>
Mon, 1 Jun 2026 03:24:26 +0000 (08:54 +0530)
committerLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Wed, 3 Jun 2026 15:22:28 +0000 (11:22 -0400)
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>
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
net/bluetooth/hci_sysfs.c

index 041ce9adc378aed590288a0d52cc864c0fcf3c92..8957ce7c21b76c4190ae073e42c131cc11fe8b88 100644 (file)
@@ -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);
 }