linux-stable/tools
Martin KaFai Lau c8de71a7ae libbpf: Ignore non function pointer member in struct_ops
[ Upstream commit d2836dddc9 ]

When libbpf initializes the kernel's struct_ops in
"bpf_map__init_kern_struct_ops()", it enforces all
pointer types must be a function pointer and rejects
others.  It turns out to be too strict.  For example,
when directly using "struct tcp_congestion_ops" from vmlinux.h,
it has a "struct module *owner" member and it is set to NULL
in a bpf_tcp_cc.o.

Instead, it only needs to ensure the member is a function
pointer if it has been set (relocated) to a bpf-prog.
This patch moves the "btf_is_func_proto(kern_mtype)" check
after the existing "if (!prog) { continue; }".  The original debug
message in "if (!prog) { continue; }" is also removed since it is
no longer valid.  Beside, there is a later debug message to tell
which function pointer is set.

The "btf_is_func_proto(mtype)" has already been guaranteed
in "bpf_object__collect_st_ops_relos()" which has been run
before "bpf_map__init_kern_struct_ops()".  Thus, this check
is removed.

v2:
- Remove outdated debug message (Andrii)
  Remove because there is a later debug message to tell
  which function pointer is set.
- Following mtype->type is no longer needed. Remove:
  "skip_mods_and_typedefs(btf, mtype->type, &mtype_id)"
- Do "if (!prog)" test before skip_mods_and_typedefs.

Fixes: 590a008882 ("bpf: libbpf: Add STRUCT_OPS support")
Signed-off-by: Martin KaFai Lau <kafai@fb.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Acked-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20210212021030.266932-1-kafai@fb.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
2021-03-04 11:37:33 +01:00
..
accounting
arch x86/uprobes: Do not use prefixes.nbytes when looping over prefixes.bytes 2020-12-06 09:58:13 +01:00
bootconfig tools/bootconfig: Add tracing_on support to helper scripts 2021-01-19 18:27:19 +01:00
bpf tools: Factor HOSTCC, HOSTLD, HOSTAR definitions 2021-01-30 13:55:19 +01:00
build tools: Factor HOSTCC, HOSTLD, HOSTAR definitions 2021-01-30 13:55:19 +01:00
cgroup blk-iocost: update iocost_monitor.py 2020-09-01 19:38:33 -06:00
debugging
edid
firewire
firmware
gpio tools: gpio: fix %llu warning in gpio-watch.c 2021-01-27 11:55:20 +01:00
hv tools: hv: change http to https in hv_kvp_daemon.c 2020-07-06 10:46:23 +00:00
iio iio: add IIO_MOD_O2 modifier 2020-08-22 10:53:12 +01:00
include tools headers UAPI: Sync linux/fscrypt.h with the kernel sources 2021-01-17 14:17:06 +01:00
io_uring tools/io_uring: fix compile breakage 2020-09-21 07:50:58 -06:00
kvm/kvm_stat tools/kvm_stat: Exempt time-based counters 2020-12-11 19:18:51 -05:00
laptop
leds
lib libbpf: Ignore non function pointer member in struct_ops 2021-03-04 11:37:33 +01:00
memory-model tools/memory-model: Expand the cheatsheet.txt notion of relaxed 2020-09-04 11:58:15 -07:00
objtool objtool: Fix seg fault with Clang non-section symbols 2021-02-17 11:02:20 +01:00
pci
pcmcia
perf tools: Factor HOSTCC, HOSTLD, HOSTAR definitions 2021-01-30 13:55:19 +01:00
power tools/power/x86/intel-speed-select: Set higher of cpuinfo_max_freq or base_frequency 2021-02-07 15:37:13 +01:00
scripts tools: Factor HOSTCC, HOSTLD, HOSTAR definitions 2021-01-30 13:55:19 +01:00
spi
testing selftests/bpf: Convert test_xdp_redirect.sh to bash 2021-03-04 11:37:30 +01:00
thermal/tmon
time
usb tools: usb: move to tools buildsystem 2020-08-19 14:11:44 +02:00
virtio virtio: fixes, features 2020-08-11 14:34:17 -07:00
vm mm: Add PG_arch_2 page flag 2020-09-04 12:46:06 +01:00
wmi
Makefile bpf: Compile resolve_btfids tool at kernel compilation start 2020-07-13 10:42:02 -07:00