From patchwork Wed Jun 7 10:05:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 104449 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6358:3046:b0:115:7a1d:dabb with SMTP id p6csp286586rwl; Wed, 7 Jun 2023 04:44:24 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4hOcM5uaYsDQPF++7LOARjNopvX3HOkvyoaTZicoonvAz6mpOFbKZ4ZnI9g3gPsfzwIARH X-Received: by 2002:a17:902:d510:b0:1b1:c90e:b7c0 with SMTP id b16-20020a170902d51000b001b1c90eb7c0mr5370995plg.59.1686138264697; Wed, 07 Jun 2023 04:44:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686138264; cv=none; d=google.com; s=arc-20160816; b=XPORR+YFwt7GsBxgcBfIDVWoI7+rh7fDInv5DFzEnkM1dnZFVe5avPWnwbP3/cK4Bf x/dgTQeokt3qQLI6zLRVR+70jTADUoSi807yUu+2/r+HOKp2vRPOwHCCtcHUdKOW/pVO QnjCG+6np5/cKxqxGBKMW9UratIIj2Xy66YEzQ4iREQ3jWGCpkPayL8ET/rmFYxnflET ecwnG0bxKmdrZozvsOWr/Rm71ZouBCfJgC7js1K2onuSITiYpWbszJvwhDAyhBr7B0K8 QY0jOtSyD1ju+LRRriVSwQUB6XvqDuTs2Wzj8drJn/UyD/swzPcccyp5RS3LJje3qlKw s8AQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=v1KVUZpGWLipzmiF3UlgbhI1aRzu8skyEMIXD7K69x4=; b=W4zK1TxKHnoAlVuYjqp5OaZuziYuB9TO4P+xkHiWsNxj1mWnHZtBYJ3v/uFlN35Tvr j2/QCRl62/GT1t7VN8eXF8pcq87JrkJG0Xm0SPh15/RUkrwnNwAqsj0qArV+8cErWdni IyYCMat/7Yle0i3RgXViWemlsEzEjtfDruNniql+XCOIpbkurpuSURZuuvb5J84tHGJ/ uf3/eMWG84VTyoLmit53acBADHjlvg6lKd7GtKeXFGG8F42e3lXDcGyyX5536r3+L49t aMtOyVjzNETxAOmmib2zQmUmoUM2/62UB1S0TI6aGUPfrnoIAjo1GSu+L6nVZTMlNGkw O4uw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=hcwjIfmE; 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=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l17-20020a170902f69100b001aaf5dcd774si9212306plg.173.2023.06.07.04.44.11; Wed, 07 Jun 2023 04:44:24 -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=@kernel.org header.s=k20201202 header.b=hcwjIfmE; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235429AbjFGLRI (ORCPT + 99 others); Wed, 7 Jun 2023 07:17:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52118 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239471AbjFGLRF (ORCPT ); Wed, 7 Jun 2023 07:17:05 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A42641702; Wed, 7 Jun 2023 04:17:04 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 3FB5263DBD; Wed, 7 Jun 2023 11:17:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 90665C43442; Wed, 7 Jun 2023 11:17:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686136623; bh=PqT7b3LTt1IrPaGyiAZXtxPqgt4zXro8Gw7CXf+6hyg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hcwjIfmEFTIUXuUtcgpBMJ4jzU5AmLI03k+n5e24wAmMp/W1YkBJLXXTTEK2axz/9 T5RVxoff/v2jBz79Uir+LB8uZkFWRyks6Q+F30CwBDcQJgIdEyNWW3cIDPa2R4P5RS J6MUJGfI6Q5HqyfmcIrRIak5MNt6+Gi2BtNAXDLaMvzT52dS4jt9jvEjC1v37a5E9e zTdlZJPWBugDtMCH7X3aNaLw8VUD97ukmGLTWHyKuF/02Zq/Zhyl2QX0IQrQjqcdpb euJakyPqO/MwXQV5UurRMzyB6zDzRIo/gm81awExyAXteEMiR11fFc+lkCITXenblb 05+boh6s8h1Bg== Received: from johan by xi.lan with local (Exim 4.94.2) (envelope-from ) id 1q6rAM-0008LU-Gz; Wed, 07 Jun 2023 13:17:26 +0200 From: Johan Hovold To: Thinh Nguyen Cc: Greg Kroah-Hartman , Andy Gross , Bjorn Andersson , Konrad Dybcio , Krishna Kurapati , Manivannan Sadhasivam , linux-usb@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, Johan Hovold , stable@vger.kernel.org, Li Jun , Sandeep Maheswaram Subject: [PATCH 2/2] USB: dwc3: fix use-after-free on core driver unbind Date: Wed, 7 Jun 2023 12:05:40 +0200 Message-Id: <20230607100540.31045-3-johan+linaro@kernel.org> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20230607100540.31045-1-johan+linaro@kernel.org> References: <20230607100540.31045-1-johan+linaro@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768044116950103459?= X-GMAIL-MSGID: =?utf-8?q?1768044116950103459?= Some dwc3 glue drivers are currently accessing the driver data of the child core device directly, which is clearly a bad idea as the child may not have probed yet or may have been unbound from its driver. As a workaround until the glue drivers have been fixed, clear the driver data pointer before allowing the glue parent device to runtime suspend to prevent its driver from accessing data that has been freed during unbind. Fixes: 6dd2565989b4 ("usb: dwc3: add imx8mp dwc3 glue layer driver") Fixes: 6895ea55c385 ("usb: dwc3: qcom: Configure wakeup interrupts during suspend") Cc: stable@vger.kernel.org # 5.12 Cc: Li Jun Cc: Sandeep Maheswaram Cc: Krishna Kurapati Signed-off-by: Johan Hovold Reviewed-by: Manivannan Sadhasivam Acked-by: Thinh Nguyen --- drivers/usb/dwc3/core.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index 7b2ce013cc5b..d68958e151a7 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -1929,6 +1929,11 @@ static int dwc3_remove(struct platform_device *pdev) pm_runtime_disable(&pdev->dev); pm_runtime_dont_use_autosuspend(&pdev->dev); pm_runtime_put_noidle(&pdev->dev); + /* + * HACK: Clear the driver data, which is currently accessed by parent + * glue drivers, before allowing the parent to suspend. + */ + platform_set_drvdata(pdev, NULL); pm_runtime_set_suspended(&pdev->dev); dwc3_free_event_buffers(dwc);