mptcp: gate diag sequence counters on CAP_NET_ADMIN
Subsystems (3)
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.
--- net/mptcp/mptcp_diag.c | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-)
net/mptcp/mptcp_diag.c +23 -5
@@ -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
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-normalFor 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)