From: sashiko-bot@kernel.org
To: "Hang Nan" <2122295973@qq.com>
Cc: mptcp@lists.linux.dev
Subject: Re: [PATCH net v4 3/3] net: mptcp: verify the token slot in mptcp_token_iter_next()
Date: Mon, 16 Nov 2026 15:58:11 +0000 [thread overview]
Message-ID: <sashiko-outbox-217329@kernel.org> (raw)
In-Reply-To: <tencent_647B95315D18DBA311A33E8120517E1DA60A@qq.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] net: mptcp: mptcp_token_iter_next() can return unhashed clone
from mptcp_sk_clone_init()
--
commit 360d7517d4f418ef6ade9477ae90312992cd23fa
Author: Hang Nan <2122295973@qq.com>
net: mptcp: verify the token slot in mptcp_token_iter_next()
This commit re-reads msk->token after taking a socket reference in
mptcp_token_iter_next() and drops the socket if the token is zero or no
longer hashes to the current slot.
> diff --git a/net/mptcp/token.c b/net/mptcp/token.c
> index 8a603fc8dc059..48470d6e751d6 100644
> --- a/net/mptcp/token.c
> +++ b/net/mptcp/token.c
> @@ -355,6 +355,7 @@ struct mptcp_sock *mptcp_token_iter_next(const struct net *net, long *s_slot,
> struct mptcp_sock *ret = NULL;
> struct hlist_nulls_node *pos;
> int slot, num = 0;
> + u32 token;
>
> for (slot = *s_slot; slot <= token_mask; *s_num = 0, slot++) {
> struct token_bucket *bucket = &token_hash[slot];
> @@ -377,7 +378,9 @@ struct mptcp_sock *mptcp_token_iter_next(const struct net *net, long *s_slot,
> if (!refcount_inc_not_zero_acquire(&sk->sk_refcnt))
> continue;
>
> - if (!net_eq(sock_net(sk), net)) {
> + token = READ_ONCE(mptcp_sk(sk)->token);
> + if (!token || (token & token_mask) != slot ||
> + !net_eq(sock_net(sk), net)) {
> sock_put(sk);
> continue;
> }
[Severity: Medium]
Can mptcp_token_iter_next() still return an unhashed mptcp_sock while
mptcp_sk_clone_init() is initializing or tearing it down?
If a freed mptcp_sock from token_hash[slot] is reused via
SLAB_TYPESAFE_BY_RCU by mptcp_sk_clone_init() in the same netns for a
passive connection whose subflow_req->token hashes to the same slot,
sk_clone_lock() sets sk_refcnt to 2 and mptcp_sk_clone_init() writes
msk->token before the clone is fully initialized or hashed:
CPU0 CPU1
mptcp_token_iter_next() /* sk freed from token_hash[slot] */
sk_nulls_for_each_rcu(sk, ...)
mptcp_sk_clone_init()
nsk = sk_clone_lock() /* reuses sk */
WRITE_ONCE(msk->token,
subflow_req->token)
refcount_inc_not_zero_acquire()
token = READ_ONCE(msk->token)
/* token != 0 && same slot/net */
return msk; <-- unhashed clone
mptcp_init_sched()
...
mptcp_token_accept()
Callers such as mptcp_diag_dump() can then access nsk before
mptcp_init_sched(), sock_reset_flag(nsk, SOCK_RCU_FREE),
security_inet_csk_clone() and mptcp_copy_inaddrs() have executed. In
addition, if mptcp_token_accept() fails, mptcp_sk_clone_destroy() calls
inet_csk_destroy_sock() -> mptcp_destroy() -> mptcp_destroy_common() ->
mptcp_token_destroy(), which returns early when sk_unhashed() is true
without clearing msk->token to 0, allowing a concurrent iterator to take a
reference during unlocked teardown.
Checking sk_unhashed(sk) after taking the reference (or setting msk->token
inside mptcp_token_accept() under bucket->lock as mptcp_token_new_connect()
does) would avoid returning an unhashed clone.
--
Sashiko AI review · https://sashiko.dev/#/patchset/tencent_D0DCF4B132B20B70FB5AE2D9272AA4AEAF07@qq.com?part=3
next prev parent reply other threads:[~2026-11-16 15:58 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20261115155747.178858-1-2122295973@qq.com>
2026-11-15 15:57 ` [PATCH net v4 1/3] net: mptcp: take token lookup references with acquire ordering Hang Nan
2026-11-17 9:43 ` netdev-bot+sashiko
2026-11-15 15:57 ` [PATCH net v4 2/3] net: mptcp: reject token 0 in mptcp_token_get_sock() Hang Nan
2026-11-17 9:43 ` netdev-bot+sashiko
2026-11-15 15:57 ` [PATCH net v4 3/3] net: mptcp: verify the token slot in mptcp_token_iter_next() Hang Nan
2026-11-16 15:58 ` sashiko-bot [this message]
2026-11-17 9:43 ` netdev-bot+sashiko
2026-11-16 12:20 ` [PATCH net v4 0/3] mptcp token hash ordering and token 0 lookups Hang Nan
2026-11-16 14:58 ` Hang Nan
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=sashiko-outbox-217329@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=2122295973@qq.com \
--cc=mptcp@lists.linux.dev \
--cc=sashiko-reviews@lists.linux.dev \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.