From: Takashi Iwai <tiwai@suse.de>
To: Daisuke Yamane <yamane07ynct@gmail.com>
Cc: sashiko-reviews@lists.linux.dev, linux-sound@vger.kernel.org,
Takashi Iwai <tiwai@suse.com>, Jaroslav Kysela <perex@perex.cz>
Subject: Re: [PATCH] ALSA: usb-audio: Skip packet header in Yamaha ZG02 capture stream
Date: Fri, 04 Dec 2026 17:08:26 +0100 [thread overview]
Message-ID: <871p7xt4ed.wl-tiwai@suse.de> (raw)
In-Reply-To: <CAHZ3=rqmYyCu7uT3dxiE2jKZHUrebL6h6Qni=Lchzn-Rp50cOg@mail.gmail.com>
On Fri, 04 Dec 2026 15:04:31 +0100,
Daisuke Yamane wrote:
>
> 2026年12月4日(金) 22:52 <sashiko-bot@kernel.org>:
> >
> > Thank you for your contribution! Sashiko AI review found 1 potential
> > issue to consider:
> > - [Medium] ALSA: usb-audio: OOB read in retire_capture_urb() with
> > pkt_offset_adj
> > --
> >
> > commit 4f42e1ac4fec821d619625b40ff2e9b8d0f517f2
> > Author: Daisuke Yamane <yamane07ynct@gmail.com>
> >
> > ALSA: usb-audio: Skip packet header in Yamaha ZG02 capture stream
> >
> > This commit adds snd_usb_set_pkt_offset_quirk() and calls it on every
> > snd_usb_pcm_prepare() to set subs->pkt_offset_adj = 8 for Yamaha ZG02
> > capture streams, skipping the 8-byte header at the start of each
> > isochronous packet.
> >
> > > diff --git a/sound/usb/quirks.c b/sound/usb/quirks.c
> > > index 0694c02558fea..ab149b22778fb 100644
> > > --- a/sound/usb/quirks.c
> > > +++ b/sound/usb/quirks.c
> > > @@ -2138,6 +2138,23 @@ void snd_usb_set_format_quirk(struct snd_usb_substream *subs,
> > > }
> > > }
> > >
> > > +/*
> > > + * Called on every prepare. snd_usb_set_format_quirk() runs only when the
> > > + * data endpoint is newly prepared, which is not the case for a capture
> > > + * endpoint that a running playback stream already prepared as its
> > > + * implicit feedback source.
> > > + */
> > > +void snd_usb_set_pkt_offset_quirk(struct snd_usb_substream *subs)
> > > +{
> > > + switch (subs->stream->chip->usb_id) {
> > > + case USB_ID(0x0499, 0x1516): /* Yamaha ZG02 */
> > > + /* capture packets: [u32 seq][u32 len] frames [u32 seq] */
> > > + if (subs->direction == SNDRV_PCM_STREAM_CAPTURE)
> > > + subs->pkt_offset_adj = 8;
> > > + break;
> > > + }
> > > +}
> >
> > [Severity: Medium]
> > Can setting subs->pkt_offset_adj = 8 cause an out-of-bounds read past
> > urb->transfer_buffer in retire_capture_urb()?
> >
> > retire_capture_urb() advances cp by subs->pkt_offset_adj, but unlike
> > subs->stream_offset_adj, it never checks that bytes >= subs->pkt_offset_adj
> > or subtracts subs->pkt_offset_adj from bytes before computing frames and
> > copying into runtime->dma_area:
> >
> > sound/usb/pcm.c:retire_capture_urb() {
> > ...
> > cp = (unsigned char *)urb->transfer_buffer + urb->iso_frame_desc[i].offset + subs->pkt_offset_adj;
> > ...
> > bytes = urb->iso_frame_desc[i].actual_length;
> > if (unlikely(bytes > urb->iso_frame_desc[i].length)) {
> > ...
> > continue;
> > }
> > ...
> > frames = bytes / stride;
> > if (!subs->txfr_quirk)
> > bytes = frames * stride;
> > ...
> > memcpy(runtime->dma_area + oldptr, cp, bytes);
> > }
> >
> > data_ep_set_params() allocates urb->transfer_buffer to maxsize * u->packets
> > with no trailing padding, and prepare_inbound_urb() packs the packets
> > back-to-back.
> >
> > On the last packet, a full-length transfer where (actual_length / stride) *
> > stride + 8 > length (such as 144 bytes with stride 16) causes memcpy() to
> > read up to 8 bytes past urb->transfer_buffer, which can fault or copy
> > adjacent memory into runtime->dma_area.
>
> This cannot happen with the ZG02 itself. Its capture endpoint (EP 0x81)
> has wMaxPacketSize 124, which is below the 144 bytes that
> data_ep_set_params() computes from freqmax, so each packet slot is 124
> bytes. The largest copy is then 124 / 16 * 16 = 112 bytes starting at
> offset 8, ending at byte 120 of the slot, and longer packets are
> dropped by the actual_length > length check.
In the case of a USB device, a malformed device descriptor can be
passed easily. That is, you cannot assume such a safety just
depending on the device ID in general, unfortunately.
thanks,
Takashi
prev parent reply other threads:[~2026-12-04 16:08 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 13:34 [PATCH] ALSA: usb-audio: Skip packet header in Yamaha ZG02 capture stream Daisuke Yamane
2026-12-04 13:52 ` sashiko-bot
2026-12-04 14:04 ` Daisuke Yamane
2026-12-04 16:08 ` Takashi Iwai [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=871p7xt4ed.wl-tiwai@suse.de \
--to=tiwai@suse.de \
--cc=linux-sound@vger.kernel.org \
--cc=perex@perex.cz \
--cc=sashiko-reviews@lists.linux.dev \
--cc=tiwai@suse.com \
--cc=yamane07ynct@gmail.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.