Skip to content

Commit efbf113

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 549e1e7 commit efbf113

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>
@@ -1397,6 +1398,34 @@ static bool is_skip_insn(struct bpf_insn *insn)
13971398
return memcmp(insn, &skip_insn, sizeof(skip_insn)) == 0;
13981399
}
13991400

1401+
static inline bool is_ldimm64_insn(struct bpf_insn *insn)
1402+
{
1403+
return insn->code == (BPF_LD | BPF_IMM | BPF_DW);
1404+
}
1405+
1406+
static bool insn_is_pseudo_func(struct bpf_insn *insn)
1407+
{
1408+
return is_ldimm64_insn(insn) && insn->src_reg == BPF_PSEUDO_FUNC;
1409+
}
1410+
1411+
static bool is_jit_enabled(void)
1412+
{
1413+
const char *jit_sysctl = "/proc/sys/net/core/bpf_jit_enable";
1414+
bool enabled = false;
1415+
int sysctl_fd;
1416+
1417+
sysctl_fd = open(jit_sysctl, 0, O_RDONLY);
1418+
if (sysctl_fd != -1) {
1419+
char tmpc;
1420+
1421+
if (read(sysctl_fd, &tmpc, sizeof(tmpc)) == 1)
1422+
enabled = (tmpc != '0');
1423+
close(sysctl_fd);
1424+
}
1425+
1426+
return enabled;
1427+
}
1428+
14001429
static int null_terminated_insn_len(struct bpf_insn *seq, int max_len)
14011430
{
14021431
int i;
@@ -1662,6 +1691,16 @@ static void do_test_single(struct bpf_test *test, bool unpriv,
16621691
goto close_fds;
16631692
}
16641693

1694+
if (!is_jit_enabled()) {
1695+
for (i = 0; i < prog_len; i++, prog++) {
1696+
if (insn_is_pseudo_func(prog)) {
1697+
printf("SKIP (callbacks are not allowed in non-JITed programs)\n");
1698+
skips++;
1699+
goto close_fds;
1700+
}
1701+
}
1702+
}
1703+
16651704
alignment_prevented_execution = 0;
16661705

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

0 commit comments

Comments
 (0)