|
21 | 21 | #include <sched.h>
|
22 | 22 | #include <limits.h>
|
23 | 23 | #include <assert.h>
|
| 24 | +#include <fcntl.h> |
24 | 25 |
|
25 | 26 | #include <linux/unistd.h>
|
26 | 27 | #include <linux/filter.h>
|
@@ -1355,6 +1356,34 @@ static bool is_skip_insn(struct bpf_insn *insn)
|
1355 | 1356 | return memcmp(insn, &skip_insn, sizeof(skip_insn)) == 0;
|
1356 | 1357 | }
|
1357 | 1358 |
|
| 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 | + |
1358 | 1387 | static int null_terminated_insn_len(struct bpf_insn *seq, int max_len)
|
1359 | 1388 | {
|
1360 | 1389 | int i;
|
@@ -1619,6 +1648,16 @@ static void do_test_single(struct bpf_test *test, bool unpriv,
|
1619 | 1648 | goto close_fds;
|
1620 | 1649 | }
|
1621 | 1650 |
|
| 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 | + |
1622 | 1661 | alignment_prevented_execution = 0;
|
1623 | 1662 |
|
1624 | 1663 | if (expected_ret == ACCEPT || expected_ret == VERBOSE_ACCEPT) {
|
|
0 commit comments