aboutsummaryrefslogtreecommitdiff
path: root/tools/testing/selftests/bpf/prog_tests/subprogs.c
diff options
context:
space:
mode:
authorGravatar Andrii Nakryiko <andrii@kernel.org> 2020-11-06 16:02:51 -0800
committerGravatar Daniel Borkmann <daniel@iogearbox.net> 2020-11-09 22:15:23 +0100
commit197afc631413d96dc60acfc7970bdd4125d38cd3 (patch)
tree18dfc01e3ad39fa1f38086fe854b0986ecaa01dd /tools/testing/selftests/bpf/prog_tests/subprogs.c
parentnet: marvell: prestera: fix compilation with CONFIG_BRIDGE=m (diff)
downloadlinux-197afc631413d96dc60acfc7970bdd4125d38cd3.tar.gz
linux-197afc631413d96dc60acfc7970bdd4125d38cd3.tar.bz2
linux-197afc631413d96dc60acfc7970bdd4125d38cd3.zip
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: 9a94f277c4fb ("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
Diffstat (limited to 'tools/testing/selftests/bpf/prog_tests/subprogs.c')
-rw-r--r--tools/testing/selftests/bpf/prog_tests/subprogs.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/tools/testing/selftests/bpf/prog_tests/subprogs.c b/tools/testing/selftests/bpf/prog_tests/subprogs.c
index a00abf58c037..3f3d2ac4dd57 100644
--- a/tools/testing/selftests/bpf/prog_tests/subprogs.c
+++ b/tools/testing/selftests/bpf/prog_tests/subprogs.c
@@ -3,12 +3,14 @@
#include <test_progs.h>
#include <time.h>
#include "test_subprogs.skel.h"
+#include "test_subprogs_unused.skel.h"
static int duration;
void test_subprogs(void)
{
struct test_subprogs *skel;
+ struct test_subprogs_unused *skel2;
int err;
skel = test_subprogs__open_and_load();
@@ -26,6 +28,10 @@ void test_subprogs(void)
CHECK(skel->bss->res3 != 19, "res3", "got %d, exp %d\n", skel->bss->res3, 19);
CHECK(skel->bss->res4 != 36, "res4", "got %d, exp %d\n", skel->bss->res4, 36);
+ skel2 = test_subprogs_unused__open_and_load();
+ ASSERT_OK_PTR(skel2, "unused_progs_skel");
+ test_subprogs_unused__destroy(skel2);
+
cleanup:
test_subprogs__destroy(skel);
}