* [kernel PATCH v1 0/1] Clear workqueue to avoid use-after-free
@ 2023-02-22 0:09 Zhengping Jiang
2023-02-22 0:09 ` [kernel PATCH v1 1/1] Bluetooth: hci_sync: clear workqueue before clear mgmt cmd Zhengping Jiang
0 siblings, 1 reply; 3+ messages in thread
From: Zhengping Jiang @ 2023-02-22 0:09 UTC (permalink / raw)
To: linux-bluetooth, marcel, luiz.dentz
Cc: chromeos-bluetooth-upstreaming, mmandlik, Zhengping Jiang,
David S. Miller, Eric Dumazet, Jakub Kicinski, Johan Hedberg,
Paolo Abeni, linux-kernel, netdev
After the hci_sync rework, cmd_sync_work was cleared when calling
hci_unregister_dev, but not when powering off the adapter.
Use-after-free errors happened because a work is still scheduled
when cmd is freed by __mgmt_power_off.
Changes in v1:
- Clear cmd_sync_work queue before clearing the mgmt cmd list
Zhengping Jiang (1):
Bluetooth: hci_sync: clear workqueue before clear mgmt cmd
net/bluetooth/hci_sync.c | 2 ++
1 file changed, 2 insertions(+)
--
2.39.2.637.g21b0678d19-goog
^ permalink raw reply [flat|nested] 3+ messages in thread
* [kernel PATCH v1 1/1] Bluetooth: hci_sync: clear workqueue before clear mgmt cmd
2023-02-22 0:09 [kernel PATCH v1 0/1] Clear workqueue to avoid use-after-free Zhengping Jiang
@ 2023-02-22 0:09 ` Zhengping Jiang
2023-02-22 18:44 ` Zhengping Jiang
0 siblings, 1 reply; 3+ messages in thread
From: Zhengping Jiang @ 2023-02-22 0:09 UTC (permalink / raw)
To: linux-bluetooth, marcel, luiz.dentz
Cc: chromeos-bluetooth-upstreaming, mmandlik, Zhengping Jiang,
David S. Miller, Eric Dumazet, Jakub Kicinski, Johan Hedberg,
Paolo Abeni, linux-kernel, netdev
Clear cmd_sync_work queue before clearing the mgmt cmd list to avoid
racing conditions which cause use-after-free.
When powering off the adapter, the mgmt cmd list will be cleared. If a
work is queued in the cmd_sync_work queue at the same time, it will
cause the risk of use-after-free, as the cmd pointer is not checked
before use.
Signed-off-by: Zhengping Jiang <jiangzp@google.com>
---
Changes in v1:
- Clear cmd_sync_work queue before clearing the mgmt cmd list
net/bluetooth/hci_sync.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c
index 117eedb6f709..6609434e3125 100644
--- a/net/bluetooth/hci_sync.c
+++ b/net/bluetooth/hci_sync.c
@@ -4840,6 +4840,8 @@ int hci_dev_close_sync(struct hci_dev *hdev)
auto_off = hci_dev_test_and_clear_flag(hdev, HCI_AUTO_OFF);
+ hci_cmd_sync_clear(hdev);
+
if (!auto_off && hdev->dev_type == HCI_PRIMARY &&
!hci_dev_test_flag(hdev, HCI_USER_CHANNEL) &&
hci_dev_test_flag(hdev, HCI_MGMT))
--
2.39.2.637.g21b0678d19-goog
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [kernel PATCH v1 1/1] Bluetooth: hci_sync: clear workqueue before clear mgmt cmd
2023-02-22 0:09 ` [kernel PATCH v1 1/1] Bluetooth: hci_sync: clear workqueue before clear mgmt cmd Zhengping Jiang
@ 2023-02-22 18:44 ` Zhengping Jiang
0 siblings, 0 replies; 3+ messages in thread
From: Zhengping Jiang @ 2023-02-22 18:44 UTC (permalink / raw)
To: linux-bluetooth, marcel, luiz.dentz
Cc: chromeos-bluetooth-upstreaming, mmandlik, David S. Miller,
Eric Dumazet, Jakub Kicinski, Johan Hedberg, Paolo Abeni,
linux-kernel, netdev
Hi,
We need to revise this patch after a local test failure. I will update
after finding the cause.
Thanks,
Zhengping
On Tue, Feb 21, 2023 at 4:09 PM Zhengping Jiang <jiangzp@google.com> wrote:
>
> Clear cmd_sync_work queue before clearing the mgmt cmd list to avoid
> racing conditions which cause use-after-free.
>
> When powering off the adapter, the mgmt cmd list will be cleared. If a
> work is queued in the cmd_sync_work queue at the same time, it will
> cause the risk of use-after-free, as the cmd pointer is not checked
> before use.
>
> Signed-off-by: Zhengping Jiang <jiangzp@google.com>
> ---
>
> Changes in v1:
> - Clear cmd_sync_work queue before clearing the mgmt cmd list
>
> net/bluetooth/hci_sync.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c
> index 117eedb6f709..6609434e3125 100644
> --- a/net/bluetooth/hci_sync.c
> +++ b/net/bluetooth/hci_sync.c
> @@ -4840,6 +4840,8 @@ int hci_dev_close_sync(struct hci_dev *hdev)
>
> auto_off = hci_dev_test_and_clear_flag(hdev, HCI_AUTO_OFF);
>
> + hci_cmd_sync_clear(hdev);
> +
> if (!auto_off && hdev->dev_type == HCI_PRIMARY &&
> !hci_dev_test_flag(hdev, HCI_USER_CHANNEL) &&
> hci_dev_test_flag(hdev, HCI_MGMT))
> --
> 2.39.2.637.g21b0678d19-goog
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-02-22 18:46 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-22 0:09 [kernel PATCH v1 0/1] Clear workqueue to avoid use-after-free Zhengping Jiang
2023-02-22 0:09 ` [kernel PATCH v1 1/1] Bluetooth: hci_sync: clear workqueue before clear mgmt cmd Zhengping Jiang
2023-02-22 18:44 ` Zhengping Jiang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®