Skip to contentSkip to conversation

mptcp: MIB counter for invalid option

PATCH In review Gang Yan 4 participants 7 messages Aug 12 – Aug 13

Subsystems (2)
lore
Share & tools
lore

Gang Yan

author
#0 lore raw

cover mptcp: MIB counter for invalid option

From: Gang Yan <[email protected]>

This series is designed for [1].

Patch 1 passes the 'net' to options parser, I used to use dev_net(skb->dev) for MIB counters, but the AI reported it is not suitable for this. This patch has no functional change.

Patch 2 adds the InvalidOptionRx counter, and increments it when receive the invalid options.

The packetdill testcase is submitted, and can be reviewed in [2].

[1] https://github.com/multipath-tcp/mptcp_net-next/issues/628
[2] https://github.com/multipath-tcp/packetdrill/pull/205
Gang Yan (2):
mptcp: pass net namespace to options parser
mptcp: add MIB counter for received invalid options

 net/mptcp/mib.c      |   1 +
 net/mptcp/mib.h      |   1 +
 net/mptcp/options.c  | 107 +++++++++++++++++++++++++++++++------------
 net/mptcp/protocol.h |   2 +-
 net/mptcp/subflow.c  |  10 ++--
 5 files changed, 85 insertions(+), 36 deletions(-)
Signature · 1 line
2.43.0
author
#1 lore raw

PATCH 1/2 mptcp: pass net namespace to options parser

From: Gang Yan <[email protected]>

The MPTCP options parser will need access to the per-netns MIB counters to track received invalid options. To prepare for this, pass the net namespace down to mptcp_get_options() and mptcp_parse_option().

This is a pure refactor with no functional change.

Assisted-by Claude:GLM-5.2
---
 net/mptcp/options.c  |  9 +++++----
 net/mptcp/protocol.h |  2 +-
 net/mptcp/subflow.c  | 10 +++++-----
 3 files changed, 11 insertions(+), 10 deletions(-)
net/mptcp/options.c +5 -4
index 97da22668dbe..dfdcc888efe3 100644
@@ -20,7 +20,8 @@ static bool mptcp_cap_flag_sha256(u8 flags)
 	return (flags & MPTCP_CAP_FLAG_MASK) == MPTCP_CAP_HMAC_SHA256;
 }
 
-static void mptcp_parse_option(const struct sk_buff *skb,
+static void mptcp_parse_option(struct net *net,
+			       const struct sk_buff *skb,
 			       const unsigned char *ptr, int opsize,
 			       struct mptcp_options_received *mp_opt)
 {
@@ -419,7 +420,7 @@ static void mptcp_parse_option(const struct sk_buff *skb,
 	}
 }
 
-void mptcp_get_options(const struct sk_buff *skb,
+void mptcp_get_options(struct net *net, const struct sk_buff *skb,
 		       struct mptcp_options_received *mp_opt)
 {
 	const struct tcphdr *th = tcp_hdr(skb);
@@ -454,7 +455,7 @@ void mptcp_get_options(const struct sk_buff *skb,
 			if (opsize > length)
 				return;	/* don't parse partial options */
 			if (opcode == TCPOPT_MPTCP)
-				mptcp_parse_option(skb, ptr, opsize, mp_opt);
+				mptcp_parse_option(net, skb, ptr, opsize, mp_opt);
 			ptr += opsize - 2;
 			length -= opsize;
 		}
@@ -1247,7 +1248,7 @@ bool mptcp_incoming_options(struct sock *sk, struct sk_buff *skb)
 		return !mptcp_over_limit(subflow->conn, sk, skb);
 	}
 
-	mptcp_get_options(skb, &mp_opt);
+	mptcp_get_options(sock_net(sk), skb, &mp_opt);
 
 	/* The subflow can be in close state only if check_fully_established()
 	 * just sent a reset. If so, tell the caller to ignore the current packet.
net/mptcp/protocol.h +1 -1
index 7e168e450fb0..333fb5c89c59 100644
@@ -927,7 +927,7 @@ struct sock *mptcp_sk_clone_init(const struct sock *sk,
 				 const struct mptcp_options_received *mp_opt,
 				 struct sock *ssk,
 				 struct request_sock *req);
-void mptcp_get_options(const struct sk_buff *skb,
+void mptcp_get_options(struct net *net, const struct sk_buff *skb,
 		       struct mptcp_options_received *mp_opt);
 
 void mptcp_finish_connect(struct sock *sk);
net/mptcp/subflow.c +5 -5
index af81ad5e699d..9a8a39b23fcb 100644
@@ -167,7 +167,7 @@ static int subflow_check_req(struct request_sock *req,
 	}
 #endif
 
-	mptcp_get_options(skb, &mp_opt);
+	mptcp_get_options(sock_net(sk_listener), skb, &mp_opt);
 
 	opt_mp_capable = !!(mp_opt.suboptions & OPTION_MPTCP_MPC_SYN);
 	opt_mp_join = !!(mp_opt.suboptions & OPTION_MPTCP_MPJ_SYN);
@@ -273,7 +273,7 @@ int mptcp_subflow_init_cookie_req(struct request_sock *req,
 	int err;
 
 	subflow_init_req(req, sk_listener);
-	mptcp_get_options(skb, &mp_opt);
+	mptcp_get_options(sock_net(sk_listener), skb, &mp_opt);
 
 	opt_mp_capable = !!(mp_opt.suboptions & OPTION_MPTCP_MPC_ACK);
 	opt_mp_join = !!(mp_opt.suboptions & OPTION_MPTCP_MPJ_ACK);
@@ -539,7 +539,7 @@ static void subflow_finish_connect(struct sock *sk, const struct sk_buff *skb)
 	subflow->ssn_offset = TCP_SKB_CB(skb)->seq;
 	pr_debug("subflow=%p synack seq=%x\n", subflow, subflow->ssn_offset);
 
-	mptcp_get_options(skb, &mp_opt);
+	mptcp_get_options(sock_net(sk), skb, &mp_opt);
 	if (subflow->request_mptcp) {
 		if (!(mp_opt.suboptions & OPTION_MPTCP_MPC_SYNACK)) {
 			if (!mptcp_try_fallback(sk,
@@ -842,13 +842,13 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk,
 		 * reordered MPC will cause fallback, but we don't have other
 		 * options.
 		 */
-		mptcp_get_options(skb, &mp_opt);
+		mptcp_get_options(sock_net(sk), skb, &mp_opt);
 		if (!(mp_opt.suboptions &
 		      (OPTION_MPTCP_MPC_SYN | OPTION_MPTCP_MPC_ACK)))
 			fallback = true;
 
 	} else if (subflow_req->mp_join) {
-		mptcp_get_options(skb, &mp_opt);
+		mptcp_get_options(sock_net(sk), skb, &mp_opt);
 		if (!(mp_opt.suboptions & OPTION_MPTCP_MPJ_ACK))
 			fallback = true;
 	}
Signature · 1 line
2.43.0
author
#2 lore raw

PATCH 2/2 mptcp: add MIB counter for received invalid options

In reply to Gang Yan

From: Gang Yan <[email protected]>

In mptcp_parse_option(), an MPTCP option is silently ignored via a 'break' under a number of conditions.

This patch adds a MIB counter tracking this as an evidence to show someone is trying to attack the peer

---
 net/mptcp/mib.c     |  1 +
 net/mptcp/mib.h     |  1 +
 net/mptcp/options.c | 98 +++++++++++++++++++++++++++++++++------------
 3 files changed, 74 insertions(+), 26 deletions(-)
net/mptcp/mib.c +1 -0
index 608cb568897c..10e8870dd985 100644
@@ -95,6 +95,7 @@ static const struct snmp_mib mptcp_snmp_list[] = {
 	SNMP_MIB_ITEM("BacklogDrop", MPTCP_MIB_BACKLOGDROP),
 	SNMP_MIB_ITEM("RcvPruned", MPTCP_MIB_RCVPRUNED),
 	SNMP_MIB_ITEM("OFOPruned", MPTCP_MIB_OFOPRUNED),
+	SNMP_MIB_ITEM("InvalidOptionRx", MPTCP_MIB_INVALDOPTIONRX),
 };
 
 /* mptcp_mib_alloc - allocate percpu mib counters
net/mptcp/mib.h +1 -0
index 1ebdb55e9534..ae0751addd64 100644
@@ -98,6 +98,7 @@ enum linux_mptcp_mib_field {
 	MPTCP_MIB_BACKLOGDROP,		/* Backlog over memory limit */
 	MPTCP_MIB_RCVPRUNED,		/* Dropped due to memory constraints */
 	MPTCP_MIB_OFOPRUNED,		/* MPTCP-level OoO queue pruned */
+	MPTCP_MIB_INVALDOPTIONRX,	/* Received an invalid MPTCP option */
 	__MPTCP_MIB_MAX
 };
 
net/mptcp/options.c +72 -26

228 lines not on this page · raw message

Signature · 1 line
2.43.0
#3 lore raw

Re: [PATCH mptcp-next 2/2] mptcp: add MIB counter for received invalid options

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] Typographical error in the newly added MIB enum name `MPTCP_MIB_INVALDOPTIONRX` which is missing…

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] Typographical error in the newly added MIB enum name MPTCP_MIB_INVALDOPTIONRX which is missing the 'I' (should be MPTCP_MIB_INVALIDOPTIONRX). --

--- Patch [2]: [PATCH mptcp-next 2/2] mptcp: add MIB counter for received invalid options --- commit 250b62cf8675c7680c8a9a998feb6bec184832c8
Author: Gang Yan <[email protected]>

mptcp: add MIB counter for received invalid options

This commit adds a new MIB counter to track when an MPTCP option is silently ignored during parsing. This serves as evidence of potential peer attacks.

net/mptcp/mib.h enum linux_mptcp_mib_field { · line 101

Quoted 9 lines
net/mptcp/mib.h +1 -0
index 1ebdb55e95343..ae0751addd64b 100644
@@ -98,6 +98,7 @@ enum linux_mptcp_mib_field {
 	MPTCP_MIB_BACKLOGDROP,		/* Backlog over memory limit */
 	MPTCP_MIB_RCVPRUNED,		/* Dropped due to memory constraints */
 	MPTCP_MIB_OFOPRUNED,		/* MPTCP-level OoO queue pruned */
+	MPTCP_MIB_INVALDOPTIONRX,	/* Received an invalid MPTCP option */

[Severity: Low]
This isn't a bug, but is there a typo in this enum name? It looks like it is missing an 'I' (INVALDOPTIONRX instead of INVALIDOPTIONRX).

Quoted 2 lines
net/mptcp/mib.h +0 -0
 	__MPTCP_MIB_MAX
 };
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
#4 lore raw
In reply to Gang Yan

Hi Gang,

Thank you for your modifications, that's great!

Our CI did some validations and here is its report:

- KVM Validation: normal (except selftest_mptcp_join): Success! ✅
- KVM Validation: normal (only selftest_mptcp_join): Success! ✅
- KVM Validation: debug (except selftest_mptcp_join): Success! ✅
- KVM Validation: debug (only selftest_mptcp_join): Success! ✅
- KVM Validation: btf-normal (only bpftest_all): Success! ✅
- KVM Validation: btf-debug (only bpftest_all): Success! ✅
- Task: https://github.com/multipath-tcp/mptcp_net-next/actions/runs/31587859371

Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/cb85dffafd7b
Patchwork: https://patchwork.kernel.org/project/mptcp/list/?series=1144623

If there are some issues, you can reproduce them using the same environment as the one used by the CI thanks to a docker image, e.g.:

    $ cd [kernel source code]
    $ docker run -v "${PWD}:${PWD}:rw" -w "${PWD}" --privileged --rm -it \
        --pull always mptcp/mptcp-upstream-virtme-docker:latest \
        auto-normal

For more details:

https://github.com/multipath-tcp/mptcp-upstream-virtme-docker

Please note that despite all the efforts that have been already done to have a stable tests suite when executed on a public CI like here, it is possible some reported issues are not due to your modifications. Still, do not hesitate to help us improve that ;-)

Cheers,
MPTCP GH Action bot
Bot operated by Matthieu Baerts (NGI0 Core)

maintainer
#5 lore raw
In reply to Gang Yan

Hi Gang,

Quoted 8 lines · Gang Yan

From: Gang Yan <[email protected]>

This series is designed for [1].

Patch 1 passes the 'net' to options parser, I used to use dev_net(skb->dev) for MIB counters, but the AI reported it is not suitable for this. This patch has no functional change.

Quoted 6 lines

Patch 2 adds the InvalidOptionRx counter, and increments it when receive the invalid options.

The packetdill testcase is submitted, and can be reviewed in [2].

[1] https://github.com/multipath-tcp/mptcp_net-next/issues/628

Thank you for the patches. Please next time add a comment on the GitHub
ticket: I already have the patches ready, but I had to wait (for administration purposes) before sending them:

============

commit 8173df5a467cac6ed421bb832ac3ee675b490fa6 (b4/mptcp-mib-inval-opt)

Author: Matthieu Baerts (NGI0) <[email protected]>
Date:   Fri Jul 31 14:10:38 2026 +0200

mptcp: options: reset parsing in case of invalidity

When an invalid option is detected -- any unexpected suboptions combinations or use of invalid sizes -- the current behaviour is to ignore the currently parsed option.

Receiving such invalid options is suspicious: either this is coming from a buggy host, or an attacker. In this case, it seems safer to drop any previously parsed MPTCP option from such packet.

commit be5492962195d2988a9c508bc8ce4d3f55ac1da7

Author: Matthieu Baerts (NGI0) <[email protected]>
Date:   Wed Jul 29 20:01:45 2026 +0200

mptcp: options: track invalid ones

Any unexpected suboptions combinations or use of invalid sizes are
suspicious: either it is coming from a buggy host, or an attacker.

Better to track that with a new MIB counter.

commit 684c6244b5b76d30aaf30d62597247485b89cdb3

Author: Matthieu Baerts (NGI0) <[email protected]>
Date:   Mon Aug 3 20:24:02 2026 +0200

mptcp: options: use a dedicated bit for csum reqd

Instead of mixing that with suboptions: that's the only non-suboptions that is present in the 'suboptions' field.

This even cause a workaround with OPTIONS_MPTCP_DSS to exclude this non-suboptions when checking which other ones are set.

Move it to a dedicated free bit, and adapt the corresponding code.

This is clearer like that.

=========

In your version, I see that you increment the counter even when the suboption is not invalid, e.g. the version or the hmac is not supported. I don't think we should do that.

If that's OK for you, I can add a co-dev by on my patches.

Cheers,
Matt

Signature · 1 line
Sponsored by the NGI0 Core fund.
#6 lore raw
Quoted 21 lines · Matthieu Baerts

Hi Gang,

Quoted 16 lines · Gang Yan

From: Gang Yan <[email protected]>

This series is designed for [1].

Patch 1 passes the 'net' to options parser, I used to use dev_net(skb->dev) for MIB counters, but the AI reported it is not suitable for this. This patch has no functional change.

Patch 2 adds the InvalidOptionRx counter, and increments it when receive the invalid options.

The packetdill testcase is submitted, and can be reviewed in [2].

[1] https://github.com/multipath-tcp/mptcp_net-next/issues/628

Hi Matt

Quoted 4 lines

Thank you for the patches. Please next time add a comment on the GitHub
ticket: I already have the patches ready, but I had to wait (for administration purposes) before sending them:

Sorry for that, no offense intended. And thanks for the review and for the process reminder.

Quoted 49 lines

============

commit 8173df5a467cac6ed421bb832ac3ee675b490fa6 (b4/mptcp-mib-inval-opt)
Author: Matthieu Baerts (NGI0) <[email protected]>
Date: Fri Jul 31 14:10:38 2026 +0200

mptcp: options: reset parsing in case of invalidity

When an invalid option is detected -- any unexpected suboptions combinations or use of invalid sizes -- the current behaviour is to ignore the currently parsed option.

Receiving such invalid options is suspicious: either this is coming from a buggy host, or an attacker. In this case, it seems safer to drop any previously parsed MPTCP option from such packet.

commit be5492962195d2988a9c508bc8ce4d3f55ac1da7
Author: Matthieu Baerts (NGI0) <[email protected]>
Date: Wed Jul 29 20:01:45 2026 +0200

mptcp: options: track invalid ones

Any unexpected suboptions combinations or use of invalid sizes are
suspicious: either it is coming from a buggy host, or an attacker.

Better to track that with a new MIB counter.

commit 684c6244b5b76d30aaf30d62597247485b89cdb3
Author: Matthieu Baerts (NGI0) <[email protected]>
Date: Mon Aug 3 20:24:02 2026 +0200

mptcp: options: use a dedicated bit for csum reqd

Instead of mixing that with suboptions: that's the only non-suboptions that is present in the 'suboptions' field.

This even cause a workaround with OPTIONS_MPTCP_DSS to exclude this non-suboptions when checking which other ones are set.

Move it to a dedicated free bit, and adapt the corresponding code.

This is clearer like that.

Quoted 7 lines

=========

In your version, I see that you increment the counter even when the suboption is not invalid, e.g. the version or the hmac is not supported. I don't think we should do that.

If that's OK for you, I can add a co-dev by on my patches.

Thank you, that’s fine with me

Thanks
Gang

Quoted 6 lines

Cheers,
Matt

Signature · 1 line
Sponsored by the NGI0 Core fund.