From: Vineet Thakran <vineet789thakran@gmail.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Neill Kapron <nkapron@google.com>
Cc: Ruslan Bilovol <ruslan.bilovol@gmail.com>,
Pavel Hofman <pavel.hofman@ivitera.com>,
linux-usb@vger.kernel.org,
Vineet Thakran <vineet789thakran@gmail.com>,
stable@vger.kernel.org
Subject: [PATCH 4/4] usb: gadget: f_uac1: fix feature unit and AC header descriptor leak
Date: Thu, 3 Dec 2026 19:32:17 +0000 [thread overview]
Message-ID: <20261203193217.465889-5-vineet789thakran@gmail.com> (raw)
In-Reply-To: <20261203193217.465889-1-vineet789thakran@gmail.com>
f_audio_bind() allocates the AC header and feature unit descriptors and
stores them in the file-scope ac_header_desc, in_feature_unit_desc and
out_feature_unit_desc pointers, which are freed only in
f_audio_unbind(). When a configuration contains more than one f_uac1
instance, each bind overwrites the pointers left by the previous one,
and those descriptors are leaked. This is the same problem syzbot
reported for f_uac2.
usb_assign_descriptors() copies the descriptors into the function, and
since the previous patch nothing uses them after f_audio_bind(). Free
them on every exit path of f_audio_bind(), including success, and drop
the now redundant kfree() calls from f_audio_unbind().
Fixes: 254cb1e0d78c ("usb: gadget: f_uac1: disable IN/OUT ep if unused")
Fixes: 0356e6283c71 ("usb: gadget: f_uac1: add volume and mute support")
Cc: stable@vger.kernel.org
Signed-off-by: Vineet Thakran <vineet789thakran@gmail.com>
---
drivers/usb/gadget/function/f_uac1.c | 41 ++++++++++++----------------
1 file changed, 17 insertions(+), 24 deletions(-)
diff --git a/drivers/usb/gadget/function/f_uac1.c b/drivers/usb/gadget/function/f_uac1.c
index 6a5c00d3a8e6..2c892db84c65 100644
--- a/drivers/usb/gadget/function/f_uac1.c
+++ b/drivers/usb/gadget/function/f_uac1.c
@@ -1277,14 +1277,14 @@ static int f_audio_bind(struct usb_configuration *c, struct usb_function *f)
out_feature_unit_desc = build_fu_desc(audio_opts->c_chmask);
if (!out_feature_unit_desc) {
status = -ENOMEM;
- goto fail;
+ goto free_ac_header;
}
}
if (FUIN_EN(audio_opts)) {
in_feature_unit_desc = build_fu_desc(audio_opts->p_chmask);
if (!in_feature_unit_desc) {
status = -ENOMEM;
- goto err_free_fu;
+ goto free_fu;
}
}
@@ -1372,7 +1372,7 @@ static int f_audio_bind(struct usb_configuration *c, struct usb_function *f)
/* allocate instance-specific interface IDs, and patch descriptors */
status = usb_interface_id(c, f);
if (status < 0)
- goto err_free_fu;
+ goto free_fu;
ac_interface_desc.bInterfaceNumber = status;
uac1->ac_intf = status;
uac1->ac_alt = 0;
@@ -1382,7 +1382,7 @@ static int f_audio_bind(struct usb_configuration *c, struct usb_function *f)
if (EPOUT_EN(audio_opts)) {
status = usb_interface_id(c, f);
if (status < 0)
- goto err_free_fu;
+ goto free_fu;
as_out_interface_alt_0_desc.bInterfaceNumber = status;
as_out_interface_alt_1_desc.bInterfaceNumber = status;
ac_header_desc->baInterfaceNr[ba_iface_id++] = status;
@@ -1393,7 +1393,7 @@ static int f_audio_bind(struct usb_configuration *c, struct usb_function *f)
if (EPIN_EN(audio_opts)) {
status = usb_interface_id(c, f);
if (status < 0)
- goto err_free_fu;
+ goto free_fu;
as_in_interface_alt_0_desc.bInterfaceNumber = status;
as_in_interface_alt_1_desc.bInterfaceNumber = status;
ac_header_desc->baInterfaceNr[ba_iface_id++] = status;
@@ -1411,7 +1411,7 @@ static int f_audio_bind(struct usb_configuration *c, struct usb_function *f)
if (FUOUT_EN(audio_opts) || FUIN_EN(audio_opts)) {
ep = usb_ep_autoconfig(cdev->gadget, &ac_int_ep_desc);
if (!ep)
- goto err_free_fu;
+ goto free_fu;
uac1->int_ep = ep;
uac1->int_ep->desc = &ac_int_ep_desc;
@@ -1422,7 +1422,7 @@ static int f_audio_bind(struct usb_configuration *c, struct usb_function *f)
if (EPOUT_EN(audio_opts)) {
ep = usb_ep_autoconfig(cdev->gadget, &as_out_ep_desc);
if (!ep)
- goto err_free_fu;
+ goto free_fu;
ss_as_out_ep_desc.bEndpointAddress = as_out_ep_desc.bEndpointAddress;
audio->out_ep = ep;
audio->out_ep->desc = &as_out_ep_desc;
@@ -1431,7 +1431,7 @@ static int f_audio_bind(struct usb_configuration *c, struct usb_function *f)
if (EPIN_EN(audio_opts)) {
ep = usb_ep_autoconfig(cdev->gadget, &as_in_ep_desc);
if (!ep)
- goto err_free_fu;
+ goto free_fu;
ss_as_in_ep_desc.bEndpointAddress = as_in_ep_desc.bEndpointAddress;
audio->in_ep = ep;
audio->in_ep->desc = &as_in_ep_desc;
@@ -1443,7 +1443,7 @@ static int f_audio_bind(struct usb_configuration *c, struct usb_function *f)
status = usb_assign_descriptors(f, f_audio_desc, f_audio_desc, f_audio_ss_desc,
f_audio_ss_desc);
if (status)
- goto err_free_fu;
+ goto free_fu;
audio->out_ep_maxpsize = le16_to_cpu(as_out_ep_desc.wMaxPacketSize);
audio->in_ep_maxpsize = le16_to_cpu(as_in_ep_desc.wMaxPacketSize);
@@ -1480,18 +1480,19 @@ static int f_audio_bind(struct usb_configuration *c, struct usb_function *f)
status = g_audio_setup(audio, "UAC1_PCM", "UAC1_Gadget");
if (status)
- goto err_card_register;
+ usb_free_all_descriptors(f);
- return 0;
-
-err_card_register:
- usb_free_all_descriptors(f);
-err_free_fu:
+free_fu:
+ /*
+ * The feature unit and AC header descriptors are shared by all
+ * instances and only needed until usb_assign_descriptors() has
+ * copied them, so release them on every exit path.
+ */
kfree(out_feature_unit_desc);
out_feature_unit_desc = NULL;
kfree(in_feature_unit_desc);
in_feature_unit_desc = NULL;
-fail:
+free_ac_header:
kfree(ac_header_desc);
ac_header_desc = NULL;
return status;
@@ -1819,14 +1820,6 @@ static void f_audio_unbind(struct usb_configuration *c, struct usb_function *f)
g_audio_cleanup(audio);
usb_free_all_descriptors(f);
- kfree(out_feature_unit_desc);
- out_feature_unit_desc = NULL;
- kfree(in_feature_unit_desc);
- in_feature_unit_desc = NULL;
-
- kfree(ac_header_desc);
- ac_header_desc = NULL;
-
audio->gadget = NULL;
}
--
2.43.0
next prev parent reply other threads:[~2026-12-03 19:39 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 19:32 [PATCH 0/4] usb: gadget: f_uac1/f_uac2: fix descriptor leaks and NULL deref with multiple instances Vineet Thakran
2026-12-03 19:32 ` [PATCH 1/4] usb: gadget: f_uac2: use per-instance feature unit IDs in control requests Vineet Thakran
2026-12-03 19:32 ` [PATCH 2/4] usb: gadget: f_uac2: fix feature unit descriptor leak Vineet Thakran
2026-12-03 19:54 ` sashiko-bot
2026-12-03 19:32 ` [PATCH 3/4] usb: gadget: f_uac1: use per-instance feature unit IDs in control requests Vineet Thakran
2026-12-03 19:32 ` Vineet Thakran [this message]
2026-12-03 19:52 ` [PATCH 4/4] usb: gadget: f_uac1: fix feature unit and AC header descriptor leak sashiko-bot
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=20261203193217.465889-5-vineet789thakran@gmail.com \
--to=vineet789thakran@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-usb@vger.kernel.org \
--cc=nkapron@google.com \
--cc=pavel.hofman@ivitera.com \
--cc=ruslan.bilovol@gmail.com \
--cc=stable@vger.kernel.org \
/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