public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] misc: hisi_hikey_usb: Fix use after free bug in hisi_hikey_usb_remove due to race condition
@ 2023-03-12 14:53 Zheng Wang
  2023-03-13 19:57 ` John Stultz
  0 siblings, 1 reply; 16+ messages in thread
From: Zheng Wang @ 2023-03-12 14:53 UTC (permalink / raw)
  To: jstultz
  Cc: arnd, gregkh, linux-kernel, hackerzheng666, 1395428693sheep,
	alex000young, Zheng Wang

In hisi_hikey_usb_probe, it called hisi_hikey_usb_of_role_switch
and bound &hisi_hikey_usb->work with relay_set_role_switch.
When it calls hub_usb_role_switch_set, it will finally call
schedule_work to start the work.

When we call hisi_hikey_usb_remove to remove the driver, there
may be a sequence as follows:

Fix it by finishing the work before cleanup in hisi_hikey_usb_remove.

CPU0                  CPU1

                    |relay_set_role_switch
hisi_hikey_usb_remove|
  usb_role_switch_put|
    usb_role_switch_release  |
     kfree(sw)     |
                    | usb_role_switch_set_role
                    |   //use

Fixes: 7a6ff4c4cbc3 ("misc: hisi_hikey_usb: Driver to support onboard USB gpio hub on Hikey960")
Signed-off-by: Zheng Wang <zyytlz.wz@163.com>
---
 drivers/misc/hisi_hikey_usb.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/misc/hisi_hikey_usb.c b/drivers/misc/hisi_hikey_usb.c
index 2165ec35a343..26fc895c4418 100644
--- a/drivers/misc/hisi_hikey_usb.c
+++ b/drivers/misc/hisi_hikey_usb.c
@@ -242,6 +242,7 @@ static int hisi_hikey_usb_probe(struct platform_device *pdev)
 static int  hisi_hikey_usb_remove(struct platform_device *pdev)
 {
 	struct hisi_hikey_usb *hisi_hikey_usb = platform_get_drvdata(pdev);
+	cancel_work_sync(&hisi_hikey_usb->work);
 
 	if (hisi_hikey_usb->hub_role_sw) {
 		usb_role_switch_unregister(hisi_hikey_usb->hub_role_sw);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2023-04-22 17:09 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-03-12 14:53 [PATCH] misc: hisi_hikey_usb: Fix use after free bug in hisi_hikey_usb_remove due to race condition Zheng Wang
2023-03-13 19:57 ` John Stultz
2023-03-14  1:01   ` Zheng Hacker
2023-04-13  8:07     ` Zheng Hacker
2023-04-13 10:55       ` Yongqin Liu
2023-04-13 11:12         ` Zheng Hacker
2023-04-13 12:47           ` Greg KH
2023-04-13 15:35             ` Zheng Hacker
2023-04-13 15:56               ` Greg KH
2023-04-13 16:46                 ` Zheng Hacker
2023-04-17 17:31                   ` Yongqin Liu
2023-04-18 13:18                     ` Zheng Hacker
2023-04-20  6:30                       ` Yongqin Liu
2023-04-21  2:35                         ` Zheng Hacker
2023-04-21 15:42                           ` Yongqin Liu
2023-04-22 17:09                             ` Zheng Hacker

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox