From mboxrd@z Thu Jan 1 00:00:00 1970 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=1795059422; b=txSfV1fqVDF7vwCDtMzpXBm2QHI771DgHMWk2L1nbQFtRwdqqp0ktKRegHp2aCgspYsD x8DObt4ePBqEACtdc2neRSiUEianVD5DxYYWqW5AJ0TMcZbkrzi852ff8tRZX2mHxHR96 PTeNjSLA/X3sxu3B+2dXWA1ABcfmTsMl6ZeVtjRfuDra+aDuf7ndC7bvxlop3ojZSE1J0 za+DI2FH7U3USeAK8xLZcelO0vjByan6LUkxS1788CQcFYuRzTBjvU3waTn+zo5MAPozZ d9GyF+N+uK0q0X+WuKB5EdYoW7CSJCFCFTUc6RtoLJaKaewhQqyLWD1FkRq6XUlm4mw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795059422; 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=Em/WHzX1jzwg3jR5aAlLPi9tuFNKTblUfHG/Fj7AqoA=; b=JchZ2sWHkt0RQlIsue+ASe5RAFyhQ/vbhaEA9mW06hax++CsIKG0KqseoK84cxGii5Rg QHEGczHYe+Wpfdczkr74CncQiEeW/XqHbSy3BkggOkzIzRta03uQNeA9hb6/3ffDmZriY SumlUJUs9/PWBwBrPOdXfczhSETj19J2TxvBpt9EPQe34Vvx9dpFzFZ/Ez4lA4WRDnmFh M5brxYdIZeCyAzw5UCxGb/mJOjsYrXWBF9MWIwx3u9XHvKkWlTopQo0LYcTUyF8xHgVEA 7NNspPVkc9WkSr2HaccED/zaLZ92z5+x3kSfcbPdZHH3Q369wLgVv8kCWsb9yhrY+Pw== 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=wT80613d; 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 8677D606A32C; Thu, 19 Nov 2026 03:37:02 +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=wT80613d Received: by smtp.kernel.org (Postfix) with ESMTPSA id 12F491F000C4; Thu, 19 Nov 2026 03:37:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795059422; bh=Em/WHzX1jzwg3jR5aAlLPi9tuFNKTblUfHG/Fj7AqoA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=wT80613dJJDuDdsUYsQtn1S6va6mIm02iyisscInWPURQ2xGgXgDfTCqcw2xa/PEv EbMnIvHRwlpJNP/DY3c2sjTX0xRnWmZSJCdLGSf7A5ZPYeHE8fIW41/ZCEQKU2iQR9 iNJLyigOEtxBheWFTl+ZAzaHqWQdtPOqqKeKIDgc= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, stable , Nathan Rebello , Seungjin Bae , Heikki Krogerus , Sasha Levin Subject: [PATCH 5.10 0835/1848] usb: typec: ucsi: ccg: Validate altmode index in GET_CURRENT_CAM response Date: Wed, 18 Nov 2026 15:47:53 +0100 Message-ID: <20261118145951.630476690@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261118145911.150052362@linuxfoundation.org> References: <20261118145911.150052362@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore 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 5.10-stable review patch. If anyone has any objections, please let me know. ------------------ From: Seungjin Bae [ Upstream commit 02ee864e8d2142c5648998944c3306ea6a763c26 ] When the PPM reports more than one DisplayPort alternate mode for a connector, ucsi_ccg_update_altmodes() merges them into a single entry in uc->updated[] and sets uc->has_multiple_dp. In that case, ucsi_ccg_update_get_current_cam_cmd() rewrites the response of the GET_CURRENT_CAM command. The response is a single byte holding the index of the currently active alternate mode, and it is provided by the PPM firmware. The function uses this byte directly as an index into uc->orig[], and then uses the linked_idx read from that entry as the translated index into uc->updated[]. Both arrays have UCSI_MAX_ALTMODES entries, but neither index is checked against that size. If a malicious or buggy PPM reports a value of UCSI_MAX_ALTMODES or larger, e.g. 0xFF, uc->orig[cam].linked_idx reads over the end of uc->orig[]. The byte read from there is then used as the index for writing cam into uc->updated[new_cam].active_idx, so the out-of-bounds read is followed by an out-of-bounds write. This happens without any userspace action, since the UCSI core issues GET_CURRENT_CAM on its own when handling connector changes. Fix this by rejecting responses whose index is out of range, printing an error and returning -EPROTO, so that the caller cannot accept this. Also check linked_idx before using it as an index, so that the write into uc->updated[] is always within bounds. The response is now only processed when the command completed without an error. ucsi_sync_control_common() only reads the response when the CCI reports command completion, so otherwise the buffer is not filled and must not be mistaken for an invalid index. This bug was found with a Python script that traces where firmware input is used. Fixes: 170a6726d0e2 ("usb: typec: ucsi: add support for separate DP altmode devices") Cc: stable Reported-by: Nathan Rebello Assisted-by: LLM Signed-off-by: Seungjin Bae Reviewed-by: Heikki Krogerus Link: https://patch.msgid.link/20261003215520.611083-2-eeodqql09@gmail.com Signed-off-by: Greg Kroah-Hartman [ sashal: adapted the ucsi_ccg_sync_control() change to ucsi_ccg_read() without CCI status checks ] Signed-off-by: Sasha Levin --- drivers/usb/typec/ucsi/ucsi_ccg.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/drivers/usb/typec/ucsi/ucsi_ccg.c b/drivers/usb/typec/ucsi/ucsi_ccg.c index b50933cd4babf..2caef7d02cbb6 100644 --- a/drivers/usb/typec/ucsi/ucsi_ccg.c +++ b/drivers/usb/typec/ucsi/ucsi_ccg.c @@ -351,14 +351,28 @@ static int ucsi_ccg_init(struct ucsi_ccg *uc) return -ETIMEDOUT; } -static void ucsi_ccg_update_get_current_cam_cmd(struct ucsi_ccg *uc, u8 *data) +static int ucsi_ccg_update_get_current_cam_cmd(struct ucsi_ccg *uc, u8 *data) { u8 cam, new_cam; cam = data[0]; + if (cam >= UCSI_MAX_ALTMODES) { + dev_err(uc->dev, "PPM returned invalid alternate mode index %u\n", + cam); + return -EPROTO; + } + new_cam = uc->orig[cam].linked_idx; + if (new_cam >= UCSI_MAX_ALTMODES) { + dev_err(uc->dev, "invalid linked alternate mode index %u for %u\n", + new_cam, cam); + return -EPROTO; + } + uc->updated[new_cam].active_idx = cam; data[0] = new_cam; + + return 0; } static bool ucsi_ccg_update_altmodes(struct ucsi *ucsi, @@ -541,7 +555,7 @@ static int ucsi_ccg_read(struct ucsi *ucsi, unsigned int offset, switch (UCSI_COMMAND(uc->last_cmd_sent)) { case UCSI_GET_CURRENT_CAM: if (uc->has_multiple_dp) - ucsi_ccg_update_get_current_cam_cmd(uc, (u8 *)val); + ret = ucsi_ccg_update_get_current_cam_cmd(uc, (u8 *)val); break; case UCSI_GET_ALTERNATE_MODES: if (UCSI_ALTMODE_RECIPIENT(uc->last_cmd_sent) == -- 2.53.0