public inbox for linux-omap@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] MUSB: fix memory corruption when using more than max endpoints
@ 2008-09-10  5:53 Kevin Hilman
       [not found] ` <1221026036-26477-1-git-send-email-khilman-1D3HCaltpLuhEniVeURVKkEOCMrvLtNR@public.gmane.org>
  0 siblings, 1 reply; 7+ messages in thread
From: Kevin Hilman @ 2008-09-10  5:53 UTC (permalink / raw)
  To: linux-omap; +Cc: Kevin Hilman

There is no check if platform code passes in more endpoints (num_eps)
than the maximum number of enpoints (MUSB_C_NUM_EPS.)  The result is
that allocate_instance() happily writes past the end of 'struct musb'
corrupting memory.

The fix below increases the max to 32 (used on omap3) and also adds a
BUG() if the platform code requests more than the max.

This memory corruption was triggering various forms of crashes/panics
with kmem_cache_alloc() in the backtrace.

Signed-off-by: Kevin Hilman <khilman@deeprootsystems.com>
---
 drivers/usb/musb/musb_core.c |    1 +
 drivers/usb/musb/musb_core.h |    2 +-
 2 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
index c939f81..a132d9f 100644
--- a/drivers/usb/musb/musb_core.c
+++ b/drivers/usb/musb/musb_core.c
@@ -1806,6 +1806,7 @@ allocate_instance(struct device *dev,
 	musb->ctrl_base = mbase;
 	musb->nIrq = -ENODEV;
 	musb->config = config;
+	BUG_ON(musb->config->num_eps > MUSB_C_NUM_EPS);
 	for (epnum = 0, ep = musb->endpoints;
 			epnum < musb->config->num_eps;
 			epnum++, ep++) {
diff --git a/drivers/usb/musb/musb_core.h b/drivers/usb/musb/musb_core.h
index 8222725..5040ceb 100644
--- a/drivers/usb/musb/musb_core.h
+++ b/drivers/usb/musb/musb_core.h
@@ -153,7 +153,7 @@ static inline void musb_host_rx(struct musb *m, u8 e) {}
 /****************************** CONSTANTS ********************************/
 
 #ifndef MUSB_C_NUM_EPS
-#define MUSB_C_NUM_EPS ((u8)16)
+#define MUSB_C_NUM_EPS ((u8)32)
 #endif
 
 #ifndef MUSB_MAX_END0_PACKET
-- 
1.6.0


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

* Re: [PATCH] MUSB: fix memory corruption when using more than max endpoints
       [not found] ` <1221026036-26477-1-git-send-email-khilman-1D3HCaltpLuhEniVeURVKkEOCMrvLtNR@public.gmane.org>
@ 2008-09-10 10:36   ` Felipe Balbi
       [not found]     ` <20080910103616.GQ16796-f9ZlEuEWxVfta4EC/59zMBl4MBrZKKet0E9HWUfgJXw@public.gmane.org>
  0 siblings, 1 reply; 7+ messages in thread
From: Felipe Balbi @ 2008-09-10 10:36 UTC (permalink / raw)
  To: ext Kevin Hilman
  Cc: linux-omap-u79uwXL29TY76Z2rM5mHXA,
	linux-usb-u79uwXL29TY76Z2rM5mHXA

Let's keep linux-usb on the loop for musb related patches ;-)

On Wed, Sep 10, 2008 at 08:53:56AM +0300, ext Kevin Hilman wrote:
> There is no check if platform code passes in more endpoints (num_eps)
> than the maximum number of enpoints (MUSB_C_NUM_EPS.)  The result is
> that allocate_instance() happily writes past the end of 'struct musb'
> corrupting memory.
> 
> The fix below increases the max to 32 (used on omap3) and also adds a
> BUG() if the platform code requests more than the max.
> 
> This memory corruption was triggering various forms of crashes/panics
> with kmem_cache_alloc() in the backtrace.
> 
> Signed-off-by: Kevin Hilman <khilman-1D3HCaltpLuhEniVeURVKkEOCMrvLtNR@public.gmane.org>

Looks ok, I'll put to my series.

> ---
>  drivers/usb/musb/musb_core.c |    1 +
>  drivers/usb/musb/musb_core.h |    2 +-
>  2 files changed, 2 insertions(+), 1 deletions(-)
> 
> diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
> index c939f81..a132d9f 100644
> --- a/drivers/usb/musb/musb_core.c
> +++ b/drivers/usb/musb/musb_core.c
> @@ -1806,6 +1806,7 @@ allocate_instance(struct device *dev,
>  	musb->ctrl_base = mbase;
>  	musb->nIrq = -ENODEV;
>  	musb->config = config;
> +	BUG_ON(musb->config->num_eps > MUSB_C_NUM_EPS);

It's good to have this check here.

>  	for (epnum = 0, ep = musb->endpoints;
>  			epnum < musb->config->num_eps;
>  			epnum++, ep++) {
> diff --git a/drivers/usb/musb/musb_core.h b/drivers/usb/musb/musb_core.h
> index 8222725..5040ceb 100644
> --- a/drivers/usb/musb/musb_core.h
> +++ b/drivers/usb/musb/musb_core.h
> @@ -153,7 +153,7 @@ static inline void musb_host_rx(struct musb *m, u8 e) {}
>  /****************************** CONSTANTS ********************************/
>  
>  #ifndef MUSB_C_NUM_EPS
> -#define MUSB_C_NUM_EPS ((u8)16)
> +#define MUSB_C_NUM_EPS ((u8)32)

16 is the right number.

-- 
balbi
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH] MUSB: fix memory corruption when using more than max endpoints
       [not found]     ` <20080910103616.GQ16796-f9ZlEuEWxVfta4EC/59zMBl4MBrZKKet0E9HWUfgJXw@public.gmane.org>
@ 2008-09-10 11:20       ` Kevin Hilman
  2008-09-10 11:26         ` Felipe Balbi
  2008-09-15  8:52       ` Felipe Balbi
  1 sibling, 1 reply; 7+ messages in thread
From: Kevin Hilman @ 2008-09-10 11:20 UTC (permalink / raw)
  To: felipe.balbi-xNZwKgViW5gAvxtiuMwx3w
  Cc: linux-omap-u79uwXL29TY76Z2rM5mHXA,
	linux-usb-u79uwXL29TY76Z2rM5mHXA

Felipe Balbi wrote:
> Let's keep linux-usb on the loop for musb related patches ;-)
> 
> On Wed, Sep 10, 2008 at 08:53:56AM +0300, ext Kevin Hilman wrote:
>> There is no check if platform code passes in more endpoints (num_eps)
>> than the maximum number of enpoints (MUSB_C_NUM_EPS.)  The result is
>> that allocate_instance() happily writes past the end of 'struct musb'
>> corrupting memory.
>>
>> The fix below increases the max to 32 (used on omap3) and also adds a
>> BUG() if the platform code requests more than the max.
>>
>> This memory corruption was triggering various forms of crashes/panics
>> with kmem_cache_alloc() in the backtrace.
>>
>> Signed-off-by: Kevin Hilman <khilman-1D3HCaltpLuhEniVeURVKkEOCMrvLtNR@public.gmane.org>
> 
> Looks ok, I'll put to my series.
> 
>> ---
>>  drivers/usb/musb/musb_core.c |    1 +
>>  drivers/usb/musb/musb_core.h |    2 +-
>>  2 files changed, 2 insertions(+), 1 deletions(-)
>>
>> diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
>> index c939f81..a132d9f 100644
>> --- a/drivers/usb/musb/musb_core.c
>> +++ b/drivers/usb/musb/musb_core.c
>> @@ -1806,6 +1806,7 @@ allocate_instance(struct device *dev,
>>  	musb->ctrl_base = mbase;
>>  	musb->nIrq = -ENODEV;
>>  	musb->config = config;
>> +	BUG_ON(musb->config->num_eps > MUSB_C_NUM_EPS);
> 
> It's good to have this check here.
> 
>>  	for (epnum = 0, ep = musb->endpoints;
>>  			epnum < musb->config->num_eps;
>>  			epnum++, ep++) {
>> diff --git a/drivers/usb/musb/musb_core.h b/drivers/usb/musb/musb_core.h
>> index 8222725..5040ceb 100644
>> --- a/drivers/usb/musb/musb_core.h
>> +++ b/drivers/usb/musb/musb_core.h
>> @@ -153,7 +153,7 @@ static inline void musb_host_rx(struct musb *m, u8 e) {}
>>  /****************************** CONSTANTS ********************************/
>>  
>>  #ifndef MUSB_C_NUM_EPS
>> -#define MUSB_C_NUM_EPS ((u8)16)
>> +#define MUSB_C_NUM_EPS ((u8)32)
> 
> 16 is the right number.
> 

If 16 is the right number, arch/arm/mach-omap2/usb-musb.c going to 
trigger this BUG every time since it sets num_eps = 32.

I don't know much about MUSB enbpoints, but if 16 is the correct max, 
then the platform code should be updated.

Kevin

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH] MUSB: fix memory corruption when using more than max endpoints
  2008-09-10 11:20       ` Kevin Hilman
@ 2008-09-10 11:26         ` Felipe Balbi
       [not found]           ` <20080910112656.GR16796-f9ZlEuEWxVfta4EC/59zMBl4MBrZKKet0E9HWUfgJXw@public.gmane.org>
  0 siblings, 1 reply; 7+ messages in thread
From: Felipe Balbi @ 2008-09-10 11:26 UTC (permalink / raw)
  To: ext Kevin Hilman; +Cc: felipe.balbi, linux-omap, linux-usb

On Wed, Sep 10, 2008 at 02:20:35PM +0300, ext Kevin Hilman wrote:
> Felipe Balbi wrote:
>> Let's keep linux-usb on the loop for musb related patches ;-)
>>
>> On Wed, Sep 10, 2008 at 08:53:56AM +0300, ext Kevin Hilman wrote:
>>> There is no check if platform code passes in more endpoints (num_eps)
>>> than the maximum number of enpoints (MUSB_C_NUM_EPS.)  The result is
>>> that allocate_instance() happily writes past the end of 'struct musb'
>>> corrupting memory.
>>>
>>> The fix below increases the max to 32 (used on omap3) and also adds a
>>> BUG() if the platform code requests more than the max.
>>>
>>> This memory corruption was triggering various forms of crashes/panics
>>> with kmem_cache_alloc() in the backtrace.
>>>
>>> Signed-off-by: Kevin Hilman <khilman@deeprootsystems.com>
>>
>> Looks ok, I'll put to my series.
>>
>>> ---
>>>  drivers/usb/musb/musb_core.c |    1 +
>>>  drivers/usb/musb/musb_core.h |    2 +-
>>>  2 files changed, 2 insertions(+), 1 deletions(-)
>>>
>>> diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
>>> index c939f81..a132d9f 100644
>>> --- a/drivers/usb/musb/musb_core.c
>>> +++ b/drivers/usb/musb/musb_core.c
>>> @@ -1806,6 +1806,7 @@ allocate_instance(struct device *dev,
>>>  	musb->ctrl_base = mbase;
>>>  	musb->nIrq = -ENODEV;
>>>  	musb->config = config;
>>> +	BUG_ON(musb->config->num_eps > MUSB_C_NUM_EPS);
>>
>> It's good to have this check here.
>>
>>>  	for (epnum = 0, ep = musb->endpoints;
>>>  			epnum < musb->config->num_eps;
>>>  			epnum++, ep++) {
>>> diff --git a/drivers/usb/musb/musb_core.h b/drivers/usb/musb/musb_core.h
>>> index 8222725..5040ceb 100644
>>> --- a/drivers/usb/musb/musb_core.h
>>> +++ b/drivers/usb/musb/musb_core.h
>>> @@ -153,7 +153,7 @@ static inline void musb_host_rx(struct musb *m, u8 e) {}
>>>  /****************************** CONSTANTS ********************************/
>>>   #ifndef MUSB_C_NUM_EPS
>>> -#define MUSB_C_NUM_EPS ((u8)16)
>>> +#define MUSB_C_NUM_EPS ((u8)32)
>>
>> 16 is the right number.
>>
>
> If 16 is the right number, arch/arm/mach-omap2/usb-musb.c going to trigger 
> this BUG every time since it sets num_eps = 32.
>
> I don't know much about MUSB enbpoints, but if 16 is the correct max, then 
> the platform code should be updated.

Check recent Dave's patches to usb-musb.c ;-)

-- 
balbi

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

* Re: [PATCH] MUSB: fix memory corruption when using more than max endpoints
       [not found]           ` <20080910112656.GR16796-f9ZlEuEWxVfta4EC/59zMBl4MBrZKKet0E9HWUfgJXw@public.gmane.org>
@ 2008-09-10 23:52             ` Tony Lindgren
  2008-09-11  8:16               ` Felipe Balbi
  0 siblings, 1 reply; 7+ messages in thread
From: Tony Lindgren @ 2008-09-10 23:52 UTC (permalink / raw)
  To: Felipe Balbi
  Cc: ext Kevin Hilman, linux-omap-u79uwXL29TY76Z2rM5mHXA,
	linux-usb-u79uwXL29TY76Z2rM5mHXA

* Felipe Balbi <felipe.balbi-xNZwKgViW5gAvxtiuMwx3w@public.gmane.org> [080910 04:27]:
> On Wed, Sep 10, 2008 at 02:20:35PM +0300, ext Kevin Hilman wrote:
> > Felipe Balbi wrote:
> >> Let's keep linux-usb on the loop for musb related patches ;-)
> >>
> >> On Wed, Sep 10, 2008 at 08:53:56AM +0300, ext Kevin Hilman wrote:
> >>> There is no check if platform code passes in more endpoints (num_eps)
> >>> than the maximum number of enpoints (MUSB_C_NUM_EPS.)  The result is
> >>> that allocate_instance() happily writes past the end of 'struct musb'
> >>> corrupting memory.
> >>>
> >>> The fix below increases the max to 32 (used on omap3) and also adds a
> >>> BUG() if the platform code requests more than the max.
> >>>
> >>> This memory corruption was triggering various forms of crashes/panics
> >>> with kmem_cache_alloc() in the backtrace.
> >>>
> >>> Signed-off-by: Kevin Hilman <khilman-1D3HCaltpLuhEniVeURVKkEOCMrvLtNR@public.gmane.org>
> >>
> >> Looks ok, I'll put to my series.
> >>
> >>> ---
> >>>  drivers/usb/musb/musb_core.c |    1 +
> >>>  drivers/usb/musb/musb_core.h |    2 +-
> >>>  2 files changed, 2 insertions(+), 1 deletions(-)
> >>>
> >>> diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
> >>> index c939f81..a132d9f 100644
> >>> --- a/drivers/usb/musb/musb_core.c
> >>> +++ b/drivers/usb/musb/musb_core.c
> >>> @@ -1806,6 +1806,7 @@ allocate_instance(struct device *dev,
> >>>  	musb->ctrl_base = mbase;
> >>>  	musb->nIrq = -ENODEV;
> >>>  	musb->config = config;
> >>> +	BUG_ON(musb->config->num_eps > MUSB_C_NUM_EPS);
> >>
> >> It's good to have this check here.
> >>
> >>>  	for (epnum = 0, ep = musb->endpoints;
> >>>  			epnum < musb->config->num_eps;
> >>>  			epnum++, ep++) {
> >>> diff --git a/drivers/usb/musb/musb_core.h b/drivers/usb/musb/musb_core.h
> >>> index 8222725..5040ceb 100644
> >>> --- a/drivers/usb/musb/musb_core.h
> >>> +++ b/drivers/usb/musb/musb_core.h
> >>> @@ -153,7 +153,7 @@ static inline void musb_host_rx(struct musb *m, u8 e) {}
> >>>  /****************************** CONSTANTS ********************************/
> >>>   #ifndef MUSB_C_NUM_EPS
> >>> -#define MUSB_C_NUM_EPS ((u8)16)
> >>> +#define MUSB_C_NUM_EPS ((u8)32)
> >>
> >> 16 is the right number.
> >>
> >
> > If 16 is the right number, arch/arm/mach-omap2/usb-musb.c going to trigger 
> > this BUG every time since it sets num_eps = 32.
> >
> > I don't know much about MUSB enbpoints, but if 16 is the correct max, then 
> > the platform code should be updated.
> 
> Check recent Dave's patches to usb-musb.c ;-)

I guess you're talking about 8cc4af26d1e2b01cd9dc2c5e6b166d08946bc2e6
that I just pushed?

Tony
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH] MUSB: fix memory corruption when using more than max endpoints
  2008-09-10 23:52             ` Tony Lindgren
@ 2008-09-11  8:16               ` Felipe Balbi
  0 siblings, 0 replies; 7+ messages in thread
From: Felipe Balbi @ 2008-09-11  8:16 UTC (permalink / raw)
  To: ext Tony Lindgren; +Cc: Felipe Balbi, ext Kevin Hilman, linux-omap, linux-usb

On Wed, Sep 10, 2008 at 04:52:03PM -0700, Tony Lindgren wrote:
> I guess you're talking about 8cc4af26d1e2b01cd9dc2c5e6b166d08946bc2e6
> that I just pushed?

Precisely.

-- 
balbi

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

* Re: [PATCH] MUSB: fix memory corruption when using more than max endpoints
       [not found]     ` <20080910103616.GQ16796-f9ZlEuEWxVfta4EC/59zMBl4MBrZKKet0E9HWUfgJXw@public.gmane.org>
  2008-09-10 11:20       ` Kevin Hilman
@ 2008-09-15  8:52       ` Felipe Balbi
  1 sibling, 0 replies; 7+ messages in thread
From: Felipe Balbi @ 2008-09-15  8:52 UTC (permalink / raw)
  To: ext Felipe Balbi
  Cc: ext Kevin Hilman, linux-omap-u79uwXL29TY76Z2rM5mHXA,
	linux-usb-u79uwXL29TY76Z2rM5mHXA

On Wed, Sep 10, 2008 at 01:36:16PM +0300, ext Felipe Balbi wrote:
> Let's keep linux-usb on the loop for musb related patches ;-)
> 
> On Wed, Sep 10, 2008 at 08:53:56AM +0300, ext Kevin Hilman wrote:
> > There is no check if platform code passes in more endpoints (num_eps)
> > than the maximum number of enpoints (MUSB_C_NUM_EPS.)  The result is
> > that allocate_instance() happily writes past the end of 'struct musb'
> > corrupting memory.
> > 
> > The fix below increases the max to 32 (used on omap3) and also adds a
> > BUG() if the platform code requests more than the max.
> > 
> > This memory corruption was triggering various forms of crashes/panics
> > with kmem_cache_alloc() in the backtrace.
> > 
> > Signed-off-by: Kevin Hilman <khilman-1D3HCaltpLuhEniVeURVKkEOCMrvLtNR@public.gmane.org>

Could you update this patch without the last change of max endpoints ???

-- 
balbi
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

end of thread, other threads:[~2008-09-15  8:52 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-09-10  5:53 [PATCH] MUSB: fix memory corruption when using more than max endpoints Kevin Hilman
     [not found] ` <1221026036-26477-1-git-send-email-khilman-1D3HCaltpLuhEniVeURVKkEOCMrvLtNR@public.gmane.org>
2008-09-10 10:36   ` Felipe Balbi
     [not found]     ` <20080910103616.GQ16796-f9ZlEuEWxVfta4EC/59zMBl4MBrZKKet0E9HWUfgJXw@public.gmane.org>
2008-09-10 11:20       ` Kevin Hilman
2008-09-10 11:26         ` Felipe Balbi
     [not found]           ` <20080910112656.GR16796-f9ZlEuEWxVfta4EC/59zMBl4MBrZKKet0E9HWUfgJXw@public.gmane.org>
2008-09-10 23:52             ` Tony Lindgren
2008-09-11  8:16               ` Felipe Balbi
2008-09-15  8:52       ` Felipe Balbi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox