arm64: bpf: Only mitigate cBPF programs loaded by unprivileged users
authorJames Morse <james.morse@arm.com>
Tue, 29 Apr 2025 15:03:38 +0000 (16:03 +0100)
committerJames Morse <james.morse@arm.com>
Thu, 8 May 2025 14:29:03 +0000 (15:29 +0100)
Support for eBPF programs loaded by unprivileged users is typically
disabled. This means only cBPF programs need to be mitigated for BHB.

In addition, only mitigate cBPF programs that were loaded by an
unprivileged user. Privileged users can also load the same program
via eBPF, making the mitigation pointless.

Signed-off-by: James Morse <james.morse@arm.com>
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
arch/arm64/net/bpf_jit_comp.c

index 0ab8e47062d9a15f6fa2802f21e8a813417a1b7a..634d78422adb27ce77086e4b07dc1d6a3793da19 100644 (file)
@@ -952,6 +952,9 @@ static void __maybe_unused build_bhb_mitigation(struct jit_ctx *ctx)
            arm64_get_spectre_v2_state() == SPECTRE_VULNERABLE)
                return;
 
+       if (capable(CAP_SYS_ADMIN))
+               return;
+
        if (supports_clearbhb(SCOPE_SYSTEM)) {
                emit(aarch64_insn_gen_hint(AARCH64_INSN_HINT_CLEARBHB), ctx);
                return;