Thread View: linux.kernel.netdev
3 messages
3 total messages
Started by Fang Xieyan
Thu, 12 Nov 2026 12:52
[PATCH net 5/5] net: wwan: iosm: validate the command parameter length
Author: Fang Xieyan
Date: Thu, 12 Nov 2026 12:52
Date: Thu, 12 Nov 2026 12:52
249 lines
18337 bytes
18337 bytes
Both command decoders read members of the parameter union without
knowing how long the parameter actually is.
ipc_mux_dl_cmdresps_decode_process() and
ipc_mux_dl_cmds_decode_process() used to be handed the size of the whole
union or of the command header, which is a property of the structures,
not of the received command: an OPEN_SESSION_RESP truncated below its
twelve byte parameter copied bytes past the command into acb->got_param
and then resumed the session establishment waiting on it, and a FLOW_CTL
whose parameter does not fit left the flow control mask and the state of
the session built from whatever bytes followed.
Derive the parameter length from what the current command owns: for MUX
Lite the bytes cmd_len declares beyond the header, for a command of an
aggregated block the bytes up to the next command, or up to the end of
the received block for the last one. Both stay capped by the received
length.
cmd_len is not used as a per-command parameter bound in the aggregated
path: next_cmd_index is what identifies the next command, and the flow
control decoder already treats a cmd_len that does not match the header
and parameter size as a legacy device instead of as an error, so the
field is not a hard bound there. In MUX Lite, cmd_len bounds the
parameter only when it covers at least the header. The protocol asks for
0x10 or more, but a shorter value is not rejected: the received length
keeps the limit there, which preserves the handling the existing
backward compatible code gives legacy devices and is still tighter than
the unbounded read it replaces. That case stays silent, like the
compatibility handling itself.
Check the member each command type really uses against that length: the
two session responses by their own size, which differ, and the flow
control mask before it is read. A parameter too short for its command
type is returned as -EMSGSIZE and the callers no longer hand it to the
command decoder, so a known but incomplete response is dropped instead
of being retried as a command.
In an aggregated block, ipc_mux_dl_acbcmd_decode() used to swallow that
error: the command was not acted upon, but the walk went on to the next
one. It now returns it, so a block that declared a command it cannot
hold is not trusted for the ones behind it either. A command of unknown
type still returns -EINVAL, is tried as a command and the walk
continues, as before.
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 | 116 +++++++++++++++------
1 file changed, 85 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 aea4cd9ec20d..bd6c82746cc4 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,36 @@ 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;
__le32 trans_id = cmdh->transaction_id;
- int size;
+ u16 cmd_len;
+ int ret, size;
- if (ipc_mux_dl_cmdresps_decode_process(ipc_mux, &cmdh->param,
- cmdh->command_type, cmdh->if_id,
- cmdh->transaction_id)) {
+ cmd_len = le16_to_cpu(cmdh->cmd_len);
+ param_len = skb->len > hdr_len ? skb->len - hdr_len : 0;
+ /*
+ * A cmd_len below the header is not a usable declaration: the
+ * received length stays the limit, as for a legacy device.
+ */
+ if (cmd_len >= hdr_len)
+ param_len = min_t(size_t, param_len, cmd_len - 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)
+ return;
+
+ 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 +525,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 +535,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 +607,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
Re: [PATCH net 5/5] net: wwan: iosm: validate the command parameter length
Author: netdev-bot+sashiko
Date: Mon, 16 Nov 2026 13:55
Date: Mon, 16 Nov 2026 13:55
172 lines
14831 bytes
14831 bytes
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 1
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] In ipc_mux_dl_cmd_decode() (MUX Lite path,
drivers/net/wwan/iosm/iosm_ipc_mux_codec.c:338-345), once cmd_len >=…
- [Low] This commit is tagged 'Cc: stable@vger.kernel.org' (Fixes:
9413491e20e1) but depends on the preceding series commit "net: wwan:…
--
net: wwan: iosm: validate the command parameter length
This patch works out a parameter length for each received DL command. For
MUX Lite it comes from cmd_len. For aggregated blocks it comes from
next_cmd_index, or from skb->len for the last command. The union member
each command type uses is checked against that length. A parameter that is
too short returns -EMSGSIZE, the callers drop the command, and in the
aggregated path the walk of the command chain stops.
> diff --git a/drivers/net/wwan/iosm/iosm_ipc_mux_codec.c b/drivers/net/wwan/iosm/iosm_ipc_mux_codec.c
> index aea4cd9ec20d3..bd6c82746cc4a 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)
> {
[Severity: Low]
This patch has Cc: stable and Fixes: 9413491e20e1. Its context, though,
depends on the earlier series patch "net: wwan: iosm: pass the DL command
parameter by pointer", which has neither a Cc: stable nor a Fixes: tag.
In the stable trees, ipc_mux_dl_cmdresps_decode_process() still takes
union mux_cmd_param by value, and the callers pass cmdh->param. The
prerequisite also introduced two things this patch changes:
- the acb->got_param = *param line removed here
- the ipc_mux_dl_acbcmd_decode() body rewritten here
So this patch won't apply on its own.
Suppose the length checks are adapted by hand onto the by-value signature.
Each call would still copy the full 12-byte union out of the skb before
param_len is checked, so the over-read this series removes would remain.
The fix also relies on "net: wwan: iosm: bound the ACBH command chain
walk" and "net: wwan: iosm: validate the MUX DL block length".
Could the prerequisite be tagged for stable as well? Alternatively, the
prerequisite annotations from Documentation/process/stable-kernel-rules.rst
would make the ordering clear to backporters.
[ ... ]
> @@ -315,19 +329,36 @@ 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;
> __le32 trans_id = cmdh->transaction_id;
> - int size;
> + u16 cmd_len;
> + int ret, size;
>
> - if (ipc_mux_dl_cmdresps_decode_process(ipc_mux, &cmdh->param,
> - cmdh->command_type, cmdh->if_id,
> - cmdh->transaction_id)) {
> + cmd_len = le16_to_cpu(cmdh->cmd_len);
> + param_len = skb->len > hdr_len ? skb->len - hdr_len : 0;
> + /*
> + * A cmd_len below the header is not a usable declaration: the
> + * received length stays the limit, as for a legacy device.
> + */
> + if (cmd_len >= hdr_len)
> + param_len = min_t(size_t, param_len, cmd_len - 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)
> + return;
[Severity: Medium]
Can this bound reject MUX Lite commands that were handled before?
Once cmd_len >= 16, param_len becomes min(skb->len - 16, cmd_len - 16).
Take a FLOW_CTL with cmd_len 0x10 (the header-only minimum mentioned in
the commit message) or 17..19. It ends up with param_len < 4. The new
check in ipc_mux_dl_cmds_decode_process() then returns before the existing
backward compatibility branch runs:
if (param_len < sizeof(param->flow_ctl))
return -EMSGSIZE;
...
if (param->flow_ctl.mask == cpu_to_le32(0xFFFFFFFF)) {
/* Backward Compatibility */
if (cmd_len == cpu_to_le16(size))
session->flow_ctl_mask =
le32_to_cpu(param->flow_ctl.mask);
else
session->flow_ctl_mask = ~0;
That branch was added for MUX Lite in 9413491e20e1. There, size is
offsetof(struct mux_lite_cmdh, param) + sizeof(flow_ctl), so the branch
expects Lite FLOW_CTL commands whose cmd_len is not 20.
Before this patch, such a command was applied and acknowledged as long as
the mask was in the received bytes. With this patch, net_tx_stop and
flow_ctl_mask are left unchanged and no MUX_LITE_CMD_FLOW_CTL_ACK is sent.
An OPEN_SESSION_RESP with cmd_len 16..27 is affected the same way, even
when all 12 parameter bytes arrived. The chain is:
ipc_mux_dl_cmd_decode()
ipc_mux_dl_cmdresps_decode_process() returns -EMSGSIZE
return (silent)
The blocking ipc_mux_session_open_send() then runs out
IPC_MUX_CMD_RUN_DEFAULT_TIMEOUT and fails. The only message logged is
"OPEN_SESSION send failed".
It isn't clear whether shipping firmware uses these lengths. However, the
commit message says:
the received length keeps the limit there, which preserves the handling
the existing backward compatible code gives legacy devices
It also argues that cmd_len is not a hard bound on the aggregated path,
because the flow control decoder treats a mismatched cmd_len as a legacy
device. Wouldn't the same reasoning apply to MUX Lite, where that
compatibility code came from?
Should cmd_len bound the parameter only when it covers the member being
read? Or should the 16..19 and 16..27 cases at least be logged and
mentioned in the commit message?
> +
> + 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)) {
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261112125201.1019-1-fangxy%40xiaopeng.com
Re: [PATCH net 5/5] net: wwan: iosm: validate the command parameter length
Author: Fang Xieyan
Date: Tue, 17 Nov 2026 10:59
Date: Tue, 17 Nov 2026 10:59
31 lines
9871 bytes
9871 bytes
On Mon, 16 Nov 2026 13:55:19 +0000, netdev-bot+sashiko@kernel.org wrote: > [Severity: Medium] > Can this bound reject MUX Lite commands that were handled before? Yes. The compatibility branch in ipc_mux_dl_cmds_decode_process() is there for cmd_len != size (size = 20), and the protocol minimum is 0x10, so my min_t() dropped the 16..19 range that branch is meant to serve. v2 will stop using cmd_len as a parameter bound in the lite path and keep only param_len = skb->len - hdr_len. There is no chain walk here, one command per skb, and ipc_mux_dl_decode() already rejects a short CMDH header, so cmd_len buys no safety. It will still be passed to the decoder unchanged, so the compatibility branch keeps working. > [Severity: Low] > This patch has Cc: stable and Fixes: 9413491e20e1. Its context, though, > depends on the earlier series patch "net: wwan: iosm: pass the DL > command parameter by pointer", which has neither a Cc: stable nor a > Fixes: tag. Correct. v2 will add Fixes: 9413491e20e1 and Cc: stable@vger.kernel.org to patch 4/5. The point on 2/5 is also valid. packet_offset equals dl_head_pad_len, so this is the same empty case mux_dl_process_dg() already rejects with dl_head_pad_len >= dg_len. v2 will use <=. Thanks for the review. pw-bot: cr
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads