From nobody Tue Nov 24 12:37:57 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=115.124.28.1 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795270760; b=KVD1qOcp/dBNF36r0lVQ5zC0yLQWaVhPD376RkV1/C6tLmm3ULcWb/Auh6xiMrW17g1l EInEF6b0ASVmVMX+1VfTA1xm6H25KO5FbbTaaOggA2aGMel8/4iKKEraqLzW35vGeTR+B 00agzoBbVicuOFp5txN4zGSo3HxU1LqoPXMyM2En5VZbrwDaGRtQtOImRj6XM73VgdH1C 9IleYiSfrMHsMg0hEkbStIbXJPnUalTaNX9AnCIZnHpyPGe1uomrE3LhOgdlxqGJIEusM tTs8LSCmn3autvFN31msl6YRp5iE1W4MwodLmGj6FrW1xVeCvuS4M71N7nukBxTCG6A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795270760; 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=gdGXhDc04esq8UKmQV0Kr8mQHHzjU1OgZnFCkRowno4=; b=WgzGPnkm4EGoUJWzgneyvzY0TSCF6I2EPu6I13IPS/GAYNDhd1YSVBqVaIixXdl1n1F/ Ab1UtkYwqcnuBt508JAqPDrRA4u3WchFfH6DfKS2rsxnet1PQo//qQpHmYwVuSjdJbktS OVuo9wtufbQp4mbEmGq4zFQ33jCcZEb/YRCd9nVtQ9b/s5+L8PG8tiFTd8CbGdr3ngchF UGiQa9mTW6bo/+Qx3oT1xOFx6A4chnyXBmw5rNyeKr8iFbUexvJLztq/dWAyreDObMIdE 2HBkFpepYyqRU+ELQsBMTpNQ2JIsDnc3ryj9fxuSCfeA61RwZNBvNshmGcyUhiS56lw== 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=q+vfaZfN; arc=none smtp.remote-ip=115.124.28.1 Received: from out28-1.mail.aliyun.com (out28-1.mail.aliyun.com [115.124.28.1]) (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 8F29B606A32A; Sat, 21 Nov 2026 14:19:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 8F29B606A32A Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=xiaopeng.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xiaopeng.com 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=q+vfaZfN DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xiaopeng.com; s=default; t=1795270747; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=gdGXhDc04esq8UKmQV0Kr8mQHHzjU1OgZnFCkRowno4=; b=q+vfaZfNrfOnOTWOZOI3tQX8YdZ+dpgmH4EPKiiKFqDSYt5q5gcjM9DLVxMEIz8R8Qjdf7ZPVUKcN3qGMwICZz/Krz3NydqcJbeFC2zrgQKQ21u/+BesgdMuEnnX5kB5HvRWY9ZWR3JRaT0IdCW+hk6ZAkjQdd6l84zmu9aWaeg= X-Alimail-AntiSpam: AC=CONTINUE;BC=0.0444128|-1;CH=green;DM=|CONTINUE|false|;DS=CONTINUE|ham_system_inform|0.00516513-0.000828919-0.994006;FP=15856795541377683968|0|0|0|0|-1|-1|-1;HT=maildocker-contentspam033037034184;MF=fangxy@xiaopeng.com;NM=1;PH=DS;RN=14;RT=14;SR=0;TI=SMTPD_---.k7GCEW8_1795270743; Received: from localhost.localdomain(mailfrom:fangxy@xiaopeng.com fp:SMTPD_---.k7GCEW8_1795270743 cluster:ay29) by smtp.aliyun-inc.com; Sat, 21 Nov 2026 22:19:06 +0800 From: Fang Xieyan To: loic.poulain@oss.qualcomm.com, ryazanov.s.a@gmail.com, netdev@vger.kernel.org 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 Subject: [PATCH net v4 1/5] net: wwan: iosm: validate the MUX DL block length Date: Sat, 21 Nov 2026 22:18:46 +0800 Message-ID: <20261121141850.73754-2-fangxy@xiaopeng.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20261121141850.73754-1-fangxy@xiaopeng.com> References: <20261121141850.73754-1-fangxy@xiaopeng.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The received length of a DL MUX block is supplied by the device and can be shorter than the header its signature advertises. ipc_mux_dl_decode() reads the four byte signature and then lets the decoders index their header structures without checking skb->len, so a short block makes the driver decode past the received data. Check the signature before reading it, and check the header size of the ADGH, FCTH and CMDH branches before dispatching to their decoders. The ADB branch already validates its own headers, and the ACBH branch is covered by the bounds checks of its command chain walk. A block too short to carry its signature is dropped on the way to the single free. Fixes: 9413491e20e1 ("net: iosm: encode or decode datagram") Cc: stable@vger.kernel.org Reviewed-by: Guanglei Zhu Signed-off-by: Fang Xieyan --- drivers/net/wwan/iosm/iosm_ipc_mux_codec.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/drivers/net/wwan/iosm/iosm_ipc_mux_codec.c b/drivers/net/wwan/= iosm/iosm_ipc_mux_codec.c index 0bbd41263cc2..5c33171ca701 100644 --- a/drivers/net/wwan/iosm/iosm_ipc_mux_codec.c +++ b/drivers/net/wwan/iosm/iosm_ipc_mux_codec.c @@ -696,6 +696,11 @@ void ipc_mux_dl_decode(struct iosm_mux *ipc_mux, struc= t sk_buff *skb) if (!skb->data) return; =20 + if (skb->len < sizeof(signature)) { + dev_err(ipc_mux->dev, "invalid MUX block length %u", skb->len); + goto free_skb; + } + /* Decode the MUX header type. */ signature =3D le32_to_cpup((__le32 *)skb->data); =20 @@ -704,15 +709,24 @@ void ipc_mux_dl_decode(struct iosm_mux *ipc_mux, stru= ct sk_buff *skb) mux_dl_adb_decode(ipc_mux, skb); break; case IOSM_AGGR_MUX_SIG_ADGH: + if (skb->len < sizeof(struct mux_adgh)) + break; + ipc_mux_dl_adgh_decode(ipc_mux, skb); break; case MUX_SIG_FCTH: + if (skb->len < sizeof(struct ipc_mem_lite_gen_tbl)) + break; + ipc_mux_dl_fcth_decode(ipc_mux, skb->data); break; case IOSM_AGGR_MUX_SIG_ACBH: /* Aggregated Command Block Header */ ipc_mux_dl_acb_decode(ipc_mux, skb); break; case MUX_SIG_CMDH: + if (skb->len < offsetof(struct mux_lite_cmdh, param)) + break; + ipc_mux_dl_cmd_decode(ipc_mux, skb); break; =20 @@ -720,6 +734,7 @@ void ipc_mux_dl_decode(struct iosm_mux *ipc_mux, struct= sk_buff *skb) dev_err(ipc_mux->dev, "invalid ABH signature"); } =20 +free_skb: ipc_pcie_kfree_skb(ipc_mux->pcie, skb); } =20 --=20 2.50.1 From nobody Tue Nov 24 12:37:57 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=115.124.28.4 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795270759; b=yz/oLldPKPdPF4wGVoKcyYMOfmqw+xBExy+3F9EfVAtd9hDZ9MwUf/4vm3PpYpNjPxNu devJWnLFtPr5WVTwVofTcbcfqzdt8dzJxDLzXur8XbcGaRN3cqMNpHqz+B5Z20QReuNiB z0reMOxfSZgQIia6ZfviCG1M+xmXYMCYDpggjy0PLitG/viwWDY5jlg4JqZ5X7zut4uDx mGItkM2Im2fDs3gepfGUBK4EbHmdoPckRJB56sW+QpcIAPCh1UFGgbFmkGMhYrvuH9OUS 2itUKV+1huMFbO+HlRdMyozVjFhS2iCI42RC+zm3vNsiPh2bK3UIN7khq3E9t4kweDg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795270759; 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=AyZSPZSAoyu0XMTrk6TSL45fPCkVoxP9QhoH2Zd6Zfo=; b=gw7waEgrd2Ay0hPjpEElJQxUMBLlCo22lfrIbBhhFsEdGTNuwEgfcgY5L2RTmptotRDM N84s+irUU353LuXIPbCY3rBpcgnQgGuaWeuoFvTjlpchlSJxZka+LHOcgp5yYJtRiERoA ZpUZViF2VpgHOPBxU94lPgrZyn4az8uhrJ4IrPSDEGuDNMglQRV6NmGoycsJW77PJmT6Q Sb+mOhQsFcGzgQDeGqgpIR1ag/DEVs/OfzXyXpIoZdCBqq/8OdJZqRdYzj0W5SW9U+Wpd 3OTRM9f/+1Of1LgEJBb24OJbv+LrImeOh6WaN2JJoSq0AOaZIhT6XfJENyWGZ5Ti/oQ== 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="pjsVH/iO"; arc=none smtp.remote-ip=115.124.28.4 Received: from out28-4.mail.aliyun.com (out28-4.mail.aliyun.com [115.124.28.4]) (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 D6022606A32C; Sat, 21 Nov 2026 14:19:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D6022606A32C Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=xiaopeng.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xiaopeng.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=xiaopeng.com header.i=@xiaopeng.com header.a=rsa-sha256 header.s=default header.b=pjsVH/iO DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xiaopeng.com; s=default; t=1795270749; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=AyZSPZSAoyu0XMTrk6TSL45fPCkVoxP9QhoH2Zd6Zfo=; b=pjsVH/iOOVfb8Wqp7YXvv9oVrYDkuf72Nv+t7GFzg67WHcZF79UFvZn6/ZR12+1Vi8TV3dBpu5hKYx5YnfAsWo/VAcIR+LKSpunWuV2hih7L7UaVfShxda2t48mduQZ+4uQnIJYW6yMwxsCSqjkKyl5KD76fuMw+u1QTrqa+lhk= X-Alimail-AntiSpam: AC=CONTINUE;BC=0.05731619|-1;CH=green;DM=|CONTINUE|false|;DS=CONTINUE|ham_system_inform|0.00349499-0.00128547-0.99522;FP=11260164001253854944|0|0|0|0|-1|-1|-1;HT=maildocker-contentspam033040092104;MF=fangxy@xiaopeng.com;NM=1;PH=DS;RN=14;RT=14;SR=0;TI=SMTPD_---.k7GCEYM_1795270746; Received: from localhost.localdomain(mailfrom:fangxy@xiaopeng.com fp:SMTPD_---.k7GCEYM_1795270746 cluster:ay29) by smtp.aliyun-inc.com; Sat, 21 Nov 2026 22:19:09 +0800 From: Fang Xieyan To: loic.poulain@oss.qualcomm.com, ryazanov.s.a@gmail.com, netdev@vger.kernel.org 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 Subject: [PATCH net v4 2/5] net: wwan: iosm: validate the ADGH datagram length Date: Sat, 21 Nov 2026 22:18:47 +0800 Message-ID: <20261121141850.73754-3-fangxy@xiaopeng.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20261121141850.73754-1-fangxy@xiaopeng.com> References: <20261121141850.73754-1-fangxy@xiaopeng.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" ipc_mux_dl_adgh_decode() takes adgh->length from the device and hands adgh_len - packet_offset to the network stack as the payload size of the cloned skb, without bounding adgh_len. A length below the header plus its negotiated padding wraps the subtraction, skb_trim() keeps the clone unchanged and the stack gets the whole rest of the block. A length equal to packet_offset yields a zero length clone that ipc_wwan_receive() still reads skb->data[0] from. Require the datagram length to exceed packet_offset and to fit into skb->len, and drop the block otherwise. Fixes: c34ca4f32c24 ("net: wwan: iosm: fix incorrect skb length") Cc: stable@vger.kernel.org Signed-off-by: Fang Xieyan --- drivers/net/wwan/iosm/iosm_ipc_mux_codec.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/net/wwan/iosm/iosm_ipc_mux_codec.c b/drivers/net/wwan/= iosm/iosm_ipc_mux_codec.c index 5c33171ca701..65421f6b4c91 100644 --- a/drivers/net/wwan/iosm/iosm_ipc_mux_codec.c +++ b/drivers/net/wwan/iosm/iosm_ipc_mux_codec.c @@ -473,6 +473,15 @@ static void ipc_mux_dl_adgh_decode(struct iosm_mux *ip= c_mux, if_id +=3D ipc_mux->wwan_q_offset; adgh_len =3D le16_to_cpu(adgh->length); =20 + /* The device supplied length bounds the datagram. It has to + * exceed packet_offset and fit into the received block. + */ + if (adgh_len <=3D packet_offset || adgh_len > skb->len) { + dev_err(ipc_mux->dev, "invalid ADGH length %u, skb len %u", + adgh_len, skb->len); + return; + } + /* Pass the packet to the netif layer */ rc =3D ipc_mux_net_receive(ipc_mux, if_id, wwan, packet_offset, adgh->service_class, skb, --=20 2.50.1 From nobody Tue Nov 24 12:37:57 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=115.124.28.98 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== 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== 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 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) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 5D3C3606A33A Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=xiaopeng.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xiaopeng.com 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 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; 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 From: Fang Xieyan To: loic.poulain@oss.qualcomm.com, ryazanov.s.a@gmail.com, netdev@vger.kernel.org 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 Subject: [PATCH net v4 3/5] net: wwan: iosm: bound the ACBH command chain walk Date: Sat, 21 Nov 2026 22:18:48 +0800 Message-ID: <20261121141850.73754-4-fangxy@xiaopeng.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20261121141850.73754-1-fangxy@xiaopeng.com> References: <20261121141850.73754-1-fangxy@xiaopeng.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Signed-off-by: Fang Xieyan --- 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 =3D 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; =20 + if (skb->len < sizeof(struct mux_acbh)) + return; + acbh =3D (struct mux_acbh *)(skb->data); block =3D (u8 *)(skb->data); + block_length =3D le32_to_cpu(acbh->block_length); =20 - next_cmd_index =3D le32_to_cpu(acbh->first_cmd_index); - next_cmd_index =3D 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 =3D le32_to_cpu(acbh->first_cmd_index); + + while (cmd_index !=3D 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; =20 - while (next_cmd_index !=3D 0) { - cmdh =3D (struct mux_cmdh *)&block[next_cmd_index]; + cmdh =3D (struct mux_cmdh *)&block[cmd_index]; next_cmd_index =3D 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 !=3D 0 && + (next_cmd_index <=3D 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 =3D offsetof(struct mux_cmdh, param) + - sizeof(cmdh->param.flow_ctl); + size =3D hdr_len + sizeof(cmdh->param.flow_ctl); ipc_mux_dl_acbcmd_decode(ipc_mux, cmdh, size); } + + cmd_index =3D next_cmd_index; } } =20 --=20 2.50.1 From nobody Tue Nov 24 12:37:57 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=115.124.28.145 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795270765; b=YbCkpOOfuDqayhsCMMkfpsfBGm6qbdntvfXUPFW7hd98wh+aI73mULU9SfBicuT2EaGz 3a4puouA5L0iK1f8w7cyzDpsV67EoqjgcroSokNwSGr+4My9TjTCbCwdBTlvfXDgVDEbG CPqZPB9K9Yb0PV1NR+c20yDuvk5xIyvLsYUIL+kYT70yWqKkvLqUkNe86y35Zkq1YG3ho qO6YqsRLOqvLunNnvTDjumU2zD8rcyXUjGTwkcbt948OXIIdIxD3IaY+jCwQdvOiJoML7 Wuwa2XxD/BHu8G2q8uY8RrOL/no0hZ5cwRc2bPBF2DLImeD2UX8x7ckh5eXBprEOSQg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795270765; 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=Pqdb1CZmw00+aWMEKUmzfViHJG+GiKGhJXCKYqajwNg=; b=QzY4/E8sqSLZWqwWefC1A86nmlEUPthRRgkXqA8HvAI/NFm98i/rf2+yImgAreynkjwl GSLV1IvGuuiYnOlQY/cmcnw/8YkCNHj9J6AGXEDhLAFuT+IZ5iDSdmAIF4Rw/Cd5HYuJK tVJrpE4wuYqSFvKZhO/t9ZXs+4sQ3aMXvSjWcaZkLad7+IJ42crZGljG6siEYr+iyVg1B hq5kVMiNGLuaENBpwgls3aMxWWMj4Sr7XrHX3z77W9Z9boYOECeqN+beNon5wVuHLN3KA esxxcocZap0NRfStvmloFXHc8sATOKU1Re3xs5DgEqFgOEb2Otym6t3H3szSz/ZsWKw== 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=qeC99Cbo; arc=none smtp.remote-ip=115.124.28.145 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 68226606A338; Sat, 21 Nov 2026 14:19:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 68226606A338 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=xiaopeng.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xiaopeng.com 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=qeC99Cbo DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xiaopeng.com; s=default; t=1795270755; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=Pqdb1CZmw00+aWMEKUmzfViHJG+GiKGhJXCKYqajwNg=; b=qeC99CboETZZmO/pp6EHlJhZBWRlRw0+RBxEVbL9YJTD3QjWtf+AJjil8eidI8pnk9sIzcIIC7jdiGTkkbyTi5UqqIG8OlGjJ2aAZwoTsSqMEdl3hkjtrCTnLHbYEZTHEsvizi8odoXXafS/RSAc/6ThvkiGKFFQi5z6wNTJtf8= X-Alimail-AntiSpam: AC=CONTINUE;BC=0.04436263|-1;CH=green;DM=|CONTINUE|false|;DS=CONTINUE|ham_system_inform|0.00745487-0.000394108-0.992151;FP=16019482191521677331|13|3|17|0|-1|-1|-1;HT=maildocker-contentspam033037026024;MF=fangxy@xiaopeng.com;NM=1;PH=DS;RN=14;RT=14;SR=0;TI=SMTPD_---.k7GCEcI_1795270753; Received: from localhost.localdomain(mailfrom:fangxy@xiaopeng.com fp:SMTPD_---.k7GCEcI_1795270753 cluster:ay29) by smtp.aliyun-inc.com; Sat, 21 Nov 2026 22:19:15 +0800 From: Fang Xieyan To: loic.poulain@oss.qualcomm.com, ryazanov.s.a@gmail.com, netdev@vger.kernel.org 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 Subject: [PATCH net v4 4/5] net: wwan: iosm: pass the DL command parameter by pointer Date: Sat, 21 Nov 2026 22:18:49 +0800 Message-ID: <20261121141850.73754-5-fangxy@xiaopeng.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20261121141850.73754-1-fangxy@xiaopeng.com> References: <20261121141850.73754-1-fangxy@xiaopeng.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" ipc_mux_dl_cmdresps_decode_process() takes the twelve byte union mux_cmd_param by value, so every received command copies the whole union out of the skb even when its type only needs one member, reading past what arrived for a truncated response. The driver also builds its link status response inside the received block. Take the parameter as a const pointer and keep the lite path response in a local variable; the aggregated path sends no response parameter. The session response path still copies the full parameter union here. The next patch adds the received parameter length check and restricts each response copy to its own member. This change is a prerequisite for that fix and is tagged for stable alongside it. Fixes: 9413491e20e1 ("net: iosm: encode or decode datagram") Cc: stable@vger.kernel.org Reviewed-by: Guanglei Zhu Signed-off-by: Fang Xieyan --- drivers/net/wwan/iosm/iosm_ipc_mux_codec.c | 29 ++++++++++------------ 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/drivers/net/wwan/iosm/iosm_ipc_mux_codec.c b/drivers/net/wwan/= iosm/iosm_ipc_mux_codec.c index a8448e273c02..3f93d7293785 100644 --- a/drivers/net/wwan/iosm/iosm_ipc_mux_codec.c +++ b/drivers/net/wwan/iosm/iosm_ipc_mux_codec.c @@ -184,7 +184,7 @@ void ipc_mux_netif_tx_flowctrl(struct mux_session *sess= ion, int idx, bool on) } =20 static int ipc_mux_dl_cmdresps_decode_process(struct iosm_mux *ipc_mux, - union mux_cmd_param param, + const union mux_cmd_param *param, __le32 command_type, u8 if_id, __le32 transaction_id) { @@ -194,7 +194,7 @@ static int ipc_mux_dl_cmdresps_decode_process(struct io= sm_mux *ipc_mux, case MUX_CMD_OPEN_SESSION_RESP: case MUX_CMD_CLOSE_SESSION_RESP: /* Resume the control application. */ - acb->got_param =3D param; + acb->got_param =3D *param; break; =20 case MUX_LITE_CMD_FLOW_CTL_ACK: @@ -318,7 +318,7 @@ static void ipc_mux_dl_cmd_decode(struct iosm_mux *ipc_= mux, struct sk_buff *skb) __le32 trans_id =3D cmdh->transaction_id; int size; =20 - if (ipc_mux_dl_cmdresps_decode_process(ipc_mux, cmdh->param, + if (ipc_mux_dl_cmdresps_decode_process(ipc_mux, &cmdh->param, cmdh->command_type, cmdh->if_id, cmdh->transaction_id)) { /* Unable to decode command response indicates the cmd_type @@ -333,14 +333,15 @@ static void ipc_mux_dl_cmd_decode(struct iosm_mux *ip= c_mux, struct sk_buff *skb) /* Decoded command may need a response. Give the * response according to the command type. */ + union mux_cmd_param response =3D {}; union mux_cmd_param *mux_cmd =3D NULL; size_t size =3D 0; u32 cmd =3D MUX_LITE_CMD_LINK_STATUS_REPORT_RESP; =20 if (cmdh->command_type =3D=3D cpu_to_le32(MUX_LITE_CMD_LINK_STATUS_REPORT)) { - mux_cmd =3D &cmdh->param; - mux_cmd->link_status_resp.response =3D + mux_cmd =3D &response; + response.link_status_resp.response =3D cpu_to_le32(MUX_CMD_RESP_SUCCESS); /* response field is u32 */ size =3D sizeof(u32); @@ -500,26 +501,22 @@ static void ipc_mux_dl_acbcmd_decode(struct iosm_mux = *ipc_mux, u32 fctl_dis =3D IOSM_AGGR_MUX_CMD_FLOW_CTL_DISABLE; u32 fctl_ena =3D IOSM_AGGR_MUX_CMD_FLOW_CTL_ENABLE; u32 fctl_ack =3D IOSM_AGGR_MUX_CMD_FLOW_CTL_ACK; - union mux_cmd_param *cmd_p =3D NULL; u32 cmd =3D link_st; u32 trans_id; =20 if (!ipc_mux_dl_cmds_decode_process(ipc_mux, &cmdh->param, cmdh->command_type, cmdh->if_id, cmdh->cmd_len, size)) { - size =3D 0; - if (cmdh->command_type =3D=3D cpu_to_le32(link_st)) { - cmd_p =3D &cmdh->param; - cmd_p->link_status_resp.response =3D MUX_CMD_RESP_SUCCESS; - } else if ((cmdh->command_type =3D=3D cpu_to_le32(fctl_ena)) || - (cmdh->command_type =3D=3D cpu_to_le32(fctl_dis))) { + if (cmdh->command_type =3D=3D cpu_to_le32(fctl_ena) || + cmdh->command_type =3D=3D cpu_to_le32(fctl_dis)) cmd =3D fctl_ack; - } else { + else if (cmdh->command_type !=3D cpu_to_le32(link_st)) return; - } + trans_id =3D le32_to_cpu(cmdh->transaction_id); + /* No response parameter is sent in the aggregated protocol. */ ipc_mux_dl_acb_send_cmds(ipc_mux, cmd, cmdh->if_id, - trans_id, cmd_p, size, false, true); + trans_id, NULL, 0, false, true); } } =20 @@ -571,7 +568,7 @@ static void ipc_mux_dl_acb_decode(struct iosm_mux *ipc_= mux, struct sk_buff *skb) skb->len - next_cmd_index < hdr_len)) break; =20 - if (ipc_mux_dl_cmdresps_decode_process(ipc_mux, cmdh->param, + if (ipc_mux_dl_cmdresps_decode_process(ipc_mux, &cmdh->param, cmdh->command_type, cmdh->if_id, cmdh->transaction_id)) { --=20 2.50.1 From nobody Tue Nov 24 12:37:57 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=115.124.28.221 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795270770; b=fqAuq9/WfxfGR9/LYvaJk1ITh+eftKVDiaqo5libsxF1bO/SIsokuFwDgdrCE6wrKvJb cUM3DOo5cHoRAP65umXMRocCoZ8EpXqPlRZL9iA4KZvANrIZH2rccqwULGhC7+8/N8zSL rgLGPUVskp+AWranQo+cLFzVEvwM+Qr5eRcIshIu+EXd4FqQl/FLswMPXsuB6ooP8J2ag 0zqNOOzu98RQ6Qu93a/1JhxWwRcI3CeHQDaQKqSlkz/I08IQg0KJtr+518b9fR3jy1fmx dRXm6IVNEntcRPQRRc9UWOuucasxtwvtN7ghgR6H5BrYry+W8u52mjeOCYwngq4Wvaw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795270770; 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=EjP5V1wK+o8RHYcg61HZrDjyGwB3sEbKCFTcA45qvlY=; b=4S6sIJ3FM/cwKZREroc9+4eCwaWfnxza+pKgYXPRGbihjWwDv63jsiXvZfqdw7z9yTmV nRurgDq5cLostI8g6Nxkop/AcsFvlf5yfJTNvRnaWgS+DeSm85x8zNZt9S1u+TE36vhfQ jUqhT8h/+oiGevdFts3o8c5zace/PkbMSx9NDIpTBeiS+nJS2w1QQsQ5BEOobB3XPvAG9 lEusTtNMZIR+J1xWepEEWcyI7CiTSXs8WncOMTcCldGAu+bxoQzOkjz1I35KQD2zUjEZr 8BmdVf/iaGN8EJ/qevQSrXgS3sBeEKS0+NMOebcyfs4Ju0K+SW2FrxQjK5rhDPKNDJw== 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=gd9wCmHy; arc=none smtp.remote-ip=115.124.28.221 Received: from out28-221.mail.aliyun.com (out28-221.mail.aliyun.com [115.124.28.221]) (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 16875606A6BA; Sat, 21 Nov 2026 14:19:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 16875606A6BA Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=xiaopeng.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xiaopeng.com 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=gd9wCmHy DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xiaopeng.com; s=default; t=1795270758; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=EjP5V1wK+o8RHYcg61HZrDjyGwB3sEbKCFTcA45qvlY=; b=gd9wCmHyXZRjp/iF6gmgwvSgdflrC8lXdDyosBFQNKcxFo2n5GC4EobRmTI4h0XYjLJl3fV9tatp4+zeEKm6guqdEduu02PNO8mgNaGevutT1niA6uIXZpqXRdk7pkaWg9LKuJLyqWBsP6rL1UYCrzA770E3hgfPn7OS/KxqT3I= X-Alimail-AntiSpam: AC=CONTINUE;BC=0.04436259|-1;CH=green;DM=|CONTINUE|false|;DS=CONTINUE|ham_system_inform|0.00490976-0.000198701-0.994892;FP=16021593803604901968|13|3|17|0|-1|-1|-1;HT=maildocker-contentspam033045099153;MF=fangxy@xiaopeng.com;NM=1;PH=DS;RN=14;RT=14;SR=0;TI=SMTPD_---.k7GCEds_1795270755; Received: from localhost.localdomain(mailfrom:fangxy@xiaopeng.com fp:SMTPD_---.k7GCEds_1795270755 cluster:ay29) by smtp.aliyun-inc.com; Sat, 21 Nov 2026 22:19:17 +0800 From: Fang Xieyan To: loic.poulain@oss.qualcomm.com, ryazanov.s.a@gmail.com, netdev@vger.kernel.org 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 Subject: [PATCH net v4 5/5] net: wwan: iosm: validate the command parameter length Date: Sat, 21 Nov 2026 22:18:50 +0800 Message-ID: <20261121141850.73754-6-fangxy@xiaopeng.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20261121141850.73754-1-fangxy@xiaopeng.com> References: <20261121141850.73754-1-fangxy@xiaopeng.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Both command decoders read members of the parameter union without knowing how long the parameter actually is, so a truncated OPEN_SESSION_RESP copies bytes past the command into acb->got_param and resumes the session establishment waiting on it, and a short FLOW_CTL builds the flow control mask from whatever bytes followed. Derive the parameter length from what the command owns: the bytes beyond the header in MUX Lite, the bytes up to the next command in an aggregated block, or up to the end of the block for the last one. Check the member each command type uses against that length and return -EMSGSIZE when it does not fit; the callers drop the command, and in an aggregated block the walk ends there. Unknown types still return -EINVAL and the walk continues. cmd_len is passed to the decoder unchanged. Fixes: 9413491e20e1 ("net: iosm: encode or decode datagram") Cc: stable@vger.kernel.org Signed-off-by: Fang Xieyan --- drivers/net/wwan/iosm/iosm_ipc_mux_codec.c | 105 +++++++++++++++------ 1 file changed, 75 insertions(+), 30 deletions(-) diff --git a/drivers/net/wwan/iosm/iosm_ipc_mux_codec.c b/drivers/net/wwan/= iosm/iosm_ipc_mux_codec.c index 3f93d7293785..b2bd53c5ba30 100644 --- a/drivers/net/wwan/iosm/iosm_ipc_mux_codec.c +++ b/drivers/net/wwan/iosm/iosm_ipc_mux_codec.c @@ -185,6 +185,7 @@ void ipc_mux_netif_tx_flowctrl(struct mux_session *sess= ion, int idx, bool on) =20 static int ipc_mux_dl_cmdresps_decode_process(struct iosm_mux *ipc_mux, const union mux_cmd_param *param, + size_t param_len, __le32 command_type, u8 if_id, __le32 transaction_id) { @@ -192,9 +193,18 @@ static int ipc_mux_dl_cmdresps_decode_process(struct i= osm_mux *ipc_mux, =20 switch (le32_to_cpu(command_type)) { case MUX_CMD_OPEN_SESSION_RESP: - case MUX_CMD_CLOSE_SESSION_RESP: + if (param_len < sizeof(param->open_session_resp)) + return -EMSGSIZE; + /* Resume the control application. */ - acb->got_param =3D *param; + acb->got_param.open_session_resp =3D param->open_session_resp; + break; + + case MUX_CMD_CLOSE_SESSION_RESP: + if (param_len < sizeof(param->close_session_resp)) + return -EMSGSIZE; + + acb->got_param.close_session_resp =3D param->close_session_resp; break; =20 case MUX_LITE_CMD_FLOW_CTL_ACK: @@ -229,6 +239,7 @@ static int ipc_mux_dl_cmdresps_decode_process(struct io= sm_mux *ipc_mux, =20 static int ipc_mux_dl_cmds_decode_process(struct iosm_mux *ipc_mux, union mux_cmd_param *param, + size_t param_len, __le32 command_type, u8 if_id, __le16 cmd_len, int size) { @@ -242,6 +253,9 @@ static int ipc_mux_dl_cmds_decode_process(struct iosm_m= ux *ipc_mux, case MUX_LITE_CMD_FLOW_CTL: case IOSM_AGGR_MUX_CMD_FLOW_CTL_DISABLE: =20 + if (param_len < sizeof(param->flow_ctl)) + return -EMSGSIZE; + if (if_id >=3D IPC_MEM_MUX_IP_SESSION_ENTRIES) { dev_err(ipc_mux->dev, "if_id [%d] not valid", if_id); @@ -315,18 +329,26 @@ static int ipc_mux_dl_cmds_decode_process(struct iosm= _mux *ipc_mux, static void ipc_mux_dl_cmd_decode(struct iosm_mux *ipc_mux, struct sk_buff= *skb) { struct mux_lite_cmdh *cmdh =3D (struct mux_lite_cmdh *)skb->data; + size_t hdr_len =3D offsetof(struct mux_lite_cmdh, param); + size_t param_len =3D skb->len > hdr_len ? skb->len - hdr_len : 0; __le32 trans_id =3D cmdh->transaction_id; - int size; + int ret, size; + + ret =3D ipc_mux_dl_cmdresps_decode_process(ipc_mux, &cmdh->param, + param_len, + cmdh->command_type, + cmdh->if_id, + cmdh->transaction_id); + if (ret =3D=3D -EMSGSIZE) + return; =20 - if (ipc_mux_dl_cmdresps_decode_process(ipc_mux, &cmdh->param, - cmdh->command_type, cmdh->if_id, - cmdh->transaction_id)) { + if (ret) { /* Unable to decode command response indicates the cmd_type * may be a command instead of response. So try to decoding it. */ - size =3D offsetof(struct mux_lite_cmdh, param) + - sizeof(cmdh->param.flow_ctl); + size =3D hdr_len + sizeof(cmdh->param.flow_ctl); if (!ipc_mux_dl_cmds_decode_process(ipc_mux, &cmdh->param, + param_len, cmdh->command_type, cmdh->if_id, cmdh->cmd_len, size)) { @@ -494,8 +516,9 @@ static void ipc_mux_dl_adgh_decode(struct iosm_mux *ipc= _mux, ipc_mux->session[if_id].flush =3D 1; } =20 -static void ipc_mux_dl_acbcmd_decode(struct iosm_mux *ipc_mux, - struct mux_cmdh *cmdh, int size) +static int ipc_mux_dl_acbcmd_decode(struct iosm_mux *ipc_mux, + struct mux_cmdh *cmdh, size_t param_len, + int size) { u32 link_st =3D IOSM_AGGR_MUX_CMD_LINK_STATUS_REPORT_RESP; u32 fctl_dis =3D IOSM_AGGR_MUX_CMD_FLOW_CTL_DISABLE; @@ -503,32 +526,39 @@ static void ipc_mux_dl_acbcmd_decode(struct iosm_mux = *ipc_mux, u32 fctl_ack =3D IOSM_AGGR_MUX_CMD_FLOW_CTL_ACK; u32 cmd =3D link_st; u32 trans_id; + int ret; =20 - if (!ipc_mux_dl_cmds_decode_process(ipc_mux, &cmdh->param, - cmdh->command_type, cmdh->if_id, - cmdh->cmd_len, size)) { - if (cmdh->command_type =3D=3D cpu_to_le32(fctl_ena) || - cmdh->command_type =3D=3D cpu_to_le32(fctl_dis)) - cmd =3D fctl_ack; - else if (cmdh->command_type !=3D cpu_to_le32(link_st)) - return; - - trans_id =3D le32_to_cpu(cmdh->transaction_id); - /* No response parameter is sent in the aggregated protocol. */ - ipc_mux_dl_acb_send_cmds(ipc_mux, cmd, cmdh->if_id, - trans_id, NULL, 0, false, true); - } + ret =3D ipc_mux_dl_cmds_decode_process(ipc_mux, &cmdh->param, param_len, + cmdh->command_type, cmdh->if_id, + cmdh->cmd_len, size); + if (ret) + return ret; + + if (cmdh->command_type =3D=3D cpu_to_le32(fctl_ena) || + cmdh->command_type =3D=3D cpu_to_le32(fctl_dis)) + cmd =3D fctl_ack; + else if (cmdh->command_type !=3D cpu_to_le32(link_st)) + return -EINVAL; + + trans_id =3D le32_to_cpu(cmdh->transaction_id); + + /* No response parameter is sent in the aggregated protocol. */ + ipc_mux_dl_acb_send_cmds(ipc_mux, cmd, cmdh->if_id, trans_id, + NULL, 0, false, true); + + return 0; } =20 /* 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 =3D offsetof(struct mux_cmdh, param); + size_t cmd_end, param_len; struct mux_acbh *acbh; struct mux_cmdh *cmdh; u32 block_length, cmd_index, next_cmd_index; u8 *block; - int size; + int ret, size; =20 if (skb->len < sizeof(struct mux_acbh)) return; @@ -568,12 +598,27 @@ static void ipc_mux_dl_acb_decode(struct iosm_mux *ip= c_mux, struct sk_buff *skb) skb->len - next_cmd_index < hdr_len)) break; =20 - if (ipc_mux_dl_cmdresps_decode_process(ipc_mux, &cmdh->param, - cmdh->command_type, - cmdh->if_id, - cmdh->transaction_id)) { + /* + * A command owns the bytes up to the next one, the last + * one of the chain those up to the end of what arrived. + */ + cmd_end =3D next_cmd_index ? next_cmd_index : skb->len; + param_len =3D cmd_end - cmd_index - hdr_len; + + ret =3D ipc_mux_dl_cmdresps_decode_process(ipc_mux, &cmdh->param, + param_len, + cmdh->command_type, + cmdh->if_id, + cmdh->transaction_id); + if (ret =3D=3D -EMSGSIZE) + break; + + if (ret) { size =3D hdr_len + sizeof(cmdh->param.flow_ctl); - ipc_mux_dl_acbcmd_decode(ipc_mux, cmdh, size); + ret =3D ipc_mux_dl_acbcmd_decode(ipc_mux, cmdh, param_len, + size); + if (ret =3D=3D -EMSGSIZE) + break; } =20 cmd_index =3D next_cmd_index; --=20 2.50.1