| Seq | Timestamp | Type | Name | Duration |
|---|---|---|---|---|
| 0/0 | 2026/09/26 03:30 | flow | patch-triage |
2mArgs:null Results: {
"EnableConfigs": [
"BPF_SYSCALL",
"BPF_JIT"
],
"FocusSymbols": [
"bpf_widen_loop_head",
"bpf_mark_loop_guard",
"bpf_commit_loop_guards",
"bpf_scc_mark_exit",
"bpf_is_state_visited"
],
"KMSANReasoning": "The patch series implements loop widening in the BPF verifier and runtime loop guards (may_goto + bpf_throw fixups) for loops that converge with widened states.\n\nAnalysis of memory safety and sanitizer applicability:\n1. No Kernel-to-User Info-Leaks: The changes operate purely within the internal BPF verifier pipeline during program verification and instruction fixups. No kernel structures or memory buffers are copied to user space.\n2. Structure Initialization: All newly allocated data structures (such as `walk_snapshot`, `scc_converged`, `scc_thrs`, and temporary instruction patch buffers) are explicitly zero-initialized using `memset`, `kvzalloc`, or `kvmemdup` from initialized data.\n3. Control Flow and Branching: Conditional branches rely only on fully initialized local or struct variables; no uninitialized struct fields or stack variables are evaluated.\n4. KASAN vs KMSAN: The primary risks associated with these changes are verifier logic errors, incorrect jump/instruction offset calculations, instruction buffer overflow, or potential state tracking use-after-free bugs. All of these potential failure modes are fully covered by KASAN, UBSAN, and standard kernel debugging facilities. No uninitialized memory usage or leak risks specific to KMSAN are introduced.\n\nTherefore, a dedicated KMSAN fuzzing session is not warranted.",
"NeedsKMSAN": false,
"Reasoning": "The patch introduces loop widening and loop guard insertion into the BPF verifier. This is a substantial change to core BPF verifier logic in kernel/bpf/ (verifier.c, states.c, fixups.c, cfg.c), implementing scalar range widening across loop iterations, verifier state snapshot/restore rollback on failure, and instruction rewrites to insert may_goto/bpf_throw guards. This code is reachable from userspace via the bpf() system call and is an important target for fuzzing to discover potential soundness issues, unbounded memory consumption, or crashes.",
"WorthFuzzing": true
} |
| 1/1 | 2026/09/26 03:30 | action | read-patch-diff |
0mArgs:null Results: {
"PatchDiff": "commit 3769330d0db57d4c049d66c93c77f5e01c5a973d\nAuthor: syz-cluster \u003ctriage@syzkaller.com\u003e\nDate: Sat Sep 26 03:30:31 2026 +0000\n\n syz-cluster: applied patch under review\n\ndiff --git a/include/linux/bpf_verifier.h b/include/linux/bpf_verifier.h\nindex 92f528c456052..e02ee286067d2 100644\n--- a/include/linux/bpf_verifier.h\n+++ b/include/linux/bpf_verifier.h\n@@ -527,6 +527,8 @@ struct bpf_verifier_state {\n \tu32 dfs_depth;\n \tu32 callback_unroll_depth;\n \tu32 may_goto_depth;\n+\t/* number of times the loop head this state is a checkpoint of was widened */\n+\tu32 loop_passes;\n };\n \n static inline struct bpf_reg_state *\n@@ -709,6 +711,16 @@ struct bpf_insn_aux_data {\n \tu32 non_stack_access:1; /* instruction can access non-stack memory */\n \t/* true if some jump or call instruction targets this instruction */\n \tu32 jump_target:1;\n+\tu32 loop_head:1; /* target of a back-edge */\n+\tu32 backedge_ft:1; /* the edge to the next insn is a back-edge */\n+\tu32 backedge_br:1; /* the jump is a back-edge */\n+\t/*\n+\t * The walk went over the back-edge of this insn with nothing to bound\n+\t * the number of trips, in a state where bpf_throw() can and cannot be called.\n+\t */\n+\tu32 guard_pending:1;\n+\tu32 guard_impossible:1;\n+\tu32 loop_guard:1; /* may_goto has to be added to the back-edge of this insn */\n \t/*\n \t * CFG strongly connected component this instruction belongs to,\n \t * zero if it is a singleton SCC.\n@@ -895,6 +907,8 @@ struct bpf_scc_visit {\n \tstruct bpf_verifier_state *entry_state;\n \tstruct bpf_scc_backedge *backedges; /* list of backedges */\n \tu32 num_backedges;\n+\t/* some state left the SCC since entry_state was set */\n+\tbool exited;\n };\n \n /* An array of bpf_scc_visit structs sharing tht same bpf_scc_callchain-\u003escc\n@@ -1046,6 +1060,16 @@ struct bpf_verifier_env {\n \t/* array of pointers to bpf_scc_info indexed by SCC id */\n \tstruct bpf_scc_info **scc_info;\n \tu32 scc_cnt;\n+\t/* per SCC constants that loop counters are compared with, see bpf_widen_loop_head() */\n+\tstruct bpf_widen_thrs **scc_thrs;\n+\t/* SCCs where some state came back to a state that is still walked */\n+\tunsigned long *scc_converged;\n+\t/* states that come back to a loop head are widened instead of walking every iteration */\n+\tbool widen_loops;\n+\t/* the walk did or tried that, so a failure can be due to the lost precision */\n+\tbool widen_used;\n+\t/* insns processed by a walk that was given up */\n+\tu32 insn_wasted;\n \tstruct bpf_iarray *succ;\n \tstruct bpf_iarray *gotox_tmp_buf;\n };\n@@ -1218,6 +1242,13 @@ void bpf_free_kfunc_btf_tab(struct bpf_kfunc_btf_tab *tab);\n int mark_chain_precision(struct bpf_verifier_env *env, int regno);\n \n int bpf_is_state_visited(struct bpf_verifier_env *env, int insn_idx);\n+bool bpf_same_loop(struct bpf_verifier_state *old, struct bpf_verifier_state *cur);\n+bool bpf_mark_loop_guard(struct bpf_verifier_env *env, struct bpf_verifier_state *cur);\n+int bpf_commit_loop_guards(struct bpf_verifier_env *env);\n+void bpf_throw(u64 cookie);\n+void bpf_scc_mark_exit(struct bpf_verifier_env *env, struct bpf_verifier_state *st, int insn_idx);\n+int bpf_widen_loop_head(struct bpf_verifier_env *env, int insn_idx, bool backedge,\n+\t\t\tstruct bpf_verifier_state *old, struct bpf_verifier_state *cur);\n int bpf_update_branch_counts(struct bpf_verifier_env *env, struct bpf_verifier_state *st);\n \n void bpf_clear_jmp_history(struct bpf_verifier_state *state);\ndiff --git a/kernel/bpf/cfg.c b/kernel/bpf/cfg.c\nindex 842c7d1eabccc..748bf544d3ba5 100644\n--- a/kernel/bpf/cfg.c\n+++ b/kernel/bpf/cfg.c\n@@ -137,8 +137,14 @@ static int push_insn(int t, int w, int e, struct bpf_verifier_env *env)\n \t\tinsn_stack[env-\u003ecfg.cur_stack++] = w;\n \t\treturn KEEP_EXPLORING;\n \t} else if ((insn_state[w] \u0026 0xF0) == DISCOVERED) {\n-\t\tif (env-\u003ebpf_capable)\n+\t\tif (env-\u003ebpf_capable) {\n+\t\t\tenv-\u003einsn_aux_data[w].loop_head = true;\n+\t\t\tif (e == FALLTHROUGH)\n+\t\t\t\tenv-\u003einsn_aux_data[t].backedge_ft = true;\n+\t\t\telse\n+\t\t\t\tenv-\u003einsn_aux_data[t].backedge_br = true;\n \t\t\treturn DONE_EXPLORING;\n+\t\t}\n \t\tverbose_linfo(env, t, \"%d: \", t);\n \t\tverbose_linfo(env, w, \"%d: \", w);\n \t\tverbose(env, \"back-edge from insn %d to %d\\n\", t, w);\ndiff --git a/kernel/bpf/fixups.c b/kernel/bpf/fixups.c\nindex 2add8001c3ec3..2b965fa4bacc0 100644\n--- a/kernel/bpf/fixups.c\n+++ b/kernel/bpf/fixups.c\n@@ -1537,6 +1537,143 @@ static int add_hidden_subprog(struct bpf_verifier_env *env, struct bpf_insn *pat\n /* Do various post-verification rewrites in a single program pass.\n * These rewrites simplify JIT and interpreter implementations.\n */\n+/*\n+ * The walk with widened loops is done. Loops where some state came back to\n+ * a state that was still walked were not walked to the end and have to be\n+ * bounded at run time.\n+ */\n+int bpf_commit_loop_guards(struct bpf_verifier_env *env)\n+{\n+\tstruct bpf_insn_aux_data *aux = env-\u003einsn_aux_data;\n+\tint i;\n+\n+\tfor (i = 0; i \u003c env-\u003eprog-\u003elen; i++) {\n+\t\tif (!aux[i].scc || !test_bit(aux[i].scc, env-\u003escc_converged))\n+\t\t\tcontinue;\n+\t\tif (aux[i].guard_impossible) {\n+\t\t\tverbose(env, \"loop with back-edge at insn %d cannot be bounded\\n\", i);\n+\t\t\treturn -E2BIG;\n+\t\t}\n+\t\tif (aux[i].guard_pending) {\n+\t\t\taux[i].loop_guard = true;\n+\t\t\tenv-\u003eseen_exception = true;\n+\t\t}\n+\t}\n+\treturn 0;\n+}\n+\n+/* Jump from insn @from of the patch that replaces insn @idx to insn @target of the program. */\n+static int guard_jump(struct bpf_insn *insn, int idx, int from, int cnt, int target)\n+{\n+\tint off;\n+\n+\t/* insns after @idx move by the size of the patch */\n+\tif (target \u003e idx)\n+\t\ttarget += cnt - 1;\n+\toff = target - (idx + from) - 1;\n+\tif (BPF_OP(insn-\u003ecode) == BPF_JA \u0026\u0026 BPF_CLASS(insn-\u003ecode) == BPF_JMP32) {\n+\t\tinsn-\u003eimm = off;\n+\t\treturn 0;\n+\t}\n+\tif (off \u003c S16_MIN || off \u003e S16_MAX) {\n+\t\tif (BPF_OP(insn-\u003ecode) != BPF_JA)\n+\t\t\treturn -ERANGE;\n+\t\t*insn = BPF_JMP32_A(off);\n+\t\treturn 0;\n+\t}\n+\tinsn-\u003eoff = off;\n+\treturn 0;\n+}\n+\n+/*\n+ * The main pass went over the back-edge of jump @insn at @idx with a state\n+ * that stands for any number of iterations. Nothing bounds the loop at run\n+ * time, so add may_goto to the back-edge. The program cannot go on when\n+ * may_goto is out of budget: nothing but the loop was verified for the state\n+ * in the loop. Call bpf_throw(). The main pass made sure it can be called.\n+ *\n+ * back-edge is the jump: back-edge is the edge to the next insn:\n+ * if cond goto guard if cond goto target\n+ * goto next guard:\n+ * guard: may_goto throw\n+ * may_goto throw goto next\n+ * goto head throw:\n+ * throw: r1 = 0\n+ * r1 = 0 call bpf_throw\n+ * call bpf_throw next:\n+ * next:\n+ *\n+ * Returns the number of insns in @buf.\n+ */\n+static int add_loop_guard(struct bpf_verifier_env *env, int idx, struct bpf_insn *buf,\n+\t\t\t int stack_depth, u16 *stack_depth_extra)\n+{\n+\tstruct bpf_insn_aux_data *aux = \u0026env-\u003einsn_aux_data[idx];\n+\tstruct bpf_insn orig = env-\u003eprog-\u003einsnsi[idx];\n+\tbool ja = BPF_OP(orig.code) == BPF_JA;\n+\tbool gotol = ja \u0026\u0026 BPF_CLASS(orig.code) == BPF_JMP32;\n+\tint target = idx + 1 + (gotol ? orig.imm : orig.off);\n+\tbool guard_jump_edge = ja || aux-\u003ebackedge_br;\n+\tstruct bpf_insn *p = buf, *jeq, *skip = NULL, *back = NULL;\n+\tint stack_off, cnt, err = 0;\n+\n+\tif (guard_jump_edge \u0026\u0026 !ja) {\n+\t\t*p = orig;\n+\t\tp-\u003eoff = 1;\n+\t\tp++;\n+\t\tskip = p;\n+\t\t*p++ = BPF_JMP_A(0);\n+\t} else if (!guard_jump_edge) {\n+\t\t*p++ = orig;\n+\t}\n+\n+\t/* the same insns may_goto is replaced with, see bpf_do_misc_fixups() */\n+\tif (bpf_jit_supports_timed_may_goto()) {\n+\t\tstack_off = -stack_depth - 16;\n+\t\t*stack_depth_extra = 16;\n+\t\t*p++ = BPF_LDX_MEM(BPF_DW, BPF_REG_AX, BPF_REG_10, stack_off);\n+\t\tjeq = p;\n+\t\t*p++ = BPF_JMP_IMM(BPF_JEQ, BPF_REG_AX, 0, 0);\n+\t\t*p++ = BPF_ALU64_IMM(BPF_SUB, BPF_REG_AX, 1);\n+\t\t*p++ = BPF_JMP_IMM(BPF_JNE, BPF_REG_AX, 0, 2);\n+\t\t*p++ = BPF_MOV64_IMM(BPF_REG_AX, stack_off);\n+\t\t*p++ = BPF_EMIT_CALL(arch_bpf_timed_may_goto);\n+\t\t*p++ = BPF_STX_MEM(BPF_DW, BPF_REG_10, BPF_REG_AX, stack_off);\n+\t} else {\n+\t\tstack_off = -stack_depth - 8;\n+\t\t*stack_depth_extra = max_t(u16, *stack_depth_extra, 8);\n+\t\t*p++ = BPF_LDX_MEM(BPF_DW, BPF_REG_AX, BPF_REG_10, stack_off);\n+\t\tjeq = p;\n+\t\t*p++ = BPF_JMP_IMM(BPF_JEQ, BPF_REG_AX, 0, 0);\n+\t\t*p++ = BPF_ALU64_IMM(BPF_SUB, BPF_REG_AX, 1);\n+\t\t*p++ = BPF_STX_MEM(BPF_DW, BPF_REG_10, BPF_REG_AX, stack_off);\n+\t}\n+\n+\tif (guard_jump_edge) {\n+\t\tback = p;\n+\t\t*p++ = gotol ? orig : BPF_JMP_A(0);\n+\t} else {\n+\t\t/* over bpf_throw() to the loop head that follows */\n+\t\t*p++ = BPF_JMP_A(2);\n+\t}\n+\tjeq-\u003eoff = p - jeq - 1;\n+\t*p++ = BPF_MOV64_IMM(BPF_REG_1, 0);\n+\t*p++ = BPF_EMIT_CALL(bpf_throw);\n+\tcnt = p - buf;\n+\n+\tif (skip)\n+\t\tskip-\u003eoff = cnt - (skip - buf) - 1;\n+\tif (back)\n+\t\terr = guard_jump(back, idx, back - buf, cnt, target);\n+\telse\n+\t\terr = guard_jump(\u0026buf[0], idx, 0, cnt, target);\n+\tif (err) {\n+\t\tverbose(env, \"insn %d: jump is out of range after may_goto is added\\n\", idx);\n+\t\treturn err;\n+\t}\n+\treturn cnt;\n+}\n+\n int bpf_do_misc_fixups(struct bpf_verifier_env *env)\n {\n \tstruct bpf_prog *prog = env-\u003eprog;\n@@ -1573,6 +1710,22 @@ int bpf_do_misc_fixups(struct bpf_verifier_env *env)\n \t}\n \n \tfor (i = 0; i \u003c insn_cnt;) {\n+\t\tif (env-\u003einsn_aux_data[i + delta].loop_guard) {\n+\t\t\tcnt = add_loop_guard(env, i + delta, insn_buf, stack_depth,\n+\t\t\t\t\t \u0026stack_depth_extra);\n+\t\t\tif (cnt \u003c 0)\n+\t\t\t\treturn cnt;\n+\n+\t\t\tnew_prog = bpf_patch_insn_data(env, i + delta, insn_buf, cnt);\n+\t\t\tif (!new_prog)\n+\t\t\t\treturn -ENOMEM;\n+\n+\t\t\tdelta += cnt - 1;\n+\t\t\tenv-\u003eprog = prog = new_prog;\n+\t\t\tinsn = new_prog-\u003einsnsi + i + delta;\n+\t\t\tgoto next_insn;\n+\t\t}\n+\n \t\tif (is_addr_space_cast32(env-\u003eprog, insn)) {\n \t\t\t/* convert to 32-bit mov that clears upper 32-bit */\n \t\t\tinsn-\u003ecode = BPF_ALU | BPF_MOV | BPF_X;\ndiff --git a/kernel/bpf/states.c b/kernel/bpf/states.c\nindex 66fb11b6c6a76..24422b7db6d97 100644\n--- a/kernel/bpf/states.c\n+++ b/kernel/bpf/states.c\n@@ -170,6 +170,7 @@ static int maybe_enter_scc(struct bpf_verifier_env *env, struct bpf_verifier_sta\n \t\treturn -ENOMEM;\n \tif (!visit-\u003eentry_state) {\n \t\tvisit-\u003eentry_state = st;\n+\t\tvisit-\u003eexited = false;\n \t\tif (env-\u003elog.level \u0026 BPF_LOG_LEVEL2)\n \t\t\tverbose(env, \"SCC enter %s\\n\", format_callchain(env, callchain));\n \t}\n@@ -212,6 +213,16 @@ static int maybe_exit_scc(struct bpf_verifier_env *env, struct bpf_verifier_stat\n \t}\n \tif (visit-\u003eentry_state != st)\n \t\treturn 0;\n+\t/*\n+\t * All states that came from @st are done. If some of them went\n+\t * around the loop and none left it, nothing that enters the loop\n+\t * the way @st did ever leaves it.\n+\t */\n+\tif (env-\u003ewiden_loops \u0026\u0026 !st-\u003especulative \u0026\u0026 visit-\u003ebackedges \u0026\u0026 !visit-\u003eexited) {\n+\t\tverbose(env, \"loop at insn %d never exits\\n\", st-\u003einsn_idx);\n+\t\tenv-\u003ewiden_used = true;\n+\t\treturn -EINVAL;\n+\t}\n \tif (env-\u003elog.level \u0026 BPF_LOG_LEVEL2)\n \t\tverbose(env, \"SCC exit %s\\n\", format_callchain(env, callchain));\n \tvisit-\u003eentry_state = NULL;\n@@ -221,6 +232,32 @@ static int maybe_exit_scc(struct bpf_verifier_env *env, struct bpf_verifier_stat\n \treturn propagate_backedges(env, visit);\n }\n \n+/*\n+ * @st left the loop that @insn_idx of its current frame is in. The loop is\n+ * left when the frame that bpf_scc_visit is for leaves it. Loops in callees\n+ * of that frame are part of one trip around the loop of the caller.\n+ */\n+void bpf_scc_mark_exit(struct bpf_verifier_env *env, struct bpf_verifier_state *st, int insn_idx)\n+{\n+\tstruct bpf_scc_callchain *callchain = \u0026env-\u003ecallchain_buf;\n+\tstruct bpf_scc_visit *visit;\n+\tu32 i, callsite;\n+\n+\tif (st-\u003especulative || !env-\u003einsn_aux_data[insn_idx].scc)\n+\t\treturn;\n+\tmemset(callchain, 0, sizeof(*callchain));\n+\tfor (i = 0; i \u003c st-\u003ecurframe; i++) {\n+\t\tcallsite = bpf_frame_insn_idx(st, i);\n+\t\tif (env-\u003einsn_aux_data[callsite].scc)\n+\t\t\treturn;\n+\t\tcallchain-\u003ecallsites[i] = callsite;\n+\t}\n+\tcallchain-\u003escc = env-\u003einsn_aux_data[insn_idx].scc;\n+\tvisit = scc_visit_lookup(env, callchain);\n+\tif (visit)\n+\t\tvisit-\u003eexited = true;\n+}\n+\n /* Lookup an bpf_scc_visit instance corresponding to @st callchain\n * and add @backedge to visit-\u003ebackedges. @st callchain must exist.\n */\n@@ -244,6 +281,8 @@ static int add_scc_backedge(struct bpf_verifier_env *env,\n \t}\n \tif (env-\u003elog.level \u0026 BPF_LOG_LEVEL2)\n \t\tverbose(env, \"SCC backedge %s\\n\", format_callchain(env, callchain));\n+\tif (env-\u003escc_converged)\n+\t\t__set_bit(callchain-\u003escc, env-\u003escc_converged);\n \tbackedge-\u003enext = visit-\u003ebackedges;\n \tvisit-\u003ebackedges = backedge;\n \tvisit-\u003enum_backedges++;\n@@ -1108,6 +1147,62 @@ static int propagate_backedges(struct bpf_verifier_env *env, struct bpf_scc_visi\n \treturn 0;\n }\n \n+/* Did the walk get to @insn_idx over a back-edge? */\n+static bool is_backedge(struct bpf_verifier_env *env, int insn_idx)\n+{\n+\tint prev = env-\u003eprev_insn_idx;\n+\tstruct bpf_insn_aux_data *aux;\n+\tstruct bpf_insn *insn;\n+\n+\tif (prev \u003c 0 || prev \u003e= env-\u003eprog-\u003elen)\n+\t\treturn false;\n+\taux = \u0026env-\u003einsn_aux_data[prev];\n+\tinsn = \u0026env-\u003eprog-\u003einsnsi[prev];\n+\t/* check_cfg() does not record the edge of an unconditional jump as a jump */\n+\tif ((BPF_CLASS(insn-\u003ecode) == BPF_JMP || BPF_CLASS(insn-\u003ecode) == BPF_JMP32) \u0026\u0026\n+\t BPF_OP(insn-\u003ecode) == BPF_JA)\n+\t\treturn aux-\u003ebackedge_ft || aux-\u003ebackedge_br;\n+\treturn insn_idx == prev + 1 ? aux-\u003ebackedge_ft : aux-\u003ebackedge_br;\n+}\n+\n+static bool iter_active_depths_differ(struct bpf_verifier_state *old,\n+\t\t\t\t struct bpf_verifier_state *cur);\n+\n+/* The state of this walk that was the last to get to loop head @insn_idx. */\n+static struct bpf_verifier_state *loop_head_state(struct bpf_verifier_env *env, int insn_idx)\n+{\n+\tstruct bpf_verifier_state *cur = env-\u003ecur_state;\n+\tstruct bpf_verifier_state_list *sl;\n+\tstruct list_head *pos;\n+\n+\t/* states are most recent first */\n+\tlist_for_each(pos, bpf_explored_state(env, insn_idx)) {\n+\t\tsl = container_of(pos, struct bpf_verifier_state_list, node);\n+\t\tif (sl-\u003estate.insn_idx == insn_idx \u0026\u0026 sl-\u003estate.branches \u0026\u0026\n+\t\t bpf_same_loop(\u0026sl-\u003estate, cur))\n+\t\t\treturn \u0026sl-\u003estate;\n+\t}\n+\treturn NULL;\n+}\n+\n+/*\n+ * @cur got to loop head @insn_idx, @old is the state that started this trip\n+ * around the loop if there is one. The trip is bounded at run time if it\n+ * took from the budget of may_goto or got an element from an iterator.\n+ * Otherwise may_goto has to be added to the back-edge if the loop is not\n+ * walked to the end. Returns false if that is not possible.\n+ */\n+static bool loop_head_guard(struct bpf_verifier_env *env, int insn_idx,\n+\t\t\t struct bpf_verifier_state *old, struct bpf_verifier_state *cur)\n+{\n+\tif (!is_backedge(env, insn_idx))\n+\t\treturn true;\n+\tif (old \u0026\u0026 (old-\u003emay_goto_depth != cur-\u003emay_goto_depth ||\n+\t\t iter_active_depths_differ(old, cur)))\n+\t\treturn true;\n+\treturn bpf_mark_loop_guard(env, cur);\n+}\n+\n static bool states_maybe_looping(struct bpf_verifier_state *old,\n \t\t\t\t struct bpf_verifier_state *cur)\n {\n@@ -1237,12 +1332,23 @@ int bpf_is_state_visited(struct bpf_verifier_env *env, int insn_idx)\n {\n \tstruct bpf_verifier_state_list *new_sl;\n \tstruct bpf_verifier_state_list *sl;\n-\tstruct bpf_verifier_state *cur = env-\u003ecur_state, *new;\n+\tstruct bpf_verifier_state *cur = env-\u003ecur_state, *new, *widen_from = NULL;\n+\tbool loop_head = env-\u003ewiden_loops \u0026\u0026 env-\u003einsn_aux_data[insn_idx].loop_head;\n \tbool force_new_state, add_new_state, loop;\n \tint n, err, states_cnt = 0;\n \tstruct list_head *pos, *tmp, *head;\n \n+\tif (loop_head) {\n+\t\twiden_from = loop_head_state(env, insn_idx);\n+\t\t/* the loop cannot be bounded at run time, walk all of it */\n+\t\tif (!loop_head_guard(env, insn_idx, widen_from, cur)) {\n+\t\t\tloop_head = false;\n+\t\t\twiden_from = NULL;\n+\t\t}\n+\t}\n+\n \tforce_new_state = env-\u003etest_state_freq || bpf_is_force_checkpoint(env, insn_idx) ||\n+\t\t\t loop_head ||\n \t\t\t /* Avoid accumulating infinitely long jmp history */\n \t\t\t cur-\u003ejmp_history_cnt \u003e 40;\n \n@@ -1364,12 +1470,32 @@ int bpf_is_state_visited(struct bpf_verifier_env *env, int insn_idx)\n \t\t\t\t}\n \t\t\t\tgoto skip_inf_loop_check;\n \t\t\t}\n+\t\t\t/*\n+\t\t\t * The state came back to the loop head. If it is within\n+\t\t\t * the state that went around the loop nothing new can\n+\t\t\t * happen on the next trip. Otherwise it is widened below\n+\t\t\t * and goes around instead of all the iterations it stands for.\n+\t\t\t */\n+\t\t\tif (loop_head \u0026\u0026 bpf_same_loop(\u0026sl-\u003estate, cur)) {\n+\t\t\t\tif (states_equal(env, \u0026sl-\u003estate, cur, RANGE_WITHIN)) {\n+\t\t\t\t\tenv-\u003ewiden_used = true;\n+\t\t\t\t\tloop = true;\n+\t\t\t\t\tgoto hit;\n+\t\t\t\t}\n+\t\t\t\tgoto skip_inf_loop_check;\n+\t\t\t}\n \t\t\t/* attempt to detect infinite loop to avoid unnecessary doomed work */\n \t\t\tif (states_maybe_looping(\u0026sl-\u003estate, cur) \u0026\u0026\n \t\t\t states_equal(env, \u0026sl-\u003estate, cur, EXACT) \u0026\u0026\n \t\t\t !iter_active_depths_differ(\u0026sl-\u003estate, cur) \u0026\u0026\n \t\t\t sl-\u003estate.may_goto_depth == cur-\u003emay_goto_depth \u0026\u0026\n \t\t\t sl-\u003estate.callback_unroll_depth == cur-\u003ecallback_unroll_depth) {\n+\t\t\t\t/* the state repeats, nothing new on the next trip */\n+\t\t\t\tif (env-\u003ewiden_loops) {\n+\t\t\t\t\tenv-\u003ewiden_used = true;\n+\t\t\t\t\tloop = true;\n+\t\t\t\t\tgoto hit;\n+\t\t\t\t}\n \t\t\t\tverbose_linfo(env, insn_idx, \"; \");\n \t\t\t\tverbose(env, \"infinite loop detected at insn %d\\n\", insn_idx);\n \t\t\t\tverbose(env, \"cur state:\");\n@@ -1402,6 +1528,9 @@ int bpf_is_state_visited(struct bpf_verifier_env *env, int insn_idx)\n \t\tif (states_equal(env, \u0026sl-\u003estate, cur, loop ? RANGE_WITHIN : NOT_EXACT)) {\n hit:\n \t\t\tsl-\u003ehit_cnt++;\n+\t\t\t/* what follows the old state was seen, it may leave the loop */\n+\t\t\tif (env-\u003ewiden_loops \u0026\u0026 !sl-\u003estate.branches)\n+\t\t\t\tbpf_scc_mark_exit(env, cur, insn_idx);\n \n \t\t\t/* if previous state reached the exit with precision and\n \t\t\t * current state is equivalent to it (except precision marks)\n@@ -1522,7 +1651,8 @@ int bpf_is_state_visited(struct bpf_verifier_env *env, int insn_idx)\n \t\t * Use bigger 'n' for checkpoints because evicting checkpoint states\n \t\t * too early would hinder iterator convergence.\n \t\t */\n-\t\tn = bpf_is_force_checkpoint(env, insn_idx) \u0026\u0026 sl-\u003estate.branches \u003e 0 ? 64 : 3;\n+\t\tn = (bpf_is_force_checkpoint(env, insn_idx) || loop_head) \u0026\u0026\n+\t\t sl-\u003estate.branches \u003e 0 ? 64 : 3;\n \t\tif (sl-\u003emiss_cnt \u003e sl-\u003ehit_cnt * n + n) {\n \t\t\t/* the state is unlikely to be useful. Remove it to\n \t\t\t * speed up verification\n@@ -1539,6 +1669,16 @@ int bpf_is_state_visited(struct bpf_verifier_env *env, int insn_idx)\n \tif (env-\u003emax_states_per_insn \u003c states_cnt)\n \t\tenv-\u003emax_states_per_insn = states_cnt;\n \n+\tif (loop_head) {\n+\t\tcur-\u003eloop_passes = 0;\n+\t\tif (widen_from) {\n+\t\t\terr = bpf_widen_loop_head(env, insn_idx, is_backedge(env, insn_idx),\n+\t\t\t\t\t\t widen_from, cur);\n+\t\t\tif (err)\n+\t\t\t\treturn err;\n+\t\t}\n+\t}\n+\n \tif (!env-\u003ebpf_capable \u0026\u0026 states_cnt \u003e BPF_COMPLEXITY_LIMIT_STATES)\n \t\treturn 0;\n \ndiff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c\nindex a7c9e2d8965d5..871aa45031d61 100644\n--- a/kernel/bpf/verifier.c\n+++ b/kernel/bpf/verifier.c\n@@ -1733,6 +1733,7 @@ int bpf_copy_verifier_state(struct bpf_verifier_state *dst_state,\n \tdst_state-\u003edfs_depth = src-\u003edfs_depth;\n \tdst_state-\u003ecallback_unroll_depth = src-\u003ecallback_unroll_depth;\n \tdst_state-\u003emay_goto_depth = src-\u003emay_goto_depth;\n+\tdst_state-\u003eloop_passes = src-\u003eloop_passes;\n \tdst_state-\u003eequal_state = src-\u003eequal_state;\n \tfor (i = 0; i \u003c= src-\u003ecurframe; i++) {\n \t\tdst = dst_state-\u003eframe[i];\n@@ -2094,9 +2095,71 @@ static struct cnum64 cnum64_from_tnum(struct tnum tnum)\n \t\treturn cnum64_from_urange(tnum.value, (tnum.value | tnum.mask));\n }\n \n+/* smallest member of @t that is \u003e= @x, wraps around to the smallest member of @t */\n+static u64 tnum_member_ge(struct tnum t, u64 x)\n+{\n+\tif ((x \u0026 ~t.mask) == t.value)\n+\t\treturn x;\n+\tif (x \u003e (t.value | t.mask))\n+\t\treturn t.value;\n+\treturn tnum_step(t, x);\n+}\n+\n+/* largest member of @t that is \u003c= @x, wraps around to the largest member of @t */\n+static u64 tnum_member_le(struct tnum t, u64 x)\n+{\n+\t/* members of 'tc' are bitwise complements of members of 't' */\n+\tstruct tnum tc = { .value = ~(t.value | t.mask), .mask = t.mask };\n+\n+\treturn ~tnum_member_ge(tc, ~x);\n+}\n+\n+/*\n+ * Move both ends of arc @c inwards to the nearest members of @t.\n+ * Values that are dropped are not members of @t.\n+ */\n+static struct cnum64 cnum64_tighten_by_tnum(struct cnum64 c, struct tnum t)\n+{\n+\tu64 lo, hi, dlo, dhi;\n+\n+\tif (cnum64_is_empty(c) || c.size == U64_MAX || !t.mask)\n+\t\treturn c;\n+\tlo = tnum_member_ge(t, c.base);\n+\tdlo = lo - c.base;\n+\tif (dlo \u003e c.size)\n+\t\treturn c;\n+\thi = tnum_member_le(t, c.base + c.size);\n+\tdhi = c.base + c.size - hi;\n+\tif (dhi \u003e c.size - dlo)\n+\t\treturn c;\n+\treturn (struct cnum64){ .base = lo, .size = c.size - dlo - dhi };\n+}\n+\n+static struct cnum32 cnum32_tighten_by_tnum(struct cnum32 c, struct tnum t)\n+{\n+\tstruct tnum tc;\n+\tu32 lo, hi, dlo, dhi;\n+\n+\tt = tnum_subreg(t);\n+\tif (cnum32_is_empty(c) || c.size == U32_MAX || !t.mask)\n+\t\treturn c;\n+\tlo = tnum_member_ge(t, c.base);\n+\tdlo = lo - c.base;\n+\tif (dlo \u003e c.size)\n+\t\treturn c;\n+\t/* complement within 32 bits */\n+\ttc = (struct tnum){ .value = (u32)~(t.value | t.mask), .mask = t.mask };\n+\thi = ~(u32)tnum_member_ge(tc, (u32)~(c.base + c.size));\n+\tdhi = c.base + c.size - hi;\n+\tif (dhi \u003e c.size - dlo)\n+\t\treturn c;\n+\treturn (struct cnum32){ .base = lo, .size = c.size - dlo - dhi };\n+}\n+\n static void __update_reg32_bounds(struct bpf_reg_state *reg)\n {\n \tcnum32_intersect_with(\u0026reg-\u003er32, cnum32_from_tnum(reg-\u003evar_off));\n+\treg-\u003er32 = cnum32_tighten_by_tnum(reg-\u003er32, reg-\u003evar_off);\n }\n \n static void __update_reg64_bounds(struct bpf_reg_state *reg)\n@@ -2105,6 +2168,7 @@ static void __update_reg64_bounds(struct bpf_reg_state *reg)\n \tbool umin_in_tnum;\n \n \tcnum64_intersect_with(\u0026reg-\u003er64, cnum64_from_tnum(reg-\u003evar_off));\n+\treg-\u003er64 = cnum64_tighten_by_tnum(reg-\u003er64, reg-\u003evar_off);\n \n \t/* Check if u64 and tnum overlap in a single value */\n \ttnum_next = tnum_step(reg-\u003evar_off, reg_umin(reg));\n@@ -7977,6 +8041,354 @@ static struct bpf_verifier_state *find_prev_entry(struct bpf_verifier_env *env,\n \treturn NULL;\n }\n \n+/* A constant that register @regno is compared with, -1 if any register. */\n+struct widen_thr {\n+\ts64 val;\n+\tint regno;\n+};\n+\n+struct bpf_widen_thrs {\n+\tu32 cnt;\n+\tstruct widen_thr thr[];\n+};\n+\n+/* passes around a loop that widen to constants the loop compares with */\n+#define WIDEN_THR_PASSES\t4\n+/* passes that widen to S32_MAX and the like, later ones drop the bound */\n+#define WIDEN_GEN_PASSES\t6\n+/* states at the loop head differ in something that can't be widened */\n+#define WIDEN_MAX_PASSES\t10\n+\n+static const struct widen_thr widen_generic[] = {\n+\t{ S32_MIN, -1 }, { 0, -1 }, { S32_MAX, -1 }, { U32_MAX, -1 },\n+};\n+\n+static int cmp_widen_thr(const void *a, const void *b)\n+{\n+\ts64 x = ((const struct widen_thr *)a)-\u003eval;\n+\ts64 y = ((const struct widen_thr *)b)-\u003eval;\n+\n+\treturn x \u003c y ? -1 : x \u003e y;\n+}\n+\n+static bool is_cmp_imm(const struct bpf_insn *insn)\n+{\n+\tu8 class = BPF_CLASS(insn-\u003ecode);\n+\tu8 op = BPF_OP(insn-\u003ecode);\n+\n+\tif (class != BPF_JMP \u0026\u0026 class != BPF_JMP32)\n+\t\treturn false;\n+\tif (BPF_SRC(insn-\u003ecode) != BPF_K)\n+\t\treturn false;\n+\treturn op != BPF_JA \u0026\u0026 op != BPF_CALL \u0026\u0026 op != BPF_EXIT \u0026\u0026 op != BPF_JCOND;\n+}\n+\n+/*\n+ * Sorted constants that registers are compared with in the SCC of @insn_idx.\n+ * A range that ends at one of them can be cut back by the exit test of\n+ * the loop, so that the state at the loop head stops growing.\n+ */\n+static const struct bpf_widen_thrs *scc_thresholds(struct bpf_verifier_env *env, int insn_idx)\n+{\n+\tstruct bpf_insn_aux_data *aux = env-\u003einsn_aux_data;\n+\tstruct bpf_insn *insns = env-\u003eprog-\u003einsnsi;\n+\tu32 scc = aux[insn_idx].scc;\n+\tstruct bpf_widen_thrs *thrs;\n+\tint i, d, n = 0;\n+\n+\tif (!scc)\n+\t\treturn NULL;\n+\tif (!env-\u003escc_thrs) {\n+\t\tenv-\u003escc_thrs = kvzalloc_objs(*env-\u003escc_thrs, env-\u003escc_cnt, GFP_KERNEL_ACCOUNT);\n+\t\tif (!env-\u003escc_thrs)\n+\t\t\treturn NULL;\n+\t}\n+\tif (env-\u003escc_thrs[scc])\n+\t\treturn env-\u003escc_thrs[scc];\n+\n+\tfor (i = 0; i \u003c env-\u003eprog-\u003elen; i++)\n+\t\tif (aux[i].scc == scc \u0026\u0026 is_cmp_imm(\u0026insns[i]))\n+\t\t\tn++;\n+\tthrs = kvzalloc(struct_size(thrs, thr, 3 * n), GFP_KERNEL_ACCOUNT);\n+\tif (!thrs)\n+\t\treturn NULL;\n+\tfor (i = 0; i \u003c env-\u003eprog-\u003elen; i++) {\n+\t\tif (aux[i].scc != scc || !is_cmp_imm(\u0026insns[i]))\n+\t\t\tcontinue;\n+\t\tfor (d = -1; d \u003c= 1; d++) {\n+\t\t\tthrs-\u003ethr[thrs-\u003ecnt].val = (s64)insns[i].imm + d;\n+\t\t\tthrs-\u003ethr[thrs-\u003ecnt++].regno = insns[i].dst_reg;\n+\t\t}\n+\t}\n+\tsort(thrs-\u003ethr, thrs-\u003ecnt, sizeof(thrs-\u003ethr[0]), cmp_widen_thr, NULL);\n+\tenv-\u003escc_thrs[scc] = thrs;\n+\treturn thrs;\n+}\n+\n+/*\n+ * Nearest constant in sorted @thr that is \u003e= @x if @up, \u003c= @x otherwise.\n+ * Constants that another register is compared with are skipped.\n+ */\n+static bool thr_nearest(const struct widen_thr *thr, u32 cnt, int regno, s64 x, bool up,\n+\t\t\ts64 *res)\n+{\n+\tbool found = false;\n+\tu32 i;\n+\n+\tfor (i = 0; i \u003c cnt; i++) {\n+\t\tif (regno \u003e= 0 \u0026\u0026 thr[i].regno \u003e= 0 \u0026\u0026 thr[i].regno != regno)\n+\t\t\tcontinue;\n+\t\tif (up \u0026\u0026 thr[i].val \u003e= x) {\n+\t\t\t*res = thr[i].val;\n+\t\t\treturn true;\n+\t\t}\n+\t\tif (!up \u0026\u0026 thr[i].val \u003c= x) {\n+\t\t\t*res = thr[i].val;\n+\t\t\tfound = true;\n+\t\t}\n+\t}\n+\treturn found;\n+}\n+\n+struct widen_ctx {\n+\tconst struct bpf_widen_thrs *thrs;\n+\tu32 passes;\n+\tint regno;\n+};\n+\n+/* Where to move the end @x of a range that keeps moving up or down. */\n+static bool widen_pick(const struct widen_ctx *w, s64 x, bool up, s64 *res)\n+{\n+\tbool found = false;\n+\ts64 t;\n+\n+\tif (w-\u003epasses \u003c= WIDEN_THR_PASSES \u0026\u0026 w-\u003ethrs \u0026\u0026\n+\t thr_nearest(w-\u003ethrs-\u003ethr, w-\u003ethrs-\u003ecnt, w-\u003eregno, x, up, \u0026t)) {\n+\t\t*res = t;\n+\t\tfound = true;\n+\t}\n+\tif (w-\u003epasses \u003c= WIDEN_GEN_PASSES \u0026\u0026\n+\t thr_nearest(widen_generic, ARRAY_SIZE(widen_generic), -1, x, up, \u0026t)) {\n+\t\t*res = !found ? t : up ? min(*res, t) : max(*res, t);\n+\t\tfound = true;\n+\t}\n+\treturn found;\n+}\n+\n+static s64 widen_smax(const struct widen_ctx *w, s64 x, s64 lim)\n+{\n+\ts64 t;\n+\n+\treturn widen_pick(w, x, true, \u0026t) \u0026\u0026 t \u003c= lim ? t : lim;\n+}\n+\n+static s64 widen_smin(const struct widen_ctx *w, s64 x, s64 lim)\n+{\n+\ts64 t;\n+\n+\treturn widen_pick(w, x, false, \u0026t) \u0026\u0026 t \u003e= lim ? t : lim;\n+}\n+\n+static u64 widen_umax(const struct widen_ctx *w, u64 x, u64 lim)\n+{\n+\ts64 t;\n+\n+\tif (x \u003e S64_MAX || !widen_pick(w, x, true, \u0026t) || (u64)t \u003e lim)\n+\t\treturn lim;\n+\treturn t;\n+}\n+\n+static u64 widen_umin(const struct widen_ctx *w, u64 x)\n+{\n+\ts64 t;\n+\n+\tif (!widen_pick(w, min_t(u64, x, S64_MAX), false, \u0026t) || t \u003c 0)\n+\t\treturn 0;\n+\treturn t;\n+}\n+\n+/*\n+ * @old is the state of a register at the loop head, @cur is its state after\n+ * a trip around the loop. If @cur has values that @old doesn't have make @cur\n+ * a guess of all the values the register can have at the loop head: both\n+ * @old and @cur, and where an end of the range moved it is moved further,\n+ * to the nearest constant the loop compares the register with.\n+ * Whether the guess is good is seen on the next trip: the state that comes\n+ * back has to be within it.\n+ */\n+static void widen_reg(const struct widen_ctx *w, const struct bpf_reg_state *old,\n+\t\t struct bpf_reg_state *cur)\n+{\n+\tu64 umin, umax, low;\n+\tu32 u32_min, u32_max;\n+\ts32 s32_min, s32_max;\n+\ts64 smin, smax;\n+\tstruct tnum t;\n+\n+\tif (old-\u003etype != SCALAR_VALUE || cur-\u003etype != SCALAR_VALUE)\n+\t\treturn;\n+\tif (cnum64_is_subset(old-\u003er64, cur-\u003er64) \u0026\u0026 cnum32_is_subset(old-\u003er32, cur-\u003er32) \u0026\u0026\n+\t tnum_in(old-\u003evar_off, cur-\u003evar_off))\n+\t\treturn;\n+\n+\tumin = min(reg_umin(old), reg_umin(cur));\n+\tumax = max(reg_umax(old), reg_umax(cur));\n+\tsmin = min(reg_smin(old), reg_smin(cur));\n+\tsmax = max(reg_smax(old), reg_smax(cur));\n+\tu32_min = min(reg_u32_min(old), reg_u32_min(cur));\n+\tu32_max = max(reg_u32_max(old), reg_u32_max(cur));\n+\ts32_min = min(reg_s32_min(old), reg_s32_min(cur));\n+\ts32_max = max(reg_s32_max(old), reg_s32_max(cur));\n+\n+\tif (reg_umin(cur) \u003c reg_umin(old))\n+\t\tumin = widen_umin(w, umin);\n+\tif (reg_umax(cur) \u003e reg_umax(old))\n+\t\tumax = widen_umax(w, umax, U64_MAX);\n+\tif (reg_smin(cur) \u003c reg_smin(old))\n+\t\tsmin = widen_smin(w, smin, S64_MIN);\n+\tif (reg_smax(cur) \u003e reg_smax(old))\n+\t\tsmax = widen_smax(w, smax, S64_MAX);\n+\tif (reg_u32_min(cur) \u003c reg_u32_min(old))\n+\t\tu32_min = widen_umin(w, u32_min);\n+\tif (reg_u32_max(cur) \u003e reg_u32_max(old))\n+\t\tu32_max = widen_umax(w, u32_max, U32_MAX);\n+\tif (reg_s32_min(cur) \u003c reg_s32_min(old))\n+\t\ts32_min = widen_smin(w, s32_min, S32_MIN);\n+\tif (reg_s32_max(cur) \u003e reg_s32_max(old))\n+\t\ts32_max = widen_smax(w, s32_max, S32_MAX);\n+\n+\t/* low bits that are the same in all values seen so far are kept, e.g. alignment */\n+\tt = tnum_union(old-\u003evar_off, cur-\u003evar_off);\n+\tlow = t.mask ? BIT_ULL(__ffs64(t.mask)) - 1 : 0;\n+\tcur-\u003evar_off = (struct tnum){ .value = t.value \u0026 low, .mask = ~low };\n+\tcur-\u003er64 = cnum64_intersect(cnum64_from_urange(umin, umax),\n+\t\t\t\t cnum64_from_srange(smin, smax));\n+\tcur-\u003er32 = cnum32_intersect(cnum32_from_urange(u32_min, u32_max),\n+\t\t\t\t cnum32_from_srange(s32_min, s32_max));\n+\tcur-\u003eid = 0;\n+\tcur-\u003edelta = 0;\n+\treg_bounds_sync(cur);\n+}\n+\n+bool bpf_same_loop(struct bpf_verifier_state *old, struct bpf_verifier_state *cur)\n+{\n+\treturn old-\u003especulative == cur-\u003especulative \u0026\u0026 same_callsites(old, cur);\n+}\n+\n+/*\n+ * @cur came to loop head @insn_idx and is not within @old, the state that\n+ * went around the loop. Widen scalars of @cur, so that the walk goes around\n+ * the loop with a state that stands for many iterations, see widen_reg().\n+ * Everything else is left as is. If that is what differs the states never\n+ * converge and the walk is given up after a few trips.\n+ */\n+int bpf_widen_loop_head(struct bpf_verifier_env *env, int insn_idx, bool backedge,\n+\t\t\tstruct bpf_verifier_state *old, struct bpf_verifier_state *cur)\n+{\n+\t/* @old is of an earlier run of the loop if @cur just entered it */\n+\tu32 passes = backedge ? old-\u003eloop_passes + 1 : 1;\n+\tstruct widen_ctx w = { scc_thresholds(env, insn_idx), passes };\n+\tstruct bpf_func_state *fold, *fcur;\n+\tint i, fr, num_slots;\n+\n+\tenv-\u003ewiden_used = true;\n+\tif (passes \u003e WIDEN_MAX_PASSES) {\n+\t\tverbose(env, \"states at loop head %d don't converge\\n\", insn_idx);\n+\t\treturn -E2BIG;\n+\t}\n+\n+\tfor (fr = 0; fr \u003c= cur-\u003ecurframe; fr++) {\n+\t\tfold = old-\u003eframe[fr];\n+\t\tfcur = cur-\u003eframe[fr];\n+\n+\t\tfor (i = 0; i \u003c BPF_REG_FP; i++) {\n+\t\t\t/* registers of callers are not the ones the loop compares */\n+\t\t\tw.regno = fr == cur-\u003ecurframe ? i : -1;\n+\t\t\twiden_reg(\u0026w, \u0026fold-\u003eregs[i], \u0026fcur-\u003eregs[i]);\n+\t\t}\n+\n+\t\tw.regno = -1;\n+\t\tnum_slots = min(fold-\u003eallocated_stack, fcur-\u003eallocated_stack) / BPF_REG_SIZE;\n+\t\tfor (i = 0; i \u003c num_slots; i++) {\n+\t\t\tif (!bpf_is_spilled_reg(\u0026fold-\u003estack[i]) ||\n+\t\t\t !bpf_is_spilled_reg(\u0026fcur-\u003estack[i]))\n+\t\t\t\tcontinue;\n+\t\t\twiden_reg(\u0026w, \u0026fold-\u003estack[i].spilled_ptr, \u0026fcur-\u003estack[i].spilled_ptr);\n+\t\t}\n+\t}\n+\tcur-\u003eloop_passes = passes;\n+\tif (env-\u003elog.level \u0026 BPF_LOG_LEVEL2)\n+\t\tverbose(env, \"loop head %d widened, pass %u\\n\", insn_idx, passes);\n+\treturn 0;\n+}\n+\n+static bool program_returns_void(struct bpf_verifier_env *env);\n+static bool return_retval_range(struct bpf_verifier_env *env, struct bpf_retval_range *range);\n+\n+/* Why bpf_throw() cannot be called in @st, NULL if it can. */\n+static const char *cannot_throw(struct bpf_verifier_env *env, struct bpf_verifier_state *st)\n+{\n+\tstruct bpf_retval_range range;\n+\tstruct bpf_func_state *frame;\n+\tint i;\n+\n+\tif (!env-\u003eprog-\u003ejit_requested || !bpf_jit_supports_exceptions())\n+\t\treturn \"JIT does not support exceptions\";\n+\tfor (i = 0; i \u003c st-\u003eacquired_refs; i++)\n+\t\tif (st-\u003erefs[i].type == REF_TYPE_PTR)\n+\t\t\treturn \"reference is held\";\n+\tif (st-\u003eactive_locks || st-\u003eactive_irq_id || st-\u003eactive_rcu_locks ||\n+\t st-\u003eactive_preempt_locks)\n+\t\treturn \"lock is held\";\n+\tfor (i = 0; i \u003c= st-\u003ecurframe; i++) {\n+\t\tframe = st-\u003eframe[i];\n+\t\tif (frame-\u003ein_callback_fn || frame-\u003ein_async_callback_fn ||\n+\t\t frame-\u003ein_exception_callback_fn)\n+\t\t\treturn \"in callback\";\n+\t}\n+\t/* callers of the global function were not told that it can throw */\n+\tif (st-\u003eframe[0]-\u003esubprogno \u0026\u0026 !subprog_info(env, st-\u003eframe[0]-\u003esubprogno)-\u003emight_throw)\n+\t\treturn \"in global function\";\n+\t/* default exception callback returns the cookie, that is 0 */\n+\tif (!env-\u003eexception_callback_subprog \u0026\u0026 !program_returns_void(env) \u0026\u0026\n+\t resolve_prog_type(env-\u003eprog) != BPF_PROG_TYPE_STRUCT_OPS \u0026\u0026\n+\t return_retval_range(env, \u0026range) \u0026\u0026 (range.minval \u003e 0 || range.maxval \u003c 0))\n+\t\treturn \"0 is not a valid return value\";\n+\treturn NULL;\n+}\n+\n+/*\n+ * The walk went over the back-edge of env-\u003eprev_insn_idx and nothing bounds\n+ * the number of trips. If the loop is not walked to the end may_goto that\n+ * ends in bpf_throw() is added to the back-edge, see commit_loop_guards().\n+ * Returns false when that cannot be done in state @cur.\n+ */\n+bool bpf_mark_loop_guard(struct bpf_verifier_env *env, struct bpf_verifier_state *cur)\n+{\n+\tstruct bpf_insn_aux_data *aux = \u0026env-\u003einsn_aux_data[env-\u003eprev_insn_idx];\n+\tstruct bpf_insn *insn = \u0026env-\u003eprog-\u003einsnsi[env-\u003eprev_insn_idx];\n+\tu8 class = BPF_CLASS(insn-\u003ecode);\n+\tu8 op = BPF_OP(insn-\u003ecode);\n+\tconst char *why;\n+\n+\twhy = cannot_throw(env, cur);\n+\tif ((class != BPF_JMP \u0026\u0026 class != BPF_JMP32) ||\n+\t op == BPF_CALL || op == BPF_EXIT || op == BPF_JCOND ||\n+\t (op == BPF_JA \u0026\u0026 BPF_SRC(insn-\u003ecode) == BPF_X))\n+\t\twhy = \"not a jump\";\n+\telse if (op != BPF_JA \u0026\u0026 aux-\u003ebackedge_ft \u0026\u0026 aux-\u003ebackedge_br)\n+\t\twhy = \"both edges are back-edges\";\n+\tif (why) {\n+\t\tif (env-\u003elog.level \u0026 BPF_LOG_LEVEL2)\n+\t\t\tverbose(env, \"cannot add may_goto to back-edge of insn %d: %s\\n\",\n+\t\t\t\tenv-\u003eprev_insn_idx, why);\n+\t\taux-\u003eguard_impossible = true;\n+\t\treturn false;\n+\t}\n+\taux-\u003eguard_pending = true;\n+\treturn true;\n+}\n+\n /*\n * Check if scalar registers are exact for the purpose of not widening.\n * More lenient than regs_exact()\n@@ -18847,6 +19259,21 @@ static int do_check_insn(struct bpf_verifier_env *env, bool *do_print_state)\n \treturn -EFAULT;\n }\n \n+/* Did the jump at @prev take the walk out of the loop @prev is in? */\n+static bool left_loop(struct bpf_verifier_env *env, int prev, int insn_idx)\n+{\n+\tstruct bpf_insn_aux_data *aux = env-\u003einsn_aux_data;\n+\tstruct bpf_insn *insn;\n+\n+\tif (prev \u003c 0 || prev \u003e= env-\u003eprog-\u003elen || !aux[prev].scc ||\n+\t aux[prev].scc == aux[insn_idx].scc)\n+\t\treturn false;\n+\t/* the callee is not in SCC of the call, the insn after the call is */\n+\tinsn = \u0026env-\u003eprog-\u003einsnsi[prev];\n+\treturn !((BPF_CLASS(insn-\u003ecode) == BPF_JMP || BPF_CLASS(insn-\u003ecode) == BPF_JMP32) \u0026\u0026\n+\t\t BPF_OP(insn-\u003ecode) == BPF_CALL);\n+}\n+\n static int do_check(struct bpf_verifier_env *env)\n {\n \tbool pop_log = !(env-\u003elog.level \u0026 BPF_LOG_LEVEL2);\n@@ -18885,6 +19312,8 @@ static int do_check(struct bpf_verifier_env *env)\n \n \t\tstate-\u003elast_insn_idx = env-\u003eprev_insn_idx;\n \t\tstate-\u003einsn_idx = env-\u003einsn_idx;\n+\t\tif (env-\u003ewiden_loops \u0026\u0026 left_loop(env, prev_insn_idx, env-\u003einsn_idx))\n+\t\t\tbpf_scc_mark_exit(env, state, prev_insn_idx);\n \t\t/*\n \t\t * Record the incoming edge so active and queued paths use the same\n \t\t * branch-recording path. A zero-offset conditional has identical\n@@ -18907,7 +19336,9 @@ static int do_check(struct bpf_verifier_env *env)\n \t\t\t}\n \t\t}\n \n-\t\tif (bpf_is_prune_point(env, env-\u003einsn_idx)) {\n+\t\t/* loop heads are where states are widened, all of them have to be looked at */\n+\t\tif (bpf_is_prune_point(env, env-\u003einsn_idx) ||\n+\t\t (env-\u003ewiden_loops \u0026\u0026 insn_aux-\u003eloop_head)) {\n \t\t\terr = bpf_is_state_visited(env, env-\u003einsn_idx);\n \t\t\tif (err \u003c 0)\n \t\t\t\treturn err;\n@@ -19011,6 +19442,9 @@ static int do_check(struct bpf_verifier_env *env)\n \t\t} else if (err \u003c 0) {\n \t\t\treturn err;\n \t\t} else if (err == PROCESS_BPF_EXIT) {\n+\t\t\t/* exit or bpf_throw() inside of a loop */\n+\t\t\tif (env-\u003ewiden_loops)\n+\t\t\t\tbpf_scc_mark_exit(env, state, env-\u003einsn_idx);\n \t\t\tgoto process_bpf_exit;\n \t\t} else if (err == INSN_IDX_UPDATED) {\n \t\t} else if (err == 0) {\n@@ -20102,6 +20536,122 @@ static int do_check_common(struct bpf_verifier_env *env, int subprog)\n \treturn ret;\n }\n \n+/* What a walk changes outside of verifier states and per insn data. */\n+struct walk_snapshot {\n+\tstruct bpf_insn_aux_data *insn_aux;\n+\tstruct bpf_func_info_aux *func_aux;\n+\tstruct bpf_subprog_info *subprogs;\n+\tstruct bpf_prog *prog;\n+\tu64 log_pos, diag_pos;\n+\tu32 insn_processed, prev_insn_processed;\n+\tu32 jmps_processed, prev_jmps_processed;\n+\tu32 total_states, peak_states, max_states_per_insn, longest_mark_read_walk;\n+\tu32 explored_states_size, free_list_size, num_backedges;\n+\tu32 id_gen, pass_cnt, max_stack_depth;\n+\tu32 max_ctx_offset, max_pkt_offset, max_tp_access, max_rdonly_access, max_rdwr_access;\n+\tbool seen_direct_write, seen_exception, explore_alu_limits, tail_call_reachable;\n+\tvoid *arena;\n+};\n+\n+static void walk_snapshot_free(struct walk_snapshot *s)\n+{\n+\tkvfree(s-\u003einsn_aux);\n+\tkvfree(s-\u003efunc_aux);\n+\tkvfree(s-\u003esubprogs);\n+\tkfree(s-\u003eprog);\n+}\n+\n+static size_t func_aux_size(struct bpf_verifier_env *env)\n+{\n+\treturn array_size(env-\u003eprog-\u003eaux-\u003efunc_info_cnt, sizeof(*env-\u003eprog-\u003eaux-\u003efunc_info_aux));\n+}\n+\n+static int walk_snapshot_save(struct bpf_verifier_env *env, struct walk_snapshot *s)\n+{\n+\tstruct bpf_prog_aux *aux = env-\u003eprog-\u003eaux;\n+\n+\tmemset(s, 0, sizeof(*s));\n+\ts-\u003einsn_aux = kvmemdup(env-\u003einsn_aux_data,\n+\t\t\t array_size(env-\u003eprog-\u003elen, sizeof(*env-\u003einsn_aux_data)),\n+\t\t\t GFP_KERNEL_ACCOUNT);\n+\ts-\u003esubprogs = kvmemdup(env-\u003esubprog_info, sizeof(env-\u003esubprog_info), GFP_KERNEL_ACCOUNT);\n+\t/* flags of the program, not its insns */\n+\ts-\u003eprog = kmemdup(env-\u003eprog, offsetof(struct bpf_prog, insnsi), GFP_KERNEL_ACCOUNT);\n+\tif (aux-\u003efunc_info_aux)\n+\t\ts-\u003efunc_aux = kvmemdup(aux-\u003efunc_info_aux, func_aux_size(env), GFP_KERNEL_ACCOUNT);\n+\tif (!s-\u003einsn_aux || !s-\u003esubprogs || !s-\u003eprog || (aux-\u003efunc_info_aux \u0026\u0026 !s-\u003efunc_aux)) {\n+\t\twalk_snapshot_free(s);\n+\t\treturn -ENOMEM;\n+\t}\n+\ts-\u003elog_pos = env-\u003elog.end_pos;\n+\ts-\u003ediag_pos = bpf_diag_event_log_save(env);\n+\ts-\u003einsn_processed = env-\u003einsn_processed;\n+\ts-\u003eprev_insn_processed = env-\u003eprev_insn_processed;\n+\ts-\u003ejmps_processed = env-\u003ejmps_processed;\n+\ts-\u003eprev_jmps_processed = env-\u003eprev_jmps_processed;\n+\ts-\u003etotal_states = env-\u003etotal_states;\n+\ts-\u003epeak_states = env-\u003epeak_states;\n+\ts-\u003emax_states_per_insn = env-\u003emax_states_per_insn;\n+\ts-\u003elongest_mark_read_walk = env-\u003elongest_mark_read_walk;\n+\ts-\u003eexplored_states_size = env-\u003eexplored_states_size;\n+\ts-\u003efree_list_size = env-\u003efree_list_size;\n+\ts-\u003enum_backedges = env-\u003enum_backedges;\n+\ts-\u003eid_gen = env-\u003eid_gen;\n+\ts-\u003epass_cnt = env-\u003epass_cnt;\n+\ts-\u003emax_stack_depth = env-\u003emax_stack_depth;\n+\ts-\u003eseen_direct_write = env-\u003eseen_direct_write;\n+\ts-\u003eseen_exception = env-\u003eseen_exception;\n+\ts-\u003eexplore_alu_limits = env-\u003eexplore_alu_limits;\n+\ts-\u003emax_ctx_offset = aux-\u003emax_ctx_offset;\n+\ts-\u003emax_pkt_offset = aux-\u003emax_pkt_offset;\n+\ts-\u003emax_tp_access = aux-\u003emax_tp_access;\n+\ts-\u003emax_rdonly_access = aux-\u003emax_rdonly_access;\n+\ts-\u003emax_rdwr_access = aux-\u003emax_rdwr_access;\n+\ts-\u003etail_call_reachable = aux-\u003etail_call_reachable;\n+\ts-\u003earena = aux-\u003earena;\n+\treturn 0;\n+}\n+\n+static void walk_snapshot_restore(struct bpf_verifier_env *env, struct walk_snapshot *s)\n+{\n+\tstruct bpf_prog_aux *aux = env-\u003eprog-\u003eaux;\n+\n+\tmemcpy(env-\u003einsn_aux_data, s-\u003einsn_aux,\n+\t array_size(env-\u003eprog-\u003elen, sizeof(*env-\u003einsn_aux_data)));\n+\tmemcpy(env-\u003esubprog_info, s-\u003esubprogs, sizeof(env-\u003esubprog_info));\n+\tmemcpy(env-\u003eprog, s-\u003eprog, offsetof(struct bpf_prog, insnsi));\n+\tif (s-\u003efunc_aux)\n+\t\tmemcpy(aux-\u003efunc_info_aux, s-\u003efunc_aux, func_aux_size(env));\n+\tenv-\u003einsn_wasted += env-\u003einsn_processed - s-\u003einsn_processed;\n+\tenv-\u003einsn_processed = s-\u003einsn_processed;\n+\tenv-\u003eprev_insn_processed = s-\u003eprev_insn_processed;\n+\tenv-\u003ejmps_processed = s-\u003ejmps_processed;\n+\tenv-\u003eprev_jmps_processed = s-\u003eprev_jmps_processed;\n+\tenv-\u003etotal_states = s-\u003etotal_states;\n+\tenv-\u003epeak_states = s-\u003epeak_states;\n+\tenv-\u003emax_states_per_insn = s-\u003emax_states_per_insn;\n+\tenv-\u003elongest_mark_read_walk = s-\u003elongest_mark_read_walk;\n+\tenv-\u003eexplored_states_size = s-\u003eexplored_states_size;\n+\tenv-\u003efree_list_size = s-\u003efree_list_size;\n+\tenv-\u003enum_backedges = s-\u003enum_backedges;\n+\tenv-\u003eid_gen = s-\u003eid_gen;\n+\tenv-\u003epass_cnt = s-\u003epass_cnt;\n+\tenv-\u003emax_stack_depth = s-\u003emax_stack_depth;\n+\tenv-\u003eseen_direct_write = s-\u003eseen_direct_write;\n+\tenv-\u003eseen_exception = s-\u003eseen_exception;\n+\tenv-\u003eexplore_alu_limits = s-\u003eexplore_alu_limits;\n+\taux-\u003emax_ctx_offset = s-\u003emax_ctx_offset;\n+\taux-\u003emax_pkt_offset = s-\u003emax_pkt_offset;\n+\taux-\u003emax_tp_access = s-\u003emax_tp_access;\n+\taux-\u003emax_rdonly_access = s-\u003emax_rdonly_access;\n+\taux-\u003emax_rdwr_access = s-\u003emax_rdwr_access;\n+\taux-\u003etail_call_reachable = s-\u003etail_call_reachable;\n+\taux-\u003earena = s-\u003earena;\n+\tif (!(env-\u003elog.level \u0026 BPF_LOG_LEVEL2))\n+\t\tbpf_vlog_reset(\u0026env-\u003elog, s-\u003elog_pos);\n+\tbpf_diag_event_log_restore(env, s-\u003ediag_pos);\n+}\n+\n /* Lazily verify all global functions based on their BTF, if they are called\n * from main BPF program or any of subprograms transitively.\n * BPF global subprogs called from dead code are not validated.\n@@ -20183,6 +20733,51 @@ static int do_check_main(struct bpf_verifier_env *env)\n \treturn ret;\n }\n \n+/*\n+ * Walk the program with loops widened first. It is much less work when it\n+ * succeeds. If it fails the reason can be the precision that widening gave\n+ * up. Then undo everything that walk did, so that the walk of every\n+ * iteration that follows can't tell that it is not the first one.\n+ * It is all or nothing for the main program and global functions, because\n+ * may_goto added to a loop of a static function is there for all callers.\n+ */\n+static int do_check_prog(struct bpf_verifier_env *env)\n+{\n+\tstruct walk_snapshot snap;\n+\tint ret;\n+\n+\t/* no loops without bpf_capable, the driver of an offloaded prog sees every insn visit */\n+\tif (!env-\u003ebpf_capable || env-\u003escc_cnt \u003c= 1 || bpf_prog_is_offloaded(env-\u003eprog-\u003eaux)) {\n+\t\tret = do_check_main(env);\n+\t\treturn ret ?: do_check_subprogs(env);\n+\t}\n+\n+\tenv-\u003escc_converged = kvzalloc_objs(*env-\u003escc_converged, BITS_TO_LONGS(env-\u003escc_cnt),\n+\t\t\t\t\t GFP_KERNEL_ACCOUNT);\n+\tif (!env-\u003escc_converged)\n+\t\treturn -ENOMEM;\n+\tret = walk_snapshot_save(env, \u0026snap);\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tenv-\u003ewiden_loops = true;\n+\tenv-\u003ewiden_used = false;\n+\tret = do_check_main(env);\n+\tret = ret ?: do_check_subprogs(env);\n+\tif (!ret \u0026\u0026 env-\u003ewiden_used)\n+\t\tret = bpf_commit_loop_guards(env);\n+\tenv-\u003ewiden_loops = false;\n+\tif (ret \u0026\u0026 ret != -ENOMEM \u0026\u0026 ret != -EAGAIN \u0026\u0026 ret != -EFAULT \u0026\u0026 env-\u003ewiden_used) {\n+\t\twalk_snapshot_restore(env, \u0026snap);\n+\t\tif (env-\u003elog.level \u0026 BPF_LOG_LEVEL)\n+\t\t\tverbose(env, \"walk with widened loops failed, walking every iteration\\n\");\n+\t\tret = do_check_main(env);\n+\t\tret = ret ?: do_check_subprogs(env);\n+\t}\n+\twalk_snapshot_free(\u0026snap);\n+\treturn ret;\n+}\n+\n static void print_verification_stats(struct bpf_verifier_env *env)\n {\n \t/* Skip over hidden subprogs which are not verified. */\n@@ -20211,6 +20806,9 @@ static void print_verification_stats(struct bpf_verifier_env *env)\n \t\tenv-\u003einsn_processed, BPF_COMPLEXITY_LIMIT_INSNS,\n \t\tenv-\u003emax_states_per_insn, env-\u003etotal_states,\n \t\tenv-\u003epeak_states, env-\u003elongest_mark_read_walk);\n+\tif (env-\u003einsn_wasted)\n+\t\tverbose(env, \"walks with widened loops that failed processed %d insns\\n\",\n+\t\t\tenv-\u003einsn_wasted);\n }\n \n int bpf_prog_ctx_arg_info_init(struct bpf_prog *prog,\n@@ -21853,8 +22451,7 @@ int bpf_check(struct bpf_prog **prog, union bpf_attr *attr, bpfptr_t uattr,\n \tif (ret \u003c 0)\n \t\tgoto skip_full_check;\n \n-\tret = do_check_main(env);\n-\tret = ret ?: do_check_subprogs(env);\n+\tret = do_check_prog(env);\n \n \tif (ret == 0 \u0026\u0026 bpf_prog_is_offloaded(env-\u003eprog-\u003eaux))\n \t\tret = bpf_prog_offload_finalize(env);\n@@ -21996,6 +22593,12 @@ int bpf_check(struct bpf_prog **prog, union bpf_attr *attr, bpfptr_t uattr,\n \tbpf_stack_liveness_free(env);\n \tkvfree(env-\u003ecfg.insn_postorder);\n \tkvfree(env-\u003escc_info);\n+\tkvfree(env-\u003escc_converged);\n+\tif (env-\u003escc_thrs) {\n+\t\tfor (i = 0; i \u003c env-\u003escc_cnt; i++)\n+\t\t\tkvfree(env-\u003escc_thrs[i]);\n+\t\tkvfree(env-\u003escc_thrs);\n+\t}\n \tkvfree(env-\u003esucc);\n \tkvfree(env-\u003egotox_tmp_buf);\n \tbpf_diag_free(env);\ndiff --git a/tools/testing/selftests/bpf/prog_tests/bpf_verif_scale.c b/tools/testing/selftests/bpf/prog_tests/bpf_verif_scale.c\nindex 902a70d5afeb6..2dc37090d7a4f 100644\n--- a/tools/testing/selftests/bpf/prog_tests/bpf_verif_scale.c\n+++ b/tools/testing/selftests/bpf/prog_tests/bpf_verif_scale.c\n@@ -154,9 +154,9 @@ void test_verif_scale_loop2()\n \tscale_test(\"loop2.bpf.o\", BPF_PROG_TYPE_RAW_TRACEPOINT, false);\n }\n \n-void test_verif_scale_loop3_fail()\n+void test_verif_scale_loop3()\n {\n-\tscale_test(\"loop3.bpf.o\", BPF_PROG_TYPE_RAW_TRACEPOINT, true /* fails */);\n+\tscale_test(\"loop3.bpf.o\", BPF_PROG_TYPE_RAW_TRACEPOINT, false);\n }\n \n void test_verif_scale_loop4()\ndiff --git a/tools/testing/selftests/bpf/prog_tests/verifier.c b/tools/testing/selftests/bpf/prog_tests/verifier.c\nindex 4f1e1c1cd5ab3..5bed8f9587772 100644\n--- a/tools/testing/selftests/bpf/prog_tests/verifier.c\n+++ b/tools/testing/selftests/bpf/prog_tests/verifier.c\n@@ -65,6 +65,7 @@\n #include \"verifier_live_stack.skel.h\"\n #include \"verifier_liveness_exp.skel.h\"\n #include \"verifier_load_acquire.skel.h\"\n+#include \"verifier_loop_widen.skel.h\"\n #include \"verifier_loops1.skel.h\"\n #include \"verifier_lwt.skel.h\"\n #include \"verifier_map_in_map.skel.h\"\n@@ -234,6 +235,7 @@ void test_verifier_leak_ptr(void) { RUN(verifier_leak_ptr); }\n void test_verifier_linked_scalars(void) { RUN(verifier_linked_scalars); }\n void test_verifier_live_stack(void) { RUN(verifier_live_stack); }\n void test_verifier_liveness_exp(void) { RUN(verifier_liveness_exp); }\n+void test_verifier_loop_widen(void) { RUN(verifier_loop_widen); }\n void test_verifier_loops1(void) { RUN(verifier_loops1); }\n void test_verifier_lwt(void) { RUN(verifier_lwt); }\n void test_verifier_map_in_map(void) { RUN(verifier_map_in_map); }\ndiff --git a/tools/testing/selftests/bpf/progs/verifier_cfg.c b/tools/testing/selftests/bpf/progs/verifier_cfg.c\nindex 3c3bb03e8217a..700eadf5d430a 100644\n--- a/tools/testing/selftests/bpf/progs/verifier_cfg.c\n+++ b/tools/testing/selftests/bpf/progs/verifier_cfg.c\n@@ -98,8 +98,8 @@ l0_%=:\tr1 = r0;\t\t\t\t\t\\\n \n SEC(\"socket\")\n __description(\"conditional loop\")\n-__failure __msg(\"infinite loop detected\")\n-__msg_unpriv(\"back-edge\")\n+__success\n+__failure_unpriv __msg_unpriv(\"back-edge\")\n __naked void conditional_loop(void)\n {\n \tasm volatile (\"\t\t\t\t\t\\\ndiff --git a/tools/testing/selftests/bpf/progs/verifier_loop_widen.c b/tools/testing/selftests/bpf/progs/verifier_loop_widen.c\nnew file mode 100644\nindex 0000000000000..4bdfc198bfaa8\n--- /dev/null\n+++ b/tools/testing/selftests/bpf/progs/verifier_loop_widen.c\n@@ -0,0 +1,344 @@\n+// SPDX-License-Identifier: GPL-2.0\n+/* Loops that are verified by widening the state at the loop head. */\n+\n+#include \u003clinux/bpf.h\u003e\n+#include \u003cbpf/bpf_helpers.h\u003e\n+#include \"bpf_misc.h\"\n+\n+struct small_val {\n+\tchar buf[400];\n+};\n+\n+struct big_val {\n+\tchar buf[1000000];\n+};\n+\n+struct {\n+\t__uint(type, BPF_MAP_TYPE_ARRAY);\n+\t__uint(max_entries, 1);\n+\t__type(key, int);\n+\t__type(value, struct small_val);\n+} map_small SEC(\".maps\");\n+\n+struct {\n+\t__uint(type, BPF_MAP_TYPE_ARRAY);\n+\t__uint(max_entries, 1);\n+\t__type(key, int);\n+\t__type(value, struct big_val);\n+} map_big SEC(\".maps\");\n+\n+struct {\n+\t__uint(type, BPF_MAP_TYPE_RINGBUF);\n+\t__uint(max_entries, 4096);\n+} ringbuf SEC(\".maps\");\n+\n+#define LOOKUP(map)\t\t\t\t\t\\\n+\t\"r1 = 0;\"\t\t\t\t\t\\\n+\t\"*(u64*)(r10 - 8) = r1;\"\t\t\t\\\n+\t\"r2 = r10;\"\t\t\t\t\t\\\n+\t\"r2 += -8;\"\t\t\t\t\t\\\n+\t\"r1 = %[\" #map \"] ll;\"\t\t\t\t\\\n+\t\"call %[bpf_map_lookup_elem];\"\t\t\t\\\n+\t\"if r0 == 0 goto l_exit_%=;\"\t\t\t\\\n+\t\"r7 = r0;\"\n+\n+/* counter steps by 4 and the loop is left on '!=', 100 trips */\n+SEC(\"socket\")\n+__success\n+__naked void stride4_ne_100(void)\n+{\n+\tasm volatile (\n+\tLOOKUP(map_small)\n+\t\"r6 = 0;\"\n+\"l_loop_%=:\"\n+\t\"r1 = r7;\"\n+\t\"r1 += r6;\"\n+\t\"r0 = *(u32*)(r1 + 0);\"\n+\t\"r6 += 4;\"\n+\t\"if r6 != 400 goto l_loop_%=;\"\n+\"l_exit_%=:\"\n+\t\"r0 = 0;\"\n+\t\"exit;\"\n+\t:\n+\t: __imm(bpf_map_lookup_elem), __imm_addr(map_small)\n+\t: __clobber_all);\n+}\n+\n+/* same loop, 250000 trips, too many to walk every one of them */\n+SEC(\"socket\")\n+__success\n+__naked void stride4_ne_250k(void)\n+{\n+\tasm volatile (\n+\tLOOKUP(map_big)\n+\t\"r6 = 0;\"\n+\"l_loop_%=:\"\n+\t\"r1 = r7;\"\n+\t\"r1 += r6;\"\n+\t\"r0 = *(u32*)(r1 + 0);\"\n+\t\"r6 += 4;\"\n+\t\"if r6 != 1000000 goto l_loop_%=;\"\n+\"l_exit_%=:\"\n+\t\"r0 = 0;\"\n+\t\"exit;\"\n+\t:\n+\t: __imm(bpf_map_lookup_elem), __imm_addr(map_big)\n+\t: __clobber_all);\n+}\n+\n+/* 8 byte stride, 32-bit counter */\n+SEC(\"socket\")\n+__success\n+__naked void stride8_ne_w_125k(void)\n+{\n+\tasm volatile (\n+\tLOOKUP(map_big)\n+\t\"w6 = 0;\"\n+\"l_loop_%=:\"\n+\t\"r1 = r7;\"\n+\t\"r1 += r6;\"\n+\t\"r0 = *(u64*)(r1 + 0);\"\n+\t\"w6 += 8;\"\n+\t\"if w6 != 1000000 goto l_loop_%=;\"\n+\"l_exit_%=:\"\n+\t\"r0 = 0;\"\n+\t\"exit;\"\n+\t:\n+\t: __imm(bpf_map_lookup_elem), __imm_addr(map_big)\n+\t: __clobber_all);\n+}\n+\n+/* counts down by 4 to zero */\n+SEC(\"socket\")\n+__success\n+__naked void stride4_down_250k(void)\n+{\n+\tasm volatile (\n+\tLOOKUP(map_big)\n+\t\"r6 = 1000000;\"\n+\"l_loop_%=:\"\n+\t\"r6 += -4;\"\n+\t\"r1 = r7;\"\n+\t\"r1 += r6;\"\n+\t\"r0 = *(u32*)(r1 + 0);\"\n+\t\"if r6 != 0 goto l_loop_%=;\"\n+\"l_exit_%=:\"\n+\t\"r0 = 0;\"\n+\t\"exit;\"\n+\t:\n+\t: __imm(bpf_map_lookup_elem), __imm_addr(map_big)\n+\t: __clobber_all);\n+}\n+\n+/* step of 1 and '\u003c', no alignment to make use of */\n+SEC(\"socket\")\n+__success\n+__naked void stride1_lt_1m(void)\n+{\n+\tasm volatile (\n+\tLOOKUP(map_big)\n+\t\"r6 = 0;\"\n+\"l_loop_%=:\"\n+\t\"r1 = r7;\"\n+\t\"r1 += r6;\"\n+\t\"r0 = *(u8*)(r1 + 0);\"\n+\t\"r6 += 1;\"\n+\t\"if r6 \u003c 1000000 goto l_loop_%=;\"\n+\"l_exit_%=:\"\n+\t\"r0 = 0;\"\n+\t\"exit;\"\n+\t:\n+\t: __imm(bpf_map_lookup_elem), __imm_addr(map_big)\n+\t: __clobber_all);\n+}\n+\n+/* two loops, one in the other */\n+SEC(\"socket\")\n+__success\n+__naked void nested_stride4(void)\n+{\n+\tasm volatile (\n+\tLOOKUP(map_big)\n+\t\"r8 = 0;\"\n+\"l_outer_%=:\"\n+\t\"r6 = 0;\"\n+\"l_loop_%=:\"\n+\t\"r1 = r7;\"\n+\t\"r1 += r6;\"\n+\t\"r0 = *(u32*)(r1 + 0);\"\n+\t\"r6 += 4;\"\n+\t\"if r6 != 1000000 goto l_loop_%=;\"\n+\t\"r8 += 1;\"\n+\t\"if r8 != 1000 goto l_outer_%=;\"\n+\"l_exit_%=:\"\n+\t\"r0 = 0;\"\n+\t\"exit;\"\n+\t:\n+\t: __imm(bpf_map_lookup_elem), __imm_addr(map_big)\n+\t: __clobber_all);\n+}\n+\n+/* the last trip reads 4 bytes at offset 400 of 400 */\n+SEC(\"socket\")\n+__failure __msg(\"invalid access to map value\")\n+__naked void stride4_ne_one_too_many(void)\n+{\n+\tasm volatile (\n+\tLOOKUP(map_small)\n+\t\"r6 = 0;\"\n+\"l_loop_%=:\"\n+\t\"r1 = r7;\"\n+\t\"r1 += r6;\"\n+\t\"r0 = *(u32*)(r1 + 0);\"\n+\t\"r6 += 4;\"\n+\t\"if r6 != 404 goto l_loop_%=;\"\n+\"l_exit_%=:\"\n+\t\"r0 = 0;\"\n+\t\"exit;\"\n+\t:\n+\t: __imm(bpf_map_lookup_elem), __imm_addr(map_small)\n+\t: __clobber_all);\n+}\n+\n+/* same with too many trips to walk */\n+SEC(\"socket\")\n+__failure __msg(\"BPF program is too large\")\n+__naked void stride4_ne_250k_one_too_many(void)\n+{\n+\tasm volatile (\n+\tLOOKUP(map_big)\n+\t\"r6 = 0;\"\n+\"l_loop_%=:\"\n+\t\"r1 = r7;\"\n+\t\"r1 += r6;\"\n+\t\"r0 = *(u32*)(r1 + 0);\"\n+\t\"r6 += 4;\"\n+\t\"if r6 != 1000004 goto l_loop_%=;\"\n+\"l_exit_%=:\"\n+\t\"r0 = 0;\"\n+\t\"exit;\"\n+\t:\n+\t: __imm(bpf_map_lookup_elem), __imm_addr(map_big)\n+\t: __clobber_all);\n+}\n+\n+/* the counter never equals the bound and reads out of bounds */\n+SEC(\"socket\")\n+__failure __msg(\"BPF program is too large\")\n+__naked void stride4_ne_misses_bound(void)\n+{\n+\tasm volatile (\n+\tLOOKUP(map_big)\n+\t\"r6 = 0;\"\n+\"l_loop_%=:\"\n+\t\"r1 = r7;\"\n+\t\"r1 += r6;\"\n+\t\"r0 = *(u32*)(r1 + 0);\"\n+\t\"r6 += 4;\"\n+\t\"if r6 != 999998 goto l_loop_%=;\"\n+\"l_exit_%=:\"\n+\t\"r0 = 0;\"\n+\t\"exit;\"\n+\t:\n+\t: __imm(bpf_map_lookup_elem), __imm_addr(map_big)\n+\t: __clobber_all);\n+}\n+\n+/* the value read after the loop is at the exit value of the counter */\n+SEC(\"socket\")\n+__failure __msg(\"BPF program is too large\")\n+__naked void stride4_ne_use_after_loop(void)\n+{\n+\tasm volatile (\n+\tLOOKUP(map_big)\n+\t\"r6 = 0;\"\n+\"l_loop_%=:\"\n+\t\"r1 = r7;\"\n+\t\"r1 += r6;\"\n+\t\"r0 = *(u32*)(r1 + 0);\"\n+\t\"r6 += 4;\"\n+\t\"if r6 != 1000000 goto l_loop_%=;\"\n+\t\"r1 = r7;\"\n+\t\"r1 += r6;\"\n+\t\"r0 = *(u32*)(r1 + 0);\"\n+\"l_exit_%=:\"\n+\t\"r0 = 0;\"\n+\t\"exit;\"\n+\t:\n+\t: __imm(bpf_map_lookup_elem), __imm_addr(map_big)\n+\t: __clobber_all);\n+}\n+\n+/*\n+ * Nothing in the loop changes what it tests. may_goto that the verifier\n+ * adds to the back-edge ends the program: 0 is returned instead of 2.\n+ */\n+SEC(\"socket\")\n+__success __retval(0)\n+__naked void spin_until_flag(void)\n+{\n+\tasm volatile (\n+\tLOOKUP(map_small)\n+\"l_loop_%=:\"\n+\t\"r0 = *(u32*)(r7 + 0);\"\n+\t\"if r0 == 0 goto l_loop_%=;\"\n+\t\"r0 = 2;\"\n+\t\"exit;\"\n+\"l_exit_%=:\"\n+\t\"r0 = 1;\"\n+\t\"exit;\"\n+\t:\n+\t: __imm(bpf_map_lookup_elem), __imm_addr(map_small)\n+\t: __clobber_all);\n+}\n+\n+/* same with the back-edge that is not a conditional jump */\n+SEC(\"socket\")\n+__success __retval(0)\n+__naked void spin_until_flag_ja(void)\n+{\n+\tasm volatile (\n+\tLOOKUP(map_small)\n+\"l_loop_%=:\"\n+\t\"r0 = *(u32*)(r7 + 0);\"\n+\t\"if r0 != 0 goto l_done_%=;\"\n+\t\"goto l_loop_%=;\"\n+\"l_done_%=:\"\n+\t\"r0 = 2;\"\n+\t\"exit;\"\n+\"l_exit_%=:\"\n+\t\"r0 = 1;\"\n+\t\"exit;\"\n+\t:\n+\t: __imm(bpf_map_lookup_elem), __imm_addr(map_small)\n+\t: __clobber_all);\n+}\n+\n+/* may_goto cannot end the program that holds a reference, every iteration is walked */\n+SEC(\"socket\")\n+__success __retval(0)\n+__naked void loop_with_reference(void)\n+{\n+\tasm volatile (\n+\t\"r1 = %[ringbuf] ll;\"\n+\t\"r2 = 8;\"\n+\t\"r3 = 0;\"\n+\t\"call %[bpf_ringbuf_reserve];\"\n+\t\"if r0 == 0 goto l_exit_%=;\"\n+\t\"r7 = r0;\"\n+\t\"r6 = 0;\"\n+\"l_loop_%=:\"\n+\t\"r6 += 1;\"\n+\t\"if r6 != 100 goto l_loop_%=;\"\n+\t\"r1 = r7;\"\n+\t\"r2 = 0;\"\n+\t\"call %[bpf_ringbuf_discard];\"\n+\"l_exit_%=:\"\n+\t\"r0 = 0;\"\n+\t\"exit;\"\n+\t:\n+\t: __imm(bpf_ringbuf_reserve), __imm(bpf_ringbuf_discard), __imm_addr(ringbuf)\n+\t: __clobber_all);\n+}\n+\n+char _license[] SEC(\"license\") = \"GPL\";\ndiff --git a/tools/testing/selftests/bpf/progs/verifier_movsx.c b/tools/testing/selftests/bpf/progs/verifier_movsx.c\nindex 195b27a51224f..280ccee336635 100644\n--- a/tools/testing/selftests/bpf/progs/verifier_movsx.c\n+++ b/tools/testing/selftests/bpf/progs/verifier_movsx.c\n@@ -226,7 +226,7 @@ l0_%=:\t\t\t\t\t\t\t\\\n \n SEC(\"socket\")\n __description(\"MOV32SX, S8, var_off u32_max\")\n-__failure __msg(\"infinite loop detected\")\n+__success\n __failure_unpriv __msg_unpriv(\"back-edge from insn 2 to 0\")\n __naked void mov64sx_s32_varoff_1(void)\n {\ndiff --git a/tools/testing/selftests/bpf/progs/verifier_precision.c b/tools/testing/selftests/bpf/progs/verifier_precision.c\nindex f4459561bf393..88358586e7964 100644\n--- a/tools/testing/selftests/bpf/progs/verifier_precision.c\n+++ b/tools/testing/selftests/bpf/progs/verifier_precision.c\n@@ -152,22 +152,21 @@ __naked int bpf_store_release(void)\n SEC(\"?raw_tp\")\n __success __log_level(2)\n /*\n- * Without the bug fix there will be no history between \"last_idx 3 first_idx 3\"\n- * and \"parent state regs=\" lines. \"R0=6\" parts are here to help anchor\n- * expected log messages to the one specific mark_chain_precision operation.\n- *\n- * This is quite fragile: if verifier checkpointing heuristic changes, this\n- * might need adjusting.\n+ * The state is widened when it comes back to the loop head, so the exit test\n+ * is decided only on the first trip around the loop. \"R0=2\" parts are here to\n+ * help anchor expected log messages to that mark_chain_precision operation.\n */\n-__msg(\"2: (07) r0 += 1 ; R0=6\")\n+__msg(\"2: (07) r0 += 1 ; R0=2\")\n __msg(\"3: (35) if r0 \u003e= 0xa goto pc+1\")\n-__msg(\"mark_precise: frame0: last_idx 3 first_idx 3 subseq_idx -1\")\n+__msg(\"mark_precise: frame0: last_idx 3 first_idx 1 subseq_idx -1\")\n __msg(\"mark_precise: frame0: regs=r0 stack= before 2: (07) r0 += 1\")\n __msg(\"mark_precise: frame0: regs=r0 stack= before 1: (07) r0 += 1\")\n-__msg(\"mark_precise: frame0: regs=r0 stack= before 4: (05) goto pc-4\")\n-__msg(\"mark_precise: frame0: regs=r0 stack= before 3: (35) if r0 \u003e= 0xa goto pc+1\")\n-__msg(\"mark_precise: frame0: parent state regs= stack=: R0=P4\")\n-__msg(\"3: R0=6\")\n+__msg(\"mark_precise: frame0: parent state regs=r0 stack=: R0=P0\")\n+__msg(\"mark_precise: frame0: last_idx 0 first_idx 0 subseq_idx 1\")\n+__msg(\"mark_precise: frame0: regs=r0 stack= before 0: (b7) r0 = 0\")\n+__msg(\"3: R0=2\")\n+__msg(\"loop head 1 widened, pass 1\")\n+__msg(\"1: safe\")\n __naked int state_loop_first_last_equal(void)\n {\n \tasm volatile (\n@@ -175,11 +174,7 @@ __naked int state_loop_first_last_equal(void)\n \t\"l0_%=:\"\n \t\t\"r0 += 1;\"\n \t\t\"r0 += 1;\"\n-\t\t/* every few iterations we'll have a checkpoint here with\n-\t\t * first_idx == last_idx, potentially confusing precision\n-\t\t * backtracking logic\n-\t\t */\n-\t\t\"if r0 \u003e= 10 goto l1_%=;\"\t/* checkpoint + mark_precise */\n+\t\t\"if r0 \u003e= 10 goto l1_%=;\"\t/* mark_precise */\n \t\t\"goto l0_%=;\"\n \t\"l1_%=:\"\n \t\t\"exit;\"\ndiff --git a/tools/testing/selftests/bpf/progs/verifier_search_pruning.c b/tools/testing/selftests/bpf/progs/verifier_search_pruning.c\nindex f40e57251e941..7098b44faafc5 100644\n--- a/tools/testing/selftests/bpf/progs/verifier_search_pruning.c\n+++ b/tools/testing/selftests/bpf/progs/verifier_search_pruning.c\n@@ -341,8 +341,7 @@ l0_%=:\tr1 = 42;\t\t\t\t\t\\\n * test would take a very long time to verify.\n */\n SEC(\"kprobe\")\n-__failure __log_level(4)\n-__msg(\"BPF program is too large.\")\n+__success\n __naked void short_loop1(void)\n {\n \tasm volatile (\ndiff --git a/tools/testing/selftests/bpf/verifier/calls.c b/tools/testing/selftests/bpf/verifier/calls.c\nindex 8b94b87135bcf..c7c501bfc660a 100644\n--- a/tools/testing/selftests/bpf/verifier/calls.c\n+++ b/tools/testing/selftests/bpf/verifier/calls.c\n@@ -559,8 +559,9 @@\n \tBPF_EXIT_INSN(),\n \t},\n \t.prog_type = BPF_PROG_TYPE_SCHED_CLS,\n-\t.errstr = \"infinite loop detected\",\n-\t.result = REJECT,\n+\t/* may_goto ends the loop after 250ms, do not run it */\n+\t.result = ACCEPT,\n+\t.runs = -1,\n },\n {\n \t\"calls: using r0 returned by callee\",\n"
} |
| 2/1 | 2026/09/26 03:30 | agent | patch-evaluator |
0mModel:core Args: null Results: {
"EnableConfigs": [
"BPF_SYSCALL",
"BPF_JIT"
],
"FocusSymbols": [
"bpf_widen_loop_head",
"bpf_mark_loop_guard",
"bpf_commit_loop_guards",
"bpf_scc_mark_exit",
"bpf_is_state_visited"
],
"Reasoning": "The patch introduces loop widening and loop guard insertion into the BPF verifier. This is a substantial change to core BPF verifier logic in kernel/bpf/ (verifier.c, states.c, fixups.c, cfg.c), implementing scalar range widening across loop iterations, verifier state snapshot/restore rollback on failure, and instruction rewrites to insert may_goto/bpf_throw guards. This code is reachable from userspace via the bpf() system call and is an important target for fuzzing to discover potential soundness issues, unbounded memory consumption, or crashes.",
"WorthFuzzing": true
}Instruction: You are an expert Linux kernel maintainer and security engineer.
Your job is to review a provided patch series and evaluate whether it warrants fuzzing with syzkaller.
IMPORTANT: The changes have ALREADY been applied and committed as the HEAD commit in
your workspace. Do NOT rely on internal assumptions. You must actively use your code access
tools to inspect the actual source code, callers, and surrounding context.
================================================================================
1. CORE TRIAGE PHILOSOPHY
================================================================================
The goal of patch fuzzing is to discover crashes, regressions, exposed latent bugs,
and newly triggered assertions introduced by the patch series.
- REACHABILITY IS THE PRIMARY GATE:
Fuzzing can only discover bugs in code that can actually execute in standard virtualized
environments (GCE or QEMU, utilizing software-emulated devices like USB gadgets, netdev, tun/tap).
If the modified code is structurally unreachable (see Section 2), it MUST NOT be fuzzed,
regardless of whether it adds assertions or complex logic.
- DO NOT BLINDLY TRUST "NO FUNCTIONAL CHANGE" (NFCI) OR "REFACTORING" CLAIMS:
Patch authors routinely label changes as "cleanups", "refactorings", or state
"No functional change intended". Do NOT take these claims at face value.
Code refactorings that rearrange logic, introduce helper functions, or alter state management
in core subsystems frequently introduce subtle semantic shifts or uncover latent kernel bugs.
If reachable executable code is modified or refactored, it MUST be fuzzed.
- NEW OR MODIFIED ASSERTIONS IN REACHABLE CODE MUST BE FUZZED:
When a patch introduces or modifies runtime checks or assertions (e.g., WARN_ON*, VM_WARN_ON*,
BUG_ON*, lockdep_assert*) in reachable code paths, it enforces new or stricter invariants.
Even if the author believes the invariant always holds, fuzzing is essential to verify whether
an unusual sequence of operations can violate it.
================================================================================
2. WHEN TO RETURN WorthFuzzing=false (NEGATIVE CRITERIA)
================================================================================
Return WorthFuzzing=false ONLY IF all modified code falls strictly into one or more of these categories:
- Non-kernel and non-executable changes:
* Modifications to Documentation/, comments, or spelling fixes.
* User-space directories, self-tests, samples, or scripts (e.g., tools/, samples/, scripts/, usr/)
that do not affect the compiled kernel image (vmlinux) or kernel modules.
* Purely decorative logging (e.g., message strings in pr_err, printk, dev_info) or tracepoints
that do not alter control flow or data structures.
* Build system or Kconfig changes that do not alter compiled C logic.
- Structurally unreachable hardware:
* Vendor-specific PCIe switches, SmartNICs, or GPU drivers (e.g., mlxsw, pds_core, qed,
ionic, amdgpu) requiring physical ASIC/PCIe cards not emulated in standard QEMU.
- Unreachable execution paths:
* Driver teardown callbacks (.remove, .shutdown, pci_unregister_driver) executed only during
physical PCI hot-unplug or manual sysfs driver unbinding.
* Code paths exclusive to architectures other than the target architecture.
================================================================================
3. WHEN TO RETURN WorthFuzzing=true (POSITIVE CRITERIA)
================================================================================
Return WorthFuzzing=true whenever the patch touches reachable executable code, including:
- Core Subsystems:
* Any logic modifications in memory management (mm/), synchronization/locking (kernel/locking/),
BPF, scheduler, core networking, VFS, or syscall handling.
- Refactorings and Code Cleanups:
* Any restructuring of reachable data structures, helper abstractions, or algorithm flows.
- Runtime Assertions and Defensive Checks:
* Any introduction or alteration of assertions (WARN_ON*, VM_WARN_ON*, BUG_ON*, etc.) in reachable paths.
- Reachable Drivers and Protocols:
* Drivers accessible via virtual buses (virtio, USB gadget, loopback, netlink, binder, sockets, etc.).
================================================================================
4. EXTRACTING FocusSymbols (PREVENTING DILUTION)
================================================================================
When WorthFuzzing=true, you must extract specific kernel functions into FocusSymbols to guide the fuzzer:
- AVOID UBIQUITOUS LIFECYCLE HOT-PATHS:
Do NOT list generic, ubiquitous functions called by almost every program in the corpus
(including, but not limited to: general memory allocators and deallocators, page fault
and trap handlers, or core synchronization primitives; this is not an exhaustive list).
Listing ubiquitous functions causes the fuzzer to classify thousands of unrelated tests as "focused",
which severely dilutes fuzzing effort away from the actual changes.
- TARGET SPECIFIC FEATURE LOGIC AND ENTRYPOINTS:
List functions that specifically implement the logic being added or altered, or direct API entrypoints
for the subsystem feature under review.
- HANDLING STATIC INLINE FUNCTIONS IN HEADERS (.h):
Compiler-inlined static functions (such as static inlines in mm/*.h or include/linux/*.h) lack
distinct symbol addresses in vmlinux and cannot be targeted directly by symbol coverage filters.
If the changes are primarily in static inline helpers, identify non-static, feature-specific caller
functions in .c files that exercise them (avoiding ubiquitous lifecycle wrappers).
================================================================================
5. IDENTIFYING EnableConfigs
================================================================================
Identify any specific CONFIG_ options required to properly compile and reach the modified code:
- Inspect Kconfig files and #ifdef guards; do not make assumptions.
- Check "depends on" lines in Kconfig to include any non-standard parent subsystem configs needed.
- Strip any 'CONFIG_' prefix (e.g., return "NET_IPV4" instead of "CONFIG_NET_IPV4").
Prefer calling several tools at the same time to save round-trips.
Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.
Prompt: Target architecture: amd64
For your convenience, here is the diff of the changes:
commit 3769330d0db57d4c049d66c93c77f5e01c5a973d
Author: syz-cluster <triage@syzkaller.com>
Date: Sat Sep 26 03:30:31 2026 +0000
syz-cluster: applied patch under review
diff --git a/include/linux/bpf_verifier.h b/include/linux/bpf_verifier.h
index 92f528c456052..e02ee286067d2 100644
--- a/include/linux/bpf_verifier.h
+++ b/include/linux/bpf_verifier.h
@@ -527,6 +527,8 @@ struct bpf_verifier_state {
u32 dfs_depth;
u32 callback_unroll_depth;
u32 may_goto_depth;
+ /* number of times the loop head this state is a checkpoint of was widened */
+ u32 loop_passes;
};
static inline struct bpf_reg_state *
@@ -709,6 +711,16 @@ struct bpf_insn_aux_data {
u32 non_stack_access:1; /* instruction can access non-stack memory */
/* true if some jump or call instruction targets this instruction */
u32 jump_target:1;
+ u32 loop_head:1; /* target of a back-edge */
+ u32 backedge_ft:1; /* the edge to the next insn is a back-edge */
+ u32 backedge_br:1; /* the jump is a back-edge */
+ /*
+ * The walk went over the back-edge of this insn with nothing to bound
+ * the number of trips, in a state where bpf_throw() can and cannot be called.
+ */
+ u32 guard_pending:1;
+ u32 guard_impossible:1;
+ u32 loop_guard:1; /* may_goto has to be added to the back-edge of this insn */
/*
* CFG strongly connected component this instruction belongs to,
* zero if it is a singleton SCC.
@@ -895,6 +907,8 @@ struct bpf_scc_visit {
struct bpf_verifier_state *entry_state;
struct bpf_scc_backedge *backedges; /* list of backedges */
u32 num_backedges;
+ /* some state left the SCC since entry_state was set */
+ bool exited;
};
/* An array of bpf_scc_visit structs sharing tht same bpf_scc_callchain->scc
@@ -1046,6 +1060,16 @@ struct bpf_verifier_env {
/* array of pointers to bpf_scc_info indexed by SCC id */
struct bpf_scc_info **scc_info;
u32 scc_cnt;
+ /* per SCC constants that loop counters are compared with, see bpf_widen_loop_head() */
+ struct bpf_widen_thrs **scc_thrs;
+ /* SCCs where some state came back to a state that is still walked */
+ unsigned long *scc_converged;
+ /* states that come back to a loop head are widened instead of walking every iteration */
+ bool widen_loops;
+ /* the walk did or tried that, so a failure can be due to the lost precision */
+ bool widen_used;
+ /* insns processed by a walk that was given up */
+ u32 insn_wasted;
struct bpf_iarray *succ;
struct bpf_iarray *gotox_tmp_buf;
};
@@ -1218,6 +1242,13 @@ void bpf_free_kfunc_btf_tab(struct bpf_kfunc_btf_tab *tab);
int mark_chain_precision(struct bpf_verifier_env *env, int regno);
int bpf_is_state_visited(struct bpf_verifier_env *env, int insn_idx);
+bool bpf_same_loop(struct bpf_verifier_state *old, struct bpf_verifier_state *cur);
+bool bpf_mark_loop_guard(struct bpf_verifier_env *env, struct bpf_verifier_state *cur);
+int bpf_commit_loop_guards(struct bpf_verifier_env *env);
+void bpf_throw(u64 cookie);
+void bpf_scc_mark_exit(struct bpf_verifier_env *env, struct bpf_verifier_state *st, int insn_idx);
+int bpf_widen_loop_head(struct bpf_verifier_env *env, int insn_idx, bool backedge,
+ struct bpf_verifier_state *old, struct bpf_verifier_state *cur);
int bpf_update_branch_counts(struct bpf_verifier_env *env, struct bpf_verifier_state *st);
void bpf_clear_jmp_history(struct bpf_verifier_state *state);
diff --git a/kernel/bpf/cfg.c b/kernel/bpf/cfg.c
index 842c7d1eabccc..748bf544d3ba5 100644
--- a/kernel/bpf/cfg.c
+++ b/kernel/bpf/cfg.c
@@ -137,8 +137,14 @@ static int push_insn(int t, int w, int e, struct bpf_verifier_env *env)
insn_stack[env->cfg.cur_stack++] = w;
return KEEP_EXPLORING;
} else if ((insn_state[w] & 0xF0) == DISCOVERED) {
- if (env->bpf_capable)
+ if (env->bpf_capable) {
+ env->insn_aux_data[w].loop_head = true;
+ if (e == FALLTHROUGH)
+ env->insn_aux_data[t].backedge_ft = true;
+ else
+ env->insn_aux_data[t].backedge_br = true;
return DONE_EXPLORING;
+ }
verbose_linfo(env, t, "%d: ", t);
verbose_linfo(env, w, "%d: ", w);
verbose(env, "back-edge from insn %d to %d\n", t, w);
diff --git a/kernel/bpf/fixups.c b/kernel/bpf/fixups.c
index 2add8001c3ec3..2b965fa4bacc0 100644
--- a/kernel/bpf/fixups.c
+++ b/kernel/bpf/fixups.c
@@ -1537,6 +1537,143 @@ static int add_hidden_subprog(struct bpf_verifier_env *env, struct bpf_insn *pat
/* Do various post-verification rewrites in a single program pass.
* These rewrites simplify JIT and interpreter implementations.
*/
+/*
+ * The walk with widened loops is done. Loops where some state came back to
+ * a state that was still walked were not walked to the end and have to be
+ * bounded at run time.
+ */
+int bpf_commit_loop_guards(struct bpf_verifier_env *env)
+{
+ struct bpf_insn_aux_data *aux = env->insn_aux_data;
+ int i;
+
+ for (i = 0; i < env->prog->len; i++) {
+ if (!aux[i].scc || !test_bit(aux[i].scc, env->scc_converged))
+ continue;
+ if (aux[i].guard_impossible) {
+ verbose(env, "loop with back-edge at insn %d cannot be bounded\n", i);
+ return -E2BIG;
+ }
+ if (aux[i].guard_pending) {
+ aux[i].loop_guard = true;
+ env->seen_exception = true;
+ }
+ }
+ return 0;
+}
+
+/* Jump from insn @from of the patch that replaces insn @idx to insn @target of the program. */
+static int guard_jump(struct bpf_insn *insn, int idx, int from, int cnt, int target)
+{
+ int off;
+
+ /* insns after @idx move by the size of the patch */
+ if (target > idx)
+ target += cnt - 1;
+ off = target - (idx + from) - 1;
+ if (BPF_OP(insn->code) == BPF_JA && BPF_CLASS(insn->code) == BPF_JMP32) {
+ insn->imm = off;
+ return 0;
+ }
+ if (off < S16_MIN || off > S16_MAX) {
+ if (BPF_OP(insn->code) != BPF_JA)
+ return -ERANGE;
+ *insn = BPF_JMP32_A(off);
+ return 0;
+ }
+ insn->off = off;
+ return 0;
+}
+
+/*
+ * The main pass went over the back-edge of jump @insn at @idx with a state
+ * that stands for any number of iterations. Nothing bounds the loop at run
+ * time, so add may_goto to the back-edge. The program cannot go on when
+ * may_goto is out of budget: nothing but the loop was verified for the state
+ * in the loop. Call bpf_throw(). The main pass made sure it can be called.
+ *
+ * back-edge is the jump: back-edge is the edge to the next insn:
+ * if cond goto guard if cond goto target
+ * goto next guard:
+ * guard: may_goto throw
+ * may_goto throw goto next
+ * goto head throw:
+ * throw: r1 = 0
+ * r1 = 0 call bpf_throw
+ * call bpf_throw next:
+ * next:
+ *
+ * Returns the number of insns in @buf.
+ */
+static int add_loop_guard(struct bpf_verifier_env *env, int idx, struct bpf_insn *buf,
+ int stack_depth, u16 *stack_depth_extra)
+{
+ struct bpf_insn_aux_data *aux = &env->insn_aux_data[idx];
+ struct bpf_insn orig = env->prog->insnsi[idx];
+ bool ja = BPF_OP(orig.code) == BPF_JA;
+ bool gotol = ja && BPF_CLASS(orig.code) == BPF_JMP32;
+ int target = idx + 1 + (gotol ? orig.imm : orig.off);
+ bool guard_jump_edge = ja || aux->backedge_br;
+ struct bpf_insn *p = buf, *jeq, *skip = NULL, *back = NULL;
+ int stack_off, cnt, err = 0;
+
+ if (guard_jump_edge && !ja) {
+ *p = orig;
+ p->off = 1;
+ p++;
+ skip = p;
+ *p++ = BPF_JMP_A(0);
+ } else if (!guard_jump_edge) {
+ *p++ = orig;
+ }
+
+ /* the same insns may_goto is replaced with, see bpf_do_misc_fixups() */
+ if (bpf_jit_supports_timed_may_goto()) {
+ stack_off = -stack_depth - 16;
+ *stack_depth_extra = 16;
+ *p++ = BPF_LDX_MEM(BPF_DW, BPF_REG_AX, BPF_REG_10, stack_off);
+ jeq = p;
+ *p++ = BPF_JMP_IMM(BPF_JEQ, BPF_REG_AX, 0, 0);
+ *p++ = BPF_ALU64_IMM(BPF_SUB, BPF_REG_AX, 1);
+ *p++ = BPF_JMP_IMM(BPF_JNE, BPF_REG_AX, 0, 2);
+ *p++ = BPF_MOV64_IMM(BPF_REG_AX, stack_off);
+ *p++ = BPF_EMIT_CALL(arch_bpf_timed_may_goto);
+ *p++ = BPF_STX_MEM(BPF_DW, BPF_REG_10, BPF_REG_AX, stack_off);
+ } else {
+ stack_off = -stack_depth - 8;
+ *stack_depth_extra = max_t(u16, *stack_depth_extra, 8);
+ *p++ = BPF_LDX_MEM(BPF_DW, BPF_REG_AX, BPF_REG_10, stack_off);
+ jeq = p;
+ *p++ = BPF_JMP_IMM(BPF_JEQ, BPF_REG_AX, 0, 0);
+ *p++ = BPF_ALU64_IMM(BPF_SUB, BPF_REG_AX, 1);
+ *p++ = BPF_STX_MEM(BPF_DW, BPF_REG_10, BPF_REG_AX, stack_off);
+ }
+
+ if (guard_jump_edge) {
+ back = p;
+ *p++ = gotol ? orig : BPF_JMP_A(0);
+ } else {
+ /* over bpf_throw() to the loop head that follows */
+ *p++ = BPF_JMP_A(2);
+ }
+ jeq->off = p - jeq - 1;
+ *p++ = BPF_MOV64_IMM(BPF_REG_1, 0);
+ *p++ = BPF_EMIT_CALL(bpf_throw);
+ cnt = p - buf;
+
+ if (skip)
+ skip->off = cnt - (skip - buf) - 1;
+ if (back)
+ err = guard_jump(back, idx, back - buf, cnt, target);
+ else
+ err = guard_jump(&buf[0], idx, 0, cnt, target);
+ if (err) {
+ verbose(env, "insn %d: jump is out of range after may_goto is added\n", idx);
+ return err;
+ }
+ return cnt;
+}
+
int bpf_do_misc_fixups(struct bpf_verifier_env *env)
{
struct bpf_prog *prog = env->prog;
@@ -1573,6 +1710,22 @@ int bpf_do_misc_fixups(struct bpf_verifier_env *env)
}
for (i = 0; i < insn_cnt;) {
+ if (env->insn_aux_data[i + delta].loop_guard) {
+ cnt = add_loop_guard(env, i + delta, insn_buf, stack_depth,
+ &stack_depth_extra);
+ if (cnt < 0)
+ return cnt;
+
+ new_prog = bpf_patch_insn_data(env, i + delta, insn_buf, cnt);
+ if (!new_prog)
+ return -ENOMEM;
+
+ delta += cnt - 1;
+ env->prog = prog = new_prog;
+ insn = new_prog->insnsi + i + delta;
+ goto next_insn;
+ }
+
if (is_addr_space_cast32(env->prog, insn)) {
/* convert to 32-bit mov that clears upper 32-bit */
insn->code = BPF_ALU | BPF_MOV | BPF_X;
diff --git a/kernel/bpf/states.c b/kernel/bpf/states.c
index 66fb11b6c6a76..24422b7db6d97 100644
--- a/kernel/bpf/states.c
+++ b/kernel/bpf/states.c
@@ -170,6 +170,7 @@ static int maybe_enter_scc(struct bpf_verifier_env *env, struct bpf_verifier_sta
return -ENOMEM;
if (!visit->entry_state) {
visit->entry_state = st;
+ visit->exited = false;
if (env->log.level & BPF_LOG_LEVEL2)
verbose(env, "SCC enter %s\n", format_callchain(env, callchain));
}
@@ -212,6 +213,16 @@ static int maybe_exit_scc(struct bpf_verifier_env *env, struct bpf_verifier_stat
}
if (visit->entry_state != st)
return 0;
+ /*
+ * All states that came from @st are done. If some of them went
+ * around the loop and none left it, nothing that enters the loop
+ * the way @st did ever leaves it.
+ */
+ if (env->widen_loops && !st->speculative && visit->backedges && !visit->exited) {
+ verbose(env, "loop at insn %d never exits\n", st->insn_idx);
+ env->widen_used = true;
+ return -EINVAL;
+ }
if (env->log.level & BPF_LOG_LEVEL2)
verbose(env, "SCC exit %s\n", format_callchain(env, callchain));
visit->entry_state = NULL;
@@ -221,6 +232,32 @@ static int maybe_exit_scc(struct bpf_verifier_env *env, struct bpf_verifier_stat
return propagate_backedges(env, visit);
}
+/*
+ * @st left the loop that @insn_idx of its current frame is in. The loop is
+ * left when the frame that bpf_scc_visit is for leaves it. Loops in callees
+ * of that frame are part of one trip around the loop of the caller.
+ */
+void bpf_scc_mark_exit(struct bpf_verifier_env *env, struct bpf_verifier_state *st, int insn_idx)
+{
+ struct bpf_scc_callchain *callchain = &env->callchain_buf;
+ struct bpf_scc_visit *visit;
+ u32 i, callsite;
+
+ if (st->speculative || !env->insn_aux_data[insn_idx].scc)
+ return;
+ memset(callchain, 0, sizeof(*callchain));
+ for (i = 0; i < st->curframe; i++) {
+ callsite = bpf_frame_insn_idx(st, i);
+ if (env->insn_aux_data[callsite].scc)
+ return;
+ callchain->callsites[i] = callsite;
+ }
+ callchain->scc = env->insn_aux_data[insn_idx].scc;
+ visit = scc_visit_lookup(env, callchain);
+ if (visit)
+ visit->exited = true;
+}
+
/* Lookup an bpf_scc_visit instance corresponding to @st callchain
* and add @backedge to visit->backedges. @st callchain must exist.
*/
@@ -244,6 +281,8 @@ static int add_scc_backedge(struct bpf_verifier_env *env,
}
if (env->log.level & BPF_LOG_LEVEL2)
verbose(env, "SCC backedge %s\n", format_callchain(env, callchain));
+ if (env->scc_converged)
+ __set_bit(callchain->scc, env->scc_converged);
backedge->next = visit->backedges;
visit->backedges = backedge;
visit->num_backedges++;
@@ -1108,6 +1147,62 @@ static int propagate_backedges(struct bpf_verifier_env *env, struct bpf_scc_visi
return 0;
}
+/* Did the walk get to @insn_idx over a back-edge? */
+static bool is_backedge(struct bpf_verifier_env *env, int insn_idx)
+{
+ int prev = env->prev_insn_idx;
+ struct bpf_insn_aux_data *aux;
+ struct bpf_insn *insn;
+
+ if (prev < 0 || prev >= env->prog->len)
+ return false;
+ aux = &env->insn_aux_data[prev];
+ insn = &env->prog->insnsi[prev];
+ /* check_cfg() does not record the edge of an unconditional jump as a jump */
+ if ((BPF_CLASS(insn->code) == BPF_JMP || BPF_CLASS(insn->code) == BPF_JMP32) &&
+ BPF_OP(insn->code) == BPF_JA)
+ return aux->backedge_ft || aux->backedge_br;
+ return insn_idx == prev + 1 ? aux->backedge_ft : aux->backedge_br;
+}
+
+static bool iter_active_depths_differ(struct bpf_verifier_state *old,
+ struct bpf_verifier_state *cur);
+
+/* The state of this walk that was the last to get to loop head @insn_idx. */
+static struct bpf_verifier_state *loop_head_state(struct bpf_verifier_env *env, int insn_idx)
+{
+ struct bpf_verifier_state *cur = env->cur_state;
+ struct bpf_verifier_state_list *sl;
+ struct list_head *pos;
+
+ /* states are most recent first */
+ list_for_each(pos, bpf_explored_state(env, insn_idx)) {
+ sl = container_of(pos, struct bpf_verifier_state_list, node);
+ if (sl->state.insn_idx == insn_idx && sl->state.branches &&
+ bpf_same_loop(&sl->state, cur))
+ return &sl->state;
+ }
+ return NULL;
+}
+
+/*
+ * @cur got to loop head @insn_idx, @old is the state that started this trip
+ * around the loop if there is one. The trip is bounded at run time if it
+ * took from the budget of may_goto or got an element from an iterator.
+ * Otherwise may_goto has to be added to the back-edge if the loop is not
+ * walked to the end. Returns false if that is not possible.
+ */
+static bool loop_head_guard(struct bpf_verifier_env *env, int insn_idx,
+ struct bpf_verifier_state *old, struct bpf_verifier_state *cur)
+{
+ if (!is_backedge(env, insn_idx))
+ return true;
+ if (old && (old->may_goto_depth != cur->may_goto_depth ||
+ iter_active_depths_differ(old, cur)))
+ return true;
+ return bpf_mark_loop_guard(env, cur);
+}
+
static bool states_maybe_looping(struct bpf_verifier_state *old,
struct bpf_verifier_state *cur)
{
@@ -1237,12 +1332,23 @@ int bpf_is_state_visited(struct bpf_verifier_env *env, int insn_idx)
{
struct bpf_verifier_state_list *new_sl;
struct bpf_verifier_state_list *sl;
- struct bpf_verifier_state *cur = env->cur_state, *new;
+ struct bpf_verifier_state *cur = env->cur_state, *new, *widen_from = NULL;
+ bool loop_head = env->widen_loops && env->insn_aux_data[insn_idx].loop_head;
bool force_new_state, add_new_state, loop;
int n, err, states_cnt = 0;
struct list_head *pos, *tmp, *head;
+ if (loop_head) {
+ widen_from = loop_head_state(env, insn_idx);
+ /* the loop cannot be bounded at run time, walk all of it */
+ if (!loop_head_guard(env, insn_idx, widen_from, cur)) {
+ loop_head = false;
+ widen_from = NULL;
+ }
+ }
+
force_new_state = env->test_state_freq || bpf_is_force_checkpoint(env, insn_idx) ||
+ loop_head ||
/* Avoid accumulating infinitely long jmp history */
cur->jmp_history_cnt > 40;
@@ -1364,12 +1470,32 @@ int bpf_is_state_visited(struct bpf_verifier_env *env, int insn_idx)
}
goto skip_inf_loop_check;
}
+ /*
+ * The state came back to the loop head. If it is within
+ * the state that went around the loop nothing new can
+ * happen on the next trip. Otherwise it is widened below
+ * and goes around instead of all the iterations it stands for.
+ */
+ if (loop_head && bpf_same_loop(&sl->state, cur)) {
+ if (states_equal(env, &sl->state, cur, RANGE_WITHIN)) {
+ env->widen_used = true;
+ loop = true;
+ goto hit;
+ }
+ goto skip_inf_loop_check;
+ }
/* attempt to detect infinite loop to avoid unnecessary doomed work */
if (states_maybe_looping(&sl->state, cur) &&
states_equal(env, &sl->state, cur, EXACT) &&
!iter_active_depths_differ(&sl->state, cur) &&
sl->state.may_goto_depth == cur->may_goto_depth &&
sl->state.callback_unroll_depth == cur->callback_unroll_depth) {
+ /* the state repeats, nothing new on the next trip */
+ if (env->widen_loops) {
+ env->widen_used = true;
+ loop = true;
+ goto hit;
+ }
verbose_linfo(env, insn_idx, "; ");
verbose(env, "infinite loop detected at insn %d\n", insn_idx);
verbose(env, "cur state:");
@@ -1402,6 +1528,9 @@ int bpf_is_state_visited(struct bpf_verifier_env *env, int insn_idx)
if (states_equal(env, &sl->state, cur, loop ? RANGE_WITHIN : NOT_EXACT)) {
hit:
sl->hit_cnt++;
+ /* what follows the old state was seen, it may leave the loop */
+ if (env->widen_loops && !sl->state.branches)
+ bpf_scc_mark_exit(env, cur, insn_idx);
/* if previous state reached the exit with precision and
* current state is equivalent to it (except precision marks)
@@ -1522,7 +1651,8 @@ int bpf_is_state_visited(struct bpf_verifier_env *env, int insn_idx)
* Use bigger 'n' for checkpoints because evicting checkpoint states
* too early would hinder iterator convergence.
*/
- n = bpf_is_force_checkpoint(env, insn_idx) && sl->state.branches > 0 ? 64 : 3;
+ n = (bpf_is_force_checkpoint(env, insn_idx) || loop_head) &&
+ sl->state.branches > 0 ? 64 : 3;
if (sl->miss_cnt > sl->hit_cnt * n + n) {
/* the state is unlikely to be useful. Remove it to
* speed up verification
@@ -1539,6 +1669,16 @@ int bpf_is_state_visited(struct bpf_verifier_env *env, int insn_idx)
if (env->max_states_per_insn < states_cnt)
env->max_states_per_insn = states_cnt;
+ if (loop_head) {
+ cur->loop_passes = 0;
+ if (widen_from) {
+ err = bpf_widen_loop_head(env, insn_idx, is_backedge(env, insn_idx),
+ widen_from, cur);
+ if (err)
+ return err;
+ }
+ }
+
if (!env->bpf_capable && states_cnt > BPF_COMPLEXITY_LIMIT_STATES)
return 0;
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index a7c9e2d8965d5..871aa45031d61 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -1733,6 +1733,7 @@ int bpf_copy_verifier_state(struct bpf_verifier_state *dst_state,
dst_state->dfs_depth = src->dfs_depth;
dst_state->callback_unroll_depth = src->callback_unroll_depth;
dst_state->may_goto_depth = src->may_goto_depth;
+ dst_state->loop_passes = src->loop_passes;
dst_state->equal_state = src->equal_state;
for (i = 0; i <= src->curframe; i++) {
dst = dst_state->frame[i];
@@ -2094,9 +2095,71 @@ static struct cnum64 cnum64_from_tnum(struct tnum tnum)
return cnum64_from_urange(tnum.value, (tnum.value | tnum.mask));
}
+/* smallest member of @t that is >= @x, wraps around to the smallest member of @t */
+static u64 tnum_member_ge(struct tnum t, u64 x)
+{
+ if ((x & ~t.mask) == t.value)
+ return x;
+ if (x > (t.value | t.mask))
+ return t.value;
+ return tnum_step(t, x);
+}
+
+/* largest member of @t that is <= @x, wraps around to the largest member of @t */
+static u64 tnum_member_le(struct tnum t, u64 x)
+{
+ /* members of 'tc' are bitwise complements of members of 't' */
+ struct tnum tc = { .value = ~(t.value | t.mask), .mask = t.mask };
+
+ return ~tnum_member_ge(tc, ~x);
+}
+
+/*
+ * Move both ends of arc @c inwards to the nearest members of @t.
+ * Values that are dropped are not members of @t.
+ */
+static struct cnum64 cnum64_tighten_by_tnum(struct cnum64 c, struct tnum t)
+{
+ u64 lo, hi, dlo, dhi;
+
+ if (cnum64_is_empty(c) || c.size == U64_MAX || !t.mask)
+ return c;
+ lo = tnum_member_ge(t, c.base);
+ dlo = lo - c.base;
+ if (dlo > c.size)
+ return c;
+ hi = tnum_member_le(t, c.base + c.size);
+ dhi = c.base + c.size - hi;
+ if (dhi > c.size - dlo)
+ return c;
+ return (struct cnum64){ .base = lo, .size = c.size - dlo - dhi };
+}
+
+static struct cnum32 cnum32_tighten_by_tnum(struct cnum32 c, struct tnum t)
+{
+ struct tnum tc;
+ u32 lo, hi, dlo, dhi;
+
+ t = tnum_subreg(t);
+ if (cnum32_is_empty(c) || c.size == U32_MAX || !t.mask)
+ return c;
+ lo = tnum_member_ge(t, c.base);
+ dlo = lo - c.base;
+ if (dlo > c.size)
+ return c;
+ /* complement within 32 bits */
+ tc = (struct tnum){ .value = (u32)~(t.value | t.mask), .mask = t.mask };
+ hi = ~(u32)tnum_member_ge(tc, (u32)~(c.base + c.size));
+ dhi = c.base + c.size - hi;
+ if (dhi > c.size - dlo)
+ return c;
+ return (struct cnum32){ .base = lo, .size = c.size - dlo - dhi };
+}
+
static void __update_reg32_bounds(struct bpf_reg_state *reg)
{
cnum32_intersect_with(®->r32, cnum32_from_tnum(reg->var_off));
+ reg->r32 = cnum32_tighten_by_tnum(reg->r32, reg->var_off);
}
static void __update_reg64_bounds(struct bpf_reg_state *reg)
@@ -2105,6 +2168,7 @@ static void __update_reg64_bounds(struct bpf_reg_state *reg)
bool umin_in_tnum;
cnum64_intersect_with(®->r64, cnum64_from_tnum(reg->var_off));
+ reg->r64 = cnum64_tighten_by_tnum(reg->r64, reg->var_off);
/* Check if u64 and tnum overlap in a single value */
tnum_next = tnum_step(reg->var_off, reg_umin(reg));
@@ -7977,6 +8041,354 @@ static struct bpf_verifier_state *find_prev_entry(struct bpf_verifier_env *env,
return NULL;
}
+/* A constant that register @regno is compared with, -1 if any register. */
+struct widen_thr {
+ s64 val;
+ int regno;
+};
+
+struct bpf_widen_thrs {
+ u32 cnt;
+ struct widen_thr thr[];
+};
+
+/* passes around a loop that widen to constants the loop compares with */
+#define WIDEN_THR_PASSES 4
+/* passes that widen to S32_MAX and the like, later ones drop the bound */
+#define WIDEN_GEN_PASSES 6
+/* states at the loop head differ in something that can't be widened */
+#define WIDEN_MAX_PASSES 10
+
+static const struct widen_thr widen_generic[] = {
+ { S32_MIN, -1 }, { 0, -1 }, { S32_MAX, -1 }, { U32_MAX, -1 },
+};
+
+static int cmp_widen_thr(const void *a, const void *b)
+{
+ s64 x = ((const struct widen_thr *)a)->val;
+ s64 y = ((const struct widen_thr *)b)->val;
+
+ return x < y ? -1 : x > y;
+}
+
+static bool is_cmp_imm(const struct bpf_insn *insn)
+{
+ u8 class = BPF_CLASS(insn->code);
+ u8 op = BPF_OP(insn->code);
+
+ if (class != BPF_JMP && class != BPF_JMP32)
+ return false;
+ if (BPF_SRC(insn->code) != BPF_K)
+ return false;
+ return op != BPF_JA && op != BPF_CALL && op != BPF_EXIT && op != BPF_JCOND;
+}
+
+/*
+ * Sorted constants that registers are compared with in the SCC of @insn_idx.
+ * A range that ends at one of them can be cut back by the exit test of
+ * the loop, so that the state at the loop head stops growing.
+ */
+static const struct bpf_widen_thrs *scc_thresholds(struct bpf_verifier_env *env, int insn_idx)
+{
+ struct bpf_insn_aux_data *aux = env->insn_aux_data;
+ struct bpf_insn *insns = env->prog->insnsi;
+ u32 scc = aux[insn_idx].scc;
+ struct bpf_widen_thrs *thrs;
+ int i, d, n = 0;
+
+ if (!scc)
+ return NULL;
+ if (!env->scc_thrs) {
+ env->scc_thrs = kvzalloc_objs(*env->scc_thrs, env->scc_cnt, GFP_KERNEL_ACCOUNT);
+ if (!env->scc_thrs)
+ return NULL;
+ }
+ if (env->scc_thrs[scc])
+ return env->scc_thrs[scc];
+
+ for (i = 0; i < env->prog->len; i++)
+ if (aux[i].scc == scc && is_cmp_imm(&insns[i]))
+ n++;
+ thrs = kvzalloc(struct_size(thrs, thr, 3 * n), GFP_KERNEL_ACCOUNT);
+ if (!thrs)
+ return NULL;
+ for (i = 0; i < env->prog->len; i++) {
+ if (aux[i].scc != scc || !is_cmp_imm(&insns[i]))
+ continue;
+ for (d = -1; d <= 1; d++) {
+ thrs->thr[thrs->cnt].val = (s64)insns[i].imm + d;
+ thrs->thr[thrs->cnt++].regno = insns[i].dst_reg;
+ }
+ }
+ sort(thrs->thr, thrs->cnt, sizeof(thrs->thr[0]), cmp_widen_thr, NULL);
+ env->scc_thrs[scc] = thrs;
+ return thrs;
+}
+
+/*
+ * Nearest constant in sorted @thr that is >= @x if @up, <= @x otherwise.
+ * Constants that another register is compared with are skipped.
+ */
+static bool thr_nearest(const struct widen_thr *thr, u32 cnt, int regno, s64 x, bool up,
+ s64 *res)
+{
+ bool found = false;
+ u32 i;
+
+ for (i = 0; i < cnt; i++) {
+ if (regno >= 0 && thr[i].regno >= 0 && thr[i].regno != regno)
+ continue;
+ if (up && thr[i].val >= x) {
+ *res = thr[i].val;
+ return true;
+ }
+ if (!up && thr[i].val <= x) {
+ *res = thr[i].val;
+ found = true;
+ }
+ }
+ return found;
+}
+
+struct widen_ctx {
+ const struct bpf_widen_thrs *thrs;
+ u32 passes;
+ int regno;
+};
+
+/* Where to move the end @x of a range that keeps moving up or down. */
+static bool widen_pick(const struct widen_ctx *w, s64 x, bool up, s64 *res)
+{
+ bool found = false;
+ s64 t;
+
+ if (w->passes <= WIDEN_THR_PASSES && w->thrs &&
+ thr_nearest(w->thrs->thr, w->thrs->cnt, w->regno, x, up, &t)) {
+ *res = t;
+ found = true;
+ }
+ if (w->passes <= WIDEN_GEN_PASSES &&
+ thr_nearest(widen_generic, ARRAY_SIZE(widen_generic), -1, x, up, &t)) {
+ *res = !found ? t : up ? min(*res, t) : max(*res, t);
+ found = true;
+ }
+ return found;
+}
+
+static s64 widen_smax(const struct widen_ctx *w, s64 x, s64 lim)
+{
+ s64 t;
+
+ return widen_pick(w, x, true, &t) && t <= lim ? t : lim;
+}
+
+static s64 widen_smin(const struct widen_ctx *w, s64 x, s64 lim)
+{
+ s64 t;
+
+ return widen_pick(w, x, false, &t) && t >= lim ? t : lim;
+}
+
+static u64 widen_umax(const struct widen_ctx *w, u64 x, u64 lim)
+{
+ s64 t;
+
+ if (x > S64_MAX || !widen_pick(w, x, true, &t) || (u64)t > lim)
+ return lim;
+ return t;
+}
+
+static u64 widen_umin(const struct widen_ctx *w, u64 x)
+{
+ s64 t;
+
+ if (!widen_pick(w, min_t(u64, x, S64_MAX), false, &t) || t < 0)
+ return 0;
+ return t;
+}
+
+/*
+ * @old is the state of a register at the loop head, @cur is its state after
+ * a trip around the loop. If @cur has values that @old doesn't have make @cur
+ * a guess of all the values the register can have at the loop head: both
+ * @old and @cur, and where an end of the range moved it is moved further,
+ * to the nearest constant the loop compares the register with.
+ * Whether the guess is good is seen on the next trip: the state that comes
+ * back has to be within it.
+ */
+static void widen_reg(const struct widen_ctx *w, const struct bpf_reg_state *old,
+ struct bpf_reg_state *cur)
+{
+ u64 umin, umax, low;
+ u32 u32_min, u32_max;
+ s32 s32_min, s32_max;
+ s64 smin, smax;
+ struct tnum t;
+
+ if (old->type != SCALAR_VALUE || cur->type != SCALAR_VALUE)
+ return;
+ if (cnum64_is_subset(old->r64, cur->r64) && cnum32_is_subset(old->r32, cur->r32) &&
+ tnum_in(old->var_off, cur->var_off))
+ return;
+
+ umin = min(reg_umin(old), reg_umin(cur));
+ umax = max(reg_umax(old), reg_umax(cur));
+ smin = min(reg_smin(old), reg_smin(cur));
+ smax = max(reg_smax(old), reg_smax(cur));
+ u32_min = min(reg_u32_min(old), reg_u32_min(cur));
+ u32_max = max(reg_u32_max(old), reg_u32_max(cur));
+ s32_min = min(reg_s32_min(old), reg_s32_min(cur));
+ s32_max = max(reg_s32_max(old), reg_s32_max(cur));
+
+ if (reg_umin(cur) < reg_umin(old))
+ umin = widen_umin(w, umin);
+ if (reg_umax(cur) > reg_umax(old))
+ umax = widen_umax(w, umax, U64_MAX);
+ if (reg_smin(cur) < reg_smin(old))
+ smin = widen_smin(w, smin, S64_MIN);
+ if (reg_smax(cur) > reg_smax(old))
+ smax = widen_smax(w, smax, S64_MAX);
+ if (reg_u32_min(cur) < reg_u32_min(old))
+ u32_min = widen_umin(w, u32_min);
+ if (reg_u32_max(cur) > reg_u32_max(old))
+ u32_max = widen_umax(w, u32_max, U32_MAX);
+ if (reg_s32_min(cur) < reg_s32_min(old))
+ s32_min = widen_smin(w, s32_min, S32_MIN);
+ if (reg_s32_max(cur) > reg_s32_max(old))
+ s32_max = widen_smax(w, s32_max, S32_MAX);
+
+ /* low bits that are the same in all values seen so far are kept, e.g. alignment */
+ t = tnum_union(old->var_off, cur->var_off);
+ low = t.mask ? BIT_ULL(__ffs64(t.mask)) - 1 : 0;
+ cur->var_off = (struct tnum){ .value = t.value & low, .mask = ~low };
+ cur->r64 = cnum64_intersect(cnum64_from_urange(umin, umax),
+ cnum64_from_srange(smin, smax));
+ cur->r32 = cnum32_intersect(cnum32_from_urange(u32_min, u32_max),
+ cnum32_from_srange(s32_min, s32_max));
+ cur->id = 0;
+ cur->delta = 0;
+ reg_bounds_sync(cur);
+}
+
+bool bpf_same_loop(struct bpf_verifier_state *old, struct bpf_verifier_state *cur)
+{
+ return old->speculative == cur->speculative && same_callsites(old, cur);
+}
+
+/*
+ * @cur came to loop head @insn_idx and is not within @old, the state that
+ * went around the loop. Widen scalars of @cur, so that the walk goes around
+ * the loop with a state that stands for many iterations, see widen_reg().
+ * Everything else is left as is. If that is what differs the states never
+ * converge and the walk is given up after a few trips.
+ */
+int bpf_widen_loop_head(struct bpf_verifier_env *env, int insn_idx, bool backedge,
+ struct bpf_verifier_state *old, struct bpf_verifier_state *cur)
+{
+ /* @old is of an earlier run of the loop if @cur just entered it */
+ u32 passes = backedge ? old->loop_passes + 1 : 1;
+ struct widen_ctx w = { scc_thresholds(env, insn_idx), passes };
+ struct bpf_func_state *fold, *fcur;
+ int i, fr, num_slots;
+
+ env->widen_used = true;
+ if (passes > WIDEN_MAX_PASSES) {
+ verbose(env, "states at loop head %d don't converge\n", insn_idx);
+ return -E2BIG;
+ }
+
+ for (fr = 0; fr <= cur->curframe; fr++) {
+ fold = old->frame[fr];
+ fcur = cur->frame[fr];
+
+ for (i = 0; i < BPF_REG_FP; i++) {
+ /* registers of callers are not the ones the loop compares */
+ w.regno = fr == cur->curframe ? i : -1;
+ widen_reg(&w, &fold->regs[i], &fcur->regs[i]);
+ }
+
+ w.regno = -1;
+ num_slots = min(fold->allocated_stack, fcur->allocated_stack) / BPF_REG_SIZE;
+ for (i = 0; i < num_slots; i++) {
+ if (!bpf_is_spilled_reg(&fold->stack[i]) ||
+ !bpf_is_spilled_reg(&fcur->stack[i]))
+ continue;
+ widen_reg(&w, &fold->stack[i].spilled_ptr, &fcur->stack[i].spilled_ptr);
+ }
+ }
+ cur->loop_passes = passes;
+ if (env->log.level & BPF_LOG_LEVEL2)
+ verbose(env, "loop head %d widened, pass %u\n", insn_idx, passes);
+ return 0;
+}
+
+static bool program_returns_void(struct bpf_verifier_env *env);
+static bool return_retval_range(struct bpf_verifier_env *env, struct bpf_retval_range *range);
+
+/* Why bpf_throw() cannot be called in @st, NULL if it can. */
+static const char *cannot_throw(struct bpf_verifier_env *env, struct bpf_verifier_state *st)
+{
+ struct bpf_retval_range range;
+ struct bpf_func_state *frame;
+ int i;
+
+ if (!env->prog->jit_requested || !bpf_jit_supports_exceptions())
+ return "JIT does not support exceptions";
+ for (i = 0; i < st->acquired_refs; i++)
+ if (st->refs[i].type == REF_TYPE_PTR)
+ return "reference is held";
+ if (st->active_locks || st->active_irq_id || st->active_rcu_locks ||
+ st->active_preempt_locks)
+ return "lock is held";
+ for (i = 0; i <= st->curframe; i++) {
+ frame = st->frame[i];
+ if (frame->in_callback_fn || frame->in_async_callback_fn ||
+ frame->in_exception_callback_fn)
+ return "in callback";
+ }
+ /* callers of the global function were not told that it can throw */
+ if (st->frame[0]->subprogno && !subprog_info(env, st->frame[0]->subprogno)->might_throw)
+ return "in global function";
+ /* default exception callback returns the cookie, that is 0 */
+ if (!env->exception_callback_subprog && !program_returns_void(env) &&
+ resolve_prog_type(env->prog) != BPF_PROG_TYPE_STRUCT_OPS &&
+ return_retval_range(env, &range) && (range.minval > 0 || range.maxval < 0))
+ return "0 is not a valid return value";
+ return NULL;
+}
+
+/*
+ * The walk went over the back-edge of env->prev_insn_idx and nothing bounds
+ * the number of trips. If the loop is not walked to the end may_goto that
+ * ends in bpf_throw() is added to the back-edge, see commit_loop_guards().
+ * Returns false when that cannot be done in state @cur.
+ */
+bool bpf_mark_loop_guard(struct bpf_verifier_env *env, struct bpf_verifier_state *cur)
+{
+ struct bpf_insn_aux_data *aux = &env->insn_aux_data[env->prev_insn_idx];
+ struct bpf_insn *insn = &env->prog->insnsi[env->prev_insn_idx];
+ u8 class = BPF_CLASS(insn->code);
+ u8 op = BPF_OP(insn->code);
+ const char *why;
+
+ why = cannot_throw(env, cur);
+ if ((class != BPF_JMP && class != BPF_JMP32) ||
+ op == BPF_CALL || op == BPF_EXIT || op == BPF_JCOND ||
+ (op == BPF_JA && BPF_SRC(insn->code) == BPF_X))
+ why = "not a jump";
+ else if (op != BPF_JA && aux->backedge_ft && aux->backedge_br)
+ why = "both edges are back-edges";
+ if (why) {
+ if (env->log.level & BPF_LOG_LEVEL2)
+ verbose(env, "cannot add may_goto to back-edge of insn %d: %s\n",
+ env->prev_insn_idx, why);
+ aux->guard_impossible = true;
+ return false;
+ }
+ aux->guard_pending = true;
+ return true;
+}
+
/*
* Check if scalar registers are exact for the purpose of not widening.
* More lenient than regs_exact()
@@ -18847,6 +19259,21 @@ static int do_check_insn(struct bpf_verifier_env *env, bool *do_print_state)
return -EFAULT;
}
+/* Did the jump at @prev take the walk out of the loop @prev is in? */
+static bool left_loop(struct bpf_verifier_env *env, int prev, int insn_idx)
+{
+ struct bpf_insn_aux_data *aux = env->insn_aux_data;
+ struct bpf_insn *insn;
+
+ if (prev < 0 || prev >= env->prog->len || !aux[prev].scc ||
+ aux[prev].scc == aux[insn_idx].scc)
+ return false;
+ /* the callee is not in SCC of the call, the insn after the call is */
+ insn = &env->prog->insnsi[prev];
+ return !((BPF_CLASS(insn->code) == BPF_JMP || BPF_CLASS(insn->code) == BPF_JMP32) &&
+ BPF_OP(insn->code) == BPF_CALL);
+}
+
static int do_check(struct bpf_verifier_env *env)
{
bool pop_log = !(env->log.level & BPF_LOG_LEVEL2);
@@ -18885,6 +19312,8 @@ static int do_check(struct bpf_verifier_env *env)
state->last_insn_idx = env->prev_insn_idx;
state->insn_idx = env->insn_idx;
+ if (env->widen_loops && left_loop(env, prev_insn_idx, env->insn_idx))
+ bpf_scc_mark_exit(env, state, prev_insn_idx);
/*
* Record the incoming edge so active and queued paths use the same
* branch-recording path. A zero-offset conditional has identical
@@ -18907,7 +19336,9 @@ static int do_check(struct bpf_verifier_env *env)
}
}
- if (bpf_is_prune_point(env, env->insn_idx)) {
+ /* loop heads are where states are widened, all of them have to be looked at */
+ if (bpf_is_prune_point(env, env->insn_idx) ||
+ (env->widen_loops && insn_aux->loop_head)) {
err = bpf_is_state_visited(env, env->insn_idx);
if (err < 0)
return err;
@@ -19011,6 +19442,9 @@ static int do_check(struct bpf_verifier_env *env)
} else if (err < 0) {
return err;
} else if (err == PROCESS_BPF_EXIT) {
+ /* exit or bpf_throw() inside of a loop */
+ if (env->widen_loops)
+ bpf_scc_mark_exit(env, state, env->insn_idx);
goto process_bpf_exit;
} else if (err == INSN_IDX_UPDATED) {
} else if (err == 0) {
@@ -20102,6 +20536,122 @@ static int do_check_common(struct bpf_verifier_env *env, int subprog)
return ret;
}
+/* What a walk changes outside of verifier states and per insn data. */
+struct walk_snapshot {
+ struct bpf_insn_aux_data *insn_aux;
+ struct bpf_func_info_aux *func_aux;
+ struct bpf_subprog_info *subprogs;
+ struct bpf_prog *prog;
+ u64 log_pos, diag_pos;
+ u32 insn_processed, prev_insn_processed;
+ u32 jmps_processed, prev_jmps_processed;
+ u32 total_states, peak_states, max_states_per_insn, longest_mark_read_walk;
+ u32 explored_states_size, free_list_size, num_backedges;
+ u32 id_gen, pass_cnt, max_stack_depth;
+ u32 max_ctx_offset, max_pkt_offset, max_tp_access, max_rdonly_access, max_rdwr_access;
+ bool seen_direct_write, seen_exception, explore_alu_limits, tail_call_reachable;
+ void *arena;
+};
+
+static void walk_snapshot_free(struct walk_snapshot *s)
+{
+ kvfree(s->insn_aux);
+ kvfree(s->func_aux);
+ kvfree(s->subprogs);
+ kfree(s->prog);
+}
+
+static size_t func_aux_size(struct bpf_verifier_env *env)
+{
+ return array_size(env->prog->aux->func_info_cnt, sizeof(*env->prog->aux->func_info_aux));
+}
+
+static int walk_snapshot_save(struct bpf_verifier_env *env, struct walk_snapshot *s)
+{
+ struct bpf_prog_aux *aux = env->prog->aux;
+
+ memset(s, 0, sizeof(*s));
+ s->insn_aux = kvmemdup(env->insn_aux_data,
+ array_size(env->prog->len, sizeof(*env->insn_aux_data)),
+ GFP_KERNEL_ACCOUNT);
+ s->subprogs = kvmemdup(env->subprog_info, sizeof(env->subprog_info), GFP_KERNEL_ACCOUNT);
+ /* flags of the program, not its insns */
+ s->prog = kmemdup(env->prog, offsetof(struct bpf_prog, insnsi), GFP_KERNEL_ACCOUNT);
+ if (aux->func_info_aux)
+ s->func_aux = kvmemdup(aux->func_info_aux, func_aux_size(env), GFP_KERNEL_ACCOUNT);
+ if (!s->insn_aux || !s->subprogs || !s->prog || (aux->func_info_aux && !s->func_aux)) {
+ walk_snapshot_free(s);
+ return -ENOMEM;
+ }
+ s->log_pos = env->log.end_pos;
+ s->diag_pos = bpf_diag_event_log_save(env);
+ s->insn_processed = env->insn_processed;
+ s->prev_insn_processed = env->prev_insn_processed;
+ s->jmps_processed = env->jmps_processed;
+ s->prev_jmps_processed = env->prev_jmps_processed;
+ s->total_states = env->total_states;
+ s->peak_states = env->peak_states;
+ s->max_states_per_insn = env->max_states_per_insn;
+ s->longest_mark_read_walk = env->longest_mark_read_walk;
+ s->explored_states_size = env->explored_states_size;
+ s->free_list_size = env->free_list_size;
+ s->num_backedges = env->num_backedges;
+ s->id_gen = env->id_gen;
+ s->pass_cnt = env->pass_cnt;
+ s->max_stack_depth = env->max_stack_depth;
+ s->seen_direct_write = env->seen_direct_write;
+ s->seen_exception = env->seen_exception;
+ s->explore_alu_limits = env->explore_alu_limits;
+ s->max_ctx_offset = aux->max_ctx_offset;
+ s->max_pkt_offset = aux->max_pkt_offset;
+ s->max_tp_access = aux->max_tp_access;
+ s->max_rdonly_access = aux->max_rdonly_access;
+ s->max_rdwr_access = aux->max_rdwr_access;
+ s->tail_call_reachable = aux->tail_call_reachable;
+ s->arena = aux->arena;
+ return 0;
+}
+
+static void walk_snapshot_restore(struct bpf_verifier_env *env, struct walk_snapshot *s)
+{
+ struct bpf_prog_aux *aux = env->prog->aux;
+
+ memcpy(env->insn_aux_data, s->insn_aux,
+ array_size(env->prog->len, sizeof(*env->insn_aux_data)));
+ memcpy(env->subprog_info, s->subprogs, sizeof(env->subprog_info));
+ memcpy(env->prog, s->prog, offsetof(struct bpf_prog, insnsi));
+ if (s->func_aux)
+ memcpy(aux->func_info_aux, s->func_aux, func_aux_size(env));
+ env->insn_wasted += env->insn_processed - s->insn_processed;
+ env->insn_processed = s->insn_processed;
+ env->prev_insn_processed = s->prev_insn_processed;
+ env->jmps_processed = s->jmps_processed;
+ env->prev_jmps_processed = s->prev_jmps_processed;
+ env->total_states = s->total_states;
+ env->peak_states = s->peak_states;
+ env->max_states_per_insn = s->max_states_per_insn;
+ env->longest_mark_read_walk = s->longest_mark_read_walk;
+ env->explored_states_size = s->explored_states_size;
+ env->free_list_size = s->free_list_size;
+ env->num_backedges = s->num_backedges;
+ env->id_gen = s->id_gen;
+ env->pass_cnt = s->pass_cnt;
+ env->max_stack_depth = s->max_stack_depth;
+ env->seen_direct_write = s->seen_direct_write;
+ env->seen_exception = s->seen_exception;
+ env->explore_alu_limits = s->explore_alu_limits;
+ aux->max_ctx_offset = s->max_ctx_offset;
+ aux->max_pkt_offset = s->max_pkt_offset;
+ aux->max_tp_access = s->max_tp_access;
+ aux->max_rdonly_access = s->max_rdonly_access;
+ aux->max_rdwr_access = s->max_rdwr_access;
+ aux->tail_call_reachable = s->tail_call_reachable;
+ aux->arena = s->arena;
+ if (!(env->log.level & BPF_LOG_LEVEL2))
+ bpf_vlog_reset(&env->log, s->log_pos);
+ bpf_diag_event_log_restore(env, s->diag_pos);
+}
+
/* Lazily verify all global functions based on their BTF, if they are called
* from main BPF program or any of subprograms transitively.
* BPF global subprogs called from dead code are not validated.
@@ -20183,6 +20733,51 @@ static int do_check_main(struct bpf_verifier_env *env)
return ret;
}
+/*
+ * Walk the program with loops widened first. It is much less work when it
+ * succeeds. If it fails the reason can be the precision that widening gave
+ * up. Then undo everything that walk did, so that the walk of every
+ * iteration that follows can't tell that it is not the first one.
+ * It is all or nothing for the main program and global functions, because
+ * may_goto added to a loop of a static function is there for all callers.
+ */
+static int do_check_prog(struct bpf_verifier_env *env)
+{
+ struct walk_snapshot snap;
+ int ret;
+
+ /* no loops without bpf_capable, the driver of an offloaded prog sees every insn visit */
+ if (!env->bpf_capable || env->scc_cnt <= 1 || bpf_prog_is_offloaded(env->prog->aux)) {
+ ret = do_check_main(env);
+ return ret ?: do_check_subprogs(env);
+ }
+
+ env->scc_converged = kvzalloc_objs(*env->scc_converged, BITS_TO_LONGS(env->scc_cnt),
+ GFP_KERNEL_ACCOUNT);
+ if (!env->scc_converged)
+ return -ENOMEM;
+ ret = walk_snapshot_save(env, &snap);
+ if (ret)
+ return ret;
+
+ env->widen_loops = true;
+ env->widen_used = false;
+ ret = do_check_main(env);
+ ret = ret ?: do_check_subprogs(env);
+ if (!ret && env->widen_used)
+ ret = bpf_commit_loop_guards(env);
+ env->widen_loops = false;
+ if (ret && ret != -ENOMEM && ret != -EAGAIN && ret != -EFAULT && env->widen_used) {
+ walk_snapshot_restore(env, &snap);
+ if (env->log.level & BPF_LOG_LEVEL)
+ verbose(env, "walk with widened loops failed, walking every iteration\n");
+ ret = do_check_main(env);
+ ret = ret ?: do_check_subprogs(env);
+ }
+ walk_snapshot_free(&snap);
+ return ret;
+}
+
static void print_verification_stats(struct bpf_verifier_env *env)
{
/* Skip over hidden subprogs which are not verified. */
@@ -20211,6 +20806,9 @@ static void print_verification_stats(struct bpf_verifier_env *env)
env->insn_processed, BPF_COMPLEXITY_LIMIT_INSNS,
env->max_states_per_insn, env->total_states,
env->peak_states, env->longest_mark_read_walk);
+ if (env->insn_wasted)
+ verbose(env, "walks with widened loops that failed processed %d insns\n",
+ env->insn_wasted);
}
int bpf_prog_ctx_arg_info_init(struct bpf_prog *prog,
@@ -21853,8 +22451,7 @@ int bpf_check(struct bpf_prog **prog, union bpf_attr *attr, bpfptr_t uattr,
if (ret < 0)
goto skip_full_check;
- ret = do_check_main(env);
- ret = ret ?: do_check_subprogs(env);
+ ret = do_check_prog(env);
if (ret == 0 && bpf_prog_is_offloaded(env->prog->aux))
ret = bpf_prog_offload_finalize(env);
@@ -21996,6 +22593,12 @@ int bpf_check(struct bpf_prog **prog, union bpf_attr *attr, bpfptr_t uattr,
bpf_stack_liveness_free(env);
kvfree(env->cfg.insn_postorder);
kvfree(env->scc_info);
+ kvfree(env->scc_converged);
+ if (env->scc_thrs) {
+ for (i = 0; i < env->scc_cnt; i++)
+ kvfree(env->scc_thrs[i]);
+ kvfree(env->scc_thrs);
+ }
kvfree(env->succ);
kvfree(env->gotox_tmp_buf);
bpf_diag_free(env);
diff --git a/tools/testing/selftests/bpf/prog_tests/bpf_verif_scale.c b/tools/testing/selftests/bpf/prog_tests/bpf_verif_scale.c
index 902a70d5afeb6..2dc37090d7a4f 100644
--- a/tools/testing/selftests/bpf/prog_tests/bpf_verif_scale.c
+++ b/tools/testing/selftests/bpf/prog_tests/bpf_verif_scale.c
@@ -154,9 +154,9 @@ void test_verif_scale_loop2()
scale_test("loop2.bpf.o", BPF_PROG_TYPE_RAW_TRACEPOINT, false);
}
-void test_verif_scale_loop3_fail()
+void test_verif_scale_loop3()
{
- scale_test("loop3.bpf.o", BPF_PROG_TYPE_RAW_TRACEPOINT, true /* fails */);
+ scale_test("loop3.bpf.o", BPF_PROG_TYPE_RAW_TRACEPOINT, false);
}
void test_verif_scale_loop4()
diff --git a/tools/testing/selftests/bpf/prog_tests/verifier.c b/tools/testing/selftests/bpf/prog_tests/verifier.c
index 4f1e1c1cd5ab3..5bed8f9587772 100644
--- a/tools/testing/selftests/bpf/prog_tests/verifier.c
+++ b/tools/testing/selftests/bpf/prog_tests/verifier.c
@@ -65,6 +65,7 @@
#include "verifier_live_stack.skel.h"
#include "verifier_liveness_exp.skel.h"
#include "verifier_load_acquire.skel.h"
+#include "verifier_loop_widen.skel.h"
#include "verifier_loops1.skel.h"
#include "verifier_lwt.skel.h"
#include "verifier_map_in_map.skel.h"
@@ -234,6 +235,7 @@ void test_verifier_leak_ptr(void) { RUN(verifier_leak_ptr); }
void test_verifier_linked_scalars(void) { RUN(verifier_linked_scalars); }
void test_verifier_live_stack(void) { RUN(verifier_live_stack); }
void test_verifier_liveness_exp(void) { RUN(verifier_liveness_exp); }
+void test_verifier_loop_widen(void) { RUN(verifier_loop_widen); }
void test_verifier_loops1(void) { RUN(verifier_loops1); }
void test_verifier_lwt(void) { RUN(verifier_lwt); }
void test_verifier_map_in_map(void) { RUN(verifier_map_in_map); }
diff --git a/tools/testing/selftests/bpf/progs/verifier_cfg.c b/tools/testing/selftests/bpf/progs/verifier_cfg.c
index 3c3bb03e8217a..700eadf5d430a 100644
--- a/tools/testing/selftests/bpf/progs/verifier_cfg.c
+++ b/tools/testing/selftests/bpf/progs/verifier_cfg.c
@@ -98,8 +98,8 @@ l0_%=: r1 = r0; \
SEC("socket")
__description("conditional loop")
-__failure __msg("infinite loop detected")
-__msg_unpriv("back-edge")
+__success
+__failure_unpriv __msg_unpriv("back-edge")
__naked void conditional_loop(void)
{
asm volatile (" \
diff --git a/tools/testing/selftests/bpf/progs/verifier_loop_widen.c b/tools/testing/selftests/bpf/progs/verifier_loop_widen.c
new file mode 100644
index 0000000000000..4bdfc198bfaa8
--- /dev/null
+++ b/tools/testing/selftests/bpf/progs/verifier_loop_widen.c
@@ -0,0 +1,344 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Loops that are verified by widening the state at the loop head. */
+
+#include <linux/bpf.h>
+#include <bpf/bpf_helpers.h>
+#include "bpf_misc.h"
+
+struct small_val {
+ char buf[400];
+};
+
+struct big_val {
+ char buf[1000000];
+};
+
+struct {
+ __uint(type, BPF_MAP_TYPE_ARRAY);
+ __uint(max_entries, 1);
+ __type(key, int);
+ __type(value, struct small_val);
+} map_small SEC(".maps");
+
+struct {
+ __uint(type, BPF_MAP_TYPE_ARRAY);
+ __uint(max_entries, 1);
+ __type(key, int);
+ __type(value, struct big_val);
+} map_big SEC(".maps");
+
+struct {
+ __uint(type, BPF_MAP_TYPE_RINGBUF);
+ __uint(max_entries, 4096);
+} ringbuf SEC(".maps");
+
+#define LOOKUP(map) \
+ "r1 = 0;" \
+ "*(u64*)(r10 - 8) = r1;" \
+ "r2 = r10;" \
+ "r2 += -8;" \
+ "r1 = %[" #map "] ll;" \
+ "call %[bpf_map_lookup_elem];" \
+ "if r0 == 0 goto l_exit_%=;" \
+ "r7 = r0;"
+
+/* counter steps by 4 and the loop is left on '!=', 100 trips */
+SEC("socket")
+__success
+__naked void stride4_ne_100(void)
+{
+ asm volatile (
+ LOOKUP(map_small)
+ "r6 = 0;"
+"l_loop_%=:"
+ "r1 = r7;"
+ "r1 += r6;"
+ "r0 = *(u32*)(r1 + 0);"
+ "r6 += 4;"
+ "if r6 != 400 goto l_loop_%=;"
+"l_exit_%=:"
+ "r0 = 0;"
+ "exit;"
+ :
+ : __imm(bpf_map_lookup_elem), __imm_addr(map_small)
+ : __clobber_all);
+}
+
+/* same loop, 250000 trips, too many to walk every one of them */
+SEC("socket")
+__success
+__naked void stride4_ne_250k(void)
+{
+ asm volatile (
+ LOOKUP(map_big)
+ "r6 = 0;"
+"l_loop_%=:"
+ "r1 = r7;"
+ "r1 += r6;"
+ "r0 = *(u32*)(r1 + 0);"
+ "r6 += 4;"
+ "if r6 != 1000000 goto l_loop_%=;"
+"l_exit_%=:"
+ "r0 = 0;"
+ "exit;"
+ :
+ : __imm(bpf_map_lookup_elem), __imm_addr(map_big)
+ : __clobber_all);
+}
+
+/* 8 byte stride, 32-bit counter */
+SEC("socket")
+__success
+__naked void stride8_ne_w_125k(void)
+{
+ asm volatile (
+ LOOKUP(map_big)
+ "w6 = 0;"
+"l_loop_%=:"
+ "r1 = r7;"
+ "r1 += r6;"
+ "r0 = *(u64*)(r1 + 0);"
+ "w6 += 8;"
+ "if w6 != 1000000 goto l_loop_%=;"
+"l_exit_%=:"
+ "r0 = 0;"
+ "exit;"
+ :
+ : __imm(bpf_map_lookup_elem), __imm_addr(map_big)
+ : __clobber_all);
+}
+
+/* counts down by 4 to zero */
+SEC("socket")
+__success
+__naked void stride4_down_250k(void)
+{
+ asm volatile (
+ LOOKUP(map_big)
+ "r6 = 1000000;"
+"l_loop_%=:"
+ "r6 += -4;"
+ "r1 = r7;"
+ "r1 += r6;"
+ "r0 = *(u32*)(r1 + 0);"
+ "if r6 != 0 goto l_loop_%=;"
+"l_exit_%=:"
+ "r0 = 0;"
+ "exit;"
+ :
+ : __imm(bpf_map_lookup_elem), __imm_addr(map_big)
+ : __clobber_all);
+}
+
+/* step of 1 and '<', no alignment to make use of */
+SEC("socket")
+__success
+__naked void stride1_lt_1m(void)
+{
+ asm volatile (
+ LOOKUP(map_big)
+ "r6 = 0;"
+"l_loop_%=:"
+ "r1 = r7;"
+ "r1 += r6;"
+ "r0 = *(u8*)(r1 + 0);"
+ "r6 += 1;"
+ "if r6 < 1000000 goto l_loop_%=;"
+"l_exit_%=:"
+ "r0 = 0;"
+ "exit;"
+ :
+ : __imm(bpf_map_lookup_elem), __imm_addr(map_big)
+ : __clobber_all);
+}
+
+/* two loops, one in the other */
+SEC("socket")
+__success
+__naked void nested_stride4(void)
+{
+ asm volatile (
+ LOOKUP(map_big)
+ "r8 = 0;"
+"l_outer_%=:"
+ "r6 = 0;"
+"l_loop_%=:"
+ "r1 = r7;"
+ "r1 += r6;"
+ "r0 = *(u32*)(r1 + 0);"
+ "r6 += 4;"
+ "if r6 != 1000000 goto l_loop_%=;"
+ "r8 += 1;"
+ "if r8 != 1000 goto l_outer_%=;"
+"l_exit_%=:"
+ "r0 = 0;"
+ "exit;"
+ :
+ : __imm(bpf_map_lookup_elem), __imm_addr(map_big)
+ : __clobber_all);
+}
+
+/* the last trip reads 4 bytes at offset 400 of 400 */
+SEC("socket")
+__failure __msg("invalid access to map value")
+__naked void stride4_ne_one_too_many(void)
+{
+ asm volatile (
+ LOOKUP(map_small)
+ "r6 = 0;"
+"l_loop_%=:"
+ "r1 = r7;"
+ "r1 += r6;"
+ "r0 = *(u32*)(r1 + 0);"
+ "r6 += 4;"
+ "if r6 != 404 goto l_loop_%=;"
+"l_exit_%=:"
+ "r0 = 0;"
+ "exit;"
+ :
+ : __imm(bpf_map_lookup_elem), __imm_addr(map_small)
+ : __clobber_all);
+}
+
+/* same with too many trips to walk */
+SEC("socket")
+__failure __msg("BPF program is too large")
+__naked void stride4_ne_250k_one_too_many(void)
+{
+ asm volatile (
+ LOOKUP(map_big)
+ "r6 = 0;"
+"l_loop_%=:"
+ "r1 = r7;"
+ "r1 += r6;"
+ "r0 = *(u32*)(r1 + 0);"
+ "r6 += 4;"
+ "if r6 != 1000004 goto l_loop_%=;"
+"l_exit_%=:"
+ "r0 = 0;"
+ "exit;"
+ :
+ : __imm(bpf_map_lookup_elem), __imm_addr(map_big)
+ : __clobber_all);
+}
+
+/* the counter never equals the bound and reads out of bounds */
+SEC("socket")
+__failure __msg("BPF program is too large")
+__naked void stride4_ne_misses_bound(void)
+{
+ asm volatile (
+ LOOKUP(map_big)
+ "r6 = 0;"
+"l_loop_%=:"
+ "r1 = r7;"
+ "r1 += r6;"
+ "r0 = *(u32*)(r1 + 0);"
+ "r6 += 4;"
+ "if r6 != 999998 goto l_loop_%=;"
+"l_exit_%=:"
+ "r0 = 0;"
+ "exit;"
+ :
+ : __imm(bpf_map_lookup_elem), __imm_addr(map_big)
+ : __clobber_all);
+}
+
+/* the value read after the loop is at the exit value of the counter */
+SEC("socket")
+__failure __msg("BPF program is too large")
+__naked void stride4_ne_use_after_loop(void)
+{
+ asm volatile (
+ LOOKUP(map_big)
+ "r6 = 0;"
+"l_loop_%=:"
+ "r1 = r7;"
+ "r1 += r6;"
+ "r0 = *(u32*)(r1 + 0);"
+ "r6 += 4;"
+ "if r6 != 1000000 goto l_loop_%=;"
+ "r1 = r7;"
+ "r1 += r6;"
+ "r0 = *(u32*)(r1 + 0);"
+"l_exit_%=:"
+ "r0 = 0;"
+ "exit;"
+ :
+ : __imm(bpf_map_lookup_elem), __imm_addr(map_big)
+ : __clobber_all);
+}
+
+/*
+ * Nothing in the loop changes what it tests. may_goto that the verifier
+ * adds to the back-edge ends the program: 0 is returned instead of 2.
+ */
+SEC("socket")
+__success __retval(0)
+__naked void spin_until_flag(void)
+{
+ asm volatile (
+ LOOKUP(map_small)
+"l_loop_%=:"
+ "r0 = *(u32*)(r7 + 0);"
+ "if r0 == 0 goto l_loop_%=;"
+ "r0 = 2;"
+ "exit;"
+"l_exit_%=:"
+ "r0 = 1;"
+ "exit;"
+ :
+ : __imm(bpf_map_lookup_elem), __imm_addr(map_small)
+ : __clobber_all);
+}
+
+/* same with the back-edge that is not a conditional jump */
+SEC("socket")
+__success __retval(0)
+__naked void spin_until_flag_ja(void)
+{
+ asm volatile (
+ LOOKUP(map_small)
+"l_loop_%=:"
+ "r0 = *(u32*)(r7 + 0);"
+ "if r0 != 0 goto l_done_%=;"
+ "goto l_loop_%=;"
+"l_done_%=:"
+ "r0 = 2;"
+ "exit;"
+"l_exit_%=:"
+ "r0 = 1;"
+ "exit;"
+ :
+ : __imm(bpf_map_lookup_elem), __imm_addr(map_small)
+ : __clobber_all);
+}
+
+/* may_goto cannot end the program that holds a reference, every iteration is walked */
+SEC("socket")
+__success __retval(0)
+__naked void loop_with_reference(void)
+{
+ asm volatile (
+ "r1 = %[ringbuf] ll;"
+ "r2 = 8;"
+ "r3 = 0;"
+ "call %[bpf_ringbuf_reserve];"
+ "if r0 == 0 goto l_exit_%=;"
+ "r7 = r0;"
+ "r6 = 0;"
+"l_loop_%=:"
+ "r6 += 1;"
+ "if r6 != 100 goto l_loop_%=;"
+ "r1 = r7;"
+ "r2 = 0;"
+ "call %[bpf_ringbuf_discard];"
+"l_exit_%=:"
+ "r0 = 0;"
+ "exit;"
+ :
+ : __imm(bpf_ringbuf_reserve), __imm(bpf_ringbuf_discard), __imm_addr(ringbuf)
+ : __clobber_all);
+}
+
+char _license[] SEC("license") = "GPL";
diff --git a/tools/testing/selftests/bpf/progs/verifier_movsx.c b/tools/testing/selftests/bpf/progs/verifier_movsx.c
index 195b27a51224f..280ccee336635 100644
--- a/tools/testing/selftests/bpf/progs/verifier_movsx.c
+++ b/tools/testing/selftests/bpf/progs/verifier_movsx.c
@@ -226,7 +226,7 @@ l0_%=: \
SEC("socket")
__description("MOV32SX, S8, var_off u32_max")
-__failure __msg("infinite loop detected")
+__success
__failure_unpriv __msg_unpriv("back-edge from insn 2 to 0")
__naked void mov64sx_s32_varoff_1(void)
{
diff --git a/tools/testing/selftests/bpf/progs/verifier_precision.c b/tools/testing/selftests/bpf/progs/verifier_precision.c
index f4459561bf393..88358586e7964 100644
--- a/tools/testing/selftests/bpf/progs/verifier_precision.c
+++ b/tools/testing/selftests/bpf/progs/verifier_precision.c
@@ -152,22 +152,21 @@ __naked int bpf_store_release(void)
SEC("?raw_tp")
__success __log_level(2)
/*
- * Without the bug fix there will be no history between "last_idx 3 first_idx 3"
- * and "parent state regs=" lines. "R0=6" parts are here to help anchor
- * expected log messages to the one specific mark_chain_precision operation.
- *
- * This is quite fragile: if verifier checkpointing heuristic changes, this
- * might need adjusting.
+ * The state is widened when it comes back to the loop head, so the exit test
+ * is decided only on the first trip around the loop. "R0=2" parts are here to
+ * help anchor expected log messages to that mark_chain_precision operation.
*/
-__msg("2: (07) r0 += 1 ; R0=6")
+__msg("2: (07) r0 += 1 ; R0=2")
__msg("3: (35) if r0 >= 0xa goto pc+1")
-__msg("mark_precise: frame0: last_idx 3 first_idx 3 subseq_idx -1")
+__msg("mark_precise: frame0: last_idx 3 first_idx 1 subseq_idx -1")
__msg("mark_precise: frame0: regs=r0 stack= before 2: (07) r0 += 1")
__msg("mark_precise: frame0: regs=r0 stack= before 1: (07) r0 += 1")
-__msg("mark_precise: frame0: regs=r0 stack= before 4: (05) goto pc-4")
-__msg("mark_precise: frame0: regs=r0 stack= before 3: (35) if r0 >= 0xa goto pc+1")
-__msg("mark_precise: frame0: parent state regs= stack=: R0=P4")
-__msg("3: R0=6")
+__msg("mark_precise: frame0: parent state regs=r0 stack=: R0=P0")
+__msg("mark_precise: frame0: last_idx 0 first_idx 0 subseq_idx 1")
+__msg("mark_precise: frame0: regs=r0 stack= before 0: (b7) r0 = 0")
+__msg("3: R0=2")
+__msg("loop head 1 widened, pass 1")
+__msg("1: safe")
__naked int state_loop_first_last_equal(void)
{
asm volatile (
@@ -175,11 +174,7 @@ __naked int state_loop_first_last_equal(void)
"l0_%=:"
"r0 += 1;"
"r0 += 1;"
- /* every few iterations we'll have a checkpoint here with
- * first_idx == last_idx, potentially confusing precision
- * backtracking logic
- */
- "if r0 >= 10 goto l1_%=;" /* checkpoint + mark_precise */
+ "if r0 >= 10 goto l1_%=;" /* mark_precise */
"goto l0_%=;"
"l1_%=:"
"exit;"
diff --git a/tools/testing/selftests/bpf/progs/verifier_search_pruning.c b/tools/testing/selftests/bpf/progs/verifier_search_pruning.c
index f40e57251e941..7098b44faafc5 100644
--- a/tools/testing/selftests/bpf/progs/verifier_search_pruning.c
+++ b/tools/testing/selftests/bpf/progs/verifier_search_pruning.c
@@ -341,8 +341,7 @@ l0_%=: r1 = 42; \
* test would take a very long time to verify.
*/
SEC("kprobe")
-__failure __log_level(4)
-__msg("BPF program is too large.")
+__success
__naked void short_loop1(void)
{
asm volatile (
diff --git a/tools/testing/selftests/bpf/verifier/calls.c b/tools/testing/selftests/bpf/verifier/calls.c
index 8b94b87135bcf..c7c501bfc660a 100644
--- a/tools/testing/selftests/bpf/verifier/calls.c
+++ b/tools/testing/selftests/bpf/verifier/calls.c
@@ -559,8 +559,9 @@
BPF_EXIT_INSN(),
},
.prog_type = BPF_PROG_TYPE_SCHED_CLS,
- .errstr = "infinite loop detected",
- .result = REJECT,
+ /* may_goto ends the loop after 250ms, do not run it */
+ .result = ACCEPT,
+ .runs = -1,
},
{
"calls: using r0 returned by callee",
|
| 3/2 | 2026/09/26 03:30 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 26916 output: 33 thoughts: 664 Thoughts: **My Assessment of the BPF Verifier Patch** Okay, here's what I'm seeing: there's a patch submitted for review, and my initial impression is that it's substantial. This looks like a deep dive into the BPF verifier, specifically implementing loop widening. Looking at the file list, the changes span across the BPF subsystem: `kernel/bpf/cfg.c`, `kernel/bpf/fixups.c`, `kernel/bpf/states.c`, `kernel/bpf/verifier.c`, and even the header `include/linux/bpf_verifier.h`. That alone tells me this isn't a trivial bug fix; it's a feature addition that impacts several core components. The patch itself extends several structures related to the verifier's state and operation: `bpf_verifier_state`, `bpf_insn_aux_data`, `bpf_scc_visit`, and `bpf_verifier_env`. We're looking at things like recording loop heads, backedge targets, and loop guards in `cfg.c`. The `fixups.c` changes include guard jumps, loop guard additions, and hooks into existing fixup routines. `states.c` is heavily modified, handling strongly connected component (SCC) exit tracking, backedge detection, and core loop widening logic. The changes to `verifier.c` are extensive. We're talking about new helper functions for tightening numeric ranges (`tnum_member_ge`, `tnum_member_le`, etc.) based on loop constraints. There are loop widening threshold checks, functions to mark loop guards, and important additions for state snapshotting and restoration. It seems the verifier can now attempt widening, and if that fails, it will fall back to walking every iteration. The core verification function `bpf_check` is being updated to use `do_check_prog`. This is a significant architectural change to the verifier, and it looks like a considerable amount of new logic. Given the scope and impact, this is definitely a major feature addition to the BPF verifier. BPF is, of course, accessible from userspace through the `bpf(BPF_PROG_LOAD, ...)` syscall. Because it's a Core Subsystem (Section 3), any logic modifications within are worth scrutinizing from a fuzzing perspective, and the verifier is a critical component of BPF. Is this code reachable? Absolutely. Any user (or root/CAP_BPF) can load BPF programs, which directly calls `bpf_check`, the function that is being changed here. Given that Syzkaller fuzzes BPF extensively, this is a prime target for fuzzing. Therefore, from a security standpoint, `WorthFuzzing=true`. Now, I'll need to check the Kconfig requirements and relevant symbols. I'll use `grepper` or check the kernel/bpf/Makefile or Kconfig files to get a clearer picture of the configurations. |
| 4/2 | 2026/09/26 03:30 | tool | grepper |
0mArgs:{
"Expression": "obj-\\$\\(CONFIG_.*BPF",
"PathPrefix": "kernel/bpf"
}Results: {
"Output": "kernel/bpf/Makefile=7=CFLAGS_core.o += -Wno-override-init $(cflags-nogcse-yy)\nkernel/bpf/Makefile-8-\nkernel/bpf/Makefile:9:obj-$(CONFIG_BPF_SYSCALL) += syscall.o verifier.o inode.o helpers.o tnum.o cnum.o log.o token.o liveness.o const_fold.o diagnostics.o\nkernel/bpf/Makefile:10:obj-$(CONFIG_BPF_SYSCALL) += bpf_iter.o map_iter.o task_iter.o prog_iter.o link_iter.o\nkernel/bpf/Makefile:11:obj-$(CONFIG_BPF_SYSCALL) += hashtab.o arraymap.o percpu_freelist.o bpf_lru_list.o lpm_trie.o map_in_map.o bloom_filter.o\nkernel/bpf/Makefile:12:obj-$(CONFIG_BPF_SYSCALL) += local_storage.o queue_stack_maps.o ringbuf.o bpf_insn_array.o\nkernel/bpf/Makefile:13:obj-$(CONFIG_BPF_SYSCALL) += bpf_local_storage.o bpf_task_storage.o\nkernel/bpf/Makefile:14:obj-$(CONFIG_BPF_SYSCALL) += fixups.o cfg.o states.o backtrack.o check_btf.o\nkernel/bpf/Makefile-15-obj-${CONFIG_BPF_LSM}\t += bpf_inode_storage.o\nkernel/bpf/Makefile:16:obj-$(CONFIG_BPF_SYSCALL) += disasm.o mprog.o\nkernel/bpf/Makefile:17:obj-$(CONFIG_BPF_JIT) += trampoline.o\nkernel/bpf/Makefile:18:obj-$(CONFIG_BPF_SYSCALL) += btf.o memalloc.o rqspinlock.o stream.o\nkernel/bpf/Makefile-19-ifeq ($(CONFIG_MMU)$(CONFIG_64BIT),yy)\nkernel/bpf/Makefile:20:obj-$(CONFIG_BPF_SYSCALL) += arena.o range_tree.o\nkernel/bpf/Makefile-21-endif\nkernel/bpf/Makefile:22:obj-$(CONFIG_BPF_JIT) += dispatcher.o\nkernel/bpf/Makefile-23-ifeq ($(CONFIG_NET),y)\nkernel/bpf/Makefile:24:obj-$(CONFIG_BPF_SYSCALL) += devmap.o\nkernel/bpf/Makefile:25:obj-$(CONFIG_BPF_SYSCALL) += cpumap.o\nkernel/bpf/Makefile:26:obj-$(CONFIG_BPF_SYSCALL) += offload.o\nkernel/bpf/Makefile:27:obj-$(CONFIG_BPF_SYSCALL) += net_namespace.o\nkernel/bpf/Makefile:28:obj-$(CONFIG_BPF_SYSCALL) += tcx.o\nkernel/bpf/Makefile-29-endif\nkernel/bpf/Makefile=30=ifeq ($(CONFIG_KEYS),y)\nkernel/bpf/Makefile:31:obj-$(CONFIG_BPF_SYSCALL) += keys.o\nkernel/bpf/Makefile-32-endif\nkernel/bpf/Makefile=33=ifeq ($(CONFIG_PERF_EVENTS),y)\nkernel/bpf/Makefile:34:obj-$(CONFIG_BPF_SYSCALL) += stackmap.o\nkernel/bpf/Makefile-35-endif\nkernel/bpf/Makefile=36=ifeq ($(CONFIG_CGROUPS),y)\nkernel/bpf/Makefile:37:obj-$(CONFIG_BPF_SYSCALL) += cgroup_iter.o bpf_cgrp_storage.o\nkernel/bpf/Makefile-38-endif\nkernel/bpf/Makefile:39:obj-$(CONFIG_CGROUP_BPF) += cgroup.o\nkernel/bpf/Makefile-40-ifeq ($(CONFIG_INET),y)\nkernel/bpf/Makefile:41:obj-$(CONFIG_BPF_SYSCALL) += reuseport_array.o\nkernel/bpf/Makefile-42-endif\n--\nkernel/bpf/Makefile=46=ifeq ($(CONFIG_BPF_JIT),y)\nkernel/bpf/Makefile:47:obj-$(CONFIG_BPF_SYSCALL) += bpf_struct_ops.o\nkernel/bpf/Makefile:48:obj-$(CONFIG_BPF_SYSCALL) += cpumask.o\nkernel/bpf/Makefile-49-# bpf_lsm_proto.o must precede bpf_lsm.o. The current pahole logic\n--\nkernel/bpf/Makefile=61=ifneq ($(CONFIG_CRYPTO),)\nkernel/bpf/Makefile:62:obj-$(CONFIG_BPF_SYSCALL) += crypto.o\nkernel/bpf/Makefile-63-endif\nkernel/bpf/Makefile:64:obj-$(CONFIG_BPF_PRELOAD) += preload/\nkernel/bpf/Makefile-65-\nkernel/bpf/Makefile:66:obj-$(CONFIG_BPF_SYSCALL) += relo_core.o\nkernel/bpf/Makefile:67:obj-$(CONFIG_BPF_SYSCALL) += btf_iter.o\nkernel/bpf/Makefile:68:obj-$(CONFIG_BPF_SYSCALL) += btf_relocate.o\nkernel/bpf/Makefile:69:obj-$(CONFIG_BPF_SYSCALL) += kmem_cache_iter.o\nkernel/bpf/Makefile-70-ifeq ($(CONFIG_DMA_SHARED_BUFFER),y)\nkernel/bpf/Makefile:71:obj-$(CONFIG_BPF_SYSCALL) += dmabuf_iter.o\nkernel/bpf/Makefile-72-endif\n--\nkernel/bpf/preload/Makefile=3=LIBBPF_INCLUDE = $(srctree)/tools/lib\nkernel/bpf/preload/Makefile-4-\nkernel/bpf/preload/Makefile:5:obj-$(CONFIG_BPF_PRELOAD_UMD) += bpf_preload.o\nkernel/bpf/preload/Makefile-6-CFLAGS_bpf_preload_kern.o += -I$(LIBBPF_INCLUDE)\n"
} |
| 5/2 | 2026/09/26 03:30 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 29821 output: 36 thoughts: 188 Thoughts: Okay, let's see what we have here. **BPF JIT Configuration Analysis** Alright, looking at `kernel/bpf/Makefile`, I see the core BPF syscall components are conditionally built based on `CONFIG_BPF_SYSCALL`. That's expected: `syscall.o`, `verifier.o`, `inode.o`, the helpers, all that. Now, I'm noting the additions to the list, things like `fixups.o`, `cfg.o`, `states.o`, all that. Seems like some potentially important control flow or instruction set features were added and depend on some configuration flags. The real interesting bit is the patch mentioning `bpf_jit_supports_timed_may_goto()` and `bpf_jit_supports_exceptions()`. These names strongly suggest interaction with the Just-In-Time compiler. It gets me thinking... are these features *required* for the JIT to function? Can they operate independently, perhaps with a fallback path? Are they *only* enabled with `CONFIG_BPF_JIT`, or does it work without JIT? And what *other* configurations are relevant here? Time to dig deeper. I'm going to `grep` the source tree for both `bpf_jit_supports_exceptions` and `bpf_jit_supports_timed_may_goto`. That should quickly reveal their dependencies and usage patterns. That will give a clear picture of how those features are controlled, configured, and if the BPF JIT is a hard dependency or simply improves some BPF features. |
| 6/2 | 2026/09/26 03:30 | tool | grepper |
0mArgs:{
"Expression": "bpf_jit_supports_timed_may_goto",
"PathPrefix": "kernel/bpf"
}Results: {
"Output": "kernel/bpf/core.c=3474=void __weak arch_bpf_stack_walk(bool (*consume_fn)(void *cookie, u64 ip, u64 sp, u64 bp), void *cookie)\n--\nkernel/bpf/core.c-3477-\nkernel/bpf/core.c:3478:bool __weak bpf_jit_supports_timed_may_goto(void)\nkernel/bpf/core.c-3479-{\n--\nkernel/bpf/fixups.c=1608=static int add_loop_guard(struct bpf_verifier_env *env, int idx, struct bpf_insn *buf,\n--\nkernel/bpf/fixups.c-1630-\t/* the same insns may_goto is replaced with, see bpf_do_misc_fixups() */\nkernel/bpf/fixups.c:1631:\tif (bpf_jit_supports_timed_may_goto()) {\nkernel/bpf/fixups.c-1632-\t\tstack_off = -stack_depth - 16;\n--\nkernel/bpf/fixups.c=1677=int bpf_do_misc_fixups(struct bpf_verifier_env *env)\n--\nkernel/bpf/fixups.c-1964-\nkernel/bpf/fixups.c:1965:\t\tif (bpf_is_may_goto_insn(insn) \u0026\u0026 bpf_jit_supports_timed_may_goto()) {\nkernel/bpf/fixups.c-1966-\t\t\tint stack_off_cnt = -stack_depth - 16;\n--\nkernel/bpf/fixups.c-2616-\tfor (i = 0; i \u003c env-\u003esubprog_cnt; i++) {\nkernel/bpf/fixups.c:2617:\t\tint delta = bpf_jit_supports_timed_may_goto() ? 2 : 1;\nkernel/bpf/fixups.c-2618-\t\tint subprog_start = subprogs[i].start;\n--\nkernel/bpf/fixups.c-2630-\t\tstack_depth = subprogs[i].stack_depth;\nkernel/bpf/fixups.c:2631:\t\tif (bpf_jit_supports_timed_may_goto()) {\nkernel/bpf/fixups.c-2632-\t\t\tinsn_buf[cnt++] = BPF_ST_MEM(BPF_DW, BPF_REG_FP, -stack_depth,\n"
} |
| 7/2 | 2026/09/26 03:30 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 31032 output: 38 thoughts: 111 Thoughts: Okay, let's dive into this BPF verification process. **BPF Verification Deep Dive** My initial move is to zero in on `bpf_check` and its internal function, `do_check_prog`. These are the core elements for verifying BPF programs, which is critical for their safe execution within the kernel. I know that `bpf_check` is located in `kernel/bpf/verifier.c`. Specifically, `bpf_check` takes a `struct bpf_prog **prog`, a `union bpf_attr *attr`, a `bpfptr_t uattr` and other parameters. My primary interest, though, is how it handles the actual verification. Looking closely at the code reveals a call to `do_check_prog` through `ret = do_check_prog(env);`. This is where the magic happens, and it's where the program's instructions are assessed for safety and compliance. It looks like line 20733 of `kernel/bpf/verifier.c` is the starting point for `do_check_prog`. From here, I can delve into the specifics of the verification logic, looking at how the environment (`env`) is used, and what checks are performed to prevent malicious BPF code from causing damage to the system. |
| 8/2 | 2026/09/26 03:30 | tool | read-file |
0mArgs:{
"File": "kernel/bpf/verifier.c",
"FirstLine": 20730,
"LineCount": 60
}Results: {
"Contents": "20730:\t\tret = do_check_common(env, 0);\n20731:\t\tif (!ret)\n20732:\t\t\tenv-\u003eprog-\u003eaux-\u003estack_depth = env-\u003esubprog_info[0].stack_depth;\n20733:\t\treturn ret;\n20734:\t}\n20735:\t\n20736:\t/*\n20737:\t * Walk the program with loops widened first. It is much less work when it\n20738:\t * succeeds. If it fails the reason can be the precision that widening gave\n20739:\t * up. Then undo everything that walk did, so that the walk of every\n20740:\t * iteration that follows can't tell that it is not the first one.\n20741:\t * It is all or nothing for the main program and global functions, because\n20742:\t * may_goto added to a loop of a static function is there for all callers.\n20743:\t */\n20744:\tstatic int do_check_prog(struct bpf_verifier_env *env)\n20745:\t{\n20746:\t\tstruct walk_snapshot snap;\n20747:\t\tint ret;\n20748:\t\n20749:\t\t/* no loops without bpf_capable, the driver of an offloaded prog sees every insn visit */\n20750:\t\tif (!env-\u003ebpf_capable || env-\u003escc_cnt \u003c= 1 || bpf_prog_is_offloaded(env-\u003eprog-\u003eaux)) {\n20751:\t\t\tret = do_check_main(env);\n20752:\t\t\treturn ret ?: do_check_subprogs(env);\n20753:\t\t}\n20754:\t\n20755:\t\tenv-\u003escc_converged = kvzalloc_objs(*env-\u003escc_converged, BITS_TO_LONGS(env-\u003escc_cnt),\n20756:\t\t\t\t\t\t GFP_KERNEL_ACCOUNT);\n20757:\t\tif (!env-\u003escc_converged)\n20758:\t\t\treturn -ENOMEM;\n20759:\t\tret = walk_snapshot_save(env, \u0026snap);\n20760:\t\tif (ret)\n20761:\t\t\treturn ret;\n20762:\t\n20763:\t\tenv-\u003ewiden_loops = true;\n20764:\t\tenv-\u003ewiden_used = false;\n20765:\t\tret = do_check_main(env);\n20766:\t\tret = ret ?: do_check_subprogs(env);\n20767:\t\tif (!ret \u0026\u0026 env-\u003ewiden_used)\n20768:\t\t\tret = bpf_commit_loop_guards(env);\n20769:\t\tenv-\u003ewiden_loops = false;\n20770:\t\tif (ret \u0026\u0026 ret != -ENOMEM \u0026\u0026 ret != -EAGAIN \u0026\u0026 ret != -EFAULT \u0026\u0026 env-\u003ewiden_used) {\n20771:\t\t\twalk_snapshot_restore(env, \u0026snap);\n20772:\t\t\tif (env-\u003elog.level \u0026 BPF_LOG_LEVEL)\n20773:\t\t\t\tverbose(env, \"walk with widened loops failed, walking every iteration\\n\");\n20774:\t\t\tret = do_check_main(env);\n20775:\t\t\tret = ret ?: do_check_subprogs(env);\n20776:\t\t}\n20777:\t\twalk_snapshot_free(\u0026snap);\n20778:\t\treturn ret;\n20779:\t}\n20780:\t\n20781:\tstatic void print_verification_stats(struct bpf_verifier_env *env)\n20782:\t{\n20783:\t\t/* Skip over hidden subprogs which are not verified. */\n20784:\t\tint i, subprog_cnt = env-\u003esubprog_cnt - env-\u003ehidden_subprog_cnt;\n20785:\t\n20786:\t\tif (env-\u003elog.level \u0026 BPF_LOG_STATS) {\n20787:\t\t\tverbose(env, \"verification time %lld usec\\n\",\n20788:\t\t\t\tdiv_u64(env-\u003everification_time, 1000));\n20789:\t\t\tverbose(env, \"stack depth max %d\\n\", env-\u003emax_stack_depth);\n"
} |
| 9/2 | 2026/09/26 03:30 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 32598 output: 31 thoughts: 1190 Thoughts: **Analyzing BPF Verifier Entrypoints and Function Visibility** Okay, let's dive into the BPF verifier code and sort out the function visibility and key entry points. My immediate focus is on understanding which functions are static versus non-static, and which are exposed as critical symbols or entrypoints. First, I'm examining `kernel/bpf/verifier.c`. I've identified several functions that seem pertinent to my investigation. `bpf_widen_loop_head`, `bpf_mark_loop_guard`, and `bpf_same_loop` are all non-static functions, and importantly, they are all exported in `bpf_verifier.h`. The definitions of these functions are also noted. `do_check_prog`, `walk_snapshot_save`, `walk_snapshot_restore`, `widen_reg`, `scc_thresholds`, `cnum64_tighten_by_tnum`, and `cnum32_tighten_by_tnum` are all static functions within `verifier.c`. `bpf_check`, the core verifier entrypoint, is non-static. Next, I'm looking at `kernel/bpf/fixups.c`. Here, `bpf_commit_loop_guards` is non-static and exported in `bpf_verifier.h`. `add_loop_guard` is a static function, called by `bpf_do_misc_fixups`, while `bpf_do_misc_fixups` itself is non-static and called by `bpf_check`. Moving on to `kernel/bpf/states.c`, I've found `bpf_scc_mark_exit` which is non-static and exported in `bpf_verifier.h`, and `bpf_is_state_visited`, which is also non-static (modified by loop widening logic). The functions `loop_head_guard`, `loop_head_state`, and `is_backedge` are all static. Lastly, in `kernel/bpf/cfg.c`, `push_insn` is a static function. My objective is to understand how these pieces fit together, and how external components interact with the verifier, so I need to verify which symbols are visible in the vmlinux/kallsyms. Let's confirm the definitions and visibility of the critical functions. From `include/linux/bpf_verifier.h`, I can confirm that `bpf_is_state_visited`, `bpf_same_loop`, `bpf_mark_loop_guard`, `bpf_commit_loop_guards`, `bpf_scc_mark_exit`, and `bpf_widen_loop_head` are all non-static, confirming my previous findings. I also checked the definitions of `bpf_widen_loop_head`, `bpf_mark_loop_guard`, `bpf_same_loop`, `bpf_commit_loop_guards` and `bpf_scc_mark_exit` in their respective files. `add_loop_guard` is static, called by `bpf_do_misc_fixups`, and `do_check_prog` is static and called by `bpf_check`. Finally, it is essential to check the dependencies. The BPF verifier is enabled by `CONFIG_BPF_SYSCALL`. I'll cross-reference `init/Kconfig` or `kernel/bpf/Kconfig` to confirm any other configurations. |
| 10/2 | 2026/09/26 03:31 | tool | grepper |
0mArgs:{
"Expression": "config BPF_SYSCALL",
"PathPrefix": "kernel/bpf"
}Results: {
"Output": "kernel/bpf/Kconfig=29=menu \"BPF subsystem\"\nkernel/bpf/Kconfig-30-\nkernel/bpf/Kconfig:31:config BPF_SYSCALL\nkernel/bpf/Kconfig-32-\tbool \"Enable bpf() system call\"\n"
} |
| 11/2 | 2026/09/26 03:31 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 34673 output: 34 thoughts: 23 Thoughts: Here's a summary of my thought process: **Diving into BPF Dependencies** Okay, I need to understand the dependencies within the BPF configuration. The logical place to start is the `kernel/bpf/Kconfig` file. I'm focusing around line 31 as a likely spot to find relevant information. That section should illuminate which other kernel features or configurations are required or impacted by the BPF settings. By examining the dependencies defined in that area, I can get a clearer picture of how BPF integrates with the broader kernel architecture. Understanding these relationships is crucial for making informed decisions regarding BPF configuration and troubleshooting any potential conflicts. Let's see what's there... |
| 12/2 | 2026/09/26 03:31 | tool | read-file |
0mArgs:{
"File": "kernel/bpf/Kconfig",
"FirstLine": 29,
"LineCount": 40
}Results: {
"Contents": " 29:\tmenu \"BPF subsystem\"\n 30:\t\n 31:\tconfig BPF_SYSCALL\n 32:\t\tbool \"Enable bpf() system call\"\n 33:\t\tselect BPF\n 34:\t\tselect IRQ_WORK\n 35:\t\tselect NEED_TASKS_RCU\n 36:\t\tselect TASKS_TRACE_RCU\n 37:\t\tselect BINARY_PRINTF\n 38:\t\tselect NET_SOCK_MSG if NET\n 39:\t\tselect NET_XGRESS if NET\n 40:\t\tselect PAGE_POOL if NET\n 41:\t\tdefault n\n 42:\t\thelp\n 43:\t\t Enable the bpf() system call that allows to manipulate BPF programs\n 44:\t\t and maps via file descriptors.\n 45:\t\n 46:\tconfig BPF_JIT\n 47:\t\tbool \"Enable BPF Just In Time compiler\"\n 48:\t\tdepends on BPF\n 49:\t\tdepends on HAVE_CBPF_JIT || HAVE_EBPF_JIT\n 50:\t\tselect EXECMEM\n 51:\t\thelp\n 52:\t\t BPF programs are normally handled by a BPF interpreter. This option\n 53:\t\t allows the kernel to generate native code when a program is loaded\n 54:\t\t into the kernel. This will significantly speed-up processing of BPF\n 55:\t\t programs.\n 56:\t\n 57:\t\t Note, an admin should enable this feature changing:\n 58:\t\t /proc/sys/net/core/bpf_jit_enable\n 59:\t\t /proc/sys/net/core/bpf_jit_harden (optional)\n 60:\t\t /proc/sys/net/core/bpf_jit_kallsyms (optional)\n 61:\t\n 62:\tconfig BPF_JIT_ALWAYS_ON\n 63:\t\tbool \"Permanently enable BPF JIT and remove BPF interpreter\"\n 64:\t\tdepends on BPF_SYSCALL \u0026\u0026 HAVE_EBPF_JIT \u0026\u0026 BPF_JIT\n 65:\t\thelp\n 66:\t\t Enables BPF JIT and removes BPF interpreter to avoid speculative\n 67:\t\t execution of BPF instructions by the interpreter.\n 68:\t\n"
} |
| 13/2 | 2026/09/26 03:31 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 35459 output: 27 thoughts: 126 Thoughts: Okay, here's my breakdown of this thought process, keeping in mind my expertise:
**My BPF Configuration Strategy**
Alright, my first instinct here is that `BPF_SYSCALL` is the critical configuration to focus on. That seems like the central setting. However, the mention of `BPF_JIT` (or specifically `BPF_JIT_ALWAYS_ON`) makes me pause. The `cannot_throw` error check gives me a clue:
```c
if (!env->prog->jit_requested || !bpf_jit_supports_exceptions())
return "JIT does not support exceptions";
```
It looks like the JIT and exception handling are potentially intertwined here. The check for `bpf_jit_supports_exceptions()` is what really piques my interest. It implies that the JIT compiler itself may be key to a specific BPF feature, and the absence of exceptions could influence JIT usage. I need to understand this better.
The code checks `prog->jit_requested`, and based on the context here, it appears to be tied into the JIT behavior with regard to exceptions. Now, I have to figure out when the `jit_requested` flag is set and how it affects the overall BPF execution. I need to trace back where `jit_requested` is used and defined in the kernel. Let's see how the JIT compilation is enabled or disabled. That will clarify how these configurations play together.
|
| 14/2 | 2026/09/26 03:31 | tool | grepper |
0mArgs:{
"Expression": "jit_requested",
"PathPrefix": "kernel/bpf"
}Results: {
"Output": "kernel/bpf/core.c=100=struct bpf_prog *bpf_prog_alloc_no_stats(unsigned int size, gfp_t gfp_extra_flags)\n--\nkernel/bpf/core.c-127-\tfp-\u003eaux-\u003eprog = fp;\nkernel/bpf/core.c:128:\tfp-\u003ejit_requested = ebpf_jit_enabled();\nkernel/bpf/core.c-129-\tfp-\u003ejit_required = IS_ENABLED(CONFIG_BPF_JIT_ALWAYS_ON);\n--\nkernel/bpf/core.c=179=int bpf_prog_alloc_jited_linfo(struct bpf_prog *prog)\nkernel/bpf/core.c-180-{\nkernel/bpf/core.c:181:\tif (!prog-\u003eaux-\u003enr_linfo || !prog-\u003ejit_requested)\nkernel/bpf/core.c-182-\t\treturn 0;\n--\nkernel/bpf/fixups.c=1098=static int jit_subprogs(struct bpf_verifier_env *env)\n--\nkernel/bpf/fixups.c-1198-\nkernel/bpf/fixups.c:1199:\t\tfunc[i]-\u003ejit_requested = 1;\nkernel/bpf/fixups.c-1200-\t\tfunc[i]-\u003eblinding_requested = prog-\u003eblinding_requested;\n--\nkernel/bpf/fixups.c=1366=int bpf_jit_subprogs(struct bpf_verifier_env *env)\n--\nkernel/bpf/fixups.c-1431-\t/* cleanup main prog to be interpreted */\nkernel/bpf/fixups.c:1432:\tprog-\u003ejit_requested = 0;\nkernel/bpf/fixups.c-1433-\tprog-\u003eblinding_requested = 0;\n--\nkernel/bpf/fixups.c=1437=int bpf_fixup_call_args(struct bpf_verifier_env *env)\n--\nkernel/bpf/fixups.c-1457-\nkernel/bpf/fixups.c:1458:\tif (env-\u003eprog-\u003ejit_requested \u0026\u0026\nkernel/bpf/fixups.c-1459-\t !bpf_prog_is_offloaded(env-\u003eprog-\u003eaux)) {\n--\nkernel/bpf/fixups.c=1677=int bpf_do_misc_fixups(struct bpf_verifier_env *env)\n--\nkernel/bpf/fixups.c-2121-\t\t\tif (env-\u003ebpf_capable \u0026\u0026 !prog-\u003eblinding_requested \u0026\u0026\nkernel/bpf/fixups.c:2122:\t\t\t prog-\u003ejit_requested \u0026\u0026\nkernel/bpf/fixups.c-2123-\t\t\t !bpf_map_key_poisoned(aux) \u0026\u0026\n--\nkernel/bpf/fixups.c-2232-\t\t */\nkernel/bpf/fixups.c:2233:\t\tif (prog-\u003ejit_requested \u0026\u0026 BITS_PER_LONG == 64 \u0026\u0026\nkernel/bpf/fixups.c-2234-\t\t (insn-\u003eimm == BPF_FUNC_map_lookup_elem ||\n--\nkernel/bpf/fixups.c-2331-\t\t/* Implement bpf_jiffies64 inline. */\nkernel/bpf/fixups.c:2332:\t\tif (prog-\u003ejit_requested \u0026\u0026 BITS_PER_LONG == 64 \u0026\u0026\nkernel/bpf/fixups.c-2333-\t\t insn-\u003eimm == BPF_FUNC_jiffies64) {\n--\nkernel/bpf/fixups.c-2512-\t\tif (IS_ENABLED(CONFIG_PERF_EVENTS) \u0026\u0026\nkernel/bpf/fixups.c:2513:\t\t prog-\u003ejit_requested \u0026\u0026 BITS_PER_LONG == 64 \u0026\u0026\nkernel/bpf/fixups.c-2514-\t\t insn-\u003eimm == BPF_FUNC_get_branch_snapshot) {\n--\nkernel/bpf/fixups.c-2567-\t\t/* Implement bpf_kptr_xchg inline */\nkernel/bpf/fixups.c:2568:\t\tif (prog-\u003ejit_requested \u0026\u0026 BITS_PER_LONG == 64 \u0026\u0026\nkernel/bpf/fixups.c-2569-\t\t insn-\u003eimm == BPF_FUNC_kptr_xchg \u0026\u0026\n--\nkernel/bpf/fixups.c-2601-\t\t\tstack_depth = subprogs[cur_subprog].stack_depth;\nkernel/bpf/fixups.c:2602:\t\t\tif (stack_depth \u003e MAX_BPF_STACK \u0026\u0026 !prog-\u003ejit_requested) {\nkernel/bpf/fixups.c-2603-\t\t\t\tverbose(env, \"stack size %d(extra %d) is too large\\n\",\n--\nkernel/bpf/verifier.c=437=static int bpf_compute_subprog_ret_regs(struct bpf_verifier_env *env)\n--\nkernel/bpf/verifier.c-443-\nkernel/bpf/verifier.c:444:\tif (!env-\u003eprog-\u003ejit_requested || bpf_prog_is_offloaded(env-\u003eprog-\u003eaux))\nkernel/bpf/verifier.c-445-\t\treturn 0;\n--\nkernel/bpf/verifier.c=2924=int bpf_add_kfunc_call(struct bpf_verifier_env *env, u32 func_id, u16 offset)\n--\nkernel/bpf/verifier.c-2944-\nkernel/bpf/verifier.c:2945:\t\tif (!env-\u003eprog-\u003ejit_requested) {\nkernel/bpf/verifier.c-2946-\t\t\tverbose(env, \"JIT is required for calling kernel function\\n\");\n--\nkernel/bpf/verifier.c=5423=static int round_up_stack_depth(struct bpf_verifier_env *env, int stack_depth)\nkernel/bpf/verifier.c-5424-{\nkernel/bpf/verifier.c:5425:\tif (env-\u003eprog-\u003ejit_requested)\nkernel/bpf/verifier.c-5426-\t\treturn round_up(stack_depth, 16);\n--\nkernel/bpf/verifier.c=8329=static const char *cannot_throw(struct bpf_verifier_env *env, struct bpf_verifier_state *st)\n--\nkernel/bpf/verifier.c-8334-\nkernel/bpf/verifier.c:8335:\tif (!env-\u003eprog-\u003ejit_requested || !bpf_jit_supports_exceptions())\nkernel/bpf/verifier.c-8336-\t\treturn \"JIT does not support exceptions\";\n--\nkernel/bpf/verifier.c=10078=bool bpf_allow_tail_call_in_subprogs(struct bpf_verifier_env *env)\nkernel/bpf/verifier.c-10079-{\nkernel/bpf/verifier.c:10080:\treturn env-\u003eprog-\u003ejit_requested \u0026\u0026\nkernel/bpf/verifier.c-10081-\t bpf_jit_supports_subprog_tailcalls();\n--\nkernel/bpf/verifier.c=18568=bool bpf_verifier_inlines_helper_call(struct bpf_verifier_env *env, s32 imm)\n--\nkernel/bpf/verifier.c-18576-#endif\nkernel/bpf/verifier.c:18577:\t\treturn env-\u003eprog-\u003ejit_requested \u0026\u0026 bpf_jit_supports_percpu_insn();\nkernel/bpf/verifier.c-18578-#endif\n--\nkernel/bpf/verifier.c=19709=static int check_map_prog_compatibility(struct bpf_verifier_env *env,\n--\nkernel/bpf/verifier.c-19799-\t\t}\nkernel/bpf/verifier.c:19800:\t\tif (!env-\u003eprog-\u003ejit_requested) {\nkernel/bpf/verifier.c-19801-\t\t\tverbose(env, \"JIT is required to use arena\\n\");\n--\nkernel/bpf/verifier.c=21151=int bpf_check_attach_target(struct bpf_verifier_log *log,\n--\nkernel/bpf/verifier.c-21232-\t\t\t}\nkernel/bpf/verifier.c:21233:\t\t\tif (!prog-\u003ejit_requested) {\nkernel/bpf/verifier.c-21234-\t\t\t\tbpf_log(log,\n"
} |
| 15/2 | 2026/09/26 03:31 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 38113 output: 224 thoughts: 1212 Thoughts: **Focusing on BPF Verifier Loop Widening for Fuzzing** Alright, let's zero in on this BPF patch. We've got `CONFIG_BPF_SYSCALL` and `CONFIG_BPF_JIT` as baseline essentials, standard stuff. Now, while `CONFIG_BPF_JIT_ALWAYS_ON` isn't strictly necessary since we can toggle `bpf_jit_enable` with the sysctl, `BPF_SYSCALL` and `BPF_JIT` are obviously crucial. The critical part is identifying the right focus symbols for fuzzing. We need to find functions specific to this patch and not ubiquitous. Let's see what stands out in the code. I'm looking at added or significantly modified functions: 1. `bpf_widen_loop_head` - Directly implements the loop widening logic in `kernel/bpf/verifier.c`. This is promising. 2. `bpf_mark_loop_guard` - Also in `kernel/bpf/verifier.c`, responsible for marking loop guards, central to bounded execution. Good! 3. `bpf_commit_loop_guards` - `kernel/bpf/fixups.c`, commits loop guards after verification. This looks important. 4. `bpf_scc_mark_exit` - `kernel/bpf/states.c`, marks loop/SCC exits. Another key function. 5. `bpf_is_state_visited` - Also in `kernel/bpf/states.c`, and it's been heavily modified with the new loop widening and infinite loop handling. Definitely a candidate. 6. `bpf_do_misc_fixups` - `kernel/bpf/fixups.c`, calls `add_loop_guard` for those `loop_guard` insns. I'm briefly considering `bpf_same_loop`, but it's a simple helper. `bpf_check` is the top-level verifier, but it's too broad; those other functions are much more specific to this patch's loop handling. Let's double-check the visibility of those functions: yep, `bpf_widen_loop_head`, `bpf_commit_loop_guards`, `bpf_mark_loop_guard`, `bpf_scc_mark_exit`, and `bpf_is_state_visited` are all non-static, so they're exported and visible for calling. Of course, `add_loop_guard` is static, which is called by `bpf_do_misc_fixups`, so we should make a note of it. So, are these functions good focus symbols? Absolutely! They are distinct, central to this patch, in core verifier code, and, importantly, reachable via the `bpf(BPF_PROG_LOAD, ...)` syscall. Now, a quick sanity check on my reasoning: This patch is all about widening loops in the BPF verifier to avoid iterating over every single instruction. Changes are touching core verifier logic in `kernel/bpf/verifier.c`, `kernel/bpf/states.c`, and `kernel/bpf/fixups.c`. It's fully reachable via the `bpf(BPF_PROG_LOAD)` system call from userspace (given the CAP\_BPF or CAP\_SYS\_ADMIN capabilities). The BPF verifier is already notoriously complex, and these changes involve bounds widening, state comparison, snapshot/restore, and loop guard insertion, which can definitely lead to soundness issues, kernel crashes, assertion failures, or memory corruption. Therefore, it's a prime target for fuzzing. Definitely `WorthFuzzing=true`. For enabling configs, `BPF_SYSCALL` and `BPF_JIT` are what we're after. Time to call `set-results`. |
| 16/2 | 2026/09/26 03:31 | tool | set-results |
0mArgs:{
"EnableConfigs": [
"BPF_SYSCALL",
"BPF_JIT"
],
"FocusSymbols": [
"bpf_widen_loop_head",
"bpf_mark_loop_guard",
"bpf_commit_loop_guards",
"bpf_scc_mark_exit",
"bpf_is_state_visited"
],
"Reasoning": "The patch introduces loop widening and loop guard insertion into the BPF verifier. This is a substantial change to core BPF verifier logic in kernel/bpf/ (verifier.c, states.c, fixups.c, cfg.c), implementing scalar range widening across loop iterations, verifier state snapshot/restore rollback on failure, and instruction rewrites to insert may_goto/bpf_throw guards. This code is reachable from userspace via the bpf() system call and is an important target for fuzzing to discover potential soundness issues, unbounded memory consumption, or crashes.",
"WorthFuzzing": true
}Results: {
"EnableConfigs": [
"BPF_SYSCALL",
"BPF_JIT"
],
"FocusSymbols": [
"bpf_widen_loop_head",
"bpf_mark_loop_guard",
"bpf_commit_loop_guards",
"bpf_scc_mark_exit",
"bpf_is_state_visited"
],
"Reasoning": "The patch introduces loop widening and loop guard insertion into the BPF verifier. This is a substantial change to core BPF verifier logic in kernel/bpf/ (verifier.c, states.c, fixups.c, cfg.c), implementing scalar range widening across loop iterations, verifier state snapshot/restore rollback on failure, and instruction rewrites to insert may_goto/bpf_throw guards. This code is reachable from userspace via the bpf() system call and is an important target for fuzzing to discover potential soundness issues, unbounded memory consumption, or crashes.",
"WorthFuzzing": true
} |
| 17/1 | 2026/09/26 03:31 | action | If |
1mArgs:{
"WorthFuzzing": true
}Results: null |
| 18/2 | 2026/09/26 03:31 | agent | kmsan-evaluator |
1mModel:core Args: null Results: {
"KMSANReasoning": "The patch series implements loop widening in the BPF verifier and runtime loop guards (may_goto + bpf_throw fixups) for loops that converge with widened states.\n\nAnalysis of memory safety and sanitizer applicability:\n1. No Kernel-to-User Info-Leaks: The changes operate purely within the internal BPF verifier pipeline during program verification and instruction fixups. No kernel structures or memory buffers are copied to user space.\n2. Structure Initialization: All newly allocated data structures (such as `walk_snapshot`, `scc_converged`, `scc_thrs`, and temporary instruction patch buffers) are explicitly zero-initialized using `memset`, `kvzalloc`, or `kvmemdup` from initialized data.\n3. Control Flow and Branching: Conditional branches rely only on fully initialized local or struct variables; no uninitialized struct fields or stack variables are evaluated.\n4. KASAN vs KMSAN: The primary risks associated with these changes are verifier logic errors, incorrect jump/instruction offset calculations, instruction buffer overflow, or potential state tracking use-after-free bugs. All of these potential failure modes are fully covered by KASAN, UBSAN, and standard kernel debugging facilities. No uninitialized memory usage or leak risks specific to KMSAN are introduced.\n\nTherefore, a dedicated KMSAN fuzzing session is not warranted.",
"NeedsKMSAN": false
}Instruction: You are an expert Linux kernel security engineer specializing in kernel memory
error detectors (KASAN and KMSAN). Your job is to review the provided patch series and
determine if the code changes justify spawning a dedicated KMSAN (KernelMemorySanitizer)
fuzzing session in addition to standard KASAN fuzzing.
CRITICAL DISTINCTION BETWEEN KASAN AND KMSAN:
- Standard KASAN kernel builds (upstream-apparmor-kasan.config) already enable
a comprehensive suite of debugging tools and sanitizers, including KASAN
(out-of-bounds accesses, use-after-free, double free, invalid free), LOCKDEP
(locking bugs and deadlocks), UB-sanitizers, and memory corruption checks.
- KMSAN (KernelMemorySanitizer) detects reads of UNINITIALIZED memory (stack, heap,
or page allocations) and kernel-to-user memory info-leaks.
Rule: THERE IS NO SENSE IN RUNNING A KMSAN SESSION IF A BUG CAN BE CAUGHT BY KASAN,
LOCKDEP, OR OTHER STANDARD BUG DETECTORS.
A dedicated KMSAN fuzzing session incurs significant resource costs. You must ONLY
set NeedsKMSAN=true if the code changes introduce or expose UNINITIALIZED MEMORY risks
that are detected ONLY by KMSAN.
Look holistically at the patch series and surrounding code. Even if no direct
uninitialized field accesses or new buffer allocations are added in the diff itself,
a patch may alter control flow, bounds checking, or data length calculations in ways
that change how the rest of the code operates on existing buffers (e.g. allowing
uninitialized stack/heap memory to be read, copied to user space, or used in control
flow). Do not hesitate to use your code access tools to inspect the surrounding code,
called functions, and callers.
Set NeedsKMSAN=true ONLY IF the patch introduces or modifies:
1. Kernel structures sent to user space (via copy_to_user, put_user, netlink skb
attributes, ioctl output arguments, socket options, or BPF buffers) where fields
or structure padding might not be fully initialized/zeroed.
2. Conditional logic or branching that depends on potentially uninitialized variables
or struct fields.
3. Allocation or initialization of complex data structures where uninitialized fields
could be read later in reachable code paths.
4. Bounds checks, lengths, or logic in a way that allows surrounding code to access
uninitialized bytes of existing buffers.
Set NeedsKMSAN=false IF:
- The code changes primarily risk out-of-bounds access, array overflows, NULL pointer
dereferences, locking deadlocks, or use-after-free bugs (these are already caught
by KASAN, LOCKDEP, or standard bug detectors).
- All stack/heap structures touched or introduced by the patch are fully zeroed
or initialized (e.g. using = {0}, memset, kzalloc) before being read or copied.
- The patch does not introduce any risk of uninitialized memory usage or info-leaks.
Use your code access tools to inspect the surrounding code if necessary, then provide
detailed KMSANReasoning contrasting KASAN vs KMSAN applicability for this patch.
Prefer calling several tools at the same time to save round-trips.
Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.
Prompt: Target architecture: amd64
For your convenience, here is the diff of the changes:
commit 3769330d0db57d4c049d66c93c77f5e01c5a973d
Author: syz-cluster <triage@syzkaller.com>
Date: Sat Sep 26 03:30:31 2026 +0000
syz-cluster: applied patch under review
diff --git a/include/linux/bpf_verifier.h b/include/linux/bpf_verifier.h
index 92f528c456052..e02ee286067d2 100644
--- a/include/linux/bpf_verifier.h
+++ b/include/linux/bpf_verifier.h
@@ -527,6 +527,8 @@ struct bpf_verifier_state {
u32 dfs_depth;
u32 callback_unroll_depth;
u32 may_goto_depth;
+ /* number of times the loop head this state is a checkpoint of was widened */
+ u32 loop_passes;
};
static inline struct bpf_reg_state *
@@ -709,6 +711,16 @@ struct bpf_insn_aux_data {
u32 non_stack_access:1; /* instruction can access non-stack memory */
/* true if some jump or call instruction targets this instruction */
u32 jump_target:1;
+ u32 loop_head:1; /* target of a back-edge */
+ u32 backedge_ft:1; /* the edge to the next insn is a back-edge */
+ u32 backedge_br:1; /* the jump is a back-edge */
+ /*
+ * The walk went over the back-edge of this insn with nothing to bound
+ * the number of trips, in a state where bpf_throw() can and cannot be called.
+ */
+ u32 guard_pending:1;
+ u32 guard_impossible:1;
+ u32 loop_guard:1; /* may_goto has to be added to the back-edge of this insn */
/*
* CFG strongly connected component this instruction belongs to,
* zero if it is a singleton SCC.
@@ -895,6 +907,8 @@ struct bpf_scc_visit {
struct bpf_verifier_state *entry_state;
struct bpf_scc_backedge *backedges; /* list of backedges */
u32 num_backedges;
+ /* some state left the SCC since entry_state was set */
+ bool exited;
};
/* An array of bpf_scc_visit structs sharing tht same bpf_scc_callchain->scc
@@ -1046,6 +1060,16 @@ struct bpf_verifier_env {
/* array of pointers to bpf_scc_info indexed by SCC id */
struct bpf_scc_info **scc_info;
u32 scc_cnt;
+ /* per SCC constants that loop counters are compared with, see bpf_widen_loop_head() */
+ struct bpf_widen_thrs **scc_thrs;
+ /* SCCs where some state came back to a state that is still walked */
+ unsigned long *scc_converged;
+ /* states that come back to a loop head are widened instead of walking every iteration */
+ bool widen_loops;
+ /* the walk did or tried that, so a failure can be due to the lost precision */
+ bool widen_used;
+ /* insns processed by a walk that was given up */
+ u32 insn_wasted;
struct bpf_iarray *succ;
struct bpf_iarray *gotox_tmp_buf;
};
@@ -1218,6 +1242,13 @@ void bpf_free_kfunc_btf_tab(struct bpf_kfunc_btf_tab *tab);
int mark_chain_precision(struct bpf_verifier_env *env, int regno);
int bpf_is_state_visited(struct bpf_verifier_env *env, int insn_idx);
+bool bpf_same_loop(struct bpf_verifier_state *old, struct bpf_verifier_state *cur);
+bool bpf_mark_loop_guard(struct bpf_verifier_env *env, struct bpf_verifier_state *cur);
+int bpf_commit_loop_guards(struct bpf_verifier_env *env);
+void bpf_throw(u64 cookie);
+void bpf_scc_mark_exit(struct bpf_verifier_env *env, struct bpf_verifier_state *st, int insn_idx);
+int bpf_widen_loop_head(struct bpf_verifier_env *env, int insn_idx, bool backedge,
+ struct bpf_verifier_state *old, struct bpf_verifier_state *cur);
int bpf_update_branch_counts(struct bpf_verifier_env *env, struct bpf_verifier_state *st);
void bpf_clear_jmp_history(struct bpf_verifier_state *state);
diff --git a/kernel/bpf/cfg.c b/kernel/bpf/cfg.c
index 842c7d1eabccc..748bf544d3ba5 100644
--- a/kernel/bpf/cfg.c
+++ b/kernel/bpf/cfg.c
@@ -137,8 +137,14 @@ static int push_insn(int t, int w, int e, struct bpf_verifier_env *env)
insn_stack[env->cfg.cur_stack++] = w;
return KEEP_EXPLORING;
} else if ((insn_state[w] & 0xF0) == DISCOVERED) {
- if (env->bpf_capable)
+ if (env->bpf_capable) {
+ env->insn_aux_data[w].loop_head = true;
+ if (e == FALLTHROUGH)
+ env->insn_aux_data[t].backedge_ft = true;
+ else
+ env->insn_aux_data[t].backedge_br = true;
return DONE_EXPLORING;
+ }
verbose_linfo(env, t, "%d: ", t);
verbose_linfo(env, w, "%d: ", w);
verbose(env, "back-edge from insn %d to %d\n", t, w);
diff --git a/kernel/bpf/fixups.c b/kernel/bpf/fixups.c
index 2add8001c3ec3..2b965fa4bacc0 100644
--- a/kernel/bpf/fixups.c
+++ b/kernel/bpf/fixups.c
@@ -1537,6 +1537,143 @@ static int add_hidden_subprog(struct bpf_verifier_env *env, struct bpf_insn *pat
/* Do various post-verification rewrites in a single program pass.
* These rewrites simplify JIT and interpreter implementations.
*/
+/*
+ * The walk with widened loops is done. Loops where some state came back to
+ * a state that was still walked were not walked to the end and have to be
+ * bounded at run time.
+ */
+int bpf_commit_loop_guards(struct bpf_verifier_env *env)
+{
+ struct bpf_insn_aux_data *aux = env->insn_aux_data;
+ int i;
+
+ for (i = 0; i < env->prog->len; i++) {
+ if (!aux[i].scc || !test_bit(aux[i].scc, env->scc_converged))
+ continue;
+ if (aux[i].guard_impossible) {
+ verbose(env, "loop with back-edge at insn %d cannot be bounded\n", i);
+ return -E2BIG;
+ }
+ if (aux[i].guard_pending) {
+ aux[i].loop_guard = true;
+ env->seen_exception = true;
+ }
+ }
+ return 0;
+}
+
+/* Jump from insn @from of the patch that replaces insn @idx to insn @target of the program. */
+static int guard_jump(struct bpf_insn *insn, int idx, int from, int cnt, int target)
+{
+ int off;
+
+ /* insns after @idx move by the size of the patch */
+ if (target > idx)
+ target += cnt - 1;
+ off = target - (idx + from) - 1;
+ if (BPF_OP(insn->code) == BPF_JA && BPF_CLASS(insn->code) == BPF_JMP32) {
+ insn->imm = off;
+ return 0;
+ }
+ if (off < S16_MIN || off > S16_MAX) {
+ if (BPF_OP(insn->code) != BPF_JA)
+ return -ERANGE;
+ *insn = BPF_JMP32_A(off);
+ return 0;
+ }
+ insn->off = off;
+ return 0;
+}
+
+/*
+ * The main pass went over the back-edge of jump @insn at @idx with a state
+ * that stands for any number of iterations. Nothing bounds the loop at run
+ * time, so add may_goto to the back-edge. The program cannot go on when
+ * may_goto is out of budget: nothing but the loop was verified for the state
+ * in the loop. Call bpf_throw(). The main pass made sure it can be called.
+ *
+ * back-edge is the jump: back-edge is the edge to the next insn:
+ * if cond goto guard if cond goto target
+ * goto next guard:
+ * guard: may_goto throw
+ * may_goto throw goto next
+ * goto head throw:
+ * throw: r1 = 0
+ * r1 = 0 call bpf_throw
+ * call bpf_throw next:
+ * next:
+ *
+ * Returns the number of insns in @buf.
+ */
+static int add_loop_guard(struct bpf_verifier_env *env, int idx, struct bpf_insn *buf,
+ int stack_depth, u16 *stack_depth_extra)
+{
+ struct bpf_insn_aux_data *aux = &env->insn_aux_data[idx];
+ struct bpf_insn orig = env->prog->insnsi[idx];
+ bool ja = BPF_OP(orig.code) == BPF_JA;
+ bool gotol = ja && BPF_CLASS(orig.code) == BPF_JMP32;
+ int target = idx + 1 + (gotol ? orig.imm : orig.off);
+ bool guard_jump_edge = ja || aux->backedge_br;
+ struct bpf_insn *p = buf, *jeq, *skip = NULL, *back = NULL;
+ int stack_off, cnt, err = 0;
+
+ if (guard_jump_edge && !ja) {
+ *p = orig;
+ p->off = 1;
+ p++;
+ skip = p;
+ *p++ = BPF_JMP_A(0);
+ } else if (!guard_jump_edge) {
+ *p++ = orig;
+ }
+
+ /* the same insns may_goto is replaced with, see bpf_do_misc_fixups() */
+ if (bpf_jit_supports_timed_may_goto()) {
+ stack_off = -stack_depth - 16;
+ *stack_depth_extra = 16;
+ *p++ = BPF_LDX_MEM(BPF_DW, BPF_REG_AX, BPF_REG_10, stack_off);
+ jeq = p;
+ *p++ = BPF_JMP_IMM(BPF_JEQ, BPF_REG_AX, 0, 0);
+ *p++ = BPF_ALU64_IMM(BPF_SUB, BPF_REG_AX, 1);
+ *p++ = BPF_JMP_IMM(BPF_JNE, BPF_REG_AX, 0, 2);
+ *p++ = BPF_MOV64_IMM(BPF_REG_AX, stack_off);
+ *p++ = BPF_EMIT_CALL(arch_bpf_timed_may_goto);
+ *p++ = BPF_STX_MEM(BPF_DW, BPF_REG_10, BPF_REG_AX, stack_off);
+ } else {
+ stack_off = -stack_depth - 8;
+ *stack_depth_extra = max_t(u16, *stack_depth_extra, 8);
+ *p++ = BPF_LDX_MEM(BPF_DW, BPF_REG_AX, BPF_REG_10, stack_off);
+ jeq = p;
+ *p++ = BPF_JMP_IMM(BPF_JEQ, BPF_REG_AX, 0, 0);
+ *p++ = BPF_ALU64_IMM(BPF_SUB, BPF_REG_AX, 1);
+ *p++ = BPF_STX_MEM(BPF_DW, BPF_REG_10, BPF_REG_AX, stack_off);
+ }
+
+ if (guard_jump_edge) {
+ back = p;
+ *p++ = gotol ? orig : BPF_JMP_A(0);
+ } else {
+ /* over bpf_throw() to the loop head that follows */
+ *p++ = BPF_JMP_A(2);
+ }
+ jeq->off = p - jeq - 1;
+ *p++ = BPF_MOV64_IMM(BPF_REG_1, 0);
+ *p++ = BPF_EMIT_CALL(bpf_throw);
+ cnt = p - buf;
+
+ if (skip)
+ skip->off = cnt - (skip - buf) - 1;
+ if (back)
+ err = guard_jump(back, idx, back - buf, cnt, target);
+ else
+ err = guard_jump(&buf[0], idx, 0, cnt, target);
+ if (err) {
+ verbose(env, "insn %d: jump is out of range after may_goto is added\n", idx);
+ return err;
+ }
+ return cnt;
+}
+
int bpf_do_misc_fixups(struct bpf_verifier_env *env)
{
struct bpf_prog *prog = env->prog;
@@ -1573,6 +1710,22 @@ int bpf_do_misc_fixups(struct bpf_verifier_env *env)
}
for (i = 0; i < insn_cnt;) {
+ if (env->insn_aux_data[i + delta].loop_guard) {
+ cnt = add_loop_guard(env, i + delta, insn_buf, stack_depth,
+ &stack_depth_extra);
+ if (cnt < 0)
+ return cnt;
+
+ new_prog = bpf_patch_insn_data(env, i + delta, insn_buf, cnt);
+ if (!new_prog)
+ return -ENOMEM;
+
+ delta += cnt - 1;
+ env->prog = prog = new_prog;
+ insn = new_prog->insnsi + i + delta;
+ goto next_insn;
+ }
+
if (is_addr_space_cast32(env->prog, insn)) {
/* convert to 32-bit mov that clears upper 32-bit */
insn->code = BPF_ALU | BPF_MOV | BPF_X;
diff --git a/kernel/bpf/states.c b/kernel/bpf/states.c
index 66fb11b6c6a76..24422b7db6d97 100644
--- a/kernel/bpf/states.c
+++ b/kernel/bpf/states.c
@@ -170,6 +170,7 @@ static int maybe_enter_scc(struct bpf_verifier_env *env, struct bpf_verifier_sta
return -ENOMEM;
if (!visit->entry_state) {
visit->entry_state = st;
+ visit->exited = false;
if (env->log.level & BPF_LOG_LEVEL2)
verbose(env, "SCC enter %s\n", format_callchain(env, callchain));
}
@@ -212,6 +213,16 @@ static int maybe_exit_scc(struct bpf_verifier_env *env, struct bpf_verifier_stat
}
if (visit->entry_state != st)
return 0;
+ /*
+ * All states that came from @st are done. If some of them went
+ * around the loop and none left it, nothing that enters the loop
+ * the way @st did ever leaves it.
+ */
+ if (env->widen_loops && !st->speculative && visit->backedges && !visit->exited) {
+ verbose(env, "loop at insn %d never exits\n", st->insn_idx);
+ env->widen_used = true;
+ return -EINVAL;
+ }
if (env->log.level & BPF_LOG_LEVEL2)
verbose(env, "SCC exit %s\n", format_callchain(env, callchain));
visit->entry_state = NULL;
@@ -221,6 +232,32 @@ static int maybe_exit_scc(struct bpf_verifier_env *env, struct bpf_verifier_stat
return propagate_backedges(env, visit);
}
+/*
+ * @st left the loop that @insn_idx of its current frame is in. The loop is
+ * left when the frame that bpf_scc_visit is for leaves it. Loops in callees
+ * of that frame are part of one trip around the loop of the caller.
+ */
+void bpf_scc_mark_exit(struct bpf_verifier_env *env, struct bpf_verifier_state *st, int insn_idx)
+{
+ struct bpf_scc_callchain *callchain = &env->callchain_buf;
+ struct bpf_scc_visit *visit;
+ u32 i, callsite;
+
+ if (st->speculative || !env->insn_aux_data[insn_idx].scc)
+ return;
+ memset(callchain, 0, sizeof(*callchain));
+ for (i = 0; i < st->curframe; i++) {
+ callsite = bpf_frame_insn_idx(st, i);
+ if (env->insn_aux_data[callsite].scc)
+ return;
+ callchain->callsites[i] = callsite;
+ }
+ callchain->scc = env->insn_aux_data[insn_idx].scc;
+ visit = scc_visit_lookup(env, callchain);
+ if (visit)
+ visit->exited = true;
+}
+
/* Lookup an bpf_scc_visit instance corresponding to @st callchain
* and add @backedge to visit->backedges. @st callchain must exist.
*/
@@ -244,6 +281,8 @@ static int add_scc_backedge(struct bpf_verifier_env *env,
}
if (env->log.level & BPF_LOG_LEVEL2)
verbose(env, "SCC backedge %s\n", format_callchain(env, callchain));
+ if (env->scc_converged)
+ __set_bit(callchain->scc, env->scc_converged);
backedge->next = visit->backedges;
visit->backedges = backedge;
visit->num_backedges++;
@@ -1108,6 +1147,62 @@ static int propagate_backedges(struct bpf_verifier_env *env, struct bpf_scc_visi
return 0;
}
+/* Did the walk get to @insn_idx over a back-edge? */
+static bool is_backedge(struct bpf_verifier_env *env, int insn_idx)
+{
+ int prev = env->prev_insn_idx;
+ struct bpf_insn_aux_data *aux;
+ struct bpf_insn *insn;
+
+ if (prev < 0 || prev >= env->prog->len)
+ return false;
+ aux = &env->insn_aux_data[prev];
+ insn = &env->prog->insnsi[prev];
+ /* check_cfg() does not record the edge of an unconditional jump as a jump */
+ if ((BPF_CLASS(insn->code) == BPF_JMP || BPF_CLASS(insn->code) == BPF_JMP32) &&
+ BPF_OP(insn->code) == BPF_JA)
+ return aux->backedge_ft || aux->backedge_br;
+ return insn_idx == prev + 1 ? aux->backedge_ft : aux->backedge_br;
+}
+
+static bool iter_active_depths_differ(struct bpf_verifier_state *old,
+ struct bpf_verifier_state *cur);
+
+/* The state of this walk that was the last to get to loop head @insn_idx. */
+static struct bpf_verifier_state *loop_head_state(struct bpf_verifier_env *env, int insn_idx)
+{
+ struct bpf_verifier_state *cur = env->cur_state;
+ struct bpf_verifier_state_list *sl;
+ struct list_head *pos;
+
+ /* states are most recent first */
+ list_for_each(pos, bpf_explored_state(env, insn_idx)) {
+ sl = container_of(pos, struct bpf_verifier_state_list, node);
+ if (sl->state.insn_idx == insn_idx && sl->state.branches &&
+ bpf_same_loop(&sl->state, cur))
+ return &sl->state;
+ }
+ return NULL;
+}
+
+/*
+ * @cur got to loop head @insn_idx, @old is the state that started this trip
+ * around the loop if there is one. The trip is bounded at run time if it
+ * took from the budget of may_goto or got an element from an iterator.
+ * Otherwise may_goto has to be added to the back-edge if the loop is not
+ * walked to the end. Returns false if that is not possible.
+ */
+static bool loop_head_guard(struct bpf_verifier_env *env, int insn_idx,
+ struct bpf_verifier_state *old, struct bpf_verifier_state *cur)
+{
+ if (!is_backedge(env, insn_idx))
+ return true;
+ if (old && (old->may_goto_depth != cur->may_goto_depth ||
+ iter_active_depths_differ(old, cur)))
+ return true;
+ return bpf_mark_loop_guard(env, cur);
+}
+
static bool states_maybe_looping(struct bpf_verifier_state *old,
struct bpf_verifier_state *cur)
{
@@ -1237,12 +1332,23 @@ int bpf_is_state_visited(struct bpf_verifier_env *env, int insn_idx)
{
struct bpf_verifier_state_list *new_sl;
struct bpf_verifier_state_list *sl;
- struct bpf_verifier_state *cur = env->cur_state, *new;
+ struct bpf_verifier_state *cur = env->cur_state, *new, *widen_from = NULL;
+ bool loop_head = env->widen_loops && env->insn_aux_data[insn_idx].loop_head;
bool force_new_state, add_new_state, loop;
int n, err, states_cnt = 0;
struct list_head *pos, *tmp, *head;
+ if (loop_head) {
+ widen_from = loop_head_state(env, insn_idx);
+ /* the loop cannot be bounded at run time, walk all of it */
+ if (!loop_head_guard(env, insn_idx, widen_from, cur)) {
+ loop_head = false;
+ widen_from = NULL;
+ }
+ }
+
force_new_state = env->test_state_freq || bpf_is_force_checkpoint(env, insn_idx) ||
+ loop_head ||
/* Avoid accumulating infinitely long jmp history */
cur->jmp_history_cnt > 40;
@@ -1364,12 +1470,32 @@ int bpf_is_state_visited(struct bpf_verifier_env *env, int insn_idx)
}
goto skip_inf_loop_check;
}
+ /*
+ * The state came back to the loop head. If it is within
+ * the state that went around the loop nothing new can
+ * happen on the next trip. Otherwise it is widened below
+ * and goes around instead of all the iterations it stands for.
+ */
+ if (loop_head && bpf_same_loop(&sl->state, cur)) {
+ if (states_equal(env, &sl->state, cur, RANGE_WITHIN)) {
+ env->widen_used = true;
+ loop = true;
+ goto hit;
+ }
+ goto skip_inf_loop_check;
+ }
/* attempt to detect infinite loop to avoid unnecessary doomed work */
if (states_maybe_looping(&sl->state, cur) &&
states_equal(env, &sl->state, cur, EXACT) &&
!iter_active_depths_differ(&sl->state, cur) &&
sl->state.may_goto_depth == cur->may_goto_depth &&
sl->state.callback_unroll_depth == cur->callback_unroll_depth) {
+ /* the state repeats, nothing new on the next trip */
+ if (env->widen_loops) {
+ env->widen_used = true;
+ loop = true;
+ goto hit;
+ }
verbose_linfo(env, insn_idx, "; ");
verbose(env, "infinite loop detected at insn %d\n", insn_idx);
verbose(env, "cur state:");
@@ -1402,6 +1528,9 @@ int bpf_is_state_visited(struct bpf_verifier_env *env, int insn_idx)
if (states_equal(env, &sl->state, cur, loop ? RANGE_WITHIN : NOT_EXACT)) {
hit:
sl->hit_cnt++;
+ /* what follows the old state was seen, it may leave the loop */
+ if (env->widen_loops && !sl->state.branches)
+ bpf_scc_mark_exit(env, cur, insn_idx);
/* if previous state reached the exit with precision and
* current state is equivalent to it (except precision marks)
@@ -1522,7 +1651,8 @@ int bpf_is_state_visited(struct bpf_verifier_env *env, int insn_idx)
* Use bigger 'n' for checkpoints because evicting checkpoint states
* too early would hinder iterator convergence.
*/
- n = bpf_is_force_checkpoint(env, insn_idx) && sl->state.branches > 0 ? 64 : 3;
+ n = (bpf_is_force_checkpoint(env, insn_idx) || loop_head) &&
+ sl->state.branches > 0 ? 64 : 3;
if (sl->miss_cnt > sl->hit_cnt * n + n) {
/* the state is unlikely to be useful. Remove it to
* speed up verification
@@ -1539,6 +1669,16 @@ int bpf_is_state_visited(struct bpf_verifier_env *env, int insn_idx)
if (env->max_states_per_insn < states_cnt)
env->max_states_per_insn = states_cnt;
+ if (loop_head) {
+ cur->loop_passes = 0;
+ if (widen_from) {
+ err = bpf_widen_loop_head(env, insn_idx, is_backedge(env, insn_idx),
+ widen_from, cur);
+ if (err)
+ return err;
+ }
+ }
+
if (!env->bpf_capable && states_cnt > BPF_COMPLEXITY_LIMIT_STATES)
return 0;
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index a7c9e2d8965d5..871aa45031d61 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -1733,6 +1733,7 @@ int bpf_copy_verifier_state(struct bpf_verifier_state *dst_state,
dst_state->dfs_depth = src->dfs_depth;
dst_state->callback_unroll_depth = src->callback_unroll_depth;
dst_state->may_goto_depth = src->may_goto_depth;
+ dst_state->loop_passes = src->loop_passes;
dst_state->equal_state = src->equal_state;
for (i = 0; i <= src->curframe; i++) {
dst = dst_state->frame[i];
@@ -2094,9 +2095,71 @@ static struct cnum64 cnum64_from_tnum(struct tnum tnum)
return cnum64_from_urange(tnum.value, (tnum.value | tnum.mask));
}
+/* smallest member of @t that is >= @x, wraps around to the smallest member of @t */
+static u64 tnum_member_ge(struct tnum t, u64 x)
+{
+ if ((x & ~t.mask) == t.value)
+ return x;
+ if (x > (t.value | t.mask))
+ return t.value;
+ return tnum_step(t, x);
+}
+
+/* largest member of @t that is <= @x, wraps around to the largest member of @t */
+static u64 tnum_member_le(struct tnum t, u64 x)
+{
+ /* members of 'tc' are bitwise complements of members of 't' */
+ struct tnum tc = { .value = ~(t.value | t.mask), .mask = t.mask };
+
+ return ~tnum_member_ge(tc, ~x);
+}
+
+/*
+ * Move both ends of arc @c inwards to the nearest members of @t.
+ * Values that are dropped are not members of @t.
+ */
+static struct cnum64 cnum64_tighten_by_tnum(struct cnum64 c, struct tnum t)
+{
+ u64 lo, hi, dlo, dhi;
+
+ if (cnum64_is_empty(c) || c.size == U64_MAX || !t.mask)
+ return c;
+ lo = tnum_member_ge(t, c.base);
+ dlo = lo - c.base;
+ if (dlo > c.size)
+ return c;
+ hi = tnum_member_le(t, c.base + c.size);
+ dhi = c.base + c.size - hi;
+ if (dhi > c.size - dlo)
+ return c;
+ return (struct cnum64){ .base = lo, .size = c.size - dlo - dhi };
+}
+
+static struct cnum32 cnum32_tighten_by_tnum(struct cnum32 c, struct tnum t)
+{
+ struct tnum tc;
+ u32 lo, hi, dlo, dhi;
+
+ t = tnum_subreg(t);
+ if (cnum32_is_empty(c) || c.size == U32_MAX || !t.mask)
+ return c;
+ lo = tnum_member_ge(t, c.base);
+ dlo = lo - c.base;
+ if (dlo > c.size)
+ return c;
+ /* complement within 32 bits */
+ tc = (struct tnum){ .value = (u32)~(t.value | t.mask), .mask = t.mask };
+ hi = ~(u32)tnum_member_ge(tc, (u32)~(c.base + c.size));
+ dhi = c.base + c.size - hi;
+ if (dhi > c.size - dlo)
+ return c;
+ return (struct cnum32){ .base = lo, .size = c.size - dlo - dhi };
+}
+
static void __update_reg32_bounds(struct bpf_reg_state *reg)
{
cnum32_intersect_with(®->r32, cnum32_from_tnum(reg->var_off));
+ reg->r32 = cnum32_tighten_by_tnum(reg->r32, reg->var_off);
}
static void __update_reg64_bounds(struct bpf_reg_state *reg)
@@ -2105,6 +2168,7 @@ static void __update_reg64_bounds(struct bpf_reg_state *reg)
bool umin_in_tnum;
cnum64_intersect_with(®->r64, cnum64_from_tnum(reg->var_off));
+ reg->r64 = cnum64_tighten_by_tnum(reg->r64, reg->var_off);
/* Check if u64 and tnum overlap in a single value */
tnum_next = tnum_step(reg->var_off, reg_umin(reg));
@@ -7977,6 +8041,354 @@ static struct bpf_verifier_state *find_prev_entry(struct bpf_verifier_env *env,
return NULL;
}
+/* A constant that register @regno is compared with, -1 if any register. */
+struct widen_thr {
+ s64 val;
+ int regno;
+};
+
+struct bpf_widen_thrs {
+ u32 cnt;
+ struct widen_thr thr[];
+};
+
+/* passes around a loop that widen to constants the loop compares with */
+#define WIDEN_THR_PASSES 4
+/* passes that widen to S32_MAX and the like, later ones drop the bound */
+#define WIDEN_GEN_PASSES 6
+/* states at the loop head differ in something that can't be widened */
+#define WIDEN_MAX_PASSES 10
+
+static const struct widen_thr widen_generic[] = {
+ { S32_MIN, -1 }, { 0, -1 }, { S32_MAX, -1 }, { U32_MAX, -1 },
+};
+
+static int cmp_widen_thr(const void *a, const void *b)
+{
+ s64 x = ((const struct widen_thr *)a)->val;
+ s64 y = ((const struct widen_thr *)b)->val;
+
+ return x < y ? -1 : x > y;
+}
+
+static bool is_cmp_imm(const struct bpf_insn *insn)
+{
+ u8 class = BPF_CLASS(insn->code);
+ u8 op = BPF_OP(insn->code);
+
+ if (class != BPF_JMP && class != BPF_JMP32)
+ return false;
+ if (BPF_SRC(insn->code) != BPF_K)
+ return false;
+ return op != BPF_JA && op != BPF_CALL && op != BPF_EXIT && op != BPF_JCOND;
+}
+
+/*
+ * Sorted constants that registers are compared with in the SCC of @insn_idx.
+ * A range that ends at one of them can be cut back by the exit test of
+ * the loop, so that the state at the loop head stops growing.
+ */
+static const struct bpf_widen_thrs *scc_thresholds(struct bpf_verifier_env *env, int insn_idx)
+{
+ struct bpf_insn_aux_data *aux = env->insn_aux_data;
+ struct bpf_insn *insns = env->prog->insnsi;
+ u32 scc = aux[insn_idx].scc;
+ struct bpf_widen_thrs *thrs;
+ int i, d, n = 0;
+
+ if (!scc)
+ return NULL;
+ if (!env->scc_thrs) {
+ env->scc_thrs = kvzalloc_objs(*env->scc_thrs, env->scc_cnt, GFP_KERNEL_ACCOUNT);
+ if (!env->scc_thrs)
+ return NULL;
+ }
+ if (env->scc_thrs[scc])
+ return env->scc_thrs[scc];
+
+ for (i = 0; i < env->prog->len; i++)
+ if (aux[i].scc == scc && is_cmp_imm(&insns[i]))
+ n++;
+ thrs = kvzalloc(struct_size(thrs, thr, 3 * n), GFP_KERNEL_ACCOUNT);
+ if (!thrs)
+ return NULL;
+ for (i = 0; i < env->prog->len; i++) {
+ if (aux[i].scc != scc || !is_cmp_imm(&insns[i]))
+ continue;
+ for (d = -1; d <= 1; d++) {
+ thrs->thr[thrs->cnt].val = (s64)insns[i].imm + d;
+ thrs->thr[thrs->cnt++].regno = insns[i].dst_reg;
+ }
+ }
+ sort(thrs->thr, thrs->cnt, sizeof(thrs->thr[0]), cmp_widen_thr, NULL);
+ env->scc_thrs[scc] = thrs;
+ return thrs;
+}
+
+/*
+ * Nearest constant in sorted @thr that is >= @x if @up, <= @x otherwise.
+ * Constants that another register is compared with are skipped.
+ */
+static bool thr_nearest(const struct widen_thr *thr, u32 cnt, int regno, s64 x, bool up,
+ s64 *res)
+{
+ bool found = false;
+ u32 i;
+
+ for (i = 0; i < cnt; i++) {
+ if (regno >= 0 && thr[i].regno >= 0 && thr[i].regno != regno)
+ continue;
+ if (up && thr[i].val >= x) {
+ *res = thr[i].val;
+ return true;
+ }
+ if (!up && thr[i].val <= x) {
+ *res = thr[i].val;
+ found = true;
+ }
+ }
+ return found;
+}
+
+struct widen_ctx {
+ const struct bpf_widen_thrs *thrs;
+ u32 passes;
+ int regno;
+};
+
+/* Where to move the end @x of a range that keeps moving up or down. */
+static bool widen_pick(const struct widen_ctx *w, s64 x, bool up, s64 *res)
+{
+ bool found = false;
+ s64 t;
+
+ if (w->passes <= WIDEN_THR_PASSES && w->thrs &&
+ thr_nearest(w->thrs->thr, w->thrs->cnt, w->regno, x, up, &t)) {
+ *res = t;
+ found = true;
+ }
+ if (w->passes <= WIDEN_GEN_PASSES &&
+ thr_nearest(widen_generic, ARRAY_SIZE(widen_generic), -1, x, up, &t)) {
+ *res = !found ? t : up ? min(*res, t) : max(*res, t);
+ found = true;
+ }
+ return found;
+}
+
+static s64 widen_smax(const struct widen_ctx *w, s64 x, s64 lim)
+{
+ s64 t;
+
+ return widen_pick(w, x, true, &t) && t <= lim ? t : lim;
+}
+
+static s64 widen_smin(const struct widen_ctx *w, s64 x, s64 lim)
+{
+ s64 t;
+
+ return widen_pick(w, x, false, &t) && t >= lim ? t : lim;
+}
+
+static u64 widen_umax(const struct widen_ctx *w, u64 x, u64 lim)
+{
+ s64 t;
+
+ if (x > S64_MAX || !widen_pick(w, x, true, &t) || (u64)t > lim)
+ return lim;
+ return t;
+}
+
+static u64 widen_umin(const struct widen_ctx *w, u64 x)
+{
+ s64 t;
+
+ if (!widen_pick(w, min_t(u64, x, S64_MAX), false, &t) || t < 0)
+ return 0;
+ return t;
+}
+
+/*
+ * @old is the state of a register at the loop head, @cur is its state after
+ * a trip around the loop. If @cur has values that @old doesn't have make @cur
+ * a guess of all the values the register can have at the loop head: both
+ * @old and @cur, and where an end of the range moved it is moved further,
+ * to the nearest constant the loop compares the register with.
+ * Whether the guess is good is seen on the next trip: the state that comes
+ * back has to be within it.
+ */
+static void widen_reg(const struct widen_ctx *w, const struct bpf_reg_state *old,
+ struct bpf_reg_state *cur)
+{
+ u64 umin, umax, low;
+ u32 u32_min, u32_max;
+ s32 s32_min, s32_max;
+ s64 smin, smax;
+ struct tnum t;
+
+ if (old->type != SCALAR_VALUE || cur->type != SCALAR_VALUE)
+ return;
+ if (cnum64_is_subset(old->r64, cur->r64) && cnum32_is_subset(old->r32, cur->r32) &&
+ tnum_in(old->var_off, cur->var_off))
+ return;
+
+ umin = min(reg_umin(old), reg_umin(cur));
+ umax = max(reg_umax(old), reg_umax(cur));
+ smin = min(reg_smin(old), reg_smin(cur));
+ smax = max(reg_smax(old), reg_smax(cur));
+ u32_min = min(reg_u32_min(old), reg_u32_min(cur));
+ u32_max = max(reg_u32_max(old), reg_u32_max(cur));
+ s32_min = min(reg_s32_min(old), reg_s32_min(cur));
+ s32_max = max(reg_s32_max(old), reg_s32_max(cur));
+
+ if (reg_umin(cur) < reg_umin(old))
+ umin = widen_umin(w, umin);
+ if (reg_umax(cur) > reg_umax(old))
+ umax = widen_umax(w, umax, U64_MAX);
+ if (reg_smin(cur) < reg_smin(old))
+ smin = widen_smin(w, smin, S64_MIN);
+ if (reg_smax(cur) > reg_smax(old))
+ smax = widen_smax(w, smax, S64_MAX);
+ if (reg_u32_min(cur) < reg_u32_min(old))
+ u32_min = widen_umin(w, u32_min);
+ if (reg_u32_max(cur) > reg_u32_max(old))
+ u32_max = widen_umax(w, u32_max, U32_MAX);
+ if (reg_s32_min(cur) < reg_s32_min(old))
+ s32_min = widen_smin(w, s32_min, S32_MIN);
+ if (reg_s32_max(cur) > reg_s32_max(old))
+ s32_max = widen_smax(w, s32_max, S32_MAX);
+
+ /* low bits that are the same in all values seen so far are kept, e.g. alignment */
+ t = tnum_union(old->var_off, cur->var_off);
+ low = t.mask ? BIT_ULL(__ffs64(t.mask)) - 1 : 0;
+ cur->var_off = (struct tnum){ .value = t.value & low, .mask = ~low };
+ cur->r64 = cnum64_intersect(cnum64_from_urange(umin, umax),
+ cnum64_from_srange(smin, smax));
+ cur->r32 = cnum32_intersect(cnum32_from_urange(u32_min, u32_max),
+ cnum32_from_srange(s32_min, s32_max));
+ cur->id = 0;
+ cur->delta = 0;
+ reg_bounds_sync(cur);
+}
+
+bool bpf_same_loop(struct bpf_verifier_state *old, struct bpf_verifier_state *cur)
+{
+ return old->speculative == cur->speculative && same_callsites(old, cur);
+}
+
+/*
+ * @cur came to loop head @insn_idx and is not within @old, the state that
+ * went around the loop. Widen scalars of @cur, so that the walk goes around
+ * the loop with a state that stands for many iterations, see widen_reg().
+ * Everything else is left as is. If that is what differs the states never
+ * converge and the walk is given up after a few trips.
+ */
+int bpf_widen_loop_head(struct bpf_verifier_env *env, int insn_idx, bool backedge,
+ struct bpf_verifier_state *old, struct bpf_verifier_state *cur)
+{
+ /* @old is of an earlier run of the loop if @cur just entered it */
+ u32 passes = backedge ? old->loop_passes + 1 : 1;
+ struct widen_ctx w = { scc_thresholds(env, insn_idx), passes };
+ struct bpf_func_state *fold, *fcur;
+ int i, fr, num_slots;
+
+ env->widen_used = true;
+ if (passes > WIDEN_MAX_PASSES) {
+ verbose(env, "states at loop head %d don't converge\n", insn_idx);
+ return -E2BIG;
+ }
+
+ for (fr = 0; fr <= cur->curframe; fr++) {
+ fold = old->frame[fr];
+ fcur = cur->frame[fr];
+
+ for (i = 0; i < BPF_REG_FP; i++) {
+ /* registers of callers are not the ones the loop compares */
+ w.regno = fr == cur->curframe ? i : -1;
+ widen_reg(&w, &fold->regs[i], &fcur->regs[i]);
+ }
+
+ w.regno = -1;
+ num_slots = min(fold->allocated_stack, fcur->allocated_stack) / BPF_REG_SIZE;
+ for (i = 0; i < num_slots; i++) {
+ if (!bpf_is_spilled_reg(&fold->stack[i]) ||
+ !bpf_is_spilled_reg(&fcur->stack[i]))
+ continue;
+ widen_reg(&w, &fold->stack[i].spilled_ptr, &fcur->stack[i].spilled_ptr);
+ }
+ }
+ cur->loop_passes = passes;
+ if (env->log.level & BPF_LOG_LEVEL2)
+ verbose(env, "loop head %d widened, pass %u\n", insn_idx, passes);
+ return 0;
+}
+
+static bool program_returns_void(struct bpf_verifier_env *env);
+static bool return_retval_range(struct bpf_verifier_env *env, struct bpf_retval_range *range);
+
+/* Why bpf_throw() cannot be called in @st, NULL if it can. */
+static const char *cannot_throw(struct bpf_verifier_env *env, struct bpf_verifier_state *st)
+{
+ struct bpf_retval_range range;
+ struct bpf_func_state *frame;
+ int i;
+
+ if (!env->prog->jit_requested || !bpf_jit_supports_exceptions())
+ return "JIT does not support exceptions";
+ for (i = 0; i < st->acquired_refs; i++)
+ if (st->refs[i].type == REF_TYPE_PTR)
+ return "reference is held";
+ if (st->active_locks || st->active_irq_id || st->active_rcu_locks ||
+ st->active_preempt_locks)
+ return "lock is held";
+ for (i = 0; i <= st->curframe; i++) {
+ frame = st->frame[i];
+ if (frame->in_callback_fn || frame->in_async_callback_fn ||
+ frame->in_exception_callback_fn)
+ return "in callback";
+ }
+ /* callers of the global function were not told that it can throw */
+ if (st->frame[0]->subprogno && !subprog_info(env, st->frame[0]->subprogno)->might_throw)
+ return "in global function";
+ /* default exception callback returns the cookie, that is 0 */
+ if (!env->exception_callback_subprog && !program_returns_void(env) &&
+ resolve_prog_type(env->prog) != BPF_PROG_TYPE_STRUCT_OPS &&
+ return_retval_range(env, &range) && (range.minval > 0 || range.maxval < 0))
+ return "0 is not a valid return value";
+ return NULL;
+}
+
+/*
+ * The walk went over the back-edge of env->prev_insn_idx and nothing bounds
+ * the number of trips. If the loop is not walked to the end may_goto that
+ * ends in bpf_throw() is added to the back-edge, see commit_loop_guards().
+ * Returns false when that cannot be done in state @cur.
+ */
+bool bpf_mark_loop_guard(struct bpf_verifier_env *env, struct bpf_verifier_state *cur)
+{
+ struct bpf_insn_aux_data *aux = &env->insn_aux_data[env->prev_insn_idx];
+ struct bpf_insn *insn = &env->prog->insnsi[env->prev_insn_idx];
+ u8 class = BPF_CLASS(insn->code);
+ u8 op = BPF_OP(insn->code);
+ const char *why;
+
+ why = cannot_throw(env, cur);
+ if ((class != BPF_JMP && class != BPF_JMP32) ||
+ op == BPF_CALL || op == BPF_EXIT || op == BPF_JCOND ||
+ (op == BPF_JA && BPF_SRC(insn->code) == BPF_X))
+ why = "not a jump";
+ else if (op != BPF_JA && aux->backedge_ft && aux->backedge_br)
+ why = "both edges are back-edges";
+ if (why) {
+ if (env->log.level & BPF_LOG_LEVEL2)
+ verbose(env, "cannot add may_goto to back-edge of insn %d: %s\n",
+ env->prev_insn_idx, why);
+ aux->guard_impossible = true;
+ return false;
+ }
+ aux->guard_pending = true;
+ return true;
+}
+
/*
* Check if scalar registers are exact for the purpose of not widening.
* More lenient than regs_exact()
@@ -18847,6 +19259,21 @@ static int do_check_insn(struct bpf_verifier_env *env, bool *do_print_state)
return -EFAULT;
}
+/* Did the jump at @prev take the walk out of the loop @prev is in? */
+static bool left_loop(struct bpf_verifier_env *env, int prev, int insn_idx)
+{
+ struct bpf_insn_aux_data *aux = env->insn_aux_data;
+ struct bpf_insn *insn;
+
+ if (prev < 0 || prev >= env->prog->len || !aux[prev].scc ||
+ aux[prev].scc == aux[insn_idx].scc)
+ return false;
+ /* the callee is not in SCC of the call, the insn after the call is */
+ insn = &env->prog->insnsi[prev];
+ return !((BPF_CLASS(insn->code) == BPF_JMP || BPF_CLASS(insn->code) == BPF_JMP32) &&
+ BPF_OP(insn->code) == BPF_CALL);
+}
+
static int do_check(struct bpf_verifier_env *env)
{
bool pop_log = !(env->log.level & BPF_LOG_LEVEL2);
@@ -18885,6 +19312,8 @@ static int do_check(struct bpf_verifier_env *env)
state->last_insn_idx = env->prev_insn_idx;
state->insn_idx = env->insn_idx;
+ if (env->widen_loops && left_loop(env, prev_insn_idx, env->insn_idx))
+ bpf_scc_mark_exit(env, state, prev_insn_idx);
/*
* Record the incoming edge so active and queued paths use the same
* branch-recording path. A zero-offset conditional has identical
@@ -18907,7 +19336,9 @@ static int do_check(struct bpf_verifier_env *env)
}
}
- if (bpf_is_prune_point(env, env->insn_idx)) {
+ /* loop heads are where states are widened, all of them have to be looked at */
+ if (bpf_is_prune_point(env, env->insn_idx) ||
+ (env->widen_loops && insn_aux->loop_head)) {
err = bpf_is_state_visited(env, env->insn_idx);
if (err < 0)
return err;
@@ -19011,6 +19442,9 @@ static int do_check(struct bpf_verifier_env *env)
} else if (err < 0) {
return err;
} else if (err == PROCESS_BPF_EXIT) {
+ /* exit or bpf_throw() inside of a loop */
+ if (env->widen_loops)
+ bpf_scc_mark_exit(env, state, env->insn_idx);
goto process_bpf_exit;
} else if (err == INSN_IDX_UPDATED) {
} else if (err == 0) {
@@ -20102,6 +20536,122 @@ static int do_check_common(struct bpf_verifier_env *env, int subprog)
return ret;
}
+/* What a walk changes outside of verifier states and per insn data. */
+struct walk_snapshot {
+ struct bpf_insn_aux_data *insn_aux;
+ struct bpf_func_info_aux *func_aux;
+ struct bpf_subprog_info *subprogs;
+ struct bpf_prog *prog;
+ u64 log_pos, diag_pos;
+ u32 insn_processed, prev_insn_processed;
+ u32 jmps_processed, prev_jmps_processed;
+ u32 total_states, peak_states, max_states_per_insn, longest_mark_read_walk;
+ u32 explored_states_size, free_list_size, num_backedges;
+ u32 id_gen, pass_cnt, max_stack_depth;
+ u32 max_ctx_offset, max_pkt_offset, max_tp_access, max_rdonly_access, max_rdwr_access;
+ bool seen_direct_write, seen_exception, explore_alu_limits, tail_call_reachable;
+ void *arena;
+};
+
+static void walk_snapshot_free(struct walk_snapshot *s)
+{
+ kvfree(s->insn_aux);
+ kvfree(s->func_aux);
+ kvfree(s->subprogs);
+ kfree(s->prog);
+}
+
+static size_t func_aux_size(struct bpf_verifier_env *env)
+{
+ return array_size(env->prog->aux->func_info_cnt, sizeof(*env->prog->aux->func_info_aux));
+}
+
+static int walk_snapshot_save(struct bpf_verifier_env *env, struct walk_snapshot *s)
+{
+ struct bpf_prog_aux *aux = env->prog->aux;
+
+ memset(s, 0, sizeof(*s));
+ s->insn_aux = kvmemdup(env->insn_aux_data,
+ array_size(env->prog->len, sizeof(*env->insn_aux_data)),
+ GFP_KERNEL_ACCOUNT);
+ s->subprogs = kvmemdup(env->subprog_info, sizeof(env->subprog_info), GFP_KERNEL_ACCOUNT);
+ /* flags of the program, not its insns */
+ s->prog = kmemdup(env->prog, offsetof(struct bpf_prog, insnsi), GFP_KERNEL_ACCOUNT);
+ if (aux->func_info_aux)
+ s->func_aux = kvmemdup(aux->func_info_aux, func_aux_size(env), GFP_KERNEL_ACCOUNT);
+ if (!s->insn_aux || !s->subprogs || !s->prog || (aux->func_info_aux && !s->func_aux)) {
+ walk_snapshot_free(s);
+ return -ENOMEM;
+ }
+ s->log_pos = env->log.end_pos;
+ s->diag_pos = bpf_diag_event_log_save(env);
+ s->insn_processed = env->insn_processed;
+ s->prev_insn_processed = env->prev_insn_processed;
+ s->jmps_processed = env->jmps_processed;
+ s->prev_jmps_processed = env->prev_jmps_processed;
+ s->total_states = env->total_states;
+ s->peak_states = env->peak_states;
+ s->max_states_per_insn = env->max_states_per_insn;
+ s->longest_mark_read_walk = env->longest_mark_read_walk;
+ s->explored_states_size = env->explored_states_size;
+ s->free_list_size = env->free_list_size;
+ s->num_backedges = env->num_backedges;
+ s->id_gen = env->id_gen;
+ s->pass_cnt = env->pass_cnt;
+ s->max_stack_depth = env->max_stack_depth;
+ s->seen_direct_write = env->seen_direct_write;
+ s->seen_exception = env->seen_exception;
+ s->explore_alu_limits = env->explore_alu_limits;
+ s->max_ctx_offset = aux->max_ctx_offset;
+ s->max_pkt_offset = aux->max_pkt_offset;
+ s->max_tp_access = aux->max_tp_access;
+ s->max_rdonly_access = aux->max_rdonly_access;
+ s->max_rdwr_access = aux->max_rdwr_access;
+ s->tail_call_reachable = aux->tail_call_reachable;
+ s->arena = aux->arena;
+ return 0;
+}
+
+static void walk_snapshot_restore(struct bpf_verifier_env *env, struct walk_snapshot *s)
+{
+ struct bpf_prog_aux *aux = env->prog->aux;
+
+ memcpy(env->insn_aux_data, s->insn_aux,
+ array_size(env->prog->len, sizeof(*env->insn_aux_data)));
+ memcpy(env->subprog_info, s->subprogs, sizeof(env->subprog_info));
+ memcpy(env->prog, s->prog, offsetof(struct bpf_prog, insnsi));
+ if (s->func_aux)
+ memcpy(aux->func_info_aux, s->func_aux, func_aux_size(env));
+ env->insn_wasted += env->insn_processed - s->insn_processed;
+ env->insn_processed = s->insn_processed;
+ env->prev_insn_processed = s->prev_insn_processed;
+ env->jmps_processed = s->jmps_processed;
+ env->prev_jmps_processed = s->prev_jmps_processed;
+ env->total_states = s->total_states;
+ env->peak_states = s->peak_states;
+ env->max_states_per_insn = s->max_states_per_insn;
+ env->longest_mark_read_walk = s->longest_mark_read_walk;
+ env->explored_states_size = s->explored_states_size;
+ env->free_list_size = s->free_list_size;
+ env->num_backedges = s->num_backedges;
+ env->id_gen = s->id_gen;
+ env->pass_cnt = s->pass_cnt;
+ env->max_stack_depth = s->max_stack_depth;
+ env->seen_direct_write = s->seen_direct_write;
+ env->seen_exception = s->seen_exception;
+ env->explore_alu_limits = s->explore_alu_limits;
+ aux->max_ctx_offset = s->max_ctx_offset;
+ aux->max_pkt_offset = s->max_pkt_offset;
+ aux->max_tp_access = s->max_tp_access;
+ aux->max_rdonly_access = s->max_rdonly_access;
+ aux->max_rdwr_access = s->max_rdwr_access;
+ aux->tail_call_reachable = s->tail_call_reachable;
+ aux->arena = s->arena;
+ if (!(env->log.level & BPF_LOG_LEVEL2))
+ bpf_vlog_reset(&env->log, s->log_pos);
+ bpf_diag_event_log_restore(env, s->diag_pos);
+}
+
/* Lazily verify all global functions based on their BTF, if they are called
* from main BPF program or any of subprograms transitively.
* BPF global subprogs called from dead code are not validated.
@@ -20183,6 +20733,51 @@ static int do_check_main(struct bpf_verifier_env *env)
return ret;
}
+/*
+ * Walk the program with loops widened first. It is much less work when it
+ * succeeds. If it fails the reason can be the precision that widening gave
+ * up. Then undo everything that walk did, so that the walk of every
+ * iteration that follows can't tell that it is not the first one.
+ * It is all or nothing for the main program and global functions, because
+ * may_goto added to a loop of a static function is there for all callers.
+ */
+static int do_check_prog(struct bpf_verifier_env *env)
+{
+ struct walk_snapshot snap;
+ int ret;
+
+ /* no loops without bpf_capable, the driver of an offloaded prog sees every insn visit */
+ if (!env->bpf_capable || env->scc_cnt <= 1 || bpf_prog_is_offloaded(env->prog->aux)) {
+ ret = do_check_main(env);
+ return ret ?: do_check_subprogs(env);
+ }
+
+ env->scc_converged = kvzalloc_objs(*env->scc_converged, BITS_TO_LONGS(env->scc_cnt),
+ GFP_KERNEL_ACCOUNT);
+ if (!env->scc_converged)
+ return -ENOMEM;
+ ret = walk_snapshot_save(env, &snap);
+ if (ret)
+ return ret;
+
+ env->widen_loops = true;
+ env->widen_used = false;
+ ret = do_check_main(env);
+ ret = ret ?: do_check_subprogs(env);
+ if (!ret && env->widen_used)
+ ret = bpf_commit_loop_guards(env);
+ env->widen_loops = false;
+ if (ret && ret != -ENOMEM && ret != -EAGAIN && ret != -EFAULT && env->widen_used) {
+ walk_snapshot_restore(env, &snap);
+ if (env->log.level & BPF_LOG_LEVEL)
+ verbose(env, "walk with widened loops failed, walking every iteration\n");
+ ret = do_check_main(env);
+ ret = ret ?: do_check_subprogs(env);
+ }
+ walk_snapshot_free(&snap);
+ return ret;
+}
+
static void print_verification_stats(struct bpf_verifier_env *env)
{
/* Skip over hidden subprogs which are not verified. */
@@ -20211,6 +20806,9 @@ static void print_verification_stats(struct bpf_verifier_env *env)
env->insn_processed, BPF_COMPLEXITY_LIMIT_INSNS,
env->max_states_per_insn, env->total_states,
env->peak_states, env->longest_mark_read_walk);
+ if (env->insn_wasted)
+ verbose(env, "walks with widened loops that failed processed %d insns\n",
+ env->insn_wasted);
}
int bpf_prog_ctx_arg_info_init(struct bpf_prog *prog,
@@ -21853,8 +22451,7 @@ int bpf_check(struct bpf_prog **prog, union bpf_attr *attr, bpfptr_t uattr,
if (ret < 0)
goto skip_full_check;
- ret = do_check_main(env);
- ret = ret ?: do_check_subprogs(env);
+ ret = do_check_prog(env);
if (ret == 0 && bpf_prog_is_offloaded(env->prog->aux))
ret = bpf_prog_offload_finalize(env);
@@ -21996,6 +22593,12 @@ int bpf_check(struct bpf_prog **prog, union bpf_attr *attr, bpfptr_t uattr,
bpf_stack_liveness_free(env);
kvfree(env->cfg.insn_postorder);
kvfree(env->scc_info);
+ kvfree(env->scc_converged);
+ if (env->scc_thrs) {
+ for (i = 0; i < env->scc_cnt; i++)
+ kvfree(env->scc_thrs[i]);
+ kvfree(env->scc_thrs);
+ }
kvfree(env->succ);
kvfree(env->gotox_tmp_buf);
bpf_diag_free(env);
diff --git a/tools/testing/selftests/bpf/prog_tests/bpf_verif_scale.c b/tools/testing/selftests/bpf/prog_tests/bpf_verif_scale.c
index 902a70d5afeb6..2dc37090d7a4f 100644
--- a/tools/testing/selftests/bpf/prog_tests/bpf_verif_scale.c
+++ b/tools/testing/selftests/bpf/prog_tests/bpf_verif_scale.c
@@ -154,9 +154,9 @@ void test_verif_scale_loop2()
scale_test("loop2.bpf.o", BPF_PROG_TYPE_RAW_TRACEPOINT, false);
}
-void test_verif_scale_loop3_fail()
+void test_verif_scale_loop3()
{
- scale_test("loop3.bpf.o", BPF_PROG_TYPE_RAW_TRACEPOINT, true /* fails */);
+ scale_test("loop3.bpf.o", BPF_PROG_TYPE_RAW_TRACEPOINT, false);
}
void test_verif_scale_loop4()
diff --git a/tools/testing/selftests/bpf/prog_tests/verifier.c b/tools/testing/selftests/bpf/prog_tests/verifier.c
index 4f1e1c1cd5ab3..5bed8f9587772 100644
--- a/tools/testing/selftests/bpf/prog_tests/verifier.c
+++ b/tools/testing/selftests/bpf/prog_tests/verifier.c
@@ -65,6 +65,7 @@
#include "verifier_live_stack.skel.h"
#include "verifier_liveness_exp.skel.h"
#include "verifier_load_acquire.skel.h"
+#include "verifier_loop_widen.skel.h"
#include "verifier_loops1.skel.h"
#include "verifier_lwt.skel.h"
#include "verifier_map_in_map.skel.h"
@@ -234,6 +235,7 @@ void test_verifier_leak_ptr(void) { RUN(verifier_leak_ptr); }
void test_verifier_linked_scalars(void) { RUN(verifier_linked_scalars); }
void test_verifier_live_stack(void) { RUN(verifier_live_stack); }
void test_verifier_liveness_exp(void) { RUN(verifier_liveness_exp); }
+void test_verifier_loop_widen(void) { RUN(verifier_loop_widen); }
void test_verifier_loops1(void) { RUN(verifier_loops1); }
void test_verifier_lwt(void) { RUN(verifier_lwt); }
void test_verifier_map_in_map(void) { RUN(verifier_map_in_map); }
diff --git a/tools/testing/selftests/bpf/progs/verifier_cfg.c b/tools/testing/selftests/bpf/progs/verifier_cfg.c
index 3c3bb03e8217a..700eadf5d430a 100644
--- a/tools/testing/selftests/bpf/progs/verifier_cfg.c
+++ b/tools/testing/selftests/bpf/progs/verifier_cfg.c
@@ -98,8 +98,8 @@ l0_%=: r1 = r0; \
SEC("socket")
__description("conditional loop")
-__failure __msg("infinite loop detected")
-__msg_unpriv("back-edge")
+__success
+__failure_unpriv __msg_unpriv("back-edge")
__naked void conditional_loop(void)
{
asm volatile (" \
diff --git a/tools/testing/selftests/bpf/progs/verifier_loop_widen.c b/tools/testing/selftests/bpf/progs/verifier_loop_widen.c
new file mode 100644
index 0000000000000..4bdfc198bfaa8
--- /dev/null
+++ b/tools/testing/selftests/bpf/progs/verifier_loop_widen.c
@@ -0,0 +1,344 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Loops that are verified by widening the state at the loop head. */
+
+#include <linux/bpf.h>
+#include <bpf/bpf_helpers.h>
+#include "bpf_misc.h"
+
+struct small_val {
+ char buf[400];
+};
+
+struct big_val {
+ char buf[1000000];
+};
+
+struct {
+ __uint(type, BPF_MAP_TYPE_ARRAY);
+ __uint(max_entries, 1);
+ __type(key, int);
+ __type(value, struct small_val);
+} map_small SEC(".maps");
+
+struct {
+ __uint(type, BPF_MAP_TYPE_ARRAY);
+ __uint(max_entries, 1);
+ __type(key, int);
+ __type(value, struct big_val);
+} map_big SEC(".maps");
+
+struct {
+ __uint(type, BPF_MAP_TYPE_RINGBUF);
+ __uint(max_entries, 4096);
+} ringbuf SEC(".maps");
+
+#define LOOKUP(map) \
+ "r1 = 0;" \
+ "*(u64*)(r10 - 8) = r1;" \
+ "r2 = r10;" \
+ "r2 += -8;" \
+ "r1 = %[" #map "] ll;" \
+ "call %[bpf_map_lookup_elem];" \
+ "if r0 == 0 goto l_exit_%=;" \
+ "r7 = r0;"
+
+/* counter steps by 4 and the loop is left on '!=', 100 trips */
+SEC("socket")
+__success
+__naked void stride4_ne_100(void)
+{
+ asm volatile (
+ LOOKUP(map_small)
+ "r6 = 0;"
+"l_loop_%=:"
+ "r1 = r7;"
+ "r1 += r6;"
+ "r0 = *(u32*)(r1 + 0);"
+ "r6 += 4;"
+ "if r6 != 400 goto l_loop_%=;"
+"l_exit_%=:"
+ "r0 = 0;"
+ "exit;"
+ :
+ : __imm(bpf_map_lookup_elem), __imm_addr(map_small)
+ : __clobber_all);
+}
+
+/* same loop, 250000 trips, too many to walk every one of them */
+SEC("socket")
+__success
+__naked void stride4_ne_250k(void)
+{
+ asm volatile (
+ LOOKUP(map_big)
+ "r6 = 0;"
+"l_loop_%=:"
+ "r1 = r7;"
+ "r1 += r6;"
+ "r0 = *(u32*)(r1 + 0);"
+ "r6 += 4;"
+ "if r6 != 1000000 goto l_loop_%=;"
+"l_exit_%=:"
+ "r0 = 0;"
+ "exit;"
+ :
+ : __imm(bpf_map_lookup_elem), __imm_addr(map_big)
+ : __clobber_all);
+}
+
+/* 8 byte stride, 32-bit counter */
+SEC("socket")
+__success
+__naked void stride8_ne_w_125k(void)
+{
+ asm volatile (
+ LOOKUP(map_big)
+ "w6 = 0;"
+"l_loop_%=:"
+ "r1 = r7;"
+ "r1 += r6;"
+ "r0 = *(u64*)(r1 + 0);"
+ "w6 += 8;"
+ "if w6 != 1000000 goto l_loop_%=;"
+"l_exit_%=:"
+ "r0 = 0;"
+ "exit;"
+ :
+ : __imm(bpf_map_lookup_elem), __imm_addr(map_big)
+ : __clobber_all);
+}
+
+/* counts down by 4 to zero */
+SEC("socket")
+__success
+__naked void stride4_down_250k(void)
+{
+ asm volatile (
+ LOOKUP(map_big)
+ "r6 = 1000000;"
+"l_loop_%=:"
+ "r6 += -4;"
+ "r1 = r7;"
+ "r1 += r6;"
+ "r0 = *(u32*)(r1 + 0);"
+ "if r6 != 0 goto l_loop_%=;"
+"l_exit_%=:"
+ "r0 = 0;"
+ "exit;"
+ :
+ : __imm(bpf_map_lookup_elem), __imm_addr(map_big)
+ : __clobber_all);
+}
+
+/* step of 1 and '<', no alignment to make use of */
+SEC("socket")
+__success
+__naked void stride1_lt_1m(void)
+{
+ asm volatile (
+ LOOKUP(map_big)
+ "r6 = 0;"
+"l_loop_%=:"
+ "r1 = r7;"
+ "r1 += r6;"
+ "r0 = *(u8*)(r1 + 0);"
+ "r6 += 1;"
+ "if r6 < 1000000 goto l_loop_%=;"
+"l_exit_%=:"
+ "r0 = 0;"
+ "exit;"
+ :
+ : __imm(bpf_map_lookup_elem), __imm_addr(map_big)
+ : __clobber_all);
+}
+
+/* two loops, one in the other */
+SEC("socket")
+__success
+__naked void nested_stride4(void)
+{
+ asm volatile (
+ LOOKUP(map_big)
+ "r8 = 0;"
+"l_outer_%=:"
+ "r6 = 0;"
+"l_loop_%=:"
+ "r1 = r7;"
+ "r1 += r6;"
+ "r0 = *(u32*)(r1 + 0);"
+ "r6 += 4;"
+ "if r6 != 1000000 goto l_loop_%=;"
+ "r8 += 1;"
+ "if r8 != 1000 goto l_outer_%=;"
+"l_exit_%=:"
+ "r0 = 0;"
+ "exit;"
+ :
+ : __imm(bpf_map_lookup_elem), __imm_addr(map_big)
+ : __clobber_all);
+}
+
+/* the last trip reads 4 bytes at offset 400 of 400 */
+SEC("socket")
+__failure __msg("invalid access to map value")
+__naked void stride4_ne_one_too_many(void)
+{
+ asm volatile (
+ LOOKUP(map_small)
+ "r6 = 0;"
+"l_loop_%=:"
+ "r1 = r7;"
+ "r1 += r6;"
+ "r0 = *(u32*)(r1 + 0);"
+ "r6 += 4;"
+ "if r6 != 404 goto l_loop_%=;"
+"l_exit_%=:"
+ "r0 = 0;"
+ "exit;"
+ :
+ : __imm(bpf_map_lookup_elem), __imm_addr(map_small)
+ : __clobber_all);
+}
+
+/* same with too many trips to walk */
+SEC("socket")
+__failure __msg("BPF program is too large")
+__naked void stride4_ne_250k_one_too_many(void)
+{
+ asm volatile (
+ LOOKUP(map_big)
+ "r6 = 0;"
+"l_loop_%=:"
+ "r1 = r7;"
+ "r1 += r6;"
+ "r0 = *(u32*)(r1 + 0);"
+ "r6 += 4;"
+ "if r6 != 1000004 goto l_loop_%=;"
+"l_exit_%=:"
+ "r0 = 0;"
+ "exit;"
+ :
+ : __imm(bpf_map_lookup_elem), __imm_addr(map_big)
+ : __clobber_all);
+}
+
+/* the counter never equals the bound and reads out of bounds */
+SEC("socket")
+__failure __msg("BPF program is too large")
+__naked void stride4_ne_misses_bound(void)
+{
+ asm volatile (
+ LOOKUP(map_big)
+ "r6 = 0;"
+"l_loop_%=:"
+ "r1 = r7;"
+ "r1 += r6;"
+ "r0 = *(u32*)(r1 + 0);"
+ "r6 += 4;"
+ "if r6 != 999998 goto l_loop_%=;"
+"l_exit_%=:"
+ "r0 = 0;"
+ "exit;"
+ :
+ : __imm(bpf_map_lookup_elem), __imm_addr(map_big)
+ : __clobber_all);
+}
+
+/* the value read after the loop is at the exit value of the counter */
+SEC("socket")
+__failure __msg("BPF program is too large")
+__naked void stride4_ne_use_after_loop(void)
+{
+ asm volatile (
+ LOOKUP(map_big)
+ "r6 = 0;"
+"l_loop_%=:"
+ "r1 = r7;"
+ "r1 += r6;"
+ "r0 = *(u32*)(r1 + 0);"
+ "r6 += 4;"
+ "if r6 != 1000000 goto l_loop_%=;"
+ "r1 = r7;"
+ "r1 += r6;"
+ "r0 = *(u32*)(r1 + 0);"
+"l_exit_%=:"
+ "r0 = 0;"
+ "exit;"
+ :
+ : __imm(bpf_map_lookup_elem), __imm_addr(map_big)
+ : __clobber_all);
+}
+
+/*
+ * Nothing in the loop changes what it tests. may_goto that the verifier
+ * adds to the back-edge ends the program: 0 is returned instead of 2.
+ */
+SEC("socket")
+__success __retval(0)
+__naked void spin_until_flag(void)
+{
+ asm volatile (
+ LOOKUP(map_small)
+"l_loop_%=:"
+ "r0 = *(u32*)(r7 + 0);"
+ "if r0 == 0 goto l_loop_%=;"
+ "r0 = 2;"
+ "exit;"
+"l_exit_%=:"
+ "r0 = 1;"
+ "exit;"
+ :
+ : __imm(bpf_map_lookup_elem), __imm_addr(map_small)
+ : __clobber_all);
+}
+
+/* same with the back-edge that is not a conditional jump */
+SEC("socket")
+__success __retval(0)
+__naked void spin_until_flag_ja(void)
+{
+ asm volatile (
+ LOOKUP(map_small)
+"l_loop_%=:"
+ "r0 = *(u32*)(r7 + 0);"
+ "if r0 != 0 goto l_done_%=;"
+ "goto l_loop_%=;"
+"l_done_%=:"
+ "r0 = 2;"
+ "exit;"
+"l_exit_%=:"
+ "r0 = 1;"
+ "exit;"
+ :
+ : __imm(bpf_map_lookup_elem), __imm_addr(map_small)
+ : __clobber_all);
+}
+
+/* may_goto cannot end the program that holds a reference, every iteration is walked */
+SEC("socket")
+__success __retval(0)
+__naked void loop_with_reference(void)
+{
+ asm volatile (
+ "r1 = %[ringbuf] ll;"
+ "r2 = 8;"
+ "r3 = 0;"
+ "call %[bpf_ringbuf_reserve];"
+ "if r0 == 0 goto l_exit_%=;"
+ "r7 = r0;"
+ "r6 = 0;"
+"l_loop_%=:"
+ "r6 += 1;"
+ "if r6 != 100 goto l_loop_%=;"
+ "r1 = r7;"
+ "r2 = 0;"
+ "call %[bpf_ringbuf_discard];"
+"l_exit_%=:"
+ "r0 = 0;"
+ "exit;"
+ :
+ : __imm(bpf_ringbuf_reserve), __imm(bpf_ringbuf_discard), __imm_addr(ringbuf)
+ : __clobber_all);
+}
+
+char _license[] SEC("license") = "GPL";
diff --git a/tools/testing/selftests/bpf/progs/verifier_movsx.c b/tools/testing/selftests/bpf/progs/verifier_movsx.c
index 195b27a51224f..280ccee336635 100644
--- a/tools/testing/selftests/bpf/progs/verifier_movsx.c
+++ b/tools/testing/selftests/bpf/progs/verifier_movsx.c
@@ -226,7 +226,7 @@ l0_%=: \
SEC("socket")
__description("MOV32SX, S8, var_off u32_max")
-__failure __msg("infinite loop detected")
+__success
__failure_unpriv __msg_unpriv("back-edge from insn 2 to 0")
__naked void mov64sx_s32_varoff_1(void)
{
diff --git a/tools/testing/selftests/bpf/progs/verifier_precision.c b/tools/testing/selftests/bpf/progs/verifier_precision.c
index f4459561bf393..88358586e7964 100644
--- a/tools/testing/selftests/bpf/progs/verifier_precision.c
+++ b/tools/testing/selftests/bpf/progs/verifier_precision.c
@@ -152,22 +152,21 @@ __naked int bpf_store_release(void)
SEC("?raw_tp")
__success __log_level(2)
/*
- * Without the bug fix there will be no history between "last_idx 3 first_idx 3"
- * and "parent state regs=" lines. "R0=6" parts are here to help anchor
- * expected log messages to the one specific mark_chain_precision operation.
- *
- * This is quite fragile: if verifier checkpointing heuristic changes, this
- * might need adjusting.
+ * The state is widened when it comes back to the loop head, so the exit test
+ * is decided only on the first trip around the loop. "R0=2" parts are here to
+ * help anchor expected log messages to that mark_chain_precision operation.
*/
-__msg("2: (07) r0 += 1 ; R0=6")
+__msg("2: (07) r0 += 1 ; R0=2")
__msg("3: (35) if r0 >= 0xa goto pc+1")
-__msg("mark_precise: frame0: last_idx 3 first_idx 3 subseq_idx -1")
+__msg("mark_precise: frame0: last_idx 3 first_idx 1 subseq_idx -1")
__msg("mark_precise: frame0: regs=r0 stack= before 2: (07) r0 += 1")
__msg("mark_precise: frame0: regs=r0 stack= before 1: (07) r0 += 1")
-__msg("mark_precise: frame0: regs=r0 stack= before 4: (05) goto pc-4")
-__msg("mark_precise: frame0: regs=r0 stack= before 3: (35) if r0 >= 0xa goto pc+1")
-__msg("mark_precise: frame0: parent state regs= stack=: R0=P4")
-__msg("3: R0=6")
+__msg("mark_precise: frame0: parent state regs=r0 stack=: R0=P0")
+__msg("mark_precise: frame0: last_idx 0 first_idx 0 subseq_idx 1")
+__msg("mark_precise: frame0: regs=r0 stack= before 0: (b7) r0 = 0")
+__msg("3: R0=2")
+__msg("loop head 1 widened, pass 1")
+__msg("1: safe")
__naked int state_loop_first_last_equal(void)
{
asm volatile (
@@ -175,11 +174,7 @@ __naked int state_loop_first_last_equal(void)
"l0_%=:"
"r0 += 1;"
"r0 += 1;"
- /* every few iterations we'll have a checkpoint here with
- * first_idx == last_idx, potentially confusing precision
- * backtracking logic
- */
- "if r0 >= 10 goto l1_%=;" /* checkpoint + mark_precise */
+ "if r0 >= 10 goto l1_%=;" /* mark_precise */
"goto l0_%=;"
"l1_%=:"
"exit;"
diff --git a/tools/testing/selftests/bpf/progs/verifier_search_pruning.c b/tools/testing/selftests/bpf/progs/verifier_search_pruning.c
index f40e57251e941..7098b44faafc5 100644
--- a/tools/testing/selftests/bpf/progs/verifier_search_pruning.c
+++ b/tools/testing/selftests/bpf/progs/verifier_search_pruning.c
@@ -341,8 +341,7 @@ l0_%=: r1 = 42; \
* test would take a very long time to verify.
*/
SEC("kprobe")
-__failure __log_level(4)
-__msg("BPF program is too large.")
+__success
__naked void short_loop1(void)
{
asm volatile (
diff --git a/tools/testing/selftests/bpf/verifier/calls.c b/tools/testing/selftests/bpf/verifier/calls.c
index 8b94b87135bcf..c7c501bfc660a 100644
--- a/tools/testing/selftests/bpf/verifier/calls.c
+++ b/tools/testing/selftests/bpf/verifier/calls.c
@@ -559,8 +559,9 @@
BPF_EXIT_INSN(),
},
.prog_type = BPF_PROG_TYPE_SCHED_CLS,
- .errstr = "infinite loop detected",
- .result = REJECT,
+ /* may_goto ends the loop after 250ms, do not run it */
+ .result = ACCEPT,
+ .runs = -1,
},
{
"calls: using r0 returned by callee",
|
| 19/3 | 2026/09/26 03:31 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 26128 output: 31 thoughts: 1304 Thoughts: **KMSAN Fuzzing Session Justification: BPF Verifier Patch** Okay, let's break this down. The question is: do these BPF verifier changes warrant a KMSAN fuzzing session? I need to be sure; these sessions are resource-intensive. First, the rules: KMSAN is for *uninitialized* memory reads and kernel-to-user leaks, things that KASAN, LOCKDEP, UBSAN, and the usual suspects *won't* catch. If standard checks would flag a problem, then running KMSAN is pointless. Alright, the patch: It's all about BPF verifier changes, loop widening, loop guards, specifically dealing with `bpf_commit_loop_guards`, `add_loop_guard`, and related structures and functions like `walk_snapshot_save` and `walk_snapshot_restore`. That sounds like it could be intricate. Now, let's dig into the details: Is there a potential for uninitialized memory usage here? I need to focus on the data structures being used. I'll start with `walk_snapshot_save` and `walk_snapshot_restore`. In `walk_snapshot_save`, I see that the `walk_snapshot` struct `s` is explicitly `memset` to zero. Its members are either copied using `kvmemdup` or explicitly assigned. That's a good sign. It *looks* like initialization is handled properly here. The restore operation handles restoring the fields into the `env`. The associated free function is also present, which releases the allocated buffers. Next, I need to check the `bpf_insn_aux_data` structure. It's got added bitfields: `loop_head`, `backedge_ft`, `backedge_br`, `guard_pending`, `guard_impossible`, and `loop_guard`. These additions are interesting and I should check to see where `insn_aux_data` is allocated. I'll use `grepper` to find all the allocation sites for it. Based on the information I've seen so far, I am *cautiously optimistic* that the changes don't inherently introduce obvious uninitialized memory risks. I need to carefully look at allocation and usage of the bitfields. I'm not seeing any red flags *yet*, but I need more data before I can say definitively whether to set `NeedsKMSAN=true`. I need to be *absolutely* sure before I recommend a KMSAN session. |
| 20/3 | 2026/09/26 03:31 | tool | grepper |
0mArgs:{
"Expression": "insn_aux_data",
"PathPrefix": "kernel/bpf/"
}Results: {
"Output": "\nFull output is too long, showing 500 out of 665 lines.\nUse more precise expression if possible.\n\nkernel/bpf/cfg.c=103=static int push_insn(int t, int w, int e, struct bpf_verifier_env *env)\n--\nkernel/bpf/cfg.c-140-\t\tif (env-\u003ebpf_capable) {\nkernel/bpf/cfg.c:141:\t\t\tenv-\u003einsn_aux_data[w].loop_head = true;\nkernel/bpf/cfg.c-142-\t\t\tif (e == FALLTHROUGH)\nkernel/bpf/cfg.c:143:\t\t\t\tenv-\u003einsn_aux_data[t].backedge_ft = true;\nkernel/bpf/cfg.c-144-\t\t\telse\nkernel/bpf/cfg.c:145:\t\t\t\tenv-\u003einsn_aux_data[t].backedge_br = true;\nkernel/bpf/cfg.c-146-\t\t\treturn DONE_EXPLORING;\n--\nkernel/bpf/cfg.c=382=static int visit_gotox_insn(int t, struct bpf_verifier_env *env)\n--\nkernel/bpf/cfg.c-389-\nkernel/bpf/cfg.c:390:\tjt = env-\u003einsn_aux_data[t].jt;\nkernel/bpf/cfg.c-391-\tif (!jt) {\n--\nkernel/bpf/cfg.c-395-\nkernel/bpf/cfg.c:396:\t\tenv-\u003einsn_aux_data[t].jt = jt;\nkernel/bpf/cfg.c-397-\t}\n--\nkernel/bpf/cfg.c=435=static int visit_abnormal_return_insn(struct bpf_verifier_env *env, int t)\n--\nkernel/bpf/cfg.c-439-\nkernel/bpf/cfg.c:440:\tif (env-\u003einsn_aux_data[t].jt)\nkernel/bpf/cfg.c-441-\t\treturn 0;\n--\nkernel/bpf/cfg.c-449-\tjt-\u003eitems[1] = subprog-\u003eexit_idx;\nkernel/bpf/cfg.c:450:\tenv-\u003einsn_aux_data[t].jt = jt;\nkernel/bpf/cfg.c-451-\treturn 0;\n--\nkernel/bpf/cfg.c=751=int bpf_compute_scc(struct bpf_verifier_env *env)\n--\nkernel/bpf/cfg.c-754-\nkernel/bpf/cfg.c:755:\tstruct bpf_insn_aux_data *aux = env-\u003einsn_aux_data;\nkernel/bpf/cfg.c-756-\tconst u32 insn_cnt = env-\u003eprog-\u003elen;\n--\nkernel/bpf/const_fold.c-10- * hold known constants and their values in\nkernel/bpf/const_fold.c:11: * env-\u003einsn_aux_data[].{const_reg_mask, const_reg_vals}.\nkernel/bpf/const_fold.c-12- */\n--\nkernel/bpf/const_fold.c=50=static void const_reg_xfer(struct bpf_verifier_env *env, struct const_arg_info *ci_out,\n--\nkernel/bpf/const_fold.c-159-\t\t\tdst-\u003estate = CONST_ARG_MAP_VALUE;\nkernel/bpf/const_fold.c:160:\t\t\tdst-\u003emap_index = env-\u003einsn_aux_data[idx].map_index;\nkernel/bpf/const_fold.c:161:\t\t\tdst-\u003eval = env-\u003einsn_aux_data[idx].map_off;\nkernel/bpf/const_fold.c-162-\t\t} else if (insn-\u003esrc_reg == BPF_PSEUDO_MAP_FD ||\n--\nkernel/bpf/const_fold.c-164-\t\t\tdst-\u003estate = CONST_ARG_MAP_PTR;\nkernel/bpf/const_fold.c:165:\t\t\tdst-\u003emap_index = env-\u003einsn_aux_data[idx].map_index;\nkernel/bpf/const_fold.c-166-\t\t} else if (insn-\u003esrc_reg == 0) {\n--\nkernel/bpf/const_fold.c=232=int bpf_compute_const_regs(struct bpf_verifier_env *env)\n--\nkernel/bpf/const_fold.c-234-\tstruct const_arg_info unknown = { .state = CONST_ARG_UNKNOWN, .val = 0 };\nkernel/bpf/const_fold.c:235:\tstruct bpf_insn_aux_data *insn_aux = env-\u003einsn_aux_data;\nkernel/bpf/const_fold.c-236-\tstruct bpf_insn *insns = env-\u003eprog-\u003einsnsi;\n--\nkernel/bpf/const_fold.c-277-\t\tu16 mask = 0, map_mask = 0, subprog_mask = 0;\nkernel/bpf/const_fold.c:278:\t\tstruct bpf_insn_aux_data *aux = \u0026insn_aux[i];\nkernel/bpf/const_fold.c-279-\t\tstruct const_arg_info *ci = ci_in[i];\n--\nkernel/bpf/const_fold.c=339=int bpf_prune_dead_branches(struct bpf_verifier_env *env)\nkernel/bpf/const_fold.c-340-{\nkernel/bpf/const_fold.c:341:\tstruct bpf_insn_aux_data *insn_aux = env-\u003einsn_aux_data;\nkernel/bpf/const_fold.c-342-\tstruct bpf_insn *insns = env-\u003eprog-\u003einsnsi;\n--\nkernel/bpf/const_fold.c-347-\tfor (i = 0; i \u003c insn_cnt; i++) {\nkernel/bpf/const_fold.c:348:\t\tstruct bpf_insn_aux_data *aux = \u0026insn_aux[i];\nkernel/bpf/const_fold.c-349-\t\tstruct bpf_insn *insn = \u0026insns[i];\n--\nkernel/bpf/core.c=1641=bool bpf_insn_is_indirect_target(const struct bpf_verifier_env *env, const struct bpf_prog *prog,\n--\nkernel/bpf/core.c-1646-\tinsn_idx += prog-\u003eaux-\u003esubprog_start;\nkernel/bpf/core.c:1647:\treturn env-\u003einsn_aux_data[insn_idx].indirect_target;\nkernel/bpf/core.c-1648-}\n--\nkernel/bpf/fixups.c=204=static int get_callee_stack_depth(struct bpf_verifier_env *env,\n--\nkernel/bpf/fixups.c-216-/* single env-\u003eprog-\u003einsni[off] instruction was replaced with the range\nkernel/bpf/fixups.c:217: * insni[off, off + cnt). Adjust corresponding insn_aux_data by copying\nkernel/bpf/fixups.c-218- * [0, off) and [off, end) to new locations, so the patched range stays zero\nkernel/bpf/fixups.c-219- */\nkernel/bpf/fixups.c:220:static void adjust_insn_aux_data(struct bpf_verifier_env *env,\nkernel/bpf/fixups.c-221-\t\t\t\t struct bpf_prog *new_prog, u32 off, u32 cnt,\n--\nkernel/bpf/fixups.c-223-{\nkernel/bpf/fixups.c:224:\tstruct bpf_insn_aux_data *data = env-\u003einsn_aux_data;\nkernel/bpf/fixups.c-225-\tstruct bpf_insn *insn = new_prog-\u003einsnsi;\n--\nkernel/bpf/fixups.c-245-\tprog_len = new_prog-\u003elen;\nkernel/bpf/fixups.c:246:\tenv-\u003einsn_aux_data_len = prog_len;\nkernel/bpf/fixups.c-247-\nkernel/bpf/fixups.c-248-\tmemmove(data + off + cnt - 1, data + off,\nkernel/bpf/fixups.c:249:\t\tsizeof(struct bpf_insn_aux_data) * (prog_len - off - cnt + 1));\nkernel/bpf/fixups.c:250:\tmemset(data + off, 0, sizeof(struct bpf_insn_aux_data) * (cnt - 1));\nkernel/bpf/fixups.c-251-\tfor (i = off; i \u003c off + cnt - 1; i++) {\n--\nkernel/bpf/fixups.c=334=struct bpf_prog *bpf_patch_insn_data(struct bpf_verifier_env *env, u32 off,\n--\nkernel/bpf/fixups.c-337-\tstruct bpf_prog *new_prog;\nkernel/bpf/fixups.c:338:\tstruct bpf_insn_aux_data *new_data = NULL;\nkernel/bpf/fixups.c-339-\tstruct bpf_insn original_insn;\n--\nkernel/bpf/fixups.c-341-\tif (len \u003e 1) {\nkernel/bpf/fixups.c:342:\t\tnew_data = vrealloc(env-\u003einsn_aux_data,\nkernel/bpf/fixups.c-343-\t\t\t\t array_size(env-\u003eprog-\u003elen + len - 1,\nkernel/bpf/fixups.c:344:\t\t\t\t\t sizeof(struct bpf_insn_aux_data)),\nkernel/bpf/fixups.c-345-\t\t\t\t GFP_KERNEL_ACCOUNT | __GFP_ZERO);\n--\nkernel/bpf/fixups.c-348-\nkernel/bpf/fixups.c:349:\t\tenv-\u003einsn_aux_data = new_data;\nkernel/bpf/fixups.c-350-\t}\n--\nkernel/bpf/fixups.c-357-\t\t\t\t\"insn %d cannot be patched due to 16-bit range\\n\",\nkernel/bpf/fixups.c:358:\t\t\t\tenv-\u003einsn_aux_data[off].orig_idx);\nkernel/bpf/fixups.c-359-\t\treturn NULL;\nkernel/bpf/fixups.c-360-\t}\nkernel/bpf/fixups.c:361:\tadjust_insn_aux_data(env, new_prog, off, len, \u0026original_insn);\nkernel/bpf/fixups.c-362-\tadjust_subprog_starts(env, off, len);\n--\nkernel/bpf/fixups.c=466=static int bpf_adj_linfo_after_remove(struct bpf_verifier_env *env, u32 off,\n--\nkernel/bpf/fixups.c-532- */\nkernel/bpf/fixups.c:533:void bpf_clear_insn_aux_data(struct bpf_verifier_env *env, int start, int len)\nkernel/bpf/fixups.c-534-{\nkernel/bpf/fixups.c:535:\tstruct bpf_insn_aux_data *aux_data = env-\u003einsn_aux_data;\nkernel/bpf/fixups.c-536-\tint end = start + len;\n--\nkernel/bpf/fixups.c=547=static int verifier_remove_insns(struct bpf_verifier_env *env, u32 off, u32 cnt)\nkernel/bpf/fixups.c-548-{\nkernel/bpf/fixups.c:549:\tstruct bpf_insn_aux_data *aux_data = env-\u003einsn_aux_data;\nkernel/bpf/fixups.c-550-\tunsigned int orig_prog_len = env-\u003eprog-\u003elen;\n--\nkernel/bpf/fixups.c-555-\nkernel/bpf/fixups.c:556:\tbpf_clear_insn_aux_data(env, off, cnt);\nkernel/bpf/fixups.c-557-\n--\nkernel/bpf/fixups.c-573-\t\tsizeof(*aux_data) * (orig_prog_len - off - cnt));\nkernel/bpf/fixups.c:574:\tenv-\u003einsn_aux_data_len -= cnt;\nkernel/bpf/fixups.c-575-\n--\nkernel/bpf/fixups.c=596=void bpf_opt_hard_wire_dead_code_branches(struct bpf_verifier_env *env)\nkernel/bpf/fixups.c-597-{\nkernel/bpf/fixups.c:598:\tstruct bpf_insn_aux_data *aux_data = env-\u003einsn_aux_data;\nkernel/bpf/fixups.c-599-\tstruct bpf_insn ja = BPF_JMP_IMM(BPF_JA, 0, 0, 0);\n--\nkernel/bpf/fixups.c=622=int bpf_opt_remove_dead_code(struct bpf_verifier_env *env)\nkernel/bpf/fixups.c-623-{\nkernel/bpf/fixups.c:624:\tstruct bpf_insn_aux_data *aux_data = env-\u003einsn_aux_data;\nkernel/bpf/fixups.c-625-\tint insn_cnt = env-\u003eprog-\u003elen;\n--\nkernel/bpf/fixups.c=671=int bpf_opt_subreg_zext_lo32_rnd_hi32(struct bpf_verifier_env *env,\n--\nkernel/bpf/fixups.c-677-\tstruct bpf_insn *rnd_hi32_patch = \u0026env-\u003einsn_buf[2];\nkernel/bpf/fixups.c:678:\tstruct bpf_insn_aux_data *aux = env-\u003einsn_aux_data;\nkernel/bpf/fixups.c-679-\tint i, patch_len, delta = 0, len = env-\u003eprog-\u003elen;\n--\nkernel/bpf/fixups.c-760-\t\tinsns = new_prog-\u003einsnsi;\nkernel/bpf/fixups.c:761:\t\taux = env-\u003einsn_aux_data;\nkernel/bpf/fixups.c-762-\t\tdelta += patch_len - 1;\n--\nkernel/bpf/fixups.c=773=int bpf_convert_ctx_accesses(struct bpf_verifier_env *env)\n--\nkernel/bpf/fixups.c-849-\nkernel/bpf/fixups.c:850:\t\tif (env-\u003einsn_aux_data[i + delta].nospec) {\nkernel/bpf/fixups.c:851:\t\t\tWARN_ON_ONCE(env-\u003einsn_aux_data[i + delta].alu_state);\nkernel/bpf/fixups.c-852-\t\t\tstruct bpf_insn *patch = insn_buf;\n--\nkernel/bpf/fixups.c-892-\t\t\t insn-\u003ecode == (BPF_STX | BPF_ATOMIC | BPF_DW)) \u0026\u0026\nkernel/bpf/fixups.c:893:\t\t\t env-\u003einsn_aux_data[i + delta].ptr_type == PTR_TO_ARENA) {\nkernel/bpf/fixups.c-894-\t\t\tinsn-\u003ecode = BPF_STX | BPF_PROBE_ATOMIC | BPF_SIZE(insn-\u003ecode);\n--\nkernel/bpf/fixups.c-920-\t\tif (type == BPF_WRITE \u0026\u0026\nkernel/bpf/fixups.c:921:\t\t env-\u003einsn_aux_data[i + delta].nospec_result) {\nkernel/bpf/fixups.c-922-\t\t\t/* nospec_result is only used to mitigate Spectre v4 and\n--\nkernel/bpf/fixups.c-939-\nkernel/bpf/fixups.c:940:\t\tptr_type = env-\u003einsn_aux_data[i + delta].ptr_type;\nkernel/bpf/fixups.c-941-\t\tswitch ((int)ptr_type) {\n--\nkernel/bpf/fixups.c-995-\nkernel/bpf/fixups.c:996:\t\tctx_field_size = env-\u003einsn_aux_data[i + delta].ctx_field_size;\nkernel/bpf/fixups.c-997-\t\tsize = BPF_LDST_BYTES(insn);\n--\nkernel/bpf/fixups.c=1098=static int jit_subprogs(struct bpf_verifier_env *env)\n--\nkernel/bpf/fixups.c-1125-\t\t */\nkernel/bpf/fixups.c:1126:\t\tenv-\u003einsn_aux_data[i].call_imm = insn-\u003eimm;\nkernel/bpf/fixups.c-1127-\t\t/* point imm to __bpf_call_base+1 from JITs point of view */\n--\nkernel/bpf/fixups.c-1315-\t\tif (bpf_pseudo_func(insn)) {\nkernel/bpf/fixups.c:1316:\t\t\tinsn[0].imm = env-\u003einsn_aux_data[i].call_imm;\nkernel/bpf/fixups.c-1317-\t\t\tinsn[1].imm = insn-\u003eoff;\n--\nkernel/bpf/fixups.c-1322-\t\t\tcontinue;\nkernel/bpf/fixups.c:1323:\t\tinsn-\u003eimm = env-\u003einsn_aux_data[i].call_imm;\nkernel/bpf/fixups.c-1324-\t\tsubprog = bpf_find_subprog(env, i + insn-\u003eimm + 1);\n--\nkernel/bpf/fixups.c=1366=int bpf_jit_subprogs(struct bpf_verifier_env *env)\n--\nkernel/bpf/fixups.c-1420-\t\t\t\tinsn-\u003eoff = 0;\nkernel/bpf/fixups.c:1421:\t\t\t\tinsn-\u003eimm = env-\u003einsn_aux_data[i].call_imm;\nkernel/bpf/fixups.c-1422-\t\t\t}\n--\nkernel/bpf/fixups.c=1545=int bpf_commit_loop_guards(struct bpf_verifier_env *env)\nkernel/bpf/fixups.c-1546-{\nkernel/bpf/fixups.c:1547:\tstruct bpf_insn_aux_data *aux = env-\u003einsn_aux_data;\nkernel/bpf/fixups.c-1548-\tint i;\n--\nkernel/bpf/fixups.c=1608=static int add_loop_guard(struct bpf_verifier_env *env, int idx, struct bpf_insn *buf,\n--\nkernel/bpf/fixups.c-1610-{\nkernel/bpf/fixups.c:1611:\tstruct bpf_insn_aux_data *aux = \u0026env-\u003einsn_aux_data[idx];\nkernel/bpf/fixups.c-1612-\tstruct bpf_insn orig = env-\u003eprog-\u003einsnsi[idx];\n--\nkernel/bpf/fixups.c=1677=int bpf_do_misc_fixups(struct bpf_verifier_env *env)\n--\nkernel/bpf/fixups.c-1685-\tconst struct bpf_map_ops *ops;\nkernel/bpf/fixups.c:1686:\tstruct bpf_insn_aux_data *aux;\nkernel/bpf/fixups.c-1687-\tstruct bpf_insn *insn_buf = env-\u003einsn_buf;\n--\nkernel/bpf/fixups.c-1712-\tfor (i = 0; i \u003c insn_cnt;) {\nkernel/bpf/fixups.c:1713:\t\tif (env-\u003einsn_aux_data[i + delta].loop_guard) {\nkernel/bpf/fixups.c-1714-\t\t\tcnt = add_loop_guard(env, i + delta, insn_buf, stack_depth,\n--\nkernel/bpf/fixups.c-1737-\nkernel/bpf/fixups.c:1738:\t\tif (env-\u003einsn_aux_data[i + delta].needs_zext)\nkernel/bpf/fixups.c-1739-\t\t\t/* Convert BPF_CLASS(insn-\u003ecode) == BPF_ALU64 to 32-bit ALU */\n--\nkernel/bpf/fixups.c-1920-\nkernel/bpf/fixups.c:1921:\t\t\taux = \u0026env-\u003einsn_aux_data[i + delta];\nkernel/bpf/fixups.c-1922-\t\t\tif (!aux-\u003ealu_state ||\n--\nkernel/bpf/fixups.c-2036-\nkernel/bpf/fixups.c:2037:\t\t\taux = \u0026env-\u003einsn_aux_data[i + delta];\nkernel/bpf/fixups.c-2038-\t\t\tmap = env-\u003eused_maps[aux-\u003emap_index];\n--\nkernel/bpf/fixups.c-2119-\nkernel/bpf/fixups.c:2120:\t\t\taux = \u0026env-\u003einsn_aux_data[i + delta];\nkernel/bpf/fixups.c-2121-\t\t\tif (env-\u003ebpf_capable \u0026\u0026 !prog-\u003eblinding_requested \u0026\u0026\n--\nkernel/bpf/fixups.c-2175-\nkernel/bpf/fixups.c:2176:\t\taux = \u0026env-\u003einsn_aux_data[i + delta];\nkernel/bpf/fixups.c-2177-\t\tif (aux-\u003earg_prog) {\n--\nkernel/bpf/fixups.c-2210-\t\t/* bpf_per_cpu_ptr() and bpf_this_cpu_ptr() */\nkernel/bpf/fixups.c:2211:\t\tif (env-\u003einsn_aux_data[i + delta].call_with_percpu_alloc_ptr) {\nkernel/bpf/fixups.c-2212-\t\t\t/* patch with 'r1 = *(u64 *)(r1 + 0)' since for percpu data,\n--\nkernel/bpf/fixups.c-2242-\t\t insn-\u003eimm == BPF_FUNC_map_lookup_percpu_elem)) {\nkernel/bpf/fixups.c:2243:\t\t\taux = \u0026env-\u003einsn_aux_data[i + delta];\nkernel/bpf/fixups.c-2244-\t\t\tif (bpf_map_ptr_poisoned(aux))\n--\nkernel/bpf/fixups.c=2756=static bool is_bpf_loop_call(struct bpf_insn *insn)\n--\nkernel/bpf/fixups.c-2763-/* For all sub-programs in the program (including main) check\nkernel/bpf/fixups.c:2764: * insn_aux_data to see if there are bpf_loop calls that require\nkernel/bpf/fixups.c-2765- * inlining. If such calls are found the calls are replaced with a\n--\nkernel/bpf/fixups.c=2772=int bpf_optimize_bpf_loop(struct bpf_verifier_env *env)\n--\nkernel/bpf/fixups.c-2783-\t\tstruct bpf_loop_inline_state *inline_state =\nkernel/bpf/fixups.c:2784:\t\t\t\u0026env-\u003einsn_aux_data[i + delta].loop_inline_state;\nkernel/bpf/fixups.c-2785-\n--\nkernel/bpf/fixups.c=2820=int bpf_remove_fastcall_spills_fills(struct bpf_verifier_env *env)\n--\nkernel/bpf/fixups.c-2822-\tstruct bpf_subprog_info *subprog = env-\u003esubprog_info;\nkernel/bpf/fixups.c:2823:\tstruct bpf_insn_aux_data *aux = env-\u003einsn_aux_data;\nkernel/bpf/fixups.c-2824-\tstruct bpf_insn *insn = env-\u003eprog-\u003einsnsi;\n--\nkernel/bpf/liveness.c=218=bpf_insn_successors(struct bpf_verifier_env *env, u32 idx)\n--\nkernel/bpf/liveness.c-250-\nkernel/bpf/liveness.c:251:\tjt = env-\u003einsn_aux_data[idx].jt;\nkernel/bpf/liveness.c-252-\tif (unlikely(jt))\n--\nkernel/bpf/liveness.c=1464=static int find_callback_subprog(struct bpf_verifier_env *env,\n--\nkernel/bpf/liveness.c-1467-{\nkernel/bpf/liveness.c:1468:\tstruct bpf_insn_aux_data *aux = \u0026env-\u003einsn_aux_data[insn_idx];\nkernel/bpf/liveness.c-1469-\tint cb_reg = -1;\n--\nkernel/bpf/liveness.c=2061=static void compute_insn_live_regs(struct bpf_verifier_env *env,\n--\nkernel/bpf/liveness.c-2223- *\nkernel/bpf/liveness.c:2224: * Store result in env-\u003einsn_aux_data[i].live_regs.\nkernel/bpf/liveness.c-2225- */\nkernel/bpf/liveness.c=2226=int bpf_compute_live_registers(struct bpf_verifier_env *env)\nkernel/bpf/liveness.c-2227-{\nkernel/bpf/liveness.c:2228:\tstruct bpf_insn_aux_data *insn_aux = env-\u003einsn_aux_data;\nkernel/bpf/liveness.c-2229-\tstruct bpf_insn *insns = env-\u003eprog-\u003einsnsi;\n--\nkernel/bpf/liveness.c-2314-\t\tfor (i = 0; i \u003c insn_cnt; ++i) {\nkernel/bpf/liveness.c:2315:\t\t\tif (env-\u003einsn_aux_data[i].scc)\nkernel/bpf/liveness.c:2316:\t\t\t\tverbose(env, \"%3d \", env-\u003einsn_aux_data[i].scc);\nkernel/bpf/liveness.c-2317-\t\t\telse\n--\nkernel/bpf/states.c=17=static bool is_iter_next_insn(struct bpf_verifier_env *env, int insn_idx)\nkernel/bpf/states.c-18-{\nkernel/bpf/states.c:19:\treturn env-\u003einsn_aux_data[insn_idx].is_iter_next;\nkernel/bpf/states.c-20-}\n--\nkernel/bpf/states.c=74=static bool compute_scc_callchain(struct bpf_verifier_env *env,\n--\nkernel/bpf/states.c-82-\t\tinsn_idx = bpf_frame_insn_idx(st, i);\nkernel/bpf/states.c:83:\t\tscc = env-\u003einsn_aux_data[insn_idx].scc;\nkernel/bpf/states.c-84-\t\tif (scc) {\n--\nkernel/bpf/states.c=240=void bpf_scc_mark_exit(struct bpf_verifier_env *env, struct bpf_verifier_state *st, int insn_idx)\n--\nkernel/bpf/states.c-245-\nkernel/bpf/states.c:246:\tif (st-\u003especulative || !env-\u003einsn_aux_data[insn_idx].scc)\nkernel/bpf/states.c-247-\t\treturn;\n--\nkernel/bpf/states.c-250-\t\tcallsite = bpf_frame_insn_idx(st, i);\nkernel/bpf/states.c:251:\t\tif (env-\u003einsn_aux_data[callsite].scc)\nkernel/bpf/states.c-252-\t\t\treturn;\n--\nkernel/bpf/states.c-254-\t}\nkernel/bpf/states.c:255:\tcallchain-\u003escc = env-\u003einsn_aux_data[insn_idx].scc;\nkernel/bpf/states.c-256-\tvisit = scc_visit_lookup(env, callchain);\n--\nkernel/bpf/states.c=510=static int clean_verifier_state(struct bpf_verifier_env *env,\n--\nkernel/bpf/states.c-519-\t\tu32 ip = bpf_frame_insn_idx(st, i);\nkernel/bpf/states.c:520:\t\tu16 live_regs = env-\u003einsn_aux_data[ip].live_regs_before;\nkernel/bpf/states.c-521-\n--\nkernel/bpf/states.c=981=static bool func_states_equal(struct bpf_verifier_env *env, struct bpf_func_state *old,\n--\nkernel/bpf/states.c-983-{\nkernel/bpf/states.c:984:\tu16 live_regs = env-\u003einsn_aux_data[insn_idx].live_regs_before;\nkernel/bpf/states.c-985-\tu16 i;\n--\nkernel/bpf/states.c=1151=static bool is_backedge(struct bpf_verifier_env *env, int insn_idx)\n--\nkernel/bpf/states.c-1153-\tint prev = env-\u003eprev_insn_idx;\nkernel/bpf/states.c:1154:\tstruct bpf_insn_aux_data *aux;\nkernel/bpf/states.c-1155-\tstruct bpf_insn *insn;\n--\nkernel/bpf/states.c-1158-\t\treturn false;\nkernel/bpf/states.c:1159:\taux = \u0026env-\u003einsn_aux_data[prev];\nkernel/bpf/states.c-1160-\tinsn = \u0026env-\u003eprog-\u003einsnsi[prev];\n--\nkernel/bpf/states.c=1331=int bpf_is_state_visited(struct bpf_verifier_env *env, int insn_idx)\n--\nkernel/bpf/states.c-1335-\tstruct bpf_verifier_state *cur = env-\u003ecur_state, *new, *widen_from = NULL;\nkernel/bpf/states.c:1336:\tbool loop_head = env-\u003ewiden_loops \u0026\u0026 env-\u003einsn_aux_data[insn_idx].loop_head;\nkernel/bpf/states.c-1337-\tbool force_new_state, add_new_state, loop;\n--\nkernel/bpf/verifier.c=222=static void scalar_min_max_add(struct bpf_reg_state *dst_reg, struct bpf_reg_state *src_reg);\nkernel/bpf/verifier.c-223-\nkernel/bpf/verifier.c:224:static void bpf_map_ptr_store(struct bpf_insn_aux_data *aux,\nkernel/bpf/verifier.c-225-\t\t\t struct bpf_map *map,\n--\nkernel/bpf/verifier.c-233-\nkernel/bpf/verifier.c:234:static void bpf_map_key_store(struct bpf_insn_aux_data *aux, u64 state)\nkernel/bpf/verifier.c-235-{\n--\nkernel/bpf/verifier.c=3359=static void mark_indirect_target(struct bpf_verifier_env *env, int idx)\nkernel/bpf/verifier.c-3360-{\nkernel/bpf/verifier.c:3361:\tenv-\u003einsn_aux_data[idx].indirect_target = true;\nkernel/bpf/verifier.c-3362-}\n--\nkernel/bpf/verifier.c=3364=static void mark_non_stack_access(struct bpf_verifier_env *env, int idx)\nkernel/bpf/verifier.c-3365-{\nkernel/bpf/verifier.c:3366:\tenv-\u003einsn_aux_data[idx].non_stack_access = true;\nkernel/bpf/verifier.c-3367-}\n--\nkernel/bpf/verifier.c=3616=static void check_fastcall_stack_contract(struct bpf_verifier_env *env,\n--\nkernel/bpf/verifier.c-3619-\tstruct bpf_subprog_info *subprog = \u0026env-\u003esubprog_info[state-\u003esubprogno];\nkernel/bpf/verifier.c:3620:\tstruct bpf_insn_aux_data *aux = env-\u003einsn_aux_data;\nkernel/bpf/verifier.c-3621-\tint i;\n--\nkernel/bpf/verifier.c=3655=static int check_stack_write_fixed_off(struct bpf_verifier_env *env,\n--\nkernel/bpf/verifier.c-3704-\t\tif (sanitize)\nkernel/bpf/verifier.c:3705:\t\t\tenv-\u003einsn_aux_data[insn_idx].nospec_result = true;\nkernel/bpf/verifier.c-3706-\t}\n--\nkernel/bpf/verifier.c=5034=static int __check_ctx_access(struct bpf_verifier_env *env, int insn_idx, int off, int size,\n--\nkernel/bpf/verifier.c-5053-\t\t} else {\nkernel/bpf/verifier.c:5054:\t\t\tenv-\u003einsn_aux_data[insn_idx].ctx_field_size = info-\u003ectx_field_size;\nkernel/bpf/verifier.c-5055-\t\t}\n--\nkernel/bpf/verifier.c=5116=static int check_sock_access(struct bpf_verifier_env *env, int insn_idx,\n--\nkernel/bpf/verifier.c-5146-\tif (valid) {\nkernel/bpf/verifier.c:5147:\t\tenv-\u003einsn_aux_data[insn_idx].ctx_field_size =\nkernel/bpf/verifier.c-5148-\t\t\tinfo.ctx_field_size;\n--\nkernel/bpf/verifier.c=8091=static const struct bpf_widen_thrs *scc_thresholds(struct bpf_verifier_env *env, int insn_idx)\nkernel/bpf/verifier.c-8092-{\nkernel/bpf/verifier.c:8093:\tstruct bpf_insn_aux_data *aux = env-\u003einsn_aux_data;\nkernel/bpf/verifier.c-8094-\tstruct bpf_insn *insns = env-\u003eprog-\u003einsnsi;\n--\nkernel/bpf/verifier.c=8366=bool bpf_mark_loop_guard(struct bpf_verifier_env *env, struct bpf_verifier_state *cur)\nkernel/bpf/verifier.c-8367-{\nkernel/bpf/verifier.c:8368:\tstruct bpf_insn_aux_data *aux = \u0026env-\u003einsn_aux_data[env-\u003eprev_insn_idx];\nkernel/bpf/verifier.c-8369-\tstruct bpf_insn *insn = \u0026env-\u003eprog-\u003einsnsi[env-\u003eprev_insn_idx];\n--\nkernel/bpf/verifier.c=8697=static int get_bpf_res_spin_lock_kfunc_flags(const struct bpf_call_arg_meta *meta);\nkernel/bpf/verifier.c:8698:static struct bpf_insn_aux_data *cur_aux(const struct bpf_verifier_env *env);\nkernel/bpf/verifier.c-8699-static int process_irq_flag(struct bpf_verifier_env *env,\n--\nkernel/bpf/verifier.c=11186=static int set_map_elem_callback_state(struct bpf_verifier_env *env,\n--\nkernel/bpf/verifier.c-11190-{\nkernel/bpf/verifier.c:11191:\tstruct bpf_insn_aux_data *insn_aux = \u0026env-\u003einsn_aux_data[insn_idx];\nkernel/bpf/verifier.c-11192-\tstruct bpf_map *map;\n--\nkernel/bpf/verifier.c=11654=record_func_map(struct bpf_verifier_env *env, struct bpf_call_arg_meta *meta,\n--\nkernel/bpf/verifier.c-11656-{\nkernel/bpf/verifier.c:11657:\tstruct bpf_insn_aux_data *aux = \u0026env-\u003einsn_aux_data[insn_idx];\nkernel/bpf/verifier.c-11658-\tstruct bpf_map *map = meta-\u003emap.ptr;\n--\nkernel/bpf/verifier.c=11700=record_func_key(struct bpf_verifier_env *env, struct bpf_call_arg_meta *meta,\n--\nkernel/bpf/verifier.c-11702-{\nkernel/bpf/verifier.c:11703:\tstruct bpf_insn_aux_data *aux = \u0026env-\u003einsn_aux_data[insn_idx];\nkernel/bpf/verifier.c-11704-\tstruct bpf_reg_state *reg;\n--\nkernel/bpf/verifier.c=11844=static int check_get_func_ip(struct bpf_verifier_env *env)\n--\nkernel/bpf/verifier.c-11864-\nkernel/bpf/verifier.c:11865:static struct bpf_insn_aux_data *cur_aux(const struct bpf_verifier_env *env)\nkernel/bpf/verifier.c-11866-{\nkernel/bpf/verifier.c:11867:\treturn \u0026env-\u003einsn_aux_data[env-\u003einsn_idx];\nkernel/bpf/verifier.c-11868-}\n--\nkernel/bpf/verifier.c=11983=static int check_helper_call(struct bpf_verifier_env *env, struct bpf_insn *insn,\n--\nkernel/bpf/verifier.c-12063-\tif (!in_sleepable_context(env))\nkernel/bpf/verifier.c:12064:\t\tenv-\u003einsn_aux_data[insn_idx].non_sleepable = true;\nkernel/bpf/verifier.c-12065-\n--\nkernel/bpf/verifier.c-12227-\t\t\treturns_cpu_specific_alloc_ptr = true;\nkernel/bpf/verifier.c:12228:\t\t\tenv-\u003einsn_aux_data[insn_idx].call_with_percpu_alloc_ptr = true;\nkernel/bpf/verifier.c-12229-\t\t}\n--\nkernel/bpf/verifier.c=14222=s64 bpf_helper_stack_access_bytes(struct bpf_verifier_env *env, struct bpf_insn *insn,\n--\nkernel/bpf/verifier.c-14224-{\nkernel/bpf/verifier.c:14225:\tstruct bpf_insn_aux_data *aux = \u0026env-\u003einsn_aux_data[insn_idx];\nkernel/bpf/verifier.c-14226-\tconst struct bpf_func_proto *fn;\n--\nkernel/bpf/verifier.c=14348=s64 bpf_kfunc_stack_access_bytes(struct bpf_verifier_env *env, struct bpf_insn *insn,\n--\nkernel/bpf/verifier.c-14350-{\nkernel/bpf/verifier.c:14351:\tstruct bpf_insn_aux_data *aux = \u0026env-\u003einsn_aux_data[insn_idx];\nkernel/bpf/verifier.c-14352-\tstruct bpf_call_arg_meta meta;\n--\nkernel/bpf/verifier.c=14424=static int check_special_kfunc(struct bpf_verifier_env *env, struct bpf_call_arg_meta *meta,\nkernel/bpf/verifier.c:14425:\t\t\t struct bpf_reg_state *regs, struct bpf_insn_aux_data *insn_aux,\nkernel/bpf/verifier.c-14426-\t\t\t const struct btf_type *ptr_type, struct btf *desc_btf)\n--\nkernel/bpf/verifier.c=14595=static int check_kfunc_call(struct bpf_verifier_env *env, struct bpf_insn *insn,\n--\nkernel/bpf/verifier.c-14603-\tstruct bpf_call_arg_meta meta;\nkernel/bpf/verifier.c:14604:\tstruct bpf_insn_aux_data *insn_aux;\nkernel/bpf/verifier.c-14605-\tconst char *operation;\n--\nkernel/bpf/verifier.c-14627-\tfunc_name = meta.func_name;\nkernel/bpf/verifier.c:14628:\tinsn_aux = \u0026env-\u003einsn_aux_data[insn_idx];\nkernel/bpf/verifier.c-14629-\n--\nkernel/bpf/verifier.c=15169=static bool can_skip_alu_sanitation(const struct bpf_verifier_env *env,\n--\nkernel/bpf/verifier.c-15176-\nkernel/bpf/verifier.c:15177:static int update_alu_sanitation_state(struct bpf_insn_aux_data *aux,\nkernel/bpf/verifier.c-15178-\t\t\t\t u32 alu_state, u32 alu_limit)\n--\nkernel/bpf/verifier.c=15194=static int sanitize_val_alu(struct bpf_verifier_env *env,\n--\nkernel/bpf/verifier.c-15196-{\nkernel/bpf/verifier.c:15197:\tstruct bpf_insn_aux_data *aux = cur_aux(env);\nkernel/bpf/verifier.c-15198-\n--\nkernel/bpf/verifier.c=15210=struct bpf_sanitize_info {\nkernel/bpf/verifier.c:15211:\tstruct bpf_insn_aux_data aux;\nkernel/bpf/verifier.c-15212-\tbool mask_to_left;\n--\nkernel/bpf/verifier.c=15235=static int sanitize_ptr_alu(struct bpf_verifier_env *env,\n--\nkernel/bpf/verifier.c-15242-{\nkernel/bpf/verifier.c:15243:\tstruct bpf_insn_aux_data *aux = commit_window ? cur_aux(env) : \u0026info-\u003eaux;\nkernel/bpf/verifier.c-15244-\tstruct bpf_verifier_state *vstate = env-\u003ecur_state;\n--\nkernel/bpf/verifier.c=15331=static void sanitize_mark_insn_seen(struct bpf_verifier_env *env)\n--\nkernel/bpf/verifier.c-15340-\tif (!vstate-\u003especulative)\nkernel/bpf/verifier.c:15341:\t\tenv-\u003einsn_aux_data[env-\u003einsn_idx].seen = env-\u003epass_cnt;\nkernel/bpf/verifier.c-15342-}\n--\nkernel/bpf/verifier.c=16607=static int adjust_reg_min_max_vals(struct bpf_verifier_env *env,\n--\n\n"
} |
| 21/3 | 2026/09/26 03:31 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 39475 output: 32 thoughts: 55 Thoughts: Here's my thought process, as requested: **Tracing the Allocation of `env->insn_aux_data`** Okay, so I need to figure out where `env->insn_aux_data` is being allocated. It's a key structure, so I need to track its initialization. My first instinct is to hunt down the allocation itself. I'll need to dig into the BPF verifier code within the kernel, specifically `kernel/bpf/verifier.c`. Given its nature, it's highly probable the allocation uses a kernel memory allocator. I'll search for calls to `kvcalloc`, `kvzalloc` – those would be the prime suspects for zero-initializing and allocating kernel memory. Alternatively, I can also just search for the name `insn_aux_data` within `verifier.c` and see if the allocation is directly tied to it, though less likely. Let's see what turns up. |
| 22/3 | 2026/09/26 03:31 | tool | grepper |
0mArgs:{
"Expression": "insn_aux_data =",
"PathPrefix": "kernel/bpf/"
}Results: {
"Output": "kernel/bpf/fixups.c=334=struct bpf_prog *bpf_patch_insn_data(struct bpf_verifier_env *env, u32 off,\n--\nkernel/bpf/fixups.c-348-\nkernel/bpf/fixups.c:349:\t\tenv-\u003einsn_aux_data = new_data;\nkernel/bpf/fixups.c-350-\t}\n--\nkernel/bpf/verifier.c=22263=int bpf_check(struct bpf_prog **prog, union bpf_attr *attr, bpfptr_t uattr,\n--\nkernel/bpf/verifier.c-22331-\tlen = env-\u003einsn_aux_data_len = env-\u003eprog-\u003elen;\nkernel/bpf/verifier.c:22332:\tenv-\u003einsn_aux_data =\nkernel/bpf/verifier.c-22333-\t\t__vmalloc(array_size(sizeof(struct bpf_insn_aux_data), len),\n"
} |
| 23/3 | 2026/09/26 03:31 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 40038 output: 38 thoughts: 18 Thoughts: Okay, here's my interpretation of what's going on, thinking as if these are *my* thoughts: **Peering into verifier.c: Line 22332** Alright, time to dive into `verifier.c`. I need to zero in on a specific point, and the line number I'm starting with is 22332. That likely points me to a critical part of the verification process, perhaps a crucial check or validation step. I'm expecting something intricate there, something that's potentially causing an issue or warrants further scrutiny. It's a good starting point to trace the program's logic and the state of the data. Let's see what the code is doing at that point, what assumptions it's making, and how it handles potential edge cases. |
| 24/3 | 2026/09/26 03:31 | tool | read-file |
0mArgs:{
"File": "kernel/bpf/verifier.c",
"FirstLine": 22325,
"LineCount": 20
}Results: {
"Contents": "22325:\t\tbpf_get_btf_vmlinux();\n22326:\t\n22327:\t\t/* Serialize verification of unprivileged programs. */\n22328:\t\tif (!is_priv)\n22329:\t\t\tmutex_lock(\u0026bpf_verifier_lock);\n22330:\t\n22331:\t\tlen = env-\u003einsn_aux_data_len = env-\u003eprog-\u003elen;\n22332:\t\tenv-\u003einsn_aux_data =\n22333:\t\t\t__vmalloc(array_size(sizeof(struct bpf_insn_aux_data), len),\n22334:\t\t\t\t GFP_KERNEL_ACCOUNT | __GFP_ZERO);\n22335:\t\tret = -ENOMEM;\n22336:\t\tif (!env-\u003einsn_aux_data)\n22337:\t\t\tgoto skip_full_check;\n22338:\t\tfor (i = 0; i \u003c len; i++)\n22339:\t\t\tenv-\u003einsn_aux_data[i].orig_idx = i;\n22340:\t\tenv-\u003esucc = bpf_iarray_realloc(NULL, 2);\n22341:\t\tif (!env-\u003esucc)\n22342:\t\t\tgoto skip_full_check;\n22343:\t\n22344:\t\tmark_verifier_state_clean(env);\n"
} |
| 25/3 | 2026/09/26 03:31 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 40638 output: 38 thoughts: 61 Thoughts: Here's my analysis of the provided snippet, thinking aloud as I would while reviewing code: **Analyzing Memory Allocation and Snapshot Operations** Okay, so `env->insn_aux_data` is being allocated, and crucially, it's being zeroed out with `__GFP_ZERO`. Good practice, keeps things clean and predictable. Now, where are we using this? Let's zoom in on `walk_snapshot_save` and `walk_snapshot_restore`. That's where the interesting stuff likely happens. Given the zeroing, this suggests that the aux data is probably storing something we need to initialize or clear, perhaps related to the snapshot process. Let's jump to `walk_snapshot_save` around line 20560. My initial thought is that we're capturing state here before the save operation. Let me find that and see what's happening. |
| 26/3 | 2026/09/26 03:31 | tool | read-file |
0mArgs:{
"File": "kernel/bpf/verifier.c",
"FirstLine": 20540,
"LineCount": 80
}Results: {
"Contents": "20540:\tstruct walk_snapshot {\n20541:\t\tstruct bpf_insn_aux_data *insn_aux;\n20542:\t\tstruct bpf_func_info_aux *func_aux;\n20543:\t\tstruct bpf_subprog_info *subprogs;\n20544:\t\tstruct bpf_prog *prog;\n20545:\t\tu64 log_pos, diag_pos;\n20546:\t\tu32 insn_processed, prev_insn_processed;\n20547:\t\tu32 jmps_processed, prev_jmps_processed;\n20548:\t\tu32 total_states, peak_states, max_states_per_insn, longest_mark_read_walk;\n20549:\t\tu32 explored_states_size, free_list_size, num_backedges;\n20550:\t\tu32 id_gen, pass_cnt, max_stack_depth;\n20551:\t\tu32 max_ctx_offset, max_pkt_offset, max_tp_access, max_rdonly_access, max_rdwr_access;\n20552:\t\tbool seen_direct_write, seen_exception, explore_alu_limits, tail_call_reachable;\n20553:\t\tvoid *arena;\n20554:\t};\n20555:\t\n20556:\tstatic void walk_snapshot_free(struct walk_snapshot *s)\n20557:\t{\n20558:\t\tkvfree(s-\u003einsn_aux);\n20559:\t\tkvfree(s-\u003efunc_aux);\n20560:\t\tkvfree(s-\u003esubprogs);\n20561:\t\tkfree(s-\u003eprog);\n20562:\t}\n20563:\t\n20564:\tstatic size_t func_aux_size(struct bpf_verifier_env *env)\n20565:\t{\n20566:\t\treturn array_size(env-\u003eprog-\u003eaux-\u003efunc_info_cnt, sizeof(*env-\u003eprog-\u003eaux-\u003efunc_info_aux));\n20567:\t}\n20568:\t\n20569:\tstatic int walk_snapshot_save(struct bpf_verifier_env *env, struct walk_snapshot *s)\n20570:\t{\n20571:\t\tstruct bpf_prog_aux *aux = env-\u003eprog-\u003eaux;\n20572:\t\n20573:\t\tmemset(s, 0, sizeof(*s));\n20574:\t\ts-\u003einsn_aux = kvmemdup(env-\u003einsn_aux_data,\n20575:\t\t\t\t array_size(env-\u003eprog-\u003elen, sizeof(*env-\u003einsn_aux_data)),\n20576:\t\t\t\t GFP_KERNEL_ACCOUNT);\n20577:\t\ts-\u003esubprogs = kvmemdup(env-\u003esubprog_info, sizeof(env-\u003esubprog_info), GFP_KERNEL_ACCOUNT);\n20578:\t\t/* flags of the program, not its insns */\n20579:\t\ts-\u003eprog = kmemdup(env-\u003eprog, offsetof(struct bpf_prog, insnsi), GFP_KERNEL_ACCOUNT);\n20580:\t\tif (aux-\u003efunc_info_aux)\n20581:\t\t\ts-\u003efunc_aux = kvmemdup(aux-\u003efunc_info_aux, func_aux_size(env), GFP_KERNEL_ACCOUNT);\n20582:\t\tif (!s-\u003einsn_aux || !s-\u003esubprogs || !s-\u003eprog || (aux-\u003efunc_info_aux \u0026\u0026 !s-\u003efunc_aux)) {\n20583:\t\t\twalk_snapshot_free(s);\n20584:\t\t\treturn -ENOMEM;\n20585:\t\t}\n20586:\t\ts-\u003elog_pos = env-\u003elog.end_pos;\n20587:\t\ts-\u003ediag_pos = bpf_diag_event_log_save(env);\n20588:\t\ts-\u003einsn_processed = env-\u003einsn_processed;\n20589:\t\ts-\u003eprev_insn_processed = env-\u003eprev_insn_processed;\n20590:\t\ts-\u003ejmps_processed = env-\u003ejmps_processed;\n20591:\t\ts-\u003eprev_jmps_processed = env-\u003eprev_jmps_processed;\n20592:\t\ts-\u003etotal_states = env-\u003etotal_states;\n20593:\t\ts-\u003epeak_states = env-\u003epeak_states;\n20594:\t\ts-\u003emax_states_per_insn = env-\u003emax_states_per_insn;\n20595:\t\ts-\u003elongest_mark_read_walk = env-\u003elongest_mark_read_walk;\n20596:\t\ts-\u003eexplored_states_size = env-\u003eexplored_states_size;\n20597:\t\ts-\u003efree_list_size = env-\u003efree_list_size;\n20598:\t\ts-\u003enum_backedges = env-\u003enum_backedges;\n20599:\t\ts-\u003eid_gen = env-\u003eid_gen;\n20600:\t\ts-\u003epass_cnt = env-\u003epass_cnt;\n20601:\t\ts-\u003emax_stack_depth = env-\u003emax_stack_depth;\n20602:\t\ts-\u003eseen_direct_write = env-\u003eseen_direct_write;\n20603:\t\ts-\u003eseen_exception = env-\u003eseen_exception;\n20604:\t\ts-\u003eexplore_alu_limits = env-\u003eexplore_alu_limits;\n20605:\t\ts-\u003emax_ctx_offset = aux-\u003emax_ctx_offset;\n20606:\t\ts-\u003emax_pkt_offset = aux-\u003emax_pkt_offset;\n20607:\t\ts-\u003emax_tp_access = aux-\u003emax_tp_access;\n20608:\t\ts-\u003emax_rdonly_access = aux-\u003emax_rdonly_access;\n20609:\t\ts-\u003emax_rdwr_access = aux-\u003emax_rdwr_access;\n20610:\t\ts-\u003etail_call_reachable = aux-\u003etail_call_reachable;\n20611:\t\ts-\u003earena = aux-\u003earena;\n20612:\t\treturn 0;\n20613:\t}\n20614:\t\n20615:\tstatic void walk_snapshot_restore(struct bpf_verifier_env *env, struct walk_snapshot *s)\n20616:\t{\n20617:\t\tstruct bpf_prog_aux *aux = env-\u003eprog-\u003eaux;\n20618:\t\n20619:\t\tmemcpy(env-\u003einsn_aux_data, s-\u003einsn_aux,\n"
} |
| 27/3 | 2026/09/26 03:31 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 42647 output: 29 thoughts: 1755 Thoughts: **Analyzing BPF Verifier Code: A Deep Dive** Okay, let's break this down systematically. First, I'm checking `walk_snapshot_restore`. The `kmemdup` and `memcpy` operations on `env->prog` are the focus. I need to confirm if anything beyond `offsetof(struct bpf_prog, insnsi)` gets clobbered or if the header of `struct bpf_prog` is properly initialized. The code copies from an existing kernel structure; `kmemdup` copies only `offsetof(struct bpf_prog, insnsi)` bytes, and then `memcpy` copies that part back. Makes sense. Next, I'm diving into `scc_thresholds`. I see `kvzalloc` being used for `env->scc_thrs`. It's zero-initialized which is good, but I also need to understand its relationship with `env->scc_cnt` and how many of those are allocated, and if it could leak. Then there's the `struct_size` call, constructing a dynamic array. The loop seems to be collecting threshold values from comparison instructions. The `sort` operation suggests a need for an ordered data structure. The code seems to use zero initialization to set a converged state for each scc, again with `kvzalloc`. This is something to keep an eye on to see what are the potential pitfalls. Now, let's move onto `bpf_scc_mark_exit`. I'm verifying the `memset` call on `callchain`. A zeroed `callchain` structure seems essential, especially given that it is a potential memory region to write to. Moving on to `thr_nearest`, I'm looking at the `found` flag. The logic around it is solid. When `!up`, `found` can be true; this means that `*res` can be set. I'm verifying if all paths set the value of `*res`. The loop iterates through and sets the `*res` if it encounters a value that fits. In `widen_pick`, I can see that `*res` is always set when `found` becomes true, which depends on the `thr_nearest` function. The same applies to `widen_smax`, `widen_smin`, `widen_umax`, `widen_umin` as well. The short-circuit evaluation of `&&` ensures that the comparison `t <= lim` is only done when `t` is set by `widen_pick`. Everything looks good here. Finally, I'm looking at `add_loop_guard`. Specifically, I am trying to understand the source of `insn_buf`. It seems it comes from `env->insn_buf`. I'll need to figure out its size. I should probably `grep` for `insn_buf` in `kernel/bpf/verifier.c` to see how it's allocated and sized. This will give me a complete view. |
| 28/3 | 2026/09/26 03:31 | tool | grepper |
0mArgs:{
"Expression": "insn_buf",
"PathPrefix": "kernel/bpf/"
}Results: {
"Output": "\nFull output is too long, showing 500 out of 676 lines.\nUse more precise expression if possible.\n\nkernel/bpf/arraymap.c=201=static int array_map_direct_value_meta(const struct bpf_map *map, u64 imm,\n--\nkernel/bpf/arraymap.c-217-/* emit BPF instructions equivalent to C code of array_map_lookup_elem() */\nkernel/bpf/arraymap.c:218:static int array_map_gen_lookup(struct bpf_map *map, struct bpf_insn *insn_buf)\nkernel/bpf/arraymap.c-219-{\nkernel/bpf/arraymap.c-220-\tstruct bpf_array *array = container_of(map, struct bpf_array, map);\nkernel/bpf/arraymap.c:221:\tstruct bpf_insn *insn = insn_buf;\nkernel/bpf/arraymap.c-222-\tu32 elem_size = array-\u003eelem_size;\n--\nkernel/bpf/arraymap.c-246-\t*insn++ = BPF_MOV64_IMM(ret, 0);\nkernel/bpf/arraymap.c:247:\treturn insn - insn_buf;\nkernel/bpf/arraymap.c-248-}\n--\nkernel/bpf/arraymap.c=277=static int percpu_array_map_direct_value_meta(const struct bpf_map *map, u64 imm, u32 *off)\n--\nkernel/bpf/arraymap.c-293-/* emit BPF instructions equivalent to C code of percpu_array_map_lookup_elem() */\nkernel/bpf/arraymap.c:294:static int percpu_array_map_gen_lookup(struct bpf_map *map, struct bpf_insn *insn_buf)\nkernel/bpf/arraymap.c-295-{\nkernel/bpf/arraymap.c-296-\tstruct bpf_array *array = container_of(map, struct bpf_array, map);\nkernel/bpf/arraymap.c:297:\tstruct bpf_insn *insn = insn_buf;\nkernel/bpf/arraymap.c-298-\n--\nkernel/bpf/arraymap.c-321-\t*insn++ = BPF_MOV64_IMM(BPF_REG_0, 0);\nkernel/bpf/arraymap.c:322:\treturn insn - insn_buf;\nkernel/bpf/arraymap.c-323-}\n--\nkernel/bpf/arraymap.c=1474=static int array_of_map_gen_lookup(struct bpf_map *map,\nkernel/bpf/arraymap.c:1475:\t\t\t\t struct bpf_insn *insn_buf)\nkernel/bpf/arraymap.c-1476-{\n--\nkernel/bpf/arraymap.c-1478-\tu32 elem_size = array-\u003eelem_size;\nkernel/bpf/arraymap.c:1479:\tstruct bpf_insn *insn = insn_buf;\nkernel/bpf/arraymap.c-1480-\tconst int ret = BPF_REG_0;\n--\nkernel/bpf/arraymap.c-1501-\nkernel/bpf/arraymap.c:1502:\treturn insn - insn_buf;\nkernel/bpf/arraymap.c-1503-}\n--\nkernel/bpf/cgroup.c=2640=static u32 sysctl_convert_ctx_access(enum bpf_access_type type,\nkernel/bpf/cgroup.c-2641-\t\t\t\t const struct bpf_insn *si,\nkernel/bpf/cgroup.c:2642:\t\t\t\t struct bpf_insn *insn_buf,\nkernel/bpf/cgroup.c-2643-\t\t\t\t struct bpf_prog *prog, u32 *target_size)\nkernel/bpf/cgroup.c-2644-{\nkernel/bpf/cgroup.c:2645:\tstruct bpf_insn *insn = insn_buf;\nkernel/bpf/cgroup.c-2646-\tu32 read_size;\n--\nkernel/bpf/cgroup.c-2700-\nkernel/bpf/cgroup.c:2701:\treturn insn - insn_buf;\nkernel/bpf/cgroup.c-2702-}\n--\nkernel/bpf/cgroup.c=2840=static u32 cg_sockopt_convert_ctx_access(enum bpf_access_type type,\nkernel/bpf/cgroup.c-2841-\t\t\t\t\t const struct bpf_insn *si,\nkernel/bpf/cgroup.c:2842:\t\t\t\t\t struct bpf_insn *insn_buf,\nkernel/bpf/cgroup.c-2843-\t\t\t\t\t struct bpf_prog *prog,\n--\nkernel/bpf/cgroup.c-2845-{\nkernel/bpf/cgroup.c:2846:\tstruct bpf_insn *insn = insn_buf;\nkernel/bpf/cgroup.c-2847-\n--\nkernel/bpf/cgroup.c-2914-\nkernel/bpf/cgroup.c:2915:\treturn insn - insn_buf;\nkernel/bpf/cgroup.c-2916-}\nkernel/bpf/cgroup.c-2917-\nkernel/bpf/cgroup.c:2918:static int cg_sockopt_get_prologue(struct bpf_insn *insn_buf,\nkernel/bpf/cgroup.c-2919-\t\t\t\t bool direct_write,\n--\nkernel/bpf/core.c=1562=struct bpf_prog *bpf_jit_blind_constants(struct bpf_verifier_env *env, struct bpf_prog *prog)\nkernel/bpf/core.c-1563-{\nkernel/bpf/core.c:1564:\tstruct bpf_insn insn_buff[16], aux[2];\nkernel/bpf/core.c-1565-\tstruct bpf_prog *clone, *tmp;\n--\nkernel/bpf/core.c-1602-\nkernel/bpf/core.c:1603:\t\trewritten = bpf_jit_blind_insn(insn, aux, insn_buff,\nkernel/bpf/core.c-1604-\t\t\t\t\t\tclone-\u003eaux-\u003everifier_zext);\n--\nkernel/bpf/core.c-1608-\t\tif (env)\nkernel/bpf/core.c:1609:\t\t\ttmp = bpf_patch_insn_data(env, i, insn_buff, rewritten);\nkernel/bpf/core.c-1610-\t\telse\nkernel/bpf/core.c:1611:\t\t\ttmp = bpf_patch_insn_single(clone, i, insn_buff, rewritten);\nkernel/bpf/core.c-1612-\n--\nkernel/bpf/fixups.c=671=int bpf_opt_subreg_zext_lo32_rnd_hi32(struct bpf_verifier_env *env,\n--\nkernel/bpf/fixups.c-674-\tstruct bpf_insn *patch;\nkernel/bpf/fixups.c:675:\t/* use env-\u003einsn_buf as two independent buffers */\nkernel/bpf/fixups.c:676:\tstruct bpf_insn *zext_patch = env-\u003einsn_buf;\nkernel/bpf/fixups.c:677:\tstruct bpf_insn *rnd_hi32_patch = \u0026env-\u003einsn_buf[2];\nkernel/bpf/fixups.c-678-\tstruct bpf_insn_aux_data *aux = env-\u003einsn_aux_data;\n--\nkernel/bpf/fixups.c=773=int bpf_convert_ctx_accesses(struct bpf_verifier_env *env)\n--\nkernel/bpf/fixups.c-779-\tstruct bpf_insn *epilogue_buf = env-\u003eepilogue_buf;\nkernel/bpf/fixups.c:780:\tstruct bpf_insn *insn_buf = env-\u003einsn_buf;\nkernel/bpf/fixups.c-781-\tstruct bpf_insn *insn;\n--\nkernel/bpf/fixups.c-797-\t\t\tsubprogs[0].stack_depth += 8;\nkernel/bpf/fixups.c:798:\t\t\tinsn_buf[cnt++] = BPF_STX_MEM(BPF_DW, BPF_REG_FP, BPF_REG_1,\nkernel/bpf/fixups.c-799-\t\t\t\t\t\t -subprogs[0].stack_depth);\nkernel/bpf/fixups.c:800:\t\t\tinsn_buf[cnt++] = env-\u003eprog-\u003einsnsi[0];\nkernel/bpf/fixups.c:801:\t\t\tnew_prog = bpf_patch_insn_data(env, 0, insn_buf, cnt);\nkernel/bpf/fixups.c-802-\t\t\tif (!new_prog)\n--\nkernel/bpf/fixups.c-817-\t\t}\nkernel/bpf/fixups.c:818:\t\tcnt = ops-\u003egen_prologue(insn_buf, env-\u003eseen_direct_write,\nkernel/bpf/fixups.c-819-\t\t\t\t\tenv-\u003eprog);\n--\nkernel/bpf/fixups.c-823-\t\t} else if (cnt) {\nkernel/bpf/fixups.c:824:\t\t\tnew_prog = bpf_patch_insn_data(env, 0, insn_buf, cnt);\nkernel/bpf/fixups.c-825-\t\t\tif (!new_prog)\n--\nkernel/bpf/fixups.c-830-\nkernel/bpf/fixups.c:831:\t\t\tret = add_kfunc_in_insns(env, insn_buf, cnt - 1);\nkernel/bpf/fixups.c-832-\t\t\tif (ret \u003c 0)\n--\nkernel/bpf/fixups.c-851-\t\t\tWARN_ON_ONCE(env-\u003einsn_aux_data[i + delta].alu_state);\nkernel/bpf/fixups.c:852:\t\t\tstruct bpf_insn *patch = insn_buf;\nkernel/bpf/fixups.c-853-\n--\nkernel/bpf/fixups.c-855-\t\t\t*patch++ = *insn;\nkernel/bpf/fixups.c:856:\t\t\tcnt = patch - insn_buf;\nkernel/bpf/fixups.c:857:\t\t\tnew_prog = bpf_patch_insn_data(env, i + delta, insn_buf, cnt);\nkernel/bpf/fixups.c-858-\t\t\tif (!new_prog)\n--\nkernel/bpf/fixups.c-902-\t\t\t\t/* jump back to the earlier generated epilogue */\nkernel/bpf/fixups.c:903:\t\t\t\tinsn_buf[0] = BPF_JMP32_A(epilogue_idx - i - delta - 1);\nkernel/bpf/fixups.c-904-\t\t\t\tcnt = 1;\nkernel/bpf/fixups.c-905-\t\t\t} else {\nkernel/bpf/fixups.c:906:\t\t\t\tmemcpy(insn_buf, epilogue_buf,\nkernel/bpf/fixups.c-907-\t\t\t\t epilogue_cnt * sizeof(*epilogue_buf));\n--\nkernel/bpf/fixups.c-914-\t\t\t}\nkernel/bpf/fixups.c:915:\t\t\tgoto patch_insn_buf;\nkernel/bpf/fixups.c-916-\t\t} else {\n--\nkernel/bpf/fixups.c-924-\t\t\t */\nkernel/bpf/fixups.c:925:\t\t\tstruct bpf_insn *patch = insn_buf;\nkernel/bpf/fixups.c-926-\n--\nkernel/bpf/fixups.c-928-\t\t\t*patch++ = BPF_ST_NOSPEC();\nkernel/bpf/fixups.c:929:\t\t\tcnt = patch - insn_buf;\nkernel/bpf/fixups.c:930:\t\t\tnew_prog = bpf_patch_insn_data(env, i + delta, insn_buf, cnt);\nkernel/bpf/fixups.c-931-\t\t\tif (!new_prog)\n--\nkernel/bpf/fixups.c-1026-\t\ttarget_size = 0;\nkernel/bpf/fixups.c:1027:\t\tcnt = convert_ctx_access(type, insn, insn_buf, env-\u003eprog,\nkernel/bpf/fixups.c-1028-\t\t\t\t\t \u0026target_size);\n--\nkernel/bpf/fixups.c-1043-\t\t\t\tif (shift)\nkernel/bpf/fixups.c:1044:\t\t\t\t\tinsn_buf[cnt++] = BPF_ALU32_IMM(BPF_RSH,\nkernel/bpf/fixups.c-1045-\t\t\t\t\t\t\t\t\tinsn-\u003edst_reg,\nkernel/bpf/fixups.c-1046-\t\t\t\t\t\t\t\t\tshift);\nkernel/bpf/fixups.c:1047:\t\t\t\tinsn_buf[cnt++] = BPF_ALU32_IMM(BPF_AND, insn-\u003edst_reg,\nkernel/bpf/fixups.c-1048-\t\t\t\t\t\t\t\t(1 \u003c\u003c size * 8) - 1);\n--\nkernel/bpf/fixups.c-1050-\t\t\t\tif (shift)\nkernel/bpf/fixups.c:1051:\t\t\t\t\tinsn_buf[cnt++] = BPF_ALU64_IMM(BPF_RSH,\nkernel/bpf/fixups.c-1052-\t\t\t\t\t\t\t\t\tinsn-\u003edst_reg,\nkernel/bpf/fixups.c-1053-\t\t\t\t\t\t\t\t\tshift);\nkernel/bpf/fixups.c:1054:\t\t\t\tinsn_buf[cnt++] = BPF_ALU32_IMM(BPF_AND, insn-\u003edst_reg,\nkernel/bpf/fixups.c-1055-\t\t\t\t\t\t\t\t(1ULL \u003c\u003c size * 8) - 1);\n--\nkernel/bpf/fixups.c-1058-\t\tif (mode == BPF_MEMSX)\nkernel/bpf/fixups.c:1059:\t\t\tinsn_buf[cnt++] = BPF_RAW_INSN(BPF_ALU64 | BPF_MOV | BPF_X,\nkernel/bpf/fixups.c-1060-\t\t\t\t\t\t insn-\u003edst_reg, insn-\u003edst_reg,\n--\nkernel/bpf/fixups.c-1062-\nkernel/bpf/fixups.c:1063:patch_insn_buf:\nkernel/bpf/fixups.c:1064:\t\tnew_prog = bpf_patch_insn_data(env, i + delta, insn_buf, cnt);\nkernel/bpf/fixups.c-1065-\t\tif (!new_prog)\n--\nkernel/bpf/fixups.c=1677=int bpf_do_misc_fixups(struct bpf_verifier_env *env)\n--\nkernel/bpf/fixups.c-1686-\tstruct bpf_insn_aux_data *aux;\nkernel/bpf/fixups.c:1687:\tstruct bpf_insn *insn_buf = env-\u003einsn_buf;\nkernel/bpf/fixups.c-1688-\tstruct bpf_prog *new_prog;\n--\nkernel/bpf/fixups.c-1695-\tif (env-\u003eseen_exception \u0026\u0026 !env-\u003eexception_callback_subprog) {\nkernel/bpf/fixups.c:1696:\t\tstruct bpf_insn *patch = insn_buf;\nkernel/bpf/fixups.c-1697-\n--\nkernel/bpf/fixups.c-1700-\t\t*patch++ = BPF_EXIT_INSN();\nkernel/bpf/fixups.c:1701:\t\tret = add_hidden_subprog(env, insn_buf, patch - insn_buf);\nkernel/bpf/fixups.c-1702-\t\tif (ret \u003c 0)\n--\nkernel/bpf/fixups.c-1713-\t\tif (env-\u003einsn_aux_data[i + delta].loop_guard) {\nkernel/bpf/fixups.c:1714:\t\t\tcnt = add_loop_guard(env, i + delta, insn_buf, stack_depth,\nkernel/bpf/fixups.c-1715-\t\t\t\t\t \u0026stack_depth_extra);\n--\nkernel/bpf/fixups.c-1718-\nkernel/bpf/fixups.c:1719:\t\t\tnew_prog = bpf_patch_insn_data(env, i + delta, insn_buf, cnt);\nkernel/bpf/fixups.c-1720-\t\t\tif (!new_prog)\n--\nkernel/bpf/fixups.c-1749-\t\t\tbool isdiv = BPF_OP(insn-\u003ecode) == BPF_DIV;\nkernel/bpf/fixups.c:1750:\t\t\tstruct bpf_insn *patch = insn_buf;\nkernel/bpf/fixups.c-1751-\n--\nkernel/bpf/fixups.c-1758-\nkernel/bpf/fixups.c:1759:\t\t\tcnt = patch - insn_buf;\nkernel/bpf/fixups.c-1760-\nkernel/bpf/fixups.c:1761:\t\t\tnew_prog = bpf_patch_insn_data(env, i + delta, insn_buf, cnt);\nkernel/bpf/fixups.c-1762-\t\t\tif (!new_prog)\n--\nkernel/bpf/fixups.c-1779-\t\t\tbool is_smod = !isdiv \u0026\u0026 insn-\u003eoff == 1;\nkernel/bpf/fixups.c:1780:\t\t\tstruct bpf_insn *patch = insn_buf;\nkernel/bpf/fixups.c-1781-\n--\nkernel/bpf/fixups.c-1805-\t\t\t\t*patch++ = *insn;\nkernel/bpf/fixups.c:1806:\t\t\t\tcnt = patch - insn_buf;\nkernel/bpf/fixups.c-1807-\t\t\t} else if (is_smod) {\n--\nkernel/bpf/fixups.c-1827-\t\t\t\t}\nkernel/bpf/fixups.c:1828:\t\t\t\tcnt = patch - insn_buf;\nkernel/bpf/fixups.c-1829-\t\t\t} else if (isdiv) {\n--\nkernel/bpf/fixups.c-1836-\t\t\t\t*patch++ = *insn;\nkernel/bpf/fixups.c:1837:\t\t\t\tcnt = patch - insn_buf;\nkernel/bpf/fixups.c-1838-\t\t\t} else {\n--\nkernel/bpf/fixups.c-1848-\t\t\t\t}\nkernel/bpf/fixups.c:1849:\t\t\t\tcnt = patch - insn_buf;\nkernel/bpf/fixups.c-1850-\t\t\t}\nkernel/bpf/fixups.c-1851-\nkernel/bpf/fixups.c:1852:\t\t\tnew_prog = bpf_patch_insn_data(env, i + delta, insn_buf, cnt);\nkernel/bpf/fixups.c-1853-\t\t\tif (!new_prog)\n--\nkernel/bpf/fixups.c-1865-\t\t BPF_MODE(insn-\u003ecode) == BPF_PROBE_MEMSX)) {\nkernel/bpf/fixups.c:1866:\t\t\tstruct bpf_insn *patch = insn_buf;\nkernel/bpf/fixups.c-1867-\t\t\tu64 uaddress_limit = bpf_arch_uaddress_limit();\n--\nkernel/bpf/fixups.c-1880-\nkernel/bpf/fixups.c:1881:\t\t\tcnt = patch - insn_buf;\nkernel/bpf/fixups.c:1882:\t\t\tnew_prog = bpf_patch_insn_data(env, i + delta, insn_buf, cnt);\nkernel/bpf/fixups.c-1883-\t\t\tif (!new_prog)\n--\nkernel/bpf/fixups.c-1895-\t\t BPF_MODE(insn-\u003ecode) == BPF_IND)) {\nkernel/bpf/fixups.c:1896:\t\t\tcnt = env-\u003eops-\u003egen_ld_abs(insn, insn_buf);\nkernel/bpf/fixups.c-1897-\t\t\tif (cnt == 0 || cnt \u003e= INSN_BUF_SIZE) {\n--\nkernel/bpf/fixups.c-1901-\nkernel/bpf/fixups.c:1902:\t\t\tnew_prog = bpf_patch_insn_data(env, i + delta, insn_buf, cnt);\nkernel/bpf/fixups.c-1903-\t\t\tif (!new_prog)\n--\nkernel/bpf/fixups.c-1916-\t\t\tconst u8 code_sub = BPF_ALU64 | BPF_SUB | BPF_X;\nkernel/bpf/fixups.c:1917:\t\t\tstruct bpf_insn *patch = insn_buf;\nkernel/bpf/fixups.c-1918-\t\t\tbool issrc, isneg, isimm;\n--\nkernel/bpf/fixups.c-1952-\t\t\t\t*patch++ = BPF_ALU64_IMM(BPF_MUL, off_reg, -1);\nkernel/bpf/fixups.c:1953:\t\t\tcnt = patch - insn_buf;\nkernel/bpf/fixups.c-1954-\nkernel/bpf/fixups.c:1955:\t\t\tnew_prog = bpf_patch_insn_data(env, i + delta, insn_buf, cnt);\nkernel/bpf/fixups.c-1956-\t\t\tif (!new_prog)\n--\nkernel/bpf/fixups.c-1982-\t\t\tstack_depth_extra = 16;\nkernel/bpf/fixups.c:1983:\t\t\tinsn_buf[0] = BPF_LDX_MEM(BPF_DW, BPF_REG_AX, BPF_REG_10, stack_off_cnt);\nkernel/bpf/fixups.c-1984-\t\t\tif (insn-\u003eoff \u003e= 0)\nkernel/bpf/fixups.c:1985:\t\t\t\tinsn_buf[1] = BPF_JMP_IMM(BPF_JEQ, BPF_REG_AX, 0, insn-\u003eoff + 5);\nkernel/bpf/fixups.c-1986-\t\t\telse\nkernel/bpf/fixups.c:1987:\t\t\t\tinsn_buf[1] = BPF_JMP_IMM(BPF_JEQ, BPF_REG_AX, 0, insn-\u003eoff - 1);\nkernel/bpf/fixups.c:1988:\t\t\tinsn_buf[2] = BPF_ALU64_IMM(BPF_SUB, BPF_REG_AX, 1);\nkernel/bpf/fixups.c:1989:\t\t\tinsn_buf[3] = BPF_JMP_IMM(BPF_JNE, BPF_REG_AX, 0, 2);\nkernel/bpf/fixups.c-1990-\t\t\t/*\n--\nkernel/bpf/fixups.c-1994-\t\t\t */\nkernel/bpf/fixups.c:1995:\t\t\tinsn_buf[4] = BPF_MOV64_IMM(BPF_REG_AX, stack_off_cnt);\nkernel/bpf/fixups.c:1996:\t\t\tinsn_buf[5] = BPF_EMIT_CALL(arch_bpf_timed_may_goto);\nkernel/bpf/fixups.c:1997:\t\t\tinsn_buf[6] = BPF_STX_MEM(BPF_DW, BPF_REG_10, BPF_REG_AX, stack_off_cnt);\nkernel/bpf/fixups.c-1998-\t\t\tcnt = 7;\nkernel/bpf/fixups.c-1999-\nkernel/bpf/fixups.c:2000:\t\t\tnew_prog = bpf_patch_insn_data(env, i + delta, insn_buf, cnt);\nkernel/bpf/fixups.c-2001-\t\t\tif (!new_prog)\n--\nkernel/bpf/fixups.c-2011-\t\t\tstack_depth_extra = 8;\nkernel/bpf/fixups.c:2012:\t\t\tinsn_buf[0] = BPF_LDX_MEM(BPF_DW, BPF_REG_AX, BPF_REG_10, stack_off);\nkernel/bpf/fixups.c-2013-\t\t\tif (insn-\u003eoff \u003e= 0)\nkernel/bpf/fixups.c:2014:\t\t\t\tinsn_buf[1] = BPF_JMP_IMM(BPF_JEQ, BPF_REG_AX, 0, insn-\u003eoff + 2);\nkernel/bpf/fixups.c-2015-\t\t\telse\nkernel/bpf/fixups.c:2016:\t\t\t\tinsn_buf[1] = BPF_JMP_IMM(BPF_JEQ, BPF_REG_AX, 0, insn-\u003eoff - 1);\nkernel/bpf/fixups.c:2017:\t\t\tinsn_buf[2] = BPF_ALU64_IMM(BPF_SUB, BPF_REG_AX, 1);\nkernel/bpf/fixups.c:2018:\t\t\tinsn_buf[3] = BPF_STX_MEM(BPF_DW, BPF_REG_10, BPF_REG_AX, stack_off);\nkernel/bpf/fixups.c-2019-\t\t\tcnt = 4;\nkernel/bpf/fixups.c-2020-\nkernel/bpf/fixups.c:2021:\t\t\tnew_prog = bpf_patch_insn_data(env, i + delta, insn_buf, cnt);\nkernel/bpf/fixups.c-2022-\t\t\tif (!new_prog)\n--\nkernel/bpf/fixups.c-2052-\nkernel/bpf/fixups.c:2053:\t\t\tinsn_buf[0] = insn[1];\nkernel/bpf/fixups.c:2054:\t\t\tinsn_buf[1] = BPF_MOV64_PERCPU_REG(insn-\u003edst_reg, insn-\u003edst_reg);\nkernel/bpf/fixups.c-2055-\t\t\tcnt = 2;\n--\nkernel/bpf/fixups.c-2057-\t\t\ti++;\nkernel/bpf/fixups.c:2058:\t\t\tnew_prog = bpf_patch_insn_data(env, i + delta, insn_buf, cnt);\nkernel/bpf/fixups.c-2059-\t\t\tif (!new_prog)\n--\nkernel/bpf/fixups.c-2072-\t\tif (insn-\u003esrc_reg == BPF_PSEUDO_KFUNC_CALL) {\nkernel/bpf/fixups.c:2073:\t\t\tret = bpf_fixup_kfunc_call(env, insn, insn_buf, i + delta, \u0026cnt);\nkernel/bpf/fixups.c-2074-\t\t\tif (ret)\n--\nkernel/bpf/fixups.c-2078-\nkernel/bpf/fixups.c:2079:\t\t\tnew_prog = bpf_patch_insn_data(env, i + delta, insn_buf, cnt);\nkernel/bpf/fixups.c-2080-\t\t\tif (!new_prog)\n--\nkernel/bpf/fixups.c-2157-\t\t\tmap_ptr = aux-\u003emap_ptr_state.map_ptr;\nkernel/bpf/fixups.c:2158:\t\t\tinsn_buf[0] = BPF_JMP_IMM(BPF_JGE, BPF_REG_3,\nkernel/bpf/fixups.c-2159-\t\t\t\t\t\t map_ptr-\u003emax_entries, 2);\nkernel/bpf/fixups.c:2160:\t\t\tinsn_buf[1] = BPF_ALU32_IMM(BPF_AND, BPF_REG_3,\nkernel/bpf/fixups.c-2161-\t\t\t\t\t\t container_of(map_ptr,\n--\nkernel/bpf/fixups.c-2163-\t\t\t\t\t\t\t\t map)-\u003eindex_mask);\nkernel/bpf/fixups.c:2164:\t\t\tinsn_buf[2] = *insn;\nkernel/bpf/fixups.c-2165-\t\t\tcnt = 3;\nkernel/bpf/fixups.c:2166:\t\t\tnew_prog = bpf_patch_insn_data(env, i + delta, insn_buf, cnt);\nkernel/bpf/fixups.c-2167-\t\t\tif (!new_prog)\n--\nkernel/bpf/fixups.c-2194-\nkernel/bpf/fixups.c:2195:\t\t\tinsn_buf[0] = ld_addrs[0];\nkernel/bpf/fixups.c:2196:\t\t\tinsn_buf[1] = ld_addrs[1];\nkernel/bpf/fixups.c:2197:\t\t\tinsn_buf[2] = *insn;\nkernel/bpf/fixups.c-2198-\t\t\tcnt = 3;\nkernel/bpf/fixups.c-2199-\nkernel/bpf/fixups.c:2200:\t\t\tnew_prog = bpf_patch_insn_data(env, i + delta, insn_buf, cnt);\nkernel/bpf/fixups.c-2201-\t\t\tif (!new_prog)\n--\nkernel/bpf/fixups.c-2214-\t\t\t */\nkernel/bpf/fixups.c:2215:\t\t\tinsn_buf[0] = BPF_LDX_MEM(BPF_DW, BPF_REG_1, BPF_REG_1, 0);\nkernel/bpf/fixups.c:2216:\t\t\tinsn_buf[1] = *insn;\nkernel/bpf/fixups.c-2217-\t\t\tcnt = 2;\nkernel/bpf/fixups.c-2218-\nkernel/bpf/fixups.c:2219:\t\t\tnew_prog = bpf_patch_insn_data(env, i + delta, insn_buf, cnt);\nkernel/bpf/fixups.c-2220-\t\t\tif (!new_prog)\n--\nkernel/bpf/fixups.c-2250-\t\t\t ops-\u003emap_gen_lookup) {\nkernel/bpf/fixups.c:2251:\t\t\t\tcnt = ops-\u003emap_gen_lookup(map_ptr, insn_buf);\nkernel/bpf/fixups.c-2252-\t\t\t\tif (cnt == -EOPNOTSUPP)\n--\nkernel/bpf/fixups.c-2262-\t\t\t\tnew_prog = bpf_patch_insn_data(env, i + delta,\nkernel/bpf/fixups.c:2263:\t\t\t\t\t\t\t insn_buf, cnt);\nkernel/bpf/fixups.c-2264-\t\t\t\tif (!new_prog)\n--\nkernel/bpf/fixups.c-2338-\nkernel/bpf/fixups.c:2339:\t\t\tinsn_buf[0] = ld_jiffies_addr[0];\nkernel/bpf/fixups.c:2340:\t\t\tinsn_buf[1] = ld_jiffies_addr[1];\nkernel/bpf/fixups.c:2341:\t\t\tinsn_buf[2] = BPF_LDX_MEM(BPF_DW, BPF_REG_0,\nkernel/bpf/fixups.c-2342-\t\t\t\t\t\t BPF_REG_0, 0);\n--\nkernel/bpf/fixups.c-2344-\nkernel/bpf/fixups.c:2345:\t\t\tnew_prog = bpf_patch_insn_data(env, i + delta, insn_buf,\nkernel/bpf/fixups.c-2346-\t\t\t\t\t\t cnt);\n--\nkernel/bpf/fixups.c-2366-\t\t\tprog-\u003ejit_required = true;\nkernel/bpf/fixups.c:2367:\t\t\tinsn_buf[0] = BPF_MOV64_IMM(BPF_REG_0, (u32)(unsigned long)\u0026cpu_number);\nkernel/bpf/fixups.c:2368:\t\t\tinsn_buf[1] = BPF_MOV64_PERCPU_REG(BPF_REG_0, BPF_REG_0);\nkernel/bpf/fixups.c:2369:\t\t\tinsn_buf[2] = BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_0, 0);\nkernel/bpf/fixups.c-2370-\t\t\tcnt = 3;\nkernel/bpf/fixups.c-2371-#else\nkernel/bpf/fixups.c:2372:\t\t\tinsn_buf[0] = BPF_ALU32_REG(BPF_XOR, BPF_REG_0, BPF_REG_0);\nkernel/bpf/fixups.c-2373-\t\t\tcnt = 1;\nkernel/bpf/fixups.c-2374-#endif\nkernel/bpf/fixups.c:2375:\t\t\tnew_prog = bpf_patch_insn_data(env, i + delta, insn_buf, cnt);\nkernel/bpf/fixups.c-2376-\t\t\tif (!new_prog)\n--\nkernel/bpf/fixups.c-2388-\t\t\tprog-\u003ejit_required = true;\nkernel/bpf/fixups.c:2389:\t\t\tinsn_buf[0] = BPF_MOV64_IMM(BPF_REG_0, (u32)(unsigned long)\u0026current_task);\nkernel/bpf/fixups.c:2390:\t\t\tinsn_buf[1] = BPF_MOV64_PERCPU_REG(BPF_REG_0, BPF_REG_0);\nkernel/bpf/fixups.c:2391:\t\t\tinsn_buf[2] = BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_0, 0);\nkernel/bpf/fixups.c-2392-\t\t\tcnt = 3;\nkernel/bpf/fixups.c-2393-\nkernel/bpf/fixups.c:2394:\t\t\tnew_prog = bpf_patch_insn_data(env, i + delta, insn_buf, cnt);\nkernel/bpf/fixups.c-2395-\t\t\tif (!new_prog)\n--\nkernel/bpf/fixups.c-2410-\t\t\t\t/* skip 'void *__data' in btf_trace_##name() and save to reg0 */\nkernel/bpf/fixups.c:2411:\t\t\t\tinsn_buf[0] = BPF_MOV64_IMM(BPF_REG_0, nr_args - 1);\nkernel/bpf/fixups.c-2412-\t\t\t\tcnt = 1;\n--\nkernel/bpf/fixups.c-2414-\t\t\t\t/* Load nr_args from ctx - 8 */\nkernel/bpf/fixups.c:2415:\t\t\t\tinsn_buf[0] = BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_1, -8);\nkernel/bpf/fixups.c:2416:\t\t\t\tinsn_buf[1] = BPF_ALU64_IMM(BPF_AND, BPF_REG_0, 0xFF);\nkernel/bpf/fixups.c-2417-\t\t\t\tcnt = 2;\nkernel/bpf/fixups.c-2418-\t\t\t}\nkernel/bpf/fixups.c:2419:\t\t\tinsn_buf[cnt++] = BPF_JMP32_REG(BPF_JGE, BPF_REG_2, BPF_REG_0, 6);\nkernel/bpf/fixups.c:2420:\t\t\tinsn_buf[cnt++] = BPF_ALU64_IMM(BPF_LSH, BPF_REG_2, 3);\nkernel/bpf/fixups.c:2421:\t\t\tinsn_buf[cnt++] = BPF_ALU64_REG(BPF_ADD, BPF_REG_2, BPF_REG_1);\nkernel/bpf/fixups.c:2422:\t\t\tinsn_buf[cnt++] = BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_2, 0);\nkernel/bpf/fixups.c:2423:\t\t\tinsn_buf[cnt++] = BPF_STX_MEM(BPF_DW, BPF_REG_3, BPF_REG_0, 0);\nkernel/bpf/fixups.c:2424:\t\t\tinsn_buf[cnt++] = BPF_MOV64_IMM(BPF_REG_0, 0);\nkernel/bpf/fixups.c:2425:\t\t\tinsn_buf[cnt++] = BPF_JMP_A(1);\nkernel/bpf/fixups.c:2426:\t\t\tinsn_buf[cnt++] = BPF_MOV64_IMM(BPF_REG_0, -EINVAL);\nkernel/bpf/fixups.c-2427-\nkernel/bpf/fixups.c:2428:\t\t\tnew_prog = bpf_patch_insn_data(env, i + delta, insn_buf, cnt);\nkernel/bpf/fixups.c-2429-\t\t\tif (!new_prog)\n--\nkernel/bpf/fixups.c-2446-\t\t\t\t/* Load nr_args from ctx - 8 */\nkernel/bpf/fixups.c:2447:\t\t\t\tinsn_buf[0] = BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_1, -8);\nkernel/bpf/fixups.c:2448:\t\t\t\tinsn_buf[1] = BPF_ALU64_IMM(BPF_AND, BPF_REG_0, 0xFF);\nkernel/bpf/fixups.c:2449:\t\t\t\tinsn_buf[2] = BPF_ALU64_IMM(BPF_LSH, BPF_REG_0, 3);\nkernel/bpf/fixups.c:2450:\t\t\t\tinsn_buf[3] = BPF_ALU64_REG(BPF_ADD, BPF_REG_0, BPF_REG_1);\nkernel/bpf/fixups.c:2451:\t\t\t\tinsn_buf[4] = BPF_LDX_MEM(BPF_DW, BPF_REG_3, BPF_REG_0, 0);\nkernel/bpf/fixups.c:2452:\t\t\t\tinsn_buf[5] = BPF_STX_MEM(BPF_DW, BPF_REG_2, BPF_REG_3, 0);\nkernel/bpf/fixups.c:2453:\t\t\t\tinsn_buf[6] = BPF_MOV64_IMM(BPF_REG_0, 0);\nkernel/bpf/fixups.c-2454-\t\t\t\tcnt = 7;\nkernel/bpf/fixups.c-2455-\t\t\t} else {\nkernel/bpf/fixups.c:2456:\t\t\t\tinsn_buf[0] = BPF_MOV64_IMM(BPF_REG_0, -EOPNOTSUPP);\nkernel/bpf/fixups.c-2457-\t\t\t\tcnt = 1;\n--\nkernel/bpf/fixups.c-2459-\nkernel/bpf/fixups.c:2460:\t\t\tnew_prog = bpf_patch_insn_data(env, i + delta, insn_buf, cnt);\nkernel/bpf/fixups.c-2461-\t\t\tif (!new_prog)\n--\nkernel/bpf/fixups.c-2476-\t\t\t\t/* skip 'void *__data' in btf_trace_##name() and save to reg0 */\nkernel/bpf/fixups.c:2477:\t\t\t\tinsn_buf[0] = BPF_MOV64_IMM(BPF_REG_0, nr_args - 1);\nkernel/bpf/fixups.c-2478-\t\t\t\tcnt = 1;\n--\nkernel/bpf/fixups.c-2480-\t\t\t\t/* Load nr_args from ctx - 8 */\nkernel/bpf/fixups.c:2481:\t\t\t\tinsn_buf[0] = BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_1, -8);\nkernel/bpf/fixups.c:2482:\t\t\t\tinsn_buf[1] = BPF_ALU64_IMM(BPF_AND, BPF_REG_0, 0xFF);\nkernel/bpf/fixups.c-2483-\t\t\t\tcnt = 2;\n--\nkernel/bpf/fixups.c-2485-\nkernel/bpf/fixups.c:2486:\t\t\tnew_prog = bpf_patch_insn_data(env, i + delta, insn_buf, cnt);\nkernel/bpf/fixups.c-2487-\t\t\tif (!new_prog)\n--\nkernel/bpf/fixups.c-2499-\t\t\t/* Load IP address from ctx - 16 */\nkernel/bpf/fixups.c:2500:\t\t\tinsn_buf[0] = BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_1, -16);\nkernel/bpf/fixups.c-2501-\nkernel/bpf/fixups.c:2502:\t\t\tnew_prog = bpf_patch_insn_data(env, i + delta, insn_buf, 1);\nkernel/bpf/fixups.c-2503-\t\t\tif (!new_prog)\n--\nkernel/bpf/fixups.c-2527-\t\t\t/* if (unlikely(flags)) return -EINVAL */\nkernel/bpf/fixups.c:2528:\t\t\tinsn_buf[0] = BPF_JMP_IMM(BPF_JNE, BPF_REG_3, 0, 7);\nkernel/bpf/fixups.c-2529-\n--\nkernel/bpf/fixups.c-2538-\t\t\t */\nkernel/bpf/fixups.c:2539:\t\t\tinsn_buf[1] = BPF_MOV32_IMM(BPF_REG_0, 0xaaaaaaab);\nkernel/bpf/fixups.c:2540:\t\t\tinsn_buf[2] = BPF_ALU64_REG(BPF_MUL, BPF_REG_2, BPF_REG_0);\nkernel/bpf/fixups.c:2541:\t\t\tinsn_buf[3] = BPF_ALU64_IMM(BPF_RSH, BPF_REG_2, 36);\nkernel/bpf/fixups.c-2542-\nkernel/bpf/fixups.c-2543-\t\t\t/* call perf_snapshot_branch_stack implementation */\nkernel/bpf/fixups.c:2544:\t\t\tinsn_buf[4] = BPF_EMIT_CALL(static_call_query(perf_snapshot_branch_stack));\nkernel/bpf/fixups.c-2545-\t\t\t/* if (entry_cnt == 0) return -ENOENT */\nkernel/bpf/fixups.c:2546:\t\t\tinsn_buf[5] = BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 4);\nkernel/bpf/fixups.c-2547-\t\t\t/* return entry_cnt * sizeof(struct perf_branch_entry) */\nkernel/bpf/fixups.c:2548:\t\t\tinsn_buf[6] = BPF_ALU32_IMM(BPF_MUL, BPF_REG_0, br_entry_size);\nkernel/bpf/fixups.c:2549:\t\t\tinsn_buf[7] = BPF_JMP_A(3);\nkernel/bpf/fixups.c-2550-\t\t\t/* return -EINVAL; */\nkernel/bpf/fixups.c:2551:\t\t\tinsn_buf[8] = BPF_MOV64_IMM(BPF_REG_0, -EINVAL);\nkernel/bpf/fixups.c:2552:\t\t\tinsn_buf[9] = BPF_JMP_A(1);\nkernel/bpf/fixups.c-2553-\t\t\t/* return -ENOENT; */\nkernel/bpf/fixups.c:2554:\t\t\tinsn_buf[10] = BPF_MOV64_IMM(BPF_REG_0, -ENOENT);\nkernel/bpf/fixups.c-2555-\t\t\tcnt = 11;\nkernel/bpf/fixups.c-2556-\nkernel/bpf/fixups.c:2557:\t\t\tnew_prog = bpf_patch_insn_data(env, i + delta, insn_buf, cnt);\nkernel/bpf/fixups.c-2558-\t\t\tif (!new_prog)\n--\nkernel/bpf/fixups.c-2570-\t\t bpf_jit_supports_ptr_xchg()) {\nkernel/bpf/fixups.c:2571:\t\t\tinsn_buf[0] = BPF_MOV64_REG(BPF_REG_0, BPF_REG_2);\nkernel/bpf/fixups.c:2572:\t\t\tinsn_buf[1] = BPF_ATOMIC_OP(BPF_DW, BPF_XCHG, BPF_REG_1, BPF_REG_0, 0);\nkernel/bpf/fixups.c-2573-\t\t\tcnt = 2;\nkernel/bpf/fixups.c-2574-\nkernel/bpf/fixups.c:2575:\t\t\tnew_prog = bpf_patch_insn_data(env, i + delta, insn_buf, cnt);\nkernel/bpf/fixups.c-2576-\t\t\tif (!new_prog)\n--\nkernel/bpf/fixups.c-2631-\t\tif (bpf_jit_supports_timed_may_goto()) {\nkernel/bpf/fixups.c:2632:\t\t\tinsn_buf[cnt++] = BPF_ST_MEM(BPF_DW, BPF_REG_FP, -stack_depth,\nkernel/bpf/fixups.c-2633-\t\t\t\t\t\t BPF_MAX_TIMED_LOOPS);\nkernel/bpf/fixups.c:2634:\t\t\tinsn_buf[cnt++] = BPF_ST_MEM(BPF_DW, BPF_REG_FP, -stack_depth + 8, 0);\nkernel/bpf/fixups.c-2635-\t\t} else {\nkernel/bpf/fixups.c-2636-\t\t\t/* Add ST insn to subprog prologue to init extra stack */\nkernel/bpf/fixups.c:2637:\t\t\tinsn_buf[cnt++] = BPF_ST_MEM(BPF_DW, BPF_REG_FP, -stack_depth,\nkernel/bpf/fixups.c-2638-\t\t\t\t\t\t BPF_MAX_LOOPS);\n--\nkernel/bpf/fixups.c-2640-\t\t/* Copy first actual insn to preserve it */\nkernel/bpf/fixups.c:2641:\t\tinsn_buf[cnt++] = env-\u003eprog-\u003einsnsi[subprog_start];\nkernel/bpf/fixups.c-2642-\nkernel/bpf/fixups.c:2643:\t\tnew_prog = bpf_patch_insn_data(env, subprog_start, insn_buf, cnt);\nkernel/bpf/fixups.c-2644-\t\tif (!new_prog)\n--\nkernel/bpf/fixups.c=2680=static struct bpf_prog *inline_bpf_loop(struct bpf_verifier_env *env,\n--\nkernel/bpf/fixups.c-2692-\nkernel/bpf/fixups.c:2693:\tstruct bpf_insn *insn_buf = env-\u003einsn_buf;\nkernel/bpf/fixups.c-2694-\tstruct bpf_prog *new_prog;\n--\nkernel/bpf/fixups.c-2706-\t */\nkernel/bpf/fixups.c:2707:\tinsn_buf[cnt++] = BPF_JMP_IMM(BPF_JLE, BPF_REG_1, BPF_MAX_LOOPS, 2);\nkernel/bpf/fixups.c:2708:\tinsn_buf[cnt++] = BPF_MOV32_IMM(BPF_REG_0, -E2BIG);\nkernel/bpf/fixups.c:2709:\tinsn_buf[cnt++] = BPF_JMP_IMM(BPF_JA, 0, 0, 16);\nkernel/bpf/fixups.c-2710-\t/* spill R6, R7, R8 to use these as loop vars */\nkernel/bpf/fixups.c:2711:\tinsn_buf[cnt++] = BPF_STX_MEM(BPF_DW, BPF_REG_10, BPF_REG_6, r6_offset);\nkernel/bpf/fixups.c:2712:\tinsn_buf[cnt++] = BPF_STX_MEM(BPF_DW, BPF_REG_10, BPF_REG_7, r7_offset);\nkernel/bpf/fixups.c:2713:\tinsn_buf[cnt++] = BPF_STX_MEM(BPF_DW, BPF_REG_10, BPF_REG_8, r8_offset);\nkernel/bpf/fixups.c-2714-\t/* initialize loop vars */\nkernel/bpf/fixups.c:2715:\tinsn_buf[cnt++] = BPF_MOV64_REG(reg_loop_max, BPF_REG_1);\nkernel/bpf/fixups.c:2716:\tinsn_buf[cnt++] = BPF_MOV32_IMM(reg_loop_cnt, 0);\nkernel/bpf/fixups.c:2717:\tinsn_buf[cnt++] = BPF_MOV64_REG(reg_loop_ctx, BPF_REG_3);\nkernel/bpf/fixups.c-2718-\t/* loop header,\n--\nkernel/bpf/fixups.c-2720-\t */\nkernel/bpf/fixups.c:2721:\tinsn_buf[cnt++] = BPF_JMP_REG(BPF_JGE, reg_loop_cnt, reg_loop_max, 5);\nkernel/bpf/fixups.c-2722-\t/* callback call,\n--\nkernel/bpf/fixups.c-2724-\t */\n\n"
} |
| 29/3 | 2026/09/26 03:31 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 58438 output: 28 thoughts: 38 Thoughts: Here's my take on the thought process, as requested: **Investigating Instruction Buffer Size** Okay, so I'm looking at this `bpf_verifier_env` structure and specifically the `insn_buf` member. It's got me wondering about its size, which is defined by `INSN_BUF_SIZE`. Given my work, it's pretty essential I understand the limitations of these buffers. So, I need to immediately dig into what `INSN_BUF_SIZE` actually resolves to. I need that number, and I need it now. Gotta confirm this isn't going to be a limiting factor in something I'm debugging. |
| 30/3 | 2026/09/26 03:31 | tool | grepper |
0mArgs:{
"Expression": "INSN_BUF_SIZE",
"PathPrefix": "include/"
}Results: {
"Output": "include/linux/bpf_verifier.h-27-/* Patch buffer size */\ninclude/linux/bpf_verifier.h:28:#define INSN_BUF_SIZE 32\ninclude/linux/bpf_verifier.h-29-\n--\ninclude/linux/bpf_verifier.h=935=struct bpf_verifier_env {\n--\ninclude/linux/bpf_verifier.h-1055-\tchar tmp_arg_name[32];\ninclude/linux/bpf_verifier.h:1056:\tstruct bpf_insn insn_buf[INSN_BUF_SIZE];\ninclude/linux/bpf_verifier.h:1057:\tstruct bpf_insn epilogue_buf[INSN_BUF_SIZE];\ninclude/linux/bpf_verifier.h-1058-\tstruct bpf_scc_callchain callchain_buf;\n"
} |
| 31/3 | 2026/09/26 03:31 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 58878 output: 35 thoughts: 1071 Thoughts: **Analyzing `add_loop_guard` Instruction Count and Data Initialization** Okay, so `INSN_BUF_SIZE` is 32. I need to figure out the maximum number of instructions `add_loop_guard` can emit. Looking at the code, let's break it down instruction by instruction. The `if (guard_jump_edge && !ja)` path adds at most 2 instructions initially. The `else if (!guard_jump_edge)` path adds one instruction. Now, the `bpf_jit_supports_timed_may_goto()` block or the `else` block, based on the availability of that functionality, can add either 9 or 4 instructions respectively. Finally the `if (guard_jump_edge)` path adds 1 or 1, and the `else` path adds 1. Then at least 2 instructions are added at the end. Thus: 2 + 7 + 1 + 2 = 12, or 1 + 4 + 1 + 2 = 8, in either case this is within the 32-instruction limit. Good. But wait, I need to consider uninitialized stack or heap data. Let's look at where `add_loop_guard` is called and what happens with the generated instructions. I see `bpf_patch_insn_data(env, i + delta, insn_buf, cnt);`. The key here is whether `cnt`, the number of instructions emitted, is valid. Looking at the call, `bpf_patch_insn_data` is only called if `cnt >= 0`. Moreover, the instructions `insn_buf[0..cnt-1]` *are* written to and initialized before the call to `bpf_patch_insn_data`! So far, so good. But, hang on a second... what about the stack? I'm using `BPF_LDX_MEM` to load from a stack offset (`stack_off`). Is `stack_off` initialized *before* `add_loop_guard` is even called, when `bpf_commit_loop_guards` marks `loop_guard`? The code seems to indicate `stack_off` will be initialized... but I need to be sure. Time to investigate how `may_goto` and similar functions initialize their stack slots. Let's trace it back through `bpf_do_misc_fixups` and see how the stack frame is set up before the `add_loop_guard` path is even reached! |
| 32/3 | 2026/09/26 03:31 | tool | grepper |
0mArgs:{
"Expression": "BPF_MAX_TIMED_LOOPS",
"PathPrefix": "kernel/bpf/"
}Results: {
"Output": "kernel/bpf/core.c=3504=u64 bpf_check_timed_may_goto(struct bpf_timed_may_goto *p)\n--\nkernel/bpf/core.c-3510-\t\tp-\u003etimestamp = time;\nkernel/bpf/core.c:3511:\t\treturn BPF_MAX_TIMED_LOOPS;\nkernel/bpf/core.c-3512-\t}\n--\nkernel/bpf/core.c-3518-\t/* Refresh the count for the stack frame. */\nkernel/bpf/core.c:3519:\treturn BPF_MAX_TIMED_LOOPS;\nkernel/bpf/core.c-3520-}\n--\nkernel/bpf/fixups.c=1677=int bpf_do_misc_fixups(struct bpf_verifier_env *env)\n--\nkernel/bpf/fixups.c-1971-\t\t\t *\nkernel/bpf/fixups.c:1972:\t\t\t * The starting value of count is BPF_MAX_TIMED_LOOPS\nkernel/bpf/fixups.c-1973-\t\t\t * (0xffff). Every iteration loads it and subs it by 1,\n--\nkernel/bpf/fixups.c-2632-\t\t\tinsn_buf[cnt++] = BPF_ST_MEM(BPF_DW, BPF_REG_FP, -stack_depth,\nkernel/bpf/fixups.c:2633:\t\t\t\t\t\t BPF_MAX_TIMED_LOOPS);\nkernel/bpf/fixups.c-2634-\t\t\tinsn_buf[cnt++] = BPF_ST_MEM(BPF_DW, BPF_REG_FP, -stack_depth + 8, 0);\n"
} |
| 33/3 | 2026/09/26 03:31 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 60992 output: 38 thoughts: 31 Thoughts: Okay, let's dive into it. **Analyzing Kernel BPF Fixups in `fixups.c`** Alright, I'm going to take a look at lines 2630-2645 of `kernel/bpf/fixups.c`. That's where the action is, apparently. Let's see what kind of fixups the kernel is performing there. I'll need to understand the surrounding context to fully grasp it, of course, but these specific lines will give me a critical piece of the puzzle. I anticipate these are likely related to addressing some specific BPF bytecode issue – maybe a security vulnerability being patched, an optimization, or perhaps a compatibility layer dealing with changes in the underlying hardware or BPF interpreter. My initial thought is to look for specific instructions being modified or re-written, or maybe an adjustment to memory offsets or register usage. It is imperative that it addresses the issue correctly, efficiently, and without introducing regressions. I'm keen to spot any clever tricks or potentially problematic areas that I can analyze further. My primary concern will be to ascertain the rationale for the fix and the side effects of this fix. |
| 34/3 | 2026/09/26 03:31 | tool | read-file |
0mArgs:{
"File": "kernel/bpf/fixups.c",
"FirstLine": 2620,
"LineCount": 45
}Results: {
"Contents": "2620:\t\t\tint slots = delta, cnt = 0;\n2621:\t\n2622:\t\t\tif (!stack_slots)\n2623:\t\t\t\tcontinue;\n2624:\t\t\t/* We need two slots in case timed may_goto is supported. */\n2625:\t\t\tif (stack_slots \u003e slots) {\n2626:\t\t\t\tverifier_bug(env, \"stack_slots supports may_goto only\");\n2627:\t\t\t\treturn -EFAULT;\n2628:\t\t\t}\n2629:\t\n2630:\t\t\tstack_depth = subprogs[i].stack_depth;\n2631:\t\t\tif (bpf_jit_supports_timed_may_goto()) {\n2632:\t\t\t\tinsn_buf[cnt++] = BPF_ST_MEM(BPF_DW, BPF_REG_FP, -stack_depth,\n2633:\t\t\t\t\t\t\t BPF_MAX_TIMED_LOOPS);\n2634:\t\t\t\tinsn_buf[cnt++] = BPF_ST_MEM(BPF_DW, BPF_REG_FP, -stack_depth + 8, 0);\n2635:\t\t\t} else {\n2636:\t\t\t\t/* Add ST insn to subprog prologue to init extra stack */\n2637:\t\t\t\tinsn_buf[cnt++] = BPF_ST_MEM(BPF_DW, BPF_REG_FP, -stack_depth,\n2638:\t\t\t\t\t\t\t BPF_MAX_LOOPS);\n2639:\t\t\t}\n2640:\t\t\t/* Copy first actual insn to preserve it */\n2641:\t\t\tinsn_buf[cnt++] = env-\u003eprog-\u003einsnsi[subprog_start];\n2642:\t\n2643:\t\t\tnew_prog = bpf_patch_insn_data(env, subprog_start, insn_buf, cnt);\n2644:\t\t\tif (!new_prog)\n2645:\t\t\t\treturn -ENOMEM;\n2646:\t\t\tenv-\u003eprog = prog = new_prog;\n2647:\t\t\t/*\n2648:\t\t\t * If may_goto is a first insn of a prog there could be a jmp\n2649:\t\t\t * insn that points to it, hence adjust all such jmps to point\n2650:\t\t\t * to insn after BPF_ST that inits may_goto count.\n2651:\t\t\t * Adjustment will succeed because bpf_patch_insn_data() didn't fail.\n2652:\t\t\t */\n2653:\t\t\tWARN_ON(adjust_jmp_off(env-\u003eprog, subprog_start, delta));\n2654:\t\t}\n2655:\t\n2656:\t\t/* Since poke tab is now finalized, publish aux to tracker. */\n2657:\t\tfor (i = 0; i \u003c prog-\u003eaux-\u003esize_poke_tab; i++) {\n2658:\t\t\tmap_ptr = prog-\u003eaux-\u003epoke_tab[i].tail_call.map;\n2659:\t\t\tif (!map_ptr-\u003eops-\u003emap_poke_track ||\n2660:\t\t\t !map_ptr-\u003eops-\u003emap_poke_untrack ||\n2661:\t\t\t !map_ptr-\u003eops-\u003emap_poke_run) {\n2662:\t\t\t\tverifier_bug(env, \"poke tab is misconfigured\");\n2663:\t\t\t\treturn -EFAULT;\n2664:\t\t\t}\n"
} |
| 35/3 | 2026/09/26 03:31 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 62162 output: 38 thoughts: 54 Thoughts: Here's my take on the thought process, tailored for an expert audience: **Diving Back into Fixups** Hold on a moment, I need to zoom out and make sure I've got the `stack_slots` and `subprogs` interaction clear in this BPF fixup context. I'm going to jump back up to lines 2600-2625 in `kernel/bpf/fixups.c`. That's where the heart of that loop logic resides, and I want to refresh my understanding of *how* that stack slot allocation plays into the process of updating program calls. I'm especially interested in how the subprogram calls are handled within this section, as this is a crucial aspect of overall BPF security and performance. Let me verify the nuances of this loop. |
| 36/3 | 2026/09/26 03:32 | tool | read-file |
0mArgs:{
"File": "kernel/bpf/fixups.c",
"FirstLine": 2600,
"LineCount": 25
}Results: {
"Contents": "2600:\t\n2601:\t\t\t\tstack_depth = subprogs[cur_subprog].stack_depth;\n2602:\t\t\t\tif (stack_depth \u003e MAX_BPF_STACK \u0026\u0026 !prog-\u003ejit_requested) {\n2603:\t\t\t\t\tverbose(env, \"stack size %d(extra %d) is too large\\n\",\n2604:\t\t\t\t\t\tstack_depth, stack_depth_extra);\n2605:\t\t\t\t\treturn -EINVAL;\n2606:\t\t\t\t}\n2607:\t\t\t\tcur_subprog++;\n2608:\t\t\t\tstack_depth = subprogs[cur_subprog].stack_depth;\n2609:\t\t\t\tstack_depth_extra = 0;\n2610:\t\t\t}\n2611:\t\t\ti++;\n2612:\t\t\tinsn++;\n2613:\t\t}\n2614:\t\n2615:\t\tenv-\u003eprog-\u003eaux-\u003estack_depth = subprogs[0].stack_depth;\n2616:\t\tfor (i = 0; i \u003c env-\u003esubprog_cnt; i++) {\n2617:\t\t\tint delta = bpf_jit_supports_timed_may_goto() ? 2 : 1;\n2618:\t\t\tint subprog_start = subprogs[i].start;\n2619:\t\t\tint stack_slots = subprogs[i].stack_extra / 8;\n2620:\t\t\tint slots = delta, cnt = 0;\n2621:\t\n2622:\t\t\tif (!stack_slots)\n2623:\t\t\t\tcontinue;\n2624:\t\t\t/* We need two slots in case timed may_goto is supported. */\n"
} |
| 37/3 | 2026/09/26 03:32 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 62855 output: 38 thoughts: 56 Thoughts: Okay, let's dive into this BPF code. I need to understand how the `subprogs[cur_subprog]` stack is being managed within `bpf_do_misc_fixups`. I have a feeling something interesting is happening there. Let me jump right to the heart of the matter – lines 1700 through 1740 of `kernel/bpf/fixups.c`. That's where the magic, or potential problem, should lie. Let's see what the stack operations are doing within that function and figure out how they are impacting the program's execution and performance. It's time to analyze the register manipulation and stack allocation within `bpf_do_misc_fixups` at those lines and ensure the data's integrity. |
| 38/3 | 2026/09/26 03:32 | tool | read-file |
0mArgs:{
"File": "kernel/bpf/fixups.c",
"FirstLine": 1700,
"LineCount": 40
}Results: {
"Contents": "1700:\t\t\t*patch++ = BPF_EXIT_INSN();\n1701:\t\t\tret = add_hidden_subprog(env, insn_buf, patch - insn_buf);\n1702:\t\t\tif (ret \u003c 0)\n1703:\t\t\t\treturn ret;\n1704:\t\t\tprog = env-\u003eprog;\n1705:\t\t\tinsn = prog-\u003einsnsi;\n1706:\t\n1707:\t\t\tenv-\u003eexception_callback_subprog = env-\u003esubprog_cnt - 1;\n1708:\t\t\t/* Don't update insn_cnt, as add_hidden_subprog always appends insns */\n1709:\t\t\tbpf_mark_subprog_exc_cb(env, env-\u003eexception_callback_subprog);\n1710:\t\t}\n1711:\t\n1712:\t\tfor (i = 0; i \u003c insn_cnt;) {\n1713:\t\t\tif (env-\u003einsn_aux_data[i + delta].loop_guard) {\n1714:\t\t\t\tcnt = add_loop_guard(env, i + delta, insn_buf, stack_depth,\n1715:\t\t\t\t\t\t \u0026stack_depth_extra);\n1716:\t\t\t\tif (cnt \u003c 0)\n1717:\t\t\t\t\treturn cnt;\n1718:\t\n1719:\t\t\t\tnew_prog = bpf_patch_insn_data(env, i + delta, insn_buf, cnt);\n1720:\t\t\t\tif (!new_prog)\n1721:\t\t\t\t\treturn -ENOMEM;\n1722:\t\n1723:\t\t\t\tdelta += cnt - 1;\n1724:\t\t\t\tenv-\u003eprog = prog = new_prog;\n1725:\t\t\t\tinsn = new_prog-\u003einsnsi + i + delta;\n1726:\t\t\t\tgoto next_insn;\n1727:\t\t\t}\n1728:\t\n1729:\t\t\tif (is_addr_space_cast32(env-\u003eprog, insn)) {\n1730:\t\t\t\t/* convert to 32-bit mov that clears upper 32-bit */\n1731:\t\t\t\tinsn-\u003ecode = BPF_ALU | BPF_MOV | BPF_X;\n1732:\t\t\t\t/* clear off and imm, so it's a normal 'wX = wY' from JIT pov */\n1733:\t\t\t\tinsn-\u003eoff = 0;\n1734:\t\t\t\tinsn-\u003eimm = 0;\n1735:\t\t\t\tgoto next_insn;\n1736:\t\t\t}\n1737:\t\n1738:\t\t\tif (env-\u003einsn_aux_data[i + delta].needs_zext)\n1739:\t\t\t\t/* Convert BPF_CLASS(insn-\u003ecode) == BPF_ALU64 to 32-bit ALU */\n"
} |
| 39/3 | 2026/09/26 03:32 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 63845 output: 38 thoughts: 47 Thoughts: Here's my analysis of the provided snippet, as if it were my thought process: **Diving Deep into Stack Depth Updates** Okay, let's zero in on how the stack depth is handled when switching between subprograms. The prompt points to `subprogs[cur_subprog].stack_depth` being updated within this loop, and the key is understanding *when* and *why* those changes occur in relation to changes in `cur_subprog`. I need to precisely identify the control flow that governs those updates. Lines 2580 to 2615 seem to be the area of interest. I'll focus my attention there and try to see what triggers the changes in `cur_subprog` and how those events relate to stack manipulation. I'm going to look for any logic related to the stack, especially any pushing or popping operations, and how those are linked to updating this `stack_depth` variable, given how dynamic this process will likely be. Understanding the conditions for subprogram switching is critical to grasp how the stack is managed across them. |
| 40/3 | 2026/09/26 03:32 | tool | read-file |
0mArgs:{
"File": "kernel/bpf/fixups.c",
"FirstLine": 2580,
"LineCount": 40
}Results: {
"Contents": "2580:\t\t\t\tenv-\u003eprog = prog = new_prog;\n2581:\t\t\t\tinsn = new_prog-\u003einsnsi + i + delta;\n2582:\t\t\t\tgoto next_insn;\n2583:\t\t\t}\n2584:\tpatch_call_imm:\n2585:\t\t\tfn = env-\u003eops-\u003eget_func_proto(insn-\u003eimm, env-\u003eprog);\n2586:\t\t\t/* all functions that have prototype and verifier allowed\n2587:\t\t\t * programs to call them, must be real in-kernel functions\n2588:\t\t\t */\n2589:\t\t\tif (!fn-\u003efunc) {\n2590:\t\t\t\tverifier_bug(env,\n2591:\t\t\t\t\t \"not inlined functions %s#%d is missing func\",\n2592:\t\t\t\t\t func_id_name(insn-\u003eimm), insn-\u003eimm);\n2593:\t\t\t\treturn -EFAULT;\n2594:\t\t\t}\n2595:\t\t\tinsn-\u003eimm = BPF_CALL_IMM(fn-\u003efunc);\n2596:\tnext_insn:\n2597:\t\t\tif (subprogs[cur_subprog + 1].start == i + delta + 1) {\n2598:\t\t\t\tsubprogs[cur_subprog].stack_depth += stack_depth_extra;\n2599:\t\t\t\tsubprogs[cur_subprog].stack_extra = stack_depth_extra;\n2600:\t\n2601:\t\t\t\tstack_depth = subprogs[cur_subprog].stack_depth;\n2602:\t\t\t\tif (stack_depth \u003e MAX_BPF_STACK \u0026\u0026 !prog-\u003ejit_requested) {\n2603:\t\t\t\t\tverbose(env, \"stack size %d(extra %d) is too large\\n\",\n2604:\t\t\t\t\t\tstack_depth, stack_depth_extra);\n2605:\t\t\t\t\treturn -EINVAL;\n2606:\t\t\t\t}\n2607:\t\t\t\tcur_subprog++;\n2608:\t\t\t\tstack_depth = subprogs[cur_subprog].stack_depth;\n2609:\t\t\t\tstack_depth_extra = 0;\n2610:\t\t\t}\n2611:\t\t\ti++;\n2612:\t\t\tinsn++;\n2613:\t\t}\n2614:\t\n2615:\t\tenv-\u003eprog-\u003eaux-\u003estack_depth = subprogs[0].stack_depth;\n2616:\t\tfor (i = 0; i \u003c env-\u003esubprog_cnt; i++) {\n2617:\t\t\tint delta = bpf_jit_supports_timed_may_goto() ? 2 : 1;\n2618:\t\t\tint subprog_start = subprogs[i].start;\n2619:\t\t\tint stack_slots = subprogs[i].stack_extra / 8;\n"
} |
| 41/3 | 2026/09/26 03:32 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 64875 output: 38 thoughts: 81 Thoughts: Here's my thought process, as requested: **Debugging a Potential Stack Issue in the Subprogram Handling** Okay, so I'm looking at this code and I'm starting to think about a potential edge case. I'm wondering if a recent change I made might be messing with the allocation or deallocation of the stack space related to the subprograms. Specifically, I'm concerned about whether the *last* subprogram is being handled correctly. I need to make sure its `stack_extra` is accounted for. My first instinct is to zero in on the loop that iterates through the subprograms. I'll need to check the lines where the post-loop processing happens. Let's see, that's probably around lines 2610-2620, right after the core `for` loop. I need to make absolutely sure everything is handled properly in relation to the `stack_extra` of the last subprog. But then again, the stack-related info has to be setup before the loop, so I should see the initialization code as well. I'll need to double check the lines before that, around 1680, which should deal with the stack setup before the loop. I'll have to consider both sections and make sure they both check out. |
| 42/3 | 2026/09/26 03:32 | tool | read-file |
0mArgs:{
"File": "kernel/bpf/fixups.c",
"FirstLine": 1675,
"LineCount": 40
}Results: {
"Contents": "1675:\t}\n1676:\t\n1677:\tint bpf_do_misc_fixups(struct bpf_verifier_env *env)\n1678:\t{\n1679:\t\tstruct bpf_prog *prog = env-\u003eprog;\n1680:\t\tenum bpf_attach_type eatype = prog-\u003eexpected_attach_type;\n1681:\t\tenum bpf_prog_type prog_type = resolve_prog_type(prog);\n1682:\t\tstruct bpf_insn *insn = prog-\u003einsnsi;\n1683:\t\tconst struct bpf_func_proto *fn;\n1684:\t\tconst int insn_cnt = prog-\u003elen;\n1685:\t\tconst struct bpf_map_ops *ops;\n1686:\t\tstruct bpf_insn_aux_data *aux;\n1687:\t\tstruct bpf_insn *insn_buf = env-\u003einsn_buf;\n1688:\t\tstruct bpf_prog *new_prog;\n1689:\t\tstruct bpf_map *map_ptr;\n1690:\t\tint i, ret, cnt, delta = 0, cur_subprog = 0;\n1691:\t\tstruct bpf_subprog_info *subprogs = env-\u003esubprog_info;\n1692:\t\tu16 stack_depth = subprogs[cur_subprog].stack_depth;\n1693:\t\tu16 stack_depth_extra = 0;\n1694:\t\n1695:\t\tif (env-\u003eseen_exception \u0026\u0026 !env-\u003eexception_callback_subprog) {\n1696:\t\t\tstruct bpf_insn *patch = insn_buf;\n1697:\t\n1698:\t\t\t*patch++ = env-\u003eprog-\u003einsnsi[insn_cnt - 1];\n1699:\t\t\t*patch++ = BPF_MOV64_REG(BPF_REG_0, BPF_REG_1);\n1700:\t\t\t*patch++ = BPF_EXIT_INSN();\n1701:\t\t\tret = add_hidden_subprog(env, insn_buf, patch - insn_buf);\n1702:\t\t\tif (ret \u003c 0)\n1703:\t\t\t\treturn ret;\n1704:\t\t\tprog = env-\u003eprog;\n1705:\t\t\tinsn = prog-\u003einsnsi;\n1706:\t\n1707:\t\t\tenv-\u003eexception_callback_subprog = env-\u003esubprog_cnt - 1;\n1708:\t\t\t/* Don't update insn_cnt, as add_hidden_subprog always appends insns */\n1709:\t\t\tbpf_mark_subprog_exc_cb(env, env-\u003eexception_callback_subprog);\n1710:\t\t}\n1711:\t\n1712:\t\tfor (i = 0; i \u003c insn_cnt;) {\n1713:\t\t\tif (env-\u003einsn_aux_data[i + delta].loop_guard) {\n1714:\t\t\t\tcnt = add_loop_guard(env, i + delta, insn_buf, stack_depth,\n"
} |
| 43/3 | 2026/09/26 03:32 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 66071 output: 32 thoughts: 372 Thoughts: **Analyzing BPF Subprogram Stack Depth Fixup** Okay, let's dive into this `kernel/bpf/fixups.c` code, specifically lines 2610-2616. I'm seeing a potential issue. The existing logic here seems to increment `stack_depth` based on the start of the *next* subprogram. But what happens if the *last* subprogram in the sequence has a `may_goto` or `loop_guard` instruction? Does the code as written properly account for it? I need to back up and confirm my understanding. Let's read a wider context, from lines 2605 to 2620. Okay, I'm reading. Lines 2607-2615... Okay, I see that the code uses a loop and `cur_subprog` to iterate through the subprograms. It updates the `stack_depth` of the *previous* `subprog`. `env->prog->aux->stack_depth` is set after the loop. Aha! Now I'm remembering something important. In `fixups.c`, the `subprogs[env->subprog_cnt].start` is set to the total length of the program. I need to verify that. I suspect this is relevant to handling the stack depth for the *last* subprogram because this could determine how the stack is handled when an exit from the final subprogram is encountered. I should look into the `bpf_check` function or the initialization of `subprogs` to be absolutely certain. |
| 44/3 | 2026/09/26 03:32 | tool | grepper |
0mArgs:{
"Expression": "subprogs\\[.*\\.start",
"PathPrefix": "kernel/bpf/"
}Results: {
"Output": "kernel/bpf/fixups.c=773=int bpf_convert_ctx_accesses(struct bpf_verifier_env *env)\n--\nkernel/bpf/fixups.c-898-\t\t\t epilogue_cnt \u0026\u0026\nkernel/bpf/fixups.c:899:\t\t\t i + delta \u003c subprogs[1].start) {\nkernel/bpf/fixups.c-900-\t\t\t/* Generate epilogue for the main prog */\n--\nkernel/bpf/fixups.c=1677=int bpf_do_misc_fixups(struct bpf_verifier_env *env)\n--\nkernel/bpf/fixups.c-2596-next_insn:\nkernel/bpf/fixups.c:2597:\t\tif (subprogs[cur_subprog + 1].start == i + delta + 1) {\nkernel/bpf/fixups.c-2598-\t\t\tsubprogs[cur_subprog].stack_depth += stack_depth_extra;\n--\nkernel/bpf/fixups.c-2617-\t\tint delta = bpf_jit_supports_timed_may_goto() ? 2 : 1;\nkernel/bpf/fixups.c:2618:\t\tint subprog_start = subprogs[i].start;\nkernel/bpf/fixups.c-2619-\t\tint stack_slots = subprogs[i].stack_extra / 8;\n--\nkernel/bpf/fixups.c=2772=int bpf_optimize_bpf_loop(struct bpf_verifier_env *env)\n--\nkernel/bpf/fixups.c-2802-\nkernel/bpf/fixups.c:2803:\t\tif (subprogs[cur_subprog + 1].start == i + delta + 1) {\nkernel/bpf/fixups.c-2804-\t\t\tsubprogs[cur_subprog].stack_depth += stack_depth_extra;\n"
} |
| 45/3 | 2026/09/26 03:32 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 67325 output: 32 thoughts: 770 Thoughts: **Analyzing the BPF Verifier Loop Widening Implementation** Okay, so I've confirmed that `subprogs[env->subprog_cnt].start` does indeed mark the end of instructions, which means the update to `subprogs[cur_subprog].stack_depth` is the correct mechanism used for `may_goto`, the existing behavior. I'm satisfied that this aligns with how things are set up. Now, let's circle back to `add_loop_guard`. This emits that `jeq->off = p - jeq - 1`, and adds the `BPF_MOV64_IMM` and `BPF_EMIT_CALL` instructions, and importantly, it's updating `stack_depth_extra` to 16, or the maximum of that and 8. So that confirms my understanding of this part too, consistent with `may_goto`. Alright, let's zoom out and look at the bigger picture of this patch and how it functions. This patch implements loop widening in the BPF verifier. It breaks down into these key areas: * **CFG Analysis:** It's using CFG analysis to tag `loop_head` and `backedge_ft`/`backedge_br`. * **Verifier (`verifier.c`):** This is where most of the magic happens: `cnum64_tighten_by_tnum` and `cnum32_tighten_by_tnum`, the SCC thresholds, `widen_reg`, `bpf_widen_loop_head`, `bpf_mark_loop_guard`, and these snapshot save/restore operations. I'm familiar with these concepts, but it's good to have them laid out. * **Fixups (`fixups.c`):** This is where `bpf_commit_loop_guards` and `add_loop_guard` come into play. These functions ultimately set the loop guards, and insert the `may_goto`/`bpf_throw` sequence, which I've seen before. * **States (`states.c`):** SCC Exit tracking and infinite loop detection are also part of this. Now, let's tackle those KMSAN criteria. Does this patch involve any kernel structures being sent to user space? No, not directly. It's all internal to the BPF verifier: bytecode analysis, register bounds tracking, and CFG modifications. No data is copied to user space, with the exception of the verifier log. The logging uses `verbose()` and `verbose_linfo()` and `bpf_vlog_reset`, which is all established verifier logging. But wait a minute, I should double check that `bpf_vlog_reset(&env->log, s->log_pos)` - that could be an exception. I'll need to verify exactly how it functions. |
| 46/3 | 2026/09/26 03:32 | tool | grepper |
0mArgs:{
"Expression": "bpf_vlog_reset",
"PathPrefix": "kernel/bpf/"
}Results: {
"Output": "kernel/bpf/liveness.c=477=static void print_instance(struct bpf_verifier_env *env, struct func_instance *instance)\n--\nkernel/bpf/liveness.c-510-\t\tif (!has_use)\nkernel/bpf/liveness.c:511:\t\t\tbpf_vlog_reset(\u0026env-\u003elog, pos);\nkernel/bpf/liveness.c-512-\t\tpos = env-\u003elog.end_pos;\n--\nkernel/bpf/liveness.c-521-\t\tif (!has_def)\nkernel/bpf/liveness.c:522:\t\t\tbpf_vlog_reset(\u0026env-\u003elog, has_use ? pos : insn_pos);\nkernel/bpf/liveness.c-523-\t\tverbose(env, \"\\n\");\n--\nkernel/bpf/liveness.c=1517=static void print_subprog_arg_access(struct bpf_verifier_env *env,\n--\nkernel/bpf/liveness.c-1563-\nkernel/bpf/liveness.c:1564:\t\tbpf_vlog_reset(\u0026env-\u003elog, env-\u003elog.end_pos - 1);\nkernel/bpf/liveness.c-1565-\t\tverbose(env, \" //\");\n--\nkernel/bpf/log.c=45=static void bpf_vlog_update_len_max(struct bpf_verifier_log *log, u32 add_len)\n--\nkernel/bpf/log.c-50-\t/* log-\u003elen_max could be larger than our current len due to\nkernel/bpf/log.c:51:\t * bpf_vlog_reset() calls, so we maintain the max of any length at any\nkernel/bpf/log.c-52-\t * previous point\n--\nkernel/bpf/log.c=60=void bpf_verifier_vlog(struct bpf_verifier_log *log, const char *fmt,\n--\nkernel/bpf/log.c-148-\nkernel/bpf/log.c:149:void bpf_vlog_reset(struct bpf_verifier_log *log, u64 new_pos)\nkernel/bpf/log.c-150-{\n--\nkernel/bpf/log.c=803=void print_insn_state(struct bpf_verifier_env *env, const struct bpf_verifier_state *vstate,\n--\nkernel/bpf/log.c-807-\t\t/* remove new line character */\nkernel/bpf/log.c:808:\t\tbpf_vlog_reset(\u0026env-\u003elog, env-\u003eprev_log_pos - 1);\nkernel/bpf/log.c-809-\t\tverbose(env, \"%*c;\", bpf_vlog_alignment(env-\u003eprev_insn_print_pos), ' ');\n--\nkernel/bpf/verifier.c=1792=static int pop_stack(struct bpf_verifier_env *env, int *prev_insn_idx,\n--\nkernel/bpf/verifier.c-1808-\tif (pop_log)\nkernel/bpf/verifier.c:1809:\t\tbpf_vlog_reset(\u0026env-\u003elog, head-\u003elog_pos);\nkernel/bpf/verifier.c-1810-\tif (insn_idx)\n--\nkernel/bpf/verifier.c=20371=static int do_check_common(struct bpf_verifier_env *env, int subprog)\n--\nkernel/bpf/verifier.c-20522-\t\tif (pop_log)\nkernel/bpf/verifier.c:20523:\t\t\tbpf_vlog_reset(\u0026env-\u003elog, 0);\nkernel/bpf/verifier.c-20524-\t\tbpf_diag_event_log_restore(env, 0);\n--\nkernel/bpf/verifier.c=20615=static void walk_snapshot_restore(struct bpf_verifier_env *env, struct walk_snapshot *s)\n--\nkernel/bpf/verifier.c-20650-\tif (!(env-\u003elog.level \u0026 BPF_LOG_LEVEL2))\nkernel/bpf/verifier.c:20651:\t\tbpf_vlog_reset(\u0026env-\u003elog, s-\u003elog_pos);\nkernel/bpf/verifier.c-20652-\tbpf_diag_event_log_restore(env, s-\u003ediag_pos);\n"
} |
| 47/3 | 2026/09/26 03:32 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 69880 output: 30 thoughts: 933 Thoughts: **Analyzing Potential Uninitialized Variable Issues in the Patch** Okay, so I'm diving into this patch with a focus on identifying potential vulnerabilities related to uninitialized variables, specifically based on the second criterion: conditional logic or branching depending on potentially uninitialized variables or struct fields. I see that the `bpf_vlog_reset` and `bpf_diag_event_log_restore` functions are just dealing with log position resets, so that's not where my focus needs to be. I need to meticulously examine each new function introduced or modified by this patch to ensure that all variables are properly initialized before being used, especially within any conditional statements or branching logic. * In `bpf_commit_loop_guards`, the loop counter `i` is correctly initialized, and the `aux[i]` array is handled safely through zero-initialization. * `guard_jump` is safe as `off` is initialized before being checked. * In `add_loop_guard`, I see that `jeq` is assigned before dereference. `skip` and `back` are checked before being dereferenced, so that's fine. `orig` is assigned safely. * `bpf_scc_mark_exit` does a `memset` on `callchain`, so initialization is fine here. * In `is_backedge`, `prev` is checked, and it's being compared safely. * In `loop_head_state`, `loop_head_guard`, and `bpf_is_state_visited` the variables seem to be used appropriately and correctly. It seems like the loop guard operations all handle initialization appropriately. The `widen_from` pointer is only dereferenced if the `loop_head` condition is true. * `tnum_member_ge`, `tnum_member_le` pass `tnum` by value, so no problems. * In `cnum64_tighten_by_tnum`, `cnum32_tighten_by_tnum` everything is initialized. * `cmp_widen_thr` has initialized `x` and `y`. * `scc_thresholds` initializes using `kvzalloc` or `kvzalloc_objs`. * In `thr_nearest`, `widen_pick`, `widen_smax`, `widen_smin`, `widen_umax`, `widen_umin`, variables are initialized as well. * In `widen_reg`, `umin` and `umax` and other variables are initialized, so the calculations should be safe. * In `bpf_widen_loop_head`, `passes` is initialized, and `w` is correctly populated with `scc_thresholds` which has already been verified for initialization. * Finally, in `cannot_throw`, the `range` variable is a local variable whose initialization is dependent on `return_retval_range` which should be examined to ensure that a return value is available. I need to make sure that the `return_retval_range` function, if it returns true, correctly initializes the `range` struct. In short, it appears that all the new variables and their usage within the patch are handled in a manner that avoids potential issues with uninitialized variables. The most important thing here is to confirm the initialization of `range` within `cannot_throw` by checking `return_retval_range`. |
| 48/3 | 2026/09/26 03:32 | tool | grepper |
0mArgs:{
"Expression": "return_retval_range",
"PathPrefix": "kernel/bpf/"
}Results: {
"Output": "kernel/bpf/verifier.c=8325=static bool program_returns_void(struct bpf_verifier_env *env);\nkernel/bpf/verifier.c:8326:static bool return_retval_range(struct bpf_verifier_env *env, struct bpf_retval_range *range);\nkernel/bpf/verifier.c-8327-\n--\nkernel/bpf/verifier.c=8329=static const char *cannot_throw(struct bpf_verifier_env *env, struct bpf_verifier_state *st)\n--\nkernel/bpf/verifier.c-8354-\t resolve_prog_type(env-\u003eprog) != BPF_PROG_TYPE_STRUCT_OPS \u0026\u0026\nkernel/bpf/verifier.c:8355:\t return_retval_range(env, \u0026range) \u0026\u0026 (range.minval \u003e 0 || range.maxval \u003c 0))\nkernel/bpf/verifier.c-8356-\t\treturn \"0 is not a valid return value\";\n--\nkernel/bpf/verifier.c=18196=static int check_ld_abs(struct bpf_verifier_env *env, struct bpf_insn *insn)\n--\nkernel/bpf/verifier.c-18284-\nkernel/bpf/verifier.c:18285:static bool return_retval_range(struct bpf_verifier_env *env, struct bpf_retval_range *range)\nkernel/bpf/verifier.c-18286-{\n--\nkernel/bpf/verifier.c=18396=static bool program_returns_void(struct bpf_verifier_env *env)\n--\nkernel/bpf/verifier.c-18402-\tcase BPF_PROG_TYPE_LSM:\nkernel/bpf/verifier.c:18403:\t\t/* See return_retval_range, for BPF_LSM_CGROUP can be 0 or 0-1 depending on hook. */\nkernel/bpf/verifier.c-18404-\t\tif (prog-\u003eexpected_attach_type != BPF_LSM_CGROUP \u0026\u0026\n--\nkernel/bpf/verifier.c=18428=static int check_return_code(struct bpf_verifier_env *env, int regno, const char *reg_name)\n--\nkernel/bpf/verifier.c-18483-\nkernel/bpf/verifier.c:18484:\tif (!return_retval_range(env, \u0026range))\nkernel/bpf/verifier.c-18485-\t\treturn 0;\n"
} |
| 49/3 | 2026/09/26 03:32 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 72248 output: 38 thoughts: 47 Thoughts: Okay, let's dive into this. Here's how I'd approach that snippet, considering I'm trying to ensure the BPF verifier behaves as expected: **Checking Return Value Range Assignment in the BPF Verifier** Alright, I need to zero in on `return_retval_range` within the BPF verifier, specifically around line 18285 in `kernel/bpf/verifier.c`. My primary concern is the consistent and correct setting of `minval` and `maxval` upon the function's successful completion. I need to verify that this critical assignment is *always* performed. This range calculation is fundamental to the verifier's ability to reason about the possible return values of BPF programs, which is, in turn, crucial for safety and optimization. If these aren't set correctly, the subsequent analysis could be flawed, leading to incorrect assumptions about program behavior and potentially opening up vulnerabilities or preventing valid programs from being loaded. My verification will have to focus on control flow within `return_retval_range`, to see if there are exit paths where `minval` and `maxval` might not be updated. I'll need to look at potential error conditions and ensure that, even in failure scenarios, the variables are appropriately managed, perhaps reset to indicate an invalid range, or marked as uninitialized. |
| 50/3 | 2026/09/26 03:32 | tool | read-file |
0mArgs:{
"File": "kernel/bpf/verifier.c",
"FirstLine": 18284,
"LineCount": 40
}Results: {
"Contents": "18284:\t\n18285:\tstatic bool return_retval_range(struct bpf_verifier_env *env, struct bpf_retval_range *range)\n18286:\t{\n18287:\t\tenum bpf_prog_type prog_type = resolve_prog_type(env-\u003eprog);\n18288:\t\n18289:\t\t/* Default return value range. */\n18290:\t\t*range = retval_range(0, 1);\n18291:\t\n18292:\t\tswitch (prog_type) {\n18293:\t\tcase BPF_PROG_TYPE_CGROUP_SOCK_ADDR:\n18294:\t\t\tswitch (env-\u003eprog-\u003eexpected_attach_type) {\n18295:\t\t\tcase BPF_CGROUP_UDP4_RECVMSG:\n18296:\t\t\tcase BPF_CGROUP_UDP6_RECVMSG:\n18297:\t\t\tcase BPF_CGROUP_UNIX_RECVMSG:\n18298:\t\t\tcase BPF_CGROUP_INET4_GETPEERNAME:\n18299:\t\t\tcase BPF_CGROUP_INET6_GETPEERNAME:\n18300:\t\t\tcase BPF_CGROUP_UNIX_GETPEERNAME:\n18301:\t\t\tcase BPF_CGROUP_INET4_GETSOCKNAME:\n18302:\t\t\tcase BPF_CGROUP_INET6_GETSOCKNAME:\n18303:\t\t\tcase BPF_CGROUP_UNIX_GETSOCKNAME:\n18304:\t\t\t\t*range = retval_range(1, 1);\n18305:\t\t\t\tbreak;\n18306:\t\t\tcase BPF_CGROUP_INET4_BIND:\n18307:\t\t\tcase BPF_CGROUP_INET6_BIND:\n18308:\t\t\t\t*range = retval_range(0, 3);\n18309:\t\t\t\tbreak;\n18310:\t\t\tdefault:\n18311:\t\t\t\tbreak;\n18312:\t\t\t}\n18313:\t\t\tbreak;\n18314:\t\tcase BPF_PROG_TYPE_CGROUP_SKB:\n18315:\t\t\tif (env-\u003eprog-\u003eexpected_attach_type == BPF_CGROUP_INET_EGRESS)\n18316:\t\t\t\t*range = retval_range(0, 3);\n18317:\t\t\tbreak;\n18318:\t\tcase BPF_PROG_TYPE_CGROUP_SOCK:\n18319:\t\tcase BPF_PROG_TYPE_SOCK_OPS:\n18320:\t\tcase BPF_PROG_TYPE_CGROUP_DEVICE:\n18321:\t\tcase BPF_PROG_TYPE_CGROUP_SYSCTL:\n18322:\t\tcase BPF_PROG_TYPE_CGROUP_SOCKOPT:\n18323:\t\t\tbreak;\n"
} |
| 51/3 | 2026/09/26 03:32 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 73386 output: 35 thoughts: 279 Thoughts: **Analyzing the State Management of `bpf_verifier_state`** Okay, so I'm diving into this `return_retval_range` function, and the first thing that jumps out is the initialization of `*range` with `retval_range(0, 1)`. That's standard practice, but it's always good to be mindful of initialization at the beginning of a function. Now, let's look deeper into what's happening with the state variables, focusing on how `bpf_verifier_state` instances are handled. I've got to ensure nothing is lost during any process. I'm now checking the `walk_snapshot` and, specifically, the `walk_snapshot_save` function. The `memset(s, 0, sizeof(*s));` call here is what I would expect for a snapshot – it makes sure everything is zeroed out before we copy the relevant fields. Good. And it seems all fields are either copied explicitly or allocated. So far, so good. But what about new fields, specifically `loop_passes`, which is added to `struct bpf_verifier_state`? That's what I really need to drill down on. Where are these `bpf_verifier_state` instances created and copied? Crucial. I've found it in `bpf_copy_verifier_state`. Okay, I see `dst_state->loop_passes = src->loop_passes;` in the `bpf_copy_verifier_state` function. The code explicitly copies the `loop_passes` field, which is great. So, there is no issue here. Now, to be really thorough, I need to know where `bpf_verifier_state` is allocated or initialized in the first place. I'm going to quickly grep for any `kzalloc.*bpf_verifier_state` or even just direct `bpf_verifier_state` allocation, to make sure everything gets initialized as it should. |
| 52/3 | 2026/09/26 03:32 | tool | grepper |
0mError:no matches Args: {
"Expression": "sizeof\\(struct bpf_verifier_state\\)",
"PathPrefix": "kernel/bpf/"
}Results: {
"error": "no matches"
} |
| 53/3 | 2026/09/26 03:32 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 74138 output: 33 thoughts: 24 Thoughts: Okay, here's my attempt at summarizing the thought process, tailored for an expert audience, and written in the first person: **Diving into the BPF Verifier State** Alright, I'm thinking I need to understand the inner workings of the BPF verifier a little better, specifically around how it tracks and manages the state of the eBPF program it's analyzing. My gut tells me that `bpf_verifier_state` is a likely candidate for the core structure that holds this information. So, my first move is to go straight into the kernel source, and I'm heading directly to `kernel/bpf/verifier.c`. I expect to find the definition, or at least a prominent use of, `bpf_verifier_state` in that file. That's my starting point for this exploration. Let's see what we can dig up. |
| 54/3 | 2026/09/26 03:32 | tool | grepper |
0mArgs:{
"Expression": "struct bpf_verifier_state \\*",
"PathPrefix": "kernel/bpf/"
}Results: {
"Output": "\nFull output is too long, showing 500 out of 555 lines.\nUse more precise expression if possible.\n\nkernel/bpf/backtrack.c-10-/* for any branch, call, exit record the history of jmps in the given state */\nkernel/bpf/backtrack.c:11:int bpf_push_jmp_history(struct bpf_verifier_env *env, struct bpf_verifier_state *cur,\nkernel/bpf/backtrack.c-12-\t\t\t int insn_flags, int spi, int frame, u64 linked_regs)\n--\nkernel/bpf/backtrack.c=64=static bool is_atomic_fetch_insn(const struct bpf_insn *insn)\n--\nkernel/bpf/backtrack.c-83- */\nkernel/bpf/backtrack.c:84:static int get_prev_insn_idx(struct bpf_verifier_state *st, int i,\nkernel/bpf/backtrack.c-85-\t\t\t u32 *history)\n--\nkernel/bpf/backtrack.c-104-\nkernel/bpf/backtrack.c:105:static struct bpf_jmp_history_entry *get_jmp_hist_entry(struct bpf_verifier_state *st,\nkernel/bpf/backtrack.c-106-\t\t\t\t\t\t u32 hist_end, int insn_idx)\n--\nkernel/bpf/backtrack.c=679=void bpf_mark_all_scalars_precise(struct bpf_verifier_env *env,\nkernel/bpf/backtrack.c:680:\t\t\t\t struct bpf_verifier_state *st)\nkernel/bpf/backtrack.c-681-{\n--\nkernel/bpf/backtrack.c=813=int bpf_mark_chain_precision(struct bpf_verifier_env *env,\nkernel/bpf/backtrack.c:814:\t\t\t struct bpf_verifier_state *starting_state,\nkernel/bpf/backtrack.c-815-\t\t\t int regno,\n--\nkernel/bpf/backtrack.c-817-{\nkernel/bpf/backtrack.c:818:\tstruct bpf_verifier_state *st = starting_state;\nkernel/bpf/backtrack.c-819-\tstruct backtrack_state *bt = \u0026env-\u003ebt;\n--\nkernel/bpf/diagnostics.c=402=void bpf_diag_event_log_restore(struct bpf_verifier_env *env, u64 log_pos)\n--\nkernel/bpf/diagnostics.c-430-\nkernel/bpf/diagnostics.c:431:u32 bpf_diag_irq_depth(const struct bpf_verifier_state *state)\nkernel/bpf/diagnostics.c-432-{\n--\nkernel/bpf/diagnostics.c=1580=static struct bpf_reg_state *target_to_reg(struct bpf_verifier_env *env,\n--\nkernel/bpf/diagnostics.c-1582-{\nkernel/bpf/diagnostics.c:1583:\tstruct bpf_verifier_state *vstate = env-\u003ecur_state;\nkernel/bpf/diagnostics.c-1584-\tstruct bpf_func_state *state;\n--\nkernel/bpf/diagnostics.c=1611=static bool reg_to_target(struct bpf_verifier_env *env, const struct bpf_reg_state *reg,\n--\nkernel/bpf/diagnostics.c-1613-{\nkernel/bpf/diagnostics.c:1614:\tstruct bpf_verifier_state *vstate = env-\u003ecur_state;\nkernel/bpf/diagnostics.c-1615-\tunsigned long addr = (unsigned long)reg;\n--\nkernel/bpf/diagnostics.h=56=void bpf_diag_event_log_restore(struct bpf_verifier_env *env, u64 log_pos);\nkernel/bpf/diagnostics.h:57:u32 bpf_diag_irq_depth(const struct bpf_verifier_state *state);\nkernel/bpf/diagnostics.h-58-void bpf_diag_free(struct bpf_verifier_env *env);\n--\nkernel/bpf/liveness.c=101=static struct func_instance *lookup_instance(struct bpf_verifier_env *env,\nkernel/bpf/liveness.c:102:\t\t\t\t\t struct bpf_verifier_state *st,\nkernel/bpf/liveness.c-103-\t\t\t\t\t u32 frameno)\n--\nkernel/bpf/liveness.c=330=static bool is_live_before(struct func_instance *instance, u32 insn_idx, u32 frameno, u32 half_spi)\n--\nkernel/bpf/liveness.c-337-\nkernel/bpf/liveness.c:338:int bpf_live_stack_query_init(struct bpf_verifier_env *env, struct bpf_verifier_state *st)\nkernel/bpf/liveness.c-339-{\n--\nkernel/bpf/log.c=624=static void print_reg_state(struct bpf_verifier_env *env,\n--\nkernel/bpf/log.c-699-\nkernel/bpf/log.c:700:void print_verifier_state(struct bpf_verifier_env *env, const struct bpf_verifier_state *vstate,\nkernel/bpf/log.c-701-\t\t\t u32 frameno, bool print_all)\n--\nkernel/bpf/log.c=797=u32 bpf_vlog_alignment(u32 pos)\n--\nkernel/bpf/log.c-802-\nkernel/bpf/log.c:803:void print_insn_state(struct bpf_verifier_env *env, const struct bpf_verifier_state *vstate,\nkernel/bpf/log.c-804-\t\t u32 frameno)\n--\nkernel/bpf/states.c=22=static void update_peak_states(struct bpf_verifier_env *env)\n--\nkernel/bpf/states.c-33- */\nkernel/bpf/states.c:34:static struct bpf_verifier_state_list *state_parent_as_list(struct bpf_verifier_state *st)\nkernel/bpf/states.c-35-{\n--\nkernel/bpf/states.c=41=static bool incomplete_read_marks(struct bpf_verifier_env *env,\nkernel/bpf/states.c:42:\t\t\t\t struct bpf_verifier_state *st);\nkernel/bpf/states.c-43-\n--\nkernel/bpf/states.c=74=static bool compute_scc_callchain(struct bpf_verifier_env *env,\nkernel/bpf/states.c:75:\t\t\t\t struct bpf_verifier_state *st,\nkernel/bpf/states.c-76-\t\t\t\t struct bpf_scc_callchain *callchain)\n--\nkernel/bpf/states.c=140=static char *format_callchain(struct bpf_verifier_env *env, struct bpf_scc_callchain *callchain)\n--\nkernel/bpf/states.c-159- */\nkernel/bpf/states.c:160:static int maybe_enter_scc(struct bpf_verifier_env *env, struct bpf_verifier_state *st)\nkernel/bpf/states.c-161-{\n--\nkernel/bpf/states.c=180=static int propagate_backedges(struct bpf_verifier_env *env, struct bpf_scc_visit *visit);\n--\nkernel/bpf/states.c-185- */\nkernel/bpf/states.c:186:static int maybe_exit_scc(struct bpf_verifier_env *env, struct bpf_verifier_state *st)\nkernel/bpf/states.c-187-{\n--\nkernel/bpf/states.c-239- */\nkernel/bpf/states.c:240:void bpf_scc_mark_exit(struct bpf_verifier_env *env, struct bpf_verifier_state *st, int insn_idx)\nkernel/bpf/states.c-241-{\n--\nkernel/bpf/states.c=264=static int add_scc_backedge(struct bpf_verifier_env *env,\nkernel/bpf/states.c:265:\t\t\t struct bpf_verifier_state *st,\nkernel/bpf/states.c-266-\t\t\t struct bpf_scc_backedge *backedge)\n--\nkernel/bpf/states.c=298=static bool incomplete_read_marks(struct bpf_verifier_env *env,\nkernel/bpf/states.c:299:\t\t\t\t struct bpf_verifier_state *st)\nkernel/bpf/states.c-300-{\n--\nkernel/bpf/states.c-311-\nkernel/bpf/states.c:312:int bpf_update_branch_counts(struct bpf_verifier_env *env, struct bpf_verifier_state *st)\nkernel/bpf/states.c-313-{\nkernel/bpf/states.c-314-\tstruct bpf_verifier_state_list *sl = NULL, *parent_sl;\nkernel/bpf/states.c:315:\tstruct bpf_verifier_state *parent;\nkernel/bpf/states.c-316-\tint err;\n--\nkernel/bpf/states.c=510=static int clean_verifier_state(struct bpf_verifier_env *env,\nkernel/bpf/states.c:511:\t\t\t\t struct bpf_verifier_state *st)\nkernel/bpf/states.c-512-{\n--\nkernel/bpf/states.c=883=static bool stack_arg_safe(struct bpf_verifier_env *env, struct bpf_func_state *old,\n--\nkernel/bpf/states.c-904-\nkernel/bpf/states.c:905:static bool refsafe(struct bpf_verifier_state *old, struct bpf_verifier_state *cur,\nkernel/bpf/states.c-906-\t\t struct bpf_idmap *idmap)\n--\nkernel/bpf/states.c=1016=static bool states_equal(struct bpf_verifier_env *env,\nkernel/bpf/states.c:1017:\t\t\t struct bpf_verifier_state *old,\nkernel/bpf/states.c:1018:\t\t\t struct bpf_verifier_state *cur,\nkernel/bpf/states.c-1019-\t\t\t enum exact_level exact)\n--\nkernel/bpf/states.c=1057=static int propagate_precision(struct bpf_verifier_env *env,\nkernel/bpf/states.c:1058:\t\t\t const struct bpf_verifier_state *old,\nkernel/bpf/states.c:1059:\t\t\t struct bpf_verifier_state *cur,\nkernel/bpf/states.c-1060-\t\t\t bool *changed)\n--\nkernel/bpf/states.c=1121=static int propagate_backedges(struct bpf_verifier_env *env, struct bpf_scc_visit *visit)\n--\nkernel/bpf/states.c-1123-\tstruct bpf_scc_backedge *backedge;\nkernel/bpf/states.c:1124:\tstruct bpf_verifier_state *st;\nkernel/bpf/states.c-1125-\tbool changed;\n--\nkernel/bpf/states.c=1151=static bool is_backedge(struct bpf_verifier_env *env, int insn_idx)\n--\nkernel/bpf/states.c-1167-\nkernel/bpf/states.c:1168:static bool iter_active_depths_differ(struct bpf_verifier_state *old,\nkernel/bpf/states.c:1169:\t\t\t\t struct bpf_verifier_state *cur);\nkernel/bpf/states.c-1170-\nkernel/bpf/states.c-1171-/* The state of this walk that was the last to get to loop head @insn_idx. */\nkernel/bpf/states.c:1172:static struct bpf_verifier_state *loop_head_state(struct bpf_verifier_env *env, int insn_idx)\nkernel/bpf/states.c-1173-{\nkernel/bpf/states.c:1174:\tstruct bpf_verifier_state *cur = env-\u003ecur_state;\nkernel/bpf/states.c-1175-\tstruct bpf_verifier_state_list *sl;\n--\nkernel/bpf/states.c=1195=static bool loop_head_guard(struct bpf_verifier_env *env, int insn_idx,\nkernel/bpf/states.c:1196:\t\t\t struct bpf_verifier_state *old, struct bpf_verifier_state *cur)\nkernel/bpf/states.c-1197-{\n--\nkernel/bpf/states.c-1205-\nkernel/bpf/states.c:1206:static bool states_maybe_looping(struct bpf_verifier_state *old,\nkernel/bpf/states.c:1207:\t\t\t\t struct bpf_verifier_state *cur)\nkernel/bpf/states.c-1208-{\n--\nkernel/bpf/states.c-1281- */\nkernel/bpf/states.c:1282:static bool iter_active_depths_differ(struct bpf_verifier_state *old, struct bpf_verifier_state *cur)\nkernel/bpf/states.c-1283-{\n--\nkernel/bpf/states.c-1305-\nkernel/bpf/states.c:1306:static void mark_all_scalars_imprecise(struct bpf_verifier_env *env, struct bpf_verifier_state *st)\nkernel/bpf/states.c-1307-{\n--\nkernel/bpf/states.c=1331=int bpf_is_state_visited(struct bpf_verifier_env *env, int insn_idx)\n--\nkernel/bpf/states.c-1334-\tstruct bpf_verifier_state_list *sl;\nkernel/bpf/states.c:1335:\tstruct bpf_verifier_state *cur = env-\u003ecur_state, *new, *widen_from = NULL;\nkernel/bpf/states.c-1336-\tbool loop_head = env-\u003ewiden_loops \u0026\u0026 env-\u003einsn_aux_data[insn_idx].loop_head;\n--\nkernel/bpf/verifier.c=208=static int acquire_reference(struct bpf_verifier_env *env, int insn_idx, int parent_id);\nkernel/bpf/verifier.c:209:static int __release_reference_nomark(struct bpf_verifier_state *state, int id);\nkernel/bpf/verifier.c-210-static int release_reference_nomark(struct bpf_verifier_env *env, int id);\n--\nkernel/bpf/verifier.c=1362=static void *realloc_array(void *arr, size_t old_n, size_t new_n, size_t size)\n--\nkernel/bpf/verifier.c-1384-\nkernel/bpf/verifier.c:1385:static int copy_reference_state(struct bpf_verifier_state *dst, const struct bpf_verifier_state *src)\nkernel/bpf/verifier.c-1386-{\n--\nkernel/bpf/verifier.c=1402=static int copy_stack_state(struct bpf_func_state *dst, const struct bpf_func_state *src)\n--\nkernel/bpf/verifier.c-1426-\nkernel/bpf/verifier.c:1427:static int resize_reference_state(struct bpf_verifier_state *state, size_t n)\nkernel/bpf/verifier.c-1428-{\n--\nkernel/bpf/verifier.c=1487=static struct bpf_reference_state *acquire_reference_state(struct bpf_verifier_env *env, int insn_idx)\nkernel/bpf/verifier.c-1488-{\nkernel/bpf/verifier.c:1489:\tstruct bpf_verifier_state *state = env-\u003ecur_state;\nkernel/bpf/verifier.c-1490-\tint new_ofs = state-\u003eacquired_refs;\n--\nkernel/bpf/verifier.c=1515=static int acquire_lock_state(struct bpf_verifier_env *env, int insn_idx, enum ref_state_type type,\n--\nkernel/bpf/verifier.c-1517-{\nkernel/bpf/verifier.c:1518:\tstruct bpf_verifier_state *state = env-\u003ecur_state;\nkernel/bpf/verifier.c-1519-\tstruct bpf_reference_state *s;\n--\nkernel/bpf/verifier.c=1536=static int acquire_irq_state(struct bpf_verifier_env *env, int insn_idx)\nkernel/bpf/verifier.c-1537-{\nkernel/bpf/verifier.c:1538:\tstruct bpf_verifier_state *state = env-\u003ecur_state;\nkernel/bpf/verifier.c-1539-\tstruct bpf_reference_state *s;\n--\nkernel/bpf/verifier.c-1552-\nkernel/bpf/verifier.c:1553:static void release_reference_state(struct bpf_verifier_state *state, int idx)\nkernel/bpf/verifier.c-1554-{\n--\nkernel/bpf/verifier.c-1571-\nkernel/bpf/verifier.c:1572:static bool find_reference_state(struct bpf_verifier_state *state, int id)\nkernel/bpf/verifier.c-1573-{\n--\nkernel/bpf/verifier.c=1591=static int release_lock_state(struct bpf_verifier_env *env, int type, int id, void *ptr)\nkernel/bpf/verifier.c-1592-{\nkernel/bpf/verifier.c:1593:\tstruct bpf_verifier_state *state = env-\u003ecur_state;\nkernel/bpf/verifier.c-1594-\tvoid *prev_ptr = NULL;\n--\nkernel/bpf/verifier.c=1618=static int release_irq_state(struct bpf_verifier_env *env, int id)\nkernel/bpf/verifier.c-1619-{\nkernel/bpf/verifier.c:1620:\tstruct bpf_verifier_state *state = env-\u003ecur_state;\nkernel/bpf/verifier.c-1621-\tu32 prev_id = 0;\n--\nkernel/bpf/verifier.c-1642-\nkernel/bpf/verifier.c:1643:static struct bpf_reference_state *find_lock_state(struct bpf_verifier_state *state, enum ref_state_type type,\nkernel/bpf/verifier.c-1644-\t\t\t\t\t\t int id, void *ptr)\n--\nkernel/bpf/verifier.c=1660=static void free_func_state(struct bpf_func_state *state)\n--\nkernel/bpf/verifier.c-1668-\nkernel/bpf/verifier.c:1669:void bpf_clear_jmp_history(struct bpf_verifier_state *state)\nkernel/bpf/verifier.c-1670-{\n--\nkernel/bpf/verifier.c-1675-\nkernel/bpf/verifier.c:1676:void bpf_free_verifier_state(struct bpf_verifier_state *state,\nkernel/bpf/verifier.c-1677-\t\t\t bool free_self)\n--\nkernel/bpf/verifier.c=1694=static int copy_func_state(struct bpf_func_state *dst,\n--\nkernel/bpf/verifier.c-1702-\nkernel/bpf/verifier.c:1703:int bpf_copy_verifier_state(struct bpf_verifier_state *dst_state,\nkernel/bpf/verifier.c:1704:\t\t\t const struct bpf_verifier_state *src)\nkernel/bpf/verifier.c-1705-{\n--\nkernel/bpf/verifier.c=1758=struct list_head *bpf_explored_state(struct bpf_verifier_env *env, int idx)\nkernel/bpf/verifier.c-1759-{\nkernel/bpf/verifier.c:1760:\tstruct bpf_verifier_state *cur = env-\u003ecur_state;\nkernel/bpf/verifier.c-1761-\tstruct bpf_func_state *state = cur-\u003eframe[cur-\u003ecurframe];\n--\nkernel/bpf/verifier.c-1765-\nkernel/bpf/verifier.c:1766:static bool same_callsites(struct bpf_verifier_state *a, struct bpf_verifier_state *b)\nkernel/bpf/verifier.c-1767-{\n--\nkernel/bpf/verifier.c=1792=static int pop_stack(struct bpf_verifier_env *env, int *prev_insn_idx,\n--\nkernel/bpf/verifier.c-1794-{\nkernel/bpf/verifier.c:1795:\tstruct bpf_verifier_state *cur = env-\u003ecur_state;\nkernel/bpf/verifier.c-1796-\tstruct bpf_verifier_stack_elem *elem, *head = env-\u003ehead;\n--\nkernel/bpf/verifier.c=1822=static bool error_recoverable_with_nospec(int err)\n--\nkernel/bpf/verifier.c-1833-\nkernel/bpf/verifier.c:1834:static struct bpf_verifier_state *push_stack(struct bpf_verifier_env *env,\nkernel/bpf/verifier.c-1835-\t\t\t\t\t int insn_idx, int prev_insn_idx,\n--\nkernel/bpf/verifier.c-1837-{\nkernel/bpf/verifier.c:1838:\tstruct bpf_verifier_state *cur = env-\u003ecur_state;\nkernel/bpf/verifier.c-1839-\tstruct bpf_verifier_stack_elem *elem;\n--\nkernel/bpf/verifier.c=2418=static void init_func_state(struct bpf_verifier_env *env,\n--\nkernel/bpf/verifier.c-2431-/* Similar to push_stack(), but for async callbacks */\nkernel/bpf/verifier.c:2432:static struct bpf_verifier_state *push_async_cb(struct bpf_verifier_env *env,\nkernel/bpf/verifier.c-2433-\t\t\t\t\t\tint insn_idx, int prev_insn_idx,\n--\nkernel/bpf/verifier.c=3350=static int check_reg_arg(struct bpf_verifier_env *env, u32 regno,\n--\nkernel/bpf/verifier.c-3352-{\nkernel/bpf/verifier.c:3353:\tstruct bpf_verifier_state *vstate = env-\u003ecur_state;\nkernel/bpf/verifier.c-3354-\tstruct bpf_func_state *state = vstate-\u003eframe[vstate-\u003ecurframe];\n--\nkernel/bpf/verifier.c=3525=static int mark_chain_precision_batch(struct bpf_verifier_env *env,\nkernel/bpf/verifier.c:3526:\t\t\t\t struct bpf_verifier_state *starting_state)\nkernel/bpf/verifier.c-3527-{\n--\nkernel/bpf/verifier.c=3930=static int mark_reg_stack_read(struct bpf_verifier_env *env,\n--\nkernel/bpf/verifier.c-3934-{\nkernel/bpf/verifier.c:3935:\tstruct bpf_verifier_state *vstate = env-\u003ecur_state;\nkernel/bpf/verifier.c-3936-\tstruct bpf_func_state *state = vstate-\u003eframe[vstate-\u003ecurframe];\n--\nkernel/bpf/verifier.c=4000=static int check_stack_read_fixed_off(struct bpf_verifier_env *env,\n--\nkernel/bpf/verifier.c-4004-{\nkernel/bpf/verifier.c:4005:\tstruct bpf_verifier_state *vstate = env-\u003ecur_state;\nkernel/bpf/verifier.c-4006-\tstruct bpf_func_state *state = vstate-\u003eframe[vstate-\u003ecurframe];\n--\nkernel/bpf/verifier.c=4349=static int check_stack_arg_read(struct bpf_verifier_env *env, struct bpf_func_state *state,\n--\nkernel/bpf/verifier.c-4352-\tstruct bpf_subprog_info *subprog = \u0026env-\u003esubprog_info[state-\u003esubprogno];\nkernel/bpf/verifier.c:4353:\tstruct bpf_verifier_state *vstate = env-\u003ecur_state;\nkernel/bpf/verifier.c-4354-\tint spi = off / BPF_REG_SIZE - 1;\n--\nkernel/bpf/verifier.c=6796=static int check_load_mem(struct bpf_verifier_env *env, struct bpf_insn *insn,\n--\nkernel/bpf/verifier.c-6799-{\nkernel/bpf/verifier.c:6800:\tstruct bpf_verifier_state *vstate = env-\u003ecur_state;\nkernel/bpf/verifier.c-6801-\tstruct bpf_func_state *state = vstate-\u003eframe[vstate-\u003ecurframe];\n--\nkernel/bpf/verifier.c=6843=static int check_store_reg(struct bpf_verifier_env *env, struct bpf_insn *insn,\n--\nkernel/bpf/verifier.c-6845-{\nkernel/bpf/verifier.c:6846:\tstruct bpf_verifier_state *vstate = env-\u003ecur_state;\nkernel/bpf/verifier.c-6847-\tstruct bpf_func_state *state = vstate-\u003eframe[vstate-\u003ecurframe];\n--\nkernel/bpf/verifier.c=7473=static int process_spin_lock(struct bpf_verifier_env *env, struct bpf_reg_state *reg, argno_t argno, int flags)\n--\nkernel/bpf/verifier.c-7476-\tconst char *lock_str = is_res_lock ? \"bpf_res_spin\" : \"bpf_spin\";\nkernel/bpf/verifier.c:7477:\tstruct bpf_verifier_state *cur = env-\u003ecur_state;\nkernel/bpf/verifier.c-7478-\tstruct bpf_reference_state *lock;\n--\nkernel/bpf/verifier.c=7910=static int process_iter_arg(struct bpf_verifier_env *env, struct bpf_reg_state *reg, argno_t argno, int insn_idx,\n--\nkernel/bpf/verifier.c-8019- */\nkernel/bpf/verifier.c:8020:static struct bpf_verifier_state *find_prev_entry(struct bpf_verifier_env *env,\nkernel/bpf/verifier.c:8021:\t\t\t\t\t\t struct bpf_verifier_state *cur,\nkernel/bpf/verifier.c-8022-\t\t\t\t\t\t int insn_idx)\n--\nkernel/bpf/verifier.c-8024-\tstruct bpf_verifier_state_list *sl;\nkernel/bpf/verifier.c:8025:\tstruct bpf_verifier_state *st;\nkernel/bpf/verifier.c-8026-\tstruct list_head *pos, *head;\n--\nkernel/bpf/verifier.c=8219=static void widen_reg(const struct widen_ctx *w, const struct bpf_reg_state *old,\n--\nkernel/bpf/verifier.c-8272-\nkernel/bpf/verifier.c:8273:bool bpf_same_loop(struct bpf_verifier_state *old, struct bpf_verifier_state *cur)\nkernel/bpf/verifier.c-8274-{\n--\nkernel/bpf/verifier.c=8285=int bpf_widen_loop_head(struct bpf_verifier_env *env, int insn_idx, bool backedge,\nkernel/bpf/verifier.c:8286:\t\t\tstruct bpf_verifier_state *old, struct bpf_verifier_state *cur)\nkernel/bpf/verifier.c-8287-{\n--\nkernel/bpf/verifier.c=8326=static bool return_retval_range(struct bpf_verifier_env *env, struct bpf_retval_range *range);\n--\nkernel/bpf/verifier.c-8328-/* Why bpf_throw() cannot be called in @st, NULL if it can. */\nkernel/bpf/verifier.c:8329:static const char *cannot_throw(struct bpf_verifier_env *env, struct bpf_verifier_state *st)\nkernel/bpf/verifier.c-8330-{\n--\nkernel/bpf/verifier.c-8365- */\nkernel/bpf/verifier.c:8366:bool bpf_mark_loop_guard(struct bpf_verifier_env *env, struct bpf_verifier_state *cur)\nkernel/bpf/verifier.c-8367-{\n--\nkernel/bpf/verifier.c=8414=static int widen_imprecise_scalars(struct bpf_verifier_env *env,\nkernel/bpf/verifier.c:8415:\t\t\t\t struct bpf_verifier_state *old,\nkernel/bpf/verifier.c:8416:\t\t\t\t struct bpf_verifier_state *cur)\nkernel/bpf/verifier.c-8417-{\n--\nkernel/bpf/verifier.c-8444-\nkernel/bpf/verifier.c:8445:static struct bpf_reg_state *get_iter_from_state(struct bpf_verifier_state *cur_st,\nkernel/bpf/verifier.c-8446-\t\t\t\t\t\t struct bpf_call_arg_meta *meta)\n--\nkernel/bpf/verifier.c=8532=static int process_iter_next_call(struct bpf_verifier_env *env, int insn_idx,\n--\nkernel/bpf/verifier.c-8534-{\nkernel/bpf/verifier.c:8535:\tstruct bpf_verifier_state *cur_st = env-\u003ecur_state, *queued_st, *prev_st;\nkernel/bpf/verifier.c-8536-\tstruct bpf_func_state *cur_fr = cur_st-\u003eframe[cur_st-\u003ecurframe], *queued_fr;\n--\nkernel/bpf/verifier.c=10488=enum {\n--\nkernel/bpf/verifier.c-10492-\nkernel/bpf/verifier.c:10493:static void mark_pkt_end(struct bpf_verifier_state *vstate, int regn, bool range_open)\nkernel/bpf/verifier.c-10494-{\n--\nkernel/bpf/verifier.c-10513-\nkernel/bpf/verifier.c:10514:static int __release_reference_nomark(struct bpf_verifier_state *state, int id)\nkernel/bpf/verifier.c-10515-{\n--\nkernel/bpf/verifier.c=10566=static int release_reference(struct bpf_verifier_env *env, int id)\n--\nkernel/bpf/verifier.c-10568-\tu32 mask = (1 \u003c\u003c STACK_SPILL) | (1 \u003c\u003c STACK_DYNPTR);\nkernel/bpf/verifier.c:10569:\tstruct bpf_verifier_state *vstate = env-\u003ecur_state;\nkernel/bpf/verifier.c-10570-\tstruct bpf_idmap *idstack = \u0026env-\u003eidmap_scratch;\n--\nkernel/bpf/verifier.c=10727=static int setup_func_entry(struct bpf_verifier_env *env, int subprog, int callsite,\nkernel/bpf/verifier.c-10728-\t\t\t set_callee_state_fn set_callee_state_cb,\nkernel/bpf/verifier.c:10729:\t\t\t struct bpf_verifier_state *state)\nkernel/bpf/verifier.c-10730-{\n--\nkernel/bpf/verifier.c=10943=static int push_callback_call(struct bpf_verifier_env *env, struct bpf_insn *insn,\n--\nkernel/bpf/verifier.c-10946-{\nkernel/bpf/verifier.c:10947:\tstruct bpf_verifier_state *state = env-\u003ecur_state, *callback_state;\nkernel/bpf/verifier.c-10948-\tstruct bpf_func_state *caller, *callee;\n--\nkernel/bpf/verifier.c-10973-\tif (bpf_is_async_callback_calling_insn(insn)) {\nkernel/bpf/verifier.c:10974:\t\tstruct bpf_verifier_state *async_cb;\nkernel/bpf/verifier.c-10975-\n--\nkernel/bpf/verifier.c=11015=static int check_func_call(struct bpf_verifier_env *env, struct bpf_insn *insn,\n--\nkernel/bpf/verifier.c-11017-{\nkernel/bpf/verifier.c:11018:\tstruct bpf_verifier_state *state = env-\u003ecur_state;\nkernel/bpf/verifier.c-11019-\tstruct bpf_subprog_info *caller_info;\n--\nkernel/bpf/verifier.c-11095-\t\tif (env-\u003esubprog_info[subprog].might_throw) {\nkernel/bpf/verifier.c:11096:\t\t\tstruct bpf_verifier_state *branch;\nkernel/bpf/verifier.c-11097-\n--\nkernel/bpf/verifier.c=11448=static void account_current_path(struct bpf_verifier_env *env)\nkernel/bpf/verifier.c-11449-{\nkernel/bpf/verifier.c:11450:\tstruct bpf_verifier_state *state = env-\u003ecur_state;\nkernel/bpf/verifier.c-11451-\tint frame;\n--\nkernel/bpf/verifier.c=11463=static bool in_rbtree_lock_required_cb(struct bpf_verifier_env *env)\nkernel/bpf/verifier.c-11464-{\nkernel/bpf/verifier.c:11465:\tstruct bpf_verifier_state *state = env-\u003ecur_state;\nkernel/bpf/verifier.c-11466-\tstruct bpf_insn *insn = env-\u003eprog-\u003einsnsi;\n--\nkernel/bpf/verifier.c=11492=static int prepare_func_exit(struct bpf_verifier_env *env, int *insn_idx)\nkernel/bpf/verifier.c-11493-{\nkernel/bpf/verifier.c:11494:\tstruct bpf_verifier_state *state = env-\u003ecur_state, *prev_st;\nkernel/bpf/verifier.c-11495-\tstruct bpf_func_state *caller, *callee;\n--\nkernel/bpf/verifier.c=11736=static int check_reference_leak(struct bpf_verifier_env *env, bool exception_exit)\nkernel/bpf/verifier.c-11737-{\nkernel/bpf/verifier.c:11738:\tstruct bpf_verifier_state *state = env-\u003ecur_state;\nkernel/bpf/verifier.c-11739-\tenum bpf_prog_type type = resolve_prog_type(env-\u003eprog);\n--\nkernel/bpf/verifier.c=11983=static int check_helper_call(struct bpf_verifier_env *env, struct bpf_insn *insn,\n--\nkernel/bpf/verifier.c-12390-\t find_reference_state(env-\u003ecur_state, meta.ref_obj.id)) {\nkernel/bpf/verifier.c:12391:\t\tstruct bpf_verifier_state *branch;\nkernel/bpf/verifier.c-12392-\t\tstruct bpf_reg_state *r0;\n--\nkernel/bpf/verifier.c-12471-\t\tif (env-\u003ecur_state-\u003ecurframe) {\nkernel/bpf/verifier.c:12472:\t\t\tstruct bpf_verifier_state *branch;\nkernel/bpf/verifier.c-12473-\n--\nkernel/bpf/verifier.c=14595=static int check_kfunc_call(struct bpf_verifier_env *env, struct bpf_insn *insn,\n--\nkernel/bpf/verifier.c-14641-\t insn-\u003eimm == special_kfunc_list[KF_bpf_res_spin_lock_irqsave])) {\nkernel/bpf/verifier.c:14642:\t\tstruct bpf_verifier_state *branch;\nkernel/bpf/verifier.c-14643-\t\tstruct bpf_reg_state *regs;\n--\nkernel/bpf/verifier.c=15215=static int sanitize_speculative_path(struct bpf_verifier_env *env,\n--\nkernel/bpf/verifier.c-15218-{\nkernel/bpf/verifier.c:15219:\tstruct bpf_verifier_state *branch;\nkernel/bpf/verifier.c-15220-\tstruct bpf_reg_state *regs;\n--\nkernel/bpf/verifier.c=15235=static int sanitize_ptr_alu(struct bpf_verifier_env *env,\n--\nkernel/bpf/verifier.c-15243-\tstruct bpf_insn_aux_data *aux = commit_window ? cur_aux(env) : \u0026info-\u003eaux;\nkernel/bpf/verifier.c:15244:\tstruct bpf_verifier_state *vstate = env-\u003ecur_state;\nkernel/bpf/verifier.c-15245-\tbool off_is_imm = tnum_is_const(off_reg-\u003evar_off);\n--\nkernel/bpf/verifier.c=15331=static void sanitize_mark_insn_seen(struct bpf_verifier_env *env)\nkernel/bpf/verifier.c-15332-{\nkernel/bpf/verifier.c:15333:\tstruct bpf_verifier_state *vstate = env-\u003ecur_state;\nkernel/bpf/verifier.c-15334-\n--\nkernel/bpf/verifier.c=15448=static int adjust_ptr_min_max_vals(struct bpf_verifier_env *env, struct bpf_insn *insn,\n--\nkernel/bpf/verifier.c-15451-{\nkernel/bpf/verifier.c:15452:\tstruct bpf_verifier_state *vstate = env-\u003ecur_state;\nkernel/bpf/verifier.c-15453-\tstruct bpf_func_state *state = vstate-\u003eframe[vstate-\u003ecurframe];\n--\nkernel/bpf/verifier.c=16416=static int maybe_fork_scalars(struct bpf_verifier_env *env, struct bpf_insn *insn,\n--\nkernel/bpf/verifier.c-16418-{\nkernel/bpf/verifier.c:16419:\tstruct bpf_verifier_state *branch;\nkernel/bpf/verifier.c-16420-\tstruct bpf_reg_state *regs;\n--\nkernel/bpf/verifier.c=16607=static int adjust_reg_min_max_vals(struct bpf_verifier_env *env,\n--\nkernel/bpf/verifier.c-16609-{\nkernel/bpf/verifier.c:16610:\tstruct bpf_verifier_state *vstate = env-\u003ecur_state;\nkernel/bpf/verifier.c-16611-\tstruct bpf_func_state *state = vstate-\u003eframe[vstate-\u003ecurframe];\n--\nkernel/bpf/verifier.c=16774=static int check_alu_op(struct bpf_verifier_env *env, struct bpf_insn *insn)\n--\nkernel/bpf/verifier.c-16962-\nkernel/bpf/verifier.c:16963:static void find_good_pkt_pointers(struct bpf_verifier_state *vstate,\nkernel/bpf/verifier.c-16964-\t\t\t\t struct bpf_reg_state *dst_reg,\n--\nkernel/bpf/verifier.c=17530=static void mark_ptr_or_null_reg(struct bpf_func_state *state,\n--\nkernel/bpf/verifier.c-17569- */\nkernel/bpf/verifier.c:17570:static void mark_ptr_or_null_regs(struct bpf_verifier_state *vstate, u32 regno,\nkernel/bpf/verifier.c-17571-\t\t\t\t bool is_null)\n--\nkernel/bpf/verifier.c=17589=static bool try_match_pkt_pointers(const struct bpf_insn *insn,\n--\nkernel/bpf/verifier.c-17591-\t\t\t\t struct bpf_reg_state *src_reg,\nkernel/bpf/verifier.c:17592:\t\t\t\t struct bpf_verifier_state *this_branch,\nkernel/bpf/verifier.c:17593:\t\t\t\t struct bpf_verifier_state *other_branch)\nkernel/bpf/verifier.c-17594-{\n\n"
} |
| 55/3 | 2026/09/26 03:32 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 85218 output: 308 thoughts: 3287 Thoughts: **KMSAN Needs Analysis for BPF Verifier Loop Widening** Okay, so I've been digging into this patch, focusing on whether we need to turn on KMSAN. This patch introduces loop widening in the BPF verifier and adds guards when the bounds can't be statically proven. My main concern is ensuring no uninitialized memory gets leaked or used. I see that the `bpf_verifier_state` is initialized properly with `kzalloc` and copying. The code I looked at, especially concerning `loop_passes`, seems solid in its initialization. Also, all the complex data structures (like `walk_snapshot`, `env->scc_thrs`, `env->scc_converged`, `buf`, `callchain`) that are allocated are getting zeroed out using `memset`, `kvzalloc`, `kvmemdup`, and `kmemdup`, so I'm not seeing any immediate red flags there. This includes the `insn_aux`, `subprogs`, `prog`, and `func_aux` members of the `walk_snapshot` structure. I made sure to double-check `add_loop_guard` and `bpf_scc_mark_exit`, and all variables are initialized correctly. Also, the tightening of scalar ranges appears safe, and I reviewed the `walk_snapshot` save/restore logic to be sure. My thought process also involved checking for potential side effects from loop widening and whether the BPF verifier or the programs it verifies could read uninitialized memory. I've concluded that the verifier itself doesn't read uninitialized memory and that the kernel handles BPF stack allocations, and KMSAN doesn't instrument BPF JIT code. Also, the verifier will reject out-of-bounds accesses to memory, and any errors would be caught by KASAN. Furthermore, this change doesn't send anything to user-space, which is good. So, thinking about the KMSAN guidelines, this patch doesn't: 1) send kernel structures to userspace, 2) have conditional logic that depends on uninitialized variables, 3) allocate complex data structures that would result in uninitialized fields being read, or 4) introduce bounds checks that could access uninitialized bytes. The patch's primary risk lies in logic errors, potential out-of-bounds access, or state corruption, all of which KASAN, LOCKDEP, and the other standard debuggers will handle. We should really only use KMSAN if there's *no* other way to detect a potential bug, and here, KASAN and standard sanitizers will handle anything this patch could cause. Therefore, because this patch doesn't introduce any risk of uninitialized memory use or leaks, and all stack/heap structures touched or introduced by the patch are fully zeroed or initialized, I believe that `NeedsKMSAN` should be set to `false`. I am confident in this decision. |
| 56/3 | 2026/09/26 03:32 | tool | set-results |
0mArgs:{
"KMSANReasoning": "The patch series implements loop widening in the BPF verifier and runtime loop guards (may_goto + bpf_throw fixups) for loops that converge with widened states.\n\nAnalysis of memory safety and sanitizer applicability:\n1. No Kernel-to-User Info-Leaks: The changes operate purely within the internal BPF verifier pipeline during program verification and instruction fixups. No kernel structures or memory buffers are copied to user space.\n2. Structure Initialization: All newly allocated data structures (such as `walk_snapshot`, `scc_converged`, `scc_thrs`, and temporary instruction patch buffers) are explicitly zero-initialized using `memset`, `kvzalloc`, or `kvmemdup` from initialized data.\n3. Control Flow and Branching: Conditional branches rely only on fully initialized local or struct variables; no uninitialized struct fields or stack variables are evaluated.\n4. KASAN vs KMSAN: The primary risks associated with these changes are verifier logic errors, incorrect jump/instruction offset calculations, instruction buffer overflow, or potential state tracking use-after-free bugs. All of these potential failure modes are fully covered by KASAN, UBSAN, and standard kernel debugging facilities. No uninitialized memory usage or leak risks specific to KMSAN are introduced.\n\nTherefore, a dedicated KMSAN fuzzing session is not warranted.",
"NeedsKMSAN": false
}Results: {
"KMSANReasoning": "The patch series implements loop widening in the BPF verifier and runtime loop guards (may_goto + bpf_throw fixups) for loops that converge with widened states.\n\nAnalysis of memory safety and sanitizer applicability:\n1. No Kernel-to-User Info-Leaks: The changes operate purely within the internal BPF verifier pipeline during program verification and instruction fixups. No kernel structures or memory buffers are copied to user space.\n2. Structure Initialization: All newly allocated data structures (such as `walk_snapshot`, `scc_converged`, `scc_thrs`, and temporary instruction patch buffers) are explicitly zero-initialized using `memset`, `kvzalloc`, or `kvmemdup` from initialized data.\n3. Control Flow and Branching: Conditional branches rely only on fully initialized local or struct variables; no uninitialized struct fields or stack variables are evaluated.\n4. KASAN vs KMSAN: The primary risks associated with these changes are verifier logic errors, incorrect jump/instruction offset calculations, instruction buffer overflow, or potential state tracking use-after-free bugs. All of these potential failure modes are fully covered by KASAN, UBSAN, and standard kernel debugging facilities. No uninitialized memory usage or leak risks specific to KMSAN are introduced.\n\nTherefore, a dedicated KMSAN fuzzing session is not warranted.",
"NeedsKMSAN": false
} |
| Total Calls | Total Tokens | Avg Tokens | Total Duration (Seconds) | Avg Duration (Seconds) |
|---|
| Total Calls | Total Duration (Seconds) | Avg Duration (Seconds) |
|---|