linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] usb: dwc2: gadget: avoid null dereference on incomplete transfer
@ 2016-03-14 19:20 John Keeping
  2016-03-30 13:21 ` Felipe Balbi
  0 siblings, 1 reply; 4+ messages in thread
From: John Keeping @ 2016-03-14 19:20 UTC (permalink / raw)
  To: John Youn; +Cc: John Keeping, Greg Kroah-Hartman, linux-usb, linux-kernel

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.

Signed-off-by: John Keeping <john@metanate.com>
---
 drivers/usb/dwc2/gadget.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
index 0abf73c..df43ec0 100644
--- a/drivers/usb/dwc2/gadget.c
+++ b/drivers/usb/dwc2/gadget.c
@@ -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);
-- 
2.7.0.226.gfe986fe

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] usb: dwc2: gadget: avoid null dereference on incomplete transfer
  2016-03-14 19:20 [PATCH] usb: dwc2: gadget: avoid null dereference on incomplete transfer John Keeping
@ 2016-03-30 13:21 ` Felipe Balbi
  2016-03-30 22:45   ` John Youn
  0 siblings, 1 reply; 4+ messages in thread
From: Felipe Balbi @ 2016-03-30 13:21 UTC (permalink / raw)
  To: John Keeping, John Youn
  Cc: John Keeping, Greg Kroah-Hartman, linux-usb, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 2299 bytes --]


Hi,

John Keeping <john@metanate.com> writes:
> 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.
>
> Signed-off-by: John Keeping <john@metanate.com>
> ---
>  drivers/usb/dwc2/gadget.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
> index 0abf73c..df43ec0 100644
> --- a/drivers/usb/dwc2/gadget.c
> +++ b/drivers/usb/dwc2/gadget.c
> @@ -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)

>  				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].

> @@ -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 ?

-- 
balbi

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 818 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] usb: dwc2: gadget: avoid null dereference on incomplete transfer
  2016-03-30 13:21 ` Felipe Balbi
@ 2016-03-30 22:45   ` John Youn
  2016-04-04 10:51     ` Felipe Balbi
  0 siblings, 1 reply; 4+ messages in thread
From: John Youn @ 2016-03-30 22:45 UTC (permalink / raw)
  To: Felipe Balbi, John Keeping, John Youn
  Cc: Greg Kroah-Hartman, linux-usb, linux-kernel

On 3/30/2016 6:22 AM, Felipe Balbi wrote:
> 
> Hi,
> 
> John Keeping <john@metanate.com> writes:
>> 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.
>>
>> Signed-off-by: John Keeping <john@metanate.com>
>> ---
>>  drivers/usb/dwc2/gadget.c | 8 ++++++--
>>  1 file changed, 6 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
>> index 0abf73c..df43ec0 100644
>> --- a/drivers/usb/dwc2/gadget.c
>> +++ b/drivers/usb/dwc2/gadget.c
>> @@ -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)
> 
>>  				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:
> 

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] usb: dwc2: gadget: avoid null dereference on incomplete transfer
  2016-03-30 22:45   ` John Youn
@ 2016-04-04 10:51     ` Felipe Balbi
  0 siblings, 0 replies; 4+ messages in thread
From: Felipe Balbi @ 2016-04-04 10:51 UTC (permalink / raw)
  To: John Youn, John Keeping, John Youn
  Cc: Greg Kroah-Hartman, linux-usb, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 2350 bytes --]


Hi,

John Youn <John.Youn@synopsys.com> writes:
> On 3/30/2016 6:22 AM, Felipe Balbi wrote:
>> 
>> Hi,
>> 
>> John Keeping <john@metanate.com> writes:
>>> 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.
>>>
>>> Signed-off-by: John Keeping <john@metanate.com>
>>> ---
>>>  drivers/usb/dwc2/gadget.c | 8 ++++++--
>>>  1 file changed, 6 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
>>> index 0abf73c..df43ec0 100644
>>> --- a/drivers/usb/dwc2/gadget.c
>>> +++ b/drivers/usb/dwc2/gadget.c
>>> @@ -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)
>> 
>>>  				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:
>> 
>
> 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

-- 
balbi

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 818 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-04-04 10:53 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-03-14 19:20 [PATCH] usb: dwc2: gadget: avoid null dereference on incomplete transfer John Keeping
2016-03-30 13:21 ` Felipe Balbi
2016-03-30 22:45   ` John Youn
2016-04-04 10:51     ` Felipe Balbi

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