Netdev List
 help / color / mirror / Atom feed
From: Dominik Maier <dmnk@google.com>
To: Matthieu Baerts <matttbe@kernel.org>,
	Mat Martineau <martineau@kernel.org>
Cc: Geliang Tang <geliang@kernel.org>,
	Paolo Abeni <pabeni@redhat.com>,
	mptcp@lists.linux.dev,  netdev@vger.kernel.org,
	dmnk+artist@google.com,  Dominik Maier <dmnk@google.com>
Subject: [PATCH mptcp-net] mptcp: gate diag sequence counters on CAP_NET_ADMIN
Date: Thu, 19 Nov 2026 20:21:59 +0100	[thread overview]
Message-ID: <20261119192159.2646113-1-dmnk@google.com> (raw)

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


                 reply	other threads:[~2026-11-19 19:22 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261119192159.2646113-1-dmnk@google.com \
    --to=dmnk@google.com \
    --cc=dmnk+artist@google.com \
    --cc=geliang@kernel.org \
    --cc=martineau@kernel.org \
    --cc=matttbe@kernel.org \
    --cc=mptcp@lists.linux.dev \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox