|
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>
|
@@ -1397,6 +1398,34 @@ static bool is_skip_insn(struct bpf_insn *insn)
|
1397 | 1398 | return memcmp(insn, &skip_insn, sizeof(skip_insn)) == 0;
|
1398 | 1399 | }
|
1399 | 1400 |
|
| 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 | + |
1400 | 1429 | static int null_terminated_insn_len(struct bpf_insn *seq, int max_len)
|
1401 | 1430 | {
|
1402 | 1431 | int i;
|
@@ -1662,6 +1691,16 @@ static void do_test_single(struct bpf_test *test, bool unpriv,
|
1662 | 1691 | goto close_fds;
|
1663 | 1692 | }
|
1664 | 1693 |
|
| 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 | + |
1665 | 1704 | alignment_prevented_execution = 0;
|
1666 | 1705 |
|
1667 | 1706 | if (expected_ret == ACCEPT || expected_ret == VERBOSE_ACCEPT) {
|
|
0 commit comments