* [PATCH net v2 0/5] net: wwan: iosm: validate MUX DL lengths and offsets
@ 2026-11-17 17:39 Fang Xieyan
2026-11-17 17:39 ` [PATCH net v2 1/5] net: wwan: iosm: validate the MUX DL block length Fang Xieyan
` (4 more replies)
0 siblings, 5 replies; 7+ messages in thread
From: Fang Xieyan @ 2026-11-17 17:39 UTC (permalink / raw)
To: Loic Poulain, Sergey Ryazanov, netdev
Cc: David S . Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Andrew Lunn, Simon Horman, Johannes Berg, Maoyi Xie, linux-kernel
The MUX downlink decoders trust several modem supplied lengths and
offsets without bounding them against what actually arrived: the block
size from the transfer descriptor, the ADGH datagram length, the ACBH
block length, the command chain offsets and the declared parameter
length. A truncated or enlarged DL block makes the driver read past the
received data, hand the network stack an undeclared payload, or walk a
command chain that loops or redecodes the same bytes. The aggregated
datagram block path is already covered by commit 526b8ef54668 ("net:
wwan: iosm: bound device offsets in the MUX downlink decoder") and is
not touched here.
This series adds those bounds. No command type, response or protocol
semantics change, so a conforming modem behaves exactly as before. A
parameter too short for the member its command type reads is dropped
with -EMSGSIZE, which also ends an aggregated block at that command.
Patch 4 is the prep change for patch 5; both carry Cc: stable, as patch
5 cannot be backported without patch 4.
cmd_len is not a parameter bound in either path. In an aggregated block
the boundary is next_cmd_index, or the end of the received block for the
last command. In MUX Lite there is one command per skb, so the received
length is already everything that command owns; the flow control decoder
treats a mismatching cmd_len as a legacy device, so the field is a
compatibility flag, not a length bound.
Patch 3 bounds the ACBH command chain by the received length rather
than block_length. Although the structure describes block_length as
the length of the aggregated command block, the uplink encoder
initializes it to the ACBH header size and does not update it as
commands are appended, so it cannot delimit the received command
chain. The field is sanity checked, while first_cmd_index and
next_cmd_index are bounded against skb->len. The walk's
array_index_nospec() call is removed: it bounded a byte offset by
sizeof(struct mux_cmdh), zeroing every legal offset past that size.
The offset indexes no array; array_index_nospec() is kept only for
if_id, an actual array index.
Patch 2 relies on the ADGH header check from patch 1, patch 5 on the
ACBH validation from patch 3 and the parameter pointer from patch 4.
Every commit applies and builds individually, W=1 drivers/net/wwan/iosm/
is clean. Found by reviewing the DL decode path against the MUX protocol
structures, not reproduced on a live modem: reaching it needs a device
that truncates or enlarges its own downlink blocks. The series is based
on the net tree at 145480b28ca8.
Changes in v2, all three points from the Sashiko AI review of v1:
- Patch 5 bounds the MUX Lite parameter by the received length alone,
not by cmd_len: v1 dropped legacy FLOW_CTL (cmd_len 16..19) and
OPEN_SESSION_RESP (16..27) even when the parameter bytes had arrived,
defeating the backward compatibility branch in
ipc_mux_dl_cmds_decode_process() that exists for exactly these (the
protocol minimum for cmd_len is 0x10).
- Patch 2 rejects adgh_len == packet_offset too: the zero length clone
reached ipc_wwan_receive(), which reads skb->data[0] without checking
skb->len. mux_dl_process_dg() already rejects the same case for the
aggregated path with dl_head_pad_len >= dg_len.
- Patch 4 gains Fixes: 9413491e20e1 and Cc: stable@vger.kernel.org: its
by-value signature copied all twelve union bytes even for a four byte
response, and patch 5 bounds the session responses, so the two are
needed together. A prerequisite itself marked for stable and present
in the series need not be listed, per stable-kernel-rules.rst.
Patch 1 is unchanged. Patch 3 changes only its changelog and comments.
v1:
https://lore.kernel.org/netdev/20261112125201.1019-1-fangxy@xiaopeng.com/
Fang Xieyan (5):
net: wwan: iosm: validate the MUX DL block length
net: wwan: iosm: validate the ADGH datagram length
net: wwan: iosm: bound the ACBH command chain walk
net: wwan: iosm: pass the DL command parameter by pointer
net: wwan: iosm: validate the command parameter length
drivers/net/wwan/iosm/iosm_ipc_mux_codec.c | 187 ++++++++++++++++-----
1 file changed, 141 insertions(+), 46 deletions(-)
--
2.50.1
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH net v2 1/5] net: wwan: iosm: validate the MUX DL block length
2026-11-17 17:39 [PATCH net v2 0/5] net: wwan: iosm: validate MUX DL lengths and offsets Fang Xieyan
@ 2026-11-17 17:39 ` Fang Xieyan
2026-11-17 17:39 ` [PATCH net v2 2/5] net: wwan: iosm: validate the ADGH datagram length Fang Xieyan
` (3 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: Fang Xieyan @ 2026-11-17 17:39 UTC (permalink / raw)
To: Loic Poulain, Sergey Ryazanov, netdev
Cc: David S . Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Andrew Lunn, Simon Horman, Johannes Berg, Maoyi Xie, linux-kernel,
stable, Guanglei Zhu
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 <zhugl3@xiaopeng.com>
Signed-off-by: Fang Xieyan <fangxy@xiaopeng.com>
---
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, struct sk_buff *skb)
if (!skb->data)
return;
+ 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 = le32_to_cpup((__le32 *)skb->data);
@@ -704,15 +709,24 @@ void ipc_mux_dl_decode(struct iosm_mux *ipc_mux, struct 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;
@@ -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");
}
+free_skb:
ipc_pcie_kfree_skb(ipc_mux->pcie, skb);
}
--
2.50.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH net v2 2/5] net: wwan: iosm: validate the ADGH datagram length
2026-11-17 17:39 [PATCH net v2 0/5] net: wwan: iosm: validate MUX DL lengths and offsets Fang Xieyan
2026-11-17 17:39 ` [PATCH net v2 1/5] net: wwan: iosm: validate the MUX DL block length Fang Xieyan
@ 2026-11-17 17:39 ` Fang Xieyan
2026-11-17 17:39 ` [PATCH net v2 3/5] net: wwan: iosm: bound the ACBH command chain walk Fang Xieyan
` (2 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: Fang Xieyan @ 2026-11-17 17:39 UTC (permalink / raw)
To: Loic Poulain, Sergey Ryazanov, netdev
Cc: David S . Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Andrew Lunn, Simon Horman, Johannes Berg, Maoyi Xie, linux-kernel,
stable
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 <fangxy@xiaopeng.com>
---
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 *ipc_mux,
if_id += ipc_mux->wwan_q_offset;
adgh_len = le16_to_cpu(adgh->length);
+ /* The device supplied length bounds the datagram. It has to
+ * exceed packet_offset and fit into the received block.
+ */
+ if (adgh_len <= 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 = ipc_mux_net_receive(ipc_mux, if_id, wwan, packet_offset,
adgh->service_class, skb,
--
2.50.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH net v2 3/5] net: wwan: iosm: bound the ACBH command chain walk
2026-11-17 17:39 [PATCH net v2 0/5] net: wwan: iosm: validate MUX DL lengths and offsets Fang Xieyan
2026-11-17 17:39 ` [PATCH net v2 1/5] net: wwan: iosm: validate the MUX DL block length Fang Xieyan
2026-11-17 17:39 ` [PATCH net v2 2/5] net: wwan: iosm: validate the ADGH datagram length Fang Xieyan
@ 2026-11-17 17:39 ` Fang Xieyan
2026-11-21 18:05 ` netdev-bot+sashiko
2026-11-17 17:39 ` [PATCH net v2 4/5] net: wwan: iosm: pass the DL command parameter by pointer Fang Xieyan
2026-11-17 17:39 ` [PATCH net v2 5/5] net: wwan: iosm: validate the command parameter length Fang Xieyan
4 siblings, 1 reply; 7+ messages in thread
From: Fang Xieyan @ 2026-11-17 17:39 UTC (permalink / raw)
To: Loic Poulain, Sergey Ryazanov, netdev
Cc: David S . Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Andrew Lunn, Simon Horman, Johannes Berg, Maoyi Xie, linux-kernel,
stable, Guanglei Zhu
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
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH net v2 4/5] net: wwan: iosm: pass the DL command parameter by pointer
2026-11-17 17:39 [PATCH net v2 0/5] net: wwan: iosm: validate MUX DL lengths and offsets Fang Xieyan
` (2 preceding siblings ...)
2026-11-17 17:39 ` [PATCH net v2 3/5] net: wwan: iosm: bound the ACBH command chain walk Fang Xieyan
@ 2026-11-17 17:39 ` Fang Xieyan
2026-11-17 17:39 ` [PATCH net v2 5/5] net: wwan: iosm: validate the command parameter length Fang Xieyan
4 siblings, 0 replies; 7+ messages in thread
From: Fang Xieyan @ 2026-11-17 17:39 UTC (permalink / raw)
To: Loic Poulain, Sergey Ryazanov, netdev
Cc: David S . Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Andrew Lunn, Simon Horman, Johannes Berg, Maoyi Xie, linux-kernel,
stable, Guanglei Zhu
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 <zhugl3@xiaopeng.com>
Signed-off-by: Fang Xieyan <fangxy@xiaopeng.com>
---
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 *session, int idx, bool on)
}
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 iosm_mux *ipc_mux,
case MUX_CMD_OPEN_SESSION_RESP:
case MUX_CMD_CLOSE_SESSION_RESP:
/* Resume the control application. */
- acb->got_param = param;
+ acb->got_param = *param;
break;
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 = cmdh->transaction_id;
int size;
- 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 *ipc_mux, struct sk_buff *skb)
/* Decoded command may need a response. Give the
* response according to the command type.
*/
+ union mux_cmd_param response = {};
union mux_cmd_param *mux_cmd = NULL;
size_t size = 0;
u32 cmd = MUX_LITE_CMD_LINK_STATUS_REPORT_RESP;
if (cmdh->command_type ==
cpu_to_le32(MUX_LITE_CMD_LINK_STATUS_REPORT)) {
- mux_cmd = &cmdh->param;
- mux_cmd->link_status_resp.response =
+ mux_cmd = &response;
+ response.link_status_resp.response =
cpu_to_le32(MUX_CMD_RESP_SUCCESS);
/* response field is u32 */
size = sizeof(u32);
@@ -500,26 +501,22 @@ static void ipc_mux_dl_acbcmd_decode(struct iosm_mux *ipc_mux,
u32 fctl_dis = IOSM_AGGR_MUX_CMD_FLOW_CTL_DISABLE;
u32 fctl_ena = IOSM_AGGR_MUX_CMD_FLOW_CTL_ENABLE;
u32 fctl_ack = IOSM_AGGR_MUX_CMD_FLOW_CTL_ACK;
- union mux_cmd_param *cmd_p = NULL;
u32 cmd = link_st;
u32 trans_id;
if (!ipc_mux_dl_cmds_decode_process(ipc_mux, &cmdh->param,
cmdh->command_type, cmdh->if_id,
cmdh->cmd_len, size)) {
- size = 0;
- if (cmdh->command_type == cpu_to_le32(link_st)) {
- cmd_p = &cmdh->param;
- cmd_p->link_status_resp.response = MUX_CMD_RESP_SUCCESS;
- } else if ((cmdh->command_type == cpu_to_le32(fctl_ena)) ||
- (cmdh->command_type == cpu_to_le32(fctl_dis))) {
+ if (cmdh->command_type == cpu_to_le32(fctl_ena) ||
+ cmdh->command_type == cpu_to_le32(fctl_dis))
cmd = fctl_ack;
- } else {
+ else if (cmdh->command_type != cpu_to_le32(link_st))
return;
- }
+
trans_id = 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);
}
}
@@ -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;
- 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)) {
--
2.50.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH net v2 5/5] net: wwan: iosm: validate the command parameter length
2026-11-17 17:39 [PATCH net v2 0/5] net: wwan: iosm: validate MUX DL lengths and offsets Fang Xieyan
` (3 preceding siblings ...)
2026-11-17 17:39 ` [PATCH net v2 4/5] net: wwan: iosm: pass the DL command parameter by pointer Fang Xieyan
@ 2026-11-17 17:39 ` Fang Xieyan
4 siblings, 0 replies; 7+ messages in thread
From: Fang Xieyan @ 2026-11-17 17:39 UTC (permalink / raw)
To: Loic Poulain, Sergey Ryazanov, netdev
Cc: David S . Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Andrew Lunn, Simon Horman, Johannes Berg, Maoyi Xie, linux-kernel,
stable
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 <fangxy@xiaopeng.com>
---
drivers/net/wwan/iosm/iosm_ipc_mux_codec.c | 106 +++++++++++++++------
1 file changed, 75 insertions(+), 31 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..592ff99b6c77 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 *session, int idx, bool on)
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 iosm_mux *ipc_mux,
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 = *param;
+ acb->got_param.open_session_resp = 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 = param->close_session_resp;
break;
case MUX_LITE_CMD_FLOW_CTL_ACK:
@@ -229,6 +239,7 @@ static int ipc_mux_dl_cmdresps_decode_process(struct iosm_mux *ipc_mux,
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_mux *ipc_mux,
case MUX_LITE_CMD_FLOW_CTL:
case IOSM_AGGR_MUX_CMD_FLOW_CTL_DISABLE:
+ if (param_len < sizeof(param->flow_ctl))
+ return -EMSGSIZE;
+
if (if_id >= IPC_MEM_MUX_IP_SESSION_ENTRIES) {
dev_err(ipc_mux->dev, "if_id [%d] not valid",
if_id);
@@ -315,19 +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 = (struct mux_lite_cmdh *)skb->data;
+ size_t hdr_len = offsetof(struct mux_lite_cmdh, param);
+ size_t param_len = skb->len > hdr_len ? skb->len - hdr_len : 0;
__le32 trans_id = cmdh->transaction_id;
- int size;
+ int ret, size;
+
+ ret = ipc_mux_dl_cmdresps_decode_process(ipc_mux, &cmdh->param,
+ param_len,
+ cmdh->command_type,
+ cmdh->if_id,
+ cmdh->transaction_id);
+ if (ret == -EMSGSIZE)
+ return;
- 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 = offsetof(struct mux_lite_cmdh, param) +
- sizeof(cmdh->param.flow_ctl);
+ size = hdr_len + sizeof(cmdh->param.flow_ctl);
if (!ipc_mux_dl_cmds_decode_process(ipc_mux, &cmdh->param,
- cmdh->command_type,
+ param_len, cmdh->command_type,
cmdh->if_id,
cmdh->cmd_len, size)) {
/* Decoded command may need a response. Give the
@@ -494,8 +515,9 @@ static void ipc_mux_dl_adgh_decode(struct iosm_mux *ipc_mux,
ipc_mux->session[if_id].flush = 1;
}
-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 = IOSM_AGGR_MUX_CMD_LINK_STATUS_REPORT_RESP;
u32 fctl_dis = IOSM_AGGR_MUX_CMD_FLOW_CTL_DISABLE;
@@ -503,32 +525,39 @@ static void ipc_mux_dl_acbcmd_decode(struct iosm_mux *ipc_mux,
u32 fctl_ack = IOSM_AGGR_MUX_CMD_FLOW_CTL_ACK;
u32 cmd = link_st;
u32 trans_id;
+ int ret;
- 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 == cpu_to_le32(fctl_ena) ||
- cmdh->command_type == cpu_to_le32(fctl_dis))
- cmd = fctl_ack;
- else if (cmdh->command_type != cpu_to_le32(link_st))
- return;
-
- trans_id = 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 = 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 == cpu_to_le32(fctl_ena) ||
+ cmdh->command_type == cpu_to_le32(fctl_dis))
+ cmd = fctl_ack;
+ else if (cmdh->command_type != cpu_to_le32(link_st))
+ return -EINVAL;
+
+ trans_id = 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;
}
/* 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);
+ 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;
if (skb->len < sizeof(struct mux_acbh))
return;
@@ -568,12 +597,27 @@ static void ipc_mux_dl_acb_decode(struct iosm_mux *ipc_mux, struct sk_buff *skb)
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)) {
+ /*
+ * 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 = next_cmd_index ? next_cmd_index : skb->len;
+ param_len = cmd_end - cmd_index - hdr_len;
+
+ ret = ipc_mux_dl_cmdresps_decode_process(ipc_mux, &cmdh->param,
+ param_len,
+ cmdh->command_type,
+ cmdh->if_id,
+ cmdh->transaction_id);
+ if (ret == -EMSGSIZE)
+ break;
+
+ if (ret) {
size = hdr_len + sizeof(cmdh->param.flow_ctl);
- ipc_mux_dl_acbcmd_decode(ipc_mux, cmdh, size);
+ ret = ipc_mux_dl_acbcmd_decode(ipc_mux, cmdh, param_len,
+ size);
+ if (ret == -EMSGSIZE)
+ break;
}
cmd_index = next_cmd_index;
--
2.50.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH net v2 3/5] net: wwan: iosm: bound the ACBH command chain walk
2026-11-17 17:39 ` [PATCH net v2 3/5] net: wwan: iosm: bound the ACBH command chain walk Fang Xieyan
@ 2026-11-21 18:05 ` netdev-bot+sashiko
0 siblings, 0 replies; 7+ messages in thread
From: netdev-bot+sashiko @ 2026-11-21 18:05 UTC (permalink / raw)
To: fangxy
Cc: loic.poulain, ryazanov.s.a, netdev, davem, edumazet, kuba, pabeni,
andrew+netdev, horms, johannes, maoyixie.tju, linux-kernel,
stable, zhugl3
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 0
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [Medium] This patch adds a new early return to ipc_mux_dl_acb_decode()
in drivers/net/wwan/iosm/iosm_ipc_mux_codec.c: `if (block_length <…
--
net: wwan: iosm: bound the ACBH command chain walk
This patch reworks ipc_mux_dl_acb_decode() so that every command offset
in a received Aggregated Command Block is bounded by skb->len. It also
validates next_cmd_index so the walk always moves forward. It removes
the array_index_nospec() call and adds a sanity check on
acbh->block_length.
> diff --git a/drivers/net/wwan/iosm/iosm_ipc_mux_codec.c b/drivers/net/wwan/iosm/iosm_ipc_mux_codec.c
> index 65421f6b4c91e..a8448e273c021 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)
> {
[ ... ]
> 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;
[Severity: Medium]
Could this new check drop every downlink ACB without any message on
some modem firmware?
Before this patch, the DL ACB decoder never read acbh->block_length.
Firmware has never had to keep it between sizeof(struct mux_acbh) and
skb->len. If the check fails, the function returns without logging
anything and the whole block is thrown away.
The comment above says block_length cannot delimit the command chain.
The loop below already bounds every command offset by skb->len. So the
check doesn't seem to add memory safety. Its only effect is that
commands can be dropped.
The only evidence of what this field holds comes from the host's uplink
encoder:
drivers/net/wwan/iosm/iosm_ipc_mux_codec.c:ipc_mux_acb_init() {
...
header->block_length = cpu_to_le32(sizeof(struct mux_acbh));
header->first_cmd_index = header->block_length;
...
}
ipc_mux_acb_add_cmd() never updates it. That doesn't match the
kernel-doc for struct mux_acbh in iosm_ipc_mux_codec.h:
* @block_length: Length (in bytes) of the Aggregated Command Block.
It also suggests the modem doesn't rely on this field in UL ACBs.
Nothing in the tree shows what the modem writes in DL ACBs.
If a firmware writes 0 here, or a value larger than the transfer,
wouldn't every DL ACB be dropped? Some of the effects:
MUX_CMD_OPEN_SESSION_RESP is never processed. ipc_mux_session_open()
then times out waiting for acb->got_response and fails.
IOSM_AGGR_MUX_CMD_FLOW_CTL_ENABLE/DISABLE are never applied.
session->net_tx_stop and session->flow_ctl_mask are not updated, and
no FLOW_CTL_ACK is sent.
LINK_STATUS_REPORT is never answered.
The ADB path isn't really a precedent. mux_dl_process_dg() checks each
datagram index against adbh->block_length as well as skb->len. ACBH
block_length, by contrast, was never read on the DL path before this
patch.
The check is still there after the later patch in this series, "net:
wwan: iosm: validate the command parameter length".
Is the block_length check needed here, since skb->len already bounds
the command chain walk?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261117173940.34970-1-fangxy%40xiaopeng.com
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-11-21 18:05 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-17 17:39 [PATCH net v2 0/5] net: wwan: iosm: validate MUX DL lengths and offsets Fang Xieyan
2026-11-17 17:39 ` [PATCH net v2 1/5] net: wwan: iosm: validate the MUX DL block length Fang Xieyan
2026-11-17 17:39 ` [PATCH net v2 2/5] net: wwan: iosm: validate the ADGH datagram length Fang Xieyan
2026-11-17 17:39 ` [PATCH net v2 3/5] net: wwan: iosm: bound the ACBH command chain walk Fang Xieyan
2026-11-21 18:05 ` netdev-bot+sashiko
2026-11-17 17:39 ` [PATCH net v2 4/5] net: wwan: iosm: pass the DL command parameter by pointer Fang Xieyan
2026-11-17 17:39 ` [PATCH net v2 5/5] net: wwan: iosm: validate the command parameter length Fang Xieyan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox