Skip to content

Commit 0dffd93

Browse files
committed
Merge tag 'for-net-2025-08-29' of git://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth
Luiz Augusto von Dentz says: ==================== bluetooth pull request for net: - vhci: Prevent use-after-free by removing debugfs files early - L2CAP: Fix use-after-free in l2cap_sock_cleanup_listen() * tag 'for-net-2025-08-29' of git://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth: Bluetooth: Fix use-after-free in l2cap_sock_cleanup_listen() Bluetooth: vhci: Prevent use-after-free by removing debugfs files early ==================== Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents 788bc43 + 862c628 commit 0dffd93

File tree

2 files changed

+44
-16
lines changed

2 files changed

+44
-16
lines changed

drivers/bluetooth/hci_vhci.c

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,28 @@ static const struct file_operations force_devcoredump_fops = {
380380
.write = force_devcd_write,
381381
};
382382

383+
static void vhci_debugfs_init(struct vhci_data *data)
384+
{
385+
struct hci_dev *hdev = data->hdev;
386+
387+
debugfs_create_file("force_suspend", 0644, hdev->debugfs, data,
388+
&force_suspend_fops);
389+
390+
debugfs_create_file("force_wakeup", 0644, hdev->debugfs, data,
391+
&force_wakeup_fops);
392+
393+
if (IS_ENABLED(CONFIG_BT_MSFTEXT))
394+
debugfs_create_file("msft_opcode", 0644, hdev->debugfs, data,
395+
&msft_opcode_fops);
396+
397+
if (IS_ENABLED(CONFIG_BT_AOSPEXT))
398+
debugfs_create_file("aosp_capable", 0644, hdev->debugfs, data,
399+
&aosp_capable_fops);
400+
401+
debugfs_create_file("force_devcoredump", 0644, hdev->debugfs, data,
402+
&force_devcoredump_fops);
403+
}
404+
383405
static int __vhci_create_device(struct vhci_data *data, __u8 opcode)
384406
{
385407
struct hci_dev *hdev;
@@ -434,22 +456,8 @@ static int __vhci_create_device(struct vhci_data *data, __u8 opcode)
434456
return -EBUSY;
435457
}
436458

437-
debugfs_create_file("force_suspend", 0644, hdev->debugfs, data,
438-
&force_suspend_fops);
439-
440-
debugfs_create_file("force_wakeup", 0644, hdev->debugfs, data,
441-
&force_wakeup_fops);
442-
443-
if (IS_ENABLED(CONFIG_BT_MSFTEXT))
444-
debugfs_create_file("msft_opcode", 0644, hdev->debugfs, data,
445-
&msft_opcode_fops);
446-
447-
if (IS_ENABLED(CONFIG_BT_AOSPEXT))
448-
debugfs_create_file("aosp_capable", 0644, hdev->debugfs, data,
449-
&aosp_capable_fops);
450-
451-
debugfs_create_file("force_devcoredump", 0644, hdev->debugfs, data,
452-
&force_devcoredump_fops);
459+
if (!IS_ERR_OR_NULL(hdev->debugfs))
460+
vhci_debugfs_init(data);
453461

454462
hci_skb_pkt_type(skb) = HCI_VENDOR_PKT;
455463

@@ -651,6 +659,21 @@ static int vhci_open(struct inode *inode, struct file *file)
651659
return 0;
652660
}
653661

662+
static void vhci_debugfs_remove(struct hci_dev *hdev)
663+
{
664+
debugfs_lookup_and_remove("force_suspend", hdev->debugfs);
665+
666+
debugfs_lookup_and_remove("force_wakeup", hdev->debugfs);
667+
668+
if (IS_ENABLED(CONFIG_BT_MSFTEXT))
669+
debugfs_lookup_and_remove("msft_opcode", hdev->debugfs);
670+
671+
if (IS_ENABLED(CONFIG_BT_AOSPEXT))
672+
debugfs_lookup_and_remove("aosp_capable", hdev->debugfs);
673+
674+
debugfs_lookup_and_remove("force_devcoredump", hdev->debugfs);
675+
}
676+
654677
static int vhci_release(struct inode *inode, struct file *file)
655678
{
656679
struct vhci_data *data = file->private_data;
@@ -662,6 +685,8 @@ static int vhci_release(struct inode *inode, struct file *file)
662685
hdev = data->hdev;
663686

664687
if (hdev) {
688+
if (!IS_ERR_OR_NULL(hdev->debugfs))
689+
vhci_debugfs_remove(hdev);
665690
hci_unregister_dev(hdev);
666691
hci_free_dev(hdev);
667692
}

net/bluetooth/l2cap_sock.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1422,7 +1422,10 @@ static int l2cap_sock_release(struct socket *sock)
14221422
if (!sk)
14231423
return 0;
14241424

1425+
lock_sock_nested(sk, L2CAP_NESTING_PARENT);
14251426
l2cap_sock_cleanup_listen(sk);
1427+
release_sock(sk);
1428+
14261429
bt_sock_unlink(&l2cap_sk_list, sk);
14271430

14281431
err = l2cap_sock_shutdown(sock, SHUT_RDWR);

0 commit comments

Comments
 (0)