Skip to contentSkip to conversation

usb: eth: fix memalign() parameter order

PATCH New Stephen Warren 4 participants 7 messages Feb 12, 2016 – Feb 24, 2016 USB

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 usb: eth: fix memalign() parameter order

From: Stephen Warren <[email protected]>

The alignment and size were swapped, leading to malloc heap corruption.

On my system, this sometimes caused U-Boot to crash during or after certain USB Ethernet operations.

Fixes c8c2797c3810 ("dm: usb: eth: Support driver model with USB Ethernet")
---
 drivers/usb/eth/usb_ether.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/eth/usb_ether.c +1 -1
index b9c9a8402e39..36734e2e51b3 100644
@@ -73,7 +73,7 @@ int usb_ether_register(struct udevice *dev, struct ueth_data *ueth, int rxsize)
 	}
 
 	ueth->rxsize = rxsize;
-	ueth->rxbuf = memalign(rxsize, ARCH_DMA_MINALIGN);
+	ueth->rxbuf = memalign(ARCH_DMA_MINALIGN, rxsize);
 	if (!ueth->rxbuf)
 		return -ENOMEM;
 
Signature · 1 line
2.7.0
#1 lore raw

PATCH 1/1 usb: eth: fix memalign() parameter order

Quoted 9 lines · Stephen Warren

From: Stephen Warren <[email protected]>

The alignment and size were swapped, leading to malloc heap corruption.

On my system, this sometimes caused U-Boot to crash during or after certain USB Ethernet operations.

Fixes c8c2797c3810 ("dm: usb: eth: Support driver model with USB Ethernet")

Oh this is a nice catch!

Quoted 18 lines
---
 drivers/usb/eth/usb_ether.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/eth/usb_ether.c +1 -1
index b9c9a8402e39..36734e2e51b3 100644
@@ -73,7 +73,7 @@ int usb_ether_register(struct udevice *dev, struct ueth_data *ueth, int rxsize)
 	}
 
 	ueth->rxsize = rxsize;
-	ueth->rxbuf = memalign(rxsize, ARCH_DMA_MINALIGN);
+	ueth->rxbuf = memalign(ARCH_DMA_MINALIGN, rxsize);
 	if (!ueth->rxbuf)
 		return -ENOMEM;
 
#2 lore raw

PATCH 1/1 usb: eth: fix memalign() parameter order

Quoted 26 lines · Marek Vasut
Quoted 9 lines · Stephen Warren

From: Stephen Warren <[email protected]>

The alignment and size were swapped, leading to malloc heap corruption.

On my system, this sometimes caused U-Boot to crash during or after certain USB Ethernet operations.

Fixes c8c2797c3810 ("dm: usb: eth: Support driver model with USB Ethernet")

Oh this is a nice catch!

Quoted 11 lines
---
 drivers/usb/eth/usb_ether.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/eth/usb_ether.c +0 -0
index b9c9a8402e39..36734e2e51b3 100644
@@ -73,7 +73,7 @@ int usb_ether_register(struct udevice *dev, struct ueth_data *ueth, int rxsize)
      }
 
Quoted 8 lines

drivers/usb/eth/usb_ether.c int usb_ether_register(struct udevice *dev, struct ueth_data *ueth, int rxsize) · line 79

Quoted 7 lines
drivers/usb/eth/usb_ether.c +1 -1
      ueth->rxsize = rxsize;
-     ueth->rxbuf = memalign(rxsize, ARCH_DMA_MINALIGN);
+     ueth->rxbuf = memalign(ARCH_DMA_MINALIGN, rxsize);
      if (!ueth->rxbuf)
              return -ENOMEM;
 

Oh dear. For some reason I thought that was fixed. But I see from this thread that it did not fix the problem at the time and I didn't send a patch either:

http://lists.denx.de/pipermail/u-boot/2015-August/222440.html

Thanks Stephen for finding this and actually fixing it :-)

- Simon

#3 lore raw

PATCH 1/1 usb: eth: fix memalign() parameter order

In reply to Stephen Warren
Quoted 9 lines · Stephen Warren

From: Stephen Warren <[email protected]>

The alignment and size were swapped, leading to malloc heap corruption.

On my system, this sometimes caused U-Boot to crash during or after certain USB Ethernet operations.

Fixes c8c2797c3810 ("dm: usb: eth: Support driver model with USB Ethernet")

Yikes.

#4 lore raw

PATCH 1/1 usb: eth: fix memalign() parameter order

Quoted 8 lines · Joe Hershberger
Quoted 7 lines · Stephen Warren

From: Stephen Warren <[email protected]>

The alignment and size were swapped, leading to malloc heap corruption.

On my system, this sometimes caused U-Boot to crash during or after certain USB Ethernet operations.

Quoted 7 lines
Quoted 2 lines
Fixes c8c2797c3810 ("dm: usb: eth: Support driver model with USB Ethernet")

Yikes.

Applied to u-boot-usb/master, thanks.

#5 lore raw

PATCH 1/1 usb: eth: fix memalign() parameter order

Quoted 9 lines · Marek Vasut
Quoted 8 lines · Joe Hershberger
Quoted 7 lines · Stephen Warren

From: Stephen Warren <[email protected]>

The alignment and size were swapped, leading to malloc heap corruption.

On my system, this sometimes caused U-Boot to crash during or after certain USB Ethernet operations.

Quoted 8 lines
Quoted 7 lines
Quoted 2 lines
Fixes c8c2797c3810 ("dm: usb: eth: Support driver model with USB Ethernet")

Yikes.

Applied to u-boot-usb/master, thanks.

Thanks. Any chance of a pull request into mainline? This issue is causing lots of crashing on one of the systems in my test setup, which potentially masks other problems.

#6 lore raw

PATCH 1/1 usb: eth: fix memalign() parameter order

Quoted 17 lines · Stephen Warren
Quoted 16 lines · Marek Vasut
Quoted 15 lines · Joe Hershberger
Quoted 10 lines · Stephen Warren

From: Stephen Warren <[email protected]>

The alignment and size were swapped, leading to malloc heap corruption.

On my system, this sometimes caused U-Boot to crash during or after certain USB Ethernet operations.

Fixes c8c2797c3810 ("dm: usb: eth: Support driver model with USB

Ethernet")

Yikes.

Quoted 7 lines
Quoted 3 lines
Quoted 2 lines

Applied to u-boot-usb/master, thanks.

Thanks. Any chance of a pull request into mainline? This issue is causing lots of crashing on one of the systems in my test setup, which potentially masks other problems.

Done, sorry for the delay.