linux-yocto/tools
Martin KaFai Lau da70cb95b8 bpftool: Fix cgroup command to only show cgroup bpf programs
commit b69d4413aa upstream.

The netkit program is not a cgroup bpf program and should not be shown
in the output of the "bpftool cgroup show" command.

However, if the netkit device happens to have ifindex 3,
the "bpftool cgroup show" command will output the netkit
bpf program as well:

> ip -d link show dev nk1
3: nk1@if2: ...
    link/ether ...
    netkit mode ...

> bpftool net show
tc:
nk1(3) netkit/peer tw_ns_nk2phy prog_id 469447

> bpftool cgroup show /sys/fs/cgroup/...
ID       AttachType      AttachFlags     Name
...      ...                             ...
469447   netkit_peer                     tw_ns_nk2phy

The reason is that the target_fd (which is the cgroup_fd here) and
the target_ifindex are in a union in the uapi/linux/bpf.h. The bpftool
iterates all values in "enum bpf_attach_type" which includes
non cgroup attach types like netkit. The cgroup_fd is usually 3 here,
so the bug is triggered when the netkit ifindex just happens
to be 3 as well.

The bpftool's cgroup.c already has a list of cgroup-only attach type
defined in "cgroup_attach_types[]". This patch fixes it by iterating
over "cgroup_attach_types[]" instead of "__MAX_BPF_ATTACH_TYPE".

Cc: Quentin Monnet <qmo@kernel.org>
Reported-by: Takshak Chahande <ctakshak@meta.com>
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
Reviewed-by: Quentin Monnet <qmo@kernel.org>
Link: https://lore.kernel.org/r/20250507203232.1420762-1-martin.lau@linux.dev
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2025-06-27 11:11:46 +01:00
..
accounting
arch x86/insn: Fix opcode map (!REX2) superscript tags 2025-06-19 15:31:28 +02:00
bootconfig tools/bootconfig: Fix the wrong format specifier 2025-02-08 09:58:00 +01:00
bpf bpftool: Fix cgroup command to only show cgroup bpf programs 2025-06-27 11:11:46 +01:00
build tools/build: Don't pass test log files to linker 2025-05-29 11:02:08 +02:00
certs
cgroup
counter
crypto
debugging
firewire
firmware
gpio
hv tools: hv: Fix a complier warning in the fcopy uio daemon 2024-12-27 14:02:15 +01:00
iio
include bpf: Fix L4 csum update on IPv6 in CHECKSUM_COMPLETE 2025-06-27 11:11:40 +01:00
kvm/kvm_stat
laptop
leds
lib libbpf: Add identical pointer detection to btf_dedup_is_equiv() 2025-06-27 11:11:32 +01:00
memory-model
mm
net tools: ynl-gen: validate 0 len strings from kernel 2025-05-29 11:03:12 +02:00
objtool objtool/rust: relax slice condition to cover more noreturn Rust functions 2025-06-19 15:32:33 +02:00
pci
pcmcia
perf perf test: Directory file descriptor leak 2025-06-27 11:11:46 +01:00
power tools/power turbostat: Fix AMD package-energy reporting 2025-06-19 15:32:21 +02:00
rcu
sched_ext tools/sched_ext: Add helper to check task migration state 2025-03-22 12:54:28 -07:00
scripts tools: Override makefile ARCH variable if defined, but empty 2024-12-14 20:03:15 +01:00
sound ASoC: dapm-graph: set fill colour of turned on nodes 2025-03-22 12:54:20 -07:00
spi
testing mm/hugetlb: unshare page tables during VMA split, not before 2025-06-27 11:11:40 +01:00
thermal
time
tracing rtla/timerlat_top: Abort event processing on second signal 2025-02-21 14:01:25 +01:00
usb
verification verification/dot2: Improve dot parser robustness 2024-12-14 20:04:03 +01:00
virtio
wmi
workqueue
writeback
Makefile