[PATCH 2/2] usb: gadget: nokia: Fix potential use-after-free on bind failure

From: Guangshuo Li

Date: Wed Nov 18 2026 - 09:14:24 EST


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@xxxxxxxxxxxxxxx>
---
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