aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorYonghong Song <yhs@fb.com>2018-02-03 01:37:15 -0500
committerDaniel Borkmann <daniel@iogearbox.net>2018-02-04 18:31:57 -0500
commit09584b406742413ac4c8d7e030374d4daa045b69 (patch)
treec69279b4bc7e8bf0771d279e8cd578fcd91174b6 /lib
parenta6b88814ab541d386d793f6df260a3e4d5cccb11 (diff)
bpf: fix selftests/bpf test_kmod.sh failure when CONFIG_BPF_JIT_ALWAYS_ON=y
With CONFIG_BPF_JIT_ALWAYS_ON is defined in the config file, tools/testing/selftests/bpf/test_kmod.sh failed like below: [root@localhost bpf]# ./test_kmod.sh sysctl: setting key "net.core.bpf_jit_enable": Invalid argument [ JIT enabled:0 hardened:0 ] [ 132.175681] test_bpf: #297 BPF_MAXINSNS: Jump, gap, jump, ... FAIL to prog_create err=-524 len=4096 [ 132.458834] test_bpf: Summary: 348 PASSED, 1 FAILED, [340/340 JIT'ed] [ JIT enabled:1 hardened:0 ] [ 133.456025] test_bpf: #297 BPF_MAXINSNS: Jump, gap, jump, ... FAIL to prog_create err=-524 len=4096 [ 133.730935] test_bpf: Summary: 348 PASSED, 1 FAILED, [340/340 JIT'ed] [ JIT enabled:1 hardened:1 ] [ 134.769730] test_bpf: #297 BPF_MAXINSNS: Jump, gap, jump, ... FAIL to prog_create err=-524 len=4096 [ 135.050864] test_bpf: Summary: 348 PASSED, 1 FAILED, [340/340 JIT'ed] [ JIT enabled:1 hardened:2 ] [ 136.442882] test_bpf: #297 BPF_MAXINSNS: Jump, gap, jump, ... FAIL to prog_create err=-524 len=4096 [ 136.821810] test_bpf: Summary: 348 PASSED, 1 FAILED, [340/340 JIT'ed] [root@localhost bpf]# The test_kmod.sh load/remove test_bpf.ko multiple times with different settings for sysctl net.core.bpf_jit_{enable,harden}. The failed test #297 of test_bpf.ko is designed such that JIT always fails. Commit 290af86629b2 (bpf: introduce BPF_JIT_ALWAYS_ON config) introduced the following tightening logic: ... if (!bpf_prog_is_dev_bound(fp->aux)) { fp = bpf_int_jit_compile(fp); #ifdef CONFIG_BPF_JIT_ALWAYS_ON if (!fp->jited) { *err = -ENOTSUPP; return fp; } #endif ... With this logic, Test #297 always gets return value -ENOTSUPP when CONFIG_BPF_JIT_ALWAYS_ON is defined, causing the test failure. This patch fixed the failure by marking Test #297 as expected failure when CONFIG_BPF_JIT_ALWAYS_ON is defined. Fixes: 290af86629b2 (bpf: introduce BPF_JIT_ALWAYS_ON config) Signed-off-by: Yonghong Song <yhs@fb.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Diffstat (limited to 'lib')
-rw-r--r--lib/test_bpf.c31
1 files changed, 26 insertions, 5 deletions
diff --git a/lib/test_bpf.c b/lib/test_bpf.c
index 4cd9ea9b3449..b4e22345963f 100644
--- a/lib/test_bpf.c
+++ b/lib/test_bpf.c
@@ -83,6 +83,7 @@ struct bpf_test {
83 __u32 result; 83 __u32 result;
84 } test[MAX_SUBTESTS]; 84 } test[MAX_SUBTESTS];
85 int (*fill_helper)(struct bpf_test *self); 85 int (*fill_helper)(struct bpf_test *self);
86 int expected_errcode; /* used when FLAG_EXPECTED_FAIL is set in the aux */
86 __u8 frag_data[MAX_DATA]; 87 __u8 frag_data[MAX_DATA];
87 int stack_depth; /* for eBPF only, since tests don't call verifier */ 88 int stack_depth; /* for eBPF only, since tests don't call verifier */
88}; 89};
@@ -2026,7 +2027,9 @@ static struct bpf_test tests[] = {
2026 }, 2027 },
2027 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL, 2028 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
2028 { }, 2029 { },
2029 { } 2030 { },
2031 .fill_helper = NULL,
2032 .expected_errcode = -EINVAL,
2030 }, 2033 },
2031 { 2034 {
2032 "check: div_k_0", 2035 "check: div_k_0",
@@ -2036,7 +2039,9 @@ static struct bpf_test tests[] = {
2036 }, 2039 },
2037 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL, 2040 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
2038 { }, 2041 { },
2039 { } 2042 { },
2043 .fill_helper = NULL,
2044 .expected_errcode = -EINVAL,
2040 }, 2045 },
2041 { 2046 {
2042 "check: unknown insn", 2047 "check: unknown insn",
@@ -2047,7 +2052,9 @@ static struct bpf_test tests[] = {
2047 }, 2052 },
2048 CLASSIC | FLAG_EXPECTED_FAIL, 2053 CLASSIC | FLAG_EXPECTED_FAIL,
2049 { }, 2054 { },
2050 { } 2055 { },
2056 .fill_helper = NULL,
2057 .expected_errcode = -EINVAL,
2051 }, 2058 },
2052 { 2059 {
2053 "check: out of range spill/fill", 2060 "check: out of range spill/fill",
@@ -2057,7 +2064,9 @@ static struct bpf_test tests[] = {
2057 }, 2064 },
2058 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL, 2065 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
2059 { }, 2066 { },
2060 { } 2067 { },
2068 .fill_helper = NULL,
2069 .expected_errcode = -EINVAL,
2061 }, 2070 },
2062 { 2071 {
2063 "JUMPS + HOLES", 2072 "JUMPS + HOLES",
@@ -2149,6 +2158,8 @@ static struct bpf_test tests[] = {
2149 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL, 2158 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
2150 { }, 2159 { },
2151 { }, 2160 { },
2161 .fill_helper = NULL,
2162 .expected_errcode = -EINVAL,
2152 }, 2163 },
2153 { 2164 {
2154 "check: LDX + RET X", 2165 "check: LDX + RET X",
@@ -2159,6 +2170,8 @@ static struct bpf_test tests[] = {
2159 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL, 2170 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
2160 { }, 2171 { },
2161 { }, 2172 { },
2173 .fill_helper = NULL,
2174 .expected_errcode = -EINVAL,
2162 }, 2175 },
2163 { /* Mainly checking JIT here. */ 2176 { /* Mainly checking JIT here. */
2164 "M[]: alt STX + LDX", 2177 "M[]: alt STX + LDX",
@@ -2333,6 +2346,8 @@ static struct bpf_test tests[] = {
2333 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL, 2346 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
2334 { }, 2347 { },
2335 { }, 2348 { },
2349 .fill_helper = NULL,
2350 .expected_errcode = -EINVAL,
2336 }, 2351 },
2337 { /* Passes checker but fails during runtime. */ 2352 { /* Passes checker but fails during runtime. */
2338 "LD [SKF_AD_OFF-1]", 2353 "LD [SKF_AD_OFF-1]",
@@ -5395,6 +5410,7 @@ static struct bpf_test tests[] = {
5395 { }, 5410 { },
5396 { }, 5411 { },
5397 .fill_helper = bpf_fill_maxinsns4, 5412 .fill_helper = bpf_fill_maxinsns4,
5413 .expected_errcode = -EINVAL,
5398 }, 5414 },
5399 { /* Mainly checking JIT here. */ 5415 { /* Mainly checking JIT here. */
5400 "BPF_MAXINSNS: Very long jump", 5416 "BPF_MAXINSNS: Very long jump",
@@ -5450,10 +5466,15 @@ static struct bpf_test tests[] = {
5450 { 5466 {
5451 "BPF_MAXINSNS: Jump, gap, jump, ...", 5467 "BPF_MAXINSNS: Jump, gap, jump, ...",
5452 { }, 5468 { },
5469#ifdef CONFIG_BPF_JIT_ALWAYS_ON
5470 CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
5471#else
5453 CLASSIC | FLAG_NO_DATA, 5472 CLASSIC | FLAG_NO_DATA,
5473#endif
5454 { }, 5474 { },
5455 { { 0, 0xababcbac } }, 5475 { { 0, 0xababcbac } },
5456 .fill_helper = bpf_fill_maxinsns11, 5476 .fill_helper = bpf_fill_maxinsns11,
5477 .expected_errcode = -ENOTSUPP,
5457 }, 5478 },
5458 { 5479 {
5459 "BPF_MAXINSNS: ld_abs+get_processor_id", 5480 "BPF_MAXINSNS: ld_abs+get_processor_id",
@@ -6344,7 +6365,7 @@ static struct bpf_prog *generate_filter(int which, int *err)
6344 6365
6345 *err = bpf_prog_create(&fp, &fprog); 6366 *err = bpf_prog_create(&fp, &fprog);
6346 if (tests[which].aux & FLAG_EXPECTED_FAIL) { 6367 if (tests[which].aux & FLAG_EXPECTED_FAIL) {
6347 if (*err == -EINVAL) { 6368 if (*err == tests[which].expected_errcode) {
6348 pr_cont("PASS\n"); 6369 pr_cont("PASS\n");
6349 /* Verifier rejected filter as expected. */ 6370 /* Verifier rejected filter as expected. */
6350 *err = 0; 6371 *err = 0;