Skip to content

Commit 6df65a6

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 038fae2 commit 6df65a6

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

tools/testing/selftests/bpf/test_verifier.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <sched.h>
2222
#include <limits.h>
2323
#include <assert.h>
24+
#include <fcntl.h>
2425

2526
#include <linux/unistd.h>
2627
#include <linux/filter.h>
@@ -1355,6 +1356,34 @@ 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+
1369+
static bool is_jit_enabled(void)
1370+
{
1371+
const char *jit_sysctl = "/proc/sys/net/core/bpf_jit_enable";
1372+
bool enabled = false;
1373+
int sysctl_fd;
1374+
1375+
sysctl_fd = open(jit_sysctl, 0, O_RDONLY);
1376+
if (sysctl_fd != -1) {
1377+
char tmpc;
1378+
1379+
if (read(sysctl_fd, &tmpc, sizeof(tmpc)) == 1)
1380+
enabled = (tmpc != '0');
1381+
close(sysctl_fd);
1382+
}
1383+
1384+
return enabled;
1385+
}
1386+
13581387
static int null_terminated_insn_len(struct bpf_insn *seq, int max_len)
13591388
{
13601389
int i;
@@ -1619,6 +1648,16 @@ static void do_test_single(struct bpf_test *test, bool unpriv,
16191648
goto close_fds;
16201649
}
16211650

1651+
if (!is_jit_enabled()) {
1652+
for (i = 0; i < prog_len; i++, prog++) {
1653+
if (insn_is_pseudo_func(prog)) {
1654+
printf("SKIP (callbacks are not allowed in non-JITed programs)\n");
1655+
skips++;
1656+
goto close_fds;
1657+
}
1658+
}
1659+
}
1660+
16221661
alignment_prevented_execution = 0;
16231662

16241663
if (expected_ret == ACCEPT || expected_ret == VERBOSE_ACCEPT) {

0 commit comments

Comments
 (0)