mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH net] net: reuseport: honour SO_LOCK_FILTER in SO_DETACH_REUSEPORT_BPF
@ 2026-11-22  8:17 Suyuan Wang via B4 Relay
  0 siblings, 0 replies; only message in thread
From: Suyuan Wang via B4 Relay @ 2026-11-22  8:17 UTC (permalink / raw)
  To: pabeni, edumazet, davem, kuba, kuniyu, willemb
  Cc: netdev, bpf, martin.lau, linux-kernel, horms

From: Suyuan Wang <stevewong@hust.edu.cn>

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@vger.kernel.org
Co-developed-by: Kaixuan Li <kaixuan.li@ntu.edu.sg>
Signed-off-by: Kaixuan Li <kaixuan.li@ntu.edu.sg>
Signed-off-by: Suyuan Wang <stevewong@hust.edu.cn>
---
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,





^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-22  8:17 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-22  8:17 [PATCH net] net: reuseport: honour SO_LOCK_FILTER in SO_DETACH_REUSEPORT_BPF Suyuan Wang via B4 Relay

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®