* [PATCH 0/2] usb: gadget: Correct cleanup ordering on failure and removal
@ 2026-11-18 14:08 Guangshuo Li
2026-11-18 14:10 ` [PATCH 1/2] usb: gadget: fsl_udc: Fix potential use-after-free during removal Guangshuo Li
2026-11-18 14:13 ` [PATCH 2/2] usb: gadget: nokia: Fix potential use-after-free on bind failure Guangshuo Li
0 siblings, 2 replies; 5+ messages in thread
From: Guangshuo Li @ 2026-11-18 14:08 UTC (permalink / raw)
To: Neill Kapron, Greg Kroah-Hartman; +Cc: linux-usb, linux-kernel, linuxppc-dev
Keep the FSL controller alive through removal and detach the Nokia
functions from their configuration before dropping their references.
Guangshuo Li (2):
usb: gadget: fsl_udc: Fix potential use-after-free during removal
usb: gadget: nokia: Fix potential use-after-free on bind failure
drivers/usb/gadget/legacy/nokia.c | 4 ++++
drivers/usb/gadget/udc/fsl_udc_core.c | 2 ++
2 files changed, 6 insertions(+)
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
--
2.43.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/2] usb: gadget: fsl_udc: Fix potential use-after-free during removal
2026-11-18 14:08 [PATCH 0/2] usb: gadget: Correct cleanup ordering on failure and removal Guangshuo Li
@ 2026-11-18 14:10 ` Guangshuo Li
2026-11-18 14:29 ` sashiko-bot
2026-11-18 14:13 ` [PATCH 2/2] usb: gadget: nokia: Fix potential use-after-free on bind failure Guangshuo Li
1 sibling, 1 reply; 5+ messages in thread
From: Guangshuo Li @ 2026-11-18 14:10 UTC (permalink / raw)
To: Neill Kapron, Greg Kroah-Hartman
Cc: linux-usb, linux-kernel, linuxppc-dev, stable
usb_del_gadget_udc() can drop the last gadget device reference and call
fsl_udc_release(), which frees udc_controller. The remaining remove path
then dereferences it to release its requests, endpoints and DMA pool.
Hold a gadget device reference until this cleanup has finished.
This issue was found by our static analysis tool under development.
Fixes: eab35c4e6d95 ("usb: gadget: fsl_udc_core: let udc-core manage gadget->dev")
Cc: stable@vger.kernel.org
Signed-off-by: Guangshuo Li <liguangshuo@mail.sdu.edu.cn>
---
drivers/usb/gadget/udc/fsl_udc_core.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/usb/gadget/udc/fsl_udc_core.c b/drivers/usb/gadget/udc/fsl_udc_core.c
index 878d70b55530..9d9d2164c5bf 100644
--- a/drivers/usb/gadget/udc/fsl_udc_core.c
+++ b/drivers/usb/gadget/udc/fsl_udc_core.c
@@ -2537,6 +2537,7 @@ static void fsl_udc_remove(struct platform_device *pdev)
DECLARE_COMPLETION_ONSTACK(done);
udc_controller->done = &done;
+ get_device(&udc_controller->gadget.dev);
usb_del_gadget_udc(&udc_controller->gadget);
/* DR has been stopped in usb_gadget_unregister_driver() */
@@ -2554,6 +2555,7 @@ static void fsl_udc_remove(struct platform_device *pdev)
release_mem_region(res->start, resource_size(res));
/* free udc --wait for the release() finished */
+ put_device(&udc_controller->gadget.dev);
wait_for_completion(&done);
/*
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/2] usb: gadget: nokia: Fix potential use-after-free on bind failure
2026-11-18 14:08 [PATCH 0/2] usb: gadget: Correct cleanup ordering on failure and removal Guangshuo Li
2026-11-18 14:10 ` [PATCH 1/2] usb: gadget: fsl_udc: Fix potential use-after-free during removal Guangshuo Li
@ 2026-11-18 14:13 ` Guangshuo Li
2026-11-18 14:28 ` sashiko-bot
1 sibling, 1 reply; 5+ messages in thread
From: Guangshuo Li @ 2026-11-18 14:13 UTC (permalink / raw)
To: Neill Kapron, Greg Kroah-Hartman; +Cc: linux-usb, linux-kernel, linuxppc-dev
If the second configuration fails to bind, nokia_bind() frees the
functions in the first configuration while they remain on its function
list. Composite cleanup then accesses the freed functions.
Remove those functions before putting them, and also put the mass-storage
function acquired for the first configuration.
This issue was found by our static analysis tool under development.
Fixes: 15761826eecd ("usb: gadget: nokia: use function framework for ACM")
Signed-off-by: Guangshuo Li <liguangshuo@mail.sdu.edu.cn>
---
drivers/usb/gadget/legacy/nokia.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/usb/gadget/legacy/nokia.c b/drivers/usb/gadget/legacy/nokia.c
index 396605a84cd1..87d496e9b2eb 100644
--- a/drivers/usb/gadget/legacy/nokia.c
+++ b/drivers/usb/gadget/legacy/nokia.c
@@ -267,6 +267,7 @@ static int nokia_bind_config(struct usb_configuration *c)
static int nokia_bind(struct usb_composite_dev *cdev)
{
struct usb_gadget *gadget = cdev->gadget;
+ struct usb_function *f, *tmp;
struct fsg_opts *fsg_opts;
struct fsg_config fsg_config;
int status;
@@ -357,6 +358,9 @@ static int nokia_bind(struct usb_composite_dev *cdev)
return 0;
err_put_cfg1:
+ list_for_each_entry_safe(f, tmp, &nokia_config_500ma_driver.functions, list)
+ usb_remove_function(&nokia_config_500ma_driver, f);
+ usb_put_function(f_msg_cfg1);
usb_put_function(f_acm_cfg1);
if (!IS_ERR_OR_NULL(f_obex1_cfg1))
usb_put_function(f_obex1_cfg1);
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 2/2] usb: gadget: nokia: Fix potential use-after-free on bind failure
2026-11-18 14:13 ` [PATCH 2/2] usb: gadget: nokia: Fix potential use-after-free on bind failure Guangshuo Li
@ 2026-11-18 14:28 ` sashiko-bot
0 siblings, 0 replies; 5+ messages in thread
From: sashiko-bot @ 2026-11-18 14:28 UTC (permalink / raw)
To: Guangshuo Li; +Cc: linux-usb
> If the second configuration fails to bind, nokia_bind() frees the
> functions in the first configuration while they remain on its function
> list. Composite cleanup then accesses the freed functions.
>
> Remove those functions before putting them, and also put the mass-storage
> function acquired for the first configuration.
>
> This issue was found by our static analysis tool under development.
>
> Fixes: 15761826eecd ("usb: gadget: nokia: use function framework for ACM")
> Signed-off-by: Guangshuo Li <liguangshuo@mail.sdu.edu.cn>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261118-324f82bd41-usb-gadget-0@mail.sdu.edu.cn?part=2
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] usb: gadget: fsl_udc: Fix potential use-after-free during removal
2026-11-18 14:10 ` [PATCH 1/2] usb: gadget: fsl_udc: Fix potential use-after-free during removal Guangshuo Li
@ 2026-11-18 14:29 ` sashiko-bot
0 siblings, 0 replies; 5+ messages in thread
From: sashiko-bot @ 2026-11-18 14:29 UTC (permalink / raw)
To: Guangshuo Li; +Cc: linux-usb
> usb_del_gadget_udc() can drop the last gadget device reference and call
> fsl_udc_release(), which frees udc_controller. The remaining remove path
> then dereferences it to release its requests, endpoints and DMA pool.
>
> Hold a gadget device reference until this cleanup has finished.
>
> This issue was found by our static analysis tool under development.
>
> Fixes: eab35c4e6d95 ("usb: gadget: fsl_udc_core: let udc-core manage gadget->dev")
> Cc: stable@vger.kernel.org
> Signed-off-by: Guangshuo Li <liguangshuo@mail.sdu.edu.cn>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261118-324f82bd41-usb-gadget-0@mail.sdu.edu.cn?part=1
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-11-18 14:29 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-18 14:08 [PATCH 0/2] usb: gadget: Correct cleanup ordering on failure and removal Guangshuo Li
2026-11-18 14:10 ` [PATCH 1/2] usb: gadget: fsl_udc: Fix potential use-after-free during removal Guangshuo Li
2026-11-18 14:29 ` sashiko-bot
2026-11-18 14:13 ` [PATCH 2/2] usb: gadget: nokia: Fix potential use-after-free on bind failure Guangshuo Li
2026-11-18 14:28 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox