[PATCH net] net: reuseport: honour SO_LOCK_FILTER in SO_DETACH_REUSEPORT_BPF
From: Suyuan Wang via B4 Relay
Date: Sun Nov 22 2026 - 03:17:32 EST
From: Suyuan Wang <stevewong@xxxxxxxxxxx>
SO_LOCK_FILTER lets a process lock the filters on a socket before
handing it to a less privileged one. Once it is set, the existing attach
and detach paths reject changes to the socket's BPF filters with -EPERM,
but SO_DETACH_REUSEPORT_BPF does not check SOCK_FILTER_LOCKED. So an
unprivileged process that receives a locked socket can still remove the
reuseport program, which then changes how packets and connections are
spread over the whole reuseport group.
Return -EPERM from reuseport_detach_prog() when the filter is locked,
like sk_detach_filter() does.
Found with a static analysis tool and checked by hand.
Fixes: 99f3a064bc2e ("bpf: net: Add SO_DETACH_REUSEPORT_BPF")
Cc: stable@xxxxxxxxxxxxxxx
Co-developed-by: Kaixuan Li <kaixuan.li@xxxxxxxxxx>
Signed-off-by: Kaixuan Li <kaixuan.li@xxxxxxxxxx>
Signed-off-by: Suyuan Wang <stevewong@xxxxxxxxxxx>
---
Tested in QEMU (x86_64): root binds a UDP socket with SO_REUSEPORT,
attaches a reuseport cBPF program and sets SO_LOCK_FILTER, then a child
running as nobody uses the inherited socket.
Before:
SO_ATTACH_REUSEPORT_CBPF: EPERM
SO_DETACH_FILTER: EPERM
SO_DETACH_REUSEPORT_BPF: succeeds, the program is gone
After:
SO_DETACH_REUSEPORT_BPF: EPERM as well
---
net/core/sock_reuseport.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/net/core/sock_reuseport.c b/net/core/sock_reuseport.c
index b9e5648fa4c5..cdff61161a70 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;
+
old_prog = NULL;
spin_lock_bh(&reuseport_lock);
reuse = rcu_dereference_protected(sk->sk_reuseport_cb,