All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Daisuke Yamane" <yamane07ynct@gmail.com>
Cc: linux-sound@vger.kernel.org
Subject: Re: [PATCH] ALSA: usb-audio: Skip packet header in Yamaha ZG02 capture stream
Date: Fri, 04 Dec 2026 13:52:51 +0000	[thread overview]
Message-ID: <sashiko-outbox-249903@kernel.org> (raw)
In-Reply-To: <20261204133429.247377-1-yamane07ynct@gmail.com>

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.

Dropping packets with bytes <= subs->pkt_offset_adj and subtracting
subs->pkt_offset_adj from bytes before computing frames in
retire_capture_urb() would prevent the over-read while keeping ZG02 frame
counts unchanged ((108 - 8) / 16 = 6, (124 - 8) / 16 = 7).

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204133429.247377-1-yamane07ynct@gmail.com?part=1

  reply	other threads:[~2026-12-04 13:52 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 [this message]
2026-12-04 14:04   ` Daisuke Yamane
2026-12-04 16:08     ` Takashi Iwai

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-249903@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --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.