mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/2] usb: gadget: f_uac1/f_uac2: fix invalid-free in srate configfs store
@ 2026-08-04 17:43 Anuj Bolewar via B4 Relay
  2026-08-04 17:43 ` [PATCH 1/2] usb: gadget: f_uac2: " Anuj Bolewar via B4 Relay
  2026-08-04 17:43 ` [PATCH 2/2] usb: gadget: f_uac1: " Anuj Bolewar via B4 Relay
  0 siblings, 2 replies; 4+ messages in thread
From: Anuj Bolewar via B4 Relay @ 2026-08-04 17:43 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: linux-usb, linux-kernel, Anuj Bolewar,
	syzbot+38bab69d2760cc99cfbe, syzbot+a4f65284f1451010b0a8,
	syzbot+2532c7901f590afd0c3a

The p_srate/c_srate configfs store helpers in f_uac1 and f_uac2 free
the strsep()-advanced split_page pointer instead of the buffer returned
by kstrdup(). When a non-numeric token appears in the first position,
kstrtou32() fails and kfree() releases a pointer into the middle of the
slab object, which KASAN reports as invalid-free.

Keep the original kstrdup() pointer and free that instead. This fixes
the syzbot reports for f_uac2_opts_p_srate_store,
f_uac2_opts_c_srate_store and f_uac1_opts_c_srate_store.

Signed-off-by: Anuj Bolewar <bolewara@gmail.com>
---
Anuj Bolewar (2):
      usb: gadget: f_uac2: fix invalid-free in srate configfs store
      usb: gadget: f_uac1: fix invalid-free in srate configfs store

 drivers/usb/gadget/function/f_uac1.c | 5 +++--
 drivers/usb/gadget/function/f_uac2.c | 5 +++--
 2 files changed, 6 insertions(+), 4 deletions(-)
---
base-commit: 2d2338c93da79b3bfe4b6099a931d9468d539952
change-id: 20260804-f-uac-srate-invalid-free-827cf8840137

Best regards,
--  
Anuj Bolewar <bolewara@gmail.com>



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

* [PATCH 1/2] usb: gadget: f_uac2: fix invalid-free in srate configfs store
  2026-08-04 17:43 [PATCH 0/2] usb: gadget: f_uac1/f_uac2: fix invalid-free in srate configfs store Anuj Bolewar via B4 Relay
@ 2026-08-04 17:43 ` Anuj Bolewar via B4 Relay
  2026-11-20  9:51   ` Greg Kroah-Hartman
  2026-08-04 17:43 ` [PATCH 2/2] usb: gadget: f_uac1: " Anuj Bolewar via B4 Relay
  1 sibling, 1 reply; 4+ messages in thread
From: Anuj Bolewar via B4 Relay @ 2026-08-04 17:43 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: linux-usb, linux-kernel, Anuj Bolewar,
	syzbot+38bab69d2760cc99cfbe, syzbot+a4f65284f1451010b0a8

From: Anuj Bolewar <bolewara@gmail.com>

The store path for the p_srate/c_srate attributes calls kfree() on
split_page after it has been advanced by strsep(). When the first
token fails to parse, strsep() leaves split_page pointing into the
middle of the kstrdup()'d buffer and the subsequent kfree() triggers
a KASAN invalid-free.

Keep the original pointer returned by kstrdup() and free that
instead.

Reported-by: syzbot+38bab69d2760cc99cfbe@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=38bab69d2760cc99cfbe
Reported-by: syzbot+a4f65284f1451010b0a8@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=a4f65284f1451010b0a8
Fixes: a7339e4f5788 ("usb: gadget: f_uac2: Support multiple sampling rates")
Assisted-by: deepseek:v4-pro
Signed-off-by: Anuj Bolewar <bolewara@gmail.com>
---
 drivers/usb/gadget/function/f_uac2.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/gadget/function/f_uac2.c b/drivers/usb/gadget/function/f_uac2.c
index 897787d0803..1ea1bedef9a 100644
--- a/drivers/usb/gadget/function/f_uac2.c
+++ b/drivers/usb/gadget/function/f_uac2.c
@@ -2013,6 +2013,7 @@ static ssize_t f_uac2_opts_##name##_store(struct config_item *item,	\
 {									\
 	struct f_uac2_opts *opts = to_f_uac2_opts(item);		\
 	char *split_page = NULL;					\
+	char *split_page_orig = NULL;					\
 	int ret = -EINVAL;						\
 	char *token;							\
 	u32 num;							\
@@ -2026,7 +2027,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);				\
+	split_page_orig = split_page = kstrdup(page, GFP_KERNEL);      \
 	while ((token = strsep(&split_page, ",")) != NULL) {		\
 		ret = kstrtou32(token, 0, &num);			\
 		if (ret)						\
@@ -2037,7 +2038,7 @@ static ssize_t f_uac2_opts_##name##_store(struct config_item *item,	\
 	};								\
 									\
 end:									\
-	kfree(split_page);						\
+	kfree(split_page_orig);						\
 	mutex_unlock(&opts->lock);					\
 	return ret;							\
 }									\

-- 
2.53.0



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

* [PATCH 2/2] usb: gadget: f_uac1: fix invalid-free in srate configfs store
  2026-08-04 17:43 [PATCH 0/2] usb: gadget: f_uac1/f_uac2: fix invalid-free in srate configfs store Anuj Bolewar via B4 Relay
  2026-08-04 17:43 ` [PATCH 1/2] usb: gadget: f_uac2: " Anuj Bolewar via B4 Relay
@ 2026-08-04 17:43 ` Anuj Bolewar via B4 Relay
  1 sibling, 0 replies; 4+ messages in thread
From: Anuj Bolewar via B4 Relay @ 2026-08-04 17:43 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: linux-usb, linux-kernel, Anuj Bolewar, syzbot+2532c7901f590afd0c3a

From: Anuj Bolewar <bolewara@gmail.com>

Same bug as f_uac2: the store path for the p_srate/c_srate
attributes frees split_page after strsep() has advanced it into the
middle of the kstrdup()'d buffer. A non-numeric first token makes
kstrtou32() fail and kfree() is called on a pointer into the slab
object, triggering a KASAN invalid-free.

Keep the original pointer returned by kstrdup() and free that
instead.

Reported-by: syzbot+2532c7901f590afd0c3a@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=2532c7901f590afd0c3a
Fixes: 695d39ffc2b5 ("usb: gadget: f_uac1: Support multiple sampling rates")
Assisted-by: deepseek:v4-pro
Signed-off-by: Anuj Bolewar <bolewara@gmail.com>
---
 drivers/usb/gadget/function/f_uac1.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/gadget/function/f_uac1.c b/drivers/usb/gadget/function/f_uac1.c
index 85c502e98f5..94c716d72c6 100644
--- a/drivers/usb/gadget/function/f_uac1.c
+++ b/drivers/usb/gadget/function/f_uac1.c
@@ -1595,6 +1595,7 @@ static ssize_t f_uac1_opts_##name##_store(struct config_item *item,	\
 {									\
 	struct f_uac1_opts *opts = to_f_uac1_opts(item);		\
 	char *split_page = NULL;					\
+	char *split_page_orig = NULL;					\
 	int ret = -EINVAL;						\
 	char *token;							\
 	u32 num;							\
@@ -1608,7 +1609,7 @@ static ssize_t f_uac1_opts_##name##_store(struct config_item *item,	\
 									\
 	i = 0;								\
 	memset(opts->name##s, 0x00, sizeof(opts->name##s));		\
-	split_page = kstrdup(page, GFP_KERNEL);				\
+	split_page_orig = split_page = kstrdup(page, GFP_KERNEL);      \
 	while ((token = strsep(&split_page, ",")) != NULL) {		\
 		ret = kstrtou32(token, 0, &num);			\
 		if (ret)						\
@@ -1619,7 +1620,7 @@ static ssize_t f_uac1_opts_##name##_store(struct config_item *item,	\
 	};								\
 									\
 end:									\
-	kfree(split_page);						\
+	kfree(split_page_orig);						\
 	mutex_unlock(&opts->lock);					\
 	return ret;							\
 }									\

-- 
2.53.0



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

* Re: [PATCH 1/2] usb: gadget: f_uac2: fix invalid-free in srate configfs store
  2026-08-04 17:43 ` [PATCH 1/2] usb: gadget: f_uac2: " Anuj Bolewar via B4 Relay
@ 2026-11-20  9:51   ` Greg Kroah-Hartman
  0 siblings, 0 replies; 4+ messages in thread
From: Greg Kroah-Hartman @ 2026-11-20  9:51 UTC (permalink / raw)
  To: bolewara
  Cc: linux-usb, linux-kernel, syzbot+38bab69d2760cc99cfbe,
	syzbot+a4f65284f1451010b0a8

On Tue, Aug 04, 2026 at 11:13:23PM +0530, Anuj Bolewar via B4 Relay wrote:
> From: Anuj Bolewar <bolewara@gmail.com>
> 
> The store path for the p_srate/c_srate attributes calls kfree() on
> split_page after it has been advanced by strsep(). When the first
> token fails to parse, strsep() leaves split_page pointing into the
> middle of the kstrdup()'d buffer and the subsequent kfree() triggers
> a KASAN invalid-free.
> 
> Keep the original pointer returned by kstrdup() and free that
> instead.
> 
> Reported-by: syzbot+38bab69d2760cc99cfbe@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=38bab69d2760cc99cfbe
> Reported-by: syzbot+a4f65284f1451010b0a8@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=a4f65284f1451010b0a8
> Fixes: a7339e4f5788 ("usb: gadget: f_uac2: Support multiple sampling rates")
> Assisted-by: deepseek:v4-pro
> Signed-off-by: Anuj Bolewar <bolewara@gmail.com>
> ---
>  drivers/usb/gadget/function/f_uac2.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/usb/gadget/function/f_uac2.c b/drivers/usb/gadget/function/f_uac2.c
> index 897787d0803..1ea1bedef9a 100644
> --- a/drivers/usb/gadget/function/f_uac2.c
> +++ b/drivers/usb/gadget/function/f_uac2.c
> @@ -2013,6 +2013,7 @@ static ssize_t f_uac2_opts_##name##_store(struct config_item *item,	\
>  {									\
>  	struct f_uac2_opts *opts = to_f_uac2_opts(item);		\
>  	char *split_page = NULL;					\
> +	char *split_page_orig = NULL;					\
>  	int ret = -EINVAL;						\
>  	char *token;							\
>  	u32 num;							\
> @@ -2026,7 +2027,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);				\
> +	split_page_orig = split_page = kstrdup(page, GFP_KERNEL);      \
>  	while ((token = strsep(&split_page, ",")) != NULL) {		\
>  		ret = kstrtou32(token, 0, &num);			\
>  		if (ret)						\
> @@ -2037,7 +2038,7 @@ static ssize_t f_uac2_opts_##name##_store(struct config_item *item,	\
>  	};								\
>  									\
>  end:									\
> -	kfree(split_page);						\
> +	kfree(split_page_orig);						\
>  	mutex_unlock(&opts->lock);					\
>  	return ret;							\
>  }									\
> 
> -- 
> 2.53.0
> 
> 

Does not apply to the usb-linus branch :(

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

end of thread, other threads:[~2026-11-20  9:51 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-08-04 17:43 [PATCH 0/2] usb: gadget: f_uac1/f_uac2: fix invalid-free in srate configfs store Anuj Bolewar via B4 Relay
2026-08-04 17:43 ` [PATCH 1/2] usb: gadget: f_uac2: " Anuj Bolewar via B4 Relay
2026-11-20  9:51   ` Greg Kroah-Hartman
2026-08-04 17:43 ` [PATCH 2/2] usb: gadget: f_uac1: " Anuj Bolewar via B4 Relay

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®