* [PATCH v2] usb: gadget: u_audio: reject srate request for unconfigured direction
@ 2026-11-21 14:31 Deepanshu Kartikey
2026-11-21 14:42 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Deepanshu Kartikey @ 2026-11-21 14:31 UTC (permalink / raw)
To: gregkh
Cc: kees, pavel.hofman, linux-usb, linux-kernel, Deepanshu Kartikey,
syzbot+e1d0e66badecc32d45eb
u_audio_get_playback_srate() unconditionally locks and reads
uac->p_prm.lock/srate, but g_audio_setup() only initializes
p_prm.lock when p_chmask is set. On a UAC2 instance configured
without a playback direction, this results in acquiring a
never spin_lock_init()'d lock when a GET_CUR sample rate
request targets playback, triggering a lockdep "trying to
register non-static key" warning.
Reject the request with -EOPNOTSUPP when p_chmask is not set,
before touching prm->lock.
Fixes: eb3a1ce6f5ed ("usb: gadget: u_audio: Add capture/playback srate getter")
Reported-by: syzbot+e1d0e66badecc32d45eb@syzkaller.appspotmail.com
Closes: http://syzkaller.appspot.com/bug?extid=e1d0e66badecc32d45eb
Assisted-by: LLM
Signed-off-by: Deepanshu Kartikey <kartikey406@gmail.com>
---
v2: Add Assisted-by tag (requested by Greg KH)
---
drivers/usb/gadget/function/u_audio.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/usb/gadget/function/u_audio.c b/drivers/usb/gadget/function/u_audio.c
index e53f2927b539..ff811ea1e25a 100644
--- a/drivers/usb/gadget/function/u_audio.c
+++ b/drivers/usb/gadget/function/u_audio.c
@@ -575,6 +575,9 @@ int u_audio_get_playback_srate(struct g_audio *audio_dev, u32 *val)
struct uac_rtd_params *prm;
unsigned long flags;
+ if (!audio_dev->params.p_chmask)
+ return -EOPNOTSUPP;
+
prm = &uac->p_prm;
spin_lock_irqsave(&prm->lock, flags);
*val = prm->srate;
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v2] usb: gadget: u_audio: reject srate request for unconfigured direction
2026-11-21 14:31 [PATCH v2] usb: gadget: u_audio: reject srate request for unconfigured direction Deepanshu Kartikey
@ 2026-11-21 14:42 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-21 14:42 UTC (permalink / raw)
To: Deepanshu Kartikey; +Cc: linux-usb
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] usb: gadget: u_audio: uninitialized stack leak via
u_audio_get_playback_srate()
--
commit d6b92cacc40344244658dfaa12df4f37045d7cc1
Author: Deepanshu Kartikey <kartikey406@gmail.com>
usb: gadget: u_audio: reject srate request for unconfigured direction
This commit returns -EOPNOTSUPP from u_audio_get_playback_srate() when
p_chmask is not set, avoiding an uninitialized spinlock acquisition on
uac->p_prm.lock.
> diff --git a/drivers/usb/gadget/function/u_audio.c b/drivers/usb/gadget/function/u_audio.c
> index 83019d359c8d1..79e3f4fdde6fb 100644
> --- a/drivers/usb/gadget/function/u_audio.c
> +++ b/drivers/usb/gadget/function/u_audio.c
> @@ -582,6 +582,9 @@ int u_audio_get_playback_srate(struct g_audio *audio_dev, u32 *val)
> struct uac_rtd_params *prm;
> unsigned long flags;
>
> + if (!audio_dev->params.p_chmask)
> + return -EOPNOTSUPP;
> +
> prm = &uac->p_prm;
> spin_lock_irqsave(&prm->lock, flags);
> *val = prm->srate;
[Severity: High]
Does returning -EOPNOTSUPP here without writing *val leak uninitialized
stack memory to the USB host?
The caller in_rq_cur() passes an uninitialized stack variable p_srate and
ignores the return value:
drivers/usb/gadget/function/f_uac2.c:in_rq_cur() {
...
u32 p_srate, c_srate;
u_audio_get_playback_srate(agdev, &p_srate);
u_audio_get_capture_srate(agdev, &c_srate);
if (control_selector == UAC2_CS_CONTROL_SAM_FREQ) {
struct cntrl_cur_lay3 c;
memset(&c, 0, sizeof(struct cntrl_cur_lay3));
if (entity_id == USB_IN_CLK_ID)
c.dCUR = cpu_to_le32(p_srate);
...
value = min_t(unsigned int, w_length, sizeof(c));
memcpy(req->buf, &c, value);
}
...
}
Previously, u_audio_get_playback_srate() set *val to prm->srate (0 from
kzalloc). With this early return, a UAC2_CS_CUR request for
UAC2_CS_CONTROL_SAM_FREQ targeting USB_IN_CLK_ID on a capture-only gadget
is not rejected; instead, in_rq_cur() copies the uninitialized p_srate into
req->buf and sends 4 bytes of kernel stack memory to the host.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261121143142.17721-1-kartikey406@gmail.com?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-21 14:42 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-21 14:31 [PATCH v2] usb: gadget: u_audio: reject srate request for unconfigured direction Deepanshu Kartikey
2026-11-21 14:42 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox