From: Paolo Abeni <pabeni@redhat.com>
To: netdev-bot+sashiko@kernel.org, imv4bel@gmail.com
Cc: edumazet@kernel.org, ncardwell@google.com, kuniyu@google.com,
davem@davemloft.net, kuba@kernel.org, horms@kernel.org,
martin.lau@linux.dev, john.fastabend@gmail.com,
weiwan@google.com, sd@queasysnail.net, jiayuan.chen@linux.dev,
netdev@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH net v5 2/2] net: restore refcount ordering for lockless socket access
Date: Tue, 3 Nov 2026 15:30:05 +0100 [thread overview]
Message-ID: <0ce94ca2-e742-4b97-b704-1ae24da7b41f@redhat.com> (raw)
In-Reply-To: <179365718192.3131.3817815695107204474@kernel.org>
On 11/2/26 23:06, netdev-bot+sashiko@kernel.org wrote:
>> diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
>> index b0239d203f045..860145d810ed4 100644
>> --- a/net/ipv4/inet_hashtables.c
>> +++ b/net/ipv4/inet_hashtables.c
>> @@ -550,7 +550,7 @@ struct sock *__inet_lookup_established(const struct net *net,
>> if (sk->sk_hash != hash)
>> continue;
>> if (likely(inet_match(net, sk, acookie, ports, dif, sdif))) {
>> - if (unlikely(!refcount_inc_not_zero(&sk->sk_refcnt)))
>> + 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,
>
> [Severity: High]
> The commit message says the change targets lookups "where the socket is
> validated again after taking a reference". Should the MPTCP token lookups
> be converted too? They follow the same pattern but still use plain
> refcount_inc_not_zero():
>
> net/mptcp/token.c:mptcp_token_get_sock() {
> ...
> if (!refcount_inc_not_zero(&sk->sk_refcnt))
> goto not_found;
>
> if (READ_ONCE(msk->token) != token ||
> !net_eq(sock_net(sk), net)) {
> sock_put(sk);
> goto again;
> }
> ...
> }
>
> mptcp_token_iter_next() does the same thing: it increments and then checks
> net_eq() again.
>
> mptcp_prot uses SLAB_TYPESAFE_BY_RCU, and mptcp_sk_clone_init() clears
> SOCK_RCU_FREE on established msks:
>
> sock_reset_flag(nsk, SOCK_RCU_FREE);
>
> So an msk can be freed and its slot reused while an RCU reader still holds
> the address.
>
> On weakly ordered CPUs, can the token and sk_net loads in the re-check run
> before the increment? If so, they could see the old object's values, and
> the lookup would return a referenced msk for a different connection or
> netns.
>
> Callers include the userspace PM netlink operations that look up by
> token, MP_JOIN handling in subflow.c and syncookies.c, and the diag and PM
> iterators. HMAC validation would probably reject most of the MP_JOIN
> cases.
>
> mptcp_subflow_reqsk_clone() already uses refcount_inc_not_zero_acquire()
> on the same msk objects.
Even this part is better handled with a separate patch.
/P
next prev parent reply other threads:[~2026-11-03 14:30 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-29 21:42 [PATCH net v5 0/2] inet: fix lockless ehash walk races Hyunwoo Kim
2026-10-29 21:42 ` [PATCH net v5 1/2] inet: reject unhashed sockets during established lookups Hyunwoo Kim
2026-11-02 22:06 ` netdev-bot+sashiko
2026-10-29 21:42 ` [PATCH net v5 2/2] net: restore refcount ordering for lockless socket access Hyunwoo Kim
2026-10-29 21:55 ` Kuniyuki Iwashima
2026-11-02 22:06 ` netdev-bot+sashiko
2026-11-03 7:47 ` Hyunwoo Kim
2026-11-03 14:30 ` Paolo Abeni [this message]
2026-11-03 14:49 ` Eric Dumazet
2026-11-03 14:40 ` [PATCH net v5 0/2] inet: fix lockless ehash walk races patchwork-bot+netdevbpf
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=0ce94ca2-e742-4b97-b704-1ae24da7b41f@redhat.com \
--to=pabeni@redhat.com \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=horms@kernel.org \
--cc=imv4bel@gmail.com \
--cc=jiayuan.chen@linux.dev \
--cc=john.fastabend@gmail.com \
--cc=kuba@kernel.org \
--cc=kuniyu@google.com \
--cc=martin.lau@linux.dev \
--cc=ncardwell@google.com \
--cc=netdev-bot+sashiko@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=sd@queasysnail.net \
--cc=stable@vger.kernel.org \
--cc=weiwan@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