mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Guangshuo Li <liguangshuo@mail.sdu.edu.cn>
To: Neill Kapron <nkapron@google.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
	linuxppc-dev@lists.ozlabs.org
Subject: [PATCH 2/2] usb: gadget: nokia: Fix potential use-after-free on bind failure
Date: Wed, 18 Nov 2026 22:13:47 +0800	[thread overview]
Message-ID: <20261118-324f82bd41-usb-gadget-2@mail.sdu.edu.cn> (raw)
In-Reply-To: <20261118-324f82bd41-usb-gadget-0@mail.sdu.edu.cn>

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


      parent reply	other threads:[~2026-11-18 14:13 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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-20 12:10   ` Greg Kroah-Hartman
2026-11-18 14:13 ` Guangshuo Li [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261118-324f82bd41-usb-gadget-2@mail.sdu.edu.cn \
    --to=liguangshuo@mail.sdu.edu.cn \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=nkapron@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®