From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.169 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796195102; b=wJ+b/ibYngcOAIsheAhTYXuuEzgtrsv6XNLPIcyXduFiGe8rOG7FQMU6wGfakgnQZSK7 tiOS12phiROCBGk+fWuDkAAgPhTcJOtFME74H0B24qPWXzE5dK7ujTCXmi/xGdC0dLpWc lTu2UOEBARp7HB+UZ8t0TlTf6A13npO/80+kkkM6Gih9LDEkHGG0ap5pQEamXA2WaG049 nTu5BX1gUNZh899zcke4xaLJh1xQUnaUpYnWKlJPtsc2XTN4rIv8FySfuHX+QU5nRISOo shV6dPwi+E1CyRPOjkpCnyjtH5TJ0gQ4NjyHBBOCm7jriVPCnlccR9M3h30hlbQbWiw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796195102; 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=uaHx3MckG8qW2LKyDKndEYw6wBgEqz9MXaFHvH3CknY=; b=4J1BwKEIxRwnXN5bhenJKcIeVXV3LfbRsjs7jWZpHZPdUNU8z+8d1oFdZVjSUpFvacyT 9pTVGiSRcNfVtsY0TaSs5+O0Nnt+vXqnnZLLTN6o3PbRB4aFRre1eqdFtdolHYuL4Vys/ wDAyMkKQ+tTw+8yoiB9nriB1dZUZ+k/oUsDjQ7EGDZ2oZsx5ZdsePVcGEMmC8LYDHtSbe WOZXnM18WhjeUt/gDcEYnSaMQIUNH16AHhjtnbAnKE6TXVm7D1oWSlbLgTaBTvx6Ng9IA 8juqEb7Jy4+aoe9NoFoSpNQvrCj0+dboYItdL0GhTSBGiJOcRdW65Mn6ZVLF1cpBZoQ== 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=k9t2drSa; arc=none smtp.remote-ip=74.125.82.169 Received: from mail-dy1-f169.google.com (mail-dy1-f169.google.com [74.125.82.169]) (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 33B5E606A323 for ; Wed, 2 Dec 2026 07:05:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 33B5E606A323 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=k9t2drSa Received: by mail-dy1-f169.google.com with SMTP id 5a478bee46e88-38699cf08dfso17738541eec.1 for ; Tue, 01 Dec 2026 23:05:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796195100; x=1796799900; 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=uaHx3MckG8qW2LKyDKndEYw6wBgEqz9MXaFHvH3CknY=; b=k9t2drSaXQa+z64BvP9z22SiJrMuIL0ojTmJ32HR9OxhwvIiG910p8Cj1bnZVbXIoQ HSq47le5+3qHZ8STlQIWOxcaIy04jXCj7rq7piXNjCRGg+zuAvN2+JG95xLN2YE8ZBUW EZQipze8t4EcAO9s8MVvnf9R9FmDa90WexkY0tt7yIOFVCU8rn2hbdTv8W2k/s9dbYKZ XLZAbhNM6z7DvvZUfx5tT2v8xn+BlVWz/yTLPriL5p8gVEvUdL2c4/thmQT/Tb4h5WZi cURTjd3UDaLqeI7Kvd90ZP0YJEn2X9fsPkhNkelEqMFtex2F8hClEAmVXP2QFB/ZU9ZD YGNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796195100; x=1796799900; 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=uaHx3MckG8qW2LKyDKndEYw6wBgEqz9MXaFHvH3CknY=; b=ugadgRocM8/tQ2GCoKD0CSHxohmA2RwI480J30thTbz7VfBlRWj6EhzHJi72jOauYY Hq+tpRvFIN7zQmooUwv9lTLmacYHKy5676gs8UB78F7RlN4Eh9Y+ZnK66ltNrf/YP4q5 pz1clA/8iFS2dzHfHqpkz/+kFwjZOcbzj1eXLvTepalnYLKzWsPgn4H7z7IjNpMXe4ML B24Ait0rXBsab5A38ADnq6NN/tbWhS1BfBc7T7+YDEHGPJPyHzAcFH4ITzJDxw46Rf9h Ox1pJCIgXavKwwHAfPqqkQysEDBiboX3gBNTFMmAk8xsBwY1v1WdYukWB7STA2WaUdKl 7KSA== X-Forwarded-Encrypted: i=1; AL+hErECWcwkx2pkbr8/WapydvbKMfwisBexmzEMZ3qliSBEIBrthsIopzYcbUXIeG/t8vp8RS3bcFhqTInXlA==@vger.kernel.org X-Gm-Message-State: APuU4Z+LkG81VOCwkvqbF3ebIVjzP1gZELQzqjneSFcbZPayEBODObTc f45Pn3grsUwToX0QK2Pz89n7NvvlGHOrIPdrYRxDpvnAN9ZjmraqSJfD X-Gm-Gg: AZFdTZf4sGHcuTNIiKBGA3r7tBN7a42vXRHX1MAktDjxafgUKaAQLjqARN/dxpEMTcq Nzw2FSb9bWidDl7UlSWjfCWKYtRxqSLKEc7s2YHE8GVZR0WnWJR2njCfGniLBGSCLJi2l7TMbCS bM+CgA284+JVAjr+b/MIVpucm5Rg6/17Qzx5HHzk6dMf7/H4v5x3YjBiZHOKDzIbX9Oqn3rjDEz WY1AufZ3Rj44By3Y329rF+vITsuSiq5naexAaPDPqZ9cTClOt8JhCU63F24TVd1W3Z3oFxgZxL0 dXoaltvWWSahj14gmIWuCerpfOQ6R16ks/5TJJGLWs07HQa4GL7Vzfa4abX5aLovnb33/UuTFZ9 saZjZajhLF5dOXsYvxGIUVimbpVehxa/mGnZuyNDE7DQkYrXpEVSvW5IgsSOgnAXVCdnCuyXu+N qVBp74nU/q4TM7BvEYisHwY9G19aXS9mvziLvMztd3PPlK3Q6JNC6ukH5c2NwXDx41UV0gDaq1/ YtD6NSjXHEtU7zwskXWnfPspbCkQ9Ln30cJeP6sfiiSwdJhHr9BPVGpzl0SUhzVcKuffd0bzuoR pLSD6QmcirrG7SrACiegX7C0zQpF9jq4+480BUkFbKt2Rjj1ZMRNSw== X-Received: by 2002:a05:7022:130d:b0:136:c443:80e5 with SMTP id a92af1059eb24-1b5568a15b7mr34001564c88.6.1796195100153; Tue, 01 Dec 2026 23:05:00 -0800 (PST) Received: from csl-conti-dell7858.ntu.edu.sg ([155.69.195.57]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-1b5566c3052sm89425931c88.1.2026.12.01.23.04.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Dec 2026 23:04:59 -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 v3 1/4] ALSA: bebob: bound the channel position walk to the response length Date: Wed, 2 Dec 2026 15:04:49 +0800 Message-Id: <20261202070452.732525-2-maoyixie.tju@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261202070452.732525-1-maoyixie.tju@gmail.com> References: <20261202070452.732525-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. v3: No change. 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