From: netdev-bot+sashiko@kernel.org
To: shyckless@gmail.com
Cc: pabeni@redhat.com, edumazet@kernel.org, davem@davemloft.net,
kuba@kernel.org, kuniyu@google.com, willemb@google.com,
netdev@vger.kernel.org, bpf@vger.kernel.org,
martin.lau@linux.dev, linux-kernel@vger.kernel.org,
horms@kernel.org
Subject: Re: [PATCH net] net: reuseport: honour SO_LOCK_FILTER in SO_DETACH_REUSEPORT_BPF
Date: Mon, 23 Nov 2026 08:47:22 +0000 [thread overview]
Message-ID: <179542364209.3135.6346728453187808939@kernel.org> (raw)
In-Reply-To: <20261122-reuseport-lock-filter-v1-1-a3e5324c8d55@gmail.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] The fix only covers the setsockopt(SO_DETACH_REUSEPORT_BPF)
path.
--
net: reuseport: honour SO_LOCK_FILTER in SO_DETACH_REUSEPORT_BPF
This commit makes reuseport_detach_prog() return -EPERM when
SOCK_FILTER_LOCKED is set. Without it, an unprivileged process that is
handed a locked socket can remove the reuseport program with
SO_DETACH_REUSEPORT_BPF. This matches what sk_detach_filter() already
does.
> diff --git a/net/core/sock_reuseport.c b/net/core/sock_reuseport.c
> index b9e5648fa4c51..cdff61161a70a 100644
> --- a/net/core/sock_reuseport.c
> +++ b/net/core/sock_reuseport.c
> @@ -727,6 +727,9 @@ int reuseport_detach_prog(struct sock *sk)
> struct sock_reuseport *reuse;
> struct bpf_prog *old_prog;
>
> + if (sock_flag(sk, SOCK_FILTER_LOCKED))
> + return -EPERM;
> +
[Severity: Medium]
This closes the setsockopt(SO_DETACH_REUSEPORT_BPF) path. Can the holder
of a locked TCP SO_REUSEPORT listener still drop the program by
disconnecting the listener and then calling listen() again?
connect(fd, AF_UNSPEC) or shutdown(fd, SHUT_RD) on a listener goes
through this chain, and none of these functions check SOCK_FILTER_LOCKED:
tcp_disconnect()
tcp_set_state(sk, TCP_CLOSE)
sk->sk_prot->unhash(sk)
inet_unhash()
reuseport_stop_listen_sock()
reuseport_detach_sock()
With net.ipv4.tcp_migrate_req at its default of 0, and a program that is
not BPF_SK_REUSEPORT_SELECT_OR_MIGRATE, reuseport_stop_listen_sock()
reaches the immediate detach:
net/core/sock_reuseport.c:reuseport_stop_listen_sock() {
...
/* Not capable to do migration, detach immediately */
reuseport_detach_sock(sk);
...
}
reuseport_detach_sock() clears sk->sk_reuseport_cb. If this socket was
the only member, it also frees the group:
if (reuse->num_socks + reuse->num_closed_socks == 0)
call_rcu(&reuse->rcu, reuseport_free_rcu);
reuseport_free_rcu() then releases the locked program:
sk_reuseport_prog_free(rcu_dereference_protected(reuse->prog, 1));
tcp_set_state() keeps the port bound when SOCK_BINDPORT_LOCK is set, so
listen() can be called again on the same port:
sk->sk_prot->unhash(sk);
if (inet_csk(sk)->icsk_bind_hash &&
!(sk->sk_userlocks & SOCK_BINDPORT_LOCK))
inet_put_port(sk);
On the second listen(), inet_reuseport_add_sock() finds no sibling and
calls reuseport_alloc(). Because sk_reuseport_cb is now NULL, this
creates a new group with prog == NULL. The socket keeps listening on
the same port, but the program is gone.
Documentation/networking/filter.rst says that once SO_LOCK_FILTER is
set, "a filter cannot be removed or changed" and that the filter "will
be kept until the socket is closed".
This only happens when the locked socket is the only member of its
group. If it has siblings, re-listen puts it back into the existing
group through reuseport_add_sock(). With migration enabled, the socket
moves to the closed section and keeps the program.
In a one-socket group, the program matters mostly when an SK_REUSEPORT
eBPF program uses SK_DROP to decide which connections are admitted. The
group-wide load-balancing change described in the commit message cannot
happen through this path.
Should the disconnect and re-listen path also respect
SOCK_FILTER_LOCKED, or should the commit message say that only the
setsockopt detach path is covered?
> old_prog = NULL;
> spin_lock_bh(&reuseport_lock);
> reuse = rcu_dereference_protected(sk->sk_reuseport_cb,
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261122-reuseport-lock-filter-v1-1-a3e5324c8d55%40gmail.com
next prev parent reply other threads:[~2026-11-23 8:47 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-22 8:17 [PATCH net] net: reuseport: honour SO_LOCK_FILTER in SO_DETACH_REUSEPORT_BPF Suyuan Wang via B4 Relay
2026-11-23 8:47 ` netdev-bot+sashiko [this message]
2026-11-23 9:01 ` Wong Steve
2026-11-23 9:04 ` Wong Steve
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=179542364209.3135.6346728453187808939@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=kuniyu@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=shyckless@gmail.com \
--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