From patchwork Fri Mar 10 13:02:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zheng Wang X-Patchwork-Id: 662079 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6E2C7C6FA99 for ; Fri, 10 Mar 2023 13:03:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230182AbjCJNDL (ORCPT ); Fri, 10 Mar 2023 08:03:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60336 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229890AbjCJNDJ (ORCPT ); Fri, 10 Mar 2023 08:03:09 -0500 Received: from m12.mail.163.com (m12.mail.163.com [220.181.12.216]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D4F43423E; Fri, 10 Mar 2023 05:03:03 -0800 (PST) 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=nZ9APEsOjKa0oCV2VufXM iPmsciw9JwNWjzWhqcS3KCkJrgiOmSmpQUev6wg30ffX2OcX3MI0MdjgmPJY4/dz cN4EJ0fetkCfvQHk2wHZsFbP7Wmod9vXzh0g0howXh6gjFWobi+HadxJLt/N9+fj oOyTRGpDRvYHyOMJo4mXlc= Received: from leanderwang-LC2.localdomain (unknown [111.206.145.21]) by zwqz-smtp-mta-g2-0 (Coremail) with SMTP id _____wDXhZJnKgtkMLlkCw--.5392S2; Fri, 10 Mar 2023 21:02:32 +0800 (CST) From: Zheng Wang 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 Subject: [PATCH] usb: renesas_usbhs: Fix use after free bug in usbhs_remove due to race condition Date: Fri, 10 Mar 2023 21:02:30 +0800 Message-Id: <20230310130230.1732896-1-zyytlz.wz@163.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-CM-TRANSID: _____wDXhZJnKgtkMLlkCw--.5392S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7Ww13Gw1rKw47WF1UAw15CFg_yoW8JF4xpa 15JFy8G3yrGrWjgan2qr4UXFyrCayqgr17WrZ7WwsxuwnxAa18Za4FqF4j9r13Xa93Ja1Y v3Wvyr95CaykCFDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0ziFdg_UUUUU= X-Originating-IP: [111.206.145.21] X-CM-SenderInfo: h2113zf2oz6qqrwthudrp/xtbBzgAuU2I0Xl15awABs1 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org 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 --- 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);