selftests/bpf: add a test case to check verifier pointer arithmetic
Subsystems (5)
PATCH 1/1 selftests/bpf: add a test case to check verifier pointer arithmetic
From: Yonghong Song <[email protected]>
With clang/llvm 4.0+, the test case is able to generate the following pattern:
....
440: (b7) r1 = 15
441: (05) goto pc+73
515: (79) r6 = *(u64 *)(r10 -152)
516: (bf) r7 = r10
517: (07) r7 += -112
518: (bf) r2 = r7
519: (0f) r2 += r1
520: (71) r1 = *(u8 *)(r8 +0)
521: (73) *(u8 *)(r2 +45) = r1
....
commit 332270fdc8b6 ("bpf: enhance verifier to understand stack pointer arithmetic") improved verifier to handle such a pattern. This patch adds a C test case to actually generate such a pattern. A dummy tracepoint interface is used to load the program into the kernel.
---
We were planning to submit this test case along with the commit 332270fdc8b6 for completeness, but it took few extra days to cleanup.
Hope it's not too late.
--- tools/testing/selftests/bpf/Makefile | 2 +- tools/testing/selftests/bpf/test_progs.c | 16 ++ tools/testing/selftests/bpf/test_tcp_estats.c | 258 ++++++++++++++++++++++++++ 3 files changed, 275 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/bpf/test_tcp_estats.c
tools/testing/selftests/bpf/Makefile +1 -1
@@ -13,7 +13,7 @@ LDLIBS += -lcap -lelf TEST_GEN_PROGS = test_verifier test_tag test_maps test_lru_map test_lpm_map test_progs -TEST_GEN_FILES = test_pkt_access.o test_xdp.o test_l4lb.o +TEST_GEN_FILES = test_pkt_access.o test_xdp.o test_l4lb.o test_tcp_estats.o TEST_PROGS := test_kmod.sh
tools/testing/selftests/bpf/test_progs.c +16 -0
@@ -268,6 +268,21 @@ static void test_l4lb(void)bpf_object__close (obj); } +static void test_tcp_estats (void ) +{ +const char *file ="./test_tcp_estats.o" ; +int err, prog_fd; +struct bpf_object *obj; +__u32 duration =0 ; + + err =bpf_prog_load (file,BPF_PROG_TYPE_TRACEPOINT , &obj, &prog_fd); +CHECK (err,"" ,"err %d errno %d\n" , err, errno); +if (err) +return ; + +bpf_object__close (obj); +} +int main (void ) {struct rlimit rinf = {RLIM_INFINITY ,RLIM_INFINITY };
@@ -277,6 +292,7 @@ int main(void)test_pkt_access ();test_xdp ();test_l4lb (); +test_tcp_estats ();printf ("Summary: %d PASSED, %d FAILED\n" , pass_cnt, error_cnt);return 0 ;
tools/testing/selftests/bpf/test_tcp_estats.c new file +258 -0
258 lines not on this page · raw message
Signature · 1 line
2.9.3
From: Alexei Starovoitov <[email protected]>
Date: Tue, 2 May 2017 19:58:14 -0700
Quoted 22 lines
From: Yonghong Song <[email protected]>
With clang/llvm 4.0+, the test case is able to generate the following pattern:
....
440: (b7) r1 = 15
441: (05) goto pc+73
515: (79) r6 = *(u64 *)(r10 -152)
516: (bf) r7 = r10
517: (07) r7 += -112
518: (bf) r2 = r7
519: (0f) r2 += r1
520: (71) r1 = *(u8 *)(r8 +0)
521: (73) *(u8 *)(r2 +45) = r1
....commit
332270fdc8b6("bpf: enhance verifier to understand stack pointer arithmetic") improved verifier to handle such a pattern. This patch adds a C test case to actually generate such a pattern. A dummy tracepoint interface is used to load the program into the kernel.
Quoted 4 lines
Signed-off-by Yonghong Song <[email protected]>Acked-by Martin KaFai Lau <[email protected]>Acked-by Daniel Borkmann <[email protected]>Signed-off-by Alexei Starovoitov <[email protected]>
Applied.