mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: 2122295973@qq.com
Cc: netdev@vger.kernel.org, mptcp@lists.linux.dev,
	matttbe@kernel.org, martineau@kernel.org, geliang@kernel.org,
	davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
	pabeni@redhat.com, horms@kernel.org, kuniyu@google.com,
	willemb@google.com, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org
Subject: Re: [PATCH net v4 1/3] net: mptcp: take token lookup references with acquire ordering
Date: Tue, 17 Nov 2026 09:43:51 +0000	[thread overview]
Message-ID: <179490863184.3133.11284908359551272618@kernel.org> (raw)
In-Reply-To: <tencent_D0DCF4B132B20B70FB5AE2D9272AA4AEAF07@qq.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

Critical: 0 · High: 1 · Medium: 0 · Low: 1

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [High] The fix is incomplete on the passive-open (sk_clone_lock)
  allocation path.
- [Low] The patch is tagged `Cc: stable@vger.kernel.org` with Fixes: tags
  pointing to v5.8-era commits (2c5ebd001d4f, 96d890daad05).

--

net: mptcp: take token lookup references with acquire ordering

This switches the refcount increments in mptcp_token_get_sock() and
mptcp_token_iter_next() to refcount_inc_not_zero_acquire(). The re-check of
msk->token and sock_net(sk) is then ordered after the reference is taken on
a SLAB_TYPESAFE_BY_RCU socket that may have been recycled. It follows what
commit 5b5d8f351dd9 did for the IPv4/IPv6 established lookups.

> Fixes: 2c5ebd001d4f ("mptcp: refactor token container")
> Fixes: 96d890daad05 ("mptcp: add msk interations helper")
> Cc: stable@vger.kernel.org

[Severity: Low]
Will this build on the stable trees these Fixes: tags reach?

refcount_inc_not_zero_acquire() was added to include/linux/refcount.h by
commit 7f8ceea0c580 in 2025. Both 2c5ebd001d4f and 96d890daad05 date from
v5.8. LTS branches that don't have 7f8ceea0c580 also don't have the helper.

Could the stable tag name the prerequisite, for example:

Cc: stable@vger.kernel.org # depends on 7f8ceea0c580

> diff --git a/net/mptcp/token.c b/net/mptcp/token.c
> index e0f2823f92efb..3429b43a9f7c3 100644
> --- a/net/mptcp/token.c
> +++ b/net/mptcp/token.c
> @@ -309,7 +309,7 @@ struct mptcp_sock *mptcp_token_get_sock(struct net *net, u32 token)
>  		    !net_eq(sock_net(sk), net))
>  			continue;
>  
> -		if (!refcount_inc_not_zero(&sk->sk_refcnt))
> +		if (!refcount_inc_not_zero_acquire(&sk->sk_refcnt))
>  			goto not_found;
>  
>  		if (READ_ONCE(msk->token) != token ||

[ ... ]

> @@ -370,7 +370,7 @@ struct mptcp_sock *mptcp_token_iter_next(const struct net *net, long *s_slot,
>  			if (num <= *s_num)
>  				continue;
>  
> -			if (!refcount_inc_not_zero(&sk->sk_refcnt))
> +			if (!refcount_inc_not_zero_acquire(&sk->sk_refcnt))
>  				continue;
>  
>  			if (!net_eq(sock_net(sk), net)) {

[Severity: High]
Does the acquire ordering also cover the passive-open allocation path?

The commit message covers the sock_init_data_uid() path. On the clone
path, every MPTCP-specific store happens after the refcount is already
live. That includes the token the readers re-check:

sk_clone_lock()
  sk_clone()
    smp_wmb();
    refcount_set(&newsk->sk_refcnt, 2);

mptcp_sk_clone_init()
    __mptcp_init_sock(nsk);
    ...
    WRITE_ONCE(msk->token, subflow_req->token);
    ...
    mptcp_set_state(nsk, TCP_ESTABLISHED);
    WRITE_ONCE(msk->first, ssk);
    list_add(&subflow->node, &msk->conn_list);
    ...
    mptcp_copy_inaddrs(nsk, ssk);
    ...
    if (!mptcp_token_accept(subflow_req, msk)) {

The SLAB_TYPESAFE_BY_RCU comment in include/linux/slab.h says "the newly
allocated object has to be fully initialized *before* its refcount gets
initialized". This path doesn't do that.

Take a reader such as mptcp_diag_dump() walking bucket S through
mptcp_token_iter_next(), holding a chain pointer to msk A. A is closed and
freed, and a clone B for a new incoming MPTCP connection reuses its memory
right away.

refcount_inc_not_zero_acquire() then succeeds on B's refcount of 2. The
following READ_ONCE() of the token can return B's new token simply because
that store has already happened. This is a timing issue, not a reordering
one, so strongly ordered CPUs are affected too.

Even with the later patch in this series ("net: mptcp: verify the token
slot in mptcp_token_iter_next()"), this is the only check after the
increment:

	token = READ_ONCE(mptcp_sk(sk)->token);
	if (!token || (token & token_mask) != slot ||
	    !net_eq(sock_net(sk), net)) {

If B's token hashes to slot S, B is returned while it is on no token chain
and is still being built in softirq. Its sk_state may still be the
TCP_LISTEN copied from the listener. msk->first, conn_list and the
addresses may not be set yet. On weakly ordered CPUs, the
__mptcp_init_sock() and pm init stores may not be visible either.

That looks like the "or one that is not initialised yet" outcome the commit
message says this change removes.

mptcp_token_get_sock() seems to have the same gap when B's token matches
the token being looked up. One example is a peer that sends an MP_JOIN for
that token right after its MPC ACK, while a reader walks a stale pointer to
a recycled object in the same bucket. The lookup then returns B before
mptcp_token_accept() has hashed it. The later "net: mptcp: reject token 0
in mptcp_token_get_sock()" patch doesn't change this.

The precedent cited in the commit message, __inet_lookup_established(),
also rejects unhashed sockets after the acquire increment:

	if (unlikely(!refcount_inc_not_zero_acquire(&sk->sk_refcnt)))
		goto out;
	if (unlikely(hlist_nulls_unhashed_lockless(&sk->sk_nulls_node) ||
		     !inet_match(net, sk, acookie, ports, dif,
				 sdif))) {

sk_clone() calls sk_node_init() before it publishes the refcount, so that
check would reject B.

Should both mptcp sites also re-check
hlist_nulls_unhashed_lockless(&sk->sk_nulls_node) after taking the
reference? Alternatively, could the clone path publish its refcount only
after the MPTCP identity is set?

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/tencent_D0DCF4B132B20B70FB5AE2D9272AA4AEAF07%40qq.com

  reply	other threads:[~2026-11-17  9:43 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20261115155747.178858-1-2122295973@qq.com>
2026-11-15 15:57 ` Hang Nan
2026-11-17  9:43   ` netdev-bot+sashiko [this message]
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-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=179490863184.3133.11284908359551272618@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=2122295973@qq.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=geliang@kernel.org \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=kuniyu@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=martineau@kernel.org \
    --cc=matttbe@kernel.org \
    --cc=mptcp@lists.linux.dev \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=stable@vger.kernel.org \
    --cc=willemb@google.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

all inboxes | Powered by JetHome®