* [PATCH v2 1/6] usb: gadget: f_uac2: use per-instance feature unit IDs in control requests
2026-12-05 11:08 [PATCH v2 0/6] usb: gadget: f_uac1/f_uac2: fix descriptor leaks, NULL deref and bind race with multiple instances Vineet Thakran
@ 2026-12-05 11:08 ` Vineet Thakran
2026-12-05 11:08 ` [PATCH v2 2/6] usb: gadget: f_uac2: serialize bind with a mutex Vineet Thakran
` (5 subsequent siblings)
6 siblings, 0 replies; 9+ messages in thread
From: Vineet Thakran @ 2026-12-05 11:08 UTC (permalink / raw)
To: Greg Kroah-Hartman, Neill Kapron
Cc: Ruslan Bilovol, Pavel Hofman, linux-usb, Vineet Thakran, stable
The class-specific control request handlers look up the feature unit
IDs through the file-scope in_feature_unit_desc/out_feature_unit_desc
pointers. These pointers are shared by every f_uac2 instance, but each
instance allocates its own descriptors in afunc_bind() and
afunc_unbind() frees them and sets the pointers to NULL.
So once one instance unbinds, every other instance that is still bound
dereferences a NULL pointer on the next feature unit control request
from the host. With two gadgets, each with a uac2 function on its own
UDC, unbinding the first gadget and connecting the second to a host
gives:
Unable to handle kernel NULL pointer dereference
pc : afunc_setup+0x2f8/0x568
afunc_bind() already stores each unit ID in agdev->params.p_fu.id and
agdev->params.c_fu.id, which live as long as the instance. Make the
USB_IN_FU_ID()/USB_OUT_FU_ID() macros read those per-instance values
instead, and fill them directly from the descriptors in afunc_bind().
This also means nothing uses the feature unit descriptors after bind,
which a later patch in this series relies on.
Fixes: eaf6cbe09920 ("usb: gadget: f_uac2: add volume and mute support")
Cc: stable@vger.kernel.org
Signed-off-by: Vineet Thakran <vineet789thakran@gmail.com>
---
drivers/usb/gadget/function/f_uac2.c | 30 ++++++++++++++--------------
1 file changed, 15 insertions(+), 15 deletions(-)
diff --git a/drivers/usb/gadget/function/f_uac2.c b/drivers/usb/gadget/function/f_uac2.c
index a5f3d4d6c34b..dca8c6d7640c 100644
--- a/drivers/usb/gadget/function/f_uac2.c
+++ b/drivers/usb/gadget/function/f_uac2.c
@@ -31,8 +31,8 @@
*/
#define USB_OUT_CLK_ID (out_clk_src_desc.bClockID)
#define USB_IN_CLK_ID (in_clk_src_desc.bClockID)
-#define USB_OUT_FU_ID (out_feature_unit_desc->bUnitID)
-#define USB_IN_FU_ID (in_feature_unit_desc->bUnitID)
+#define USB_OUT_FU_ID(_agdev) ((_agdev)->params.c_fu.id)
+#define USB_IN_FU_ID(_agdev) ((_agdev)->params.p_fu.id)
#define CONTROL_ABSENT 0
#define CONTROL_RDONLY 1
@@ -1340,7 +1340,7 @@ afunc_bind(struct usb_configuration *cfg, struct usb_function *fn)
sizeof(agdev->params.p_srates));
agdev->params.p_ssize = uac2_opts->p_ssize;
if (FUIN_EN(uac2_opts)) {
- agdev->params.p_fu.id = USB_IN_FU_ID;
+ agdev->params.p_fu.id = in_feature_unit_desc->bUnitID;
agdev->params.p_fu.mute_present = uac2_opts->p_mute_present;
agdev->params.p_fu.volume_present = uac2_opts->p_volume_present;
agdev->params.p_fu.volume_min = uac2_opts->p_volume_min;
@@ -1352,7 +1352,7 @@ afunc_bind(struct usb_configuration *cfg, struct usb_function *fn)
sizeof(agdev->params.c_srates));
agdev->params.c_ssize = uac2_opts->c_ssize;
if (FUOUT_EN(uac2_opts)) {
- agdev->params.c_fu.id = USB_OUT_FU_ID;
+ agdev->params.c_fu.id = out_feature_unit_desc->bUnitID;
agdev->params.c_fu.mute_present = uac2_opts->c_mute_present;
agdev->params.c_fu.volume_present = uac2_opts->c_volume_present;
agdev->params.c_fu.volume_min = uac2_opts->c_volume_min;
@@ -1586,11 +1586,11 @@ in_rq_cur(struct usb_function *fn, const struct usb_ctrlrequest *cr)
"%s:%d control_selector=%d TODO!\n",
__func__, __LINE__, control_selector);
}
- } else if ((FUIN_EN(opts) && (entity_id == USB_IN_FU_ID)) ||
- (FUOUT_EN(opts) && (entity_id == USB_OUT_FU_ID))) {
+ } else if ((FUIN_EN(opts) && (entity_id == USB_IN_FU_ID(agdev))) ||
+ (FUOUT_EN(opts) && (entity_id == USB_OUT_FU_ID(agdev)))) {
unsigned int is_playback = 0;
- if (FUIN_EN(opts) && (entity_id == USB_IN_FU_ID))
+ if (FUIN_EN(opts) && (entity_id == USB_IN_FU_ID(agdev)))
is_playback = 1;
if (control_selector == UAC_FU_MUTE) {
@@ -1675,11 +1675,11 @@ in_rq_range(struct usb_function *fn, const struct usb_ctrlrequest *cr)
"%s:%d control_selector=%d TODO!\n",
__func__, __LINE__, control_selector);
}
- } else if ((FUIN_EN(opts) && (entity_id == USB_IN_FU_ID)) ||
- (FUOUT_EN(opts) && (entity_id == USB_OUT_FU_ID))) {
+ } else if ((FUIN_EN(opts) && (entity_id == USB_IN_FU_ID(agdev))) ||
+ (FUOUT_EN(opts) && (entity_id == USB_OUT_FU_ID(agdev)))) {
unsigned int is_playback = 0;
- if (FUIN_EN(opts) && (entity_id == USB_IN_FU_ID))
+ if (FUIN_EN(opts) && (entity_id == USB_IN_FU_ID(agdev)))
is_playback = 1;
if (control_selector == UAC_FU_VOLUME) {
@@ -1765,11 +1765,11 @@ out_rq_cur_complete(struct usb_ep *ep, struct usb_request *req)
return;
}
- if ((FUIN_EN(opts) && (entity_id == USB_IN_FU_ID)) ||
- (FUOUT_EN(opts) && (entity_id == USB_OUT_FU_ID))) {
+ if ((FUIN_EN(opts) && (entity_id == USB_IN_FU_ID(agdev))) ||
+ (FUOUT_EN(opts) && (entity_id == USB_OUT_FU_ID(agdev)))) {
unsigned int is_playback = 0;
- if (FUIN_EN(opts) && (entity_id == USB_IN_FU_ID))
+ if (FUIN_EN(opts) && (entity_id == USB_IN_FU_ID(agdev)))
is_playback = 1;
if (control_selector == UAC_FU_MUTE) {
@@ -1819,8 +1819,8 @@ out_rq_cur(struct usb_function *fn, const struct usb_ctrlrequest *cr)
req->complete = uac2_cs_control_sam_freq;
return w_length;
}
- } else if ((FUIN_EN(opts) && (entity_id == USB_IN_FU_ID)) ||
- (FUOUT_EN(opts) && (entity_id == USB_OUT_FU_ID))) {
+ } else if ((FUIN_EN(opts) && (entity_id == USB_IN_FU_ID(agdev))) ||
+ (FUOUT_EN(opts) && (entity_id == USB_OUT_FU_ID(agdev)))) {
memcpy(&uac2->setup_cr, cr, sizeof(*cr));
req->context = agdev;
req->complete = out_rq_cur_complete;
--
2.43.0
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH v2 2/6] usb: gadget: f_uac2: serialize bind with a mutex
2026-12-05 11:08 [PATCH v2 0/6] usb: gadget: f_uac1/f_uac2: fix descriptor leaks, NULL deref and bind race with multiple instances Vineet Thakran
2026-12-05 11:08 ` [PATCH v2 1/6] usb: gadget: f_uac2: use per-instance feature unit IDs in control requests Vineet Thakran
@ 2026-12-05 11:08 ` Vineet Thakran
2026-12-05 11:08 ` [PATCH v2 3/6] usb: gadget: f_uac2: fix feature unit descriptor leak Vineet Thakran
` (4 subsequent siblings)
6 siblings, 0 replies; 9+ messages in thread
From: Vineet Thakran @ 2026-12-05 11:08 UTC (permalink / raw)
To: Greg Kroah-Hartman, Neill Kapron
Cc: Ruslan Bilovol, Pavel Hofman, linux-usb, Vineet Thakran, stable
afunc_bind() sets up descriptors that are shared by all f_uac2
instances: setup_descriptor() rebuilds the static fs/hs/ss descriptor
arrays, and the feature unit descriptors live in the file-scope
in_feature_unit_desc/out_feature_unit_desc pointers, which
afunc_unbind() frees.
Nothing serializes this between instances. configfs only holds the
per-gadget lock while binding, and the UDC core drops udc_lock before
calling the gadget driver's bind(), so two gadgets bound to different
UDCs can run afunc_bind() at the same time, or one can run afunc_bind()
while the other runs afunc_unbind(). Binding and unbinding two such
gadgets in parallel loops gives:
BUG: KASAN: double-free in afunc_unbind+0x4c/0x70
Add a file-scope mutex, as f_midi2 does with f_midi2_desc_mutex, and
hold it in afunc_bind() from the first write to the shared descriptors
until it returns, and around the frees in afunc_unbind().
Fixes: 3fa4eaa6c082 ("usb: gadget: f_uac2: disable IN/OUT ep if unused")
Fixes: eaf6cbe09920 ("usb: gadget: f_uac2: add volume and mute support")
Cc: stable@vger.kernel.org
Signed-off-by: Vineet Thakran <vineet789thakran@gmail.com>
---
drivers/usb/gadget/function/f_uac2.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/drivers/usb/gadget/function/f_uac2.c b/drivers/usb/gadget/function/f_uac2.c
index dca8c6d7640c..7a3179ad8f97 100644
--- a/drivers/usb/gadget/function/f_uac2.c
+++ b/drivers/usb/gadget/function/f_uac2.c
@@ -13,6 +13,7 @@
#include <linux/usb/audio.h>
#include <linux/usb/audio-v2.h>
#include <linux/module.h>
+#include <linux/mutex.h>
#include "u_audio.h"
@@ -246,6 +247,9 @@ static struct uac2_output_terminal_descriptor io_out_ot_desc = {
static struct uac2_feature_unit_descriptor *in_feature_unit_desc;
static struct uac2_feature_unit_descriptor *out_feature_unit_desc;
+/* Serializes access to the descriptors shared by all instances */
+static DEFINE_MUTEX(f_uac2_desc_mutex);
+
static struct uac2_ac_header_descriptor ac_hdr_desc = {
.bLength = sizeof ac_hdr_desc,
.bDescriptorType = USB_DT_CS_INTERFACE,
@@ -1059,6 +1063,8 @@ afunc_bind(struct usb_configuration *cfg, struct usb_function *fn)
if (ret)
return ret;
+ guard(mutex)(&f_uac2_desc_mutex);
+
strings_fn[STR_ASSOC].s = uac2_opts->function_name;
strings_fn[STR_IF_CTRL].s = uac2_opts->if_ctrl_name;
strings_fn[STR_CLKSRC_IN].s = uac2_opts->clksrc_in_name;
@@ -2306,6 +2312,7 @@ static void afunc_unbind(struct usb_configuration *c, struct usb_function *f)
agdev->gadget = NULL;
+ guard(mutex)(&f_uac2_desc_mutex);
kfree(out_feature_unit_desc);
out_feature_unit_desc = NULL;
kfree(in_feature_unit_desc);
--
2.43.0
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH v2 3/6] usb: gadget: f_uac2: fix feature unit descriptor leak
2026-12-05 11:08 [PATCH v2 0/6] usb: gadget: f_uac1/f_uac2: fix descriptor leaks, NULL deref and bind race with multiple instances Vineet Thakran
2026-12-05 11:08 ` [PATCH v2 1/6] usb: gadget: f_uac2: use per-instance feature unit IDs in control requests Vineet Thakran
2026-12-05 11:08 ` [PATCH v2 2/6] usb: gadget: f_uac2: serialize bind with a mutex Vineet Thakran
@ 2026-12-05 11:08 ` Vineet Thakran
2026-12-05 11:08 ` [PATCH v2 4/6] usb: gadget: f_uac1: use per-instance feature unit IDs in control requests Vineet Thakran
` (3 subsequent siblings)
6 siblings, 0 replies; 9+ messages in thread
From: Vineet Thakran @ 2026-12-05 11:08 UTC (permalink / raw)
To: Greg Kroah-Hartman, Neill Kapron
Cc: Ruslan Bilovol, Pavel Hofman, linux-usb, Vineet Thakran,
syzbot+da5ce3f4a00c8cbe0d4e, stable
afunc_bind() allocates the feature unit descriptors and stores them in
the file-scope in_feature_unit_desc/out_feature_unit_desc pointers,
which are freed only in afunc_unbind(). When a configuration contains
more than one f_uac2 instance, each bind overwrites the pointers left
by the previous one, and those descriptors are leaked:
unreferenced object 0xffff888111d43640 (size 32):
build_fu_desc+0x3f/0x70 drivers/usb/gadget/function/f_uac2.c:773
afunc_bind+0x1414/0x16a0 drivers/usb/gadget/function/f_uac2.c:1062
usb_add_function+0xca/0x270 drivers/usb/gadget/composite.c:333
configfs_composite_bind+0x667/0x9b0 drivers/usb/gadget/configfs.c:1803
usb_assign_descriptors() copies the descriptors into the function, and
since the per-instance feature unit ID change nothing uses them after
afunc_bind(). Free them on every exit path of afunc_bind(), including
success, and drop the now redundant kfree() calls from afunc_unbind().
The set_ep_max_packet_size_bint() error paths also returned without
freeing the descriptors. They cannot trigger today, as that function
only fails for an unknown speed, but route them through the same
cleanup so that every exit path releases the descriptors.
Reported-by: syzbot+da5ce3f4a00c8cbe0d4e@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=da5ce3f4a00c8cbe0d4e
Fixes: eaf6cbe09920 ("usb: gadget: f_uac2: add volume and mute support")
Cc: stable@vger.kernel.org
Signed-off-by: Vineet Thakran <vineet789thakran@gmail.com>
---
drivers/usb/gadget/function/f_uac2.c | 54 +++++++++++++---------------
1 file changed, 25 insertions(+), 29 deletions(-)
diff --git a/drivers/usb/gadget/function/f_uac2.c b/drivers/usb/gadget/function/f_uac2.c
index 7a3179ad8f97..4bc876512ffb 100644
--- a/drivers/usb/gadget/function/f_uac2.c
+++ b/drivers/usb/gadget/function/f_uac2.c
@@ -1101,7 +1101,7 @@ afunc_bind(struct usb_configuration *cfg, struct usb_function *fn)
in_feature_unit_desc = build_fu_desc(p_channels);
if (!in_feature_unit_desc) {
ret = -ENOMEM;
- goto err_free_fu;
+ goto free_fu;
}
}
@@ -1169,7 +1169,7 @@ afunc_bind(struct usb_configuration *cfg, struct usb_function *fn)
ret = usb_interface_id(cfg, fn);
if (ret < 0) {
dev_err(dev, "%s:%d Error!\n", __func__, __LINE__);
- goto err_free_fu;
+ goto free_fu;
}
iad_desc.bFirstInterface = ret;
@@ -1181,7 +1181,7 @@ afunc_bind(struct usb_configuration *cfg, struct usb_function *fn)
ret = usb_interface_id(cfg, fn);
if (ret < 0) {
dev_err(dev, "%s:%d Error!\n", __func__, __LINE__);
- goto err_free_fu;
+ goto free_fu;
}
std_as_out_if0_desc.bInterfaceNumber = ret;
std_as_out_if1_desc.bInterfaceNumber = ret;
@@ -1211,7 +1211,7 @@ afunc_bind(struct usb_configuration *cfg, struct usb_function *fn)
ret = usb_interface_id(cfg, fn);
if (ret < 0) {
dev_err(dev, "%s:%d Error!\n", __func__, __LINE__);
- goto err_free_fu;
+ goto free_fu;
}
std_as_in_if0_desc.bInterfaceNumber = ret;
std_as_in_if1_desc.bInterfaceNumber = ret;
@@ -1225,7 +1225,7 @@ afunc_bind(struct usb_configuration *cfg, struct usb_function *fn)
if (!uac2->int_ep) {
dev_err(dev, "%s:%d Error!\n", __func__, __LINE__);
ret = -ENODEV;
- goto err_free_fu;
+ goto free_fu;
}
std_ac_if_desc.bNumEndpoints = 1;
@@ -1241,42 +1241,42 @@ afunc_bind(struct usb_configuration *cfg, struct usb_function *fn)
USB_SPEED_FULL, true);
if (ret < 0) {
dev_err(dev, "%s:%d Error!\n", __func__, __LINE__);
- return ret;
+ goto free_fu;
}
ret = set_ep_max_packet_size_bint(dev, uac2_opts, &fs_epout_desc,
USB_SPEED_FULL, false);
if (ret < 0) {
dev_err(dev, "%s:%d Error!\n", __func__, __LINE__);
- return ret;
+ goto free_fu;
}
ret = set_ep_max_packet_size_bint(dev, uac2_opts, &hs_epin_desc,
USB_SPEED_HIGH, true);
if (ret < 0) {
dev_err(dev, "%s:%d Error!\n", __func__, __LINE__);
- return ret;
+ goto free_fu;
}
ret = set_ep_max_packet_size_bint(dev, uac2_opts, &hs_epout_desc,
USB_SPEED_HIGH, false);
if (ret < 0) {
dev_err(dev, "%s:%d Error!\n", __func__, __LINE__);
- return ret;
+ goto free_fu;
}
ret = set_ep_max_packet_size_bint(dev, uac2_opts, &ss_epin_desc,
USB_SPEED_SUPER, true);
if (ret < 0) {
dev_err(dev, "%s:%d Error!\n", __func__, __LINE__);
- return ret;
+ goto free_fu;
}
ret = set_ep_max_packet_size_bint(dev, uac2_opts, &ss_epout_desc,
USB_SPEED_SUPER, false);
if (ret < 0) {
dev_err(dev, "%s:%d Error!\n", __func__, __LINE__);
- return ret;
+ goto free_fu;
}
if (EPOUT_EN(uac2_opts)) {
@@ -1284,7 +1284,7 @@ afunc_bind(struct usb_configuration *cfg, struct usb_function *fn)
if (!agdev->out_ep) {
dev_err(dev, "%s:%d Error!\n", __func__, __LINE__);
ret = -ENODEV;
- goto err_free_fu;
+ goto free_fu;
}
if (EPOUT_FBACK_IN_EN(uac2_opts)) {
agdev->in_ep_fback = usb_ep_autoconfig(gadget,
@@ -1293,7 +1293,7 @@ afunc_bind(struct usb_configuration *cfg, struct usb_function *fn)
dev_err(dev, "%s:%d Error!\n",
__func__, __LINE__);
ret = -ENODEV;
- goto err_free_fu;
+ goto free_fu;
}
}
}
@@ -1303,7 +1303,7 @@ afunc_bind(struct usb_configuration *cfg, struct usb_function *fn)
if (!agdev->in_ep) {
dev_err(dev, "%s:%d Error!\n", __func__, __LINE__);
ret = -ENODEV;
- goto err_free_fu;
+ goto free_fu;
}
}
@@ -1337,7 +1337,7 @@ afunc_bind(struct usb_configuration *cfg, struct usb_function *fn)
ret = usb_assign_descriptors(fn, fs_audio_desc, hs_audio_desc, ss_audio_desc,
ss_audio_desc);
if (ret)
- goto err_free_fu;
+ goto free_fu;
agdev->gadget = gadget;
@@ -1372,15 +1372,17 @@ afunc_bind(struct usb_configuration *cfg, struct usb_function *fn)
agdev->notify = afunc_notify;
ret = g_audio_setup(agdev, "UAC2 PCM", "UAC2_Gadget");
- if (ret)
- goto err_free_descs;
-
- return 0;
+ if (ret) {
+ usb_free_all_descriptors(fn);
+ agdev->gadget = NULL;
+ }
-err_free_descs:
- usb_free_all_descriptors(fn);
- agdev->gadget = NULL;
-err_free_fu:
+free_fu:
+ /*
+ * The feature unit 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);
@@ -2311,12 +2313,6 @@ static void afunc_unbind(struct usb_configuration *c, struct usb_function *f)
usb_free_all_descriptors(f);
agdev->gadget = NULL;
-
- guard(mutex)(&f_uac2_desc_mutex);
- kfree(out_feature_unit_desc);
- out_feature_unit_desc = NULL;
- kfree(in_feature_unit_desc);
- in_feature_unit_desc = NULL;
}
static struct usb_function *afunc_alloc(struct usb_function_instance *fi)
--
2.43.0
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH v2 4/6] usb: gadget: f_uac1: use per-instance feature unit IDs in control requests
2026-12-05 11:08 [PATCH v2 0/6] usb: gadget: f_uac1/f_uac2: fix descriptor leaks, NULL deref and bind race with multiple instances Vineet Thakran
` (2 preceding siblings ...)
2026-12-05 11:08 ` [PATCH v2 3/6] usb: gadget: f_uac2: fix feature unit descriptor leak Vineet Thakran
@ 2026-12-05 11:08 ` Vineet Thakran
2026-12-05 11:08 ` [PATCH v2 5/6] usb: gadget: f_uac1: serialize bind with a mutex Vineet Thakran
` (2 subsequent siblings)
6 siblings, 0 replies; 9+ messages in thread
From: Vineet Thakran @ 2026-12-05 11:08 UTC (permalink / raw)
To: Greg Kroah-Hartman, Neill Kapron
Cc: Ruslan Bilovol, Pavel Hofman, linux-usb, Vineet Thakran, stable
The class-specific control request handlers look up the feature unit
IDs through the file-scope in_feature_unit_desc/out_feature_unit_desc
pointers. These pointers are shared by every f_uac1 instance, but each
instance allocates its own descriptors in f_audio_bind() and
f_audio_unbind() frees them and sets the pointers to NULL.
So once one instance unbinds, every other instance that is still bound
dereferences a NULL pointer on the next feature unit control request
from the host. With two gadgets, each with a uac1 function on its own
UDC, unbinding the first gadget and connecting the second to a host
gives:
Unable to handle kernel NULL pointer dereference
pc : f_audio_setup+0x364/0x64c
f_audio_bind() already stores each unit ID in audio->params.p_fu.id and
audio->params.c_fu.id, which live as long as the instance. Make the
USB_IN_FU_ID()/USB_OUT_FU_ID() macros read those per-instance values
instead, and fill them directly from the descriptors in f_audio_bind().
This also means nothing uses the feature unit descriptors after bind,
which a later patch in this series relies on.
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 | 42 ++++++++++++++--------------
1 file changed, 21 insertions(+), 21 deletions(-)
diff --git a/drivers/usb/gadget/function/f_uac1.c b/drivers/usb/gadget/function/f_uac1.c
index 7539817cd407..6a5c00d3a8e6 100644
--- a/drivers/usb/gadget/function/f_uac1.c
+++ b/drivers/usb/gadget/function/f_uac1.c
@@ -23,8 +23,8 @@
/* UAC1 spec: 3.7.2.3 Audio Channel Cluster Format */
#define UAC1_CHANNEL_MASK 0x0FFF
-#define USB_OUT_FU_ID (out_feature_unit_desc->bUnitID)
-#define USB_IN_FU_ID (in_feature_unit_desc->bUnitID)
+#define USB_OUT_FU_ID(_audio) ((_audio)->params.c_fu.id)
+#define USB_IN_FU_ID(_audio) ((_audio)->params.p_fu.id)
#define EPIN_EN(_opts) ((_opts)->p_chmask != 0)
#define EPOUT_EN(_opts) ((_opts)->c_chmask != 0)
@@ -496,11 +496,11 @@ in_rq_cur(struct usb_function *fn, const struct usb_ctrlrequest *cr)
u8 control_selector = w_value >> 8;
int value = -EOPNOTSUPP;
- if ((FUIN_EN(opts) && (entity_id == USB_IN_FU_ID)) ||
- (FUOUT_EN(opts) && (entity_id == USB_OUT_FU_ID))) {
+ if ((FUIN_EN(opts) && (entity_id == USB_IN_FU_ID(audio))) ||
+ (FUOUT_EN(opts) && (entity_id == USB_OUT_FU_ID(audio)))) {
unsigned int is_playback = 0;
- if (FUIN_EN(opts) && (entity_id == USB_IN_FU_ID))
+ if (FUIN_EN(opts) && (entity_id == USB_IN_FU_ID(audio)))
is_playback = 1;
if (control_selector == UAC_FU_MUTE) {
@@ -547,11 +547,11 @@ in_rq_min(struct usb_function *fn, const struct usb_ctrlrequest *cr)
u8 control_selector = w_value >> 8;
int value = -EOPNOTSUPP;
- if ((FUIN_EN(opts) && (entity_id == USB_IN_FU_ID)) ||
- (FUOUT_EN(opts) && (entity_id == USB_OUT_FU_ID))) {
+ if ((FUIN_EN(opts) && (entity_id == USB_IN_FU_ID(audio))) ||
+ (FUOUT_EN(opts) && (entity_id == USB_OUT_FU_ID(audio)))) {
unsigned int is_playback = 0;
- if (FUIN_EN(opts) && (entity_id == USB_IN_FU_ID))
+ if (FUIN_EN(opts) && (entity_id == USB_IN_FU_ID(audio)))
is_playback = 1;
if (control_selector == UAC_FU_VOLUME) {
@@ -594,11 +594,11 @@ in_rq_max(struct usb_function *fn, const struct usb_ctrlrequest *cr)
u8 control_selector = w_value >> 8;
int value = -EOPNOTSUPP;
- if ((FUIN_EN(opts) && (entity_id == USB_IN_FU_ID)) ||
- (FUOUT_EN(opts) && (entity_id == USB_OUT_FU_ID))) {
+ if ((FUIN_EN(opts) && (entity_id == USB_IN_FU_ID(audio))) ||
+ (FUOUT_EN(opts) && (entity_id == USB_OUT_FU_ID(audio)))) {
unsigned int is_playback = 0;
- if (FUIN_EN(opts) && (entity_id == USB_IN_FU_ID))
+ if (FUIN_EN(opts) && (entity_id == USB_IN_FU_ID(audio)))
is_playback = 1;
if (control_selector == UAC_FU_VOLUME) {
@@ -641,11 +641,11 @@ in_rq_res(struct usb_function *fn, const struct usb_ctrlrequest *cr)
u8 control_selector = w_value >> 8;
int value = -EOPNOTSUPP;
- if ((FUIN_EN(opts) && (entity_id == USB_IN_FU_ID)) ||
- (FUOUT_EN(opts) && (entity_id == USB_OUT_FU_ID))) {
+ if ((FUIN_EN(opts) && (entity_id == USB_IN_FU_ID(audio))) ||
+ (FUOUT_EN(opts) && (entity_id == USB_OUT_FU_ID(audio)))) {
unsigned int is_playback = 0;
- if (FUIN_EN(opts) && (entity_id == USB_IN_FU_ID))
+ if (FUIN_EN(opts) && (entity_id == USB_IN_FU_ID(audio)))
is_playback = 1;
if (control_selector == UAC_FU_VOLUME) {
@@ -693,11 +693,11 @@ out_rq_cur_complete(struct usb_ep *ep, struct usb_request *req)
return;
}
- if ((FUIN_EN(opts) && (entity_id == USB_IN_FU_ID)) ||
- (FUOUT_EN(opts) && (entity_id == USB_OUT_FU_ID))) {
+ if ((FUIN_EN(opts) && (entity_id == USB_IN_FU_ID(audio))) ||
+ (FUOUT_EN(opts) && (entity_id == USB_OUT_FU_ID(audio)))) {
unsigned int is_playback = 0;
- if (FUIN_EN(opts) && (entity_id == USB_IN_FU_ID))
+ if (FUIN_EN(opts) && (entity_id == USB_IN_FU_ID(audio)))
is_playback = 1;
if (control_selector == UAC_FU_MUTE) {
@@ -742,8 +742,8 @@ out_rq_cur(struct usb_function *fn, const struct usb_ctrlrequest *cr)
u8 entity_id = (w_index >> 8) & 0xff;
u8 control_selector = w_value >> 8;
- if ((FUIN_EN(opts) && (entity_id == USB_IN_FU_ID)) ||
- (FUOUT_EN(opts) && (entity_id == USB_OUT_FU_ID))) {
+ if ((FUIN_EN(opts) && (entity_id == USB_IN_FU_ID(audio))) ||
+ (FUOUT_EN(opts) && (entity_id == USB_OUT_FU_ID(audio)))) {
memcpy(&uac1->setup_cr, cr, sizeof(*cr));
req->context = audio;
req->complete = out_rq_cur_complete;
@@ -1452,7 +1452,7 @@ static int f_audio_bind(struct usb_configuration *c, struct usb_function *f)
sizeof(audio->params.c_srates));
audio->params.c_ssize = audio_opts->c_ssize;
if (FUIN_EN(audio_opts)) {
- audio->params.p_fu.id = USB_IN_FU_ID;
+ audio->params.p_fu.id = in_feature_unit_desc->bUnitID;
audio->params.p_fu.mute_present = audio_opts->p_mute_present;
audio->params.p_fu.volume_present =
audio_opts->p_volume_present;
@@ -1465,7 +1465,7 @@ static int f_audio_bind(struct usb_configuration *c, struct usb_function *f)
sizeof(audio->params.p_srates));
audio->params.p_ssize = audio_opts->p_ssize;
if (FUOUT_EN(audio_opts)) {
- audio->params.c_fu.id = USB_OUT_FU_ID;
+ audio->params.c_fu.id = out_feature_unit_desc->bUnitID;
audio->params.c_fu.mute_present = audio_opts->c_mute_present;
audio->params.c_fu.volume_present =
audio_opts->c_volume_present;
--
2.43.0
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH v2 5/6] usb: gadget: f_uac1: serialize bind with a mutex
2026-12-05 11:08 [PATCH v2 0/6] usb: gadget: f_uac1/f_uac2: fix descriptor leaks, NULL deref and bind race with multiple instances Vineet Thakran
` (3 preceding siblings ...)
2026-12-05 11:08 ` [PATCH v2 4/6] usb: gadget: f_uac1: use per-instance feature unit IDs in control requests Vineet Thakran
@ 2026-12-05 11:08 ` Vineet Thakran
2026-12-05 11:08 ` [PATCH v2 6/6] usb: gadget: f_uac1: fix feature unit and AC header descriptor leak Vineet Thakran
2026-12-05 11:24 ` [PATCH v2 0/6] usb: gadget: f_uac1/f_uac2: fix descriptor leaks, NULL deref and bind race with multiple instances sashiko-bot
6 siblings, 0 replies; 9+ messages in thread
From: Vineet Thakran @ 2026-12-05 11:08 UTC (permalink / raw)
To: Greg Kroah-Hartman, Neill Kapron
Cc: Ruslan Bilovol, Pavel Hofman, linux-usb, Vineet Thakran, stable
f_audio_bind() sets up descriptors that are shared by all f_uac1
instances: setup_descriptor() rebuilds the static f_audio_desc array,
and the AC header and feature unit descriptors live in the file-scope
ac_header_desc, in_feature_unit_desc and out_feature_unit_desc
pointers, which f_audio_unbind() frees.
Nothing serializes this between instances. configfs only holds the
per-gadget lock while binding, and the UDC core drops udc_lock before
calling the gadget driver's bind(), so two gadgets bound to different
UDCs can run f_audio_bind() at the same time, or one can run
f_audio_bind() while the other runs f_audio_unbind(). Binding and
unbinding two such gadgets in parallel loops gives:
BUG: KASAN: slab-use-after-free in f_audio_bind+0x2898/0x28f4
Add a file-scope mutex, as f_midi2 does with f_midi2_desc_mutex, and
hold it in f_audio_bind() from the first write to the shared descriptors
until it returns, and around the frees in 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 | 20 ++++++++++++++------
1 file changed, 14 insertions(+), 6 deletions(-)
diff --git a/drivers/usb/gadget/function/f_uac1.c b/drivers/usb/gadget/function/f_uac1.c
index 6a5c00d3a8e6..012f8d4be0c0 100644
--- a/drivers/usb/gadget/function/f_uac1.c
+++ b/drivers/usb/gadget/function/f_uac1.c
@@ -16,6 +16,7 @@
#include <linux/usb/audio.h>
#include <linux/module.h>
+#include <linux/mutex.h>
#include "u_audio.h"
#include "u_uac1.h"
@@ -126,6 +127,9 @@ static struct uac1_output_terminal_descriptor usb_in_ot_desc = {
static struct uac_feature_unit_descriptor *in_feature_unit_desc;
static struct uac_feature_unit_descriptor *out_feature_unit_desc;
+/* Serializes access to the descriptors shared by all instances */
+static DEFINE_MUTEX(f_uac1_desc_mutex);
+
/* AC IN Interrupt Endpoint */
static struct usb_endpoint_descriptor ac_int_ep_desc = {
.bLength = USB_DT_ENDPOINT_SIZE,
@@ -1249,6 +1253,8 @@ static int f_audio_bind(struct usb_configuration *c, struct usb_function *f)
audio_opts = container_of(f->fi, struct f_uac1_opts, func_inst);
+ guard(mutex)(&f_uac1_desc_mutex);
+
strings_uac1[STR_AC_IF].s = audio_opts->function_name;
strings_uac1[STR_USB_OUT_IT].s = audio_opts->c_it_name;
@@ -1819,13 +1825,15 @@ 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;
+ scoped_guard(mutex, &f_uac1_desc_mutex) {
+ 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;
+ kfree(ac_header_desc);
+ ac_header_desc = NULL;
+ }
audio->gadget = NULL;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH v2 6/6] usb: gadget: f_uac1: fix feature unit and AC header descriptor leak
2026-12-05 11:08 [PATCH v2 0/6] usb: gadget: f_uac1/f_uac2: fix descriptor leaks, NULL deref and bind race with multiple instances Vineet Thakran
` (4 preceding siblings ...)
2026-12-05 11:08 ` [PATCH v2 5/6] usb: gadget: f_uac1: serialize bind with a mutex Vineet Thakran
@ 2026-12-05 11:08 ` Vineet Thakran
2026-12-05 11:20 ` sashiko-bot
2026-12-05 11:24 ` [PATCH v2 0/6] usb: gadget: f_uac1/f_uac2: fix descriptor leaks, NULL deref and bind race with multiple instances sashiko-bot
6 siblings, 1 reply; 9+ messages in thread
From: Vineet Thakran @ 2026-12-05 11:08 UTC (permalink / raw)
To: Greg Kroah-Hartman, Neill Kapron
Cc: Ruslan Bilovol, Pavel Hofman, linux-usb, Vineet Thakran, stable
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 patches nothing uses them after f_audio_bind(). Make
them local variables of f_audio_bind(), pass them to setup_descriptor(),
free them on every exit path of f_audio_bind(), including success, and
drop the now redundant kfree() calls from f_audio_unbind().
The static f_audio_desc and f_audio_ss_desc arrays used to take the
address of the file-scope pointers. Their entries become NULL
placeholders, and setup_descriptor() now fills in the AC header entry of
f_audio_ss_desc the same way it already does for f_audio_desc.
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 | 72 ++++++++++++----------------
1 file changed, 31 insertions(+), 41 deletions(-)
diff --git a/drivers/usb/gadget/function/f_uac1.c b/drivers/usb/gadget/function/f_uac1.c
index 012f8d4be0c0..71a34777f96f 100644
--- a/drivers/usb/gadget/function/f_uac1.c
+++ b/drivers/usb/gadget/function/f_uac1.c
@@ -81,9 +81,6 @@ static struct usb_interface_descriptor ac_interface_desc = {
.bInterfaceSubClass = USB_SUBCLASS_AUDIOCONTROL,
};
-/* B.3.2 Class-Specific AC Interface Descriptor */
-static struct uac1_ac_header_descriptor *ac_header_desc;
-
static struct uac_input_terminal_descriptor usb_out_it_desc = {
.bLength = UAC_DT_INPUT_TERMINAL_SIZE,
.bDescriptorType = USB_DT_CS_INTERFACE,
@@ -124,9 +121,6 @@ static struct uac1_output_terminal_descriptor usb_in_ot_desc = {
/* .bSourceID = DYNAMIC */
};
-static struct uac_feature_unit_descriptor *in_feature_unit_desc;
-static struct uac_feature_unit_descriptor *out_feature_unit_desc;
-
/* Serializes access to the descriptors shared by all instances */
static DEFINE_MUTEX(f_uac1_desc_mutex);
@@ -264,15 +258,15 @@ static struct uac_iso_endpoint_descriptor as_iso_in_desc = {
static struct usb_descriptor_header *f_audio_desc[] = {
(struct usb_descriptor_header *)&ac_interface_desc,
- (struct usb_descriptor_header *)&ac_header_desc,
+ NULL, /* ac_header_desc, set by setup_descriptor() */
(struct usb_descriptor_header *)&usb_out_it_desc,
(struct usb_descriptor_header *)&io_out_ot_desc,
- (struct usb_descriptor_header *)&out_feature_unit_desc,
+ NULL, /* out_feature_unit_desc, set by setup_descriptor() */
(struct usb_descriptor_header *)&io_in_it_desc,
(struct usb_descriptor_header *)&usb_in_ot_desc,
- (struct usb_descriptor_header *)&in_feature_unit_desc,
+ NULL, /* in_feature_unit_desc, set by setup_descriptor() */
(struct usb_descriptor_header *)&ac_int_ep_desc,
@@ -336,7 +330,7 @@ static struct usb_ss_ep_comp_descriptor ss_as_in_ep_desc_comp = {
static struct usb_descriptor_header *f_audio_ss_desc[] = {
(struct usb_descriptor_header *)&ac_interface_desc,
- (struct usb_descriptor_header *)&ac_header_desc,
+ NULL, /* ac_header_desc, set by setup_descriptor() */
(struct usb_descriptor_header *)&usb_out_it_desc,
(struct usb_descriptor_header *)&io_out_ot_desc,
@@ -1085,7 +1079,10 @@ uac1_ac_header_descriptor *build_ac_header_desc(struct f_uac1_opts *opts)
/* Use macro to overcome line length limitation */
#define USBDHDR(p) (struct usb_descriptor_header *)(p)
-static void setup_descriptor(struct f_uac1_opts *opts)
+static void setup_descriptor(struct f_uac1_opts *opts,
+ struct uac1_ac_header_descriptor *ac_header_desc,
+ struct uac_feature_unit_descriptor *in_feature_unit_desc,
+ struct uac_feature_unit_descriptor *out_feature_unit_desc)
{
/* patch descriptors */
int i = 1; /* ID's start with 1 */
@@ -1143,6 +1140,7 @@ static void setup_descriptor(struct f_uac1_opts *opts)
i = 0;
f_audio_desc[i++] = USBDHDR(&ac_interface_desc);
f_audio_desc[i++] = USBDHDR(ac_header_desc);
+ f_audio_ss_desc[1] = USBDHDR(ac_header_desc);
if (EPOUT_EN(opts)) {
f_audio_desc[i++] = USBDHDR(&usb_out_it_desc);
@@ -1241,6 +1239,9 @@ static int f_audio_bind(struct usb_configuration *c, struct usb_function *f)
struct f_uac1 *uac1 = func_to_uac1(f);
struct g_audio *audio = func_to_g_audio(f);
struct f_uac1_opts *audio_opts;
+ struct uac1_ac_header_descriptor *ac_header_desc;
+ struct uac_feature_unit_descriptor *in_feature_unit_desc = NULL;
+ struct uac_feature_unit_descriptor *out_feature_unit_desc = NULL;
struct usb_ep *ep = NULL;
struct usb_string *us;
int ba_iface_id;
@@ -1283,14 +1284,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;
}
}
@@ -1378,7 +1379,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;
@@ -1388,7 +1389,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;
@@ -1399,7 +1400,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;
@@ -1417,7 +1418,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;
@@ -1428,7 +1429,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;
@@ -1437,19 +1438,20 @@ 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;
}
- setup_descriptor(audio_opts);
+ setup_descriptor(audio_opts, ac_header_desc, in_feature_unit_desc,
+ out_feature_unit_desc);
/* copy descriptors, and track endpoint copies */
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);
@@ -1486,20 +1488,18 @@ 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;
-
- return 0;
+ usb_free_all_descriptors(f);
-err_card_register:
- usb_free_all_descriptors(f);
-err_free_fu:
+free_fu:
+ /*
+ * The feature unit and AC header descriptors are 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;
}
@@ -1825,16 +1825,6 @@ static void f_audio_unbind(struct usb_configuration *c, struct usb_function *f)
g_audio_cleanup(audio);
usb_free_all_descriptors(f);
- scoped_guard(mutex, &f_uac1_desc_mutex) {
- 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
^ permalink raw reply related [flat|nested] 9+ messages in thread* Re: [PATCH v2 6/6] usb: gadget: f_uac1: fix feature unit and AC header descriptor leak
2026-12-05 11:08 ` [PATCH v2 6/6] usb: gadget: f_uac1: fix feature unit and AC header descriptor leak Vineet Thakran
@ 2026-12-05 11:20 ` sashiko-bot
0 siblings, 0 replies; 9+ messages in thread
From: sashiko-bot @ 2026-12-05 11:20 UTC (permalink / raw)
To: Vineet Thakran; +Cc: linux-usb
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] usb: gadget: f_uac1: missing Fixes tag for commit b8fb6db6cb04
--
commit a85ccf2bbf11aaa9c0c1c9b9110fcce6fe4b8e2f
Author: Vineet Thakran <vineet789thakran@gmail.com>
> usb: gadget: f_uac1: fix feature unit and AC header descriptor leak
>
> 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 patches nothing uses them after f_audio_bind(). Make
> them local variables of f_audio_bind(), pass them to setup_descriptor(),
> free them on every exit path of f_audio_bind(), including success, and
> drop the now redundant kfree() calls from f_audio_unbind().
>
> The static f_audio_desc and f_audio_ss_desc arrays used to take the
> address of the file-scope pointers. Their entries become NULL
> placeholders, and setup_descriptor() now fills in the AC header entry of
> f_audio_ss_desc the same way it already does for f_audio_desc.
>
> 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>
[Severity: Low]
Since this also fixes f_audio_ss_desc[1] taking the address of the
ac_header_desc pointer instead of storing the allocated descriptor in
setup_descriptor(), should this include:
Fixes: b8fb6db6cb04 ("usb: f_uac1: adds support for SS and SSP")
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261205110831.204588-1-vineet789thakran@gmail.com?part=6
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2 0/6] usb: gadget: f_uac1/f_uac2: fix descriptor leaks, NULL deref and bind race with multiple instances
2026-12-05 11:08 [PATCH v2 0/6] usb: gadget: f_uac1/f_uac2: fix descriptor leaks, NULL deref and bind race with multiple instances Vineet Thakran
` (5 preceding siblings ...)
2026-12-05 11:08 ` [PATCH v2 6/6] usb: gadget: f_uac1: fix feature unit and AC header descriptor leak Vineet Thakran
@ 2026-12-05 11:24 ` sashiko-bot
6 siblings, 0 replies; 9+ messages in thread
From: sashiko-bot @ 2026-12-05 11:24 UTC (permalink / raw)
To: Vineet Thakran; +Cc: linux-usb
Sashiko has finished reviewing this 6-patch series:
- Patches 1-5: no issues found.
- Patch 6 ("usb: gadget: f_uac1: fix feature unit and AC header..."): 1
potential issue (1 Low)
A detailed review has been sent as a separate reply to patch 6.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261205110831.204588-1-vineet789thakran@gmail.com
^ permalink raw reply [flat|nested] 9+ messages in thread