* [PATCH net v3 0/5] net: wwan: iosm: validate MUX DL lengths and offsets
@ 2026-11-20 10:55 Fang Xieyan
2026-11-20 10:55 ` [PATCH net v3 1/5] net: wwan: iosm: validate the MUX DL block length Fang Xieyan
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: Fang Xieyan @ 2026-11-20 10:55 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, Guanglei Zhu,
linux-kernel, stable
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 net-next at 9068e05d35f3.
Changes in v3:
- Rebase onto net-next (9068e05d35f3) so the series applies on top of
66974df65a0b ("net: wwan: iosm: drop redundant skb->data check in MUX
DL decode"). Patch 1 no longer anchors its signature-length check on
the removed skb->data test; the check now sits directly before the
signature read. This clears the v2 patchwork context failure at
iosm_ipc_mux_codec.c:696 and the dependent context-hw gate failure.
- Patch 5 wraps the over-long continuation line in
ipc_mux_dl_cmd_decode(): param_len now goes on its own line, clearing
the checkpatch "line length of 82 exceeds 80 columns" warning.
- Cc Guanglei Zhu, whom get_maintainer.pl now lists for this file after
his review of 66974df65a0b (the v2 cc_maintainers warning).
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.
v2:
https://lore.kernel.org/netdev/20261117173940.34970-1-fangxy@xiaopeng.com/
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 | 186 ++++++++++++++++-----
1 file changed, 141 insertions(+), 45 deletions(-)
--
2.50.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH net v3 1/5] net: wwan: iosm: validate the MUX DL block length
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 ` Fang Xieyan
2026-11-20 10:55 ` [PATCH net v3 2/5] net: wwan: iosm: validate the ADGH datagram length Fang Xieyan
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Fang Xieyan @ 2026-11-20 10:55 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, Guanglei Zhu,
linux-kernel, stable
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 2b8a22980c87..1c5aae25f08f 100644
--- a/drivers/net/wwan/iosm/iosm_ipc_mux_codec.c
+++ b/drivers/net/wwan/iosm/iosm_ipc_mux_codec.c
@@ -693,6 +693,11 @@ void ipc_mux_dl_decode(struct iosm_mux *ipc_mux, struct sk_buff *skb)
{
u32 signature;
+ 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);
@@ -701,15 +706,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;
@@ -717,6 +731,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] 6+ messages in thread
* [PATCH net v3 2/5] net: wwan: iosm: validate the ADGH datagram length
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 ` Fang Xieyan
2026-11-20 10:55 ` [PATCH net v3 3/5] net: wwan: iosm: bound the ACBH command chain walk Fang Xieyan
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Fang Xieyan @ 2026-11-20 10:55 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, Guanglei Zhu,
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 1c5aae25f08f..341c58b851cb 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] 6+ messages in thread
* [PATCH net v3 3/5] net: wwan: iosm: bound the ACBH command chain walk
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
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
4 siblings, 0 replies; 6+ messages in thread
From: Fang Xieyan @ 2026-11-20 10:55 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, Guanglei Zhu,
linux-kernel, stable
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
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH net v3 4/5] net: wwan: iosm: pass the DL command parameter by pointer
2026-11-20 10:55 [PATCH net v3 0/5] net: wwan: iosm: validate MUX DL lengths and offsets Fang Xieyan
` (2 preceding siblings ...)
2026-11-20 10:55 ` [PATCH net v3 3/5] net: wwan: iosm: bound the ACBH command chain walk Fang Xieyan
@ 2026-11-20 10:55 ` Fang Xieyan
2026-11-20 10:55 ` [PATCH net v3 5/5] net: wwan: iosm: validate the command parameter length Fang Xieyan
4 siblings, 0 replies; 6+ messages in thread
From: Fang Xieyan @ 2026-11-20 10:55 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, Guanglei Zhu,
linux-kernel, stable
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 f1a742b20eab..3c5b957893ab 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] 6+ messages in thread
* [PATCH net v3 5/5] net: wwan: iosm: validate the command parameter length
2026-11-20 10:55 [PATCH net v3 0/5] net: wwan: iosm: validate MUX DL lengths and offsets Fang Xieyan
` (3 preceding siblings ...)
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 ` Fang Xieyan
4 siblings, 0 replies; 6+ messages in thread
From: Fang Xieyan @ 2026-11-20 10:55 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, Guanglei Zhu,
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 | 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 3c5b957893ab..4d7783a059d3 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,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 = (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,
+ 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 = 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 +526,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 +598,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] 6+ messages in thread
end of thread, other threads:[~2026-11-20 10:56 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH net v3 3/5] net: wwan: iosm: bound the ACBH command chain walk Fang Xieyan
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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox