Skip to content

Commit 43745d1

Browse files
zhuyifei1999anakryiko
authored andcommitted
bpftool: Fix regression of "bpftool cgroup tree" EINVAL on older kernels
If cgroup_has_attached_progs queries an attach type not supported by the running kernel, due to the kernel being older than the bpftool build, it would encounter an -EINVAL from BPF_PROG_QUERY syscall. Prior to commit 98b303c ("bpftool: Query only cgroup-related attach types"), this EINVAL would be ignored by the function, allowing the function to only consider supported attach types. The commit changed so that, instead of querying all attach types, only attach types from the array `cgroup_attach_types` is queried. The assumption is that because these are only cgroup attach types, they should all be supported. Unfortunately this assumption may be false when the kernel is older than the bpftool build, where the attach types queried by bpftool is not yet implemented in the kernel. This would result in errors such as: $ bpftool cgroup tree CgroupPath ID AttachType AttachFlags Name Error: can't query bpf programs attached to /sys/fs/cgroup: Invalid argument This patch restores the logic of ignoring EINVAL from prior to that patch. Fixes: 98b303c ("bpftool: Query only cgroup-related attach types") Reported-by: Sagarika Sharma <[email protected]> Reported-by: Minh-Anh Nguyen <[email protected]> Signed-off-by: YiFei Zhu <[email protected]> Signed-off-by: Andrii Nakryiko <[email protected]> Acked-by: Quentin Monnet <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 9fd0606 commit 43745d1

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

tools/bpf/bpftool/cgroup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ static int cgroup_has_attached_progs(int cgroup_fd)
221221
for (i = 0; i < ARRAY_SIZE(cgroup_attach_types); i++) {
222222
int count = count_attached_bpf_progs(cgroup_fd, cgroup_attach_types[i]);
223223

224-
if (count < 0)
224+
if (count < 0 && errno != EINVAL)
225225
return -1;
226226

227227
if (count > 0) {

0 commit comments

Comments
 (0)