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 3/4] usb: gadget: f_uac1: use per-instance feature unit IDs in control requests
Date: Thu, 3 Dec 2026 19:32:16 +0000 [thread overview]
Message-ID: <20261203193217.465889-4-vineet789thakran@gmail.com> (raw)
In-Reply-To: <20261203193217.465889-1-vineet789thakran@gmail.com>
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 at virtual address 0000000000000003
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 the following patch 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
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 ` Vineet Thakran [this message]
2026-12-03 19:32 ` [PATCH 4/4] usb: gadget: f_uac1: fix feature unit and AC header " Vineet Thakran
2026-12-03 19:52 ` 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-4-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