Skip to contentSkip to conversation

usb: dwc2: gadget: avoid null dereference on incomplete transfer

PATCH In review John Keeping 3 participants 4 messages Mar 14, 2016 – Apr 4, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 usb: dwc2: gadget: avoid null dereference on incomplete transfer

Setting up a gadget with the uac2 function results in:

  Unable to handle kernel NULL pointer dereference at virtual address 00000058
  ...
  PC is at dwc2_hsotg_irq+0x7f0/0x908
  LR is at dwc2_hsotg_irq+0x4c/0x908
  Backtrace:
  [<c03cd5fc>] (dwc2_hsotg_irq) from [<c00814fc>] (handle_irq_event_percpu+0x130/0x3ec)
  [<c00813cc>] (handle_irq_event_percpu) from [<c0081800>] (handle_irq_event+0x48/0x6c)

In all other loops we already skip endpoints that are null, so do so here as well.

---
 drivers/usb/dwc2/gadget.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/usb/dwc2/gadget.c +6 -2
index 0abf73c..df43ec0 100644
@@ -2606,7 +2606,9 @@ irq_retry:
 		for (idx = 1; idx < hsotg->num_of_eps; idx++) {
 			hs_ep = hsotg->eps_in[idx];
 
-			if (!hs_ep->isochronous || hs_ep->has_correct_parity)
+			if (!hs_ep ||
+			    !hs_ep->isochronous ||
+			    hs_ep->has_correct_parity)
 				continue;
 
 			epctl_reg = DIEPCTL(idx);
@@ -2623,7 +2625,9 @@ irq_retry:
 		for (idx = 1; idx < hsotg->num_of_eps; idx++) {
 			hs_ep = hsotg->eps_out[idx];
 
-			if (!hs_ep->isochronous || hs_ep->has_correct_parity)
+			if (!hs_ep ||
+			    !hs_ep->isochronous ||
+			    hs_ep->has_correct_parity)
 				continue;
 
 			epctl_reg = DOEPCTL(idx);
Signature · 1 line
2.7.0.226.gfe986fe
#1 lore raw

Hi,

Quoted 23 lines · John Keeping

Setting up a gadget with the uac2 function results in:

  Unable to handle kernel NULL pointer dereference at virtual address 00000058
  ...
  PC is at dwc2_hsotg_irq+0x7f0/0x908
  LR is at dwc2_hsotg_irq+0x4c/0x908
  Backtrace:
  [<c03cd5fc>] (dwc2_hsotg_irq) from [<c00814fc>] (handle_irq_event_percpu+0x130/0x3ec)
  [<c00813cc>] (handle_irq_event_percpu) from [<c0081800>] (handle_irq_event+0x48/0x6c)

In all other loops we already skip endpoints that are null, so do so here as well.

---
 drivers/usb/dwc2/gadget.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/usb/dwc2/gadget.c +0 -0
index 0abf73c..df43ec0 100644

drivers/usb/dwc2/gadget.c irq_retry: · line 2611

Quoted 7 lines
drivers/usb/dwc2/gadget.c +3 -1
@@ -2606,7 +2606,9 @@ irq_retry:
 		for (idx = 1; idx < hsotg->num_of_eps; idx++) {
 			hs_ep = hsotg->eps_in[idx];
 
-			if (!hs_ep->isochronous || hs_ep->has_correct_parity)
+			if (!hs_ep ||
+			    !hs_ep->isochronous ||
+			    hs_ep->has_correct_parity)

this is fine (even though choice of where to break line is a bit odd), but I have a question about how the rest of the code works (a bit off-topic, sorry)

drivers/usb/dwc2/gadget.c irq_retry: · line 2614

Quoted 3 lines
drivers/usb/dwc2/gadget.c +0 -0
 				continue;
 
 			epctl_reg = DIEPCTL(idx);

So, this means that the first ISO endpoint without correct parity will be used. Isn't this a bit fragile ? What happens when you use a device with several different interfaces using several different endpoints ?

Isn't there a register where we can check which physical endpoint generated the IRQ ? Seems like you really wanna check what:

#define DIEPINT(_a) HSOTG_REG(0x908 + ((_a) * 0x20))

say about eps_in[idx].

drivers/usb/dwc2/gadget.c irq_retry: · line 2633

Quoted 11 lines
drivers/usb/dwc2/gadget.c +3 -1
@@ -2623,7 +2625,9 @@ irq_retry:
 		for (idx = 1; idx < hsotg->num_of_eps; idx++) {
 			hs_ep = hsotg->eps_out[idx];
 
-			if (!hs_ep->isochronous || hs_ep->has_correct_parity)
+			if (!hs_ep ||
+			    !hs_ep->isochronous ||
+			    hs_ep->has_correct_parity)
 				continue;
 
 			epctl_reg = DOEPCTL(idx);

ditto for eps_out[idx] and:

#define DOEPINT(_a) HSOTG_REG(0xB08 + ((_a) * 0x20))

comments ?

Signature · 1 line
balbi
#2 lore raw
Quoted 41 lines · Felipe Balbi

Hi,

Quoted 23 lines · John Keeping

Setting up a gadget with the uac2 function results in:

  Unable to handle kernel NULL pointer dereference at virtual address 00000058
  ...
  PC is at dwc2_hsotg_irq+0x7f0/0x908
  LR is at dwc2_hsotg_irq+0x4c/0x908
  Backtrace:
  [<c03cd5fc>] (dwc2_hsotg_irq) from [<c00814fc>] (handle_irq_event_percpu+0x130/0x3ec)
  [<c00813cc>] (handle_irq_event_percpu) from [<c0081800>] (handle_irq_event+0x48/0x6c)

In all other loops we already skip endpoints that are null, so do so here as well.

---
 drivers/usb/dwc2/gadget.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/usb/dwc2/gadget.c +0 -0
index 0abf73c..df43ec0 100644

drivers/usb/dwc2/gadget.c irq_retry: · line 2611

Quoted 7 lines
drivers/usb/dwc2/gadget.c +3 -1
@@ -2606,7 +2606,9 @@ irq_retry:
 		for (idx = 1; idx < hsotg->num_of_eps; idx++) {
 			hs_ep = hsotg->eps_in[idx];
 
-			if (!hs_ep->isochronous || hs_ep->has_correct_parity)
+			if (!hs_ep ||
+			    !hs_ep->isochronous ||
+			    hs_ep->has_correct_parity)

this is fine (even though choice of where to break line is a bit odd), but I have a question about how the rest of the code works (a bit off-topic, sorry)

Quoted 2 lines
drivers/usb/dwc2/gadget.c +0 -0
 				continue;
 
Quoted 9 lines

drivers/usb/dwc2/gadget.c irq_retry: · line 2614

Quoted 1 line
drivers/usb/dwc2/gadget.c +0 -0
 			epctl_reg = DIEPCTL(idx);

So, this means that the first ISO endpoint without correct parity will be used. Isn't this a bit fragile ? What happens when you use a device with several different interfaces using several different endpoints ?

Isn't there a register where we can check which physical endpoint generated the IRQ ? Seems like you really wanna check what:

We discussed this back when the patch was first submitted and determined it should work fine like this. I don't remember exactly why though.

But this ISOC parity stuff is a workaround and we have a series of patches to correctly set up ISOC allowing us to remove it. We're doing some final tests before we send them.

Regards,
John

#3 lore raw

Hi,

Quoted 52 lines · John Youn
Quoted 41 lines · Felipe Balbi

Hi,

Quoted 23 lines · John Keeping

Setting up a gadget with the uac2 function results in:

  Unable to handle kernel NULL pointer dereference at virtual address 00000058
  ...
  PC is at dwc2_hsotg_irq+0x7f0/0x908
  LR is at dwc2_hsotg_irq+0x4c/0x908
  Backtrace:
  [<c03cd5fc>] (dwc2_hsotg_irq) from [<c00814fc>] (handle_irq_event_percpu+0x130/0x3ec)
  [<c00813cc>] (handle_irq_event_percpu) from [<c0081800>] (handle_irq_event+0x48/0x6c)

In all other loops we already skip endpoints that are null, so do so here as well.

---
 drivers/usb/dwc2/gadget.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/usb/dwc2/gadget.c +0 -0
index 0abf73c..df43ec0 100644

drivers/usb/dwc2/gadget.c irq_retry: · line 2611

Quoted 7 lines
drivers/usb/dwc2/gadget.c +3 -1
@@ -2606,7 +2606,9 @@ irq_retry:
 		for (idx = 1; idx < hsotg->num_of_eps; idx++) {
 			hs_ep = hsotg->eps_in[idx];
 
-			if (!hs_ep->isochronous || hs_ep->has_correct_parity)
+			if (!hs_ep ||
+			    !hs_ep->isochronous ||
+			    hs_ep->has_correct_parity)

this is fine (even though choice of where to break line is a bit odd), but I have a question about how the rest of the code works (a bit off-topic, sorry)

Quoted 2 lines
drivers/usb/dwc2/gadget.c +0 -0
 				continue;
 
Quoted 9 lines

drivers/usb/dwc2/gadget.c irq_retry: · line 2614

Quoted 1 line
drivers/usb/dwc2/gadget.c +0 -0
 			epctl_reg = DIEPCTL(idx);

So, this means that the first ISO endpoint without correct parity will be used. Isn't this a bit fragile ? What happens when you use a device with several different interfaces using several different endpoints ?

Isn't there a register where we can check which physical endpoint generated the IRQ ? Seems like you really wanna check what:

Quoted 7 lines

We discussed this back when the patch was first submitted and determined it should work fine like this. I don't remember exactly why though.

But this ISOC parity stuff is a workaround and we have a series of patches to correctly set up ISOC allowing us to remove it. We're doing some final tests before we send them.

fair enough, thanks

Signature · 1 line
balbi