* [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