Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp2637717rwl; Thu, 13 Apr 2023 08:59:21 -0700 (PDT) X-Google-Smtp-Source: AKy350ZGporXRq8TTy5VbyqRrGNPrd56r2bD+GrWEPXgh7VSVrrL2o+87sRdyee8CYJWewgTCzWp X-Received: by 2002:a17:903:22ca:b0:1a0:5524:eb8e with SMTP id y10-20020a17090322ca00b001a05524eb8emr3131394plg.68.1681401561101; Thu, 13 Apr 2023 08:59:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681401561; cv=none; d=google.com; s=arc-20160816; b=l1aNCjBbE1VQbZsd35kqbJ7O067+B/CC5n/LBQaohC5sBcG0cFEhO2nrd8sunhmrU1 hJMCsSBVBf8h5VPxXb5ErI3skpdTH9iEXUNHkj4aXqxs2A+a0vLbAZUVB4q69dggKUK7 gnbv42MTjCdHu6JXXCMiAbG3ktdu/NRzyEwsZMF4V7WHEC0SKaS3XQTkHA6hR8Vwlew8 mCN0hwssvwP614JGLPCXA4sHdqrtnBtm/Dfik1jJM+evfxEWP181RPhujDpjEk+cOLOA ebFIxSPLHvVFPkOGpm5voO5WFbRhQiUVZSyPjuxI+0JPDDJVeEFsQwlEB8DXU0ZDavGt AoKQ== 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=sXqNs6lg+IIJ+O1PdH2eS9ZXTmGxoGzuMU3zSlyWTwU=; b=LE7lxe3xqgcuCKy0UY/Miq59G2DoeIIFdcDr9WQ1uZ9NjC30J93W8H3CBXKNv3z30O gZDN407GvAmQD4XjDqnZeGx3j2RjtoYWgJR4B/d7b8EPnTO1OsBE7lmUFJtHd9ObnbqO LiBHA1W7JgYoB3o3AZUeZ//+7p67VY6pscLItLA/53hPH0K4OU6ySG+a6g6ufU8K7FbO tPdDeQ0dj21kh+Yhv6QfWB96eeOd4RYGIt6XorGdSEq9JrNgB9ot4ABsIuBnTe0kifJc kzLwXF1Po+ZEomLN/ABdH3gYhBdKfULjJp4NKeJghSd85aopZQSQDnJh6NgFuBoMMM2+ 9eaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=To8EJTqE; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w23-20020a170902a71700b0019955f0dc48si2137133plq.527.2023.04.13.08.59.08; Thu, 13 Apr 2023 08:59:21 -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=To8EJTqE; 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 S231556AbjDMPoS (ORCPT + 99 others); Thu, 13 Apr 2023 11:44:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33260 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229633AbjDMPoR (ORCPT ); Thu, 13 Apr 2023 11:44:17 -0400 Received: from m12.mail.163.com (m12.mail.163.com [220.181.12.215]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 3913310EF; Thu, 13 Apr 2023 08:44:13 -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=sXqNs 6lg+IIJ+O1PdH2eS9ZXTmGxoGzuMU3zSlyWTwU=; b=To8EJTqEiLT2b/MoWMK5Q Rtj93+txGBKWM+MorhT/fsGWGdWpxxYBEdiQNVDRHMM9r7GFEtuzNSsOfXkufbx4 OXQDyiypLYdRuTbV9b4xPzksnRBPm+rE1YeRH1EprvIk2KCRMvfGTX8niJAbc+5W U75tr5rnADbHUZVMyfx5Ig= Received: from leanderwang-LC2.localdomain (unknown [111.206.145.21]) by zwqz-smtp-mta-g4-4 (Coremail) with SMTP id _____wBXhWY5IzhkpE9VBQ--.3426S2; Thu, 13 Apr 2023 23:43:53 +0800 (CST) From: Zheng Wang To: gregkh@linuxfoundation.org Cc: yoshihiro.shimoda.uh@renesas.com, 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 v2] usb: renesas_usbhs: Fix use after free bug in usbhs_remove due to race condition Date: Thu, 13 Apr 2023 23:43:51 +0800 Message-Id: <20230413154351.619730-1-zyytlz.wz@163.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: _____wBXhWY5IzhkpE9VBQ--.3426S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7Ww13Gw1rKw47WF1UurWDCFg_yoW8Gr13pa 15JFyUG3yrGrWjga1vqr4UXryrCayqgry7WrZrWwsxuwnxAa18Za40qF4Uur13Xa93JF4j vw1vyr95ZaykCFDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0z_9N3DUUUUU= X-Originating-IP: [111.206.145.21] X-CM-SenderInfo: h2113zf2oz6qqrwthudrp/1tbiQhpQU1aEE+iaiQAAsh 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,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: X-Mailing-List: linux-kernel@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 --- v2: - beautify the format as Yoshihiro Shimoda suggested --- 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