Skip to contentSkip to conversation

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

PATCH Superseded Balaji Selvanathan 2 participants 5 messages May 6 – May 7

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 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.

---
 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: ae8987f4e690f397f507c4b1efabd68b3ed08db6
change-id: 20260506-usb-8438fa6d437b

Best regards,

Signature · 1 line
Balaji Selvanathan <[email protected]>
#1 lore raw
Quoted 19 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.

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

Quoted 7 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);
  }
 
  /**

Does this need:

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

?

#2 lore raw
Quoted 29 lines · Marek Vasut
Quoted 19 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.

---
  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 · line 213

Quoted 7 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);
   }
     /**

Does this need:

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

?

Hi Marek,

We remove only "free(evt)"; "free(dwc->ev_buffs);" from this patch (884b10e86a05 "usb: dwc3: core: fix memory leaks in event buffer cleanup") is needed.

Regards

#3 lore raw
Quoted 31 lines · Balaji Selvanathan
Quoted 29 lines · Marek Vasut
Quoted 19 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.

---
  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 · line 213

Quoted 7 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);
   }
     /**

Does this need:

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

?

Hi Marek,

We remove only "free(evt)"; "free(dwc->ev_buffs);" from this patch (884b10e86a05 "usb: dwc3: core: fix memory leaks in event buffer cleanup") is needed.

The Fixes tag is only a reference for posterity, to trace which previous commit this change repairs. The change itself is fine. Thanks !

#4 lore raw
Quoted 32 lines · Marek Vasut
Quoted 31 lines · Balaji Selvanathan
Quoted 29 lines · Marek Vasut
Quoted 19 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.

---
  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 · line 213

Quoted 7 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);
   }
     /**

Does this need:

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

?

Hi Marek,

We remove only "free(evt)"; "free(dwc->ev_buffs);" from this patch (884b10e86a05 "usb: dwc3: core: fix memory leaks in event buffer cleanup") is needed.

The Fixes tag is only a reference for posterity, to trace which previous commit this change repairs. The change itself is fine. Thanks !

Hi Marek,

Got it. Thanks for the feedback. Have added fixes tag and respinned: https://lore.kernel.org/u-boot/[email protected]/

Regards,

Balaji