public inbox for bpf@vger.kernel.org
 help / color / mirror / Atom feed
From: Guillaume GONNET <ggonnet.linux@gmail.com>
To: bpf@vger.kernel.org
Cc: ast@kernel.org, daniel@iogearbox.net, john.fastabend@gmail.com,
	Guillaume GONNET <ggonnet.linux@gmail.com>
Subject: [PATCH] bpf: fix TCX/netkit detach permissions when prog FD isn't given
Date: Sat, 24 Jan 2026 22:43:28 +0100	[thread overview]
Message-ID: <20260124214328.185113-1-ggonnet.linux@gmail.com> (raw)

Since c8644cd0e, BPF permissions are indirectly checked by having a
program FD or bpffs ACL. When using BPF_PROG_DETACH command on TCX or
netkit device, it's not required to provide a program FD. Instead, the
program can be specified using a relative specifier (eg., BPF_F_AFTER).

In this case, there is no permission check as there is no FD involved,
so any user can execute that detach command. This is problematic when
BPF is used to filter out packets not intended to user as it can just
remove the filter from the network interface.

For this reason, require CAP_NET_ADMIN or CAP_SYS_ADMIN in detach (only
when the BPF program FD isn't provided).

Signed-off-by: Guillaume GONNET <ggonnet.linux@gmail.com>
---
 kernel/bpf/syscall.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index 3c5c03d43f5f..d1600aef6e03 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -4563,6 +4563,8 @@ static int bpf_prog_detach(const union bpf_attr *attr)
 			prog = bpf_prog_get_type(attr->attach_bpf_fd, ptype);
 			if (IS_ERR(prog))
 				return PTR_ERR(prog);
+		} else if (!bpf_net_capable()) {
+			return -EPERM;
 		}
 	} else if (is_cgroup_prog_type(ptype, 0, false)) {
 		if (attr->attach_flags || attr->relative_fd)
-- 
2.34.1


             reply	other threads:[~2026-01-24 21:44 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-24 21:43 Guillaume GONNET [this message]
2026-01-24 22:06 ` [PATCH] bpf: fix TCX/netkit detach permissions when prog FD isn't given bot+bpf-ci
2026-01-26 13:24 ` Daniel Borkmann
2026-01-26 17:03   ` Guillaume GONNET
2026-01-26 17:07   ` [PATCH bpf] " Guillaume GONNET
2026-01-26 17:23     ` bot+bpf-ci
2026-01-26 17:34       ` [PATCH] " Guillaume GONNET
2026-01-26 21:40         ` patchwork-bot+netdevbpf
2026-01-27  1:56         ` kernel test robot
     [not found]           ` <CAADnVQJNvx34irz6JYbmZvmaYU0AGRDcu8znsKjA_di798RisA@mail.gmail.com>
2026-01-27  2:29             ` Alexei Starovoitov
2026-01-27  8:26               ` [PATCH bpf v4] bpf: Fix tcx/netkit detach permissions when prog fd " Guillaume Gonnet
2026-01-27 13:10                 ` Daniel Borkmann
2026-01-27 16:02                   ` [PATCH bpf v5] " Guillaume Gonnet
2026-01-28  2:50                     ` patchwork-bot+netdevbpf
2026-01-27  3:12         ` [PATCH] bpf: fix TCX/netkit detach permissions when prog FD " kernel test robot
2026-01-26 17:48       ` [PATCH bpf] " Daniel Borkmann

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=20260124214328.185113-1-ggonnet.linux@gmail.com \
    --to=ggonnet.linux@gmail.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=john.fastabend@gmail.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