From: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
To: Zheng Wang <zyytlz.wz@163.com>,
"gregkh@linuxfoundation.org" <gregkh@linuxfoundation.org>
Cc: "p.zabel@pengutronix.de" <p.zabel@pengutronix.de>,
"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"hackerzheng666@gmail.com" <hackerzheng666@gmail.com>,
"1395428693sheep@gmail.com" <1395428693sheep@gmail.com>,
"alex000young@gmail.com" <alex000young@gmail.com>
Subject: RE: [RESEND PATCH] usb: renesas_usbhs: Fix use after free bug in usbhs_remove due to race condition
Date: Thu, 13 Apr 2023 12:19:44 +0000 [thread overview]
Message-ID: <TYBPR01MB5341FED435E5533E4B60B10CD8989@TYBPR01MB5341.jpnprd01.prod.outlook.com> (raw)
In-Reply-To: <20230413074926.239605-1-zyytlz.wz@163.com>
Hi,
> From: Zheng Wang, Sent: Thursday, April 13, 2023 4:49 PM
>
> In usbhs_probe, &priv->notify_hotplug_work is bound with
> usbhsc_notify_hotplug. It will be started then.
>
> If we remove the driver which will call usbhs_remove
> to make cleanup, there may be a unfinished work.
>
> The possible sequence is as follows:
>
> Fix it by finishing the work before cleanup in the usbhs_remove
>
> CPU0 CPU1
>
> |usbhsc_notify_hotplug
> usbhs_remove |
> usbhs_mod_remove |
> usbhs_mod_gadget_remove|
> kfree(gpriv); |
> |usbhsc_hotplug
> |usbhs_mod_call start
> |usbhsg_start
> |usbhsg_try_start
> |//use gpriv
Thank you for the patch!
You should adjust the figure like followings because Greg mentioned it on other patch [1].
-----
CPU0 CPU1
| usbhsc_notify_hotplug
usbhs_remove |
usbhs_mod_remove |
usbhs_mod_gadget_remove |
kfree(gpriv); |
| usbhsc_hotplug
| usbhs_mod_call start
| usbhsg_start
| usbhsg_try_start
| //use gpriv
-----
[1]
https://lore.kernel.org/lkml/ZBNCam0XjWehrF3c@kroah.com/
Best regards,
Yoshihiro Shimoda
> Fixes: bc57381e6347 ("usb: renesas_usbhs: use delayed_work instead of work_struct")
> Signed-off-by: Zheng Wang <zyytlz.wz@163.com>
> ---
> drivers/usb/renesas_usbhs/common.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/usb/renesas_usbhs/common.c b/drivers/usb/renesas_usbhs/common.c
> index 96f3939a65e2..17a0987ef4f5 100644
> --- a/drivers/usb/renesas_usbhs/common.c
> +++ b/drivers/usb/renesas_usbhs/common.c
> @@ -768,6 +768,7 @@ static int usbhs_remove(struct platform_device *pdev)
>
> dev_dbg(&pdev->dev, "usb remove\n");
>
> + cancel_delayed_work_sync(&priv->notify_hotplug_work);
> /* power off */
> if (!usbhs_get_dparam(priv, runtime_pwctrl))
> usbhsc_power_ctrl(priv, 0);
> --
> 2.25.1
next prev parent reply other threads:[~2023-04-13 12:20 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-13 7:49 Zheng Wang
2023-04-13 12:19 ` Yoshihiro Shimoda [this message]
2023-04-13 15:38 ` Zheng Hacker
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=TYBPR01MB5341FED435E5533E4B60B10CD8989@TYBPR01MB5341.jpnprd01.prod.outlook.com \
--to=yoshihiro.shimoda.uh@renesas.com \
--cc=1395428693sheep@gmail.com \
--cc=alex000young@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=hackerzheng666@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=p.zabel@pengutronix.de \
--cc=zyytlz.wz@163.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®