From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f52.google.com (mail-pj1-f52.google.com [209.85.216.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1C7AA261B70 for ; Wed, 5 Aug 2026 01:34:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.52 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785893687; cv=none; b=S8jakfG44nnUsYnohA29j0uKcMA8GdddCa5H1SKSjnSQBXuBECqlU9Mn+ee/0B2Od6xlEdNMiwptH1xbaNxHa9Dvx4mIffbrzkAwBiBWny8ncousfwHhC3mEks+sAPNMGw85WBnwmgmIjwaADvIdTiB4OOBIT7cyMwL/hq38S94= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785893687; c=relaxed/simple; bh=6ggo468VqCJiBEAW/CY4gRyFscERZZi0d+FSNRqo7fM=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=sjAVjmt4BY/fixB7OODOp5cZvGDRS+hDMg1MQ0YLL/LTmJkSGHfmY5b0x+JLwJ/B/eYbsXcHvuw1/YOo52U+m3SJvxsV9dG8mnImPFa7CdmYAk5Kfl72TTidmboeKj7pvBJ4NiZLtbBFGbI375URzhVmxWAJGTQ+aGG6mGYA1V4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=xbow.com; spf=pass smtp.mailfrom=xbow.com; dkim=pass (2048-bit key) header.d=xbow.com header.i=@xbow.com header.b=f5IG8uNz; arc=none smtp.client-ip=209.85.216.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=xbow.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xbow.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=xbow.com header.i=@xbow.com header.b="f5IG8uNz" Received: by mail-pj1-f52.google.com with SMTP id 98e67ed59e1d1-3856d6fbcb3so320717a91.2 for ; Tue, 04 Aug 2026 18:34:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xbow.com; s=google; t=1785893685; x=1786498485; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=4cYrPAdGr78t7YkoLwcMiDz4Rg7VzdKjNoh6ElfleWU=; b=f5IG8uNzFilA+bx40PllHgen6xCmvCxpPtA5YGpIpz0e/ltOqlvTkHxL2IO35l0Gwb ICLo0tlLQ0zJEuiliXsoX9dYAChX9rZDREoueg/RBIGkanujl+uKZrC3wXVwbrDKv/Ua oUpeMJF5dwLHmyc8cbHyenvtqBv+7viuTB2UCqy++MzV7H70CHMD6d7CGngZ8N8fmIHU f2PoOWaxVfbwOmklUTxI24901jJp0Y7VKAR/sK2sP5CN4N4zeHPu7Jzak2E+ISJW2AJD HudQPn7ALTxL//rdvXHIeLMcTQDz7F6G5qTOhcXxthZigqla24PMVMaK0NYsD2b/AE7t zafw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785893685; x=1786498485; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=4cYrPAdGr78t7YkoLwcMiDz4Rg7VzdKjNoh6ElfleWU=; b=W2iP/mkuyXIa+kpZ+a/g7rrWA3D9ar9gVkyoTbKQFDTdyqLwt7qVr/mkyQ4A1goLVe H8fZkABoEJ9HIC3pUwOknjoDOWcrUfRcUR9c/n7lefP35cKSGD7IG0+Y72Vzz07N27V7 MCgvws+EJATyCbrAzqtKc6cPuCRovm0iuqtx6lv9TsuygdY/eMWFNKnAnaCaQGzRdHbP L9xI0bpOH/1oyTY33F0Ajd9eWSgEUJgsZr34nL4Tm4F0Zo670y+vG80/NwuH28REd8MR 4sMW2F26uuow8WRl5GYM/xP43q2K179DoyKcxyr1498kZuCM2ICBhrXPQz8PXueJiyws reew== X-Forwarded-Encrypted: i=1; AHgh+RrK+hlTvzbiWtFUTFuVdNtvKyeB4bJMFge0yywrqAUfrWhpN/GnzkEi5LeuuGFMIiOT+Z0uH7zuPacp/f4=@vger.kernel.org X-Gm-Message-State: AOJu0YxuIKWPQG59X2FybkuFAnS4GIf3/1QkgI/K7rrXYOLpORA+Glu/ rBp/Is6rPKglbFPMlyQJGEaYf4tRt9k702sHrJi/hS5mbQn1C5b7D8QTocAguXJOmMo= X-Gm-Gg: AR+sD12zMKLCQajFOE3X5t//Va9mzQ074WzkWS2EM6T+ZJHYkNJa31BiNusIJHC3amo GzMHBFrjeVueumVOlxm9jAXH5AmjGrUexXUS3evEM/VVP7frVyqITVsExX8PbDUL8ltfFnhGl6j dqQmp2LCi0q+Z7JYT0SxCZq2nxFuwDI7VM5O0z5hghhxbvFbvm2llf+ftqM2D8mlBoO+OMz/l1S vjNL1zSAvsxvbUum+yvz9TMVsS676tVLdbzHFBqizLmpeHdc0k6Cy6ivaNhAF+WE1hjRmkaOWub C7PnK0LZP1VJi0/CW8EbgVFHBNqUQDBjJ3eBwfy+50Iw6M6O0VuSOAJlVYkOXCL0Bg1JdKY7cTs tGcCD6ig0vaLyQs3K0oG+w6uGU7NB5PKrxUj6xNVekyKDkNT5DVSU/zlmMeaGTetH6KWQGQe34b hDLB6SINSJAooCVj3FPs/rVHOJMoIZyQ2ejk8vumzaMqYj5aFSya2dMAPv4VjdiPngYFkCoRjCS tg+CdsRNS29qqxi9T/8VZ9BjZTvE/uoCN83LtM= X-Received: by 2002:a17:90b:5823:b0:38e:485c:ebd3 with SMTP id 98e67ed59e1d1-3903c5b727cmr3065888a91.15.1785893685187; Tue, 04 Aug 2026 18:34:45 -0700 (PDT) Received: from Mac.lan ([125.128.148.126]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3903d2f9807sm545246a91.1.2026.08.04.18.34.43 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 04 Aug 2026 18:34:44 -0700 (PDT) From: Baul Lee To: perex@perex.cz, tiwai@suse.com Cc: linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org, federico.kirschbaum@xbow.com, stable@vger.kernel.org, Baul Lee Subject: [PATCH] ALSA: usb-audio: fix OOB write on Type II inbound URBs Date: Wed, 5 Aug 2026 10:34:41 +0900 Message-ID: <20260805013441.38245-1-baul.lee@xbow.com> X-Mailer: git-send-email 2.50.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit data_ep_set_params() sizes each URB transfer buffer before it adds the Format Type II transfer delimiter: u->packets = urb_packs; u->buffer_size = maxsize * u->packets; if (fmt->fmt_type == UAC_FORMAT_TYPE_II) u->packets++; /* for transfer delimiter */ u->urb = usb_alloc_urb(u->packets, GFP_KERNEL); buffer_size is computed from the pre-increment packet count and never recomputed, so for a Type II endpoint the buffer is one packet short of the packet count the URB is built with. prepare_inbound_urb() then lays out one iso frame per packet and never consults buffer_size: offs = 0; for (i = 0; i < urb_ctx->packets; i++) { urb->iso_frame_desc[i].offset = offs; urb->iso_frame_desc[i].length = ep->curpacksize; offs += ep->curpacksize; } urb->transfer_buffer_length = offs; urb->number_of_packets = urb_ctx->packets; The last descriptor therefore points one packet past the end of the transfer buffer, where the host controller writes device data on every inbound transfer. prepare_silent_urb() and prepare_playback_urb() bound their fill loops by ctx->buffer_size, so only capture is affected. fmt_type comes from the device's audio streaming descriptors, so any device advertising a Type II capture format hits this once userspace sets hw_params on the stream. KASAN on 7.2.0-rc5 (arm64) with a dummy_hcd/raw-gadget device, one report per inbound transfer: BUG: KASAN: slab-out-of-bounds in dummy_timer Write of size 64 at addr ffff0000186171c0 by task cons02/166 __asan_memcpy dummy_timer hrtimer_run_softirq Allocated by task 166: usb_alloc_coherent snd_usb_endpoint_set_params The buggy address is located 0 bytes to the right of allocated 64-byte region [ffff000018617180, ffff0000186171c0) Compute buffer_size after the delimiter packet has been accounted for, and bound the fill loop by buffer_size, as prepare_silent_urb() already does on the outbound side. This grows every Type II URB allocation by one maxsize packet. Discovered by XBOW, triaged by Baul Lee Fixes: 8fdff6a319e7 ("ALSA: snd-usb: implement new endpoint streaming model") Reported-by: Federico Kirschbaum Reported-by: Baul Lee Cc: stable@vger.kernel.org Signed-off-by: Baul Lee --- sound/usb/endpoint.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sound/usb/endpoint.c b/sound/usb/endpoint.c index dca06ba1c67e..a1d449f2a342 100644 --- a/sound/usb/endpoint.c +++ b/sound/usb/endpoint.c @@ -385,13 +385,15 @@ static int prepare_inbound_urb(struct snd_usb_endpoint *ep, case SND_USB_ENDPOINT_TYPE_DATA: offs = 0; for (i = 0; i < urb_ctx->packets; i++) { + if (offs + ep->curpacksize > urb_ctx->buffer_size) + break; urb->iso_frame_desc[i].offset = offs; urb->iso_frame_desc[i].length = ep->curpacksize; offs += ep->curpacksize; } urb->transfer_buffer_length = offs; - urb->number_of_packets = urb_ctx->packets; + urb->number_of_packets = i; break; case SND_USB_ENDPOINT_TYPE_SYNC: @@ -1243,10 +1245,10 @@ static int data_ep_set_params(struct snd_usb_endpoint *ep) u->index = i; u->ep = ep; u->packets = urb_packs; - u->buffer_size = maxsize * u->packets; if (fmt->fmt_type == UAC_FORMAT_TYPE_II) u->packets++; /* for transfer delimiter */ + u->buffer_size = maxsize * u->packets; u->urb = usb_alloc_urb(u->packets, GFP_KERNEL); if (!u->urb) goto out_of_memory; -- 2.50.1 (Apple Git-155)