Skip to contentSkip to conversation

MUSB: fix memory corruption when using more than max endpoints

PATCH In review Kevin Hilman 5 participants 7 messages Sep 10, 2008 – Sep 15, 2008 3 messages not in the archive

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

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
index c939f81..a132d9f 100644
@@ -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
index 8222725..5040ceb 100644
@@ -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
#2 lore raw
In reply to a message not in the archive

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 that allocate_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.

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
index c939f81..a132d9f 100644

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 -0
 	for (epnum = 0, ep = musb->endpoints;
 			epnum < musb->config->num_eps;
 			epnum++, ep++) {
drivers/usb/musb/musb_core.h +1 -1
index 8222725..5040ceb 100644
@@ -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
#4 lore raw
In reply to a message not in the archive
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 that allocate_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.

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
index c939f81..a132d9f 100644

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.

Quoted 10 lines
drivers/usb/musb/musb_core.c +0 -0
 	for (epnum = 0, ep = musb->endpoints;
 			epnum < musb->config->num_eps;
 			epnum++, ep++) {
drivers/usb/musb/musb_core.h +0 -0
index 8222725..5040ceb 100644
@@ -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

#5 lore raw
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 that allocate_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.

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
index c939f81..a132d9f 100644

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.

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 -0
 	for (epnum = 0, ep = musb->endpoints;
 			epnum < musb->config->num_eps;
 			epnum++, ep++) {
drivers/usb/musb/musb_core.h +1 -1
index 8222725..5040ceb 100644
@@ -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.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 ;-)

Signature · 1 line
balbi
#7 lore raw
In reply to a message not in the archive
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 that allocate_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.

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
index c939f81..a132d9f 100644

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 155

Quoted 12 lines
drivers/usb/musb/musb_core.c +0 -0
 	for (epnum = 0, ep = musb->endpoints;
 			epnum < musb->config->num_eps;
 			epnum++, ep++) {
drivers/usb/musb/musb_core.h +1 -1
index 8222725..5040ceb 100644
@@ -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.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 [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#8 lore raw
Quoted 2 lines · Tony Lindgren

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

Precisely.

Signature · 1 line
balbi
#9 lore raw
In reply to a message not in the archive
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 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.

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