[RESEND] usb: renesas_usbhs: Fix use after free bug in usbhs_remove due to race condition
Message ID | 20230413074926.239605-1-zyytlz.wz@163.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp862251vqo; Thu, 13 Apr 2023 01:01:33 -0700 (PDT) X-Google-Smtp-Source: AKy350ZGD+sJVNC0dE2GRWMCJ3fiQZPuheI2bHU3XisGEa3Ez8zOXQgJKVUhclE9LbugfqyhuX0x X-Received: by 2002:a17:906:35c9:b0:946:c1d2:8b5d with SMTP id p9-20020a17090635c900b00946c1d28b5dmr5944534ejb.17.1681372893394; Thu, 13 Apr 2023 01:01:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681372893; cv=none; d=google.com; s=arc-20160816; b=i2mQWeyAe3YCJO6BzdR7cbzsdeNfaLamPjh2sWhl8msy9/SvHDAUQ4uNjG6ccdcqsi uNzRmDCeyraFSjh7uTeRvnLGWbsjRVcorusM4dXrqjgNVvU1blCxlrVGPILXa61/UQz/ V8FY8ZTIhEYYZHkqXUG8qC3i+dq9S+BeFq1/EnnrTkOPvSyMxRpnZVkre3MEFNqVi3Hi pTCXdrom6nVcq07VtqT0ntQYIAX6XHL+WuO4GdjOVniJAB+GFyMBN0DOk9PiPbZ83lbp qFnGHe7DqtzKPUTz4gbNtREaIk1FTPr7moNnlSkFqBq6KQygkfbbB1YBRTCKNwyVQgsd bHEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=6TtIQg09ZmPHNc7fwNMyG9gkvYgQeJ5WuDUEisBpScU=; b=gpoJKl1DcquKGoFxjLms4j6fo7lX/zDfa6IJWoaCv9FsppXLvZaB2vmvyhtoC7RTJG hG68PJsugOfsZ2LXaLMfktwuXYwP2YUkfX/Xc/xS+dnxS2rO9tjbICaq9er1hnFbrbg5 57ADB+KRf2zunFj7UU4sUSbVcbp71KrgwaRWM+y2RcLuuv6MjM+WwOzXVLqxWwjg4PBk EuzAD9gc9B+P0hoe4XzgC5uJD+W8JL2abKFBjB6rw0lSNU2C6JjoR2V18NFJfKKmLbCL rtLInA09JR/n4JiAihy1BqIFUZ5HCu53GLq6ohcXJgr9afI09xLz3DiDMyjGFKmMbfS9 WCaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=RxNbs3Gj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=163.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id fw22-20020a170907501600b0094a7c65f1bcsi1222856ejc.215.2023.04.13.01.01.09; Thu, 13 Apr 2023 01:01:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=RxNbs3Gj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=163.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230013AbjDMHuW (ORCPT <rfc822;peter110.wang@gmail.com> + 99 others); Thu, 13 Apr 2023 03:50:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34478 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230063AbjDMHuT (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 13 Apr 2023 03:50:19 -0400 Received: from m12.mail.163.com (m12.mail.163.com [220.181.12.216]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 1238B9EC9; Thu, 13 Apr 2023 00:49:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=6TtIQ g09ZmPHNc7fwNMyG9gkvYgQeJ5WuDUEisBpScU=; b=RxNbs3Gjyl9cXI5OkfVXy i7frEY3tkxOjz4VRLt/2cmcaWumZfqF4VnegiLRG3Cih6M4EiasHMBn2cyYnzYwu NM8sXTsNYFv5foRQDP0rXxlHRUFLcnop0tbmwGHiENR/H4NRow+pxscTn5Wdycc9 NZmQ8yp4VGmPzdrlbuJy9w= Received: from leanderwang-LC2.localdomain (unknown [111.206.145.21]) by zwqz-smtp-mta-g4-1 (Coremail) with SMTP id _____wDXGOwItDdkTX8uBQ--.1680S2; Thu, 13 Apr 2023 15:49:28 +0800 (CST) From: Zheng Wang <zyytlz.wz@163.com> To: gregkh@linuxfoundation.org Cc: p.zabel@pengutronix.de, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, hackerzheng666@gmail.com, 1395428693sheep@gmail.com, alex000young@gmail.com, Zheng Wang <zyytlz.wz@163.com> Subject: [RESEND PATCH] usb: renesas_usbhs: Fix use after free bug in usbhs_remove due to race condition Date: Thu, 13 Apr 2023 15:49:26 +0800 Message-Id: <20230413074926.239605-1-zyytlz.wz@163.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: _____wDXGOwItDdkTX8uBQ--.1680S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7Ww13Gw1rKw47WF1UAw15CFg_yoW8JF4xpa 15JFy8G3yrGrWjgan2qr4UXFyrCayqgr17WrZ7WwsxuwnxAa18Za4FqF4j9r13Xa93Ja1Y v3Wvyr95CaykCFDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0zi0tC3UUUUU= X-Originating-IP: [111.206.145.21] X-CM-SenderInfo: h2113zf2oz6qqrwthudrp/xtbBzglQU2I0YqBUwwAAsH X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763047263190642802?= X-GMAIL-MSGID: =?utf-8?q?1763047263190642802?= |
Series |
[RESEND] usb: renesas_usbhs: Fix use after free bug in usbhs_remove due to race condition
|
|
Commit Message
Zheng Wang
April 13, 2023, 7:49 a.m. UTC
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
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(+)
Comments
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
Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com> 于2023年4月13日周四 20:19写道: > > 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]. Thanks for your advice. Will apply in the next. Best regards, Zheng > ----- > 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 >
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);