From: sashiko-bot@kernel.org
To: "Deepanshu Kartikey" <kartikey406@gmail.com>
Cc: linux-usb@vger.kernel.org
Subject: Re: [PATCH v2] usb: gadget: u_audio: reject srate request for unconfigured direction
Date: Sat, 21 Nov 2026 14:42:04 +0000 [thread overview]
Message-ID: <sashiko-outbox-227102@kernel.org> (raw)
In-Reply-To: <20261121143142.17721-1-kartikey406@gmail.com>
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
prev parent reply other threads:[~2026-11-21 14:42 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
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 message]
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=sashiko-outbox-227102@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=kartikey406@gmail.com \
--cc=linux-usb@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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