bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] x86/bpf: use bpf_capable() instead of capable(CAP_SYS_ADMIN)
@ 2025-08-06 14:31 Ondrej Mosnacek
  2025-08-07  1:18 ` Serge E. Hallyn
  0 siblings, 1 reply; 8+ messages in thread
From: Ondrej Mosnacek @ 2025-08-06 14:31 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann; +Cc: bpf, selinux, linux-security-module

Don't check against the overloaded CAP_SYS_ADMINin do_jit(), but instead
use bpf_capable(), which checks against the more granular CAP_BPF first.
Going straight to CAP_SYS_ADMIN may cause unnecessary audit log spam
under SELinux, as privileged domains using BPF would usually only be
allowed CAP_BPF and not CAP_SYS_ADMIN.

Link: https://bugzilla.redhat.com/show_bug.cgi?id=2369326
Fixes: d4e89d212d40 ("x86/bpf: Call branch history clearing sequence on exit")
Signed-off-by: Ondrej Mosnacek <omosnace@redhat.com>
---
 arch/x86/net/bpf_jit_comp.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
index 15672cb926fc1..2a825e5745ca1 100644
--- a/arch/x86/net/bpf_jit_comp.c
+++ b/arch/x86/net/bpf_jit_comp.c
@@ -2591,8 +2591,7 @@ emit_jmp:
 			seen_exit = true;
 			/* Update cleanup_addr */
 			ctx->cleanup_addr = proglen;
-			if (bpf_prog_was_classic(bpf_prog) &&
-			    !capable(CAP_SYS_ADMIN)) {
+			if (bpf_prog_was_classic(bpf_prog) && !bpf_capable()) {
 				u8 *ip = image + addrs[i - 1];
 
 				if (emit_spectre_bhb_barrier(&prog, ip, bpf_prog))
-- 
2.50.1


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

end of thread, other threads:[~2025-09-02 17:37 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-06 14:31 [PATCH] x86/bpf: use bpf_capable() instead of capable(CAP_SYS_ADMIN) Ondrej Mosnacek
2025-08-07  1:18 ` Serge E. Hallyn
2025-08-08 23:58   ` Serge E. Hallyn
2025-08-09  0:46     ` Alexei Starovoitov
2025-08-09  1:06       ` Serge E. Hallyn
2025-08-13  9:49       ` Ondrej Mosnacek
2025-08-25 11:40         ` Ondrej Mosnacek
2025-09-02 17:36         ` Alexei Starovoitov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).