usb: atm: ueagle-atm: fix use-after-free in uea_upload_pre_firmware
Subsystems (3)
PATCH 1/1 usb: atm: ueagle-atm: fix use-after-free in uea_upload_pre_firmware
syzbot reported a slab-use-after-free read in uea_upload_pre_firmware. This is because the usb_device is passed as context to request_firmware_nowait but its reference count is not incremented. Thus, if the USB device is disconnected before the firmware load completes, the callback accesses a freed usb_device.
Fix this by taking a reference with usb_get_dev() before calling request_firmware_nowait() and releasing it with usb_put_dev() in the completion callback or if the request fails to start.
--- drivers/usb/atm/ueagle-atm.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/usb/atm/ueagle-atm.c +6 -2
@@ -663,6 +663,7 @@ static void uea_upload_pre_firmware(const struct firmware *fw_entry,uea_err (usb,"firmware is corrupted\n" ); err:release_firmware (fw_entry); +usb_put_dev (usb); }/*
@@ -693,13 +694,16 @@ static int uea_load_firmware(struct usb_device *usb, unsigned int ver)break ; } +usb_get_dev (usb); ret =request_firmware_nowait (THIS_MODULE ,1 , fw_name, &usb->dev,GFP_KERNEL , usb, uea_upload_pre_firmware); -if (ret) +if (ret) {uea_err (usb,"firmware %s is not available\n" , fw_name); -else +usb_put_dev (usb); + }else {uea_info (usb,"loading firmware %s\n" , fw_name); + }return ret; }
Signature · 1 line
2.46.0.windows.1
Stanislaw Gruszka
maintainerHi,
Quoted 1 line · Yuhong Cheng
syzbot reported a slab-use-after-free read in
uea_upload_pre_firmware. This is because theusb_deviceis passed as context torequest_firmware_nowaitbut its reference count is not incremented. Thus, if the USB device is disconnected before the firmware load completes, the callback accesses a freedusb_device.
I think this not true, please see:
https://lore.kernel.org/linux-usb/[email protected]/
Regards
Stanislaw
Quoted 41 lines
Fix this by taking a reference with
usb_get_dev()before callingrequest_firmware_nowait()and releasing it withusb_put_dev()in the completion callback or if the request fails to start.Reported-by [email protected]--- drivers/usb/atm/ueagle-atm.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)drivers/usb/atm/ueagle-atm.c +6
-2@@ -663,6 +663,7 @@ static void uea_upload_pre_firmware(const struct firmware *fw_entry,uea_err (usb,"firmware is corrupted\n" ); err:release_firmware (fw_entry); +usb_put_dev (usb); }/* @@ -693,13 +694,16 @@ static int uea_load_firmware(struct usb_device *usb, unsigned int ver)break ; } +usb_get_dev (usb); ret =request_firmware_nowait (THIS_MODULE ,1 , fw_name, &usb->dev,GFP_KERNEL , usb, uea_upload_pre_firmware); -if (ret) +if (ret) {uea_err (usb,"firmware %s is not available\n" , fw_name); -else +usb_put_dev (usb); + }else {uea_info (usb,"loading firmware %s\n" , fw_name); + }return ret; }Signature · 1 line
2.46.0.windows.1