All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net] tcp: restrict SO_ATTACH_BPF to privileged users
@ 2026-10-28 21:58 Manjunath Patil
  2026-10-28 22:12 ` Alexei Starovoitov
  0 siblings, 1 reply; 4+ messages in thread
From: Manjunath Patil @ 2026-10-28 21:58 UTC (permalink / raw)
  To: netdev@vger.kernel.org
  Cc: Eric Dumazet, David S. Miller, Jakub Kicinski, Paolo Abeni,
	Simon Horman, Alexei Starovoitov, Daniel Borkmann,
	Willem de Bruijn, bpf@vger.kernel.org, Manjunath Patil,
	stable@vger.kernel.org

Commit 5d39580f68e6 ("tcp: restrict SO_ATTACH_FILTER to priv users")
requires CAP_NET_ADMIN to attach a classic BPF filter to a TCP socket.
However, a caller can still attach an eBPF socket filter through
SO_ATTACH_BPF without this capability. Both options install a filter
that runs on incoming TCP packets.

Disabling unprivileged BPF loading does not close this gap: a caller
that already holds a socket-filter program file descriptor can still
use SO_ATTACH_BPF.

Use one CAP_NET_ADMIN check for both attachment options before taking
the socket lock. Use the same namespace-aware capability helper already
used by SO_ATTACH_FILTER. Leave other socket types unchanged.

Fixes: 5d39580f68e6 ("tcp: restrict SO_ATTACH_FILTER to priv users")
Assisted-by: Codex:gpt-6
Signed-off-by: Manjunath Patil <manjunath.b.patil@oracle.com>
---
 net/core/sock.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/net/core/sock.c b/net/core/sock.c
index e7405be8941f..5f6d8b9ff4f6 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -1310,6 +1310,12 @@ int sk_setsockopt(struct sock *sk, int level, int optname,
 					optlen, optname == SO_RCVTIMEO_OLD);
 	}
 
+	/* Restrict TCP socket filters to prevent sequence/ack-number probing. */
+	if ((optname == SO_ATTACH_FILTER || optname == SO_ATTACH_BPF) &&
+	    sk_is_tcp(sk) &&
+	    !sockopt_ns_capable(sock_net(sk)->user_ns, CAP_NET_ADMIN))
+		return -EPERM;
+
 	sockopt_lock_sock(sk);
 
 	switch (optname) {
@@ -1466,11 +1472,6 @@ int sk_setsockopt(struct sock *sk, int level, int optname,
 	case SO_ATTACH_FILTER: {
 		struct sock_fprog fprog;
 
-		if (sk_is_tcp(sk) &&
-		    !sockopt_ns_capable(sock_net(sk)->user_ns, CAP_NET_ADMIN)) {
-			ret = -EPERM;
-			break;
-		}
 		ret = copy_bpf_fprog_from_user(&fprog, optval, optlen);
 		if (!ret)
 			ret = sk_attach_filter(&fprog, sk);

base-commit: 65ba8f34ec886ec72b2c07ddc8cf3d815c32869d
-- 
2.52.0

^ permalink raw reply related	[flat|nested] 4+ messages in thread
* Re: [PATCH net] tcp: restrict SO_ATTACH_BPF to privileged users
@ 2026-10-28 22:01 netdev-bot+sinfo
  0 siblings, 0 replies; 4+ messages in thread
From: netdev-bot+sinfo @ 2026-10-28 22:01 UTC (permalink / raw)
  To: Manjunath Patil
  Cc: netdev@vger.kernel.org, Eric Dumazet, David S. Miller,
	Jakub Kicinski, Paolo Abeni, Simon Horman, Alexei Starovoitov,
	Daniel Borkmann, Willem de Bruijn, bpf@vger.kernel.org,
	stable@vger.kernel.org

Hi!

This is an automated message. This series looks like a fix, but its
commit messages seem to be missing some information:

 - How the issue was discovered, e.g. hit in production, hit during
   development, syzbot report, manual code inspection, LLM or static
   analysis tool scan.

 - Whether the issue was actually triggered, or is only theoretical
   (e.g. found by code inspection). If it was triggered please include
   the symptoms, like the stack trace or error messages.

Please do not repost the series just to address the above. Instead,
reply to this email with the missing information, so that reviewers
can take it into account. If the series needs another revision for
other reasons, please include the information in the commit messages
then.

The evaluation is done by an LLM so it may be wrong, if you think
that is the case please reply and explain.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-10-28 23:44 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-28 21:58 [PATCH net] tcp: restrict SO_ATTACH_BPF to privileged users Manjunath Patil
2026-10-28 22:12 ` Alexei Starovoitov
2026-10-28 23:43   ` manjunath.b.patil
  -- strict thread matches above, loose matches on Subject: below --
2026-10-28 22:01 netdev-bot+sinfo

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.