net/mptcp/token.c | 13 ++++++++--- net/mptcp/token_test.c | 51 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 3 deletions(-)
From: NanHang <2122295973@qq.com> This series restores acquire ordering for the mptcp token lookup and fixes two pre-existing defects in that hash table which ordering alone cannot cover. Patch 1 converts mptcp_token_get_sock() and mptcp_token_iter_next() to refcount_inc_not_zero_acquire(). These sockets live in a SLAB_TYPESAFE_BY_RCU slab, so the re-check of msk->token and sock_net() after the increment only rejects a recycled socket if those loads are ordered after the increment; without the acquire they can be satisfied before it, against the previous owner's contents. Patch 2 rejects token 0 in mptcp_token_get_sock(). Token 0 is never assigned, but it is what mptcp_token_destroy() stores into a socket being torn down, and what a freshly allocated msk holds until it is hashed. For a lookup for token 0 both validations compare 0 with 0 and accept such a socket; the token is copied from the wire by mptcp_parse_option(), so a peer can ask for it. The join path then uses the result, including msk->pm.anno_list, which is initialised only later. Patch 3 makes mptcp_token_iter_next() re-read the token after the increment and drop the socket unless it is non-zero and still hashes to the slot being walked, so a socket recycled in the same network namespace is not handed to mptcp_diag or the userspace path manager before it is initialised. None of the three has a runtime trigger. Patch 1 is argued at the instruction level (on arm64 the CAS becomes CASA; on x86-64 both variants compile to the same lock cmpxchg) and KCSAN cannot observe it, since it does not model reordering of marked accesses. Patches 2 and 3 are static arguments; patch 2 now carries a KUnit case that fails without the guard, which is as far as the state can be constructed without the race. v1 -> v2: - Point the Fixes: tags at the commits that introduced each lockless lookup instead of at the refcount consolidation (sashiko review). v2 -> v3: - Rewrite the rationale of the ordering patch: the acquire pairs with the SLAB_TYPESAFE_BY_RCU reuse window published by sock_init_data_uid(), not with mptcp_token_destroy() (sashiko review). - Add the token 0 and iterator patches, reported by the same review. v3 -> v4: - Drop "net: core: take the reuseport migration reference with acquire ordering". reuseport_migrate_sock() does not validate anything after the increment, and the listener state that could be raced is re-checked under queue->rskq_lock in inet_csk_reqsk_queue_add(), so the acquire orders nothing there (sashiko review). v4 -> v5: - Add a KUnit case for the token 0 guard, as asked by netdev-bot+sinfo. Hang Nan (3): net: mptcp: take token lookup references with acquire ordering net: mptcp: reject token 0 in mptcp_token_get_sock() net: mptcp: verify the token slot in mptcp_token_iter_next() net/mptcp/token.c | 13 ++++++++--- net/mptcp/token_test.c | 51 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 3 deletions(-) -- 2.47.3
Hi Hang Nan, On 16/11/2026 15:58, Hang Nan wrote: > This series restores acquire ordering for the mptcp token lookup and fixes > two pre-existing defects in that hash table which ordering alone cannot > cover. I didn't do a full review of this series because of the build failures, but here are just a couple of quick notes: - The patches you send are not linked to the cover-letter, see the In-Reply-To [1] pointing to a different Message-ID than the cover-letter [2]. Your messages ID are probably modified when sent. - Please wait for Netdev Sashiko [3] before sending new versions. - Use 'mptcp:' prefix instead of 'net: mptcp:' - Split the new kunit tests from the modification in the code to ease backports. - (Honestly, a test for a !token guard is probably not worth 50 lines. The first KUNIT_EXPECT_PTR_EQ on the empty table, or no new test at all seems more reasonable.) - (I agree that the Token 0 is never assigned... in Linux: the RFC8684 accepts it, but the Linux implementation don't. Maybe mention that in the commit message to avoid confusions.) [1] https://lore.kernel.org/tencent_BB8DA72524E32FD374B8B2950B247B62E207@qq.com [2] https://lore.kernel.org/tencent_50E9A78F95855D54DA67136F3D8520017F0A@qq.com [3] https://netdev-ai.bots.linux.dev/sashiko/ Cheers, Matt -- Sponsored by the NGI0 Core fund.
© 2016 - 2026 Red Hat, Inc.