Skip to contentSkip to conversation

mptcp: gate diag sequence counters on CAP_NET_ADMIN

PATCH Applied Dominik Maier 5 participants 6 messages Nov 19 – Nov 25

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

PATCH 1/1 mptcp: gate diag sequence counters on CAP_NET_ADMIN

In net/mptcp/diag.c, subflow_get_info() restricts MPTCP sequence-related subflow attributes (rel_write_seq, map_seq, map_subflow_seq, ssn_offset) to callers holding CAP_NET_ADMIN in the network namespace.

However, mptcp_diag_get_info() unconditionally exports mptcpi_write_seq, mptcpi_snd_una, and mptcpi_rcv_nxt via INET_DIAG_INFO because .idiag_get_info does not receive the caller's net_admin status. Any unprivileged local user can therefore dump or query cross-UID MPTCP sockets by token via SOCK_DIAG_BY_FAMILY and read live 64-bit MPTCP Data Sequence Numbers.

Emit INET_DIAG_INFO from an .idiag_get_aux callback in mptcp_diag (which already receives net_admin from inet_sk_diag_fill(), while msk never sets icsk_ca_ops so netlink attribute ordering is unchanged) and zero mptcpi_write_seq, mptcpi_snd_una, and mptcpi_rcv_nxt when !net_admin. getsockopt(SOL_MPTCP, MPTCP_INFO) for the socket owner and token-based lookup in mptcp_diag_dump_one() remain unchanged.

This issue was discovered with an AI-assisted code review tool (ARTIST) and reproduced in QEMU/KVM on an unmodified v7.4-rc3 kernel without kernel modifications or error injection; a standalone reproducer is available on request. This revised .idiag_get_aux patch was compile-tested with -Werror and checked with checkpatch.pl --strict; it has not yet been runtime-tested against the reproducer or the MPTCP diag selftests.

Fixes ac3b45f60954 ("mptcp: add MPTCP socket diag interface")
---
 net/mptcp/mptcp_diag.c | 28 +++++++++++++++++++++++-----
 1 file changed, 23 insertions(+), 5 deletions(-)
net/mptcp/mptcp_diag.c +23 -5
index 136c2d0..62d8f1f 100644
@@ -193,10 +193,9 @@ static void mptcp_diag_get_info(struct sock *sk, struct inet_diag_msg *r,
 				void *_info)
 {
 	struct mptcp_sock *msk = mptcp_sk(sk);
-	struct mptcp_info *info = _info;
 
 	r->idiag_rqueue = sk_rmem_alloc_get(sk) +
-			  READ_ONCE(mptcp_sk(sk)->backlog_len);
+			  READ_ONCE(msk->backlog_len);
 	r->idiag_wqueue = sk_wmem_alloc_get(sk);
 
 	if (inet_sk_state_load(sk) == TCP_LISTEN) {
@@ -210,11 +209,29 @@ static void mptcp_diag_get_info(struct sock *sk, struct inet_diag_msg *r,
 			r->idiag_wqueue = READ_ONCE(lsk->sk_max_ack_backlog);
 		}
 	}
+}
 
-	if (!info)
-		return;
+static int mptcp_diag_get_aux(struct sock *sk, bool net_admin,
+			      struct sk_buff *skb)
+{
+	struct mptcp_sock *msk = mptcp_sk(sk);
+	struct mptcp_info *info;
+	struct nlattr *attr;
 
+	attr = nla_reserve_64bit(skb, INET_DIAG_INFO,
+				 sizeof(struct mptcp_info), INET_DIAG_PAD);
+	if (!attr)
+		return -EMSGSIZE;
+
+	info = nla_data(attr);
 	mptcp_diag_fill_info(msk, info);
+	/* Only export seq related counters to user with CAP_NET_ADMIN */
+	if (!net_admin) {
+		info->mptcpi_write_seq = 0;
+		info->mptcpi_snd_una = 0;
+		info->mptcpi_rcv_nxt = 0;
+	}
+	return 0;
 }
 
 static const struct inet_diag_handler mptcp_diag_handler = {
@@ -222,8 +239,9 @@ static const struct inet_diag_handler mptcp_diag_handler = {
 	.dump		 = mptcp_diag_dump,
 	.dump_one	 = mptcp_diag_dump_one,
 	.idiag_get_info  = mptcp_diag_get_info,
+	.idiag_get_aux	 = mptcp_diag_get_aux,
 	.idiag_type	 = IPPROTO_MPTCP,
-	.idiag_info_size = sizeof(struct mptcp_info),
+	.idiag_info_size = 0,
 };
 
 static int __init mptcp_diag_init(void)
Signature · 1 line
2.56.1.750.gf70dc682cf-goog
#1 lore raw

Hi Dominik,

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: Unstable: 4 failed test(s): regression:sched-bbr regression:sched-mem-pressure(2) regression:sched-rmem regression:sched-serverlim(2) ⚠️ (2 improvements, 777 new outliers to review)
- Task: https://github.com/multipath-tcp/mptcp_net-next/actions/runs/44601177439

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

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
#2 lore raw
In reply to Dominik Maier

Hi Dominik,

(+cc Kalpan)

Quoted 10 lines · Dominik Maier

In net/mptcp/diag.c, subflow_get_info() restricts MPTCP sequence-related subflow attributes (rel_write_seq, map_seq, map_subflow_seq, ssn_offset) to callers holding CAP_NET_ADMIN in the network namespace.

However, mptcp_diag_get_info() unconditionally exports mptcpi_write_seq, mptcpi_snd_una, and mptcpi_rcv_nxt via INET_DIAG_INFO because .idiag_get_info does not receive the caller's net_admin status. Any unprivileged local user can therefore dump or query cross-UID MPTCP sockets by token via SOCK_DIAG_BY_FAMILY and read live 64-bit MPTCP Data Sequence Numbers.

Thank you for this patch!

Quoted 6 lines

Emit INET_DIAG_INFO from an .idiag_get_aux callback in mptcp_diag (which already receives net_admin from inet_sk_diag_fill(), while msk never sets icsk_ca_ops so netlink attribute ordering is unchanged) and zero mptcpi_write_seq, mptcpi_snd_una, and mptcpi_rcv_nxt when !net_admin. getsockopt(SOL_MPTCP, MPTCP_INFO) for the socket owner and token-based lookup in mptcp_diag_dump_one() remain unchanged.

Oh, that's a good idea, I didn't think about .idiag_get_aux callback.

Kalpan was trying to fix the same thing:

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

@Kalpan: what do you think of this? If it looks good to you, and you tested it, can you send your Tested-by tag?

We can add:

Cheers,
Matt

Signature · 1 line
Sponsored by the NGI0 Core fund.
Tested-by
#3 lore raw

Hi Matt, Hi Dominik,

I tested the proposed change on a locally built kernel with MPTCP enabled.

Runtime testing passed for both client and server sockets:
- Privileged Netlink requests return the actual sequence counters, matching getsockopt(MPTCP_INFO).
- Unprivileged Netlink requests return zero for mptcpi_write_seq, mptcpi_snd_una and mptcpi_rcv_nxt.
- Other diagnostic information remains available to unprivileged users.

The full kernel build and runtime tests completed successfully.

Cheers,
Kalpan Jani

From: Matthieu Baerts <[email protected]>
To: "Dominik Maier"<[email protected]>
Cc: "Mat Martineau"<[email protected]>, "Geliang Tang"<[email protected]>, "Paolo Abeni"<[email protected]>, <[email protected]>, <[email protected]>, <[email protected]>, "Kalpan Jani"<[email protected]>
Date: Tue, 24 Nov 2026 16:47:10 +0530
Subject: Re: [PATCH mptcp-net] mptcp: gate diag sequence counters on CAP_NET_ADMIN

Quoted 45 lines

Hi Dominik,

(+cc Kalpan)

Quoted 10 lines · Dominik Maier

In net/mptcp/diag.c, subflow_get_info() restricts MPTCP sequence-related subflow attributes (rel_write_seq, map_seq, map_subflow_seq, ssn_offset) to callers holding CAP_NET_ADMIN in the network namespace.

However, mptcp_diag_get_info() unconditionally exports mptcpi_write_seq, mptcpi_snd_una, and mptcpi_rcv_nxt via INET_DIAG_INFO because .idiag_get_info does not receive the caller's net_admin status. Any unprivileged local user can therefore dump or query cross-UID MPTCP sockets by token via SOCK_DIAG_BY_FAMILY and read live 64-bit MPTCP Data Sequence Numbers.

Thank you for this patch!

Quoted 6 lines

Emit INET_DIAG_INFO from an .idiag_get_aux callback in mptcp_diag (which already receives net_admin from inet_sk_diag_fill(), while msk never sets icsk_ca_ops so netlink attribute ordering is unchanged) and zero mptcpi_write_seq, mptcpi_snd_una, and mptcpi_rcv_nxt when !net_admin. getsockopt(SOL_MPTCP, MPTCP_INFO) for the socket owner and token-based lookup in mptcp_diag_dump_one() remain unchanged.

Oh, that's a good idea, I didn't think about .idiag_get_aux callback.

Kalpan was trying to fix the same thing:

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

@Kalpan: what do you think of this? If it looks good to you, and you tested it, can you send your Tested-by tag?

We can add:

Cheers,
Matt

Signature · 1 line
Sponsored by the NGI0 Core fund.
maintainer Reviewed-by
#4 lore raw

Hi Kalpan,

Quoted 4 lines · Kalpan Jani

Hi Matt, Hi Dominik,

I tested the proposed change on a locally built kernel with MPTCP enabled.

Quoted 8 lines

Runtime testing passed for both client and server sockets:
- Privileged Netlink requests return the actual sequence counters, matching getsockopt(MPTCP_INFO).
- Unprivileged Netlink requests return zero for mptcpi_write_seq, mptcpi_snd_una and mptcpi_rcv_nxt.
- Other diagnostic information remains available to unprivileged users.

The full kernel build and runtime tests completed successfully.

Thank you for having tested that and your previous work!

Dominik's patch looks good to me:

@netdev maintainers: I see this patch is still listed on Suie, can you please apply it in -net directly?

Cheers,
Matt

Signature · 1 line
Sponsored by the NGI0 Core fund.
#5 lore raw
In reply to Dominik Maier
This patch was applied to netdev/net.git (main) by Paolo Abeni <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by Paolo Abeni <[email protected]>:

Quoted 4 lines · On Thu, 19 Nov 2026 20:21:59 +0100 you wrote:

In net/mptcp/diag.c, subflow_get_info() restricts MPTCP sequence-related subflow attributes (rel_write_seq, map_seq, map_subflow_seq, ssn_offset) to callers holding CAP_NET_ADMIN in the network namespace.

Quoted 8 lines

However, mptcp_diag_get_info() unconditionally exports mptcpi_write_seq, mptcpi_snd_una, and mptcpi_rcv_nxt via INET_DIAG_INFO because .idiag_get_info does not receive the caller's net_admin status. Any unprivileged local user can therefore dump or query cross-UID MPTCP sockets by token via SOCK_DIAG_BY_FAMILY and read live 64-bit MPTCP Data Sequence Numbers.

[...]

Here is the summary with links:
- [mptcp-net] mptcp: gate diag sequence counters on CAP_NET_ADMIN

    https://git.kernel.org/netdev/net/c/7ed616970b65

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html