Skip to content

Commit 5cb8a82

Browse files
mannkafaitheihor
authored andcommitted
bpf: Allow fall back to interpreter for programs with stack size <= 512
OpenWRT users reported regression on ARMv6 devices after updating to latest HEAD, where tcpdump filter: tcpdump -i mon1 \ "not wlan addr3 3c37121a2b3c and not wlan addr2 184ecbca2a3a \ and not wlan addr2 14130b4d3f47 and not wlan addr2 f0f61cf440b7 \ and not wlan addr3 a84b4dedf471 and not wlan addr3 d022be17e1d7 \ and not wlan addr3 5c497967208b and not wlan addr2 706655784d5b" fails with warning: "Kernel filter failed: No error information" when using config: # CONFIG_BPF_JIT_ALWAYS_ON is not set CONFIG_BPF_JIT_DEFAULT_ON=y The issue arises because commits: 1. "bpf: Fix array bounds error with may_goto" changed default runtime to __bpf_prog_ret0_warn when jit_requested = 1 2. "bpf: Avoid __bpf_prog_ret0_warn when jit fails" returns error when jit_requested = 1 but jit fails This change restores interpreter fallback capability for BPF programs with stack size <= 512 bytes when jit fails. Reported-by: Felix Fietkau <[email protected]> Closes: https://lore.kernel.org/bpf/[email protected]/ Fixes: 6ebc503 ("bpf: Fix array bounds error with may_goto") Fixes: 86bc9c7 ("bpf: Avoid __bpf_prog_ret0_warn when jit fails") Signed-off-by: KaFai Wan <[email protected]>
1 parent ed19bc9 commit 5cb8a82

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

kernel/bpf/core.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2366,8 +2366,8 @@ static unsigned int __bpf_prog_ret0_warn(const void *ctx,
23662366
const struct bpf_insn *insn)
23672367
{
23682368
/* If this handler ever gets executed, then BPF_JIT_ALWAYS_ON
2369-
* is not working properly, or interpreter is being used when
2370-
* prog->jit_requested is not 0, so warn about it!
2369+
* or may_goto may cause stack size > 512 is not working properly,
2370+
* so warn about it!
23712371
*/
23722372
WARN_ON_ONCE(1);
23732373
return 0;
@@ -2478,10 +2478,10 @@ static void bpf_prog_select_func(struct bpf_prog *fp)
24782478
* But for non-JITed programs, we don't need bpf_func, so no bounds
24792479
* check needed.
24802480
*/
2481-
if (!fp->jit_requested &&
2482-
!WARN_ON_ONCE(idx >= ARRAY_SIZE(interpreters))) {
2481+
if (idx < ARRAY_SIZE(interpreters)) {
24832482
fp->bpf_func = interpreters[idx];
24842483
} else {
2484+
WARN_ON_ONCE(!fp->jit_requested);
24852485
fp->bpf_func = __bpf_prog_ret0_warn;
24862486
}
24872487
#else
@@ -2505,7 +2505,7 @@ struct bpf_prog *bpf_prog_select_runtime(struct bpf_prog *fp, int *err)
25052505
/* In case of BPF to BPF calls, verifier did all the prep
25062506
* work with regards to JITing, etc.
25072507
*/
2508-
bool jit_needed = fp->jit_requested;
2508+
bool jit_needed = false;
25092509

25102510
if (fp->bpf_func)
25112511
goto finalize;
@@ -2515,6 +2515,8 @@ struct bpf_prog *bpf_prog_select_runtime(struct bpf_prog *fp, int *err)
25152515
jit_needed = true;
25162516

25172517
bpf_prog_select_func(fp);
2518+
if (fp->bpf_func == __bpf_prog_ret0_warn)
2519+
jit_needed = true;
25182520

25192521
/* eBPF JITs can rewrite the program in case constant
25202522
* blinding is active. However, in case of error during

0 commit comments

Comments
 (0)