From: Kuniyuki Iwashima <kuniyu@google.com>
To: Lin Jiapeng <ljp1205831794@gmail.com>
Cc: Eric Dumazet <edumazet@kernel.org>,
Paolo Abeni <pabeni@redhat.com>,
Willem de Bruijn <willemb@google.com>,
"David S. Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>,
Simon Horman <horms@kernel.org>, Martin KaFai Lau <kafai@fb.com>,
Daniel Borkmann <daniel@iogearbox.net>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
TencentOS Corvus AI <corvus@tencent.com>,
stable@vger.kernel.org, Lin Jiapeng <jiapenglin@tencent.com>
Subject: Re: [PATCH net] net: reuseport: avoid duplicate closed socket insertion
Date: Sat, 7 Nov 2026 19:37:08 +0000 [thread overview]
Message-ID: <au99hnLthtlu0Mln@google.com> (raw)
In-Reply-To: <20261106135841.418-1-ljp1205831794@gmail.com>
On Fri, 06 Nov 2026 21:58:38 +0800, Lin Jiapeng wrote:
> Clearing SO_REUSEPORT on a TCP listener clears sk_reuseport but leaves
> sk_reuseport_cb attached to its reuseport group. A subsequent listen()
> does not put the socket back into the listening section because
> inet_hash() checks sk_reuseport. However, inet_unhash() checks
> sk_reuseport_cb and calls reuseport_stop_listen_sock().
>
> With request migration enabled, reuseport_stop_listen_sock() ignores
> whether __reuseport_detach_sock() actually removed the socket from the
> listening section and unconditionally appends it to the closed section.
> Repeated connect(AF_UNSPEC)/listen() cycles therefore insert the same
> socket until num_closed_socks exceeds max_socks. The next insertion
> writes before socks[], overlapping prog on x86-64 and leading to type
> confusion when a reuseport program is attached or detached.
>
> Only insert the socket into the closed section when it was actually
> removed from the listening section. A socket that was not rehashed as a
> listener is already represented in the closed section, so leaving it
> there preserves request migration semantics and prevents duplicate
> entries and the resulting negative array indices.
>
> Fixes: 333bb73f620e1 ("tcp: Keep TCP_CLOSE sockets in the reuseport group.")
> Reported-by: TencentOS Corvus AI <corvus@tencent.com>
> Cc: stable@vger.kernel.org
> Signed-off-by: Lin Jiapeng <jiapenglin@tencent.com>
The right fix is to disallow changing SO_REUSEPORT once
the socket is bind()ed.
I was sidetacked while preparing fixes, so let me post them.
https://lore.kernel.org/netdev/20260928174546.4022833-1-kuniyu@google.com/
pw-bot: rejected
> ---
> net/core/sock_reuseport.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/net/core/sock_reuseport.c b/net/core/sock_reuseport.c
> index fccbdd0430b0..775f446516c3 100644
> --- a/net/core/sock_reuseport.c
> +++ b/net/core/sock_reuseport.c
> @@ -480,8 +480,8 @@ void reuseport_stop_listen_sock(struct sock *sk)
> */
> bpf_sk_reuseport_detach(sk);
>
> - __reuseport_detach_sock(sk, reuse);
> - __reuseport_add_closed_sock(sk, reuse);
> + if (__reuseport_detach_sock(sk, reuse))
> + __reuseport_add_closed_sock(sk, reuse);
>
> spin_unlock_bh(&reuseport_lock);
> return;
> --
> 2.55.0
>
prev parent reply other threads:[~2026-11-07 19:37 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-06 13:58 [PATCH net] net: reuseport: avoid duplicate closed socket insertion Lin Jiapeng
2026-11-06 14:01 ` netdev-bot+sinfo
2026-11-06 14:55 ` Lin Jiapeng
2026-11-07 5:02 ` Jiayuan Chen
2026-11-07 8:08 ` Lin Jiapeng
2026-11-07 19:37 ` Kuniyuki Iwashima [this message]
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=au99hnLthtlu0Mln@google.com \
--to=kuniyu@google.com \
--cc=corvus@tencent.com \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=horms@kernel.org \
--cc=jiapenglin@tencent.com \
--cc=kafai@fb.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ljp1205831794@gmail.com \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.