stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
To: Johan Hovold <johan@kernel.org>
Cc: Johan Hovold <johan+linaro@kernel.org>,
	Thinh Nguyen <Thinh.Nguyen@synopsys.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Andy Gross <agross@kernel.org>,
	Bjorn Andersson <andersson@kernel.org>,
	Konrad Dybcio <konrad.dybcio@linaro.org>,
	Krishna Kurapati <quic_kriskura@quicinc.com>,
	linux-usb@vger.kernel.org, linux-arm-msm@vger.kernel.org,
	linux-kernel@vger.kernel.org, stable@vger.kernel.org,
	Li Jun <jun.li@nxp.com>,
	Sandeep Maheswaram <quic_c_sanm@quicinc.com>
Subject: Re: [PATCH 2/2] USB: dwc3: fix use-after-free on core driver unbind
Date: Thu, 8 Jun 2023 20:46:46 +0530	[thread overview]
Message-ID: <20230608151646.GH5672@thinkpad> (raw)
In-Reply-To: <ZIHchsMdf2nPv3wh@hovoldconsulting.com>

On Thu, Jun 08, 2023 at 03:49:58PM +0200, Johan Hovold wrote:
> On Thu, Jun 08, 2023 at 06:53:13PM +0530, Manivannan Sadhasivam wrote:
> > On Thu, Jun 08, 2023 at 03:09:27PM +0200, Johan Hovold wrote:
> > > On Thu, Jun 08, 2023 at 06:32:46PM +0530, Manivannan Sadhasivam wrote:
> > > > On Wed, Jun 07, 2023 at 12:05:40PM +0200, Johan Hovold wrote:
> > > > > 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.
> > > 
> > > > > @@ -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);
> > > > 
> > > > This is required because you have seen the glue driver going to runtime suspend
> > > > once the below pm_runtime_set_suspended() is completed?
> > > 
> > > This is based on analysis of the code. The parent (glue) can not suspend
> > > while the child (core) is in the active state, but once we set the
> > > suspended state that could happen.
> > 
> > I could see that the driver core is setting drvdata to NULL during
> > device_unbind_cleanup(), so not sure if this scenario could be met otherwise it
> > will be redundant.
> 
> If this was redundant I wouldn't have added it. ;)
> 
> The parent driver has no business accessing the driver data of the child
> in the first place, but it must absolutely not do so after the child has
> been unbound from its driver and the driver data is getting freed.
> 
> Relying on the clean up in driver core that resets this pointer does not
> work as that would still leave a window where the parent could access
> this stale data.
> 

Well, I agree with the small window here.

Reviewed-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>

- Mani

> Johan

-- 
மணிவண்ணன் சதாசிவம்

  reply	other threads:[~2023-06-08 15:17 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20230607100540.31045-1-johan+linaro@kernel.org>
2023-06-07 10:05 ` [PATCH 1/2] USB: dwc3: qcom: fix NULL-deref on suspend Johan Hovold
2023-06-08 12:49   ` Manivannan Sadhasivam
2023-06-09  0:32   ` Thinh Nguyen
2023-06-07 10:05 ` [PATCH 2/2] USB: dwc3: fix use-after-free on core driver unbind Johan Hovold
2023-06-08 13:02   ` Manivannan Sadhasivam
2023-06-08 13:09     ` Johan Hovold
2023-06-08 13:23       ` Manivannan Sadhasivam
2023-06-08 13:49         ` Johan Hovold
2023-06-08 15:16           ` Manivannan Sadhasivam [this message]
2023-06-09  0:33   ` Thinh Nguyen

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=20230608151646.GH5672@thinkpad \
    --to=manivannan.sadhasivam@linaro.org \
    --cc=Thinh.Nguyen@synopsys.com \
    --cc=agross@kernel.org \
    --cc=andersson@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=johan+linaro@kernel.org \
    --cc=johan@kernel.org \
    --cc=jun.li@nxp.com \
    --cc=konrad.dybcio@linaro.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=quic_c_sanm@quicinc.com \
    --cc=quic_kriskura@quicinc.com \
    --cc=stable@vger.kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).