]> git.baikalelectronics.ru Git - kernel.git/commit
libbpf: Don't attempt to load unused subprog as an entry-point BPF program
authorAndrii Nakryiko <andrii@kernel.org>
Sat, 7 Nov 2020 00:02:51 +0000 (16:02 -0800)
committerDaniel Borkmann <daniel@iogearbox.net>
Mon, 9 Nov 2020 21:15:23 +0000 (22:15 +0100)
commit667fad517816798a98666136a18f0db5732e58a0
tree18dfc01e3ad39fa1f38086fe854b0986ecaa01dd
parentc20f9b5edf96f2cd6d23694ca02fde30d41d32e1
libbpf: Don't attempt to load unused subprog as an entry-point BPF program

If BPF code contains unused BPF subprogram and there are no other subprogram
calls (which can realistically happen in real-world applications given
sufficiently smart Clang code optimizations), libbpf will erroneously assume
that subprograms are entry-point programs and will attempt to load them with
UNSPEC program type.

Fix by not relying on subcall instructions and rather detect it based on the
structure of BPF object's sections.

Fixes: 08d3b8a14e80 ("tools: libbpf: restore the ability to load programs from .text section")
Reported-by: Dmitrii Banshchikov <dbanschikov@fb.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Yonghong Song <yhs@fb.com>
Link: https://lore.kernel.org/bpf/20201107000251.256821-1-andrii@kernel.org
tools/lib/bpf/libbpf.c
tools/testing/selftests/bpf/prog_tests/subprogs.c
tools/testing/selftests/bpf/progs/test_subprogs_unused.c [new file with mode: 0644]