History

bpf: Implement CAP_BPF

Implement permissions as stated in uapi/linux/capability.h In order to do that the verifier allow_ptr_leaks flag is split into four flags and they are set as: env->allow_ptr_leaks = bpf_allow_ptr_leaks(); env->bypass_spec_v1 = bpf_bypass_spec_v1(); env->bypass_spec_v4 = bpf_bypass_spec_v4(); env->bpf_capable = bpf_capable(); The first three currently equivalent to perfmon_capable(), since leaking kernel pointers and reading kernel memory via side channel attacks is roughly equivalent to reading kernel memory with cap_perfmon. 'bpf_capable' enables bounded loops, precision tracking, bpf to bpf calls and other verifier features. 'allow_ptr_leaks' enable ptr leaks, ptr conversions, subtraction of pointers. 'bypass_spec_v1' disables speculative analysis in the verifier, run time mitigations in bpf array, and enables indirect variable access in bpf programs. 'bypass_spec_v4' disables emission of sanitation code by the verifier. That means that the networking BPF program loaded with CAP_BPF + CAP_NET_ADMIN will have speculative checks done by the verifier and other spectre mitigation applied. Such networking BPF program will not be able to leak kernel pointers and will not be able to access arbitrary kernel memory.

Alexei Starovoitov committed 6 years ago

Commit 2c78ee81 parent a17b53c19 files · +134 −60Browse files

Showing the changes to kernel/bpf/queue_stack_maps.c (1 of 19 files). Show all

Unified · Split

kernel/bpf/queue_stack_maps.c+1−1
@@ -45,7 +45,7 @@ static bool queue_stack_map_is_full(struct bpf_queue_stack *qs) · 44 unmodified lines
4545 /* Called from syscall */
4646 static int queue_stack_map_alloc_check(union bpf_attr *attr)
4747 {
48− if (!capable(CAP_SYS_ADMIN))
48+ if (!bpf_capable())
4949 return -EPERM;
5050
5151 /* check sanity of attributes */