Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795050973; b=J+x5H+/ticy3zF1aKOnQ2hyCXLhwhULWPF20/8vHUWw7ycYKXdHQcnkebv7EQdG651uI WwCeH++2Agnj9UKVGd9YWc2TeeoD7NQTqJ0UDKTgkxGYx8IW/gOWyXek07qmlDKhb7+ki JJy5zzG+b1QKGQNcV6Io2dKOYhRF40FS16ICrZnUKnK6czcX81xsiyXG+kGQiXGlisVyh dFn2PWybiqMDB1XTT8o4GhK0OGVvT7KJetLoXIOyRvKN7D+rySsn5MFU/CSc+JaBb1FfS mqWGlOm3w9UDCvfam/+WvOJwZEQvgaTe0kPbJNSgSV6E+oPqdQaYF2cVdOSKOrlsQsg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795050973; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=iCevrzCrzPYcP5NpXfVLe61KGZsY97KPMDBA0LXv/Yw=; b=ilCdyLF3eusDOE2moXtQm7SyV+B0Lm6sWUTfvNGF7TGQADt6V2fNt+iaLUQBqjTcJkgh AS4YJaK56F5W7bbonKZ20OCNqb4PTmurM4fRkNgWJHkFcx9wJcZ7hFx8MWcpWQezEAHee pO3PkJZH3UThLhCC8BX1jG+kWM8MAlZ0j7zMHQNHPToEnJwTEIDdXQJiPr52asemzBlsD 0SeeRkLu08py2egVXVAbKzVAaQQcNqibD9aD+qHn3Gc/cVT7JgO6LpSxm1fknQC+3hcE4 qk/d2LksebQ94jMgRNFkDskWopMXS9MaDivJN5T97aczPQ3GAfFu+TfHs9U5alAumlA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=JuWudALT; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BB876606A320; Thu, 19 Nov 2026 01:16:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=JuWudALT Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1C9901F000C4; Thu, 19 Nov 2026 01:16:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795050973; bh=iCevrzCrzPYcP5NpXfVLe61KGZsY97KPMDBA0LXv/Yw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=JuWudALTQpdUJ2nGStsGhz+T6Gem6NtICYDaa5bFHXFS6YO9Cfxva3fsWbt9Y2oUs NUiGVMuBqsXgXtUOIE/clAxEP8bigdKAnG3PqcoiXVzVcHose5qx0X9Dyo8mX2sjWW fk2XcNhDkS2rH944j5osuWCf4D+yjL4LfH2yPcUY= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Badhri Jagan Sridharan , Heikki Krogerus , stable , Denis Arefev Subject: [PATCH 5.15 0012/2214] usb: typec: tcpm: bound altmode_desc[] per iteration in svdm_consume_modes() Date: Wed, 18 Nov 2026 15:28:08 +0100 Message-ID: <20261118150010.637131611@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261118150009.797899913@linuxfoundation.org> References: <20261118150009.797899913@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Greg Kroah-Hartman commit 3389c149c68c3fea61910ad5d34f7bf3bff44e32 upstream. svdm_consume_modes() checks pmdata->altmodes against the array size once before the loop over the count, but forgot to check the bound at every point in the loop. In the well-behaved SVDM discovery flow this is harmless because each of at most SVID_DISCOVERY_MAX SVIDs contributes at most MODE_DISCOVERY_MAX modes, exactly filling altmode_desc[ALTMODE_DISCOVERY_MAX]. But the CMDT_RSP_ACK handler in tcpm_pd_svdm() does not correlate an incoming ACK with any request the port actually sent. Once port->partner is set, an unsolicited Discover Modes ACK is consumed unconditionally. A broken or malicious port partner can therefore drive altmodes to ALTMODE_DISCOVERY_MAX - 1 via the normal flow, and then send one extra Discover Modes ACK with seven VDOs. Because the pre-loop check passes, the loop could then writes up to five entries past altmode_desc[]. For mode_data_prime the next field in struct tcpm_port is the partner_altmode[] pointer array, which then receives partner-chosen SVID/VDO bytes. Move the bound check inside the loop so the array can never be indexed past ALTMODE_DISCOVERY_MAX regardless of how many VDOs the partner supplies or how the function was reached. Assisted-by: gkh_clanker_t1000 Cc: Badhri Jagan Sridharan Cc: Heikki Krogerus Cc: stable Link: https://patch.msgid.link/2026051351-reshuffle-skillful-90af@gregkh Signed-off-by: Greg Kroah-Hartman [Denis Arefev: adapted for 5.10/6.1: tcpm has no SOP' support here, svdm_consume_modes() takes no rx_sop_type argument and has a single pre-loop bound check instead of the two in the SOP/SOP' switch; drop that one check and add the per-iteration bound check] Signed-off-by: Denis Arefev Signed-off-by: Greg Kroah-Hartman --- drivers/usb/typec/tcpm/tcpm.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) --- a/drivers/usb/typec/tcpm/tcpm.c +++ b/drivers/usb/typec/tcpm/tcpm.c @@ -1536,17 +1536,16 @@ static void svdm_consume_modes(struct tc struct typec_altmode_desc *paltmode; int i; - if (pmdata->altmodes >= ARRAY_SIZE(port->partner_altmode)) { - /* Already logged in svdm_consume_svids() */ - return; - } - if (pmdata->svid_index < 0 || pmdata->svid_index >= pmdata->nsvids) { tcpm_log(port, "Invalid SVID index %d", pmdata->svid_index); return; } for (i = 1; i < cnt; i++) { + if (pmdata->altmodes >= ALTMODE_DISCOVERY_MAX) { + /* Already logged in svdm_consume_svids() */ + return; + } paltmode = &pmdata->altmode_desc[pmdata->altmodes]; memset(paltmode, 0, sizeof(*paltmode));