The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] usb: atm: ueagle-atm: fix use-after-free in uea_upload_pre_firmware
@ 2026-07-11 14:42 Yuhong Cheng
  2026-07-11 15:17 ` Stanislaw Gruszka
  0 siblings, 1 reply; 3+ messages in thread
From: Yuhong Cheng @ 2026-07-11 14:42 UTC (permalink / raw)
  To: castet.matthieu, stf_xl
  Cc: linux-usb, linux-kernel, Yuhong Cheng, syzbot+123456

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.

Reported-by: syzbot+123456@syzkaller.appspotmail.com
---
 drivers/usb/atm/ueagle-atm.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/atm/ueagle-atm.c b/drivers/usb/atm/ueagle-atm.c
index d610cdcef..eaf2f2d3a 100644
--- a/drivers/usb/atm/ueagle-atm.c
+++ b/drivers/usb/atm/ueagle-atm.c
@@ -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;
 }
-- 
2.46.0.windows.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH] usb: atm: ueagle-atm: fix use-after-free in uea_upload_pre_firmware
  2026-06-29 21:09 [syzbot] [usb?] KASAN: slab-use-after-free Read " syzbot
@ 2026-07-11 14:49 ` Yuhong Cheng
  0 siblings, 0 replies; 3+ messages in thread
From: Yuhong Cheng @ 2026-07-11 14:49 UTC (permalink / raw)
  To: castet.matthieu, stf_xl
  Cc: linux-usb, linux-kernel, Yuhong Cheng,
	syzbot+3d45d763d18796f97412

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.

Reported-by: syzbot+3d45d763d18796f97412@syzkaller.appspotmail.com
---
 drivers/usb/atm/ueagle-atm.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/atm/ueagle-atm.c b/drivers/usb/atm/ueagle-atm.c
index d610cdcef..eaf2f2d3a 100644
--- a/drivers/usb/atm/ueagle-atm.c
+++ b/drivers/usb/atm/ueagle-atm.c
@@ -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;
 }
-- 
2.46.0.windows.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] usb: atm: ueagle-atm: fix use-after-free in uea_upload_pre_firmware
  2026-07-11 14:42 [PATCH] usb: atm: ueagle-atm: fix use-after-free in uea_upload_pre_firmware Yuhong Cheng
@ 2026-07-11 15:17 ` Stanislaw Gruszka
  0 siblings, 0 replies; 3+ messages in thread
From: Stanislaw Gruszka @ 2026-07-11 15:17 UTC (permalink / raw)
  To: Yuhong Cheng; +Cc: castet.matthieu, linux-usb, linux-kernel, syzbot+123456

Hi,

On Sat, Jul 11, 2026 at 10:42:59PM +0800, Yuhong Cheng wrote:
> 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.

I think this not true, please see:
https://lore.kernel.org/linux-usb/20260702093707.GA6804@wp.pl/

Regards
Stanislaw

> 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.
> 
> Reported-by: syzbot+123456@syzkaller.appspotmail.com
> ---
>  drivers/usb/atm/ueagle-atm.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/usb/atm/ueagle-atm.c b/drivers/usb/atm/ueagle-atm.c
> index d610cdcef..eaf2f2d3a 100644
> --- a/drivers/usb/atm/ueagle-atm.c
> +++ b/drivers/usb/atm/ueagle-atm.c
> @@ -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;
>  }
> -- 
> 2.46.0.windows.1
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-07-11 15:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-11 14:42 [PATCH] usb: atm: ueagle-atm: fix use-after-free in uea_upload_pre_firmware Yuhong Cheng
2026-07-11 15:17 ` Stanislaw Gruszka
  -- strict thread matches above, loose matches on Subject: below --
2026-06-29 21:09 [syzbot] [usb?] KASAN: slab-use-after-free Read " syzbot
2026-07-11 14:49 ` [PATCH] usb: atm: ueagle-atm: fix use-after-free " Yuhong Cheng

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox