Skip to contentSkip to conversation

usb: dwc3: gadget: Fix null pointer exception

PATCH Superseded Albert Wang 2 participants 3 messages Nov 4, 2021 – Nov 9, 2021

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 usb: dwc3: gadget: Fix null pointer exception

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.

---
 drivers/usb/dwc3/gadget.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/usb/dwc3/gadget.c +6 -0
index 23de2a5a40d6..83c7344888fd 100644
@@ -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);
 
Signature · 1 line
2.33.1.1089.g2158813163f-goog
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · 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.

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").

Quoted 31 lines
---
 drivers/usb/dwc3/gadget.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/usb/dwc3/gadget.c +6 -0
index 23de2a5a40d6..83c7344888fd 100644
@@ -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);
 
Signature · 1 line
2.33.1.1089.g2158813163f-goog
#2 lore raw

Ok, let me do that.

Thanks,
Albert

Quoted 51 lines · Jack Pham
Quoted 8 lines · 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.

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").

Quoted 31 lines
---
 drivers/usb/dwc3/gadget.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/usb/dwc3/gadget.c +6 -1
index 23de2a5a40d6..83c7344888fd 100644
@@ -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