From: Fang Xieyan <fangxy@xiaopeng.com>
To: Loic Poulain <loic.poulain@oss.qualcomm.com>,
Sergey Ryazanov <ryazanov.s.a@gmail.com>,
netdev@vger.kernel.org
Cc: "David S . Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@kernel.org>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Andrew Lunn <andrew+netdev@lunn.ch>,
Simon Horman <horms@kernel.org>,
Johannes Berg <johannes@sipsolutions.net>,
Maoyi Xie <maoyixie.tju@gmail.com>,
Guanglei Zhu <zhugl3@xiaopeng.com>,
linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: [PATCH net v3 3/5] net: wwan: iosm: bound the ACBH command chain walk
Date: Fri, 20 Nov 2026 18:55:57 +0800 [thread overview]
Message-ID: <20261120105559.54519-4-fangxy@xiaopeng.com> (raw)
In-Reply-To: <20261120105559.54519-1-fangxy@xiaopeng.com>
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 341c58b851cb..f1a742b20eab 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
next prev parent reply other threads:[~2026-11-20 10:56 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-20 10:55 [PATCH net v3 0/5] net: wwan: iosm: validate MUX DL lengths and offsets Fang Xieyan
2026-11-20 10:55 ` [PATCH net v3 1/5] net: wwan: iosm: validate the MUX DL block length Fang Xieyan
2026-11-20 10:55 ` [PATCH net v3 2/5] net: wwan: iosm: validate the ADGH datagram length Fang Xieyan
2026-11-20 10:55 ` Fang Xieyan [this message]
2026-11-20 10:55 ` [PATCH net v3 4/5] net: wwan: iosm: pass the DL command parameter by pointer Fang Xieyan
2026-11-20 10:55 ` [PATCH net v3 5/5] net: wwan: iosm: validate the command parameter length Fang Xieyan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261120105559.54519-4-fangxy@xiaopeng.com \
--to=fangxy@xiaopeng.com \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=horms@kernel.org \
--cc=johannes@sipsolutions.net \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=loic.poulain@oss.qualcomm.com \
--cc=maoyixie.tju@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=ryazanov.s.a@gmail.com \
--cc=stable@vger.kernel.org \
--cc=zhugl3@xiaopeng.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®