Currently the following prog types don't fall back to bpf_base_func_proto() (instead they have cgroup_base_func_proto which has a limited set of helpers from bpf_base_func_proto): * BPF_PROG_TYPE_CGROUP_DEVICE * BPF_PROG_TYPE_CGROUP_SYSCTL * BPF_PROG_TYPE_CGROUP_SOCKOPT I don't see any specific reason why we shouldn't use bpf_base_func_proto(), every other type of program (except bpf-lirc and, understandably, tracing) use it, so let's fall back to bpf_base_func_proto for those prog types as well. This basically boils down to adding access to the following helpers: * BPF_FUNC_get_prandom_u32 * BPF_FUNC_get_smp_processor_id * BPF_FUNC_get_numa_node_id * BPF_FUNC_tail_call * BPF_FUNC_ktime_get_ns * BPF_FUNC_spin_lock (CAP_SYS_ADMIN) * BPF_FUNC_spin_unlock (CAP_SYS_ADMIN) * BPF_FUNC_jiffies64 (CAP_SYS_ADMIN) I've also added bpf_perf_event_output() because it's really handy for logging and debugging.
Unified · Split
| @@ -1523,6 +1523,7 @@ extern const struct bpf_func_proto bpf_strtoul_proto; · 1522 unmodified lines | ||
| 1523 | 1523 | extern const struct bpf_func_proto bpf_tcp_sock_proto; |
| 1524 | 1524 | extern const struct bpf_func_proto bpf_jiffies64_proto; |
| 1525 | 1525 | extern const struct bpf_func_proto bpf_get_ns_current_pid_tgid_proto; |
| 1526 | +extern const struct bpf_func_proto bpf_event_output_data_proto; | |
| 1526 | 1527 | |
| 1527 | 1528 | const struct bpf_func_proto *bpf_tracing_func_proto( |
| 1528 | 1529 | enum bpf_func_id func_id, const struct bpf_prog *prog); |
| @@ -1060,30 +1060,16 @@ static const struct bpf_func_proto * · 1059 unmodified lines | ||
| 1060 | 1060 | cgroup_base_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog) |
| 1061 | 1061 | { |
| 1062 | 1062 | switch (func_id) { |
| 1063 | − case BPF_FUNC_map_lookup_elem: | |
| 1064 | − return &bpf_map_lookup_elem_proto; | |
| 1065 | − case BPF_FUNC_map_update_elem: | |
| 1066 | − return &bpf_map_update_elem_proto; | |
| 1067 | − case BPF_FUNC_map_delete_elem: | |
| 1068 | − return &bpf_map_delete_elem_proto; | |
| 1069 | − case BPF_FUNC_map_push_elem: | |
| 1070 | − return &bpf_map_push_elem_proto; | |
| 1071 | − case BPF_FUNC_map_pop_elem: | |
| 1072 | − return &bpf_map_pop_elem_proto; | |
| 1073 | − case BPF_FUNC_map_peek_elem: | |
| 1074 | − return &bpf_map_peek_elem_proto; | |
| 1075 | 1063 | case BPF_FUNC_get_current_uid_gid: |
| 1076 | 1064 | return &bpf_get_current_uid_gid_proto; |
| 1077 | 1065 | case BPF_FUNC_get_local_storage: |
| 1078 | 1066 | return &bpf_get_local_storage_proto; |
| 1079 | 1067 | case BPF_FUNC_get_current_cgroup_id: |
| 1080 | 1068 | return &bpf_get_current_cgroup_id_proto; |
| 1081 | − case BPF_FUNC_trace_printk: | |
| 1082 | − if (capable(CAP_SYS_ADMIN)) | |
| 1083 | − return bpf_get_trace_printk_proto(); | |
| 1084 | − /* fall through */ | |
| 1069 | + case BPF_FUNC_perf_event_output: | |
| 1070 | + return &bpf_event_output_data_proto; | |
| 1085 | 1071 | default: |
| 1086 | − return NULL; | |
| 1072 | + return bpf_base_func_proto(func_id); | |
| 1087 | 1073 | } |
| 1088 | 1074 | } |
| 1089 | 1075 | |
| @@ -4214,7 +4214,7 @@ BPF_CALL_5(bpf_event_output_data, void *, ctx, struct bpf_map *, map, u64, flags · 4213 unmodified lines | ||
| 4214 | 4214 | return bpf_event_output(map, flags, data, size, NULL, 0, NULL); |
| 4215 | 4215 | } |
| 4216 | 4216 | |
| 4217 | −static const struct bpf_func_proto bpf_event_output_data_proto = { | |
| 4217 | +const struct bpf_func_proto bpf_event_output_data_proto = { | |
| 4218 | 4218 | .func = bpf_event_output_data, |
| 4219 | 4219 | .gpl_only = true, |
| 4220 | 4220 | .ret_type = RET_INTEGER, |
| @@ -92,3 +92,27 @@ · 91 unmodified lines | ||
| 92 | 92 | .result = ACCEPT, |
| 93 | 93 | .retval = 1, |
| 94 | 94 | }, |
| 95 | +{ | |
| 96 | + "perfevent for cgroup dev", | |
| 97 | + .insns = { __PERF_EVENT_INSNS__ }, | |
| 98 | + .prog_type = BPF_PROG_TYPE_CGROUP_DEVICE, | |
| 99 | + .fixup_map_event_output = { 4 }, | |
| 100 | + .result = ACCEPT, | |
| 101 | + .retval = 1, | |
| 102 | +}, | |
| 103 | +{ | |
| 104 | + "perfevent for cgroup sysctl", | |
| 105 | + .insns = { __PERF_EVENT_INSNS__ }, | |
| 106 | + .prog_type = BPF_PROG_TYPE_CGROUP_SYSCTL, | |
| 107 | + .fixup_map_event_output = { 4 }, | |
| 108 | + .result = ACCEPT, | |
| 109 | + .retval = 1, | |
| 110 | +}, | |
| 111 | +{ | |
| 112 | + "perfevent for cgroup sockopt", | |
| 113 | + .insns = { __PERF_EVENT_INSNS__ }, | |
| 114 | + .prog_type = BPF_PROG_TYPE_CGROUP_SOCKOPT, | |
| 115 | + .fixup_map_event_output = { 4 }, | |
| 116 | + .result = ACCEPT, | |
| 117 | + .retval = 1, | |
| 118 | +}, | |