๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #20820

Re: [PATCH net] net: reuseport: honour SO_LOCK_FILTER in SO_DETACH_REUSEPORT_BPF

#20820
From: netdev-bot+sashiko
Date: Mon, 23 Nov 2026 08:47
110 lines
11924 bytes
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
Technical Details
Message-ID: <179542364209.3135.6346728453187808939@kernel.org>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-369153-linux-kernel-netdev=dewy.ru
References: <20261122-reuseport-lock-filter-v1-1-a3e5324c8d55@gmail.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-369153-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net] net: reuseport: honour SO_LOCK_FILTER in
 SO_DETACH_REUSEPORT_BPF
Date: Mon, 23 Nov 2026 08:47:22 +0000
Organization: Usenet Network
Message-ID: <179542364209.3135.6346728453187808939@kernel.org>
References: <20261122-reuseport-lock-filter-v1-1-a3e5324c8d55@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="3830377"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:qlq2GZfwl3NJsC3TqM2Myuipb0Y= sha256:qIZC3UVRz+LFvxwj1l/K9xhjAjqrqskduAFW49lLFL4=
	sha1:3+Y4OEjFYTtyjCEIDNZTVZRpC5M= sha256:ENLuldj4VyJJt4KgcbQppwyMsVrIwp3kb+IMPq7OUBA=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id EEA9D125D98; Mon, 23 Nov 2026 11:47:46 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.4
X-Spam-Status: No, score=-3.4 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1,
	DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id GDtSIX_W9py9;
	Mon, 23 Nov 2026 11:47:43 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-369153-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id D33C9125D97; Mon, 23 Nov 2026 11:47:33 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id D70162A620; Mon, 23 Nov 2026 08:47:29 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1795423649;
	b=3H1M5NAc4wLxSb8x3zN+T3mmXy0y71SmnujdOcb1SzBH8oWS4/yDNX+CzcI18UIc9rqo
	 A5qK/N1UnU4Rvr951HcWGPdhaNE6/0Vxi0dqswnQzJ6tAGVY0TFhZQHM/8pm23uP6/83j
	 bMtCwmeFyIkqXEbBa+TdvJJZWmkQGhm+dcHx8nkp3Mc8DIWSRsj6c1GczeCzW6zVfRZ6B
	 260OMI6V29NbPQYJ8hRXhO+HBDlIxS+oSQeIzOQYShlisFiIZm+YjCXPG/+YsSp7tpo8r
	 xXPSNlfo6muWmGjS0pjbO6kDKiEzsmUb+HcrqXlLfcGb4Pbo8+gWqmrh8tRyF1T/c8w==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795423649;
	h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc:
	 Date:Message-ID:In-Reply-To:References:X-sashiko-severity:
	 Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version;
	bh=0xoAI2aZiZKz5fbdLwbV+D0yONBgbldgE9alS44kdKk=;
	b=SY3AqO6d7c6tjGFPlLCVQehcMnvsjwLeEzEQA5Hzba35KBQOUsrEOeViXQL4VykSkmMO
	 VKg1GPuX+r0/gaAX4NvwOybkiOYDR4bfp5PsTSxqx+COoXqqno/dSOc01bhtFe306zAul
	 OdC+aL/fiZ7fSCyMBzSalXKt4NLvCi76UuvVHSCaV6o13jHrCCVZshezdE6VWtZVFqM40
	 4qMobTqVCL8B9FnISX9eQbGC4TdLJPIgsd1s3hijA9uRqIBCuycMpdpelXadpx6HQMPFs
	 ZxL1XcxAkHV+cBi/6+vsnDlAuObzUm6ek/HxNkctrrJLXwY5AmqbJy+ONlv3dxtNzig==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Rwf2JgKV;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id AE276606A32D;
	Mon, 23 Nov 2026 08:47:29 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Rwf2JgKV
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1795423643;
	b=ug5GUOonisR83PsJPtADgsUdabU9EgXHbDAmBRHPkYZnsOqpGBT5hHJkpphYa9JvpaYE
	 hNpA1ikUgnKODhQ3U1xvFadjmxCE2X0yW69yp71igp8aKr5+tFGcj72Nts3NeJXhdRsi1
	 WN2bbEmMlOwKXPEQPZ1rbjFeg5ujp80ngXqWEaOCQuvdtm5pPAtwwbFvd3woP1fwInEsj
	 150Gn9D/om35gRR8CsWxMocnEqW2u5OCOpYXmO6LI6tFJ/4E/L1Ecs+UFYbn0yiiQNmdz
	 V8C3r07gwY4/UJmmBjWd8j4dx8ELlfkObGDoUezhJdBvX3SwI3rVZvmOMez+WR1v8pQ==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795423643;
	h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID:
	 In-Reply-To:References:X-sashiko-severity:Content-Type:
	 Content-Transfer-Encoding:MIME-Version;
	bh=0xoAI2aZiZKz5fbdLwbV+D0yONBgbldgE9alS44kdKk=;
	b=OEeKWWiGGaKaqgXUvg+ocfTyWILUVreUEUauniwLNTSB1A9SbG2C7fEXev6xWAzfTkRP
	 0oR2Cn203T1NHPX//q35Yju6ocA1rXW5+PtLaF/bbDkNnCUftTBIbZ60KT1KzgldBzfdd
	 3VmrklB+nEo+pQ9Br86uyDB+OeSibBn8+KOW2crOv6QFv+gH6XsWhcbSgpbrqNcGvFLo2
	 IhC9jdwFQXaN50taKxZnlb2y9tUYVjKgJ2DYxitNBM2bejElnJ6n9DVZUDZcPnbAlxFVM
	 Bp9nH4Wt9SoCH7u/xhD5RAepff70ri/LfCKMLkZtV+MUwkyotQYbscBjl/2COtRFE3g==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Rwf2JgKV;
	arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id CAC30606A31A;
	Mon, 23 Nov 2026 08:47:23 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 874071F000CF;
	Mon, 23 Nov 2026 08:47:22 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1795423643;
	bh=0xoAI2aZiZKz5fbdLwbV+D0yONBgbldgE9alS44kdKk=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=Rwf2JgKVsS3H77PJppUUvv4nvblUNhTmnDqxT48OAdT320TnAi1uKuDRQraIwOHaG
	 JCzJ0OKgG61F1cK9knaS845UxSk6CpippWqnnhBaPP5kYAdH9M+C0gsvV7tLUQGHCh
	 OYaNnjGujS3YmQ29L0uKMFj6fmB/N2KhhCHIYHIXxOOiRJ3xCrRqTKz+Zc9N9SqsxD
	 UPcft5J44vREXgLF+PiIpSqO8lP5qv4OQsuiqZEE6jf2GPoR/dEMPrmUrc4i3eGM+Y
	 gXGhyXAhr+71ykOkbRT5qUvGqrhZi0iQvmPyWDIwEYQaas4XC0apDCmcu5MBMAmCHu
	 U1ZraY5e/o6Lg==
X-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
X-In-Reply-To: <20261122-reuseport-lock-filter-v1-1-a3e5324c8d55@gmail.com>
X-sashiko-severity: Medium
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list