mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: syzbot <syzbot+a4f65284f1451010b0a8@syzkaller.appspotmail.com>
To: linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com
Subject: Forwarded: [PATCH] usb: gadget: f_uac2: fix invalid free in UAC2_RATE_ATTRIBUTE store
Date: Wed, 29 Jul 2026 02:25:21 -0700	[thread overview]
Message-ID: <6a69c701.d9e86bb5.297b12.005a.GAE@google.com> (raw)
In-Reply-To: <6a698f41.d9e86bb5.297b12.0051.GAE@google.com>

For archival purposes, forwarding an incoming command email to
linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com.

***

Subject: [PATCH] usb: gadget: f_uac2: fix invalid free in UAC2_RATE_ATTRIBUTE store
Author: kartikey406@gmail.com

#syz test: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master


The store callback generated by UAC2_RATE_ATTRIBUTE() parses a
comma-separated list of sample rates by repeatedly calling strsep()
on split_page, which was obtained via kstrdup(). strsep() advances
the pointer it is given to point past each consumed token, so by
the time the loop reaches the end label - either after a normal
full parse or after an early exit via "goto end" when kstrtou32()
fails on a malformed token - split_page no longer points at the
start of the buffer returned by kstrdup(). kfree() is then called
on this interior pointer, which is not a valid allocation start
address, resulting in a KASAN invalid-free.

Fix this by keeping a separate pointer, orig_page, that is set
once from the kstrdup() return value and is never modified by
strsep(). orig_page is initialized to NULL so that early exits
before kstrdup() is reached (e.g. the opts->refcnt busy check)
result in a harmless kfree(NULL) instead of freeing an
uninitialized stack value. kfree() is called on orig_page instead
of split_page at the end label.

Since both f_uac2_opts_p_srate_store() and f_uac2_opts_c_srate_store()
are generated from this same macro, this fixes both attributes.

Reported-by: syzbot+a4f65284f1451010b0a8@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=a4f65284f1451010b0a8
Signed-off-by: Deepanshu Kartikey <kartikey406@gmail.com>
---
 drivers/usb/gadget/function/f_uac2.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/gadget/function/f_uac2.c b/drivers/usb/gadget/function/f_uac2.c
index 897787d0803c..4b403cb779fd 100644
--- a/drivers/usb/gadget/function/f_uac2.c
+++ b/drivers/usb/gadget/function/f_uac2.c
@@ -2012,7 +2012,7 @@ static ssize_t f_uac2_opts_##name##_store(struct config_item *item,	\
 					  const char *page, size_t len)	\
 {									\
 	struct f_uac2_opts *opts = to_f_uac2_opts(item);		\
-	char *split_page = NULL;					\
+	char *split_page = NULL, *orig_page = NULL;					\
 	int ret = -EINVAL;						\
 	char *token;							\
 	u32 num;							\
@@ -2026,7 +2026,7 @@ static ssize_t f_uac2_opts_##name##_store(struct config_item *item,	\
 									\
 	i = 0;								\
 	memset(opts->name##s, 0x00, sizeof(opts->name##s));		\
-	split_page = kstrdup(page, GFP_KERNEL);				\
+	orig_page = split_page = kstrdup(page, GFP_KERNEL);				\
 	while ((token = strsep(&split_page, ",")) != NULL) {		\
 		ret = kstrtou32(token, 0, &num);			\
 		if (ret)						\
@@ -2037,7 +2037,7 @@ static ssize_t f_uac2_opts_##name##_store(struct config_item *item,	\
 	};								\
 									\
 end:									\
-	kfree(split_page);						\
+	kfree(orig_page);						\
 	mutex_unlock(&opts->lock);					\
 	return ret;							\
 }									\
-- 
2.43.0


      reply	other threads:[~2026-07-29  9:25 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-29  5:27 [syzbot] [usb?] KASAN: invalid-free in f_uac2_opts_c_srate_store syzbot
2026-07-29  9:25 ` syzbot [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=6a69c701.d9e86bb5.297b12.005a.GAE@google.com \
    --to=syzbot+a4f65284f1451010b0a8@syzkaller.appspotmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=syzkaller-bugs@googlegroups.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®