Netdev List
 help / color / mirror / Atom feed
* [PATCH mptcp-net] mptcp: gate diag sequence counters on CAP_NET_ADMIN
@ 2026-11-19 19:21 Dominik Maier
  0 siblings, 0 replies; only message in thread
From: Dominik Maier @ 2026-11-19 19:21 UTC (permalink / raw)
  To: Matthieu Baerts, Mat Martineau
  Cc: Geliang Tang, Paolo Abeni, mptcp, netdev, dmnk+artist,
	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.

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")
Cc: stable@vger.kernel.org
Signed-off-by: Dominik Maier <dmnk@google.com>
---
 net/mptcp/mptcp_diag.c | 28 +++++++++++++++++++++++-----
 1 file changed, 23 insertions(+), 5 deletions(-)

diff --git a/net/mptcp/mptcp_diag.c b/net/mptcp/mptcp_diag.c
index 136c2d0..62d8f1f 100644
--- a/net/mptcp/mptcp_diag.c
+++ b/net/mptcp/mptcp_diag.c
@@ -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)
-- 
2.56.1.750.gf70dc682cf-goog


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-19 19:22 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-19 19:21 [PATCH mptcp-net] mptcp: gate diag sequence counters on CAP_NET_ADMIN Dominik Maier

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox