From: kaf@nwlink.com
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Neill Kapron <nkapron@google.com>, linux-usb@vger.kernel.org
Subject: Re: [PATCH] usb: gadget: u_audio: don't exceed maxpacket when adding a residue frame
Date: Mon, 16 Nov 2026 13:01:53 -0800 [thread overview]
Message-ID: <db18fcc4f778afbf515fed81a4a13488@nwlink.com> (raw)
In-Reply-To: <20261026231026.721536-1-kaf@nwlink.com>
On 2026-10-26 16:10, Kyle Farrell wrote:
> u_audio_iso_complete() clamps the base packet size to ep->maxpacket
> and accumulates fractional-frame residue in p_residue_mil. Once a
> whole frame has accumulated, it is appended to the packet without
> checking whether it fits within ep->maxpacket.
>
> Only append the extra frame if it fits. Consume the accumulated
> residue whether or not the frame is sent, preventing it from growing
> when the additional frame cannot fit. When the frame fits, behavior
> is unchanged. Otherwise, the stream cannot sustain the requested
> sample rate.
>
> For example, with 27 channels of 32-bit samples at 19200 Hz on a
> high-speed link with p_hs_bint=3, the required packet size of 1080
> bytes is capped at 1024. The base packet is 972 bytes, but appending
> a residue frame increases it to 1080 bytes, exceeding the allocated
> request buffer by 56 bytes.
>
> Fixes: 9bb87f168931 ("usb: gadget: f_uac2: send reasonably sized
> packets")
> Link:
> https://lore.kernel.org/linux-usb/sashiko-outbox-174688@kernel.org/
> Signed-off-by: Kyle Farrell <kaf@nwlink.com>
> ---
> drivers/usb/gadget/function/u_audio.c | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/usb/gadget/function/u_audio.c
> b/drivers/usb/gadget/function/u_audio.c
> index f0ee83abcebc..f73d1085c1d1 100644
> --- a/drivers/usb/gadget/function/u_audio.c
> +++ b/drivers/usb/gadget/function/u_audio.c
> @@ -230,9 +230,13 @@ static void u_audio_iso_complete(struct usb_ep
> *ep, struct usb_request *req)
> do_div(div_result, uac->p_interval);
> do_div(div_result, 1000000);
> if ((unsigned int) div_result >= uac->p_framesize) {
> - req->length += uac->p_framesize;
> + /* req->length is bounded by ep->maxpacket above. */
> + if (uac->p_framesize <= ep->maxpacket - req->length) {
> + req->length += uac->p_framesize;
> + pr_debug("increased req length to %d\n", req->length);
> + }
> +
> uac->p_residue_mil -= uac->p_framesize * p_interval_mil;
> - pr_debug("increased req length to %d\n", req->length);
> }
> pr_debug("remains uac->p_residue_mil %llu\n", uac->p_residue_mil);
>
>
> base-commit: bdf12cde30830d46a8ef1ba93986356f1164b4f1
This patch also is suitable for stable backporting, as it fixes a
potential out-of-bounds write in existing configurations. Please add
the following trailer when applying:
Cc: stable@vger.kernel.org
Thanks,
Kyle Farrell
next prev parent reply other threads:[~2026-11-16 21:01 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-26 23:10 [PATCH] usb: gadget: u_audio: don't exceed maxpacket when adding a residue frame Kyle Farrell
2026-10-26 23:15 ` sashiko-bot
2026-11-16 21:01 ` kaf [this message]
2026-11-16 22:31 ` Neill Kapron
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=db18fcc4f778afbf515fed81a4a13488@nwlink.com \
--to=kaf@nwlink.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-usb@vger.kernel.org \
--cc=nkapron@google.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.