Skip to contentSkip to conversation

bpf: guard bpf_get_current_cgroup_id() with CONFIG_CGROUPS

PATCH Applied Yonghong Song 2 participants 2 messages Jun 4, 2018

Subsystems (6)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bpf: guard bpf_get_current_cgroup_id() with CONFIG_CGROUPS

Commit bf6fa2c893c5 ("bpf: implement bpf_get_current_cgroup_id() helper") introduced a new helper bpf_get_current_cgroup_id(). The helper has a dependency on CONFIG_CGROUPS.

When CONFIG_CGROUPS is not defined, using the helper will result the following verifier error:
kernel subsystem misconfigured func bpf_get_current_cgroup_id#80
which is hard for users to interpret.
Guarding the reference to bpf_get_current_cgroup_id_proto with CONFIG_CGROUPS will result in below better message:
unknown func bpf_get_current_cgroup_id#80

Fixes bf6fa2c893c5 ("bpf: implement bpf_get_current_cgroup_id() helper")
---
 kernel/trace/bpf_trace.c | 2 ++
 1 file changed, 2 insertions(+)
kernel/trace/bpf_trace.c +2 -0
index e2ab5b7..0ae6829 100644
@@ -564,8 +564,10 @@ tracing_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
 		return &bpf_get_prandom_u32_proto;
 	case BPF_FUNC_probe_read_str:
 		return &bpf_probe_read_str_proto;
+#ifdef CONFIG_CGROUPS
 	case BPF_FUNC_get_current_cgroup_id:
 		return &bpf_get_current_cgroup_id_proto;
+#endif
 	default:
 		return NULL;
 	}
Signature · 1 line
2.9.5
maintainer Applied
#1 lore raw
Quoted 12 lines · Yonghong Song

Commit bf6fa2c893c5 ("bpf: implement bpf_get_current_cgroup_id() helper") introduced a new helper bpf_get_current_cgroup_id(). The helper has a dependency on CONFIG_CGROUPS.

When CONFIG_CGROUPS is not defined, using the helper will result the following verifier error:
kernel subsystem misconfigured func bpf_get_current_cgroup_id#80
which is hard for users to interpret.
Guarding the reference to bpf_get_current_cgroup_id_proto with CONFIG_CGROUPS will result in below better message:
unknown func bpf_get_current_cgroup_id#80

Quoted 3 lines
Fixes bf6fa2c893c5 ("bpf: implement bpf_get_current_cgroup_id() helper")

Applied to bpf-next, thanks Yonghong!