Skip to content

Commit b2f5447

Browse files
seehearfeelKernel Patches Daemon
authored and
Kernel Patches Daemon
committed
selftests/bpf: Skip callback tests if jit is disabled in test_verifier
If CONFIG_BPF_JIT_ALWAYS_ON is not set and bpf_jit_enable is 0, there exist 6 failed tests. [root@linux bpf]# echo 0 > /proc/sys/net/core/bpf_jit_enable [root@linux bpf]# echo 0 > /proc/sys/kernel/unprivileged_bpf_disabled [root@linux bpf]# ./test_verifier | grep FAIL #106/p inline simple bpf_loop call FAIL #107/p don't inline bpf_loop call, flags non-zero FAIL #108/p don't inline bpf_loop call, callback non-constant FAIL #109/p bpf_loop_inline and a dead func FAIL #110/p bpf_loop_inline stack locations for loop vars FAIL #111/p inline bpf_loop call in a big program FAIL Summary: 768 PASSED, 15 SKIPPED, 6 FAILED The test log shows that callbacks are not allowed in non-JITed programs, interpreter doesn't support them yet, thus these tests should be skipped if jit is disabled, copy some check functions from the other places under tools directory, and then handle this case in do_test_single(). With this patch: [root@linux bpf]# echo 0 > /proc/sys/net/core/bpf_jit_enable [root@linux bpf]# echo 0 > /proc/sys/kernel/unprivileged_bpf_disabled [root@linux bpf]# ./test_verifier | grep FAIL Summary: 768 PASSED, 21 SKIPPED, 0 FAILED Signed-off-by: Tiezhu Yang <[email protected]>
1 parent 07039ae commit b2f5447

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

tools/testing/selftests/bpf/test_verifier.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
1ULL << CAP_BPF)
7575
#define UNPRIV_SYSCTL "kernel/unprivileged_bpf_disabled"
7676
static bool unpriv_disabled = false;
77+
static bool jit_disabled;
7778
static int skips;
7879
static bool verbose = false;
7980
static int verif_log_level = 0;
@@ -1355,6 +1356,16 @@ static bool is_skip_insn(struct bpf_insn *insn)
13551356
return memcmp(insn, &skip_insn, sizeof(skip_insn)) == 0;
13561357
}
13571358

1359+
static bool is_ldimm64_insn(struct bpf_insn *insn)
1360+
{
1361+
return insn->code == (BPF_LD | BPF_IMM | BPF_DW);
1362+
}
1363+
1364+
static bool insn_is_pseudo_func(struct bpf_insn *insn)
1365+
{
1366+
return is_ldimm64_insn(insn) && insn->src_reg == BPF_PSEUDO_FUNC;
1367+
}
1368+
13581369
static int null_terminated_insn_len(struct bpf_insn *seq, int max_len)
13591370
{
13601371
int i;
@@ -1622,6 +1633,16 @@ static void do_test_single(struct bpf_test *test, bool unpriv,
16221633
alignment_prevented_execution = 0;
16231634

16241635
if (expected_ret == ACCEPT || expected_ret == VERBOSE_ACCEPT) {
1636+
if (fd_prog < 0 && saved_errno == EINVAL && jit_disabled) {
1637+
for (i = 0; i < prog_len; i++, prog++) {
1638+
if (!insn_is_pseudo_func(prog))
1639+
continue;
1640+
printf("SKIP (callbacks are not allowed in non-JITed programs)\n");
1641+
skips++;
1642+
goto close_fds;
1643+
}
1644+
}
1645+
16251646
if (fd_prog < 0) {
16261647
printf("FAIL\nFailed to load prog '%s'!\n",
16271648
strerror(saved_errno));
@@ -1844,6 +1865,8 @@ int main(int argc, char **argv)
18441865
return EXIT_FAILURE;
18451866
}
18461867

1868+
jit_disabled = !is_jit_enabled();
1869+
18471870
/* Use libbpf 1.0 API mode */
18481871
libbpf_set_strict_mode(LIBBPF_STRICT_ALL);
18491872

0 commit comments

Comments
 (0)