From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.216.51 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796035799; b=ZojvNjVlCVRfMi5/mcanLCu2pAhYlX35pg7XJYtgbImNi0i3uPdqkC/QXA0ku8wQiLt4 OOoNIoYg2/INKoPCdf1uS8rWRyDN+07WPQ/aFhYKI8X5NeHO0DUEvBrdp92w9+Eb8vqd1 gxPnNNALORmerFe2sV7Fxxw2CRpQ0L6dNn99kEshy7gF1yHdvYh/uGBfy0Vm/TJ7feX+Y xzH3cd1+seb0UmQ0oWenW/Xba5Qou8iJ+cIzVcp2vQFyNxbSuvcrtx4gNE4cD/4XqwNcd H5dBu8OEIbVQxmLE6wzQsCxek5cVuCm4VbeavpqnLTx1Lxg6AXDif50GDYBoFeLCkew== 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=dEyB0ngCzQzLZ7Jxnzvqo3HsbgaN+KQRzw0wfV9Y3SJjIH0McDLhlXlP8/BEyMOAthjb FzoHjlcaIYCiy5Wno4GuVSmm/+mVIP8mSLfl2TW3DOM8A4+JpkWgUoyFnpgXhCex9H0Ji SQ03OuCtczhDkhS7Ji6U4D9i2jVvvytbvtKar3RcbNXyqCTqCb/j15N4ZmAps6Hb8qljk yk+8r94okmwjKdPdiEU7zGp3KBjTLPKtIDSd3vPUaE4YpweRn7T13glxq7RKumTtNmhak aYOgBAB8wxvReM/44092XaYMjvrUxY2IIdtpzL0sAMfw5HpM1ZSIiApwtFc2zucWHOQ== 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.51 Received: from mail-pj1-f51.google.com (mail-pj1-f51.google.com [209.85.216.51]) (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 2965C606A320 for ; Mon, 30 Nov 2026 10:49:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 2965C606A320 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-f51.google.com with SMTP id 98e67ed59e1d1-3b4021b572dso6304472a91.2 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=daTxBvmTukCQDehMuy2CYQKhQ+1duy/FQapTfjL20eJn9K+KnZjyfbi28IU8c6uG7Z vK4ZmC8utu5kPqNs33fkut62L+UsrWJDHCflx207md5OWx7TofUjnvB4F8nFNBKrcgEV bzuZfnhJKqD81GH6LqYBDcT/hwRzE+0cEldIFW9CMg7UjSP0xs/cRjGTwCOffKF0AOA6 oGn/0LFFgYCKNXr7Y2x7Fd8Iyb6dQ4BhkDR4RxqcDMYCfQa+yZprJtbmV0OzuoeqHQ4u CymHhhVgorjVXDG8t2mbSZZprc41XXcsBsSrf7NpV5h0AZAEnptkiDQhVRwOwKfesimt XxOg== X-Forwarded-Encrypted: i=1; AL+hErHQIfsfIfd4Ya+mmqIOK4lr+jh+23VbV0dhd2aptwbE+Gf5TTO4iHIMHYNhQkZABmow18bC+1Qkz81Fuw==@vger.kernel.org X-Gm-Message-State: APuU4Z9kjpRH2ZpbyYBLcsvao8u9Xiwh1btrRT+fQW31Si4EBls5/OKO EGWWSvk5+HoPRcGV9l/aLTxk5qAJ8SqOmm1G6n/cJiW4Th+yuS7gteO7 X-Gm-Gg: AZFdTZeyeWd8z6yQM/6qtbjUr7q5vylI/xaNl+oNjgZmuxyHfuTzUfdYoMM1fJJ3yBM QHY8KzpaPPVnMETOFhnp+APN9cSuI9w65LeiHn5vce8j7aKKKqI6CVZHsFkH5q33hsOBWGThO3G osCiecT8e5syuanxW1U6Kwpib+ofPvQqvR0puTykRfz6ypMxVR8sHzeprac+hakYrDwXtaLjNzz bVRbHyx2iE2jFFMCy+z8WnOxzgMisM7VUkxg2UDgLLP/+01RfReGu3SAJRVPQaD/u6kZ8K15Pap K86I5oyrjbrYslRKuTvIcrr+67K/48uNbsATnr8ZB3ROVW7598RIZZsw7+DCtCMf7m5B4X2MGNQ hXDrG4nxoG786h+tUYS14y9aA7BE3YXkFmFlqualVFnk6I/UWSmcoC94VTVjzPeTCIiRqlzDvt+ 7T1wtNPPIC4d67kzAoUMcinO5ZxSlR8PHUofmL3wFVJG1SUoZItDnGZ0KJjJSvRxHmWc2QBT5j+ dLjI55obNJaPdEle0rvlZMdBBKw5M1oA0KdTzY0q2lCbb1AbvR4LxFiasvhujbEPyRA0O1NrCDq THTEyHTMw/l5qhrC1umgUWhyWSrtbKGA9BnotEzK0NsE9SBbI9RGehQX8w/Wjsl6JDwie6XANzM = 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: linux-sound@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