aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYiFei Zhu <zhuyifei@google.com>2022-08-16 20:55:16 +0000
committerDaniel Borkmann <daniel@iogearbox.net>2022-08-18 00:27:49 +0200
commit14b20b784f59bdd95f6f1cfb112c9818bcec4d84 (patch)
tree238373603eb4aad3fbbe6361cd5ff473ae225847
parentbpf: Partially revert flexible-array member replacement (diff)
downloadlinux-dev-14b20b784f59bdd95f6f1cfb112c9818bcec4d84.tar.xz
linux-dev-14b20b784f59bdd95f6f1cfb112c9818bcec4d84.zip
bpf: Restrict bpf_sys_bpf to CAP_PERFMON
The verifier cannot perform sufficient validation of any pointers passed into bpf_attr and treats them as integers rather than pointers. The helper will then read from arbitrary pointers passed into it. Restrict the helper to CAP_PERFMON since the security model in BPF of arbitrary kernel read is CAP_BPF + CAP_PERFMON. Fixes: af2ac3e13e45 ("bpf: Prepare bpf syscall to be used from kernel and user space.") Signed-off-by: YiFei Zhu <zhuyifei@google.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Acked-by: Alexei Starovoitov <ast@kernel.org> Link: https://lore.kernel.org/bpf/20220816205517.682470-1-zhuyifei@google.com
-rw-r--r--kernel/bpf/syscall.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index a4d40d98428a..27760627370d 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -5197,7 +5197,7 @@ syscall_prog_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
{
switch (func_id) {
case BPF_FUNC_sys_bpf:
- return &bpf_sys_bpf_proto;
+ return !perfmon_capable() ? NULL : &bpf_sys_bpf_proto;
case BPF_FUNC_btf_find_by_name_kind:
return &bpf_btf_find_by_name_kind_proto;
case BPF_FUNC_sys_close: