Skip to contentSkip to conversation

usb: dwc3: Fix crash on fastboot exit due to incorrect memory free

PATCH Superseded Balaji Selvanathan 3 participants 5 messages May 7

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 usb: dwc3: Fix crash on fastboot exit due to incorrect memory free

The dwc3_free_one_event_buffer() function incorrectly called free() on event buffer structures allocated with devm_kzalloc(). This caused heap corruption and a synchronous abort when exiting fastboot mode via "fastboot continue".

Device-managed memory is automatically freed when the device is removed, so manual deallocation causes the heap allocator to access corrupted metadata.

Fixes 884b10e86a05 ("usb: dwc3: core: fix memory leaks in event buffer cleanup")

---
Changes in v2:
- Added Fixes tag in commit description
- Link to v1: https://lore.kernel.org/u-boot/[email protected]/

---
 drivers/usb/dwc3/core.c | 1 -
 1 file changed, 1 deletion(-)
drivers/usb/dwc3/core.c +0 -1
index 0dee14c8b59..be198041f08 100644
@@ -208,7 +208,6 @@ static void dwc3_free_one_event_buffer(struct dwc3 *dwc,
 		struct dwc3_event_buffer *evt)
 {
 	dma_free_coherent(evt->buf);
-	free(evt);
 }
 
 /**

---
base-commit: 3cdd19089f1b1b7cd08530f33ff4708abcfd426c
change-id: 20260507-usb-34b404ff063a

Best regards,

Signature · 1 line
Balaji Selvanathan <[email protected]>
Reviewed-by on v2 1/1
#1 lore raw

Hi Balaji,

Thank you for the patch.

Quoted 5 lines · Balaji Selvanathan

The dwc3_free_one_event_buffer() function incorrectly called free() on event buffer structures allocated with devm_kzalloc(). This caused heap corruption and a synchronous abort when exiting fastboot mode via "fastboot continue".

Quoted 7 lines

Device-managed memory is automatically freed when the device is removed, so manual deallocation causes the heap allocator to access corrupted metadata.

Fixes 884b10e86a05 ("usb: dwc3: core: fix memory leaks in event buffer cleanup")

Marek, I'm assuming you will pick this up.
If you want me to take it instead, let me know.

Quoted 28 lines

---
Changes in v2:
- Added Fixes tag in commit description
- Link to v1: https://lore.kernel.org/u-boot/[email protected]/

---
 drivers/usb/dwc3/core.c | 1 -
 1 file changed, 1 deletion(-)
drivers/usb/dwc3/core.c +0 -2
index 0dee14c8b59..be198041f08 100644
@@ -208,7 +208,6 @@ static void dwc3_free_one_event_buffer(struct dwc3 *dwc,
 		struct dwc3_event_buffer *evt)
 {
 	dma_free_coherent(evt->buf);
-	free(evt);
 }
 
 /**
 
---

base-commit: 3cdd19089f1b1b7cd08530f33ff4708abcfd426c
change-id: 20260507-usb-34b404ff063a

Best regards,

Signature · 1 line
Balaji Selvanathan <[email protected]>
#2 lore raw
Quoted 15 lines · Mattijs Korpershoek

Hi Balaji,

Thank you for the patch.

Quoted 9 lines · Balaji Selvanathan

The dwc3_free_one_event_buffer() function incorrectly called free() on event buffer structures allocated with devm_kzalloc(). This caused heap corruption and a synchronous abort when exiting fastboot mode via "fastboot continue".

Device-managed memory is automatically freed when the device is removed, so manual deallocation causes the heap allocator to access corrupted metadata.

Quoted 8 lines
Quoted 3 lines
Fixes 884b10e86a05 ("usb: dwc3: core: fix memory leaks in event buffer cleanup")

Marek, I'm assuming you will pick this up.
If you want me to take it instead, let me know.

I'll pick up V3 once the nitpick is addressed.

#3 lore raw
In reply to Balaji Selvanathan
Quoted 5 lines · Balaji Selvanathan

The dwc3_free_one_event_buffer() function incorrectly called free() on event buffer structures allocated with devm_kzalloc(). This caused heap corruption and a synchronous abort when exiting fastboot mode via "fastboot continue".

Quoted 7 lines

Device-managed memory is automatically freed when the device is removed, so manual deallocation causes the heap allocator to access corrupted metadata.

Fixes 884b10e86a05 ("usb: dwc3: core: fix memory leaks in event buffer cleanup")

Ah, and I missed a nitpick. Fixes should be part of the commit footer. Same block as in the Signed-off-by:

See: https://docs.kernel.org/process/submitting-patches.html#using-reported-by-tested-by-reviewed-by-suggested-by-and-fixes

Quoted 28 lines

---
Changes in v2:
- Added Fixes tag in commit description
- Link to v1: https://lore.kernel.org/u-boot/[email protected]/

---
 drivers/usb/dwc3/core.c | 1 -
 1 file changed, 1 deletion(-)
drivers/usb/dwc3/core.c +0 -2
index 0dee14c8b59..be198041f08 100644
@@ -208,7 +208,6 @@ static void dwc3_free_one_event_buffer(struct dwc3 *dwc,
 		struct dwc3_event_buffer *evt)
 {
 	dma_free_coherent(evt->buf);
-	free(evt);
 }
 
 /**
 
---

base-commit: 3cdd19089f1b1b7cd08530f33ff4708abcfd426c
change-id: 20260507-usb-34b404ff063a

Best regards,

Signature · 1 line
Balaji Selvanathan <[email protected]>
#4 lore raw
Quoted 11 lines · Mattijs Korpershoek
Quoted 9 lines · Balaji Selvanathan

The dwc3_free_one_event_buffer() function incorrectly called free() on event buffer structures allocated with devm_kzalloc(). This caused heap corruption and a synchronous abort when exiting fastboot mode via "fastboot continue".

Device-managed memory is automatically freed when the device is removed, so manual deallocation causes the heap allocator to access corrupted metadata.

Quoted 7 lines
Quoted 3 lines
Fixes 884b10e86a05 ("usb: dwc3: core: fix memory leaks in event buffer cleanup")

Ah, and I missed a nitpick. Fixes should be part of the commit footer. Same block as in the Signed-off-by:

See: https://docs.kernel.org/process/submitting-patches.html#using-reported-by-tested-by-reviewed-by-suggested-by-and-fixes

Hi,

Thanks for the feedback; Pls find respin here: https://lore.kernel.org/u-boot/[email protected]/

Regards,

Balaji

Quoted 28 lines
Quoted 28 lines

---
Changes in v2:
- Added Fixes tag in commit description
- Link to v1: https://lore.kernel.org/u-boot/[email protected]/

---
  drivers/usb/dwc3/core.c | 1 -
  1 file changed, 1 deletion(-)
drivers/usb/dwc3/core.c +0 -2
index 0dee14c8b59..be198041f08 100644
@@ -208,7 +208,6 @@ static void dwc3_free_one_event_buffer(struct dwc3 *dwc,
  		struct dwc3_event_buffer *evt)
  {
  	dma_free_coherent(evt->buf);
-	free(evt);
  }
 
  /**
 
---

base-commit: 3cdd19089f1b1b7cd08530f33ff4708abcfd426c
change-id: 20260507-usb-34b404ff063a

Best regards,

Signature · 1 line
Balaji Selvanathan <[email protected]>