MUSB: fix memory corruption when using more than max endpoints
Subsystems (2)
PATCH 1/1 MUSB: fix memory corruption when using more than max endpoints
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.
--- drivers/usb/musb/musb_core.c | 1 + drivers/usb/musb/musb_core.h | 2 +- 2 files changed, 2 insertions(+), 1 deletions(-)
drivers/usb/musb/musb_core.c +1 -0
@@ -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++) {
drivers/usb/musb/musb_core.h +1 -1
@@ -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
Signature · 1 line
1.6.0
A message that is not in the archive (sent off-list or not yet received): 1221026036-26477-1-git-send-email-khilman-1D3HCaltpLuhEniVeURVKkEOCMrvLtNR@public.gmane.org
Let's keep linux-usb on the loop for musb related patches ;-)
Quoted 5 lines · ext 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 thatallocate_instance()happily writes past the end of 'struct musb' corrupting memory.
Quoted 7 lines
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 <[email protected]>
Looks ok, I'll put to my series.
Quoted 10 lines
--- drivers/usb/musb/musb_core.c | 1 + drivers/usb/musb/musb_core.h | 2 +- 2 files changed, 2 insertions(+), 1 deletions(-)drivers/usb/musb/musb_core.c +0
-0
drivers/usb/musb/musb_core.c allocate_instance(struct device *dev, · line 1809
Quoted 4 lines
drivers/usb/musb/musb_core.c +1
-0@@ -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.
drivers/usb/musb/musb_core.h static inline void musb_host_rx(struct musb *m, u8 e) {} · line 156
Quoted 13 lines
drivers/usb/musb/musb_core.c +0
-0for (epnum =0 , ep = musb->endpoints; epnum < musb->config->num_eps; epnum++, ep++) {drivers/usb/musb/musb_core.h +1
-1@@ -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.
Signature · 5 lines
balbi -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
A message that is not in the archive (sent off-list or not yet received): 20080910103616.GQ16796-f9ZlEuEWxVfta4EC/[email protected]
Quoted 45 lines · Felipe Balbi
Let's keep linux-usb on the loop for musb related patches ;-)
Quoted 5 lines · ext 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 thatallocate_instance()happily writes past the end of 'struct musb' corrupting memory.Quoted 7 lines
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 <[email protected]>Looks ok, I'll put to my series.
Quoted 10 lines
--- drivers/usb/musb/musb_core.c | 1 + drivers/usb/musb/musb_core.h | 2 +- 2 files changed, 2 insertions(+), 1 deletions(-)drivers/usb/musb/musb_core.c +0
-0drivers/usb/musb/musb_core.c allocate_instance(struct device *dev, · line 1809
Quoted 4 lines
drivers/usb/musb/musb_core.c +1
-0@@ -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.
Quoted 10 lines
drivers/usb/musb/musb_core.c +0
-0for (epnum =0 , ep = musb->endpoints; epnum < musb->config->num_eps; epnum++, ep++) {drivers/usb/musb/musb_core.h +0
-0@@ -153,7 +153,7 @@ static inline void musb_host_rx(struct musb *m, u8 e) {}/****************************** CONSTANTS ********************************/
Quoted 6 lines
drivers/usb/musb/musb_core.h static inline void musb_host_rx(struct musb *m, u8 e) {} · line 156
Quoted 3 lines
drivers/usb/musb/musb_core.h +1
-1#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 [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 52 lines · ext Kevin Hilman
Quoted 35 lines · Felipe Balbi
Let's keep linux-usb on the loop for musb related patches ;-)
Quoted 5 lines · ext 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 thatallocate_instance()happily writes past the end of 'struct musb' corrupting memory.Quoted 7 lines
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 <[email protected]>Looks ok, I'll put to my series.
Quoted 10 lines
--- drivers/usb/musb/musb_core.c | 1 + drivers/usb/musb/musb_core.h | 2 +- 2 files changed, 2 insertions(+), 1 deletions(-)drivers/usb/musb/musb_core.c +0
-0drivers/usb/musb/musb_core.c allocate_instance(struct device *dev, · line 1809
Quoted 4 lines
drivers/usb/musb/musb_core.c +1
-0@@ -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.
Quoted 15 lines
drivers/usb/musb/musb_core.h static inline void musb_host_rx(struct musb *m, u8 e) {} · line 155
Quoted 12 lines
drivers/usb/musb/musb_core.c +0
-0for (epnum =0 , ep = musb->endpoints; epnum < musb->config->num_eps; epnum++, ep++) {drivers/usb/musb/musb_core.h +1
-1@@ -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.
Quoted 5 lines
If 16 is the right number,
arch/arm/mach-omap2/usb-musb.cgoing to trigger this BUG every time since it setsnum_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 ;-)
Signature · 1 line
balbi
A message that is not in the archive (sent off-list or not yet received): 20080910112656.GR16796-f9ZlEuEWxVfta4EC/[email protected]
Quoted 53 lines · Felipe Balbi
Quoted 52 lines · ext Kevin Hilman
Quoted 50 lines · Felipe Balbi
Let's keep linux-usb on the loop for musb related patches ;-)
Quoted 5 lines · ext 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 thatallocate_instance()happily writes past the end of 'struct musb' corrupting memory.Quoted 7 lines
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 <[email protected]>Looks ok, I'll put to my series.
Quoted 10 lines
--- drivers/usb/musb/musb_core.c | 1 + drivers/usb/musb/musb_core.h | 2 +- 2 files changed, 2 insertions(+), 1 deletions(-)drivers/usb/musb/musb_core.c +0
-0drivers/usb/musb/musb_core.c allocate_instance(struct device *dev, · line 1809
Quoted 4 lines
drivers/usb/musb/musb_core.c +1
-0@@ -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.
drivers/usb/musb/musb_core.h static inline void musb_host_rx(struct musb *m, u8 e) {} · line 155
Quoted 12 lines
drivers/usb/musb/musb_core.c +0
-0for (epnum =0 , ep = musb->endpoints; epnum < musb->config->num_eps; epnum++, ep++) {drivers/usb/musb/musb_core.h +1
-1@@ -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.
Quoted 7 lines
Quoted 5 lines
If 16 is the right number,
arch/arm/mach-omap2/usb-musb.cgoing to trigger this BUG every time since it setsnum_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 [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 2 lines · Tony Lindgren
I guess you're talking about
8cc4af26d1e2b01cd9dc2c5e6b166d08946bc2e6that I just pushed?
Precisely.
Signature · 1 line
balbi
Quoted 15 lines · ext Felipe Balbi
Let's keep linux-usb on the loop for musb related patches ;-)
Quoted 12 lines · ext 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 thatallocate_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 <[email protected]>
Could you update this patch without the last change of max endpoints ???
Signature · 5 lines
balbi -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html