Skip to content

Commit e6dc162

Browse files
yonghong-songZhengShunQian
authored andcommitted
bpf: fix selftests/bpf test_kmod.sh failure when CONFIG_BPF_JIT_ALWAYS_ON=y
[ Upstream commit 09584b4 ] 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 290af86 (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: 290af86 (bpf: introduce BPF_JIT_ALWAYS_ON config) Signed-off-by: Yonghong Song <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Signed-off-by: Sasha Levin <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 6f20fb2 commit e6dc162

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

lib/test_bpf.c

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ struct bpf_test {
8383
__u32 result;
8484
} test[MAX_SUBTESTS];
8585
int (*fill_helper)(struct bpf_test *self);
86+
int expected_errcode; /* used when FLAG_EXPECTED_FAIL is set in the aux */
8687
__u8 frag_data[MAX_DATA];
8788
};
8889

@@ -1780,7 +1781,9 @@ static struct bpf_test tests[] = {
17801781
},
17811782
CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
17821783
{ },
1783-
{ }
1784+
{ },
1785+
.fill_helper = NULL,
1786+
.expected_errcode = -EINVAL,
17841787
},
17851788
{
17861789
"check: div_k_0",
@@ -1790,7 +1793,9 @@ static struct bpf_test tests[] = {
17901793
},
17911794
CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
17921795
{ },
1793-
{ }
1796+
{ },
1797+
.fill_helper = NULL,
1798+
.expected_errcode = -EINVAL,
17941799
},
17951800
{
17961801
"check: unknown insn",
@@ -1801,7 +1806,9 @@ static struct bpf_test tests[] = {
18011806
},
18021807
CLASSIC | FLAG_EXPECTED_FAIL,
18031808
{ },
1804-
{ }
1809+
{ },
1810+
.fill_helper = NULL,
1811+
.expected_errcode = -EINVAL,
18051812
},
18061813
{
18071814
"check: out of range spill/fill",
@@ -1811,7 +1818,9 @@ static struct bpf_test tests[] = {
18111818
},
18121819
CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
18131820
{ },
1814-
{ }
1821+
{ },
1822+
.fill_helper = NULL,
1823+
.expected_errcode = -EINVAL,
18151824
},
18161825
{
18171826
"JUMPS + HOLES",
@@ -1903,6 +1912,8 @@ static struct bpf_test tests[] = {
19031912
CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
19041913
{ },
19051914
{ },
1915+
.fill_helper = NULL,
1916+
.expected_errcode = -EINVAL,
19061917
},
19071918
{
19081919
"check: LDX + RET X",
@@ -1913,6 +1924,8 @@ static struct bpf_test tests[] = {
19131924
CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
19141925
{ },
19151926
{ },
1927+
.fill_helper = NULL,
1928+
.expected_errcode = -EINVAL,
19161929
},
19171930
{ /* Mainly checking JIT here. */
19181931
"M[]: alt STX + LDX",
@@ -2087,6 +2100,8 @@ static struct bpf_test tests[] = {
20872100
CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
20882101
{ },
20892102
{ },
2103+
.fill_helper = NULL,
2104+
.expected_errcode = -EINVAL,
20902105
},
20912106
{ /* Passes checker but fails during runtime. */
20922107
"LD [SKF_AD_OFF-1]",
@@ -4462,6 +4477,7 @@ static struct bpf_test tests[] = {
44624477
{ },
44634478
{ },
44644479
.fill_helper = bpf_fill_maxinsns4,
4480+
.expected_errcode = -EINVAL,
44654481
},
44664482
{ /* Mainly checking JIT here. */
44674483
"BPF_MAXINSNS: Very long jump",
@@ -4517,10 +4533,15 @@ static struct bpf_test tests[] = {
45174533
{
45184534
"BPF_MAXINSNS: Jump, gap, jump, ...",
45194535
{ },
4536+
#ifdef CONFIG_BPF_JIT_ALWAYS_ON
4537+
CLASSIC | FLAG_NO_DATA | FLAG_EXPECTED_FAIL,
4538+
#else
45204539
CLASSIC | FLAG_NO_DATA,
4540+
#endif
45214541
{ },
45224542
{ { 0, 0xababcbac } },
45234543
.fill_helper = bpf_fill_maxinsns11,
4544+
.expected_errcode = -ENOTSUPP,
45244545
},
45254546
{
45264547
"BPF_MAXINSNS: ld_abs+get_processor_id",
@@ -5290,7 +5311,7 @@ static struct bpf_prog *generate_filter(int which, int *err)
52905311

52915312
*err = bpf_prog_create(&fp, &fprog);
52925313
if (tests[which].aux & FLAG_EXPECTED_FAIL) {
5293-
if (*err == -EINVAL) {
5314+
if (*err == tests[which].expected_errcode) {
52945315
pr_cont("PASS\n");
52955316
/* Verifier rejected filter as expected. */
52965317
*err = 0;

0 commit comments

Comments
 (0)