]> git.baikalelectronics.ru Git - kernel.git/commitdiff
bpf: Exempt CAP_BPF from checks against bpf_jit_limit
authorLorenz Bauer <lmb@cloudflare.com>
Wed, 22 Sep 2021 11:11:52 +0000 (12:11 +0100)
committerDaniel Borkmann <daniel@iogearbox.net>
Tue, 28 Sep 2021 07:28:37 +0000 (09:28 +0200)
When introducing CAP_BPF, bpf_jit_charge_modmem() was not changed to treat
programs with CAP_BPF as privileged for the purpose of JIT memory allocation.
This means that a program without CAP_BPF can block a program with CAP_BPF
from loading a program.

Fix this by checking bpf_capable() in bpf_jit_charge_modmem().

Fixes: b38450704486 ("bpf: Implement CAP_BPF")
Signed-off-by: Lorenz Bauer <lmb@cloudflare.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20210922111153.19843-1-lmb@cloudflare.com
kernel/bpf/core.c

index 9f4636d021b108f178343c9822c673e547b0a8cb..d6b7dfdd806610165a223a48b77cfc1abe6d156a 100644 (file)
@@ -827,7 +827,7 @@ int bpf_jit_charge_modmem(u32 pages)
 {
        if (atomic_long_add_return(pages, &bpf_jit_current) >
            (bpf_jit_limit >> PAGE_SHIFT)) {
-               if (!capable(CAP_SYS_ADMIN)) {
+               if (!bpf_capable()) {
                        atomic_long_sub(pages, &bpf_jit_current);
                        return -EPERM;
                }