🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #15138

[PATCH net 3/5] net: wwan: iosm: bound the ACBH command chain walk

#15138
From: Fang Xieyan
Date: Thu, 12 Nov 2026 12:51
118 lines
13470 bytes
ipc_mux_dl_acb_decode() walks the command chain of a received
Aggregated Command Block. first_cmd_index is passed through
array_index_nospec() with sizeof(struct mux_cmdh) as its bound, which
treats a byte offset as an array index: every valid offset at or beyond
that size is turned into zero, so the command it points at is dropped.
next_cmd_index is not validated at all before it is followed, so it can
point outside the received block, back at an already processed command,
or into the header just read. The walk can therefore read past the end
of the skb, revisit an earlier command indefinitely, or decode an
overlapping command header.

The overlapping case does not fault, which makes it the quiet one: the
current walk does not check that next_cmd_index advances beyond the
header just read. An index into that header is therefore followed, and
those bytes are decoded a second time as another command and
acknowledged a second time.

Bound the commands by the received length and require every command
offset to leave room for a complete command header. block_length is
checked to cover the block header and not to exceed the received
buffer, but it is not used to delimit the commands: the driver gives
the field no meaning beyond the header on this path, and its own
uplink encoder leaves block_length at the size of the block header.
What arrived holds either way.

Validate the link to the next command before the command carrying it is
processed: a non zero index has to advance past the current header, stay
inside the received data and leave room for a complete next header. Only
a zero index terminates the chain, which is how the uplink side of the
driver terminates its own command blocks as well. The offsets then
strictly increase, so the walk terminates, and a command is no longer
acted upon before its link is known to be usable. The array_index_nospec()
call is gone with these checks, which constrain the same value properly.

Fixes: 1f52d7b62285 ("net: wwan: iosm: Enable M.2 7360 WWAN card support")
Cc: stable@vger.kernel.org
Reviewed-by: Guanglei Zhu <zhugl3@xiaopeng.com>
Signed-off-by: Fang Xieyan <fangxy@xiaopeng.com>
---
 drivers/net/wwan/iosm/iosm_ipc_mux_codec.c | 46 ++++++++++++++++++----
 1 file changed, 38 insertions(+), 8 deletions(-)

diff --git a/drivers/net/wwan/iosm/iosm_ipc_mux_codec.c b/drivers/net/wwan/iosm/iosm_ipc_mux_codec.c
index b573067a366f..2c4f175233a1 100644
--- a/drivers/net/wwan/iosm/iosm_ipc_mux_codec.c
+++ b/drivers/net/wwan/iosm/iosm_ipc_mux_codec.c
@@ -526,30 +526,60 @@ static void ipc_mux_dl_acbcmd_decode(struct iosm_mux *ipc_mux,
 /* Decode an aggregated command block. */
 static void ipc_mux_dl_acb_decode(struct iosm_mux *ipc_mux, struct sk_buff *skb)
 {
+	size_t hdr_len = offsetof(struct mux_cmdh, param);
 	struct mux_acbh *acbh;
 	struct mux_cmdh *cmdh;
-	u32 next_cmd_index;
+	u32 block_length, cmd_index, next_cmd_index;
 	u8 *block;
 	int size;
 
+	if (skb->len < sizeof(struct mux_acbh))
+		return;
+
 	acbh = (struct mux_acbh *)(skb->data);
 	block = (u8 *)(skb->data);
+	block_length = le32_to_cpu(acbh->block_length);
 
-	next_cmd_index = le32_to_cpu(acbh->first_cmd_index);
-	next_cmd_index = array_index_nospec(next_cmd_index,
-					    sizeof(struct mux_cmdh));
+	/*
+	 * Keep block_length within the received buffer, but use skb->len
+	 * to bound the command chain: the uplink encoder sets
+	 * block_length to the ACBH header size.
+	 */
+	if (block_length < sizeof(struct mux_acbh) || block_length > skb->len)
+		return;
+
+	cmd_index = le32_to_cpu(acbh->first_cmd_index);
+
+	while (cmd_index != 0) {
+		/* Every command header has to lie inside the received data. */
+		if (cmd_index < sizeof(struct mux_acbh) ||
+		    cmd_index > skb->len ||
+		    hdr_len > skb->len - cmd_index)
+			break;
 
-	while (next_cmd_index != 0) {
-		cmdh = (struct mux_cmdh *)&block[next_cmd_index];
+		cmdh = (struct mux_cmdh *)&block[cmd_index];
 		next_cmd_index = le32_to_cpu(cmdh->next_cmd_index);
+
+		/*
+		 * The next index has to move past this header, stay inside
+		 * the received data and leave room for a header of its own.
+		 */
+		if (next_cmd_index != 0 &&
+		    (next_cmd_index <= cmd_index ||
+		     next_cmd_index - cmd_index < hdr_len ||
+		     next_cmd_index > skb->len ||
+		     skb->len - next_cmd_index < hdr_len))
+			break;
+
 		if (ipc_mux_dl_cmdresps_decode_process(ipc_mux, cmdh->param,
 						       cmdh->command_type,
 						       cmdh->if_id,
 						       cmdh->transaction_id)) {
-			size = offsetof(struct mux_cmdh, param) +
-				sizeof(cmdh->param.flow_ctl);
+			size = hdr_len + sizeof(cmdh->param.flow_ctl);
 			ipc_mux_dl_acbcmd_decode(ipc_mux, cmdh, size);
 		}
+
+		cmd_index = next_cmd_index;
 	}
 }
 
-- 
2.50.1
Technical Details
Message-ID: <20261112125201.1019-4-fangxy@xiaopeng.com>
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!nntp.comgw.net!eternal-september.org!feeder.eternal-september.org!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-361814-linux-kernel-netdev=dewy.ru
References: <20261112125201.1019-1-fangxy@xiaopeng.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!nntp.comgw.net!eternal-september.org!feeder.eternal-september.org!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-361814-linux-kernel-netdev=dewy.ru
From: fangxy@xiaopeng.com (Fang Xieyan)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net 3/5] net: wwan: iosm: bound the ACBH command chain walk
Date: Thu, 12 Nov 2026 20:51:59 +0800
Organization: Usenet Network
Message-ID: <20261112125201.1019-4-fangxy@xiaopeng.com>
References: <20261112125201.1019-1-fangxy@xiaopeng.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="1089012"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:TOeiDo/6ronnGjNvIlWxsK+2YJ0= sha256:UEAECnSkSQnRbHW8cYO2XEuYIB6AyrRCWHDs/7Rvov8=
	sha1:KbnaBUWrt6Q8AMYVoTAUhHYsNbE= sha256:/kzXzGHg55PReZglRktSJA8PBXeMctXZpE1z+ViZmd8=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id DF97211422E; Thu, 12 Nov 2026 16:01:59 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.05
X-Spam-Status: No, score=-3.05 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001]
	autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (1024-bit key)
	header.d=xiaopeng.com
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id lSv_VBHLD6Dz;
	Thu, 12 Nov 2026 16:01:55 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-361814-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=none (p=none dis=none) header.from=xiaopeng.com
X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
	by mail.dewy.ru (Postfix) with ESMTPS id A7698114227; Thu, 12 Nov 2026 16:01:47 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by tor.lore.kernel.org (Postfix) with ESMTP id 2BCEAC3271; Thu, 12 Nov 2026 12:52:49 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1794487942;
	b=ngp7WjJseedbaedkVR/iv2k7laGpIzFZY42oTTWTS7LKeKJPZ4PONWbLOmPEBrK1Etkh
	 acTAX6u3n6ClOxAh30HL/rxsoptKJIw3hJ+XJm7TPj23sOvN9xA2q/N3ALuxRksaCj/PO
	 8Pxl8As3UdVt3TOWrgT6zypR6OFJyST58R15pLx3vrn+8lBIh7z0ZLYwqry1oT0nTlLgT
	 7b9Hz2MDTi25OgQ4YInlecsPDEfcKRiOeycy6igjBEErihV5Wrupn4sq+gmg+OqoH0x31
	 rfsqUZIbu9rbLCyJxwnDrJTJWi8pem9fDQXFbkK6TIs9mgmfqFdseLQSxkd1ewSJniQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794487942;
	h=X-Original-To:Received:DMARC-Filter:DKIM-Signature:
	 X-Alimail-AntiSpam:Received:From:To:Cc:Subject:Date:Message-ID:
	 X-Mailer:In-Reply-To:References:X-Mailing-List:List-Id:List-Post:
	 List-Help:List-Subscribe:List-Unsubscribe:List-Owner:Precedence:
	 MIME-Version:Content-Transfer-Encoding;
	bh=OxtGBN2glWF6C8GA+0CSJwlB27w7Ez9V7PeT7YJ/Diw=;
	b=1IiOyYlkxdGT05XYJke1Ax4+I2jgGuOfR6toSCBJP1bEdzhczS/8U1HtFoud1ncgtUfH
	 bdUOkbBIHR5+5aGTvbqFOImX/Nl6pb48A8soLvYjn0kXmwYQBAQivja8XZ/vBXmjcZKqo
	 cGHwwvelNof4CJPwU5l1qLaN1ffXpKa6vH4Rq0folTCo4xG8j6m1s8u3cmVfZJ60c2gcU
	 O3K7ZLoE9ADz8KY9YaSTmcydPGyMaM8WeD9uCAEXZCzLBrzebo315ae6PGtOrc0sKPTFw
	 gyoclHO0laTTO9FiZ8ZbePEgMqKfZMsfwrJTOOJCbzsrnLYXckWf4Z+W1lBWhb1afpQ==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=xiaopeng.com header.i=@xiaopeng.com header.a=rsa-sha256 header.s=default header.b=spONBNO4;
	dmarc=none header.from=xiaopeng.com;
	spf=pass smtp.mailfrom=xiaopeng.com;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 5962760A2608;
	Thu, 12 Nov 2026 12:52:22 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (1024-bit key) header.d=xiaopeng.com header.i=@xiaopeng.com header.a=rsa-sha256 header.s=default header.b=spONBNO4
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=115.124.28.145
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1794487941;
	b=R5/242tjydElX2qdadot1zM+1broSW5vdh23Qb3lauYRGAhmho5XPGWFdc1yHjBGnB77
	 I8MJj0mWza5HHnbjd/7LqSYIS1VDo475tn/6WjS/og9orsnOmygB0eH/CMUqeU3TwwwjA
	 vSYuudGVVDXWJu9p0c+qrUwe7rZ0QWc64dAZo8xRZRT0BAgAnYgvumrbCsKndCYSYn2eL
	 MCWisnVVC06Io0B+tW88dmWKkN9X8+ZNv0/eLo7r9tVZKpFqIQnC8w8K8K3D3CbjptaM4
	 OZzOP6OozSZS6LuRCt7Iggo7uknOX4vWyYak9t5fHbYSZs4X2u63i6au8jc12knXPsQ==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794487941;
	h=DMARC-Filter:DKIM-Signature:X-Alimail-AntiSpam:Received:From:To:Cc:
	 Subject:Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version:
	 Content-Transfer-Encoding;
	bh=OxtGBN2glWF6C8GA+0CSJwlB27w7Ez9V7PeT7YJ/Diw=;
	b=SplxYWi9tprf7mnh7rXjt+wmDKElg5xdzJb4QDBNisPW4oZLBTCyQyVhZwrKW4RUvSMC
	 AYk0G8c+YmWpCuATRqiTMnpDyWqgW2ANiC5T10LvCxkCDxFZF4K7LSwa0rPXkC5RiK92a
	 8NzHw+Ryg/l/ko4mD7MMxlA9WJyLnHREFaxanFLB9cNoSZ8QUbUe5GmFDGJTzGYmT0Bv8
	 nu6wtzdKlEuEMrxjoDwIf66mA+wQuwv5ba+tT2DPZtFcS3ipzVq+v0X3Ipy2uS13TOJwP
	 OcXrbUmBKEvG9mByF2GrZRwRyNSWvQKXSwZDn5o9rVQYPukHCqQ2DT2jaDx2KGcL4mw==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=none header.from=xiaopeng.com;
	spf=pass smtp.mailfrom=xiaopeng.com;
	dkim=pass header.d=xiaopeng.com header.i=@xiaopeng.com header.a=rsa-sha256 header.s=default header.b=spONBNO4;
	arc=none smtp.remote-ip=115.124.28.145
X-Received: from out28-145.mail.aliyun.com (out28-145.mail.aliyun.com [115.124.28.145])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id C53A8606A89A;
	Thu, 12 Nov 2026 12:52:17 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org C53A8606A89A
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=xiaopeng.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xiaopeng.com
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
	d=xiaopeng.com; s=default;
	t=1794487929; h=From:To:Subject:Date:Message-ID:MIME-Version;
	bh=OxtGBN2glWF6C8GA+0CSJwlB27w7Ez9V7PeT7YJ/Diw=;
	b=spONBNO4lEj1LGJMlCANeljE8TWPk5LEbfe/vLh2EngZ558UOQylKLP4kIWov2d9Ux8Xd5pVM4QQN5b9EJd8ItzOAcSSvLw+vL523cDzZdpaugPKoRYIkitOJxDSckW8/D3e+0YX3dLID2GlKmDhLjPcXVmKMWzldgWF/bC4NIE=
X-Alimail-AntiSpam: AC=CONTINUE;BC=0.04437039|-1;CH=green;DM=|CONTINUE|false|;DS=CONTINUE|ham_system_inform|0.00378321-8.81247e-05-0.996129;FP=14274725869513639104|0|0|0|0|-1|-1|-1;HT=maildocker-contentspam033037034184;MF=fangxy@xiaopeng.com;NM=1;PH=DS;RN=15;RT=15;SR=0;TI=SMTPD_---.k0cpddf_1794487927;
X-Received: from localhost.localdomain(mailfrom:fangxy@xiaopeng.com fp:SMTPD_---.k0cpddf_1794487927 cluster:ay29)
          by smtp.aliyun-inc.com;
          Thu, 12 Nov 2026 20:52:09 +0800
X-Cc: Johannes Berg <johannes@sipsolutions.net>,
	Andrew Lunn <andrew+netdev@lunn.ch>,
	"David S . Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>,
	Paolo Abeni <pabeni@redhat.com>,
	linux-kernel@vger.kernel.org,
	Maoyi Xie <maoyixie.tju@gmail.com>,
	Simon Horman <horms@kernel.org>,
	M Chetan Kumar <m.chetan.kumar@linux.intel.com>,
	stable@vger.kernel.org,
	Guanglei Zhu <zhugl3@xiaopeng.com>
X-Mailer: git-send-email 2.50.1
X-In-Reply-To: <20261112125201.1019-1-fangxy@xiaopeng.com>
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list