Article View: linux.kernel.netdev
Article #17773Re: [PATCH net v4 3/3] net: mptcp: verify the token slot in mptcp_token_iter_next()
From: netdev-bot+sashiko
Date: Tue, 17 Nov 2026 09:43
Date: Tue, 17 Nov 2026 09:43
211 lines
15627 bytes
15627 bytes
Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 (1) · Low: 2
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] Under the new check in mptcp_token_iter_next()
(net/mptcp/token.c:381-386), a socket passes if its token is non-zero…
- [Low] The commit message says the affected callers are "mptcp_diag and
the userspace path manager".
- [Low] The patch uses a plain READ_ONCE() of msk->token as an
"initialisation complete" signal (net/mptcp/token.c:381), but nothing…
Pre-existing issues:
- [Medium] This problem wasn't introduced by this patch, but the walk in
mptcp_token_iter_next() (net/mptcp/token.c:370-393) does not follow…
--
net: mptcp: verify the token slot in mptcp_token_iter_next()
This patch makes mptcp_token_iter_next() re-read msk->token after it takes
a reference on a socket. The socket is skipped unless the token is
non-zero and hashes to the slot being walked. The goal is to stop the
iterator from returning a recycled msk whose pm state is not initialised.
> mptcp_token_iter_next() takes a reference on a socket found on the chain
> of the slot it is walking and then re-checks only net_eq(). A socket
> that was freed and whose memory has been reused by a new msk in the same
> network namespace passes that check while it is still zeroed, and the
> callers - mptcp_diag and the userspace path manager - then use mptcp_pm
> state that has not been initialised yet.
[Severity: Low]
Is "the userspace path manager" the right caller to name here?
Apart from mptcp_diag_dump(), every caller of mptcp_token_iter_next() is
in net/mptcp/pm_kernel.c:
mptcp_nl_add_subflow_or_signal_addr()
mptcp_nl_remove_subflow_and_signal_addr()
mptcp_nl_remove_id_zero_address()
mptcp_nl_flush_addrs_list()
mptcp_pm_nl_set_flags_all()
Each of them skips userspace PM sockets:
if (mptcp_pm_is_userspace(msk))
goto next;
net/mptcp/pm_userspace.c does not use the iterator. It uses
mptcp_token_get_sock(), which already re-checks the token after taking
the reference.
Could the commit message name the in-kernel path manager endpoint
operations instead?
> 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
[ ... ]
> @@ -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)) {
[Severity: Medium]
Does a non-zero token that maps to this slot really show that the msk is
on this chain and fully set up?
On the passive path, the token is published while the refcount is already
non-zero and before the msk is hashed. First, sk_clone_lock() does:
smp_wmb();
refcount_set(&newsk->sk_refcnt, 2);
Then mptcp_sk_clone_init() in net/mptcp/protocol.c does:
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)) {
Here is one way to hit it:
- A diag dump or PM netlink walk holds a stale RCU pointer to a freed msk
in slot S.
- That memory is reused by this clone.
- The new token happens to hash to S.
refcount_inc_not_zero_acquire() then succeeds, and the token is non-zero
and matches the slot. So the iterator returns an msk that is not hashed
yet.
Callers then do lockless reads before lock_sock(): sk_state, conn_list,
and the inet addresses via mptcp_local_address(). These race with the
initialisation above.
The failure path looks worse. mptcp_token_accept() can fail, for example
when mptcp_subflow_reqsk_clone()->mptcp_token_move_request() has moved
the request token during reqsk migration. In that case
mptcp_sk_clone_destroy() does:
bh_unlock_sock(nsk);
sock_put(nsk);
sock_set_flag(nsk, SOCK_DEAD);
tcp_orphan_count_inc();
inet_sk(nsk)->inet_num = 0;
inet_csk_destroy_sock(nsk);
A reader blocked in lock_sock() can get the socket right after
bh_unlock_sock(). Examples are mptcp_nl_remove_subflow_and_signal_addr()
and mptcp_nl_flush_addrs_list(). The same applies to lock_sock_fast() in
mptcp_diag_fill_info().
Can that reader then run pm and subflow operations while
inet_csk_destroy_sock()->mptcp_destroy() tears down the msk without the
socket lock?
Would a check tied to hash membership close this window? Another option
would be to assign msk->token inside mptcp_token_accept() under the
bucket lock.
[Severity: Low]
Is a plain READ_ONCE() enough to treat the token as an "initialisation
done" flag?
On the clone path, __mptcp_init_sock()->mptcp_pm_data_init() runs before
WRITE_ONCE(msk->token, ...) in mptcp_sk_clone_init(). There is no release
barrier between them.
On the reader side, refcount_inc_not_zero_acquire() pairs only with the
smp_wmb()/refcount_set() in sk_clone_lock(). That store comes before any
MPTCP init. After the token load there is only a control dependency.
The callers make some lockless reads before taking the socket lock:
mptcp_pm_is_userspace() (reads pm.pm_type)
list_empty(&msk->conn_list)
READ_ONCE(msk->fully_established)
the pm counters in mptcp_diag_fill_info():
info->mptcpi_extra_subflows = READ_ONCE(msk->pm.extra_subflows);
info->mptcpi_add_addr_signal = READ_ONCE(msk->pm.add_addr_signaled);
On arm64 or POWER, can these reads be satisfied before the token load?
They would then see the listener values copied by sock_copy() even though
the token check passed.
Would this need smp_store_release()/smp_load_acquire() on msk->token, or
a hash membership check?
> sock_put(sk);
> continue;
> }
[Severity: Medium]
This isn't a bug introduced by this patch, but the walk in
mptcp_token_iter_next() does not follow the nulls-list protocol that the
other msk_chain readers in net/mptcp/token.c use.
mptcp_token_get_sock() restarts when its post-acquire re-check fails, and
when the walk ends on another chain:
if (READ_ONCE(msk->token) != token ||
!net_eq(sock_net(sk), net)) {
sock_put(sk);
goto again;
}
...
if (get_nulls_value(pos) != (token & token_mask))
goto again;
mptcp_token_exists() does the same nulls check.
The msk cache is SLAB_TYPESAFE_BY_RCU. An msk deleted from slot X and
re-added to slot Y can move a lockless walker onto chain Y.
The new (token & token_mask) != slot test detects that hop, but it
responds with continue. The walker then takes and drops a reference on
each entry of chain Y, and stops at Y's nulls marker.
Are the remaining entries of slot X skipped for this dump or PM pass?
Before this patch the X entries were skipped as well, and Y's entries
were returned instead.
Should a failed slot check restart the bucket walk? And should
get_nulls_value(pos) be compared against slot when the walk ends?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/tencent_D0DCF4B132B20B70FB5AE2D9272AA4AEAF07%40qq.com
Technical Details
Message-ID:
<179490863464.3133.2064838572417107624@kernel.org>Path:
mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!nntp.comgw.net!eternal-september.org!feeder.eternal-september.org!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-365146-linux-kernel-netdev=dewy.ruReferences:
<tencent_647B95315D18DBA311A33E8120517E1DA60A@qq.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!nntp.comgw.net!eternal-september.org!feeder.eternal-september.org!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-365146-linux-kernel-netdev=dewy.ru From: netdev-bot+sashiko@kernel.org Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net v4 3/3] net: mptcp: verify the token slot in mptcp_token_iter_next() Date: Tue, 17 Nov 2026 09:43:54 +0000 Organization: Usenet Network Message-ID: <179490863464.3133.2064838572417107624@kernel.org> References: <tencent_647B95315D18DBA311A33E8120517E1DA60A@qq.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="2295808"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:TNQipE3ZBS6IDCcJd9UdA3qSD6c= sha256:4wIzCz7GXm0iP8tKHuoSNnl9QmbAgnIZrdLMszo1KsM= sha1:R0d16YyqLFuR+Kyk0ATpJDwQZAU= sha256:B0yuYbs4aCZfRSfMZOoZ9Ys8iM0QvfKSMJZQwjgjVwQ= List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id D3400114EEA; Tue, 17 Nov 2026 12:45:01 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.501 X-Spam-Status: No, score=-3.501 tagged_above=-9999 required=6.31 tests=[DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=kernel.org X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 1pNEngTD0X3b; Tue, 17 Nov 2026 12:44:55 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-365146-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org X-Received: from sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74]) by mail.dewy.ru (Postfix) with ESMTPS id BF058114EE6; Tue, 17 Nov 2026 12:44:45 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sto.lore.kernel.org (Postfix) with ESMTP id C0FEA602B78; Tue, 17 Nov 2026 09:44:44 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1794908637; b=rY8bd9Mwi+3VDADrI2gmmf2gK+8FHK8qtIxtocWKrFRA8ySaD4zydGTfxxoMeCKCegCX bCBYs0hcEq4KWXBT7KANY17WCd/QX3q5gmh+3XDU6EQ6itqDIex0+aczgKNbX1tUceGnF 6wej796c+2e6P+BAIVxDH2R3GX9b7YQjlT8cvuAqk/LLv63CqvL19r2mlr4KEG/JysREC XKxq2ttc2ZsGwvaW3r63ytGPIAPxdVpxuQ1jR+wjg3npmpnk5rd1bID3WCgSRv/ykda/K EzzfxGIqWjVrKz8R+oMotXGssePIrkCBPofGzMc0Qjsrwc2gignEdOvVr3OlxQ0kvzQ== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794908637; h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc: Date:Message-ID:In-Reply-To:References:X-sashiko-severity: Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version; bh=EkMkRGE3wUMYDlYWX26IfHh9fQHE7ly+qPAGDAGs94Y=; b=yJmqyZuaTp1P17DWrzJOV1CWeSVJB2peyBbBzG+BgmlgamwTxjQWwo6d4Kj0sphGnDGd l1XrpX/sYQsVG73Xv9KW2eNdqyuWWZIkhJy7XQpJExD3xM2Ehi3bBtdfpxDjQ4Z8rWtvy 49GiPjKxtqXrp4EXHaX4ZbYdxnfj1CKoceOURru1T1RPVyRZp49rxPdJoYKzz4skEpA/o SYX7IJugpUXQwBhnjT3vq1tQ6VlKGkvwYte5MujwRxLidKM7q6qpTJRYwNYt5Z0/pAoEk H5vyXrpuhnOtQM/baY5Bif4TVnmrZjJHjQ9R7WhfGXu0mrXsX1Yfzug/sZEVCwI+Nlw== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=P3smttsi; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E1BA7606A894; Tue, 17 Nov 2026 09:43:56 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=P3smttsi X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794908636; b=26/PW073ZYQxZFlCsAjcMWItFfikDPD82mE3PQRKmW1Hw5m2XdRVuYZU14B4zNfXmbC6 5XHXbmmHPjKMCgjEA4xO8DlwDy19omeHDq05e6deMooez7Vj56qHegOIjqLl+RR2ETf7I Lbdb6CVnOAvhoXxsX6rWcovNFmDOTosC9yz7cwNlTc357GFwYcopJJwTuYv2nRRazrAhd IDZTwAb1K4z17CvpDIP3WwT+Y5no8zuLc6I+VrULk0rtF2NL+yEghmN00xG3IWf9ycOM+ OZ/S3sV2UWEP1451kK2EKAjeFpPY5UvFf5W2womj7jIp3D+8Mblyha5gSWt/0DTgG4A== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794908636; h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID: In-Reply-To:References:X-sashiko-severity:Content-Type: Content-Transfer-Encoding:MIME-Version; bh=EkMkRGE3wUMYDlYWX26IfHh9fQHE7ly+qPAGDAGs94Y=; b=3zIX7bw4N+OiSWfwMBT38ZHEqnxPiJzLWOsI+3b9fbBXcXoeFNJwMqsjUtvW31Mni2Ar wGNi65zGWTq+j9nkxdr2jrzeMCq8Fk280pBN5+l+owXxThJiph7pBICoVbZJIjUponHuU +W+muDRsc44govm5kP1Cz23jZnaabrrKqaYru2h2ra27LJk8PcHMErm48/mZrRiHK62Ia rAxggwzVuS2Pdt/CHRrMtrq4O6jx2qQzyq8MvgKDtaiiOBWMZZ1egHHPVGSXTNotkgUzv 6Usg2M0d4FcS1Oa5OM1bHzzxEbsc9ATz+KvtJlJnf0WVbYZgq42DsG+2PI3EjVFYR1w== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=P3smttsi; arc=none smtp.remote-ip=100.103.45.18 X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 10EA8606A898; Tue, 17 Nov 2026 09:43:55 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0F0821F000D2; Tue, 17 Nov 2026 09:43:55 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794908635; bh=EkMkRGE3wUMYDlYWX26IfHh9fQHE7ly+qPAGDAGs94Y=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=P3smttsihzvyAwE/2EaRi4cKFqx4R/4ZOu2OGX3an0jJ+abA3lN4gk8bsaKvqfRkD L5WQMZ+0f9obDAc5cuTfpANlUNY+ef8amWshZFC5QG5qcupobxitUQ+QTaeX21jna5 jsHTCIVzoGw2vkx9vAOSdVgkH/6N/etJDhDWEyMrMyCNRyHvWnrThbWE0heiVcpvGG XCjuxucnK6/hiDNMIpydWo6BjI5kEhJD8pCZJo/tWB6cz14ZBvnV9AVCiMTEiCtEjN 64Z/HmFtSCpfDxHBcZVPHU0uIEMphMRfdLoJI4FBcV4bBHhHBo0/Mn/SX0r6UpOULH EA/YhbbSDtphQ== X-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 X-In-Reply-To: <tencent_647B95315D18DBA311A33E8120517E1DA60A@qq.com> X-sashiko-severity: Medium X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list