From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.216.47 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796035799; b=beyQBa/71rvH0VIMBZBKJV1VHtOQupdoM5vn/1Sj8HRKim3t2ya1T1XXkdFEbYMvyNew WNDb9CB3vjoZynd0s+HnH7CHv6DjiBTOxYUb3S7RVJ5QgMx63M4jXaRkzQtmUVVkc5Bqg gMZmlFpYsBV3cimR5l7I1imptlaNr6rUsXlTMDNFD4EkNBPX/LuP5zLMGfkDwsiNZSPhv MN78zeQq1fX6KHLqLePuXvCPZtuC9ppnrBwkUffUD+659wekIE+Wd3C6OHTU+sI4ZRbh5 UI/LIsXxtsFYWSGbLNR1zDWQgwBQVgrdN5IIkQpe2AqyfkSeHyaqAIFRwIGYJkXfacg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796035799; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-Id:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=Y66sTZ5fYXCqFNOMhsFL1rNWr361zXQCTxwroCs524E=; b=pEC66gcp4TN3i3NkLjJ2T0xt23vkHU73jFy6LsX5J0fb+vOTmJVT4J/4nXZlrpVI2p+1 lQOGHOWQ+sOTAW0H/WHXq+P3wCHjT+pmHqNYt/B6kQxnPqV3p5SzZzwfNvpgz6u9qZpzn 8/ZO6HzSyciRL6lYL0lxWuHyKaH/wRETwiAwJdRfNb4W+s/6kGLfDrIH5t0VPYQuFocY6 u9Nfy5iTSzVLoBl31MEygl26ngwIIvyLbK7ZYcBajT1Wl5UJ4hZCjktJZBJEmM2igdAfg NE/U9UfeivIy3VFoh5QIsem4u+6uhlBOYt1ExrcT4FNSW6jpHw8tj/xdEfQ2yPtt1hQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=tcWbkQ6j; arc=none smtp.remote-ip=209.85.216.47 Received: from mail-pj1-f47.google.com (mail-pj1-f47.google.com [209.85.216.47]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3C9F5606A325 for ; Mon, 30 Nov 2026 10:49:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 3C9F5606A325 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=tcWbkQ6j Received: by mail-pj1-f47.google.com with SMTP id 98e67ed59e1d1-3b51a9606e8so2543888a91.3 for ; Mon, 30 Nov 2026 02:49:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796035798; x=1796640598; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=Y66sTZ5fYXCqFNOMhsFL1rNWr361zXQCTxwroCs524E=; b=tcWbkQ6jQa8jON04e8jYgGYJ56n+7Ft4dac4dGvFCp+EOWZJfExg4dBWnMmxuTNPh6 C47YixpZbDM26239JcACNuzGAyOXNPdL1uiK2h2/1hj9Q5JxVY+fGKjHE/2bsoyeIyxr 80NW3564UstsTGdDAdxtDdYmrp7d14JJfBxX149dVJYSTa/t9Y7Y+mDt3Ks0lf+vBGlS d9SOoQMu2lHzFE1LmAKUOCAfuFsXn0yk/H7R82ngvsjjMPPO2z6O2nAEZ7rEB+KFO5b7 qKT1whCpW9Mrhn7jiXTp6NqH5yIYizvsOyX0AHHc5aXN9rcWOxTH8KrgxIgzyIjwUtAn n5Dg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796035798; x=1796640598; h=content-transfer-encoding:mime-version:references:in-reply-to :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=Y66sTZ5fYXCqFNOMhsFL1rNWr361zXQCTxwroCs524E=; b=MHNQxvh38cqcdKyG02c13qsyUK073fkid7XI3W9Onf63o001AtqOvkEAw4o6bEuscl b1PHTbkToUvlpQ+uEAJI1CNP8BU3ZBypycn3NKoxEoL6snJWZWCeVbedd2NR+We/HrDe s59gT+FZZEAeHlEcRatobEKUTVMBlj9cDtODEO208Pwa2YY9ncOPZHsxGfTb37YQNu58 haludQuV1hPT8fiSCSfbDvSdlwQWJMshbOVgNeZvbuGUiwvEjJnLVFEVnxpV57Mxu/lk O9XlME1uH5jkd66QGZYIDSmt3jJ0ZLtGRbWhXEg4huFOjff3+dpX8wcgbYtUsWSZCQ9A eH7g== X-Forwarded-Encrypted: i=1; AL+hErF9kE0/dbmjy9rQ6tjiEXyT84Pti3QAIMuGXF2ln+qSDVE4eTqWd/APfu1xFeYze1hBDc/O5I8=@vger.kernel.org X-Gm-Message-State: APuU4Z+IfzJtU8PA3DVcXJW+5qHcUCtwD7O4PwM5JA+wYq+Shq4Zv24s o+vsvMkrU0NGQ4MWhhYPQTs9tAIawNYrSG34l9AP93jSkdm7aGlyEVAX X-Gm-Gg: AZFdTZdzCzWdAY9uL6/3Zjq2tmcuPgpEYTrGJWhAV6p0xEVQqscDyABfnQwApKThRyW aDMvSmAsHHy8lehMxxE6Fub3m+dyRa4r4vcqv1kUTKw0wJRUMIXOcE+1yuUor2pqff3W/ql0Y50 bgHuTrAGQwE/mgmhwsJDvbAE/qQn9PA5cmGhIAGN2cVcSOWa65IeKeSfQlwa+AfZbDLorAXfQDt fgNh1hjke7m/tI/zMVbmnRGRmpGp9l3bvisyKiK2Dyc1/lCHnYBSRYsUk2BZtibdUNbKEmp+AsX ODrhxFTG4wh7Y9RiX5hcHxDyCWbDHXP2O4P7Y+9I92ELvG3dhq0SUQQIdE0JbnH2lLwLlt+yRsi PB/iBE8ue8Pi4KK5XbkEmX9nUGAanbeXU3frQCQDYFBk8grXCF7HMqhCT7D8TWF2kSYNMqKVaIE Ykxe1Wb9P3PU1V0BELyQqQcKEvAJr9xS8IPxTqyvGdf9Zk2c0q+AOJlyZjySwDLw2s3hRfcD1DY v38MLdhgaGLNE3g5u1qzdzN8FHtD6dDFLBO8YfsYdpdTpH+fuvDPa7JPHL03e2TaNHd4f+26R9O OPefzgnne1RC2w19lok1XdLpUj5QXsawMkbf2yF/fWODrF0DRnY4BpTgHhuyaX6KkPrfD7S+VnI = X-Received: by 2002:a17:90b:4a88:b0:3b5:29e:11ac with SMTP id 98e67ed59e1d1-3b5029e1483mr16882271a91.37.1796035798539; Mon, 30 Nov 2026 02:49:58 -0800 (PST) Received: from csl-conti-dell7858.ntu.edu.sg ([155.69.195.57]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3b41ad46ef5sm52391623a91.8.2026.11.30.02.49.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 02:49:56 -0800 (PST) From: Maoyi Xie To: Clemens Ladisch , Takashi Sakamoto Cc: Jaroslav Kysela , Takashi Iwai , linux-sound@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH v2 1/3] ALSA: bebob: bound the channel position walk to the response length Date: Mon, 30 Nov 2026 18:49:47 +0800 Message-Id: <20261130104949.2216908-2-maoyixie.tju@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261130104949.2216908-1-maoyixie.tju@gmail.com> References: <20261130104949.2216908-1-maoyixie.tju@gmail.com> X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit map_data_channels() walks the channel position response by the section and channel counts in that response. Nothing checks the counts against the length of the response. A section of 128 channels can read past the 256-byte buffer. Take the length of the data from avc_bridgeco_get_plug_ch_pos(). Return -EIO for a section that does not fit. Found with a CodeQL-based static analysis tool. Reproduced in a userspace harness under AddressSanitizer. Not tested on hardware. Fixes: eb7b3a056cd8 ("ALSA: bebob: Add commands and connections/streams management") Cc: stable@vger.kernel.org Signed-off-by: Maoyi Xie --- I used an LLM to help write the harness and this patch. v2: No change. sound/firewire/bebob/bebob.h | 2 +- sound/firewire/bebob/bebob_command.c | 5 +++-- sound/firewire/bebob/bebob_stream.c | 11 +++++++++-- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/sound/firewire/bebob/bebob.h b/sound/firewire/bebob/bebob.h index 41e019b9e24e..7891a5802f1a 100644 --- a/sound/firewire/bebob/bebob.h +++ b/sound/firewire/bebob/bebob.h @@ -194,7 +194,7 @@ avc_bridgeco_fill_msu_addr(u8 buf[AVC_BRIDGECO_ADDR_BYTES], } int avc_bridgeco_get_plug_ch_pos(struct fw_unit *unit, u8 addr[AVC_BRIDGECO_ADDR_BYTES], - u8 *buf, unsigned int len); + u8 *buf, unsigned int *len); int avc_bridgeco_get_plug_type(struct fw_unit *unit, u8 addr[AVC_BRIDGECO_ADDR_BYTES], enum avc_bridgeco_plug_type *type); diff --git a/sound/firewire/bebob/bebob_command.c b/sound/firewire/bebob/bebob_command.c index 022df09c68ff..2e5a43e24615 100644 --- a/sound/firewire/bebob/bebob_command.c +++ b/sound/firewire/bebob/bebob_command.c @@ -181,14 +181,14 @@ end: int avc_bridgeco_get_plug_ch_pos(struct fw_unit *unit, u8 addr[AVC_BRIDGECO_ADDR_BYTES], - u8 *buf, unsigned int len) + u8 *buf, unsigned int *len) { int err; /* Info type is 'channel position'. */ avc_bridgeco_fill_plug_info_extension_command(buf, addr, 0x03); - err = fcp_avc_transaction(unit, buf, 12, buf, 256, + err = fcp_avc_transaction(unit, buf, 12, buf, *len, BIT(1) | BIT(2) | BIT(3) | BIT(4) | BIT(5) | BIT(6) | BIT(7) | BIT(9)); if (err < 0) @@ -206,6 +206,7 @@ int avc_bridgeco_get_plug_ch_pos(struct fw_unit *unit, /* Pick up specific data. */ memmove(buf, buf + 10, err - 10); + *len = err - 10; err = 0; end: return err; diff --git a/sound/firewire/bebob/bebob_stream.c b/sound/firewire/bebob/bebob_stream.c index 449cb17717f0..5850357cb3da 100644 --- a/sound/firewire/bebob/bebob_stream.c +++ b/sound/firewire/bebob/bebob_stream.c @@ -255,7 +255,7 @@ static int map_data_channels(struct snd_bebob *bebob, struct amdtp_stream *s) { unsigned int sec, sections, ch, channels; unsigned int pcm, midi, location; - unsigned int stm_pos, sec_loc, pos; + unsigned int stm_pos, sec_loc, pos, len; u8 *buf, addr[AVC_BRIDGECO_ADDR_BYTES], type; enum avc_bridgeco_plug_dir dir; int err; @@ -274,7 +274,8 @@ static int map_data_channels(struct snd_bebob *bebob, struct amdtp_stream *s) dir = AVC_BRIDGECO_PLUG_DIR_IN; avc_bridgeco_fill_unit_addr(addr, dir, AVC_BRIDGECO_PLUG_UNIT_ISOC, 0); - err = avc_bridgeco_get_plug_ch_pos(bebob->unit, addr, buf, 256); + len = 256; + err = avc_bridgeco_get_plug_ch_pos(bebob->unit, addr, buf, &len); if (err < 0) { dev_err(&bebob->unit->device, "fail to get channel position for isoc %s plug 0: %d\n", @@ -311,6 +312,12 @@ static int map_data_channels(struct snd_bebob *bebob, struct amdtp_stream *s) goto end; } + /* this section should be within the response */ + if (pos >= len || pos + 1 + buf[pos] * 2 > len) { + err = -EIO; + goto end; + } + /* the number of channels in this section */ channels = buf[pos++]; -- 2.34.1