-
Notifications
You must be signed in to change notification settings - Fork 840
Description
Describe the bug
When using bpf_core_enum_value_exists on an enum and within it bpf_core_enum_value on the same enum value, when the value doesn't exist, the output go binary fails to load.
When loading the compiled object file with libbpf (bpftool) it loads successfully.
The code is in the attached file, but the problem can be seen in:
if (bpf_core_enum_value_exists(enum cgroup_subsys_id, cpuset_cgrp_id_lublub)) {
__attribute__((unused)) const volatile int val =
bpf_core_enum_value(enum cgroup_subsys_id, cpuset_cgrp_id_lublub);
}where the kernel enum cgroup_subsys_id is queried for type cpuset_cgrp_id_lublub (which doesn't really exist). The expected behaviour, which happens when loading the object with bpftool, is that the program passes the verifier's checks because the code inside the if shouldn't be evaluated.
The second value in the enum in the attached code, cpuset_cgrp_id, indeed exists, so using it instead of the fictitious value cpuset_cgrp_id_lublub works with both cilium and libbpf.
How to reproduce
The code:
enum-error.tar.gz
build with make and run with ./main.
Loading with bpftool (succeeds):
bpftool prog load bpf_bpf.o /sys/fs/bpf/bpf_bpf
rm /sys/fs/bpf/bpf_bpf # to removeVersion information
github.com/cilium/ebpf v0.12.3go version go1.21.5 linux/amd64Linux 5.15.0