Bluetooth: hci_qca: fix use-after-free in ibs debugfs files
PATCH 1/1 Bluetooth: hci_qca: fix use-after-free in ibs debugfs files
qca_debugfs_init() creates an "ibs" directory under hdev->debugfs and stores pointers to fields of struct qca_data in the debugfs files. qca_close() frees qca_data without removing that directory, while hdev->debugfs is only removed when the HCI device is released. The HCI device can outlive the driver data, for example when an HCI socket still references it, so reading or writing one of the ibs files then dereferences freed memory.
Store the directory dentry in struct qca_data and remove the directory with debugfs_remove_recursive() before qca_data is freed. debugfs_remove() waits for callers that are already inside the file operations, and any later access fails with -EIO instead of reaching the debugfs helpers. This covers the two writable files as well.
--- drivers/bluetooth/hci_qca.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/bluetooth/hci_qca.c +5 -0
@@ -161,6 +161,7 @@ struct qca_data {struct delayed_work ctrl_memdump_timeout;struct qca_memdump_info *qca_memdump;unsigned long flags; +struct dentry *debugfs_ibs_dir;struct completion drop_ev_comp;wait_queue_head_t suspend_wait_q;enum qca_memdump_states memdump_state;
@@ -665,6 +666,7 @@ static void qca_debugfs_init(struct hci_dev *hdev)return ; ibs_dir =debugfs_create_dir ("ibs" , hdev->debugfs); + qca->debugfs_ibs_dir = ibs_dir;/* read only */ mode =0444 ;
@@ -744,6 +746,9 @@ static int qca_close(struct hci_uart *hu) hu->priv =NULL ; +debugfs_remove_recursive (qca->debugfs_ibs_dir); + qca->debugfs_ibs_dir =NULL ; +kfree (qca);return 0 ;
Signature · 1 line
2.34.1
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/1202755/
---Test result---
Test Summary:
CheckPatch PASS 0.54 seconds VerifyFixes PASS 0.10 seconds VerifySignedoff PASS 5.49 seconds GitLint PASS 9.75 seconds SubjectPrefix PASS 0.50 seconds BuildKernel PASS 23.24 seconds CheckAllWarning PASS 22.03 seconds CheckSparse PASS 24.64 seconds BuildKernel32 PASS 20.28 seconds CheckKernelLLVM PASS 21.23 seconds TestRunnerSetup PASS 454.56 seconds IncrementalBuild PASS 44.95 seconds
https://github.com/bluez/bluetooth-next/pull/1070
---
Regards,
Linux Bluetooth
Quoted 14 lines · YuanZhe Liu
qca_debugfs_init()creates an "ibs" directory underhdev->debugfsand stores pointers to fields of structqca_datain the debugfs files.qca_close()freesqca_datawithout removing that directory, whilehdev->debugfsis only removed when the HCI device is released. The HCI device can outlive the driver data, for example when an HCI socket still references it, so reading or writing one of the ibs files then dereferences freed memory.Store the directory dentry in struct
qca_dataand remove the directory withdebugfs_remove_recursive()beforeqca_datais freed.debugfs_remove()waits for callers that are already inside the file operations, and any later access fails with-EIOinstead of reaching the debugfs helpers. This covers the two writable files as well.
Quoted 5 lines
Fixes 0ff252c1976d ("Bluetooth: hciuart: Add support QCA chipset for UART")Signed-off-by YuanZhe Liu <[email protected]>---
This patch was applied to bluetooth/bluetooth-next.git (master) by Luiz Augusto von Dentz <[email protected]>:
Hello:
This patch was applied to bluetooth/bluetooth-next.git (master) by Luiz Augusto von Dentz <[email protected]>:
Quoted 9 lines · On Thu, 5 Nov 2026 13:56:45 +0800 you wrote:
qca_debugfs_init()creates an "ibs" directory underhdev->debugfsand stores pointers to fields of structqca_datain the debugfs files.qca_close()freesqca_datawithout removing that directory, whilehdev->debugfsis only removed when the HCI device is released. The HCI device can outlive the driver data, for example when an HCI socket still references it, so reading or writing one of the ibs files then dereferences freed memory.[...]
Here is the summary with links:
- Bluetooth: hci_qca: fix use-after-free in ibs debugfs files
https://git.kernel.org/bluetooth/bluetooth-next/c/eeca795cec6d
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html