devicetree.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>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Felipe Balbi <balbi@kernel.org>, Rob Herring <robh+dt@kernel.org>,
	Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
	Andy Gross <agross@kernel.org>,
	Bjorn Andersson <bjorn.andersson@linaro.org>,
	Konrad Dybcio <konrad.dybcio@somainline.org>,
	Krishna Kurapati <quic_kriskura@quicinc.com>,
	Stephen Boyd <swboyd@chromium.org>,
	Doug Anderson <dianders@chromium.org>,
	Matthias Kaehlcke <mka@chromium.org>,
	Pavankumar Kondeti <quic_pkondeti@quicinc.com>,
	quic_ppratap@quicinc.com, quic_vpulyala@quicinc.com,
	linux-arm-msm@vger.kernel.org, linux-usb@vger.kernel.org,
	devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org
Subject: Re: [PATCH v2 4/9] usb: dwc3: qcom: fix use-after-free on runtime-PM wakeup
Date: Sat, 6 Aug 2022 22:14:35 +0530	[thread overview]
Message-ID: <20220806164435.GL14384@thinkpad> (raw)
In-Reply-To: <Yu6SE1wKXk6/qT9Z@hovoldconsulting.com>

On Sat, Aug 06, 2022 at 06:08:51PM +0200, Johan Hovold wrote:
> On Sat, Aug 06, 2022 at 08:03:11PM +0530, Manivannan Sadhasivam wrote:
> > On Thu, Aug 04, 2022 at 05:09:56PM +0200, Johan Hovold wrote:
> > > The Qualcomm dwc3 runtime-PM implementation checks the xhci
> > > platform-device pointer in the wakeup-interrupt handler to determine
> > > whether the controller is in host mode and if so triggers a resume.
> > > 
> > > After a role switch in OTG mode the xhci platform-device would have been
> > > freed and the next wakeup from runtime suspend would access the freed
> > > memory.
> > > 
> > > Note that role switching is executed from a freezable workqueue, which
> > > guarantees that the pointer is stable during suspend.
> > > 
> > > Also note that runtime PM has been broken since commit 2664deb09306
> > > ("usb: dwc3: qcom: Honor wakeup enabled/disabled state"), which
> > > incidentally also prevents this issue from being triggered.
> > > 
> > > Fixes: a4333c3a6ba9 ("usb: dwc3: Add Qualcomm DWC3 glue driver")
> > > Cc: stable@vger.kernel.org      # 4.18
> > > Signed-off-by: Johan Hovold <johan+linaro@kernel.org>
> > 
> > It'd be good to mention the introduction of dwc3_qcom_is_host() function.
> > Initially I thought it is used in a single place, but going through the rest of
> > the patches reveals that it is used later on.
> 
> I think the helper is warranted on its own as it serves as documentation
> of the underlying assumptions that this code relies on.
> 

That's even better.

Thanks,
Mani

> > > +/* Only usable in contexts where the role can not change. */
> > > +static bool dwc3_qcom_is_host(struct dwc3_qcom *qcom)
> > > +{
> > > +	struct dwc3 *dwc = platform_get_drvdata(qcom->dwc3);
> > > +
> > > +	return dwc->xhci;
> > > +}
> > > +
> > >  static enum usb_device_speed dwc3_qcom_read_usb2_speed(struct dwc3_qcom *qcom)
> > >  {
> > >  	struct dwc3 *dwc = platform_get_drvdata(qcom->dwc3);
> > > @@ -460,7 +468,11 @@ static irqreturn_t qcom_dwc3_resume_irq(int irq, void *data)
> > >  	if (qcom->pm_suspended)
> > >  		return IRQ_HANDLED;
> > >  
> > > -	if (dwc->xhci)
> > > +	/*
> > > +	 * This is safe as role switching is done from a freezable workqueue
> > > +	 * and the wakeup interrupts are disabled as part of resume.
> > > +	 */
> > > +	if (dwc3_qcom_is_host(qcom))
> > >  		pm_runtime_resume(&dwc->xhci->dev);
> > >  
> > >  	return IRQ_HANDLED;
> > > diff --git a/drivers/usb/dwc3/host.c b/drivers/usb/dwc3/host.c
> > > index f56c30cf151e..f6f13e7f1ba1 100644
> > > --- a/drivers/usb/dwc3/host.c
> > > +++ b/drivers/usb/dwc3/host.c
> > > @@ -135,4 +135,5 @@ int dwc3_host_init(struct dwc3 *dwc)
> > >  void dwc3_host_exit(struct dwc3 *dwc)
> > >  {
> > >  	platform_device_unregister(dwc->xhci);
> > > +	dwc->xhci = NULL;
> > >  }
> > > -- 
> > > 2.35.1
> 
> Johan

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

  reply	other threads:[~2022-08-06 16:44 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-04 15:09 [PATCH v2 0/9] usb: dwc3: qcom: fix wakeup implementation Johan Hovold
2022-08-04 15:09 ` [PATCH v2 1/9] usb: dwc3: fix PHY disable sequence Johan Hovold
2022-08-06 13:48   ` Manivannan Sadhasivam
2022-08-04 15:09 ` [PATCH v2 2/9] Revert "usb: dwc3: qcom: Keep power domain on to retain controller status" Johan Hovold
2022-08-06 13:52   ` Manivannan Sadhasivam
2022-08-04 15:09 ` [PATCH v2 3/9] usb: dwc3: qcom: fix gadget-only builds Johan Hovold
2022-08-04 18:18   ` Randy Dunlap
2022-08-06 14:15   ` Manivannan Sadhasivam
2022-08-06 16:04     ` Johan Hovold
2022-08-06 16:42       ` Manivannan Sadhasivam
2022-08-06 16:51         ` Johan Hovold
2022-08-08 13:05   ` Greg Kroah-Hartman
2022-08-08 13:34     ` Johan Hovold
2022-08-18 17:44       ` Greg Kroah-Hartman
2022-08-04 15:09 ` [PATCH v2 4/9] usb: dwc3: qcom: fix use-after-free on runtime-PM wakeup Johan Hovold
2022-08-04 15:53   ` Matthias Kaehlcke
2022-08-06 14:33   ` Manivannan Sadhasivam
2022-08-06 16:08     ` Johan Hovold
2022-08-06 16:44       ` Manivannan Sadhasivam [this message]
2022-08-04 15:09 ` [PATCH v2 5/9] usb: dwc3: qcom: fix runtime PM wakeup Johan Hovold
2022-08-04 20:00   ` Matthias Kaehlcke
2022-08-06 14:35   ` Manivannan Sadhasivam
2022-08-04 15:09 ` [PATCH v2 6/9] usb: dwc3: qcom: fix peripheral and OTG suspend Johan Hovold
2022-08-04 21:38   ` kernel test robot
2022-08-05  6:58     ` Johan Hovold
2022-08-05  7:10       ` Johan Hovold
2022-08-04 15:09 ` [PATCH v2 7/9] dt-bindings: usb: qcom,dwc3: add wakeup-source property Johan Hovold
2022-08-06 15:08   ` Manivannan Sadhasivam
2022-08-06 16:41     ` Johan Hovold
2022-08-06 16:52       ` Manivannan Sadhasivam
2022-08-06 17:09         ` Johan Hovold
2022-08-08  8:05           ` Manivannan Sadhasivam
2022-08-04 15:10 ` [PATCH v2 8/9] usb: dwc3: qcom: fix wakeup implementation Johan Hovold
2022-08-04 16:59   ` Matthias Kaehlcke
2022-08-05 16:58     ` Matthias Kaehlcke
2022-08-06 16:22       ` Johan Hovold
2022-08-08 17:22         ` Matthias Kaehlcke
2022-08-06 14:57   ` Manivannan Sadhasivam
2022-08-06 16:33     ` Johan Hovold
2022-08-04 15:10 ` [PATCH v2 9/9] usb: dwc3: qcom: clean up suspend callbacks Johan Hovold
2022-08-04 17:08   ` Matthias Kaehlcke
2022-08-04 15:15 ` [PATCH v2 0/9] usb: dwc3: qcom: fix wakeup implementation Johan Hovold

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=20220806164435.GL14384@thinkpad \
    --to=manivannan.sadhasivam@linaro.org \
    --cc=agross@kernel.org \
    --cc=balbi@kernel.org \
    --cc=bjorn.andersson@linaro.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dianders@chromium.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=johan+linaro@kernel.org \
    --cc=johan@kernel.org \
    --cc=konrad.dybcio@somainline.org \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=mka@chromium.org \
    --cc=quic_kriskura@quicinc.com \
    --cc=quic_pkondeti@quicinc.com \
    --cc=quic_ppratap@quicinc.com \
    --cc=quic_vpulyala@quicinc.com \
    --cc=robh+dt@kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=swboyd@chromium.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).