aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Borkmann <daniel@iogearbox.net>2018-02-15 04:22:55 -0500
committerDaniel Borkmann <daniel@iogearbox.net>2018-02-15 04:22:56 -0500
commit0b6b8a3dd86db78c3f38587d667d77065c75e4f8 (patch)
tree13fe37577e91a1b80d7ae5e9c733ed236a1b748b
parent615a9474985799c8b48645b8e95a9b9f0691f56a (diff)
parent544bdebc6fcb68c2e8075bc2d3b68e39789d4165 (diff)
Merge branch 'bpf-misc-selftest-improvements'
Joe Stringer says: ==================== This is series makes some minor changes primarily focused on making it easier to understand why test_verifier is failing a test. This includes printing the observed output when a test fails in a different way than expected, or when unprivileged tests fail due to sysctl kernel.unprivileged_bpf_disabled=1. The last patch removes some apparently dead code. ==================== Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
-rw-r--r--kernel/bpf/verifier.c4
-rw-r--r--tools/testing/selftests/bpf/test_verifier.c39
2 files changed, 34 insertions, 9 deletions
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index 5fb69a85d967..3c74b163eaeb 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -508,10 +508,6 @@ err:
508static const int caller_saved[CALLER_SAVED_REGS] = { 508static const int caller_saved[CALLER_SAVED_REGS] = {
509 BPF_REG_0, BPF_REG_1, BPF_REG_2, BPF_REG_3, BPF_REG_4, BPF_REG_5 509 BPF_REG_0, BPF_REG_1, BPF_REG_2, BPF_REG_3, BPF_REG_4, BPF_REG_5
510}; 510};
511#define CALLEE_SAVED_REGS 5
512static const int callee_saved[CALLEE_SAVED_REGS] = {
513 BPF_REG_6, BPF_REG_7, BPF_REG_8, BPF_REG_9
514};
515 511
516static void __mark_reg_not_init(struct bpf_reg_state *reg); 512static void __mark_reg_not_init(struct bpf_reg_state *reg);
517 513
diff --git a/tools/testing/selftests/bpf/test_verifier.c b/tools/testing/selftests/bpf/test_verifier.c
index c0f16e93f9bd..2971ba2829ac 100644
--- a/tools/testing/selftests/bpf/test_verifier.c
+++ b/tools/testing/selftests/bpf/test_verifier.c
@@ -57,6 +57,9 @@
57#define F_NEEDS_EFFICIENT_UNALIGNED_ACCESS (1 << 0) 57#define F_NEEDS_EFFICIENT_UNALIGNED_ACCESS (1 << 0)
58#define F_LOAD_WITH_STRICT_ALIGNMENT (1 << 1) 58#define F_LOAD_WITH_STRICT_ALIGNMENT (1 << 1)
59 59
60#define UNPRIV_SYSCTL "kernel/unprivileged_bpf_disabled"
61static bool unpriv_disabled = false;
62
60struct bpf_test { 63struct bpf_test {
61 const char *descr; 64 const char *descr;
62 struct bpf_insn insns[MAX_INSNS]; 65 struct bpf_insn insns[MAX_INSNS];
@@ -11291,7 +11294,8 @@ static void do_test_single(struct bpf_test *test, bool unpriv,
11291 goto fail_log; 11294 goto fail_log;
11292 } 11295 }
11293 if (!strstr(bpf_vlog, expected_err) && !reject_from_alignment) { 11296 if (!strstr(bpf_vlog, expected_err) && !reject_from_alignment) {
11294 printf("FAIL\nUnexpected error message!\n"); 11297 printf("FAIL\nUnexpected error message!\n\tEXP: %s\n\tRES: %s\n",
11298 expected_err, bpf_vlog);
11295 goto fail_log; 11299 goto fail_log;
11296 } 11300 }
11297 } 11301 }
@@ -11375,9 +11379,20 @@ out:
11375 return ret; 11379 return ret;
11376} 11380}
11377 11381
11382static void get_unpriv_disabled()
11383{
11384 char buf[2];
11385 FILE *fd;
11386
11387 fd = fopen("/proc/sys/"UNPRIV_SYSCTL, "r");
11388 if (fgets(buf, 2, fd) == buf && atoi(buf))
11389 unpriv_disabled = true;
11390 fclose(fd);
11391}
11392
11378static int do_test(bool unpriv, unsigned int from, unsigned int to) 11393static int do_test(bool unpriv, unsigned int from, unsigned int to)
11379{ 11394{
11380 int i, passes = 0, errors = 0; 11395 int i, passes = 0, errors = 0, skips = 0;
11381 11396
11382 for (i = from; i < to; i++) { 11397 for (i = from; i < to; i++) {
11383 struct bpf_test *test = &tests[i]; 11398 struct bpf_test *test = &tests[i];
@@ -11385,7 +11400,10 @@ static int do_test(bool unpriv, unsigned int from, unsigned int to)
11385 /* Program types that are not supported by non-root we 11400 /* Program types that are not supported by non-root we
11386 * skip right away. 11401 * skip right away.
11387 */ 11402 */
11388 if (!test->prog_type) { 11403 if (!test->prog_type && unpriv_disabled) {
11404 printf("#%d/u %s SKIP\n", i, test->descr);
11405 skips++;
11406 } else if (!test->prog_type) {
11389 if (!unpriv) 11407 if (!unpriv)
11390 set_admin(false); 11408 set_admin(false);
11391 printf("#%d/u %s ", i, test->descr); 11409 printf("#%d/u %s ", i, test->descr);
@@ -11394,13 +11412,17 @@ static int do_test(bool unpriv, unsigned int from, unsigned int to)
11394 set_admin(true); 11412 set_admin(true);
11395 } 11413 }
11396 11414
11397 if (!unpriv) { 11415 if (unpriv) {
11416 printf("#%d/p %s SKIP\n", i, test->descr);
11417 skips++;
11418 } else {
11398 printf("#%d/p %s ", i, test->descr); 11419 printf("#%d/p %s ", i, test->descr);
11399 do_test_single(test, false, &passes, &errors); 11420 do_test_single(test, false, &passes, &errors);
11400 } 11421 }
11401 } 11422 }
11402 11423
11403 printf("Summary: %d PASSED, %d FAILED\n", passes, errors); 11424 printf("Summary: %d PASSED, %d SKIPPED, %d FAILED\n", passes,
11425 skips, errors);
11404 return errors ? EXIT_FAILURE : EXIT_SUCCESS; 11426 return errors ? EXIT_FAILURE : EXIT_SUCCESS;
11405} 11427}
11406 11428
@@ -11428,6 +11450,13 @@ int main(int argc, char **argv)
11428 } 11450 }
11429 } 11451 }
11430 11452
11453 get_unpriv_disabled();
11454 if (unpriv && unpriv_disabled) {
11455 printf("Cannot run as unprivileged user with sysctl %s.\n",
11456 UNPRIV_SYSCTL);
11457 return EXIT_FAILURE;
11458 }
11459
11431 setrlimit(RLIMIT_MEMLOCK, unpriv ? &rlim : &rinf); 11460 setrlimit(RLIMIT_MEMLOCK, unpriv ? &rlim : &rinf);
11432 return do_test(unpriv, from, to); 11461 return do_test(unpriv, from, to);
11433} 11462}