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)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 6 Oct 2021 13:55:55 +0000 (15:55 +0200)
commit59efda5073abb4fff2ce8c90ca9c2d25882e84a4
tree87cf6dd581420d943939186326f852710c67ae0a
parentf908072391a653776d7ce9e23d63d3789a6c4b7d
bpf: Exempt CAP_BPF from checks against bpf_jit_limit

[ Upstream commit 8a98ae12fbefdb583a7696de719a1d57e5e940a2 ]

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: 2c78ee898d8f ("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
Signed-off-by: Sasha Levin <sashal@kernel.org>
kernel/bpf/core.c