fix: drivers/usb/serial: garmin_write_bulk: urb freed prematurely on success path
Subsystems (3)
PATCH 1/1 fix: drivers/usb/serial: garmin_write_bulk: urb freed prematurely on success path
In garmin_write_bulk(), usb_free_urb(urb) is called unconditionally after URB submission, even on the success path. When the URB completes later, the completion callback may perform additional operations on the already-freed URB structure, causing use-after-free or double free.
Move usb_free_urb(urb) to the error path only, allowing the completion callback to properly manage the URB lifecycle on success.
--- drivers/usb/serial/garmin_gps.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/usb/serial/garmin_gps.c +2 -4
@@ -1029,12 +1029,10 @@ static int garmin_write_bulk(struct usb_serial_port *port, count = status;usb_unanchor_urb (urb);kfree (buffer); +usb_free_urb (urb); +return count; } -/* we are done with this urb, so let the host driver -* really free it when it is finished with it */ -usb_free_urb (urb); -return count; }
Signature · 1 line
2.39.5 (Apple Git-154)
Johan Hovold
maintainerQuoted 7 lines · WenTao Liang
In
garmin_write_bulk(),usb_free_urb(urb)is called unconditionally after URB submission, even on the success path. When the URB completes later, the completion callback may perform additional operations on the already-freed URB structure, causing use-after-free or double free.Move
usb_free_urb(urb)to the error path only, allowing the completion callback to properly manage the URB lifecycle on success.
No, this patch is also broken. USB core holds a reference to the URB until the completion has been called.
Quoted 2 lines
Fixes c4ac4496e835 ("USB: serial: garmin_gps: fix memory leak on failed URB submit")
This commit has nothing to do with this.
Quoted 1 line
Signed-off-by WenTao Liang <[email protected]>
Johan