* [PATCH] usb: dwc3: gadget: Fix null pointer exception
@ 2021-11-04 6:26 Albert Wang
2021-11-06 1:25 ` Jack Pham
0 siblings, 1 reply; 3+ messages in thread
From: Albert Wang @ 2021-11-04 6:26 UTC (permalink / raw)
To: balbi, gregkh; +Cc: badhri, linux-usb, linux-kernel, Albert Wang
In the endpoint interrupt functions
dwc3_gadget_endpoint_transfer_in_progress() and
dwc3_gadget_endpoint_trbs_complete() will dereference the endpoint
descriptor. But it could be cleared in __dwc3_gadget_ep_disable()
when accessory disconnected. So we need to check whether it is null
or not before dereferencing it.
Signed-off-by: Albert Wang <albertccwang@google.com>
---
drivers/usb/dwc3/gadget.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index 23de2a5a40d6..83c7344888fd 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -3252,6 +3252,9 @@ static bool dwc3_gadget_endpoint_trbs_complete(struct dwc3_ep *dep,
struct dwc3 *dwc = dep->dwc;
bool no_started_trb = true;
+ if (!dep->endpoint.desc)
+ return no_started_trb;
+
dwc3_gadget_ep_cleanup_completed_requests(dep, event, status);
if (dep->flags & DWC3_EP_END_TRANSFER_PENDING)
@@ -3299,6 +3302,9 @@ static void dwc3_gadget_endpoint_transfer_in_progress(struct dwc3_ep *dep,
{
int status = 0;
+ if (!dep->endpoint.desc)
+ return;
+
if (usb_endpoint_xfer_isoc(dep->endpoint.desc))
dwc3_gadget_endpoint_frame_from_event(dep, event);
--
2.33.1.1089.g2158813163f-goog
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] usb: dwc3: gadget: Fix null pointer exception
2021-11-04 6:26 [PATCH] usb: dwc3: gadget: Fix null pointer exception Albert Wang
@ 2021-11-06 1:25 ` Jack Pham
2021-11-09 5:10 ` Albert Wang
0 siblings, 1 reply; 3+ messages in thread
From: Jack Pham @ 2021-11-06 1:25 UTC (permalink / raw)
To: Albert Wang; +Cc: balbi, gregkh, badhri, linux-usb, linux-kernel, Wesley Cheng
On Thu, Nov 04, 2021 at 02:26:16PM +0800, Albert Wang wrote:
> In the endpoint interrupt functions
> dwc3_gadget_endpoint_transfer_in_progress() and
> dwc3_gadget_endpoint_trbs_complete() will dereference the endpoint
> descriptor. But it could be cleared in __dwc3_gadget_ep_disable()
> when accessory disconnected. So we need to check whether it is null
> or not before dereferencing it.
>
> Signed-off-by: Albert Wang <albertccwang@google.com>
Nice catch. I think this might have been caused when the call to
dwc3_remove_requests() in __dwc3_gadget_ep_disable() was moved after
the endpoint descriptors is cleared. So you can probably add:
Fixes: f09ddcfcb8c5 ("usb: dwc3: gadget: Prevent EP queuing while
stopping transfers").
Reviewed-by: Jack Pham <quic_jackp@quicinc.com>
> ---
> drivers/usb/dwc3/gadget.c | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
> index 23de2a5a40d6..83c7344888fd 100644
> --- a/drivers/usb/dwc3/gadget.c
> +++ b/drivers/usb/dwc3/gadget.c
> @@ -3252,6 +3252,9 @@ static bool dwc3_gadget_endpoint_trbs_complete(struct dwc3_ep *dep,
> struct dwc3 *dwc = dep->dwc;
> bool no_started_trb = true;
>
> + if (!dep->endpoint.desc)
> + return no_started_trb;
> +
> dwc3_gadget_ep_cleanup_completed_requests(dep, event, status);
>
> if (dep->flags & DWC3_EP_END_TRANSFER_PENDING)
> @@ -3299,6 +3302,9 @@ static void dwc3_gadget_endpoint_transfer_in_progress(struct dwc3_ep *dep,
> {
> int status = 0;
>
> + if (!dep->endpoint.desc)
> + return;
> +
> if (usb_endpoint_xfer_isoc(dep->endpoint.desc))
> dwc3_gadget_endpoint_frame_from_event(dep, event);
>
> --
> 2.33.1.1089.g2158813163f-goog
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] usb: dwc3: gadget: Fix null pointer exception
2021-11-06 1:25 ` Jack Pham
@ 2021-11-09 5:10 ` Albert Wang
0 siblings, 0 replies; 3+ messages in thread
From: Albert Wang @ 2021-11-09 5:10 UTC (permalink / raw)
To: Jack Pham; +Cc: balbi, gregkh, badhri, linux-usb, linux-kernel, Wesley Cheng
Ok, let me do that.
Thanks,
Albert
On Sat, Nov 6, 2021 at 9:25 AM Jack Pham <quic_jackp@quicinc.com> wrote:
>
> On Thu, Nov 04, 2021 at 02:26:16PM +0800, Albert Wang wrote:
> > In the endpoint interrupt functions
> > dwc3_gadget_endpoint_transfer_in_progress() and
> > dwc3_gadget_endpoint_trbs_complete() will dereference the endpoint
> > descriptor. But it could be cleared in __dwc3_gadget_ep_disable()
> > when accessory disconnected. So we need to check whether it is null
> > or not before dereferencing it.
> >
> > Signed-off-by: Albert Wang <albertccwang@google.com>
>
> Nice catch. I think this might have been caused when the call to
> dwc3_remove_requests() in __dwc3_gadget_ep_disable() was moved after
> the endpoint descriptors is cleared. So you can probably add:
>
> Fixes: f09ddcfcb8c5 ("usb: dwc3: gadget: Prevent EP queuing while
> stopping transfers").
>
> Reviewed-by: Jack Pham <quic_jackp@quicinc.com>
>
> > ---
> > drivers/usb/dwc3/gadget.c | 6 ++++++
> > 1 file changed, 6 insertions(+)
> >
> > diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
> > index 23de2a5a40d6..83c7344888fd 100644
> > --- a/drivers/usb/dwc3/gadget.c
> > +++ b/drivers/usb/dwc3/gadget.c
> > @@ -3252,6 +3252,9 @@ static bool dwc3_gadget_endpoint_trbs_complete(struct dwc3_ep *dep,
> > struct dwc3 *dwc = dep->dwc;
> > bool no_started_trb = true;
> >
> > + if (!dep->endpoint.desc)
> > + return no_started_trb;
> > +
> > dwc3_gadget_ep_cleanup_completed_requests(dep, event, status);
> >
> > if (dep->flags & DWC3_EP_END_TRANSFER_PENDING)
> > @@ -3299,6 +3302,9 @@ static void dwc3_gadget_endpoint_transfer_in_progress(struct dwc3_ep *dep,
> > {
> > int status = 0;
> >
> > + if (!dep->endpoint.desc)
> > + return;
> > +
> > if (usb_endpoint_xfer_isoc(dep->endpoint.desc))
> > dwc3_gadget_endpoint_frame_from_event(dep, event);
> >
> > --
> > 2.33.1.1089.g2158813163f-goog
> >
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-11-09 5:10 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-04 6:26 [PATCH] usb: dwc3: gadget: Fix null pointer exception Albert Wang
2021-11-06 1:25 ` Jack Pham
2021-11-09 5:10 ` Albert Wang
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).