mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Suyuan Wang via B4 Relay <devnull+shyckless.gmail.com@kernel.org>
To: pabeni@redhat.com, edumazet@kernel.org, davem@davemloft.net,
	 kuba@kernel.org, kuniyu@google.com, willemb@google.com
Cc: netdev@vger.kernel.org, bpf@vger.kernel.org,
	martin.lau@linux.dev,  linux-kernel@vger.kernel.org,
	horms@kernel.org
Subject: [PATCH net] net: reuseport: honour SO_LOCK_FILTER in SO_DETACH_REUSEPORT_BPF
Date: Sun, 22 Nov 2026 08:17:26 +0000	[thread overview]
Message-ID: <20261122-reuseport-lock-filter-v1-1-a3e5324c8d55@gmail.com> (raw)

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,





                 reply	other threads:[~2026-11-22  8:17 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261122-reuseport-lock-filter-v1-1-a3e5324c8d55@gmail.com \
    --to=devnull+shyckless.gmail.com@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

all inboxes | Powered by JetHome®