bpf: Make bpf_get_current_[ancestor_]cgroup_id() available for all program types
Subsystems (6)
PATCH 1/1 bpf: Make bpf_get_current_[ancestor_]cgroup_id() available for all program types
These helpers are safe to call from any context and there's no reason to restrict access to them. Remove them from bpf_trace and filter lists and add to bpf_base_func_proto() under perfmon_capable().
Please note that while test_verifier results remain the same, I'm unsure whether subjecting their availability to perfmon_capable() is the right decision.
--- kernel/bpf/cgroup.c | 4 ---- kernel/bpf/helpers.c | 6 ++++++ kernel/trace/bpf_trace.c | 4 ---- net/core/filter.c | 6 ------ 4 files changed, 6 insertions(+), 14 deletions(-)
kernel/bpf/cgroup.c +0 -4
@@ -2529,10 +2529,6 @@ cgroup_current_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)return &bpf_get_current_pid_tgid_proto;case BPF_FUNC_get_current_comm:return &bpf_get_current_comm_proto; -case BPF_FUNC_get_current_cgroup_id: -return &bpf_get_current_cgroup_id_proto; -case BPF_FUNC_get_current_ancestor_cgroup_id: -return &bpf_get_current_ancestor_cgroup_id_proto;#ifdef CONFIG_CGROUP_NET_CLASSID case BPF_FUNC_get_cgroup_classid:return &bpf_get_cgroup_classid_curr_proto;
kernel/bpf/helpers.c +6 -0
@@ -1726,6 +1726,12 @@ bpf_base_func_proto(enum bpf_func_id func_id)return &bpf_task_pt_regs_proto;case BPF_FUNC_trace_vprintk:return bpf_get_trace_vprintk_proto (); +#ifdef CONFIG_CGROUPS +case BPF_FUNC_get_current_cgroup_id: +return &bpf_get_current_cgroup_id_proto; +case BPF_FUNC_get_current_ancestor_cgroup_id: +return &bpf_get_current_ancestor_cgroup_id_proto; +#endif default :return NULL ; }
kernel/trace/bpf_trace.c +0 -4
@@ -1455,10 +1455,6 @@ bpf_tracing_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog) NULL : &bpf_probe_read_compat_str_proto;#endif #ifdef CONFIG_CGROUPS -case BPF_FUNC_get_current_cgroup_id: -return &bpf_get_current_cgroup_id_proto; -case BPF_FUNC_get_current_ancestor_cgroup_id: -return &bpf_get_current_ancestor_cgroup_id_proto;case BPF_FUNC_cgrp_storage_get:return &bpf_cgrp_storage_get_proto;case BPF_FUNC_cgrp_storage_delete:
net/core/filter.c +0 -6
@@ -8144,12 +8144,6 @@ sk_msg_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)return &bpf_sk_storage_delete_proto;case BPF_FUNC_get_netns_cookie:return &bpf_get_netns_cookie_sk_msg_proto; -#ifdef CONFIG_CGROUPS -case BPF_FUNC_get_current_cgroup_id: -return &bpf_get_current_cgroup_id_proto; -case BPF_FUNC_get_current_ancestor_cgroup_id: -return &bpf_get_current_ancestor_cgroup_id_proto; -#endif #ifdef CONFIG_CGROUP_NET_CLASSID case BPF_FUNC_get_cgroup_classid:return &bpf_get_cgroup_classid_curr_proto;
Signature · 1 line
2.39.2
PATCH v2 1/1 bpf: Make bpf_get_current_[ancestor_]cgroup_id() available for all program types
These helpers are safe to call from any context and there's no reason to restrict access to them. Remove them from bpf_trace and filter lists and add to bpf_base_func_proto() under perfmon_capable().
v2: After consulting with Andrii, relocated in bpf_base_func_proto() so that
they require bpf_capable() but not perfomon_capable() as it doesn't read from or affect others on the system.
--- kernel/bpf/cgroup.c | 4 ---- kernel/bpf/helpers.c | 4 ++++ kernel/trace/bpf_trace.c | 4 ---- net/core/filter.c | 6 ------ 4 files changed, 4 insertions(+), 14 deletions(-)
kernel/bpf/cgroup.c +0 -4
@@ -2529,10 +2529,6 @@ cgroup_current_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)return &bpf_get_current_pid_tgid_proto;case BPF_FUNC_get_current_comm:return &bpf_get_current_comm_proto; -case BPF_FUNC_get_current_cgroup_id: -return &bpf_get_current_cgroup_id_proto; -case BPF_FUNC_get_current_ancestor_cgroup_id: -return &bpf_get_current_ancestor_cgroup_id_proto;#ifdef CONFIG_CGROUP_NET_CLASSID case BPF_FUNC_get_cgroup_classid:return &bpf_get_cgroup_classid_curr_proto;
kernel/bpf/helpers.c +4 -0
@@ -1693,6 +1693,10 @@ bpf_base_func_proto(enum bpf_func_id func_id)return &bpf_cgrp_storage_get_proto;case BPF_FUNC_cgrp_storage_delete:return &bpf_cgrp_storage_delete_proto; +case BPF_FUNC_get_current_cgroup_id: +return &bpf_get_current_cgroup_id_proto; +case BPF_FUNC_get_current_ancestor_cgroup_id: +return &bpf_get_current_ancestor_cgroup_id_proto;#endif default :break ;
kernel/trace/bpf_trace.c +0 -4
@@ -1455,10 +1455,6 @@ bpf_tracing_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog) NULL : &bpf_probe_read_compat_str_proto;#endif #ifdef CONFIG_CGROUPS -case BPF_FUNC_get_current_cgroup_id: -return &bpf_get_current_cgroup_id_proto; -case BPF_FUNC_get_current_ancestor_cgroup_id: -return &bpf_get_current_ancestor_cgroup_id_proto;case BPF_FUNC_cgrp_storage_get:return &bpf_cgrp_storage_get_proto;case BPF_FUNC_cgrp_storage_delete:
net/core/filter.c +0 -6
@@ -8144,12 +8144,6 @@ sk_msg_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)return &bpf_sk_storage_delete_proto;case BPF_FUNC_get_netns_cookie:return &bpf_get_netns_cookie_sk_msg_proto; -#ifdef CONFIG_CGROUPS -case BPF_FUNC_get_current_cgroup_id: -return &bpf_get_current_cgroup_id_proto; -case BPF_FUNC_get_current_ancestor_cgroup_id: -return &bpf_get_current_ancestor_cgroup_id_proto; -#endif #ifdef CONFIG_CGROUP_NET_CLASSID case BPF_FUNC_get_cgroup_classid:return &bpf_get_cgroup_classid_curr_proto;
Signature · 1 line
2.39.2
This patch was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:
Hello:
This patch was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:
Quoted 9 lines · On Thu, 2 Mar 2023 09:42:59 -1000 you wrote:
These helpers are safe to call from any context and there's no reason to restrict access to them. Remove them from
bpf_traceand filter lists and add tobpf_base_func_proto()underperfmon_capable().v2: After consulting with Andrii, relocated in
bpf_base_func_proto()so that
they requirebpf_capable()but notperfomon_capable()as it doesn't read from or affect others on the system.[...]
Here is the summary with links:
- [v2,bpf-next] bpf: Make bpf_get_current_[ancestor_]cgroup_id() available for all program types
https://git.kernel.org/bpf/bpf-next/c/c501bf55c88b
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html