Skip to contentSkip to conversation

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

PATCH In review Balaji Selvanathan 4 participants 5 messages May 7 – May 11

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

PATCH v3 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 v3:
- Move Fixes tag to commit footer in commit description
- Link to v2: https://lore.kernel.org/u-boot/[email protected]/

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-b0dfbffe0946

Best regards,

Signature · 1 line
Balaji Selvanathan <[email protected]>
Reviewed-by on v3 1/1
#1 lore raw
Quoted 11 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.

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

Did Mattijs RB got dropped ?

#2 lore raw
Quoted 10 lines · Marek Vasut
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 5 lines
Quoted 2 lines
Fixes 884b10e86a05 ("usb: dwc3: core: fix memory leaks in event buffer cleanup")

Did Mattijs RB got dropped ?

Hi,

Thought Mattijs will give reviewed-by after placing "Fixes:" tag in commit footer.

Thanks

#3 lore raw
Quoted 14 lines · Balaji Selvanathan
Quoted 13 lines · Marek Vasut
Quoted 12 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.

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

buffer cleanup")

Quoted 8 lines
Quoted 3 lines

Did Mattijs RB got dropped ?

Hi,

Thought Mattijs will give reviewed-by after placing "Fixes:" tag in commit footer.

Usually, when comments are only nitpicks, it's okay to keep the Reviewed-by tag.

Putting it back here:

Quoted 2 lines

Thanks

Tested-by on v3 1/1
#4 lore raw
In reply to Balaji Selvanathan
Quoted 29 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.

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

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

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 -0
index 0dee14c8b59..be198041f08 100644

drivers/usb/dwc3/core.c static void dwc3_free_one_event_buffer(struct dwc3 *dwc, · line 211

Quoted 4 lines
drivers/usb/dwc3/core.c +0 -1
@@ -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);

Thanks for the fix Balaji! This fixed a crash I've been seeing on Rockchip RK3576 trying to use the UMS gadget, so

Best regards,
Alexey