Follow ups for verifier errors set
Subsystems (4)
Kumar Kartikeya Dwivedi
maintainerv4 cover Follow ups for verifier errors set
Some follow up changes based on comments from Eduard, Sashiko, and BPF CI Bot. See commits for details.
Patches 1-4 of v3 were applied to bpf-next. This is the remainder, rebased on the current bpf-next/master.
Changelog:
----------
v3 -> v4
v3: https://lore.kernel.org/bpf/[email protected]
* Drop v3 patches 1-4, which are already applied.
* Rebase on the current bpf-next/master.
* State in the Program Structure patch that CO-RE relocations stay where c26e97721b17 put them and only func_info and line_info validation moves ahead of the layout checks. (Alexei)
v2 -> v3
v2: https://lore.kernel.org/bpf/[email protected]
* Rebase on bpf-next/master, which now applies CO-RE relocations before subprogram discovery, and only move func_info and line_info validation ahead of the layout checks.
* Drop the truncated final LD_IMM64 relocation guard and its test, as bpf_check() now rejects that form up front and core_reloc_raw covers it.
v1 -> v2
v1: https://lore.kernel.org/bpf/[email protected]
* Drop v1 patches 3, 5-7, 11, and 13-14 because they are already present in bpf-next.
* Use instruction-neutral wording for variable-offset stack accesses rather than inferring an atomic operation from value_regno == -1. (Eduard)
* Update the variable-offset assertions and cover the retained uninitialized stack-read diagnostic through the existing CAP_PERFMON-less read inside the allocated stack. (BPF CI)
* Keep v1 patch 4 unchanged after confirming that the write filter is reachable for lineage-preserving ALU operations with unchanged diagnostic snapshots; only its spill arm is impossible. Say so in the commit message. (Eduard)
* Consider active critical sections only for sleepable programs and let non-sleepable programs reach the existing no-active-context fallback instead of adding an early branch. A non-sleepable program can still hold RCU, preempt, IRQ, or lock state, so the fallback alone would keep blaming the region. Keep the "non-sleepable prog" description. (Eduard, BPF CI)
* Select the helper and global-function suggestions by cause, matching the kfunc site. (BPF CI)
* Split the kfunc coverage into a non-sleepable program case and a sleepable program inside an RCU read-side critical section. (Eduard)
* Scan subprogram properties with nested loops and drop the partial recursive-edge details together with their assertion. (Eduard)
* Reject CO-RE relocations targeting a truncated final LD_IMM64 before applying them, since BTF validation now runs before the subprogram layout check, and add raw CO-RE coverage for the rejection. Add the Fixes tag. (BPF CI)
* Rebase on the current bpf-next/master and let the new property scan also set the callx marker that check_subprogs() collects upstream.
Kumar Kartikeya Dwivedi (3):
selftests/bpf: Test non-sleepable kfunc context
bpf: Correct Program Structure diagnostic context selftests/bpf: Test Program Structure diagnostic context
kernel/bpf/cfg.c | 2 +- kernel/bpf/verifier.c | 54 +++++++++++++------ .../selftests/bpf/progs/preempt_lock.c | 26 +++++++++ .../selftests/bpf/progs/verifier_cfg.c | 40 ++++++++++++++ .../selftests/bpf/progs/verifier_gotox.c | 2 + 5 files changed, 106 insertions(+), 18 deletions(-)
base-commit: ea9358e1270ab2c3ba6f36bd9bdda68617665516
Signature · 1 line
2.53.0
Kumar Kartikeya Dwivedi
maintainerPATCH v4 1/3 selftests/bpf: Test non-sleepable kfunc context
A sleepable kfunc call can be rejected because the program itself is not sleepable or because a sleepable program is inside an active critical section.
Exercise the two causes separately. Call a sleepable kfunc directly from a non-sleepable tracing program, then call it from a sleepable tracing program inside an RCU read-side critical section. Assert both the legacy verifier messages and the structured reasons.
--- .../selftests/bpf/progs/preempt_lock.c | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+)
tools/testing/selftests/bpf/progs/preempt_lock.c +26 -0
@@ -6,6 +6,8 @@#include "bpf_experimental.h" extern int bpf_copy_from_user_str(void *dst, u32 dst__sz, const void *unsafe_ptr__ign, u64 flags) __weak __ksym; +extern void bpf_rcu_read_lock(void) __ksym; +extern void bpf_rcu_read_unlock(void) __ksym; SEC("?tc") __failure __msg("BPF_EXIT instruction in main prog cannot be used inside bpf_preempt_disable-ed region")
@@ -179,6 +181,30 @@ int preempt_sleepable_kfunc(void *ctx)return 0 ; } +SEC("?fentry/" SYS_PREFIX "sys_getpgid") +__failure __msg("program must be sleepable to call sleepable kfunc bpf_copy_from_user_str") +__msg("cannot be used in non-sleepable program") +int non_sleepable_kfunc (void *ctx) +{ +u32 data; + +bpf_copy_from_user_str (&data,sizeof (data),NULL ,0 ); +return 0 ; +} + +SEC("?fentry.s/" SYS_PREFIX "sys_getpgid") +__failure __msg("kernel func bpf_copy_from_user_str is sleepable within rcu_read_lock region") +__msg("cannot be used in RCU read lock region") +int sleepable_kfunc_in_rcu (void *ctx) +{ +u32 data; + +bpf_rcu_read_lock (); +bpf_copy_from_user_str (&data,sizeof (data),NULL ,0 ); +bpf_rcu_read_unlock (); +return 0 ; +} + int __noinline preempt_global_subprog(void) {preempt_balance_subprog ();
Signature · 1 line
2.53.0
Kumar Kartikeya Dwivedi
maintainerPATCH v4 2/3 bpf: Correct Program Structure diagnostic context
In reply to Kumar Kartikeya DwivediProgram Structure reports have two attribution gaps. A missing jump table is reported at the beginning of its subprogram rather than at the gotox that needs the table, and the subprogram-layout checks run before func_info and line_info are validated and installed, so their reports cannot name the source function or line.
Report the missing jump table at the gotox instruction that looks it up, rather than at the start of its subprogram.
func_info and line_info validation only needs the subprogram boundaries found by add_subprogs() and the LD_ABS and tail-call properties that check_subprogs() collects while scanning instructions; it does not depend on the layout checks themselves. Split the property collection into its own nested subprogram and instruction scan, together with the program's callx marker, and run bpf_check_btf_info() before check_subprogs(). The jump-boundary and fallthrough reports then carry validated source information without changing either check.
CO-RE relocations are unaffected: commit c26e97721b17 ("bpf: Apply CO-RE relocations before subprogram validation") applies them before add_subprogs(), and they stay there. Only the func_info and line_info validation moves.
--- kernel/bpf/cfg.c | 2 +- kernel/bpf/verifier.c | 54 +++++++++++++++++++++++++++++-------------- 2 files changed, 38 insertions(+), 18 deletions(-)
kernel/bpf/cfg.c +1 -1
@@ -393,7 +393,7 @@ subprog_jt(int t, struct bpf_verifier_env *env)if (!subprog->jt) {verbose (env,"no jump tables found for subprog starting at %u\n" , subprog_start);bpf_diag_program_structure ( - env, subprog_start,"missing jump table" , + env, t,"missing jump table" ,"Make sure subprograms containing gotox instructions are accompanied by jump tables referencing these subprograms." ,"No jump table was found for the subprogram that starts at instruction %u." , subprog_start);
kernel/bpf/verifier.c +37 -17
86 lines not on this page · raw message
Signature · 1 line
2.53.0
Kumar Kartikeya Dwivedi
maintainerPATCH v4 3/3 selftests/bpf: Test Program Structure diagnostic context
In reply to Kumar Kartikeya DwivediExercise each corrected Program Structure report. Place a missing-table gotox after another instruction so its attribution differs from the subprogram start.
Add malformed subprogram layouts for a branch crossing a subprogram boundary and a subprogram that falls through its end. Both cases carry BTF line records and assert that their structured reports include the corresponding source function and file.
--- .../selftests/bpf/progs/verifier_cfg.c | 40 +++++++++++++++++++ .../selftests/bpf/progs/verifier_gotox.c | 2 + 2 files changed, 42 insertions(+)
tools/testing/selftests/bpf/progs/verifier_cfg.c +40 -0
@@ -56,6 +56,46 @@ __naked void out_of_range_jump2(void) " ::: __clobber_all); } +static __naked __noinline __used int cross_subprog_target(void) +{ + asmvolatile (" \ +r0 = 0; \ +exit; \ +" ::: __clobber_all); +} + +SEC("socket") +__description("jump across subprogram boundary") +__failure __msg("jump out of range from insn 1") +__msg("jump_across_subprog_boundary @ verifier_cfg.c") +__naked void jump_across_subprog_boundary (void ) +{ + asmvolatile (" \ +call cross_subprog_target; \ +goto +1; \ +exit; \ +" ::: __clobber_all); +} + +static __naked __noinline __used int fallthrough_subprog(void) +{ + asmvolatile (" \ +r0 = 0; \ +" ::: __clobber_all); +} + +SEC("socket") +__description("subprogram fallthrough") +__failure __msg("last insn is not an exit or jmp") +__msg("fallthrough_subprog @ verifier_cfg.c") +__naked void subprog_fallthrough (void ) +{ + asmvolatile (" \ +call fallthrough_subprog; \ +exit; \ +" ::: __clobber_all); +} + SEC("socket") __description("invalid DW LDSX instruction in diagnostics") __failure __msg("BUG_ldx_99")
tools/testing/selftests/bpf/progs/verifier_gotox.c +2 -0
@@ -101,9 +101,11 @@ __naked void jump_table_terminal_gotox_subprog(void)*/ SEC("socket") __failure __msg("no jump tables found for subprog starting at 0") +__msg(">>> 1 | (0d) gotox r0")__naked void jump_table_no_jump_table (void ) { asm volatile (" \ + r0 = 0; \ .8byte %[gotox_r0]; \ r0 = 1; \ exit; \
Signature · 1 line
2.53.0
This series was applied to bpf/bpf-next.git (master) by Daniel Borkmann <[email protected]>:
Hello:
This series was applied to bpf/bpf-next.git (master) by Daniel Borkmann <[email protected]>:
Quoted 9 lines · On Sat, 26 Sep 2026 15:30:42 +0200 you wrote:
Some follow up changes based on comments from Eduard, Sashiko, and BPF CI Bot. See commits for details.
Patches 1-4 of v3 were applied to bpf-next. This is the remainder, rebased on the current bpf-next/master.
Changelog:
[...]
Here is the summary with links:
- [bpf-next,v4,1/3] selftests/bpf: Test non-sleepable kfunc context
https://git.kernel.org/bpf/bpf-next/c/8295510622f3 - [bpf-next,v4,2/3] bpf: Correct Program Structure diagnostic context https://git.kernel.org/bpf/bpf-next/c/d91052063bee - [bpf-next,v4,3/3] selftests/bpf: Test Program Structure diagnostic context https://git.kernel.org/bpf/bpf-next/c/917cfd1ed5ed
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html