Skip to contentSkip to conversation

mptcp: add MPTCP_MIB_RCVINVALIDOPT counter for invalid options

PATCH In review T S Rameshkumar 4 participants 4 messages Oct 13

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mptcp: add MPTCP_MIB_RCVINVALIDOPT counter for invalid options

In mptcp_parse_option(), invalid MPTCP options or unsupported suboptions and malformed option lengths are silently ignored via break statements. As noted in GitHub issue #628, tracking these invalid options with a MIB counter is useful to detect potential attacks, network corruption, or misbehaving peers.

Introduce MPTCP_MIB_RCVINVALIDOPT ("RcvInvalidOpt") to track invalid MPTCP options encountered during parsing. When mptcp_parse_option() encounters invalid combinations, lengths, versions, or unknown subtypes, jump to the bad_opt label to increment MPTCP_MIB_RCVINVALIDOPT.

To increment the MIB counter, mptcp_parse_option() requires a pointer to struct net. Safely resolve net in mptcp_get_options() via mptcp_skb_net() from skb->sk, skb->dev, or skb_dst, with NULL guards to prevent NULL pointer dereferences when sk, dev, or dst is not set.

---
 net/mptcp/mib.c     |  1 +
 net/mptcp/mib.h     |  1 +
 net/mptcp/options.c | 68 ++++++++++++++++++++++++++++-----------------
 3 files changed, 45 insertions(+), 25 deletions(-)
net/mptcp/mib.c +1 -0
index 608cb5688..0ab1ddac8 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("RcvInvalidOpt", MPTCP_MIB_RCVINVALIDOPT),
 };
 
 /* mptcp_mib_alloc - allocate percpu mib counters
net/mptcp/mib.h +1 -0
index 1ebdb55e9..483f79dab 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_RCVINVALIDOPT,	/* Received invalid MPTCP option */
 	__MPTCP_MIB_MAX
 };
 
net/mptcp/options.c +43 -25

202 lines not on this page · raw message

Signature · 1 line
2.34.1
maintainer
#1 lore raw

Hi T S,

Quoted 5 lines · T S Rameshkumar

In mptcp_parse_option(), invalid MPTCP options or unsupported suboptions and malformed option lengths are silently ignored via break statements. As noted in GitHub issue #628, tracking these invalid options with a MIB counter is useful to detect potential attacks, network corruption, or misbehaving peers.

Thank you for the patches. Please next time add a comment on the GitHub
ticket: patches have already been shared and waiting for a review (don't hesitate to review it). If a ticket is assigned, that means someone is working on it.

https://lore.kernel.org/mptcp/[email protected]/

Cheers,
Matt

Signature · 1 line
Sponsored by the NGI0 Core fund.
#2 lore raw
In reply to T S Rameshkumar
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] mptcp: missed MIB increment for backlog packets due to mptcp_skb_net() --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] mptcp: missed MIB increment for backlog packets due to mptcp_skb_net() --

commit 69466d93fa353450c6162f23ad6457846e513a9d
Author: T S Rameshkumar <[email protected]>

mptcp: add MPTCP_MIB_RCVINVALIDOPT counter for invalid options

This commit introduces the MPTCP_MIB_RCVINVALIDOPT counter to track invalid MPTCP options encountered during parsing. To perform the increment, it attempts to resolve the net pointer from the socket buffer in mptcp_skb_net() by checking skb->sk, skb->dev, and skb_dst.

Quoted 4 lines
net/mptcp/options.c +0 -0
index adbf8e0773dbb..a1af2acfa791b 100644

[ ... ]

Quoted 11 lines
net/mptcp/options.c +3 -0
@@ -419,13 +422,28 @@ static void mptcp_parse_option(const struct sk_buff *skb,
 		break;
 
 	default:
+bad_opt:
+		if (net)
+			MPTCP_INC_STATS(net, MPTCP_MIB_RCVINVALIDOPT);
 		break;
 	}
 }
 

net/mptcp/options.c static void mptcp_parse_option(const struct sk_buff *skb, · line 441

Quoted 10 lines
net/mptcp/options.c +10 -0
+static inline struct net *mptcp_skb_net(const struct sk_buff *skb)
+{
+	if (skb->sk)
+		return sock_net(skb->sk);
+	if (skb->dev)
+		return dev_net_rcu(skb->dev);
+	if (skb_dst(skb) && skb_dst_dev_rcu(skb))
+		return skb_dst_dev_net_rcu(skb);
+	return NULL;
+}

[Severity: Medium]
For TCP packets processed from the socket backlog queue, is it possible for mptcp_skb_net() to always return NULL?

When a packet is processed from the backlog (e.g. via tcp_v4_do_rcv()), skb->dev is cleared unconditionally, skb_dst is dropped, and skb->sk is not yet set for incoming packets.

Because all three pointers are NULL, the function will return NULL. This will cause the MIB increment at the bad_opt label to be silently skipped for any malformed options present in backlog packets.

Since the callers of mptcp_get_options() generally have access to the relevant socket, could they pass the known net or sk directly instead of deriving it from the skb?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#3 lore raw
In reply to T S Rameshkumar

Hi T,

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! ✅
- Perf: Success! ✅
- Task: https://github.com/multipath-tcp/mptcp_net-next/actions/runs/38375270540

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

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)