Netdev List
 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 2/3] net: mptcp: reject token 0 in mptcp_token_get_sock()
Date: Tue, 17 Nov 2026 09:43:53 +0000	[thread overview]
Message-ID: <179490863332.3133.3484259413562043053@kernel.org> (raw)
In-Reply-To: <tencent_43D317CA682E96EDDF89E59E669052BF7E09@qq.com>

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

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

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).

- [Medium] This patch rests on the claim that a freshly allocated msk
  "holds [token 0] until it is hashed".

--

net: mptcp: reject token 0 in mptcp_token_get_sock()

This patch makes mptcp_token_get_sock() return NULL early for token 0.
The commit message says token 0 is what a torn down msk holds, and what a
freshly allocated msk holds until it is hashed. The goal is to stop an
MP_JOIN SYN carrying token 0 from matching a dying or half-initialised msk.

> Both validations in mptcp_token_get_sock() compare the socket's token
> with the requested one, so for a request for token 0 they cannot tell a
> match apart from a socket whose token has just been cleared.  With
> SLAB_TYPESAFE_BY_RCU the same is true for a socket whose memory has
> already been reused by a new msk that has not been hashed yet.

> diff --git a/net/mptcp/token.c b/net/mptcp/token.c
> index 3429b43a9f7c3..8a603fc8dc059 100644
> --- a/net/mptcp/token.c
> +++ b/net/mptcp/token.c
> @@ -299,6 +299,10 @@ struct mptcp_sock *mptcp_token_get_sock(struct net *net, u32 token)
>  	struct mptcp_sock *msk;
>  	struct sock *sk;
>  
> +	/* Token 0 is never assigned, but is what a torn down socket holds. */
> +	if (!token)
> +		return NULL;
> +

[Severity: Medium]
The commit message says a freshly allocated msk holds token 0 "until it is
hashed". Does that hold for the passive MP_CAPABLE path?

In mptcp_sk_clone_init(), the real non-zero token is stored well before
the msk is linked into msk_chain:

net/mptcp/protocol.c:mptcp_sk_clone_init() {
    ...
	WRITE_ONCE(msk->token, subflow_req->token);
    ...
	mptcp_copy_inaddrs(nsk, ssk);

	mptcp_rcv_space_init(msk, ssk);
	msk->rcvq_space.time = mptcp_stamp();

	if (!mptcp_token_accept(subflow_req, msk)) {
    ...
}

Consider a reader in mptcp_token_get_sock() that holds a stale chain
pointer to an msk whose memory is being reused as this clone, and that is
looking up the same token T. It would see token == T, a refcount of 2
from sk_clone(), and a matching netns.

In that case both READ_ONCE(msk->token) != token checks pass and
refcount_inc_not_zero_acquire() succeeds. Nothing checks whether the
socket is hashed, so an unhashed msk that is still being built is
returned. The new !token check doesn't cover this case.

subflow_token_join_request() then uses that msk without holding its lock:

  subflow_check_req()
    subflow_token_join_request()
      mptcp_token_get_sock()
      mptcp_pm_get_local_id()
      mptcp_pm_is_backup()
      mptcp_pm_announced_has_ssk()   (different source port)
      subflow_req_create_thmac()

mptcp_pm_get_local_id() could read the listener's addresses copied by
sock_copy(), before mptcp_copy_inaddrs() runs. It could then return the
wrong local ID, or add an implicit endpoint that shouldn't exist.
subflow_req_create_thmac() could also run before the keys are set up.

The token store is a plain WRITE_ONCE() with no release ordering, and the
reader has no matching acquire. On weakly ordered CPUs, could
mptcp_pm_announced_has_ssk() see the new token but still see the
pm.anno_list and pm.lock contents copied from the listener?

If mptcp_token_accept() then fails, mptcp_sk_clone_destroy() tears the msk
down while the join request still holds its reference. Because
mptcp_token_destroy() returns early for unhashed sockets, the msk keeps
token T.

The third patch in this series ("net: mptcp: verify the token slot in
mptcp_token_iter_next()") does not touch mptcp_token_get_sock() or the
clone path, so this case is still open at the end of the series.

Would checking that the socket is hashed after taking the reference work
here? Another option is to publish msk->token under the bucket lock just
before hashing. Either would cover this case as well as the token 0
cases.

>  	rcu_read_lock();
>  	bucket = token_bucket(token);
>

-- 
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 ` [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 [this message]
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=179490863332.3133.3484259413562043053@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