summaryrefslogtreecommitdiffstats
path: root/tools/testing/selftests/bpf/prog_tests/varlen.c
diff options
context:
space:
mode:
authorJohn Fastabend <john.fastabend@gmail.com>2020-06-22 20:22:23 -0700
committerDaniel Borkmann <daniel@iogearbox.net>2020-06-24 00:04:36 +0200
commit2fde1747c986cac28fa66d0cffd7577db042640b (patch)
treeb63ed51d2ae66d7a8aea24308b6de2041440c8e9 /tools/testing/selftests/bpf/prog_tests/varlen.c
parent5e85c6bb8e74bd9daa4f5815da373d4ac2cb1a35 (diff)
downloadlinux-2fde1747c986cac28fa66d0cffd7577db042640b.tar.bz2
selftests/bpf: Add variable-length data concat pattern less than test
Extend original variable-length tests with a case to catch a common existing pattern of testing for < 0 for errors. Note because verifier also tracks upper bounds and we know it can not be greater than MAX_LEN here we can skip upper bound check. In ALU64 enabled compilation converting from long->int return types in probe helpers results in extra instruction pattern, <<= 32, s >>= 32. The trade-off is the non-ALU64 case works. If you really care about every extra insn (XDP case?) then you probably should be using original int type. In addition adding a sext insn to bpf might help the verifier in the general case to avoid these types of tricks. Signed-off-by: John Fastabend <john.fastabend@gmail.com> Signed-off-by: Andrii Nakryiko <andriin@fb.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Link: https://lore.kernel.org/bpf/20200623032224.4020118-3-andriin@fb.com
Diffstat (limited to 'tools/testing/selftests/bpf/prog_tests/varlen.c')
-rw-r--r--tools/testing/selftests/bpf/prog_tests/varlen.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/tools/testing/selftests/bpf/prog_tests/varlen.c b/tools/testing/selftests/bpf/prog_tests/varlen.c
index 7533565e096d..c75525eab02c 100644
--- a/tools/testing/selftests/bpf/prog_tests/varlen.c
+++ b/tools/testing/selftests/bpf/prog_tests/varlen.c
@@ -51,6 +51,18 @@ void test_varlen(void)
CHECK_VAL(data->total2, size1 + size2);
CHECK(memcmp(data->payload2, exp_str, size1 + size2), "content_check",
"doesn't match!");
+
+ CHECK_VAL(data->payload3_len1, size1);
+ CHECK_VAL(data->payload3_len2, size2);
+ CHECK_VAL(data->total3, size1 + size2);
+ CHECK(memcmp(data->payload3, exp_str, size1 + size2), "content_check",
+ "doesn't match!");
+
+ CHECK_VAL(data->payload4_len1, size1);
+ CHECK_VAL(data->payload4_len2, size2);
+ CHECK_VAL(data->total4, size1 + size2);
+ CHECK(memcmp(data->payload4, exp_str, size1 + size2), "content_check",
+ "doesn't match!");
cleanup:
test_varlen__destroy(skel);
}