🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #20139

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

#20139
From: Fang Xieyan
Date: Sat, 21 Nov 2026 14:18
100 lines
12139 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 and drops every command at or
beyond that offset. next_cmd_index is not validated, so the walk can
read past the end of the skb, loop on an earlier command, or decode
the header just read as a second command.

Bound every command offset by the received length and require room
for a complete command header. Validate the next index before
processing the command carrying it: it has to advance past the
current header and leave room for a complete next header, and only
zero terminates the chain. The offsets then strictly increase and the
walk terminates. The array_index_nospec() call is removed and
block_length is only sanity checked.

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 65421f6b4c91..a8448e273c02 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));
+	/*
+	 * The uplink encoder leaves block_length at the ACBH header size.
+	 * It cannot delimit the command chain, so use skb->len to bound
+	 * the command offsets.
+	 */
+	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) {
+		/* Past the block header, and a full command header fits. */
+		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: <20261121141850.73754-4-fangxy@xiaopeng.com>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-368348-linux-kernel-netdev=dewy.ru
References: <20261121141850.73754-1-fangxy@xiaopeng.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-368348-linux-kernel-netdev=dewy.ru
From: fangxy@xiaopeng.com (Fang Xieyan)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net v4 3/5] net: wwan: iosm: bound the ACBH command chain walk
Date: Sat, 21 Nov 2026 22:18:48 +0800
Organization: Usenet Network
Message-ID: <20261121141850.73754-4-fangxy@xiaopeng.com>
References: <20261121141850.73754-1-fangxy@xiaopeng.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="3422871"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:WOAFvUMGpDeceW68VCb6J9nrWI0= sha256:nzbbJqkrq7108Bdn1CF9zzz/0w1+/DSMSJWgfUm55rM=
	sha1:Gcg2rv/mJzGObFEXtizV5nMPbVQ= sha256:gKR6+j/OMhkW3LZzhlji6GtWdvUknl2YDNWlABlTnhQ=
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 ECAB8115B6A; Sat, 21 Nov 2026 17:20:06 +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 jJTi68NEvmqN;
	Sat, 21 Nov 2026 17:20:04 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-368348-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 sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id DBCAA115B54; Sat, 21 Nov 2026 17:19:55 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id B4C10468FF; Sat, 21 Nov 2026 14:19:35 +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=1795270770;
	b=pZidUOfVePjF7IQO94a68QYQi9SJ2FWiL+gXv69Bu5xO98D74ltHthCpVz+uytNVCNZt
	 gVVvH2DdGmV47+D8wTdwLbTX2oc/IDkDx5v0bnYiDJCGa+lFS/ERCb0/jspUN1JIy4e9F
	 FoZN0QBBEqtOROdYK9vAq1UggHiKJGwDwaCY94qCDjhLZVlj54SH6OW+8shw7I57e0oWs
	 JqDJHyisgGoum5iMhS0awC+pfut9nk91yOT1B/30wVF23+fWvC0+uuJ6zdGGDAGmtmftJ
	 6ri5caibDyVaXetMmY9GiuJ3sTXK0X6t3/1+sQrDodzldoyhR22abmw8fiQTmjZb7Lw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795270770;
	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=dH3XbXnDqDUIiU7bFseXAANFSe3VoFujE+ufZbliiUE=;
	b=0IhtjBU9I60Fk9Qk4qOGH9CO7Cb5Dga2NbUWBQl30Q3w3LU+mnfgCoSHov4eMHV/Hl/f
	 W//BCzptFbKnwIH2a5Dr5UKIzY5dlsluZX0eCeNEU9Uy8lzz35y1pQxEvAjyrpJ/wCeYD
	 3EHzBOeklCuTsWhe7QNd4ft90UwV7464fHN+i4vzfNFgYe9QzABkuO2lCwsjxALcIgdtv
	 iOJp4lGb4JJZzwerGMVSdmODQWdus2xG3mLuzwDFkxpuv6lEkXsExUsYtvzfYvmJFNrH+
	 9EDWniQWSaKJeGHRqcPh8sR6SusiOj8vPHM5a/XcsHLllwBhmZlb4Us3PbmH13MijCg==
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=j3CjG3SF;
	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 00B72606A693;
	Sat, 21 Nov 2026 14:19:30 +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=j3CjG3SF
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=115.124.28.98
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1795270764;
	b=uMauK85g9IfoDGbvMkMMsOrE+Ud7ml48pGRv/lTEWqHspSvwLqd//PX5fRwlD6GUXLc9
	 NKbABwaEl1OuZE3odD1P8WUUPirDZfKZ3awXsiEG3/Q+hoc26VZiSbx2NJ0FAopG0eOEN
	 BpzwPcbu5iJ60Xu6c81j/ZS7/SGEpz5GgjENz+Gw88nfWOnr86CHJUDo7gQO/IEgUME1t
	 AzPCttqKVTC0okIbSd1OPwa+QIaxyMxSf+Flu7V6uS78k+SHfJXkdThLBIFqfv8YtgCaM
	 OrMhH0ayLJTq7gMqAULKKzv3v96OUX+FlM/vWXpAkrkDEawconY0YvBzNr57DtNwrUw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795270764;
	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=dH3XbXnDqDUIiU7bFseXAANFSe3VoFujE+ufZbliiUE=;
	b=3j2Z2LOQUKd33/B3PAov8xrOhYgra103N+XfkvlkBw/6wvUbcDwvIdv3QiX2djl23BMz
	 iuTGO2+UTe1ypTRu42LsEZpKe/O7sJoTV82fIOv4CytfSKym9t77kRhPomHh/NU1i8y/L
	 Nhx8IaWukiAWCN7o1Usm1yYqn96vCHpVDtfdbTzr7oi/Reg5WPx8EipL8y3i2LxczmLGO
	 al0Ot3H/hPf9uRt9m8GFsg8ZFhHepn9Keb1V+/kzib6QtqCjlULDAs2j07CJH2yp8zeKf
	 jUfWjLcHhg+ZNYduTuP7p1oWEEjEwUMy4tOw9zPPZ1xZ4w55gON/yl5V9RfZ38wuLvw==
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=j3CjG3SF;
	arc=none smtp.remote-ip=115.124.28.98
X-Received: from out28-98.mail.aliyun.com (out28-98.mail.aliyun.com [115.124.28.98])
	(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 5D3C3606A33A;
	Sat, 21 Nov 2026 14:19:21 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 5D3C3606A33A
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=1795270753; h=From:To:Subject:Date:Message-ID:MIME-Version;
	bh=dH3XbXnDqDUIiU7bFseXAANFSe3VoFujE+ufZbliiUE=;
	b=j3CjG3SFZtXsjDmFZrw+ps4y2DMi30dT+MvJerfMc9/2ndbLy6N4i29ZwmG/4m+YeCquZi4aFMAz58v5RjqJaTI+XTRDXNIpADCJo8qKNA6EA7KFO17Vf4DUAFBOCHlGgjNxzbLaBLKhKbXMVp7d3M0isXy8Xg8FB/ZtgYWjT/c=
X-Alimail-AntiSpam: AC=CONTINUE;BC=0.04449996|-1;CH=green;DM=|CONTINUE|false|;DS=CONTINUE|ham_system_inform|0.00378321-8.81247e-05-0.996129;FP=14274760503927538816|0|0|0|0|-1|-1|-1;HT=maildocker-contentspam033045038069;MF=fangxy@xiaopeng.com;NM=1;PH=DS;RN=14;RT=14;SR=0;TI=SMTPD_---.k7GCEaC_1795270749;
X-Received: from localhost.localdomain(mailfrom:fangxy@xiaopeng.com fp:SMTPD_---.k7GCEaC_1795270749 cluster:ay29)
          by smtp.aliyun-inc.com;
          Sat, 21 Nov 2026 22:19:12 +0800
X-Cc: davem@davemloft.net,
	edumazet@kernel.org,
	kuba@kernel.org,
	pabeni@redhat.com,
	andrew+netdev@lunn.ch,
	horms@kernel.org,
	johannes@sipsolutions.net,
	maoyixie.tju@gmail.com,
	zhugl3@xiaopeng.com,
	linux-kernel@vger.kernel.org,
	stable@vger.kernel.org
X-Mailer: git-send-email 2.50.1
X-In-Reply-To: <20261121141850.73754-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