| #
4c2cdb61 |
| 21-Oct-2026 |
Alexei Starovoitov <ast@kernel.org> |
selftests/bpf: Test unwind_exit of an exception callback
In both tests the prog that throws returns to a call that unwind_goto follows, and its exception callback ends with unwind_exit: - An extensi
selftests/bpf: Test unwind_exit of an exception callback
In both tests the prog that throws returns to a call that unwind_goto follows, and its exception callback ends with unwind_exit: - An extension replaces a subprog that cannot unwind. unwind_goto after the call stays, since it shares the pad with a call of a subprog that can unwind. - A subprog that can unwind does a tail call.
unwind_exit of the callback has to be exit. Without the fix the callers go to the pad and return 2 instead of 3 and 42 instead of 7.
Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://patch.msgid.link/20261020231942.2568163-4-alexei.starovoitov@gmail.com
show more ...
|
| #
86cec089 |
| 20-Oct-2026 |
Alexei Starovoitov <ast@kernel.org> |
selftests/bpf: Add tests for unwind_goto and unwind_exit
The tests spell the two insns out as raw insns, so they don't depend on llvm version.
verifier_unwind: - A static subprog, a global one and
selftests/bpf: Add tests for unwind_goto and unwind_exit
The tests spell the two insns out as raw insns, so they don't depend on llvm version.
verifier_unwind: - A static subprog, a global one and a callee of callx leave either way at run time, through one and two frames. The verifier follows a static subprog, so the tests derive the argument from skb->len or read it from a map. - r0 of unwind_exit, r6-r9 and the stack are there in the pad. r1-r5 are not readable. - A pad is checked like any other code: it has to drop rcu_read_lock. - How the callee left is a part of the verifier state: two states that differ only in that are not pruned. - The pad of a call of a global subprog is always checked. - A callee that never returns, where unwind_goto stays and 'goto pc-1' follows it, and one that never unwinds, where it goes away with the pad. - What follows unwind_goto runs speculatively: with CAP_BPF only there is nospec in front of an insn that isn't safe with r0 of unwind_exit. - unwind_exit without unwind_goto after the call. - unwind_goto that doesn't follow a call of a subprog or is a jump target. - Reserved fields. - A sync callback cannot unwind. What it calls can. - unwind_exit of an async and of an exception callback is exit. - Tail call and ld_abs in a subprog that can unwind. - unwind_exit of the main prog is exit. - What x86-64 and arm64 JITs emit. With KASAN x86-64 JIT wraps a load in pushes, a call and pops, so the patterns start after the loads. - Private stack. On x86-64 r9 has to be restored on the way to the pad.
The last one has to look at the return value of a prog that uses private stack. raw_tp is such a prog. Its test_run doesn't take a packet, so let test_loader run it like it runs syscall progs.
unwind_attach, with the caller run after every attach: - fentry on a subprog that unwinds. fexit is refused. - freplace of a subprog that unwinds by an extension that returns and by one that unwinds. The caller goes on after the call or in the pad. - An extension that unwinds cannot replace a subprog that doesn't.
Every check that the series adds was removed in turn to see that a test fails.
Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://patch.msgid.link/20261020181320.1284798-5-alexei.starovoitov@gmail.com
show more ...
|