Bluetooth: Fix use-after-free read in hci_cmd_timeout()
Subsystems (2)
PATCH 1/1 Bluetooth: Fix use-after-free read in hci_cmd_timeout()
syzbot reported use-after-free in hci_cmd_timeout() [1]. The scenario for the issue is as follows:
Task Workqueue
----------------------------------------------------------------------hci_dev_open_sync
...
hci_dev_init_sync <- failed
...
if (hdev->sent_cmd)
kfree_skb(hdev->sent_cmd)
hci_cmd_timeout
...
if (hdev->sent_cmd)
sent = hdev->sent_cmd->data
^^ UAF occurred
hdev->sent_cmd = NULLWhen hci_dev_init_sync() failed, hci_dev_open_sync() frees hdev->send_cmd and set it to NULL. However, hci_cmd_timeout() can run just after freeing hdev->sent_cmd because hdev->cmd_timer is not canceled.
This patch fixes the issue by canceling hdev->cmd_timer before freeing hdev->sent_cmd.
--- net/bluetooth/hci_sync.c | 1 + 1 file changed, 1 insertion(+)
net/bluetooth/hci_sync.c +1 -0
@@ -4696,6 +4696,7 @@ int hci_dev_open_sync(struct hci_dev *hdev) hdev->flush (hdev);if (hdev->sent_cmd) { +cancel_delayed_work_sync (&hdev->cmd_timer);kfree_skb (hdev->sent_cmd); hdev->sent_cmd =NULL ; }
Signature · 1 line
2.38.1
This is an automated email and please do not reply to this email.
Dear Submitter,
Thank you for submitting the patches to the linux bluetooth mailing list.
While preparing the CI tests, the patches you submitted couldn't be applied to the current HEAD of the repository.
----- Output -----
error: patch failed: net/bluetooth/hci_sync.c:4696
error: net/bluetooth/hci_sync.c: patch does not apply
hint: Use 'git am --show-current-patch' to see the failed patch
Please resolve the issue and submit the patches again.
---
Regards,
Linux Bluetooth
Luiz Augusto von Dentz
maintainerHi Shigeru,
Quoted 47 lines · Shigeru Yoshida
syzbot reported use-after-free in
hci_cmd_timeout()[1]. The scenario for the issue is as follows:Task Workqueue
----------------------------------------------------------------------hci_dev_open_sync
...
hci_dev_init_sync<- failed
...
if (hdev->sent_cmd)kfree_skb(hdev->sent_cmd) hci_cmd_timeout ... if (hdev->sent_cmd) sent = hdev->sent_cmd->data ^^ UAF occurred hdev->sent_cmd = NULLWhen
hci_dev_init_sync()failed,hci_dev_open_sync()freeshdev->send_cmdand set it to NULL. However,hci_cmd_timeout()can run just after freeinghdev->sent_cmdbecausehdev->cmd_timeris not canceled.This patch fixes the issue by canceling
hdev->cmd_timerbefore freeinghdev->sent_cmd.Reported-by [email protected]Signed-off-by Shigeru Yoshida <[email protected]>--- net/bluetooth/hci_sync.c | 1 + 1 file changed, 1 insertion(+)net/bluetooth/hci_sync.c +1
-1@@ -4696,6 +4696,7 @@ int hci_dev_open_sync(struct hci_dev *hdev) hdev->flush (hdev);if (hdev->sent_cmd) { +cancel_delayed_work_sync (&hdev->cmd_timer);kfree_skb (hdev->sent_cmd); hdev->sent_cmd =NULL ; } --
Quoted 1 line
2.38.1
A similar fix has already been applied:
Signature · 1 line
Luiz Augusto von Dentz