AI Trajectory


Trajectory: (Expand/Collapse All)
Seq Timestamp Type Name Duration
0/0 2026/10/24 15:12 flow patch-triage
1m Args:
null

Results:
{
  "EnableConfigs": [
    "BPF_SYSCALL",
    "DEBUG_INFO_BTF"
  ],
  "FocusSymbols": [
    "check_kfunc_call",
    "process_iter_arg",
    "invalidate_reference",
    "release_reference",
    "check_ptr_to_btf_access",
    "unmark_stack_slots_iter",
    "mark_stack_slots_dynptr",
    "btf_check_iter_kfuncs"
  ],
  "KMSANReasoning": "The patch series modifies the BPF verifier and BTF metadata to track and invalidate borrowed struct references returned by open-coded iterator next functions (bpf_iter_\u003ctype\u003e_next) upon subsequent next calls or iterator destruction. \n\nThis change addresses pointer lifetime tracking within the BPF verifier to prevent BPF programs from accessing stale or freed kernel objects (use-after-free or dangling pointer dereferences). These types of memory safety violations in BPF programs are detected at runtime by KASAN (out-of-bounds, use-after-free).\n\nThe patch does not introduce new kernel-to-user memory transfers, ioctls, or padding exposure, nor does it create or read uninitialized stack, heap, or page allocations in the kernel. All new local variables in the verifier code are properly initialized before use. Consequently, there are no uninitialized memory access or info-leak risks that would necessitate a dedicated KMSAN fuzzing session.",
  "NeedsKMSAN": false,
  "Reasoning": "The patch modifies the BPF verifier's reference-tracking and lifetime-invalidation logic for open-coded iterators, dynptrs, and trusted BTF pointers. It introduces KF_ITER_RET_INDEPENDENT to BTF kfunc checks and updates check_kfunc_call, process_iter_arg, check_ptr_to_btf_access, invalidate_reference, and release_reference in kernel/bpf/verifier.c. These changes are reachable from unprivileged or privileged userspace via the bpf(BPF_PROG_LOAD) syscall when loading programs that make use of iterators and BTF accesses. Fuzzing is warranted to uncover latent verifier state bugs or edge cases in reference invalidation.",
  "WorthFuzzing": true
}

1/1 2026/10/24 15:12 action read-patch-diff
0m Args:
null

Results:
{
  "PatchDiff": "commit 1121dd1c7c4c1347066df764307b88c0ccdd6f83\nAuthor: syz-cluster \u003ctriage@syzkaller.com\u003e\nDate:   Sat Oct 24 15:12:00 2026 +0000\n\n    syz-cluster: applied patch under review\n\ndiff --git a/Documentation/bpf/bpf_iterators.rst b/Documentation/bpf/bpf_iterators.rst\nindex 189e3ec1c6c8e..72435e32ffa16 100644\n--- a/Documentation/bpf/bpf_iterators.rst\n+++ b/Documentation/bpf/bpf_iterators.rst\n@@ -86,6 +86,16 @@ Constructor/next/destructor implementation contract is as follows:\n     resources and marks stack space used by `struct bpf_iter_\u003ctype\u003e` as usable\n     for something else. Destructor is marked with KF_ITER_DESTROY flag.\n \n+The verifier treats a non-RCU, non-acquired struct result as borrowed from\n+the iterator's current element. It invalidates the previous result and its\n+tracked derived pointers on the next call, including when it returns NULL,\n+and on destruction of the iterator. Resources borrowing that lifetime must\n+be released first. A next method whose struct result has an independent\n+lifetime must use ``KF_ITER_RET_INDEPENDENT``. This flag requires\n+``KF_ITER_NEXT`` and a struct pointer return type, and cannot be combined\n+with ``KF_ACQUIRE``. RCU-protected and acquired results retain their own\n+lifetime rules.\n+\n Any open-coded BPF iterator implementation has to implement at least these\n three methods. It is enforced that for any given type of iterator only\n applicable constructor/destructor/next are callable. I.e., verifier ensures\ndiff --git a/include/linux/btf.h b/include/linux/btf.h\nindex b66e20a18c54f..a18254b7521bd 100644\n--- a/include/linux/btf.h\n+++ b/include/linux/btf.h\n@@ -82,6 +82,7 @@\n #define KF_IMPLICIT_ARGS (1 \u003c\u003c 16) /* kfunc has implicit arguments supplied by the verifier */\n #define KF_SPINLOCK_SAFE (1 \u003c\u003c 17) /* kfunc is allowed inside bpf_spin_lock-ed region */\n #define KF_PERFMON      (1 \u003c\u003c 18) /* kfunc requires CAP_PERFMON */\n+#define KF_ITER_RET_INDEPENDENT (1 \u003c\u003c 19) /* next result outlives the current element */\n \n /*\n  * Tag marking a kernel function as a kfunc. This is meant to minimize the\ndiff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c\nindex 538129ed24188..e360c0aefc375 100644\n--- a/kernel/bpf/btf.c\n+++ b/kernel/bpf/btf.c\n@@ -9716,6 +9716,10 @@ static int btf_check_iter_kfuncs(struct btf *btf, const char *func_name,\n \tif (!flags || (flags \u0026 (flags - 1)))\n \t\treturn -EINVAL;\n \n+\tif ((func_flags \u0026 KF_ITER_RET_INDEPENDENT) \u0026\u0026\n+\t    (!(flags \u0026 KF_ITER_NEXT) || (func_flags \u0026 KF_ACQUIRE)))\n+\t\treturn -EINVAL;\n+\n \t/* any BPF iter kfunc should have `struct bpf_iter_\u003ctype\u003e *` first arg */\n \tnr_args = btf_type_vlen(func);\n \tif (nr_args \u003c 1)\n@@ -9756,6 +9760,12 @@ static int btf_check_iter_kfuncs(struct btf *btf, const char *func_name,\n \t\tt = btf_type_skip_modifiers(btf, func-\u003etype, NULL);\n \t\tif (!t || !btf_type_is_ptr(t))\n \t\t\treturn -EINVAL;\n+\t\t/* The opt-out applies only to non-acquired struct results. */\n+\t\tif (func_flags \u0026 KF_ITER_RET_INDEPENDENT) {\n+\t\t\tt = btf_type_skip_modifiers(btf, t-\u003etype, NULL);\n+\t\t\tif (!t || !__btf_type_is_struct(t))\n+\t\t\t\treturn -EINVAL;\n+\t\t}\n \t}\n \n \tif (flags \u0026 KF_ITER_DESTROY) {\n@@ -9822,7 +9832,8 @@ static int btf_check_kfunc_protos(struct btf *btf, u32 func_id, u32 func_flags)\n \tif (!func || !btf_type_is_func_proto(func))\n \t\treturn -EINVAL;\n \n-\tif (func_flags \u0026 (KF_ITER_NEW | KF_ITER_NEXT | KF_ITER_DESTROY)) {\n+\tif (func_flags \u0026 (KF_ITER_NEW | KF_ITER_NEXT | KF_ITER_DESTROY |\n+\t\t\t  KF_ITER_RET_INDEPENDENT)) {\n \t\terr = btf_check_iter_kfuncs(btf, func_name, func, func_flags);\n \t\tif (err)\n \t\t\treturn err;\ndiff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c\nindex 5601d20562186..c223bf3bc9cdb 100644\n--- a/kernel/bpf/verifier.c\n+++ b/kernel/bpf/verifier.c\n@@ -211,6 +211,9 @@ static int acquire_reference(struct bpf_verifier_env *env, int insn_idx, int par\n static int __release_reference_nomark(struct bpf_verifier_state *state, int id);\n static int release_reference_nomark(struct bpf_verifier_env *env, int id);\n static int release_reference(struct bpf_verifier_env *env, int id);\n+static int invalidate_reference(struct bpf_verifier_env *env, int id);\n+static u32 reg_lifetime_id(struct bpf_verifier_env *env,\n+\t\t\t   const struct bpf_reg_state *reg);\n static void invalidate_non_owning_refs(struct bpf_verifier_env *env);\n static void invalidate_rcu_protected_refs(struct bpf_verifier_env *env);\n static bool in_rbtree_lock_required_cb(struct bpf_verifier_env *env);\n@@ -793,8 +796,8 @@ static int mark_stack_slots_dynptr(struct bpf_verifier_env *env, struct bpf_reg_\n \t\tif (err)\n \t\t\treturn err;\n \n-\t\t/* Track parent's id if the parent is a referenced object */\n-\t\tparent_id = ref_obj-\u003eid;\n+\t\t/* All non-clone constructors take their backing object in R1. */\n+\t\tparent_id = reg_lifetime_id(env, \u0026cur_regs(env)[BPF_REG_1]);\n \n \t\tif (dynptr_type_referenced(type)) {\n \t\t\tint id;\n@@ -1074,7 +1077,7 @@ static int unmark_stack_slots_iter(struct bpf_verifier_env *env,\n \t\t\t\t   struct bpf_reg_state *reg, int nr_slots)\n {\n \tstruct bpf_func_state *state = bpf_func(env, reg);\n-\tint spi, i, j;\n+\tint spi, i, j, err;\n \n \tspi = iter_get_spi(env, reg, nr_slots);\n \tif (spi \u003c 0)\n@@ -1084,8 +1087,11 @@ static int unmark_stack_slots_iter(struct bpf_verifier_env *env,\n \t\tstruct bpf_stack_state *slot = bpf_stack_slot(state, spi - i);\n \t\tstruct bpf_reg_state *st = \u0026slot-\u003espilled_ptr;\n \n-\t\tif (i == 0)\n-\t\t\tWARN_ON_ONCE(release_reference(env, st-\u003eid));\n+\t\tif (i == 0) {\n+\t\t\terr = release_reference(env, st-\u003eid);\n+\t\t\tif (err)\n+\t\t\t\treturn err;\n+\t\t}\n \n \t\tbpf_mark_reg_not_init(env, st);\n \n@@ -1627,6 +1633,12 @@ static bool reg_is_referenced(struct bpf_verifier_env *env, const struct bpf_reg\n \treturn find_reference_state(env-\u003ecur_state, reg-\u003eid);\n }\n \n+static u32 reg_lifetime_id(struct bpf_verifier_env *env,\n+\t\t\t   const struct bpf_reg_state *reg)\n+{\n+\treturn reg_is_referenced(env, reg) ? reg-\u003eid : reg-\u003eparent_id;\n+}\n+\n static int release_lock_state(struct bpf_verifier_env *env, int type, int id, void *ptr)\n {\n \tstruct bpf_verifier_state *state = env-\u003ecur_state;\n@@ -6848,9 +6860,14 @@ static int check_ptr_to_btf_access(struct bpf_verifier_env *env,\n \t\tflag \u0026= ~PTR_MAYBE_NULL;\n \n \tif (atype == BPF_READ \u0026\u0026 value_regno \u003e= 0) {\n+\t\tu32 parent_id = reg_lifetime_id(env, reg);\n+\n \t\tret = mark_btf_ld_reg(env, regs, value_regno, ret, reg-\u003ebtf, btf_id, flag);\n \t\tif (ret \u003c 0)\n \t\t\treturn ret;\n+\t\tif ((regs[value_regno].type \u0026 PTR_TRUSTED) \u0026\u0026\n+\t\t    !(regs[value_regno].type \u0026 (MEM_RCU | MEM_PERCPU | MEM_USER)))\n+\t\t\tregs[value_regno].parent_id = parent_id;\n \t}\n \n \treturn 0;\n@@ -8636,6 +8653,21 @@ static bool is_iter_destroy_kfunc(struct bpf_call_arg_meta *meta)\n \treturn meta-\u003ekfunc_flags \u0026 KF_ITER_DESTROY;\n }\n \n+static bool iter_next_borrows_struct(struct bpf_call_arg_meta *meta)\n+{\n+\tconst struct btf_type *t;\n+\n+\tif (!(meta-\u003ekfunc_flags \u0026 KF_ITER_NEXT) ||\n+\t    (meta-\u003ekfunc_flags \u0026 (KF_ITER_RET_INDEPENDENT | KF_ACQUIRE)))\n+\t\treturn false;\n+\n+\tt = btf_type_skip_modifiers(meta-\u003ebtf, meta-\u003efunc_proto-\u003etype, NULL);\n+\tif (!t || !btf_type_is_ptr(t))\n+\t\treturn false;\n+\tt = btf_type_skip_modifiers(meta-\u003ebtf, t-\u003etype, NULL);\n+\treturn t \u0026\u0026 __btf_type_is_struct(t);\n+}\n+\n static bool is_kfunc_arg_iter(struct bpf_call_arg_meta *meta, int arg_idx,\n \t\t\t      const struct btf_param *arg)\n {\n@@ -8746,6 +8778,13 @@ static int process_iter_arg(struct bpf_verifier_env *env, struct bpf_reg_state *\n \t\tmeta-\u003eiter.frameno = reg-\u003eframeno;\n \t\tupdate_ref_obj(\u0026meta-\u003eref_obj, \u0026bpf_stack_slot(state, spi)-\u003espilled_ptr);\n \n+\t\t/* The iterator stays. What was borrowed from the previous element goes. */\n+\t\tif (iter_next_borrows_struct(meta)) {\n+\t\t\terr = invalidate_reference(env, meta-\u003eref_obj.id);\n+\t\t\tif (err)\n+\t\t\t\treturn err;\n+\t\t}\n+\n \t\tif (is_iter_destroy_kfunc(meta)) {\n \t\t\terr = unmark_stack_slots_iter(env, reg, nr_slots);\n \t\t\tif (err)\n@@ -11073,8 +11112,8 @@ static int idstack_pop(struct bpf_idmap *idmap)\n \treturn idmap-\u003emap[--idmap-\u003ecnt].old;\n }\n \n-/* Release id and objects derived from it iteratively in a DFS manner */\n-static int release_reference(struct bpf_verifier_env *env, int id)\n+/* Invalidate id and objects derived from it iteratively in a DFS manner */\n+static int invalidate_reference(struct bpf_verifier_env *env, int id)\n {\n \tu32 mask = (1 \u003c\u003c STACK_SPILL) | (1 \u003c\u003c STACK_DYNPTR);\n \tstruct bpf_verifier_state *vstate = env-\u003ecur_state;\n@@ -11089,11 +11128,6 @@ static int release_reference(struct bpf_verifier_env *env, int id)\n \tif (err)\n \t\treturn err;\n \n-\tif (find_reference_state(vstate, id)) {\n-\t\terr = release_reference_nomark(env, id);\n-\t\tWARN_ON_ONCE(err);\n-\t}\n-\n \twhile ((id = idstack_pop(idstack))) {\n \t\t/*\n \t\t * Child references are inaccessible after parent is released,\n@@ -11145,6 +11179,14 @@ static int release_reference(struct bpf_verifier_env *env, int id)\n \treturn 0;\n }\n \n+static int release_reference(struct bpf_verifier_env *env, int id)\n+{\n+\tif (find_reference_state(env-\u003ecur_state, id))\n+\t\tWARN_ON_ONCE(release_reference_nomark(env, id));\n+\n+\treturn invalidate_reference(env, id);\n+}\n+\n static void invalidate_non_owning_refs(struct bpf_verifier_env *env)\n {\n \tstruct bpf_func_state *unused;\n@@ -15822,6 +15864,8 @@ static int check_kfunc_call(struct bpf_verifier_env *env, struct bpf_insn *insn,\n \t\t\tregs[BPF_REG_0].btf = desc_btf;\n \t\t\tregs[BPF_REG_0].type = type;\n \t\t\tregs[BPF_REG_0].btf_id = ptr_type_id;\n+\t\t\tif (iter_next_borrows_struct(\u0026meta) \u0026\u0026 !(type \u0026 MEM_RCU))\n+\t\t\t\tregs[BPF_REG_0].parent_id = meta.ref_obj.id;\n \t\t}\n \n \t\tif (is_kfunc_ret_null(\u0026meta)) {\ndiff --git a/tools/testing/selftests/bpf/progs/iters_testmod.c b/tools/testing/selftests/bpf/progs/iters_testmod.c\nindex 145750bb64ef8..8896335668b47 100644\n--- a/tools/testing/selftests/bpf/progs/iters_testmod.c\n+++ b/tools/testing/selftests/bpf/progs/iters_testmod.c\n@@ -8,6 +8,44 @@\n \n char _license[] SEC(\"license\") = \"GPL\";\n \n+struct bpf_iter_testmod_current {\n+\tu64 __opaque;\n+};\n+\n+SEC(\"raw_tp/sys_enter\")\n+__success\n+int iter_independent_lifetime_after_next(const void *ctx)\n+{\n+\tstruct bpf_iter_testmod_current it;\n+\tstruct task_struct *task;\n+\n+\tbpf_iter_testmod_current_new(\u0026it);\n+\ttask = bpf_iter_testmod_current_next(\u0026it);\n+\tif (!task)\n+\t\tgoto out;\n+\n+\tbpf_iter_testmod_current_next(\u0026it);\n+\tbpf_kfunc_trusted_task_test(task);\n+out:\n+\tbpf_iter_testmod_current_destroy(\u0026it);\n+\treturn 0;\n+}\n+\n+SEC(\"raw_tp/sys_enter\")\n+__success\n+int iter_independent_lifetime_after_destroy(const void *ctx)\n+{\n+\tstruct bpf_iter_testmod_current it;\n+\tstruct task_struct *task;\n+\n+\tbpf_iter_testmod_current_new(\u0026it);\n+\ttask = bpf_iter_testmod_current_next(\u0026it);\n+\tbpf_iter_testmod_current_destroy(\u0026it);\n+\tif (task)\n+\t\tbpf_kfunc_trusted_task_test(task);\n+\treturn 0;\n+}\n+\n SEC(\"raw_tp/sys_enter\")\n __success\n int iter_next_trusted(const void *ctx)\n@@ -28,6 +66,298 @@ int iter_next_trusted(const void *ctx)\n \treturn 0;\n }\n \n+SEC(\"raw_tp/sys_enter\")\n+__failure __msg(\"invalid mem access 'scalar'\")\n+int iter_next_trusted_after_destroy(const void *ctx)\n+{\n+\tstruct task_struct *cur_task = bpf_get_current_task_btf();\n+\tstruct bpf_iter_task_vma vma_it;\n+\tstruct vm_area_struct *vma_ptr;\n+\n+\tbpf_iter_task_vma_new(\u0026vma_it, cur_task, 0);\n+\n+\tvma_ptr = bpf_iter_task_vma_next(\u0026vma_it);\n+\tif (!vma_ptr)\n+\t\tgoto out;\n+\n+\tbpf_iter_task_vma_destroy(\u0026vma_it);\n+\treturn vma_ptr-\u003evm_start;\n+out:\n+\tbpf_iter_task_vma_destroy(\u0026vma_it);\n+\treturn 0;\n+}\n+\n+SEC(\"raw_tp/sys_enter\")\n+__failure __msg(\"invalid mem access 'scalar'\")\n+int iter_next_trusted_after_next(const void *ctx)\n+{\n+\tstruct task_struct *cur_task = bpf_get_current_task_btf();\n+\tstruct bpf_iter_task_vma vma_it;\n+\tstruct vm_area_struct *vma_ptr, *next_vma_ptr;\n+\tu64 vm_start;\n+\n+\tbpf_iter_task_vma_new(\u0026vma_it, cur_task, 0);\n+\n+\tvma_ptr = bpf_iter_task_vma_next(\u0026vma_it);\n+\tif (!vma_ptr)\n+\t\tgoto out;\n+\n+\tnext_vma_ptr = bpf_iter_task_vma_next(\u0026vma_it);\n+\tif (!next_vma_ptr)\n+\t\tgoto out;\n+\n+\tvm_start = vma_ptr-\u003evm_start;\n+\tbpf_iter_task_vma_destroy(\u0026vma_it);\n+\treturn vm_start;\n+out:\n+\tbpf_iter_task_vma_destroy(\u0026vma_it);\n+\treturn 0;\n+}\n+\n+SEC(\"raw_tp/sys_enter\")\n+__failure __msg(\"invalid mem access 'scalar'\")\n+int iter_next_trusted_after_next_null(const void *ctx)\n+{\n+\tstruct task_struct *cur_task = bpf_get_current_task_btf();\n+\tstruct bpf_iter_task_vma vma_it;\n+\tstruct vm_area_struct *vma_ptr, *next_vma_ptr;\n+\tu64 vm_start;\n+\n+\tbpf_iter_task_vma_new(\u0026vma_it, cur_task, 0);\n+\n+\tvma_ptr = bpf_iter_task_vma_next(\u0026vma_it);\n+\tif (!vma_ptr)\n+\t\tgoto out;\n+\n+\tnext_vma_ptr = bpf_iter_task_vma_next(\u0026vma_it);\n+\tif (next_vma_ptr)\n+\t\tgoto out;\n+\n+\tvm_start = vma_ptr-\u003evm_start;\n+\tbpf_iter_task_vma_destroy(\u0026vma_it);\n+\treturn vm_start;\n+out:\n+\tbpf_iter_task_vma_destroy(\u0026vma_it);\n+\treturn 0;\n+}\n+\n+SEC(\"raw_tp/sys_enter\")\n+__failure __msg(\"invalid mem access 'scalar'\")\n+int iter_next_trusted_field_after_destroy(const void *ctx)\n+{\n+\tstruct task_struct *cur_task = bpf_get_current_task_btf();\n+\tstruct bpf_iter_task_vma vma_it;\n+\tstruct vm_area_struct *vma_ptr;\n+\tstruct file *file_ptr;\n+\n+\tbpf_iter_task_vma_new(\u0026vma_it, cur_task, 0);\n+\n+\tvma_ptr = bpf_iter_task_vma_next(\u0026vma_it);\n+\tif (!vma_ptr)\n+\t\tgoto out;\n+\n+\tfile_ptr = vma_ptr-\u003evm_file;\n+\tbpf_iter_task_vma_destroy(\u0026vma_it);\n+\tif (file_ptr)\n+\t\treturn file_ptr-\u003ef_mode;\n+\treturn 0;\n+out:\n+\tbpf_iter_task_vma_destroy(\u0026vma_it);\n+\treturn 0;\n+}\n+\n+SEC(\"raw_tp/sys_enter\")\n+__failure __msg(\"invalid mem access 'scalar'\")\n+int iter_next_trusted_field_after_next(const void *ctx)\n+{\n+\tstruct task_struct *cur_task = bpf_get_current_task_btf();\n+\tstruct bpf_iter_task_vma vma_it;\n+\tstruct vm_area_struct *vma_ptr, *next_vma_ptr;\n+\tstruct file *file_ptr;\n+\tu32 mode;\n+\n+\tbpf_iter_task_vma_new(\u0026vma_it, cur_task, 0);\n+\n+\tvma_ptr = bpf_iter_task_vma_next(\u0026vma_it);\n+\tif (!vma_ptr)\n+\t\tgoto out;\n+\n+\tfile_ptr = vma_ptr-\u003evm_file;\n+\tif (!file_ptr)\n+\t\tgoto out;\n+\n+\tnext_vma_ptr = bpf_iter_task_vma_next(\u0026vma_it);\n+\tif (!next_vma_ptr)\n+\t\tgoto out;\n+\n+\tmode = file_ptr-\u003ef_mode;\n+\tbpf_iter_task_vma_destroy(\u0026vma_it);\n+\treturn mode;\n+out:\n+\tbpf_iter_task_vma_destroy(\u0026vma_it);\n+\treturn 0;\n+}\n+\n+SEC(\"raw_tp/sys_enter\")\n+__failure __msg(\"Leaking reference id=\")\n+int iter_next_file_dynptr_after_next(const void *ctx)\n+{\n+\tstruct task_struct *cur_task = bpf_get_current_task_btf();\n+\tstruct bpf_iter_task_vma vma_it;\n+\tstruct vm_area_struct *vma_ptr;\n+\tstruct bpf_dynptr dynptr;\n+\tstruct file *file_ptr;\n+\n+\tbpf_iter_task_vma_new(\u0026vma_it, cur_task, 0);\n+\n+\tvma_ptr = bpf_iter_task_vma_next(\u0026vma_it);\n+\tif (!vma_ptr)\n+\t\tgoto out;\n+\n+\tfile_ptr = vma_ptr-\u003evm_file;\n+\tif (!file_ptr)\n+\t\tgoto out;\n+\n+\tbpf_dynptr_from_file(file_ptr, 0, \u0026dynptr);\n+\tbpf_iter_task_vma_next(\u0026vma_it);\n+\tbpf_dynptr_file_discard(\u0026dynptr);\n+out:\n+\tbpf_iter_task_vma_destroy(\u0026vma_it);\n+\treturn 0;\n+}\n+\n+SEC(\"raw_tp/sys_enter\")\n+__failure __msg(\"Leaking reference id=\")\n+int iter_next_file_dynptr_after_destroy(const void *ctx)\n+{\n+\tstruct task_struct *cur_task = bpf_get_current_task_btf();\n+\tstruct bpf_iter_task_vma vma_it;\n+\tstruct vm_area_struct *vma_ptr;\n+\tstruct bpf_dynptr dynptr;\n+\tstruct file *file_ptr;\n+\n+\tbpf_iter_task_vma_new(\u0026vma_it, cur_task, 0);\n+\n+\tvma_ptr = bpf_iter_task_vma_next(\u0026vma_it);\n+\tif (!vma_ptr)\n+\t\tgoto out;\n+\n+\tfile_ptr = vma_ptr-\u003evm_file;\n+\tif (!file_ptr)\n+\t\tgoto out;\n+\n+\tbpf_dynptr_from_file(file_ptr, 0, \u0026dynptr);\n+\tbpf_iter_task_vma_destroy(\u0026vma_it);\n+\tbpf_dynptr_file_discard(\u0026dynptr);\n+\treturn 0;\n+out:\n+\tbpf_iter_task_vma_destroy(\u0026vma_it);\n+\treturn 0;\n+}\n+\n+SEC(\"raw_tp/sys_enter\")\n+__success\n+int iter_next_file_dynptr_discard_before_advance(const void *ctx)\n+{\n+\tstruct task_struct *cur_task = bpf_get_current_task_btf();\n+\tstruct bpf_iter_task_vma vma_it;\n+\tstruct vm_area_struct *vma_ptr;\n+\tstruct bpf_dynptr dynptr;\n+\tstruct file *file_ptr;\n+\n+\tbpf_iter_task_vma_new(\u0026vma_it, cur_task, 0);\n+\n+\tvma_ptr = bpf_iter_task_vma_next(\u0026vma_it);\n+\tif (!vma_ptr)\n+\t\tgoto out;\n+\n+\tfile_ptr = vma_ptr-\u003evm_file;\n+\tif (!file_ptr)\n+\t\tgoto out;\n+\n+\tbpf_dynptr_from_file(file_ptr, 0, \u0026dynptr);\n+\tbpf_dynptr_file_discard(\u0026dynptr);\n+\tbpf_iter_task_vma_next(\u0026vma_it);\n+out:\n+\tbpf_iter_task_vma_destroy(\u0026vma_it);\n+\treturn 0;\n+}\n+\n+SEC(\"raw_tp/sys_enter\")\n+__success\n+int iter_next_trusted_current_after_next(const void *ctx)\n+{\n+\tstruct task_struct *cur_task = bpf_get_current_task_btf();\n+\tstruct bpf_iter_task_vma vma_it;\n+\tstruct vm_area_struct *vma_ptr;\n+\n+\tbpf_iter_task_vma_new(\u0026vma_it, cur_task, 0);\n+\n+\tvma_ptr = bpf_iter_task_vma_next(\u0026vma_it);\n+\tif (!vma_ptr)\n+\t\tgoto out;\n+\n+\tvma_ptr = bpf_iter_task_vma_next(\u0026vma_it);\n+\tif (vma_ptr)\n+\t\tbpf_kfunc_trusted_vma_test(vma_ptr);\n+out:\n+\tbpf_iter_task_vma_destroy(\u0026vma_it);\n+\treturn 0;\n+}\n+\n+SEC(\"raw_tp/sys_enter\")\n+__success\n+int iter_next_trusted_rcu_field_after_destroy(const void *ctx)\n+{\n+\tstruct task_struct *cur_task = bpf_get_current_task_btf();\n+\tstruct bpf_iter_task_vma vma_it;\n+\tstruct vm_area_struct *vma_ptr;\n+\tstruct mm_struct *mm_ptr;\n+\tstruct file *file_ptr = NULL;\n+\n+\tbpf_iter_task_vma_new(\u0026vma_it, cur_task, 0);\n+\n+\tvma_ptr = bpf_iter_task_vma_next(\u0026vma_it);\n+\tif (vma_ptr) {\n+\t\tmm_ptr = vma_ptr-\u003evm_mm;\n+\t\t/* exe_file has RCU protection independent of the iterator. */\n+\t\tif (mm_ptr)\n+\t\t\tfile_ptr = mm_ptr-\u003eexe_file;\n+\t}\n+\n+\tbpf_iter_task_vma_destroy(\u0026vma_it);\n+\tif (file_ptr)\n+\t\treturn file_ptr-\u003ef_mode;\n+\treturn 0;\n+}\n+\n+SEC(\"raw_tp/sys_enter\")\n+__success\n+int iter_next_trusted_rcu_field_after_next(const void *ctx)\n+{\n+\tstruct task_struct *cur_task = bpf_get_current_task_btf();\n+\tstruct bpf_iter_task_vma vma_it;\n+\tstruct vm_area_struct *vma_ptr;\n+\tstruct mm_struct *mm_ptr;\n+\tstruct file *file_ptr = NULL;\n+\tu32 mode = 0;\n+\n+\tbpf_iter_task_vma_new(\u0026vma_it, cur_task, 0);\n+\n+\tvma_ptr = bpf_iter_task_vma_next(\u0026vma_it);\n+\tif (vma_ptr) {\n+\t\tmm_ptr = vma_ptr-\u003evm_mm;\n+\t\tif (mm_ptr)\n+\t\t\tfile_ptr = mm_ptr-\u003eexe_file;\n+\t}\n+\n+\tbpf_iter_task_vma_next(\u0026vma_it);\n+\tif (file_ptr)\n+\t\tmode = file_ptr-\u003ef_mode;\n+\tbpf_iter_task_vma_destroy(\u0026vma_it);\n+\treturn mode;\n+}\n+\n SEC(\"raw_tp/sys_enter\")\n __failure __msg(\"Possibly NULL pointer passed to trusted R1\")\n int iter_next_trusted_or_null(const void *ctx)\n@@ -77,6 +407,46 @@ int iter_next_rcu(const void *ctx)\n \treturn 0;\n }\n \n+SEC(\"raw_tp/sys_enter\")\n+__success\n+int iter_next_rcu_after_destroy(const void *ctx)\n+{\n+\tstruct task_struct *cur_task = bpf_get_current_task_btf();\n+\tstruct bpf_iter_task task_it;\n+\tstruct task_struct *task_ptr;\n+\n+\tbpf_iter_task_new(\u0026task_it, cur_task, 0);\n+\n+\ttask_ptr = bpf_iter_task_next(\u0026task_it);\n+\tbpf_iter_task_destroy(\u0026task_it);\n+\tif (!task_ptr)\n+\t\treturn 0;\n+\n+\tbpf_kfunc_rcu_task_test(task_ptr);\n+\treturn 0;\n+}\n+\n+SEC(\"raw_tp/sys_enter\")\n+__success\n+int iter_next_rcu_after_next(const void *ctx)\n+{\n+\tstruct task_struct *cur_task = bpf_get_current_task_btf();\n+\tstruct bpf_iter_task task_it;\n+\tstruct task_struct *task_ptr;\n+\n+\tbpf_iter_task_new(\u0026task_it, cur_task, 0);\n+\n+\ttask_ptr = bpf_iter_task_next(\u0026task_it);\n+\tif (!task_ptr)\n+\t\tgoto out;\n+\n+\tbpf_iter_task_next(\u0026task_it);\n+\tbpf_kfunc_rcu_task_test(task_ptr);\n+out:\n+\tbpf_iter_task_destroy(\u0026task_it);\n+\treturn 0;\n+}\n+\n SEC(\"raw_tp/sys_enter\")\n __failure __msg(\"Possibly NULL pointer passed to trusted R1\")\n int iter_next_rcu_or_null(const void *ctx)\ndiff --git a/tools/testing/selftests/bpf/progs/verifier_vfs_accept.c b/tools/testing/selftests/bpf/progs/verifier_vfs_accept.c\nindex 55398c04290a8..25f37a3dd7cfb 100644\n--- a/tools/testing/selftests/bpf/progs/verifier_vfs_accept.c\n+++ b/tools/testing/selftests/bpf/progs/verifier_vfs_accept.c\n@@ -11,6 +11,23 @@\n \n static char buf[64];\n \n+SEC(\"lsm.s/file_open\")\n+__success\n+int BPF_PROG(inode_field_before_file_put)\n+{\n+\tstruct file *file;\n+\tino_t ino;\n+\n+\tfile = bpf_get_task_exe_file(bpf_get_current_task_btf());\n+\tif (!file)\n+\t\treturn 0;\n+\n+\tino = file-\u003ef_inode-\u003ei_ino;\n+\tbpf_put_file(file);\n+\t__sink(ino);\n+\treturn 0;\n+}\n+\n SEC(\"lsm.s/file_open\")\n __success\n int BPF_PROG(get_task_exe_file_and_put_kfunc_from_current_sleepable)\ndiff --git a/tools/testing/selftests/bpf/progs/verifier_vfs_reject.c b/tools/testing/selftests/bpf/progs/verifier_vfs_reject.c\nindex b5f456d57669e..ed2bd2faebf36 100644\n--- a/tools/testing/selftests/bpf/progs/verifier_vfs_reject.c\n+++ b/tools/testing/selftests/bpf/progs/verifier_vfs_reject.c\n@@ -12,6 +12,25 @@\n \n static char buf[PATH_MAX];\n \n+SEC(\"lsm.s/file_open\")\n+__failure __msg(\"invalid mem access 'scalar'\")\n+int BPF_PROG(inode_field_after_file_put)\n+{\n+\tstruct inode *inode;\n+\tstruct file *file;\n+\tino_t ino;\n+\n+\tfile = bpf_get_task_exe_file(bpf_get_current_task_btf());\n+\tif (!file)\n+\t\treturn 0;\n+\n+\tinode = file-\u003ef_inode;\n+\tbpf_put_file(file);\n+\tino = inode-\u003ei_ino;\n+\t__sink(ino);\n+\treturn 0;\n+}\n+\n SEC(\"lsm.s/file_open\")\n __failure __msg(\"Possibly NULL pointer passed to trusted R1\")\n int BPF_PROG(get_task_exe_file_kfunc_null)\ndiff --git a/tools/testing/selftests/bpf/test_kmods/bpf_testmod.c b/tools/testing/selftests/bpf/test_kmods/bpf_testmod.c\nindex 6380f52f4dd2c..76fbe64755ef9 100644\n--- a/tools/testing/selftests/bpf/test_kmods/bpf_testmod.c\n+++ b/tools/testing/selftests/bpf/test_kmods/bpf_testmod.c\n@@ -281,6 +281,27 @@ __bpf_kfunc void bpf_iter_testmod_seq_destroy(struct bpf_iter_testmod_seq *it)\n \tit-\u003ecnt = 0;\n }\n \n+__bpf_kfunc int bpf_iter_testmod_current_new(struct bpf_iter_testmod_current *it)\n+{\n+\tit-\u003eremaining = 2;\n+\treturn 0;\n+}\n+\n+__bpf_kfunc struct task_struct *\n+bpf_iter_testmod_current_next(struct bpf_iter_testmod_current *it)\n+{\n+\tif (!it-\u003eremaining)\n+\t\treturn NULL;\n+\tit-\u003eremaining--;\n+\t/* current remains alive independently of the iterator. */\n+\treturn current;\n+}\n+\n+__bpf_kfunc void bpf_iter_testmod_current_destroy(struct bpf_iter_testmod_current *it)\n+{\n+\tit-\u003eremaining = 0;\n+}\n+\n __bpf_kfunc void bpf_kfunc_common_test(void)\n {\n }\n@@ -1016,6 +1037,10 @@ BTF_ID_FLAGS(func, bpf_iter_testmod_seq_new, KF_ITER_NEW)\n BTF_ID_FLAGS(func, bpf_iter_testmod_seq_next, KF_ITER_NEXT | KF_RET_NULL)\n BTF_ID_FLAGS(func, bpf_iter_testmod_seq_destroy, KF_ITER_DESTROY)\n BTF_ID_FLAGS(func, bpf_iter_testmod_seq_value)\n+BTF_ID_FLAGS(func, bpf_iter_testmod_current_new, KF_ITER_NEW)\n+BTF_ID_FLAGS(func, bpf_iter_testmod_current_next,\n+\t     KF_ITER_NEXT | KF_RET_NULL | KF_ITER_RET_INDEPENDENT)\n+BTF_ID_FLAGS(func, bpf_iter_testmod_current_destroy, KF_ITER_DESTROY)\n BTF_ID_FLAGS(func, bpf_kfunc_common_test)\n BTF_ID_FLAGS(func, bpf_kfunc_arena_arg_test)\n BTF_ID_FLAGS(func, bpf_kfunc_arena_cap_test)\ndiff --git a/tools/testing/selftests/bpf/test_kmods/bpf_testmod.h b/tools/testing/selftests/bpf/test_kmods/bpf_testmod.h\nindex 4ba9def74404b..aef780261ef4f 100644\n--- a/tools/testing/selftests/bpf/test_kmods/bpf_testmod.h\n+++ b/tools/testing/selftests/bpf/test_kmods/bpf_testmod.h\n@@ -31,6 +31,10 @@ struct bpf_iter_testmod_seq {\n \tint cnt;\n };\n \n+struct bpf_iter_testmod_current {\n+\tu64 remaining;\n+};\n+\n struct bpf_testmod_ops {\n \tint (*test_1)(void);\n \tvoid (*test_2)(int a, int b);\ndiff --git a/tools/testing/selftests/bpf/test_kmods/bpf_testmod_kfunc.h b/tools/testing/selftests/bpf/test_kmods/bpf_testmod_kfunc.h\nindex 3b810f1e438f7..e9902e651d72b 100644\n--- a/tools/testing/selftests/bpf/test_kmods/bpf_testmod_kfunc.h\n+++ b/tools/testing/selftests/bpf/test_kmods/bpf_testmod_kfunc.h\n@@ -33,6 +33,11 @@ struct prog_test_ref_kfunc {\n #endif\n \n struct bpf_iter_testmod_seq;\n+struct bpf_iter_testmod_current;\n+\n+int bpf_iter_testmod_current_new(struct bpf_iter_testmod_current *it) __ksym;\n+struct task_struct *bpf_iter_testmod_current_next(struct bpf_iter_testmod_current *it) __ksym;\n+void bpf_iter_testmod_current_destroy(struct bpf_iter_testmod_current *it) __ksym;\n \n struct prog_test_pass1 {\n \tint x0;\n"
}

2/1 2026/10/24 15:12 agent patch-evaluator
1m Model:
core

Args:
null

Results:
{
  "EnableConfigs": [
    "BPF_SYSCALL",
    "DEBUG_INFO_BTF"
  ],
  "FocusSymbols": [
    "check_kfunc_call",
    "process_iter_arg",
    "invalidate_reference",
    "release_reference",
    "check_ptr_to_btf_access",
    "unmark_stack_slots_iter",
    "mark_stack_slots_dynptr",
    "btf_check_iter_kfuncs"
  ],
  "Reasoning": "The patch modifies the BPF verifier's reference-tracking and lifetime-invalidation logic for open-coded iterators, dynptrs, and trusted BTF pointers. It introduces KF_ITER_RET_INDEPENDENT to BTF kfunc checks and updates check_kfunc_call, process_iter_arg, check_ptr_to_btf_access, invalidate_reference, and release_reference in kernel/bpf/verifier.c. These changes are reachable from unprivileged or privileged userspace via the bpf(BPF_PROG_LOAD) syscall when loading programs that make use of iterators and BTF accesses. Fuzzing is warranted to uncover latent verifier state bugs or edge cases in reference invalidation.",
  "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 1121dd1c7c4c1347066df764307b88c0ccdd6f83
Author: syz-cluster <triage@syzkaller.com>
Date:   Sat Oct 24 15:12:00 2026 +0000

    syz-cluster: applied patch under review

diff --git a/Documentation/bpf/bpf_iterators.rst b/Documentation/bpf/bpf_iterators.rst
index 189e3ec1c6c8e..72435e32ffa16 100644
--- a/Documentation/bpf/bpf_iterators.rst
+++ b/Documentation/bpf/bpf_iterators.rst
@@ -86,6 +86,16 @@ Constructor/next/destructor implementation contract is as follows:
     resources and marks stack space used by `struct bpf_iter_<type>` as usable
     for something else. Destructor is marked with KF_ITER_DESTROY flag.
 
+The verifier treats a non-RCU, non-acquired struct result as borrowed from
+the iterator's current element. It invalidates the previous result and its
+tracked derived pointers on the next call, including when it returns NULL,
+and on destruction of the iterator. Resources borrowing that lifetime must
+be released first. A next method whose struct result has an independent
+lifetime must use ``KF_ITER_RET_INDEPENDENT``. This flag requires
+``KF_ITER_NEXT`` and a struct pointer return type, and cannot be combined
+with ``KF_ACQUIRE``. RCU-protected and acquired results retain their own
+lifetime rules.
+
 Any open-coded BPF iterator implementation has to implement at least these
 three methods. It is enforced that for any given type of iterator only
 applicable constructor/destructor/next are callable. I.e., verifier ensures
diff --git a/include/linux/btf.h b/include/linux/btf.h
index b66e20a18c54f..a18254b7521bd 100644
--- a/include/linux/btf.h
+++ b/include/linux/btf.h
@@ -82,6 +82,7 @@
 #define KF_IMPLICIT_ARGS (1 << 16) /* kfunc has implicit arguments supplied by the verifier */
 #define KF_SPINLOCK_SAFE (1 << 17) /* kfunc is allowed inside bpf_spin_lock-ed region */
 #define KF_PERFMON      (1 << 18) /* kfunc requires CAP_PERFMON */
+#define KF_ITER_RET_INDEPENDENT (1 << 19) /* next result outlives the current element */
 
 /*
  * Tag marking a kernel function as a kfunc. This is meant to minimize the
diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
index 538129ed24188..e360c0aefc375 100644
--- a/kernel/bpf/btf.c
+++ b/kernel/bpf/btf.c
@@ -9716,6 +9716,10 @@ static int btf_check_iter_kfuncs(struct btf *btf, const char *func_name,
 	if (!flags || (flags & (flags - 1)))
 		return -EINVAL;
 
+	if ((func_flags & KF_ITER_RET_INDEPENDENT) &&
+	    (!(flags & KF_ITER_NEXT) || (func_flags & KF_ACQUIRE)))
+		return -EINVAL;
+
 	/* any BPF iter kfunc should have `struct bpf_iter_<type> *` first arg */
 	nr_args = btf_type_vlen(func);
 	if (nr_args < 1)
@@ -9756,6 +9760,12 @@ static int btf_check_iter_kfuncs(struct btf *btf, const char *func_name,
 		t = btf_type_skip_modifiers(btf, func->type, NULL);
 		if (!t || !btf_type_is_ptr(t))
 			return -EINVAL;
+		/* The opt-out applies only to non-acquired struct results. */
+		if (func_flags & KF_ITER_RET_INDEPENDENT) {
+			t = btf_type_skip_modifiers(btf, t->type, NULL);
+			if (!t || !__btf_type_is_struct(t))
+				return -EINVAL;
+		}
 	}
 
 	if (flags & KF_ITER_DESTROY) {
@@ -9822,7 +9832,8 @@ static int btf_check_kfunc_protos(struct btf *btf, u32 func_id, u32 func_flags)
 	if (!func || !btf_type_is_func_proto(func))
 		return -EINVAL;
 
-	if (func_flags & (KF_ITER_NEW | KF_ITER_NEXT | KF_ITER_DESTROY)) {
+	if (func_flags & (KF_ITER_NEW | KF_ITER_NEXT | KF_ITER_DESTROY |
+			  KF_ITER_RET_INDEPENDENT)) {
 		err = btf_check_iter_kfuncs(btf, func_name, func, func_flags);
 		if (err)
 			return err;
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index 5601d20562186..c223bf3bc9cdb 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -211,6 +211,9 @@ static int acquire_reference(struct bpf_verifier_env *env, int insn_idx, int par
 static int __release_reference_nomark(struct bpf_verifier_state *state, int id);
 static int release_reference_nomark(struct bpf_verifier_env *env, int id);
 static int release_reference(struct bpf_verifier_env *env, int id);
+static int invalidate_reference(struct bpf_verifier_env *env, int id);
+static u32 reg_lifetime_id(struct bpf_verifier_env *env,
+			   const struct bpf_reg_state *reg);
 static void invalidate_non_owning_refs(struct bpf_verifier_env *env);
 static void invalidate_rcu_protected_refs(struct bpf_verifier_env *env);
 static bool in_rbtree_lock_required_cb(struct bpf_verifier_env *env);
@@ -793,8 +796,8 @@ static int mark_stack_slots_dynptr(struct bpf_verifier_env *env, struct bpf_reg_
 		if (err)
 			return err;
 
-		/* Track parent's id if the parent is a referenced object */
-		parent_id = ref_obj->id;
+		/* All non-clone constructors take their backing object in R1. */
+		parent_id = reg_lifetime_id(env, &cur_regs(env)[BPF_REG_1]);
 
 		if (dynptr_type_referenced(type)) {
 			int id;
@@ -1074,7 +1077,7 @@ static int unmark_stack_slots_iter(struct bpf_verifier_env *env,
 				   struct bpf_reg_state *reg, int nr_slots)
 {
 	struct bpf_func_state *state = bpf_func(env, reg);
-	int spi, i, j;
+	int spi, i, j, err;
 
 	spi = iter_get_spi(env, reg, nr_slots);
 	if (spi < 0)
@@ -1084,8 +1087,11 @@ static int unmark_stack_slots_iter(struct bpf_verifier_env *env,
 		struct bpf_stack_state *slot = bpf_stack_slot(state, spi - i);
 		struct bpf_reg_state *st = &slot->spilled_ptr;
 
-		if (i == 0)
-			WARN_ON_ONCE(release_reference(env, st->id));
+		if (i == 0) {
+			err = release_reference(env, st->id);
+			if (err)
+				return err;
+		}
 
 		bpf_mark_reg_not_init(env, st);
 
@@ -1627,6 +1633,12 @@ static bool reg_is_referenced(struct bpf_verifier_env *env, const struct bpf_reg
 	return find_reference_state(env->cur_state, reg->id);
 }
 
+static u32 reg_lifetime_id(struct bpf_verifier_env *env,
+			   const struct bpf_reg_state *reg)
+{
+	return reg_is_referenced(env, reg) ? reg->id : reg->parent_id;
+}
+
 static int release_lock_state(struct bpf_verifier_env *env, int type, int id, void *ptr)
 {
 	struct bpf_verifier_state *state = env->cur_state;
@@ -6848,9 +6860,14 @@ static int check_ptr_to_btf_access(struct bpf_verifier_env *env,
 		flag &= ~PTR_MAYBE_NULL;
 
 	if (atype == BPF_READ && value_regno >= 0) {
+		u32 parent_id = reg_lifetime_id(env, reg);
+
 		ret = mark_btf_ld_reg(env, regs, value_regno, ret, reg->btf, btf_id, flag);
 		if (ret < 0)
 			return ret;
+		if ((regs[value_regno].type & PTR_TRUSTED) &&
+		    !(regs[value_regno].type & (MEM_RCU | MEM_PERCPU | MEM_USER)))
+			regs[value_regno].parent_id = parent_id;
 	}
 
 	return 0;
@@ -8636,6 +8653,21 @@ static bool is_iter_destroy_kfunc(struct bpf_call_arg_meta *meta)
 	return meta->kfunc_flags & KF_ITER_DESTROY;
 }
 
+static bool iter_next_borrows_struct(struct bpf_call_arg_meta *meta)
+{
+	const struct btf_type *t;
+
+	if (!(meta->kfunc_flags & KF_ITER_NEXT) ||
+	    (meta->kfunc_flags & (KF_ITER_RET_INDEPENDENT | KF_ACQUIRE)))
+		return false;
+
+	t = btf_type_skip_modifiers(meta->btf, meta->func_proto->type, NULL);
+	if (!t || !btf_type_is_ptr(t))
+		return false;
+	t = btf_type_skip_modifiers(meta->btf, t->type, NULL);
+	return t && __btf_type_is_struct(t);
+}
+
 static bool is_kfunc_arg_iter(struct bpf_call_arg_meta *meta, int arg_idx,
 			      const struct btf_param *arg)
 {
@@ -8746,6 +8778,13 @@ static int process_iter_arg(struct bpf_verifier_env *env, struct bpf_reg_state *
 		meta->iter.frameno = reg->frameno;
 		update_ref_obj(&meta->ref_obj, &bpf_stack_slot(state, spi)->spilled_ptr);
 
+		/* The iterator stays. What was borrowed from the previous element goes. */
+		if (iter_next_borrows_struct(meta)) {
+			err = invalidate_reference(env, meta->ref_obj.id);
+			if (err)
+				return err;
+		}
+
 		if (is_iter_destroy_kfunc(meta)) {
 			err = unmark_stack_slots_iter(env, reg, nr_slots);
 			if (err)
@@ -11073,8 +11112,8 @@ static int idstack_pop(struct bpf_idmap *idmap)
 	return idmap->map[--idmap->cnt].old;
 }
 
-/* Release id and objects derived from it iteratively in a DFS manner */
-static int release_reference(struct bpf_verifier_env *env, int id)
+/* Invalidate id and objects derived from it iteratively in a DFS manner */
+static int invalidate_reference(struct bpf_verifier_env *env, int id)
 {
 	u32 mask = (1 << STACK_SPILL) | (1 << STACK_DYNPTR);
 	struct bpf_verifier_state *vstate = env->cur_state;
@@ -11089,11 +11128,6 @@ static int release_reference(struct bpf_verifier_env *env, int id)
 	if (err)
 		return err;
 
-	if (find_reference_state(vstate, id)) {
-		err = release_reference_nomark(env, id);
-		WARN_ON_ONCE(err);
-	}
-
 	while ((id = idstack_pop(idstack))) {
 		/*
 		 * Child references are inaccessible after parent is released,
@@ -11145,6 +11179,14 @@ static int release_reference(struct bpf_verifier_env *env, int id)
 	return 0;
 }
 
+static int release_reference(struct bpf_verifier_env *env, int id)
+{
+	if (find_reference_state(env->cur_state, id))
+		WARN_ON_ONCE(release_reference_nomark(env, id));
+
+	return invalidate_reference(env, id);
+}
+
 static void invalidate_non_owning_refs(struct bpf_verifier_env *env)
 {
 	struct bpf_func_state *unused;
@@ -15822,6 +15864,8 @@ static int check_kfunc_call(struct bpf_verifier_env *env, struct bpf_insn *insn,
 			regs[BPF_REG_0].btf = desc_btf;
 			regs[BPF_REG_0].type = type;
 			regs[BPF_REG_0].btf_id = ptr_type_id;
+			if (iter_next_borrows_struct(&meta) && !(type & MEM_RCU))
+				regs[BPF_REG_0].parent_id = meta.ref_obj.id;
 		}
 
 		if (is_kfunc_ret_null(&meta)) {
diff --git a/tools/testing/selftests/bpf/progs/iters_testmod.c b/tools/testing/selftests/bpf/progs/iters_testmod.c
index 145750bb64ef8..8896335668b47 100644
--- a/tools/testing/selftests/bpf/progs/iters_testmod.c
+++ b/tools/testing/selftests/bpf/progs/iters_testmod.c
@@ -8,6 +8,44 @@
 
 char _license[] SEC("license") = "GPL";
 
+struct bpf_iter_testmod_current {
+	u64 __opaque;
+};
+
+SEC("raw_tp/sys_enter")
+__success
+int iter_independent_lifetime_after_next(const void *ctx)
+{
+	struct bpf_iter_testmod_current it;
+	struct task_struct *task;
+
+	bpf_iter_testmod_current_new(&it);
+	task = bpf_iter_testmod_current_next(&it);
+	if (!task)
+		goto out;
+
+	bpf_iter_testmod_current_next(&it);
+	bpf_kfunc_trusted_task_test(task);
+out:
+	bpf_iter_testmod_current_destroy(&it);
+	return 0;
+}
+
+SEC("raw_tp/sys_enter")
+__success
+int iter_independent_lifetime_after_destroy(const void *ctx)
+{
+	struct bpf_iter_testmod_current it;
+	struct task_struct *task;
+
+	bpf_iter_testmod_current_new(&it);
+	task = bpf_iter_testmod_current_next(&it);
+	bpf_iter_testmod_current_destroy(&it);
+	if (task)
+		bpf_kfunc_trusted_task_test(task);
+	return 0;
+}
+
 SEC("raw_tp/sys_enter")
 __success
 int iter_next_trusted(const void *ctx)
@@ -28,6 +66,298 @@ int iter_next_trusted(const void *ctx)
 	return 0;
 }
 
+SEC("raw_tp/sys_enter")
+__failure __msg("invalid mem access 'scalar'")
+int iter_next_trusted_after_destroy(const void *ctx)
+{
+	struct task_struct *cur_task = bpf_get_current_task_btf();
+	struct bpf_iter_task_vma vma_it;
+	struct vm_area_struct *vma_ptr;
+
+	bpf_iter_task_vma_new(&vma_it, cur_task, 0);
+
+	vma_ptr = bpf_iter_task_vma_next(&vma_it);
+	if (!vma_ptr)
+		goto out;
+
+	bpf_iter_task_vma_destroy(&vma_it);
+	return vma_ptr->vm_start;
+out:
+	bpf_iter_task_vma_destroy(&vma_it);
+	return 0;
+}
+
+SEC("raw_tp/sys_enter")
+__failure __msg("invalid mem access 'scalar'")
+int iter_next_trusted_after_next(const void *ctx)
+{
+	struct task_struct *cur_task = bpf_get_current_task_btf();
+	struct bpf_iter_task_vma vma_it;
+	struct vm_area_struct *vma_ptr, *next_vma_ptr;
+	u64 vm_start;
+
+	bpf_iter_task_vma_new(&vma_it, cur_task, 0);
+
+	vma_ptr = bpf_iter_task_vma_next(&vma_it);
+	if (!vma_ptr)
+		goto out;
+
+	next_vma_ptr = bpf_iter_task_vma_next(&vma_it);
+	if (!next_vma_ptr)
+		goto out;
+
+	vm_start = vma_ptr->vm_start;
+	bpf_iter_task_vma_destroy(&vma_it);
+	return vm_start;
+out:
+	bpf_iter_task_vma_destroy(&vma_it);
+	return 0;
+}
+
+SEC("raw_tp/sys_enter")
+__failure __msg("invalid mem access 'scalar'")
+int iter_next_trusted_after_next_null(const void *ctx)
+{
+	struct task_struct *cur_task = bpf_get_current_task_btf();
+	struct bpf_iter_task_vma vma_it;
+	struct vm_area_struct *vma_ptr, *next_vma_ptr;
+	u64 vm_start;
+
+	bpf_iter_task_vma_new(&vma_it, cur_task, 0);
+
+	vma_ptr = bpf_iter_task_vma_next(&vma_it);
+	if (!vma_ptr)
+		goto out;
+
+	next_vma_ptr = bpf_iter_task_vma_next(&vma_it);
+	if (next_vma_ptr)
+		goto out;
+
+	vm_start = vma_ptr->vm_start;
+	bpf_iter_task_vma_destroy(&vma_it);
+	return vm_start;
+out:
+	bpf_iter_task_vma_destroy(&vma_it);
+	return 0;
+}
+
+SEC("raw_tp/sys_enter")
+__failure __msg("invalid mem access 'scalar'")
+int iter_next_trusted_field_after_destroy(const void *ctx)
+{
+	struct task_struct *cur_task = bpf_get_current_task_btf();
+	struct bpf_iter_task_vma vma_it;
+	struct vm_area_struct *vma_ptr;
+	struct file *file_ptr;
+
+	bpf_iter_task_vma_new(&vma_it, cur_task, 0);
+
+	vma_ptr = bpf_iter_task_vma_next(&vma_it);
+	if (!vma_ptr)
+		goto out;
+
+	file_ptr = vma_ptr->vm_file;
+	bpf_iter_task_vma_destroy(&vma_it);
+	if (file_ptr)
+		return file_ptr->f_mode;
+	return 0;
+out:
+	bpf_iter_task_vma_destroy(&vma_it);
+	return 0;
+}
+
+SEC("raw_tp/sys_enter")
+__failure __msg("invalid mem access 'scalar'")
+int iter_next_trusted_field_after_next(const void *ctx)
+{
+	struct task_struct *cur_task = bpf_get_current_task_btf();
+	struct bpf_iter_task_vma vma_it;
+	struct vm_area_struct *vma_ptr, *next_vma_ptr;
+	struct file *file_ptr;
+	u32 mode;
+
+	bpf_iter_task_vma_new(&vma_it, cur_task, 0);
+
+	vma_ptr = bpf_iter_task_vma_next(&vma_it);
+	if (!vma_ptr)
+		goto out;
+
+	file_ptr = vma_ptr->vm_file;
+	if (!file_ptr)
+		goto out;
+
+	next_vma_ptr = bpf_iter_task_vma_next(&vma_it);
+	if (!next_vma_ptr)
+		goto out;
+
+	mode = file_ptr->f_mode;
+	bpf_iter_task_vma_destroy(&vma_it);
+	return mode;
+out:
+	bpf_iter_task_vma_destroy(&vma_it);
+	return 0;
+}
+
+SEC("raw_tp/sys_enter")
+__failure __msg("Leaking reference id=")
+int iter_next_file_dynptr_after_next(const void *ctx)
+{
+	struct task_struct *cur_task = bpf_get_current_task_btf();
+	struct bpf_iter_task_vma vma_it;
+	struct vm_area_struct *vma_ptr;
+	struct bpf_dynptr dynptr;
+	struct file *file_ptr;
+
+	bpf_iter_task_vma_new(&vma_it, cur_task, 0);
+
+	vma_ptr = bpf_iter_task_vma_next(&vma_it);
+	if (!vma_ptr)
+		goto out;
+
+	file_ptr = vma_ptr->vm_file;
+	if (!file_ptr)
+		goto out;
+
+	bpf_dynptr_from_file(file_ptr, 0, &dynptr);
+	bpf_iter_task_vma_next(&vma_it);
+	bpf_dynptr_file_discard(&dynptr);
+out:
+	bpf_iter_task_vma_destroy(&vma_it);
+	return 0;
+}
+
+SEC("raw_tp/sys_enter")
+__failure __msg("Leaking reference id=")
+int iter_next_file_dynptr_after_destroy(const void *ctx)
+{
+	struct task_struct *cur_task = bpf_get_current_task_btf();
+	struct bpf_iter_task_vma vma_it;
+	struct vm_area_struct *vma_ptr;
+	struct bpf_dynptr dynptr;
+	struct file *file_ptr;
+
+	bpf_iter_task_vma_new(&vma_it, cur_task, 0);
+
+	vma_ptr = bpf_iter_task_vma_next(&vma_it);
+	if (!vma_ptr)
+		goto out;
+
+	file_ptr = vma_ptr->vm_file;
+	if (!file_ptr)
+		goto out;
+
+	bpf_dynptr_from_file(file_ptr, 0, &dynptr);
+	bpf_iter_task_vma_destroy(&vma_it);
+	bpf_dynptr_file_discard(&dynptr);
+	return 0;
+out:
+	bpf_iter_task_vma_destroy(&vma_it);
+	return 0;
+}
+
+SEC("raw_tp/sys_enter")
+__success
+int iter_next_file_dynptr_discard_before_advance(const void *ctx)
+{
+	struct task_struct *cur_task = bpf_get_current_task_btf();
+	struct bpf_iter_task_vma vma_it;
+	struct vm_area_struct *vma_ptr;
+	struct bpf_dynptr dynptr;
+	struct file *file_ptr;
+
+	bpf_iter_task_vma_new(&vma_it, cur_task, 0);
+
+	vma_ptr = bpf_iter_task_vma_next(&vma_it);
+	if (!vma_ptr)
+		goto out;
+
+	file_ptr = vma_ptr->vm_file;
+	if (!file_ptr)
+		goto out;
+
+	bpf_dynptr_from_file(file_ptr, 0, &dynptr);
+	bpf_dynptr_file_discard(&dynptr);
+	bpf_iter_task_vma_next(&vma_it);
+out:
+	bpf_iter_task_vma_destroy(&vma_it);
+	return 0;
+}
+
+SEC("raw_tp/sys_enter")
+__success
+int iter_next_trusted_current_after_next(const void *ctx)
+{
+	struct task_struct *cur_task = bpf_get_current_task_btf();
+	struct bpf_iter_task_vma vma_it;
+	struct vm_area_struct *vma_ptr;
+
+	bpf_iter_task_vma_new(&vma_it, cur_task, 0);
+
+	vma_ptr = bpf_iter_task_vma_next(&vma_it);
+	if (!vma_ptr)
+		goto out;
+
+	vma_ptr = bpf_iter_task_vma_next(&vma_it);
+	if (vma_ptr)
+		bpf_kfunc_trusted_vma_test(vma_ptr);
+out:
+	bpf_iter_task_vma_destroy(&vma_it);
+	return 0;
+}
+
+SEC("raw_tp/sys_enter")
+__success
+int iter_next_trusted_rcu_field_after_destroy(const void *ctx)
+{
+	struct task_struct *cur_task = bpf_get_current_task_btf();
+	struct bpf_iter_task_vma vma_it;
+	struct vm_area_struct *vma_ptr;
+	struct mm_struct *mm_ptr;
+	struct file *file_ptr = NULL;
+
+	bpf_iter_task_vma_new(&vma_it, cur_task, 0);
+
+	vma_ptr = bpf_iter_task_vma_next(&vma_it);
+	if (vma_ptr) {
+		mm_ptr = vma_ptr->vm_mm;
+		/* exe_file has RCU protection independent of the iterator. */
+		if (mm_ptr)
+			file_ptr = mm_ptr->exe_file;
+	}
+
+	bpf_iter_task_vma_destroy(&vma_it);
+	if (file_ptr)
+		return file_ptr->f_mode;
+	return 0;
+}
+
+SEC("raw_tp/sys_enter")
+__success
+int iter_next_trusted_rcu_field_after_next(const void *ctx)
+{
+	struct task_struct *cur_task = bpf_get_current_task_btf();
+	struct bpf_iter_task_vma vma_it;
+	struct vm_area_struct *vma_ptr;
+	struct mm_struct *mm_ptr;
+	struct file *file_ptr = NULL;
+	u32 mode = 0;
+
+	bpf_iter_task_vma_new(&vma_it, cur_task, 0);
+
+	vma_ptr = bpf_iter_task_vma_next(&vma_it);
+	if (vma_ptr) {
+		mm_ptr = vma_ptr->vm_mm;
+		if (mm_ptr)
+			file_ptr = mm_ptr->exe_file;
+	}
+
+	bpf_iter_task_vma_next(&vma_it);
+	if (file_ptr)
+		mode = file_ptr->f_mode;
+	bpf_iter_task_vma_destroy(&vma_it);
+	return mode;
+}
+
 SEC("raw_tp/sys_enter")
 __failure __msg("Possibly NULL pointer passed to trusted R1")
 int iter_next_trusted_or_null(const void *ctx)
@@ -77,6 +407,46 @@ int iter_next_rcu(const void *ctx)
 	return 0;
 }
 
+SEC("raw_tp/sys_enter")
+__success
+int iter_next_rcu_after_destroy(const void *ctx)
+{
+	struct task_struct *cur_task = bpf_get_current_task_btf();
+	struct bpf_iter_task task_it;
+	struct task_struct *task_ptr;
+
+	bpf_iter_task_new(&task_it, cur_task, 0);
+
+	task_ptr = bpf_iter_task_next(&task_it);
+	bpf_iter_task_destroy(&task_it);
+	if (!task_ptr)
+		return 0;
+
+	bpf_kfunc_rcu_task_test(task_ptr);
+	return 0;
+}
+
+SEC("raw_tp/sys_enter")
+__success
+int iter_next_rcu_after_next(const void *ctx)
+{
+	struct task_struct *cur_task = bpf_get_current_task_btf();
+	struct bpf_iter_task task_it;
+	struct task_struct *task_ptr;
+
+	bpf_iter_task_new(&task_it, cur_task, 0);
+
+	task_ptr = bpf_iter_task_next(&task_it);
+	if (!task_ptr)
+		goto out;
+
+	bpf_iter_task_next(&task_it);
+	bpf_kfunc_rcu_task_test(task_ptr);
+out:
+	bpf_iter_task_destroy(&task_it);
+	return 0;
+}
+
 SEC("raw_tp/sys_enter")
 __failure __msg("Possibly NULL pointer passed to trusted R1")
 int iter_next_rcu_or_null(const void *ctx)
diff --git a/tools/testing/selftests/bpf/progs/verifier_vfs_accept.c b/tools/testing/selftests/bpf/progs/verifier_vfs_accept.c
index 55398c04290a8..25f37a3dd7cfb 100644
--- a/tools/testing/selftests/bpf/progs/verifier_vfs_accept.c
+++ b/tools/testing/selftests/bpf/progs/verifier_vfs_accept.c
@@ -11,6 +11,23 @@
 
 static char buf[64];
 
+SEC("lsm.s/file_open")
+__success
+int BPF_PROG(inode_field_before_file_put)
+{
+	struct file *file;
+	ino_t ino;
+
+	file = bpf_get_task_exe_file(bpf_get_current_task_btf());
+	if (!file)
+		return 0;
+
+	ino = file->f_inode->i_ino;
+	bpf_put_file(file);
+	__sink(ino);
+	return 0;
+}
+
 SEC("lsm.s/file_open")
 __success
 int BPF_PROG(get_task_exe_file_and_put_kfunc_from_current_sleepable)
diff --git a/tools/testing/selftests/bpf/progs/verifier_vfs_reject.c b/tools/testing/selftests/bpf/progs/verifier_vfs_reject.c
index b5f456d57669e..ed2bd2faebf36 100644
--- a/tools/testing/selftests/bpf/progs/verifier_vfs_reject.c
+++ b/tools/testing/selftests/bpf/progs/verifier_vfs_reject.c
@@ -12,6 +12,25 @@
 
 static char buf[PATH_MAX];
 
+SEC("lsm.s/file_open")
+__failure __msg("invalid mem access 'scalar'")
+int BPF_PROG(inode_field_after_file_put)
+{
+	struct inode *inode;
+	struct file *file;
+	ino_t ino;
+
+	file = bpf_get_task_exe_file(bpf_get_current_task_btf());
+	if (!file)
+		return 0;
+
+	inode = file->f_inode;
+	bpf_put_file(file);
+	ino = inode->i_ino;
+	__sink(ino);
+	return 0;
+}
+
 SEC("lsm.s/file_open")
 __failure __msg("Possibly NULL pointer passed to trusted R1")
 int BPF_PROG(get_task_exe_file_kfunc_null)
diff --git a/tools/testing/selftests/bpf/test_kmods/bpf_testmod.c b/tools/testing/selftests/bpf/test_kmods/bpf_testmod.c
index 6380f52f4dd2c..76fbe64755ef9 100644
--- a/tools/testing/selftests/bpf/test_kmods/bpf_testmod.c
+++ b/tools/testing/selftests/bpf/test_kmods/bpf_testmod.c
@@ -281,6 +281,27 @@ __bpf_kfunc void bpf_iter_testmod_seq_destroy(struct bpf_iter_testmod_seq *it)
 	it->cnt = 0;
 }
 
+__bpf_kfunc int bpf_iter_testmod_current_new(struct bpf_iter_testmod_current *it)
+{
+	it->remaining = 2;
+	return 0;
+}
+
+__bpf_kfunc struct task_struct *
+bpf_iter_testmod_current_next(struct bpf_iter_testmod_current *it)
+{
+	if (!it->remaining)
+		return NULL;
+	it->remaining--;
+	/* current remains alive independently of the iterator. */
+	return current;
+}
+
+__bpf_kfunc void bpf_iter_testmod_current_destroy(struct bpf_iter_testmod_current *it)
+{
+	it->remaining = 0;
+}
+
 __bpf_kfunc void bpf_kfunc_common_test(void)
 {
 }
@@ -1016,6 +1037,10 @@ BTF_ID_FLAGS(func, bpf_iter_testmod_seq_new, KF_ITER_NEW)
 BTF_ID_FLAGS(func, bpf_iter_testmod_seq_next, KF_ITER_NEXT | KF_RET_NULL)
 BTF_ID_FLAGS(func, bpf_iter_testmod_seq_destroy, KF_ITER_DESTROY)
 BTF_ID_FLAGS(func, bpf_iter_testmod_seq_value)
+BTF_ID_FLAGS(func, bpf_iter_testmod_current_new, KF_ITER_NEW)
+BTF_ID_FLAGS(func, bpf_iter_testmod_current_next,
+	     KF_ITER_NEXT | KF_RET_NULL | KF_ITER_RET_INDEPENDENT)
+BTF_ID_FLAGS(func, bpf_iter_testmod_current_destroy, KF_ITER_DESTROY)
 BTF_ID_FLAGS(func, bpf_kfunc_common_test)
 BTF_ID_FLAGS(func, bpf_kfunc_arena_arg_test)
 BTF_ID_FLAGS(func, bpf_kfunc_arena_cap_test)
diff --git a/tools/testing/selftests/bpf/test_kmods/bpf_testmod.h b/tools/testing/selftests/bpf/test_kmods/bpf_testmod.h
index 4ba9def74404b..aef780261ef4f 100644
--- a/tools/testing/selftests/bpf/test_kmods/bpf_testmod.h
+++ b/tools/testing/selftests/bpf/test_kmods/bpf_testmod.h
@@ -31,6 +31,10 @@ struct bpf_iter_testmod_seq {
 	int cnt;
 };
 
+struct bpf_iter_testmod_current {
+	u64 remaining;
+};
+
 struct bpf_testmod_ops {
 	int (*test_1)(void);
 	void (*test_2)(int a, int b);
diff --git a/tools/testing/selftests/bpf/test_kmods/bpf_testmod_kfunc.h b/tools/testing/selftests/bpf/test_kmods/bpf_testmod_kfunc.h
index 3b810f1e438f7..e9902e651d72b 100644
--- a/tools/testing/selftests/bpf/test_kmods/bpf_testmod_kfunc.h
+++ b/tools/testing/selftests/bpf/test_kmods/bpf_testmod_kfunc.h
@@ -33,6 +33,11 @@ struct prog_test_ref_kfunc {
 #endif
 
 struct bpf_iter_testmod_seq;
+struct bpf_iter_testmod_current;
+
+int bpf_iter_testmod_current_new(struct bpf_iter_testmod_current *it) __ksym;
+struct task_struct *bpf_iter_testmod_current_next(struct bpf_iter_testmod_current *it) __ksym;
+void bpf_iter_testmod_current_destroy(struct bpf_iter_testmod_current *it) __ksym;
 
 struct prog_test_pass1 {
 	int x0;

3/2 2026/10/24 15:12 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 13001
							output: 34
							thoughts: 949
						

Thoughts:
**Fuzzing Decision for the BPF Verifier Patch**

Okay, let's break this down. We've got a patch touching the BPF subsystem, specifically the verifier and BTF, on amd64. Straight away, I'm thinking syzkaller potential here.

Looking at the changes, we've got modifications to `btf.h`, `btf.c`, and the verifier itself (`verifier.c`). The verifier is a critical piece, and any change there needs a good look. We have new definitions and checks in `btf_check_iter_kfuncs` and `btf_check_kfunc_protos` related to `KF_ITER_RET_INDEPENDENT`. We have new functions in the verifier (`invalidate_reference`, `reg_lifetime_id`, `iter_next_borrows_struct`) and modifications to existing functions like `mark_stack_slots_dynptr`, `unmark_stack_slots_iter`, `check_ptr_to_btf_access`, `process_iter_arg`, and `check_kfunc_call`. It seems that the patch is changing how the verifier tracks lifetimes and parent IDs of pointers returned by iterator "next" methods and pointers derived from BTF accesses. References are being invalidated when we call `next` or when iterators are destroyed. This *directly* impacts how the verifier validates BPF programs.

The "Return WorthFuzzing=true" criteria definitely applies here. BPF is a core subsystem and this patch touches executable code reachable via the `bpf()` syscall (`BPF_PROG_LOAD`). This is a clear "yes" for fuzzing. We are modifying core verifier logic.

Now, let's identify the specific functions and configs we'll need for syzkaller. I'll need to go hunting for the key symbols and potentially any associated config options. This should allow us to build a more effective fuzzing campaign.



4/2 2026/10/24 15:12 tool grepper
0m Args:
{
  "Expression": "CONFIG_BPF_SYSCALL",
  "PathPrefixes": [
    "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 loops.o scev.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\n--\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\n--\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=47=ifeq ($(CONFIG_BPF_JIT),y)\nkernel/bpf/Makefile:48:obj-$(CONFIG_BPF_SYSCALL) += bpf_struct_ops.o\nkernel/bpf/Makefile:49:obj-$(CONFIG_BPF_SYSCALL) += cpumask.o\nkernel/bpf/Makefile-50-# bpf_lsm_proto.o must precede bpf_lsm.o. The current pahole logic\n--\nkernel/bpf/Makefile=63=obj-$(CONFIG_BPF_PRELOAD) += preload/\nkernel/bpf/Makefile-64-\nkernel/bpf/Makefile:65:obj-$(CONFIG_BPF_SYSCALL) += relo_core.o\nkernel/bpf/Makefile:66:obj-$(CONFIG_BPF_SYSCALL) += btf_iter.o\nkernel/bpf/Makefile:67:obj-$(CONFIG_BPF_SYSCALL) += btf_relocate.o\nkernel/bpf/Makefile:68:obj-$(CONFIG_BPF_SYSCALL) += kmem_cache_iter.o\nkernel/bpf/Makefile-69-ifeq ($(CONFIG_DMA_SHARED_BUFFER),y)\nkernel/bpf/Makefile:70:obj-$(CONFIG_BPF_SYSCALL) += dmabuf_iter.o\nkernel/bpf/Makefile-71-endif\n--\nkernel/bpf/core.c=286=void __bpf_prog_free(struct bpf_prog *fp)\n--\nkernel/bpf/core.c-288-\tif (fp-\u003eaux) {\nkernel/bpf/core.c:289:#ifdef CONFIG_BPF_SYSCALL\nkernel/bpf/core.c-290-\t\tbpf_prog_stream_free(fp);\n--\nkernel/bpf/core.c=2480=EVAL4(PROG_NAME_LIST, 416, 448, 480, 512)\n--\nkernel/bpf/core.c-2483-\nkernel/bpf/core.c:2484:#ifdef CONFIG_BPF_SYSCALL\nkernel/bpf/core.c-2485-int bpf_patch_call_args(struct bpf_insn *insn, u32 stack_depth)\n--\nkernel/bpf/core.c=3124=void __bpf_free_used_btfs(struct btf_mod_pair *used_btfs, u32 len)\nkernel/bpf/core.c-3125-{\nkernel/bpf/core.c:3126:#ifdef CONFIG_BPF_SYSCALL\nkernel/bpf/core.c-3127-\tstruct btf_mod_pair *btf_mod;\n--\nkernel/bpf/core.c=3167=static void bpf_prog_free_deferred(struct work_struct *work)\n--\nkernel/bpf/core.c-3178-\tbpf_prog_kallsyms_del_all(aux-\u003eprog);\nkernel/bpf/core.c:3179:#ifdef CONFIG_BPF_SYSCALL\nkernel/bpf/core.c-3180-\tbpf_free_kfunc_btf_tab(aux-\u003ekfunc_btf_tab);\n--\nkernel/bpf/core.c=3620=static noinline void bpf_prog_report_may_goto_violation(void)\nkernel/bpf/core.c-3621-{\nkernel/bpf/core.c:3622:#ifdef CONFIG_BPF_SYSCALL\nkernel/bpf/core.c-3623-\tstruct bpf_stream_stage ss;\n--\nkernel/bpf/core.c=3660=__weak u64 bpf_arena_get_kern_vm_start(struct bpf_arena *arena)\n--\nkernel/bpf/core.c-3664-\nkernel/bpf/core.c:3665:#ifdef CONFIG_BPF_SYSCALL\nkernel/bpf/core.c-3666-__weak bool bpf_arena_handle_page_fault(unsigned long addr, bool is_write,\n--\nkernel/bpf/core.c=3691=EXPORT_TRACEPOINT_SYMBOL_GPL(xdp_bulk_tx);\nkernel/bpf/core.c-3692-\nkernel/bpf/core.c:3693:#ifdef CONFIG_BPF_SYSCALL\nkernel/bpf/core.c-3694-\n--\nkernel/bpf/trampoline.c=1566=int __weak arch_bpf_trampoline_size(const struct btf_func_model *m, u32 flags,\n--\nkernel/bpf/trampoline.c-1573-    defined(CONFIG_HAVE_SINGLE_FTRACE_DIRECT_OPS) \u0026\u0026 \\\nkernel/bpf/trampoline.c:1574:    defined(CONFIG_BPF_SYSCALL)\nkernel/bpf/trampoline.c-1575-\n--\nkernel/bpf/trampoline.c=1826=void bpf_trampoline_multi_detach(struct bpf_prog *prog,\n--\nkernel/bpf/trampoline.c-1863-\t  CONFIG_HAVE_SINGLE_FTRACE_DIRECT_OPS \u0026\u0026\nkernel/bpf/trampoline.c:1864:\t  CONFIG_BPF_SYSCALL */\nkernel/bpf/trampoline.c-1865-\n"
}

5/2 2026/10/24 15:12 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 16798
							output: 41
							thoughts: 66
						

Thoughts:
Okay, let's see, my initial observation is that `verifier.o` and `btf.o` both have a dependency on `CONFIG_BPF_SYSCALL`. That's a reasonable starting point, but I need to understand the broader context. My next thought is, are there other configuration options that indirectly influence the build of these modules, particularly those relating to open-coded iterators or BTF specifically? I'll need to dive into the source code of `kernel/bpf/verifier.c` and `kernel/bpf/btf.c` to see if there are any other config options influencing the build of these object files. Need to check for config symbols in the `if` conditions in the source to form a complete understanding.



6/2 2026/10/24 15:12 tool grepper
0m Args:
{
  "Expression": "CONFIG_DEBUG_INFO_BTF",
  "PathPrefixes": [
    "kernel/bpf/",
    "init/Kconfig"
  ]
}

Results:
{
  "Output": "kernel/bpf/Makefile=43=ifeq ($(CONFIG_SYSFS),y)\nkernel/bpf/Makefile:44:obj-$(CONFIG_DEBUG_INFO_BTF) += sysfs_btf.o\nkernel/bpf/Makefile:45:obj-$(CONFIG_DEBUG_INFO_BTF_INLINE) += btf_vmlinux_inline.o\nkernel/bpf/Makefile-46-endif\n--\nkernel/bpf/btf.c=6851=static struct btf *btf_parse_base(struct btf_verifier_env *env, const char *name,\n--\nkernel/bpf/btf.c-6856-\nkernel/bpf/btf.c:6857:\tif (!IS_ENABLED(CONFIG_DEBUG_INFO_BTF))\nkernel/bpf/btf.c-6858-\t\treturn ERR_PTR(-ENOENT);\n--\nkernel/bpf/btf.c=6937=__u32 btf_relocate_id(const struct btf *btf, __u32 id)\n--\nkernel/bpf/btf.c-6943-\nkernel/bpf/btf.c:6944:#ifdef CONFIG_DEBUG_INFO_BTF_MODULES\nkernel/bpf/btf.c-6945-\n--\nkernel/bpf/btf.c=7062=static struct btf *btf_parse_module(const char *module_name, const void *data,\n--\nkernel/bpf/btf.c-7164-\nkernel/bpf/btf.c:7165:#endif /* CONFIG_DEBUG_INFO_BTF_MODULES */\nkernel/bpf/btf.c-7166-\n--\nkernel/bpf/btf.c=9291=enum {\n--\nkernel/bpf/btf.c-9294-\nkernel/bpf/btf.c:9295:#ifdef CONFIG_DEBUG_INFO_BTF_MODULES\nkernel/bpf/btf.c-9296-struct btf_module {\n--\nkernel/bpf/btf.c=9309=static void purge_cand_cache(struct btf *btf);\nkernel/bpf/btf.c-9310-\nkernel/bpf/btf.c:9311:#if IS_MODULE(CONFIG_DEBUG_INFO_BTF_INLINE)\nkernel/bpf/btf.c-9312-extern char __start_BTF_inline_link[];\n--\nkernel/bpf/btf.c=9409=static void btf_vmlinux_inline_lazy_init(void)\n--\nkernel/bpf/btf.c-9412-\nkernel/bpf/btf.c:9413:#endif /* IS_MODULE(CONFIG_DEBUG_INFO_BTF_INLINE) */\nkernel/bpf/btf.c-9414-\nkernel/bpf/btf.c=9415=static int btf_module_notify(struct notifier_block *nb, unsigned long op,\n--\nkernel/bpf/btf.c-9436-\nkernel/bpf/btf.c:9437:#if IS_ENABLED(CONFIG_DEBUG_INFO_BTF_INLINE)\nkernel/bpf/btf.c-9438-\t\tif (mod-\u003ebtf_inline_data_size) {\n--\nkernel/bpf/btf.c=9560=fs_initcall(btf_module_init);\nkernel/bpf/btf.c:9561:#endif /* CONFIG_DEBUG_INFO_BTF_MODULES */\nkernel/bpf/btf.c-9562-\nkernel/bpf/btf.c=9563=struct module *btf_try_get_module(const struct btf *btf)\n--\nkernel/bpf/btf.c-9565-\tstruct module *res = NULL;\nkernel/bpf/btf.c:9566:#ifdef CONFIG_DEBUG_INFO_BTF_MODULES\nkernel/bpf/btf.c-9567-\tstruct btf_module *btf_mod, *tmp;\n--\nkernel/bpf/btf.c=9593=struct btf *btf_get_module_btf(const struct module *module)\nkernel/bpf/btf.c-9594-{\nkernel/bpf/btf.c:9595:#ifdef CONFIG_DEBUG_INFO_BTF_MODULES\nkernel/bpf/btf.c-9596-\tstruct btf_module *btf_mod, *tmp;\n--\nkernel/bpf/btf.c-9606-\nkernel/bpf/btf.c:9607:#ifdef CONFIG_DEBUG_INFO_BTF_MODULES\nkernel/bpf/btf.c-9608-\tmutex_lock(\u0026btf_module_mutex);\n--\nkernel/bpf/btf.c=9623=static int check_btf_kconfigs(const struct module *module, const char *feature)\nkernel/bpf/btf.c-9624-{\nkernel/bpf/btf.c:9625:\tif (!module \u0026\u0026 IS_ENABLED(CONFIG_DEBUG_INFO_BTF)) {\nkernel/bpf/btf.c-9626-\t\tpr_err(\"missing vmlinux BTF, cannot register %s\\n\", feature);\n--\nkernel/bpf/btf.c-9628-\t}\nkernel/bpf/btf.c:9629:\tif (module \u0026\u0026 IS_ENABLED(CONFIG_DEBUG_INFO_BTF_MODULES))\nkernel/bpf/btf.c-9630-\t\tpr_warn(\"missing module BTF, cannot register %s\\n\", feature);\n--\nkernel/bpf/btf.c=9781=static int btf_check_kfunc_name(struct btf *btf, const char *func_name, u32 kind)\nkernel/bpf/btf.c-9782-{\nkernel/bpf/btf.c:9783:#ifdef CONFIG_DEBUG_INFO_BTF_MODULES\nkernel/bpf/btf.c-9784-\tstruct btf_module *btf_mod, *tmp;\n--\nkernel/bpf/btf.c-9797-\nkernel/bpf/btf.c:9798:#ifdef CONFIG_DEBUG_INFO_BTF_MODULES\nkernel/bpf/btf.c-9799-\tguard(mutex)(\u0026btf_module_mutex);\n--\nkernel/bpf/btf.c=10447=static struct bpf_cand_cache *populate_cand_cache(struct bpf_cand_cache *cands,\n--\nkernel/bpf/btf.c-10474-\nkernel/bpf/btf.c:10475:#ifdef CONFIG_DEBUG_INFO_BTF_MODULES\nkernel/bpf/btf.c-10476-static void __purge_cand_cache(struct btf *btf, struct bpf_cand_cache **cache,\n--\nkernel/bpf/btf_vmlinux_inline.c-10-\nkernel/bpf/btf_vmlinux_inline.c:11:#if IS_BUILTIN(CONFIG_DEBUG_INFO_BTF_INLINE)\nkernel/bpf/btf_vmlinux_inline.c-12-extern char __start_BTF_inline[];\n--\nkernel/bpf/btf_vmlinux_inline.c=16=static int __init btf_vmlinux_inline_init(void)\nkernel/bpf/btf_vmlinux_inline.c-17-{\nkernel/bpf/btf_vmlinux_inline.c:18:#if IS_BUILTIN(CONFIG_DEBUG_INFO_BTF_INLINE)\nkernel/bpf/btf_vmlinux_inline.c-19-\tsize_t data_size = __stop_BTF_inline - __start_BTF_inline;\n--\nkernel/bpf/verifier.c=3075=int bpf_add_kfunc_call(struct bpf_verifier_env *env, u32 func_id, u16 offset)\n--\nkernel/bpf/verifier.c-3091-\t\tif (!btf_vmlinux) {\nkernel/bpf/verifier.c:3092:\t\t\tverbose(env, \"calling kernel function is not supported without CONFIG_DEBUG_INFO_BTF\\n\");\nkernel/bpf/verifier.c-3093-\t\t\treturn -ENOTSUPP;\n--\nkernel/bpf/verifier.c=6876=static int check_ptr_to_map_access(struct bpf_verifier_env *env,\n--\nkernel/bpf/verifier.c-6890-\tif (!btf_vmlinux) {\nkernel/bpf/verifier.c:6891:\t\tverbose(env, \"map_ptr access not supported without CONFIG_DEBUG_INFO_BTF\\n\");\nkernel/bpf/verifier.c-6892-\t\treturn -ENOTSUPP;\n--\nkernel/bpf/verifier.c=20929=static int check_pseudo_btf_id(struct bpf_verifier_env *env,\n--\nkernel/bpf/verifier.c-20945-\t\tif (!btf_vmlinux) {\nkernel/bpf/verifier.c:20946:\t\t\tverbose(env, \"kernel is missing BTF, make sure CONFIG_DEBUG_INFO_BTF=y is specified in Kconfig.\\n\");\nkernel/bpf/verifier.c-20947-\t\t\treturn -EINVAL;\n--\nkernel/bpf/verifier.c=23146=struct btf *bpf_get_btf_vmlinux(void)\n--\nkernel/bpf/verifier.c-23150-\nkernel/bpf/verifier.c:23151:\tif (!btf \u0026\u0026 IS_ENABLED(CONFIG_DEBUG_INFO_BTF)) {\nkernel/bpf/verifier.c-23152-\t\tmutex_lock(\u0026btf_vmlinux_lock);\n"
}

7/2 2026/10/24 15:12 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 19628
							output: 34
							thoughts: 131
						

Thoughts:
Okay, here's my summary, tailored as requested:

**Assessing BPF Kfunc Support Requirements**

Alright, let's break this down. I'm focusing on `bpf_add_kfunc_call` and immediately see that if we don't have `btf_vmlinux`, we’re dead in the water – it's an unsupported feature. Makes sense, given the reliance on BTF information for resolving these kernel function calls. The code explicitly states that *all* kfuncs, and that *includes* iterators which are crucial for this type of functionality, depend on `CONFIG_DEBUG_INFO_BTF`. Seems pretty clear-cut.

Now, my mind shifts to the configurations at play here. I need to confirm `CONFIG_BPF_SYSCALL` is enabled, and then make sure `CONFIG_DEBUG_INFO_BTF` is also enabled, this is the first thing that jumps out. I also need to go and examine the dependencies of `CONFIG_DEBUG_INFO_BTF` in `lib/Kconfig.debug`. That's where I'll get the real story.



8/2 2026/10/24 15:12 tool grepper
0m Args:
{
  "Expression": "config DEBUG_INFO_BTF",
  "PathPrefixes": [
    "lib/Kconfig.debug"
  ]
}

Results:
{
  "Output": "lib/Kconfig.debug=378=config DEBUG_INFO_SPLIT\n--\nlib/Kconfig.debug-397-\nlib/Kconfig.debug:398:config DEBUG_INFO_BTF\nlib/Kconfig.debug-399-\tbool \"Generate BTF type information\"\n--\nlib/Kconfig.debug=428=config PAHOLE_HAS_INLINE\n--\nlib/Kconfig.debug-433-\nlib/Kconfig.debug:434:config DEBUG_INFO_BTF_MODULES\nlib/Kconfig.debug-435-\tbool \"Generate BTF type information for kernel modules\"\n--\nlib/Kconfig.debug-440-\nlib/Kconfig.debug:441:config DEBUG_INFO_BTF_INLINE\nlib/Kconfig.debug-442-\ttristate \"Provide information about inline sites in BTF\"\n"
}

9/2 2026/10/24 15:12 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 20266
							output: 34
							thoughts: 19
						

Thoughts:
Here's my analysis of the provided text, rendered as a first-person expert summary:

**Digging into the Kconfig.debug file**

Okay, so we're looking at `lib/Kconfig.debug`. I know this file intimately – it's where we manage a lot of the low-level debug and instrumentation options for the kernel and related libraries. Now, the context here is critical. Where should I be focusing? Ah, they're suggesting line 398. That usually means something pretty specific. I'll need to remember to check for any relevant dependencies or conditional statements around that line, too. Let's get to it. Time to dive in.



10/2 2026/10/24 15:12 tool read-file
0m Args:
{
  "File": "lib/Kconfig.debug",
  "FirstLine": 398,
  "LineCount": 35
}

Results:
{
  "Contents": " 398:\tconfig DEBUG_INFO_BTF\n 399:\t\tbool \"Generate BTF type information\"\n 400:\t\tdepends on !DEBUG_INFO_SPLIT \u0026\u0026 !DEBUG_INFO_REDUCED\n 401:\t\tdepends on !GCC_PLUGIN_RANDSTRUCT || COMPILE_TEST\n 402:\t\tdepends on BPF_SYSCALL\n 403:\t\tdepends on PAHOLE_VERSION \u003e= 122\n 404:\t\t# pahole uses elfutils, which does not have support for Hexagon relocations\n 405:\t\tdepends on !HEXAGON\n 406:\t\thelp\n 407:\t\t  Generate deduplicated BTF type information from DWARF debug info.\n 408:\t\t  Turning this on requires pahole v1.22 or later, which will convert\n 409:\t\t  DWARF type info into equivalent deduplicated BTF type info.\n 410:\t\n 411:\tconfig PAHOLE_HAS_BTF_TAG\n 412:\t\tdef_bool PAHOLE_VERSION \u003e= 123\n 413:\t\tdepends on CC_IS_CLANG\n 414:\t\thelp\n 415:\t\t  Decide whether pahole emits btf_tag attributes (btf_type_tag and\n 416:\t\t  btf_decl_tag) or not. Currently only clang compiler implements\n 417:\t\t  these attributes, so make the config depend on CC_IS_CLANG.\n 418:\t\n 419:\tconfig PAHOLE_HAS_LANG_EXCLUDE\n 420:\t\tdef_bool PAHOLE_VERSION \u003e= 124\n 421:\t\thelp\n 422:\t\t  Support for the --lang_exclude flag which makes pahole exclude\n 423:\t\t  compilation units from the supplied language. Used in Kbuild to\n 424:\t\t  omit Rust CUs which are not supported in version 1.24 of pahole,\n 425:\t\t  otherwise it would emit malformed kernel and module binaries when\n 426:\t\t  using DEBUG_INFO_BTF_MODULES.\n 427:\t\n 428:\tconfig PAHOLE_HAS_INLINE\n 429:\t\tdef_bool PAHOLE_VERSION \u003e= 132\n 430:\t\thelp\n 431:\t\t  Support for the \"inline\" BTF feature is available. It encodes\n 432:\t\t  information about inline sites and how to retrieve their parameters.\n"
}

11/2 2026/10/24 15:12 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 21089
							output: 35
							thoughts: 126
						

Thoughts:
**Analyzing the Relationship Between DEBUG_INFO_BTF and BPF_SYSCALL**

Okay, so it looks like `DEBUG_INFO_BTF` has a dependency on `BPF_SYSCALL`, that makes sense. Now I want to dive into the code and see exactly what changes were made that relate to this connection, specifically within `kernel/bpf/verifier.c` and `kernel/bpf/btf.c`. Let's get to it.

Alright, looking at `kernel/bpf/btf.c`, I see a couple of functions that might be relevant: `btf_check_iter_kfuncs` and `btf_check_kfunc_protos`. Both are static, so I'll need to remember that when I'm chasing down their usage.  I'm particularly interested in `btf_check_kfunc_protos`, so let's check its callers to understand where it's being used within the larger context. Knowing that will give me a better understanding of how `DEBUG_INFO_BTF` and `BPF_SYSCALL` are influencing the flow here.



12/2 2026/10/24 15:12 tool grepper
0m Args:
{
  "Expression": "btf_check_kfunc_protos",
  "PathPrefixes": [
    "kernel/bpf/"
  ]
}

Results:
{
  "Output": "kernel/bpf/btf.c=9781=static int btf_check_kfunc_name(struct btf *btf, const char *func_name, u32 kind)\n--\nkernel/bpf/btf.c-9813-\nkernel/bpf/btf.c:9814:static int btf_check_kfunc_protos(struct btf *btf, u32 func_id, u32 func_flags)\nkernel/bpf/btf.c-9815-{\n--\nkernel/bpf/btf.c=10127=static int __register_btf_kfunc_id_set(enum btf_kfunc_hook hook,\n--\nkernel/bpf/btf.c-10139-\tfor (i = 0; i \u003c kset-\u003eset-\u003ecnt; i++) {\nkernel/bpf/btf.c:10140:\t\tret = btf_check_kfunc_protos(btf, btf_relocate_id(btf, kset-\u003eset-\u003epairs[i].id),\nkernel/bpf/btf.c-10141-\t\t\t\t\t     kset-\u003eset-\u003epairs[i].flags);\n"
}

13/2 2026/10/24 15:12 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 21805
							output: 96
							thoughts: 176
						

Thoughts:
**My Analysis of Kfunc Set Registration and Verifier Changes**

Okay, so `register_btf_kfunc_id_set` is triggered during the initialization of the kernel or a module when new kfunc sets are registered. That's my starting point. Now, I want to delve into the modifications within `kernel/bpf/verifier.c` to see how these changes are impacting the BPF verifier's behavior, particularly in the context of kfuncs.

Let's see, the key functions that have been modified are:

1.  `mark_stack_slots_dynptr`
2.  `unmark_stack_slots_iter`
3.  `reg_lifetime_id`
4.  `check_ptr_to_btf_access`
5.  `iter_next_borrows_struct`
6.  `process_iter_arg`
7.  `invalidate_reference`
8.  `release_reference`
9.  `check_kfunc_call`

I need to understand the impact of any changes to these functions; their visibility and callers are key. Are these functions static? That would suggest a more localized impact, or are they exported for use elsewhere? I need to analyze how they're being used within the verifier and potentially beyond. That information will tell me how the BPF verifier's kfunc handling is evolving.



14/2 2026/10/24 15:12 tool grepper
0m Args:
{
  "Expression": "(mark_stack_slots_dynptr|unmark_stack_slots_iter|reg_lifetime_id|check_ptr_to_btf_access|iter_next_borrows_struct|process_iter_arg|invalidate_reference|release_reference|check_kfunc_call)\\(",
  "PathPrefixes": [
    "kernel/bpf/verifier.c"
  ]
}

Results:
{
  "Output": "kernel/bpf/verifier.c=212=static int release_reference_nomark(struct bpf_verifier_env *env, int id);\nkernel/bpf/verifier.c:213:static int release_reference(struct bpf_verifier_env *env, int id);\nkernel/bpf/verifier.c:214:static int invalidate_reference(struct bpf_verifier_env *env, int id);\nkernel/bpf/verifier.c:215:static u32 reg_lifetime_id(struct bpf_verifier_env *env,\nkernel/bpf/verifier.c-216-\t\t\t   const struct bpf_reg_state *reg);\n--\nkernel/bpf/verifier.c=745=static int destroy_dynptrs_in_stack_slots(struct bpf_verifier_env *env,\n--\nkernel/bpf/verifier.c-759-\nkernel/bpf/verifier.c:760:static int mark_stack_slots_dynptr(struct bpf_verifier_env *env, struct bpf_reg_state *reg,\nkernel/bpf/verifier.c-761-\t\t\t\t   enum bpf_arg_type arg_type, int insn_idx,\n--\nkernel/bpf/verifier.c-799-\t\t/* All non-clone constructors take their backing object in R1. */\nkernel/bpf/verifier.c:800:\t\tparent_id = reg_lifetime_id(env, \u0026cur_regs(env)[BPF_REG_1]);\nkernel/bpf/verifier.c-801-\n--\nkernel/bpf/verifier.c=826=static void invalidate_dynptr(struct bpf_verifier_env *env, struct bpf_stack_state *stack)\n--\nkernel/bpf/verifier.c-838-\nkernel/bpf/verifier.c:839:static int unmark_stack_slots_dynptr(struct bpf_verifier_env *env, struct bpf_reg_state *reg)\nkernel/bpf/verifier.c-840-{\n--\nkernel/bpf/verifier.c-853-\treg = \u0026bpf_stack_slot(state, spi)-\u003espilled_ptr;\nkernel/bpf/verifier.c:854:\treturn release_reference(env, dynptr_type_referenced(reg-\u003edynptr.type)\nkernel/bpf/verifier.c-855-\t\t\t\t      ? reg-\u003eparent_id\n--\nkernel/bpf/verifier.c=889=static int destroy_if_dynptr_stack_slot(struct bpf_verifier_env *env,\n--\nkernel/bpf/verifier.c-924-\t/* Invalidate the dynptr and any derived slices */\nkernel/bpf/verifier.c:925:\terr = release_reference(env, slot-\u003espilled_ptr.id);\nkernel/bpf/verifier.c-926-\tif (!err) {\n--\nkernel/bpf/verifier.c=1033=static int mark_stack_slots_iter(struct bpf_verifier_env *env,\n--\nkernel/bpf/verifier.c-1075-\nkernel/bpf/verifier.c:1076:static int unmark_stack_slots_iter(struct bpf_verifier_env *env,\nkernel/bpf/verifier.c-1077-\t\t\t\t   struct bpf_reg_state *reg, int nr_slots)\n--\nkernel/bpf/verifier.c-1090-\t\tif (i == 0) {\nkernel/bpf/verifier.c:1091:\t\t\terr = release_reference(env, st-\u003eid);\nkernel/bpf/verifier.c-1092-\t\t\tif (err)\n--\nkernel/bpf/verifier.c=1631=static bool reg_is_referenced(struct bpf_verifier_env *env, const struct bpf_reg_state *reg)\n--\nkernel/bpf/verifier.c-1635-\nkernel/bpf/verifier.c:1636:static u32 reg_lifetime_id(struct bpf_verifier_env *env,\nkernel/bpf/verifier.c-1637-\t\t\t   const struct bpf_reg_state *reg)\n--\nkernel/bpf/verifier.c=6646=static int check_arena_member_load(struct bpf_verifier_env *env, struct bpf_reg_state *regs,\n--\nkernel/bpf/verifier.c-6679-\nkernel/bpf/verifier.c:6680:static int check_ptr_to_btf_access(struct bpf_verifier_env *env,\nkernel/bpf/verifier.c-6681-\t\t\t\t   struct bpf_reg_state *regs, struct bpf_reg_state *reg,\n--\nkernel/bpf/verifier.c-6862-\tif (atype == BPF_READ \u0026\u0026 value_regno \u003e= 0) {\nkernel/bpf/verifier.c:6863:\t\tu32 parent_id = reg_lifetime_id(env, reg);\nkernel/bpf/verifier.c-6864-\n--\nkernel/bpf/verifier.c=7257=static int check_mem_access(struct bpf_verifier_env *env, int insn_idx, struct bpf_reg_state *reg, argno_t argno,\n--\nkernel/bpf/verifier.c-7448-\t\t   !type_may_be_null(reg-\u003etype)) {\nkernel/bpf/verifier.c:7449:\t\terr = check_ptr_to_btf_access(env, regs, reg, argno, off, size, t,\nkernel/bpf/verifier.c-7450-\t\t\t\t\t      value_regno);\n--\nkernel/bpf/verifier.c=7937=static int check_helper_mem_access(struct bpf_verifier_env *env, struct bpf_reg_state *reg,\n--\nkernel/bpf/verifier.c-8001-\tcase PTR_TO_BTF_ID:\nkernel/bpf/verifier.c:8002:\t\treturn check_ptr_to_btf_access(env, regs, reg, argno, 0,\nkernel/bpf/verifier.c-8003-\t\t\t\t\t       access_size, access_type, -1);\n--\nkernel/bpf/verifier.c=8544=static int process_dynptr_func(struct bpf_verifier_env *env, struct bpf_reg_state *reg,\n--\nkernel/bpf/verifier.c-8583-\nkernel/bpf/verifier.c:8584:\t\terr = mark_stack_slots_dynptr(env, reg, arg_type, insn_idx,\nkernel/bpf/verifier.c-8585-\t\t\t\t\t      \u0026meta-\u003eref_obj, \u0026meta-\u003edynptr);\n--\nkernel/bpf/verifier.c=8651=static bool is_iter_destroy_kfunc(struct bpf_call_arg_meta *meta)\n--\nkernel/bpf/verifier.c-8655-\nkernel/bpf/verifier.c:8656:static bool iter_next_borrows_struct(struct bpf_call_arg_meta *meta)\nkernel/bpf/verifier.c-8657-{\n--\nkernel/bpf/verifier.c=8671=static bool is_kfunc_arg_iter(struct bpf_call_arg_meta *meta, int arg_idx,\n--\nkernel/bpf/verifier.c-8683-\nkernel/bpf/verifier.c:8684:static int process_iter_arg(struct bpf_verifier_env *env, struct bpf_reg_state *reg,\nkernel/bpf/verifier.c-8685-\t\t\t    u32 arg, argno_t argno, int insn_idx,\n--\nkernel/bpf/verifier.c-8781-\t\t/* The iterator stays. What was borrowed from the previous element goes. */\nkernel/bpf/verifier.c:8782:\t\tif (iter_next_borrows_struct(meta)) {\nkernel/bpf/verifier.c:8783:\t\t\terr = invalidate_reference(env, meta-\u003eref_obj.id);\nkernel/bpf/verifier.c-8784-\t\t\tif (err)\n--\nkernel/bpf/verifier.c-8788-\t\tif (is_iter_destroy_kfunc(meta)) {\nkernel/bpf/verifier.c:8789:\t\t\terr = unmark_stack_slots_iter(env, reg, nr_slots);\nkernel/bpf/verifier.c-8790-\t\t\tif (err)\n--\nkernel/bpf/verifier.c=9796=static int check_func_arg(struct bpf_verifier_env *env, u32 arg, u32 slot, u32 prev_slot,\n--\nkernel/bpf/verifier.c-10222-\t\t}\nkernel/bpf/verifier.c:10223:\t\terr = process_iter_arg(env, reg, arg, argno, insn_idx, meta);\nkernel/bpf/verifier.c-10224-\t\tif (err \u003c 0)\n--\nkernel/bpf/verifier.c=11107=static int idstack_pop(struct bpf_idmap *idmap)\n--\nkernel/bpf/verifier.c-11115-/* Invalidate id and objects derived from it iteratively in a DFS manner */\nkernel/bpf/verifier.c:11116:static int invalidate_reference(struct bpf_verifier_env *env, int id)\nkernel/bpf/verifier.c-11117-{\n--\nkernel/bpf/verifier.c-11181-\nkernel/bpf/verifier.c:11182:static int release_reference(struct bpf_verifier_env *env, int id)\nkernel/bpf/verifier.c-11183-{\n--\nkernel/bpf/verifier.c-11186-\nkernel/bpf/verifier.c:11187:\treturn invalidate_reference(env, id);\nkernel/bpf/verifier.c-11188-}\n--\nkernel/bpf/verifier.c=12633=static int release_reg(struct bpf_verifier_env *env, struct bpf_reg_state *reg,\n--\nkernel/bpf/verifier.c-12641-\tif (release_dynptr)\nkernel/bpf/verifier.c:12642:\t\terr = unmark_stack_slots_dynptr(env, reg);\nkernel/bpf/verifier.c-12643-\telse if (convert_rcu)\n--\nkernel/bpf/verifier.c-12645-\telse if (reg_is_referenced(env, reg))\nkernel/bpf/verifier.c:12646:\t\terr = release_reference(env, reg-\u003eid);\nkernel/bpf/verifier.c-12647-\n--\nkernel/bpf/verifier.c=15436=static int check_return_code(struct bpf_verifier_env *env, int regno, const char *reg_name);\nkernel/bpf/verifier.c-15437-\nkernel/bpf/verifier.c:15438:static int check_kfunc_call(struct bpf_verifier_env *env, struct bpf_insn *insn,\nkernel/bpf/verifier.c-15439-\t\t\t    int *insn_idx_p)\n--\nkernel/bpf/verifier.c-15823-\nkernel/bpf/verifier.c:15824:\t\t\t/* Ensures we don't access the memory after a release_reference() */\nkernel/bpf/verifier.c-15825-\t\t\tif (meta.ref_obj.id) {\n--\nkernel/bpf/verifier.c-15866-\t\t\tregs[BPF_REG_0].btf_id = ptr_type_id;\nkernel/bpf/verifier.c:15867:\t\t\tif (iter_next_borrows_struct(\u0026meta) \u0026\u0026 !(type \u0026 MEM_RCU))\nkernel/bpf/verifier.c-15868-\t\t\t\tregs[BPF_REG_0].parent_id = meta.ref_obj.id;\n--\nkernel/bpf/verifier.c=20253=static int do_check_insn(struct bpf_verifier_env *env, bool *do_print_state)\n--\nkernel/bpf/verifier.c-20331-\t\t\tif (insn-\u003esrc_reg == BPF_PSEUDO_KFUNC_CALL)\nkernel/bpf/verifier.c:20332:\t\t\t\treturn check_kfunc_call(env, insn, \u0026env-\u003einsn_idx);\nkernel/bpf/verifier.c-20333-\t\t\treturn check_helper_call(env, insn, \u0026env-\u003einsn_idx);\n"
}

15/2 2026/10/24 15:12 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 25619
							output: 34
							thoughts: 722
						

Thoughts:
**Focusing on Verifier Functions for Effective Fuzzing**

Okay, so I'm looking at these modified functions within `verifier.c`: `check_kfunc_call`, `process_iter_arg`, `check_ptr_to_btf_access`, `mark_stack_slots_dynptr`, `unmark_stack_slots_iter`, `release_reference`, and `invalidate_reference`. They're all declared `static` within that file. The question is, are these functions, even though they are static in the source, actually visible or useful as "FocusSymbols" for fuzzing, according to the instructions?

Let me review Section 4 of the guidelines, which emphasizes the need to be precise when specifying FocusSymbols to avoid diluting the fuzzer's efforts. The key is to avoid ubiquitous functions, focusing instead on logic-specific functions or API entrypoints related to the changes. Static inline functions in headers are problematic as they don't get distinct symbols. But what about static functions declared in a .c file? Do those get included in the `vmlinux` symbol table, the `kallsyms`?

Yes, they *should* be in `vmlinux` unless the compiler inlines them. So the next step is to determine if the compiler has inlined any of these functions. I need to check their size, because really large functions are unlikely to be inlined.

Let's see: `check_kfunc_call` looks huge, over 400 lines! It's definitely *not* inlined. `check_ptr_to_btf_access` is also pretty big (>200 lines). `process_iter_arg` is a medium-sized function, about 150 lines. The other functions are related: `release_reference` calls `invalidate_reference`. Lastly, `btf_check_iter_kfuncs` is in another file, and it is a distinct function. I'm pretty sure that they are all separate functions.

But wait, these static functions are low-level; are there open-coded iterator kfuncs that exercise this? I need to consider functions like `bpf_iter_task_vma_new`, `bpf_iter_task_vma_next`, and `bpf_iter_task_vma_destroy`. I need to review and check the open-coded iterators in the kernel, because they are the caller functions of `check_kfunc_call` that the guidelines suggest.



16/2 2026/10/24 15:12 tool grepper
0m Args:
{
  "Expression": "bpf_iter_.*_next",
  "PathPrefixes": [
    "kernel/bpf/"
  ]
}

Results:
{
  "Output": "kernel/bpf/bpf_iter.c=795=__bpf_kfunc int bpf_iter_num_new(struct bpf_iter_num *it, int start, int end)\n--\nkernel/bpf/bpf_iter.c-802-\t/* start == end is legit, it's an empty range and we'll just get NULL\nkernel/bpf/bpf_iter.c:803:\t * on first (and any subsequent) bpf_iter_num_next() call\nkernel/bpf/bpf_iter.c-804-\t */\n--\nkernel/bpf/bpf_iter.c-815-\nkernel/bpf/bpf_iter.c:816:\t/* user will call bpf_iter_num_next() first,\nkernel/bpf/bpf_iter.c-817-\t * which will set s-\u003ecur to exactly start value;\n--\nkernel/bpf/bpf_iter.c-825-\nkernel/bpf/bpf_iter.c:826:__bpf_kfunc int *bpf_iter_num_next(struct bpf_iter_num* it)\nkernel/bpf/bpf_iter.c-827-{\n--\nkernel/bpf/btf.c=9705=static int btf_check_iter_kfuncs(struct btf *btf, const char *func_name,\n--\nkernel/bpf/btf.c-9758-\tif (flags \u0026 KF_ITER_NEXT) {\nkernel/bpf/btf.c:9759:\t\t/* bpf_iter_\u003ctype\u003e_next() should return pointer */\nkernel/bpf/btf.c-9760-\t\tt = btf_type_skip_modifiers(btf, func-\u003etype, NULL);\n--\nkernel/bpf/cgroup_iter.c=322=__bpf_kfunc int bpf_iter_css_new(struct bpf_iter_css *it,\n--\nkernel/bpf/cgroup_iter.c-346-\nkernel/bpf/cgroup_iter.c:347:__bpf_kfunc struct cgroup_subsys_state *bpf_iter_css_next(struct bpf_iter_css *it)\nkernel/bpf/cgroup_iter.c-348-{\n--\nkernel/bpf/dmabuf_iter.c=161=__bpf_kfunc int bpf_iter_dmabuf_new(struct bpf_iter_dmabuf *it)\n--\nkernel/bpf/dmabuf_iter.c-171-\nkernel/bpf/dmabuf_iter.c:172:__bpf_kfunc struct dma_buf *bpf_iter_dmabuf_next(struct bpf_iter_dmabuf *it)\nkernel/bpf/dmabuf_iter.c-173-{\n--\nkernel/bpf/helpers.c=3566=bpf_iter_bits_new(struct bpf_iter_bits *it, const u64 *unsafe_ptr__ign, u32 nr_words)\n--\nkernel/bpf/helpers.c-3618-/**\nkernel/bpf/helpers.c:3619: * bpf_iter_bits_next() - Get the next bit in a bpf_iter_bits\nkernel/bpf/helpers.c-3620- * @it: The bpf_iter_bits to be checked\n--\nkernel/bpf/helpers.c-3626- */\nkernel/bpf/helpers.c:3627:__bpf_kfunc int *bpf_iter_bits_next(struct bpf_iter_bits *it)\nkernel/bpf/helpers.c-3628-{\n--\nkernel/bpf/helpers.c=5157=BTF_ID_FLAGS(func, bpf_iter_num_new, KF_ITER_NEW | KF_SPINLOCK_SAFE)\nkernel/bpf/helpers.c:5158:BTF_ID_FLAGS(func, bpf_iter_num_next, KF_ITER_NEXT | KF_RET_NULL | KF_SPINLOCK_SAFE)\nkernel/bpf/helpers.c-5159-BTF_ID_FLAGS(func, bpf_iter_num_destroy, KF_ITER_DESTROY | KF_SPINLOCK_SAFE)\nkernel/bpf/helpers.c=5160=BTF_ID_FLAGS(func, bpf_iter_task_vma_new, KF_ITER_NEW | KF_RCU)\nkernel/bpf/helpers.c:5161:BTF_ID_FLAGS(func, bpf_iter_task_vma_next, KF_ITER_NEXT | KF_RET_NULL)\nkernel/bpf/helpers.c-5162-BTF_ID_FLAGS(func, bpf_iter_task_vma_destroy, KF_ITER_DESTROY)\n--\nkernel/bpf/helpers.c=5164=BTF_ID_FLAGS(func, bpf_iter_css_task_new, KF_ITER_NEW)\nkernel/bpf/helpers.c:5165:BTF_ID_FLAGS(func, bpf_iter_css_task_next, KF_ITER_NEXT | KF_RET_NULL)\nkernel/bpf/helpers.c-5166-BTF_ID_FLAGS(func, bpf_iter_css_task_destroy, KF_ITER_DESTROY)\nkernel/bpf/helpers.c=5167=BTF_ID_FLAGS(func, bpf_iter_css_new, KF_ITER_NEW | KF_RCU_PROTECTED)\nkernel/bpf/helpers.c:5168:BTF_ID_FLAGS(func, bpf_iter_css_next, KF_ITER_NEXT | KF_RET_NULL)\nkernel/bpf/helpers.c-5169-BTF_ID_FLAGS(func, bpf_iter_css_destroy, KF_ITER_DESTROY)\n--\nkernel/bpf/helpers.c=5171=BTF_ID_FLAGS(func, bpf_iter_task_new, KF_ITER_NEW | KF_RCU_PROTECTED)\nkernel/bpf/helpers.c:5172:BTF_ID_FLAGS(func, bpf_iter_task_next, KF_ITER_NEXT | KF_RET_NULL)\nkernel/bpf/helpers.c-5173-BTF_ID_FLAGS(func, bpf_iter_task_destroy, KF_ITER_DESTROY)\n--\nkernel/bpf/helpers.c=5189=BTF_ID_FLAGS(func, bpf_iter_bits_new, KF_ITER_NEW | KF_PERFMON)\nkernel/bpf/helpers.c:5190:BTF_ID_FLAGS(func, bpf_iter_bits_next, KF_ITER_NEXT | KF_RET_NULL)\nkernel/bpf/helpers.c-5191-BTF_ID_FLAGS(func, bpf_iter_bits_destroy, KF_ITER_DESTROY)\n--\nkernel/bpf/helpers.c=5197=BTF_ID_FLAGS(func, bpf_iter_kmem_cache_new, KF_ITER_NEW | KF_SLEEPABLE)\nkernel/bpf/helpers.c:5198:BTF_ID_FLAGS(func, bpf_iter_kmem_cache_next, KF_ITER_NEXT | KF_RET_NULL | KF_SLEEPABLE)\nkernel/bpf/helpers.c-5199-BTF_ID_FLAGS(func, bpf_iter_kmem_cache_destroy, KF_ITER_DESTROY | KF_SLEEPABLE)\n--\nkernel/bpf/helpers.c=5213=BTF_ID_FLAGS(func, bpf_iter_dmabuf_new, KF_ITER_NEW | KF_SLEEPABLE)\nkernel/bpf/helpers.c:5214:BTF_ID_FLAGS(func, bpf_iter_dmabuf_next, KF_ITER_NEXT | KF_RET_NULL | KF_SLEEPABLE)\nkernel/bpf/helpers.c-5215-BTF_ID_FLAGS(func, bpf_iter_dmabuf_destroy, KF_ITER_DESTROY | KF_SLEEPABLE)\n--\nkernel/bpf/kmem_cache_iter.c=24=__bpf_kfunc int bpf_iter_kmem_cache_new(struct bpf_iter_kmem_cache *it)\n--\nkernel/bpf/kmem_cache_iter.c-34-\nkernel/bpf/kmem_cache_iter.c:35:__bpf_kfunc struct kmem_cache *bpf_iter_kmem_cache_next(struct bpf_iter_kmem_cache *it)\nkernel/bpf/kmem_cache_iter.c-36-{\n--\nkernel/bpf/kmem_cache_iter.c=170=static void *kmem_cache_iter_seq_next(struct seq_file *seq, void *v, loff_t *pos)\n--\nkernel/bpf/kmem_cache_iter.c-175-\nkernel/bpf/kmem_cache_iter.c:176:\treturn bpf_iter_kmem_cache_next(\u0026p-\u003eit);\nkernel/bpf/kmem_cache_iter.c-177-}\n--\nkernel/bpf/states.c=1167=static bool states_maybe_looping(struct bpf_verifier_state *old,\n--\nkernel/bpf/states.c-1195- *   1:   r1 = \u0026it                      ; \u003cCHECKPOINT HERE\u003e\nkernel/bpf/states.c:1196: *   2:   call bpf_iter_num_next        ; this is iter_next() call\nkernel/bpf/states.c-1197- *   3:   if r0 == 0 goto done\n--\nkernel/bpf/states.c-1205- * This is a typical loop. Let's assume that we have a prune point at 1:,\nkernel/bpf/states.c:1206: * before we get to `call bpf_iter_num_next` (e.g., because of that `goto\nkernel/bpf/states.c-1207- * again`, assuming other heuristics don't get in a way).\n--\nkernel/bpf/states.c-1236- *   bpf_iter_num_new(\u0026it, 0, 10);\nkernel/bpf/states.c:1237: *   while ((p = bpf_iter_num_next(\u0026t))) {\nkernel/bpf/states.c-1238- *       x = p;\n--\nkernel/bpf/states.c=1370=int bpf_is_state_visited(struct bpf_verifier_env *env, int insn_idx)\n--\nkernel/bpf/states.c-1446-\t\t\t *     2. r6 = bpf_get_prandom_u32()\nkernel/bpf/states.c:1447:\t\t\t *     3. while (bpf_iter_num_next(\u0026fp[-8])) {\nkernel/bpf/states.c-1448-\t\t\t *     4.   if (r6 != 42) {\n--\nkernel/bpf/task_iter.c=957=static struct vm_area_struct *\nkernel/bpf/task_iter.c:958:bpf_iter_task_vma_find_next(struct bpf_iter_task_vma_kern_data *data)\nkernel/bpf/task_iter.c-959-{\n--\nkernel/bpf/task_iter.c=994=static void bpf_iter_task_vma_snapshot_reset(struct vm_area_struct *snap)\n--\nkernel/bpf/task_iter.c-1001-\nkernel/bpf/task_iter.c:1002:__bpf_kfunc struct vm_area_struct *bpf_iter_task_vma_next(struct bpf_iter_task_vma *it)\nkernel/bpf/task_iter.c-1003-{\n--\nkernel/bpf/task_iter.c-1013-\nkernel/bpf/task_iter.c:1014:\tvma = bpf_iter_task_vma_find_next(kit-\u003edata);\nkernel/bpf/task_iter.c-1015-\tif (!vma)\n--\nkernel/bpf/task_iter.c=1061=__bpf_kfunc int bpf_iter_css_task_new(struct bpf_iter_css_task *it,\n--\nkernel/bpf/task_iter.c-1085-\nkernel/bpf/task_iter.c:1086:__bpf_kfunc struct task_struct *bpf_iter_css_task_next(struct bpf_iter_css_task *it)\nkernel/bpf/task_iter.c-1087-{\n--\nkernel/bpf/task_iter.c=1130=__bpf_kfunc int bpf_iter_task_new(struct bpf_iter_task *it,\n--\nkernel/bpf/task_iter.c-1161-\nkernel/bpf/task_iter.c:1162:__bpf_kfunc struct task_struct *bpf_iter_task_next(struct bpf_iter_task *it)\nkernel/bpf/task_iter.c-1163-{\n--\nkernel/bpf/verifier.c=8877=static struct bpf_reg_state *get_iter_from_state(struct bpf_verifier_state *cur_st,\n--\nkernel/bpf/verifier.c-8886-/* process_iter_next_call() is called when verifier gets to iterator's next\nkernel/bpf/verifier.c:8887: * \"method\" (e.g., bpf_iter_num_next() for numbers iterator) call. We'll refer\nkernel/bpf/verifier.c-8888- * to it as just \"iter_next()\" in comments below.\n--\nkernel/bpf/verifier.c-8952- *     bpf_iter_num_new(\u0026it, 0, 10);\nkernel/bpf/verifier.c:8953: *     while (bpf_iter_num_next(\u0026it)) {\nkernel/bpf/verifier.c-8954- *       if (a == 0) {\n--\nkernel/bpf/verifier.c=13655=enum special_kfunc_type {\n--\nkernel/bpf/verifier.c-13706-\tKF_bpf_iter_num_new,\nkernel/bpf/verifier.c:13707:\tKF_bpf_iter_num_next,\nkernel/bpf/verifier.c-13708-\tKF_bpf_iter_num_destroy,\n--\nkernel/bpf/verifier.c=13793=BTF_ID(func, bpf_iter_num_new)\nkernel/bpf/verifier.c:13794:BTF_ID(func, bpf_iter_num_next)\nkernel/bpf/verifier.c-13795-BTF_ID(func, bpf_iter_num_destroy)\n--\nkernel/bpf/verifier.c=15438=static int check_kfunc_call(struct bpf_verifier_env *env, struct bpf_insn *insn,\n--\nkernel/bpf/verifier.c-15850-\t\t\t\t * the iterator's next function (e.g.,\nkernel/bpf/verifier.c:15851:\t\t\t\t * bpf_iter_task_next).\nkernel/bpf/verifier.c-15852-\t\t\t\t */\n--\nkernel/bpf/verifier.c=23392=int bpf_fixup_kfunc_call(struct bpf_verifier_env *env, struct bpf_insn *insn,\n--\nkernel/bpf/verifier.c-23565-\t\t*cnt = i;\nkernel/bpf/verifier.c:23566:\t} else if (desc-\u003efunc_id == special_kfunc_list[KF_bpf_iter_num_next]) {\nkernel/bpf/verifier.c:23567:\t\t/* inline bpf_iter_num_next(\u0026it); R1=\u0026it, returns \u0026s-\u003ecur or NULL */\nkernel/bpf/verifier.c-23568-\t\tint i = 0;\n"
}

17/2 2026/10/24 15:12 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 31067
							output: 35
							thoughts: 964
						

Thoughts:
**Focusing the Fuzzer on BPF Logic**

Okay, let's get down to brass tacks. I need to guide the fuzzer effectively, which means avoiding the usual pitfalls. The instructions are clear: don't target ubiquitous functions – no general allocators, no synchronization primitives. We want specific feature logic and entry points.

My initial thought was to examine `bpf_check` or `bpf_prog_load`, but that's far too broad. Instead, I need to pinpoint the *specific* functions implementing the recently added or altered logic. Following that, I've identified the following functions as potential targets: `invalidate_reference`, `release_reference`, `process_iter_arg`, `check_kfunc_call`, `check_ptr_to_btf_access`, `mark_stack_slots_dynptr`, `unmark_stack_slots_iter`, and `btf_check_iter_kfuncs`.

Now, the instructions warn about static inline functions. A quick check reveals that none of the above are static inline, though a few are static. I need to consider potential inlining of `reg_lifetime_id` and `iter_next_borrows_struct` as small helpers. Now let's do a quick estimate of code size. `invalidate_reference` spans about 60 lines, with loops and logic, making inlining less likely. `release_reference` calls other functions. `process_iter_arg` is around 100 lines. `check_kfunc_call` is significantly larger, about 500 lines. `check_ptr_to_btf_access` is around 200 lines and `btf_check_iter_kfuncs` is ~100 lines.

I also need to consider open-coded iterator kfuncs: `bpf_iter_task_vma_next`, `bpf_iter_task_vma_destroy`, and `bpf_iter_task_next`. Crucially, kfunc symbols *are* in vmlinux, they are non-static `__bpf_kfunc` exported via BTF! And the critical realization: syzkaller does, in fact, support BPF programs and kfuncs. That means `check_kfunc_call`, `process_iter_arg`, `check_ptr_to_btf_access`, `invalidate_reference`, and `release_reference` will be triggered when the verifier checks BPF programs that are using iterators and BTF access!

Finally, let's review the required configurations: `CONFIG_BPF_SYSCALL` and `CONFIG_DEBUG_INFO_BTF`. I need to ensure that the environment is set up properly for this. Now, I need to check if `bpf_iter_task_vma_new` requires anything specific. I will need to consult `kernel/bpf/task_iter.c`.



18/2 2026/10/24 15:12 tool grepper
0m Args:
{
  "Expression": "bpf_iter_task_vma",
  "PathPrefixes": [
    "kernel/bpf/"
  ]
}

Results:
{
  "Output": "kernel/bpf/helpers.c=5159=BTF_ID_FLAGS(func, bpf_iter_num_destroy, KF_ITER_DESTROY | KF_SPINLOCK_SAFE)\nkernel/bpf/helpers.c:5160:BTF_ID_FLAGS(func, bpf_iter_task_vma_new, KF_ITER_NEW | KF_RCU)\nkernel/bpf/helpers.c:5161:BTF_ID_FLAGS(func, bpf_iter_task_vma_next, KF_ITER_NEXT | KF_RET_NULL)\nkernel/bpf/helpers.c:5162:BTF_ID_FLAGS(func, bpf_iter_task_vma_destroy, KF_ITER_DESTROY)\nkernel/bpf/helpers.c-5163-#ifdef CONFIG_CGROUPS\n--\nkernel/bpf/task_iter.c=843=static inline void bpf_iter_mmput_async(struct mm_struct *mm)\n--\nkernel/bpf/task_iter.c-851-\nkernel/bpf/task_iter.c:852:struct bpf_iter_task_vma_kern_data {\nkernel/bpf/task_iter.c-853-\tstruct task_struct *task;\n--\nkernel/bpf/task_iter.c-858-\nkernel/bpf/task_iter.c:859:struct bpf_iter_task_vma {\nkernel/bpf/task_iter.c-860-\t/* opaque iterator state; having __u64 here allows to preserve correct\n--\nkernel/bpf/task_iter.c-865-\nkernel/bpf/task_iter.c:866:/* Non-opaque version of bpf_iter_task_vma */\nkernel/bpf/task_iter.c:867:struct bpf_iter_task_vma_kern {\nkernel/bpf/task_iter.c:868:\tstruct bpf_iter_task_vma_kern_data *data;\nkernel/bpf/task_iter.c-869-} __attribute__((aligned(8)));\n--\nkernel/bpf/task_iter.c=871=__bpf_kfunc_start_defs();\nkernel/bpf/task_iter.c-872-\nkernel/bpf/task_iter.c:873:__bpf_kfunc int bpf_iter_task_vma_new(struct bpf_iter_task_vma *it,\nkernel/bpf/task_iter.c-874-\t\t\t\t      struct task_struct *task, u64 addr)\nkernel/bpf/task_iter.c-875-{\nkernel/bpf/task_iter.c:876:\tstruct bpf_iter_task_vma_kern *kit = (void *)it;\nkernel/bpf/task_iter.c-877-\tint err;\nkernel/bpf/task_iter.c-878-\nkernel/bpf/task_iter.c:879:\tBUILD_BUG_ON(sizeof(struct bpf_iter_task_vma_kern) != sizeof(struct bpf_iter_task_vma));\nkernel/bpf/task_iter.c:880:\tBUILD_BUG_ON(__alignof__(struct bpf_iter_task_vma_kern) != __alignof__(struct bpf_iter_task_vma));\nkernel/bpf/task_iter.c-881-\n--\nkernel/bpf/task_iter.c-900-\t * before, so non-NULL kit-\u003edata doesn't point to previously\nkernel/bpf/task_iter.c:901:\t * bpf_mem_alloc'd bpf_iter_task_vma_kern_data\nkernel/bpf/task_iter.c-902-\t */\nkernel/bpf/task_iter.c:903:\tkit-\u003edata = bpf_mem_alloc(\u0026bpf_global_ma, sizeof(struct bpf_iter_task_vma_kern_data));\nkernel/bpf/task_iter.c-904-\tif (!kit-\u003edata)\n--\nkernel/bpf/task_iter.c-938-\tbpf_mem_free(\u0026bpf_global_ma, kit-\u003edata);\nkernel/bpf/task_iter.c:939:\t/* NULL kit-\u003edata signals failed bpf_iter_task_vma initialization */\nkernel/bpf/task_iter.c-940-\tkit-\u003edata = NULL;\n--\nkernel/bpf/task_iter.c=957=static struct vm_area_struct *\nkernel/bpf/task_iter.c:958:bpf_iter_task_vma_find_next(struct bpf_iter_task_vma_kern_data *data)\nkernel/bpf/task_iter.c-959-{\n--\nkernel/bpf/task_iter.c-993-\nkernel/bpf/task_iter.c:994:static void bpf_iter_task_vma_snapshot_reset(struct vm_area_struct *snap)\nkernel/bpf/task_iter.c-995-{\n--\nkernel/bpf/task_iter.c-1001-\nkernel/bpf/task_iter.c:1002:__bpf_kfunc struct vm_area_struct *bpf_iter_task_vma_next(struct bpf_iter_task_vma *it)\nkernel/bpf/task_iter.c-1003-{\nkernel/bpf/task_iter.c:1004:\tstruct bpf_iter_task_vma_kern *kit = (void *)it;\nkernel/bpf/task_iter.c-1005-\tstruct vm_area_struct *snap, *vma;\nkernel/bpf/task_iter.c-1006-\nkernel/bpf/task_iter.c:1007:\tif (!kit-\u003edata) /* bpf_iter_task_vma_new failed */\nkernel/bpf/task_iter.c-1008-\t\treturn NULL;\n--\nkernel/bpf/task_iter.c-1011-\nkernel/bpf/task_iter.c:1012:\tbpf_iter_task_vma_snapshot_reset(snap);\nkernel/bpf/task_iter.c-1013-\nkernel/bpf/task_iter.c:1014:\tvma = bpf_iter_task_vma_find_next(kit-\u003edata);\nkernel/bpf/task_iter.c-1015-\tif (!vma)\n--\nkernel/bpf/task_iter.c-1034-\nkernel/bpf/task_iter.c:1035:__bpf_kfunc void bpf_iter_task_vma_destroy(struct bpf_iter_task_vma *it)\nkernel/bpf/task_iter.c-1036-{\nkernel/bpf/task_iter.c:1037:\tstruct bpf_iter_task_vma_kern *kit = (void *)it;\nkernel/bpf/task_iter.c-1038-\nkernel/bpf/task_iter.c-1039-\tif (kit-\u003edata) {\nkernel/bpf/task_iter.c:1040:\t\tbpf_iter_task_vma_snapshot_reset(\u0026kit-\u003edata-\u003esnapshot);\nkernel/bpf/task_iter.c-1041-\t\tput_task_struct(kit-\u003edata-\u003etask);\n"
}

19/2 2026/10/24 15:12 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 34602
							output: 279
							thoughts: 831
						

Thoughts:
**BPF Verifier Deep Dive: Iterator and Reference Tracking**

Okay, so `task_iter.o` is built with `CONFIG_BPF_SYSCALL`, meaning we're dealing with the BPF syscall and, crucially, its associated iterator functionality. This immediately flags `CONFIG_BPF_SYSCALL` and `DEBUG_INFO_BTF` as the primary configuration flags I need to focus on. They're likely intertwined, and any issues here will likely be uncovered when the syzkaller fuzzing campaign gets underway.

I dove into the `init/Kconfig` file and confirmed that `BPF_SYSCALL` is enabled if `BPF` is enabled, and `DEBUG_INFO_BTF` is enabled if `BPF_SYSCALL` is enabled. Seems pretty standard.

Now, let's look at the actual code changes. I've noted modifications in `include/linux/btf.h` with `KF_ITER_RET_INDEPENDENT`, as well as changes in `kernel/bpf/btf.c` with the addition of `btf_check_iter_kfuncs` and `btf_check_kfunc_protos`. This is critical for the BTF data that's used.

However, the real meat and potatoes are in the BPF verifier, `kernel/bpf/verifier.c`. This is where the magic happens, and the changes there are extensive:
*   I can see that we have `mark_stack_slots_dynptr` and `unmark_stack_slots_iter`. This touches the core BPF verifier logic for reference tracking, dynptrs, iterators, and pointer dereferences.
*   We've got `reg_lifetime_id`, which is a key function to track lifetimes.
*   We have `check_ptr_to_btf_access`, which has to be well-considered.
*   I can see some added logic to `process_iter_arg`, particularly `iter_next_borrows_struct`, and the handling of `invalidate_reference`. We need to scrutinize how it works.
*   `check_kfunc_call`, `invalidate_reference` and `release_reference`, they have to be reviewed as well.

Specifically, the verifier is now propagating `reg_lifetime_id` when reading a `PTR_TRUSTED` field. The `invalidate_reference` and `release_reference` logic is central to iterator state management. `unmark_stack_slots_iter` also shows a distinct departure from `WARN_ON_ONCE`.

The changes indicate a significant overhaul of how BPF iterators interact with the verifier, particularly around reference tracking, dynamic pointers, and pointer dereferences. This could be fertile ground for bugs, especially when combined with the potential for complex BPF programs.

The BPF verifier is reachable through the `bpf(BPF_PROG_LOAD, ...)` syscall, so I'm thinking about how syzkaller can generate test cases with iterators, pointer dereferences, and function calls. The objective is to expose issues or unsoundness in the verifier code, including any potential crashes.

I've identified these specific functions as critical for my analysis, and I'll be focusing on these:

*   `process_iter_arg`
*   `invalidate_reference`
*   `release_reference`
*   `check_kfunc_call`
*   `check_ptr_to_btf_access`
*   `unmark_stack_slots_iter`
*   `mark_stack_slots_dynptr`
*   `btf_check_iter_kfuncs`

And I've got a clear plan: I'll focus on getting the kernel configured with `BPF_SYSCALL` and `DEBUG_INFO_BTF` and using syzkaller to generate test cases. I'm all set.



20/2 2026/10/24 15:13 tool set-results
0m Args:
{
  "EnableConfigs": [
    "BPF_SYSCALL",
    "DEBUG_INFO_BTF"
  ],
  "FocusSymbols": [
    "check_kfunc_call",
    "process_iter_arg",
    "invalidate_reference",
    "release_reference",
    "check_ptr_to_btf_access",
    "unmark_stack_slots_iter",
    "mark_stack_slots_dynptr",
    "btf_check_iter_kfuncs"
  ],
  "Reasoning": "The patch modifies the BPF verifier's reference-tracking and lifetime-invalidation logic for open-coded iterators, dynptrs, and trusted BTF pointers. It introduces KF_ITER_RET_INDEPENDENT to BTF kfunc checks and updates check_kfunc_call, process_iter_arg, check_ptr_to_btf_access, invalidate_reference, and release_reference in kernel/bpf/verifier.c. These changes are reachable from unprivileged or privileged userspace via the bpf(BPF_PROG_LOAD) syscall when loading programs that make use of iterators and BTF accesses. Fuzzing is warranted to uncover latent verifier state bugs or edge cases in reference invalidation.",
  "WorthFuzzing": true
}

Results:
{
  "EnableConfigs": [
    "BPF_SYSCALL",
    "DEBUG_INFO_BTF"
  ],
  "FocusSymbols": [
    "check_kfunc_call",
    "process_iter_arg",
    "invalidate_reference",
    "release_reference",
    "check_ptr_to_btf_access",
    "unmark_stack_slots_iter",
    "mark_stack_slots_dynptr",
    "btf_check_iter_kfuncs"
  ],
  "Reasoning": "The patch modifies the BPF verifier's reference-tracking and lifetime-invalidation logic for open-coded iterators, dynptrs, and trusted BTF pointers. It introduces KF_ITER_RET_INDEPENDENT to BTF kfunc checks and updates check_kfunc_call, process_iter_arg, check_ptr_to_btf_access, invalidate_reference, and release_reference in kernel/bpf/verifier.c. These changes are reachable from unprivileged or privileged userspace via the bpf(BPF_PROG_LOAD) syscall when loading programs that make use of iterators and BTF accesses. Fuzzing is warranted to uncover latent verifier state bugs or edge cases in reference invalidation.",
  "WorthFuzzing": true
}

21/1 2026/10/24 15:13 action If
0m Args:
{
  "WorthFuzzing": true
}

Results:
null

22/2 2026/10/24 15:13 agent kmsan-evaluator
0m Model:
core

Args:
null

Results:
{
  "KMSANReasoning": "The patch series modifies the BPF verifier and BTF metadata to track and invalidate borrowed struct references returned by open-coded iterator next functions (bpf_iter_\u003ctype\u003e_next) upon subsequent next calls or iterator destruction. \n\nThis change addresses pointer lifetime tracking within the BPF verifier to prevent BPF programs from accessing stale or freed kernel objects (use-after-free or dangling pointer dereferences). These types of memory safety violations in BPF programs are detected at runtime by KASAN (out-of-bounds, use-after-free).\n\nThe patch does not introduce new kernel-to-user memory transfers, ioctls, or padding exposure, nor does it create or read uninitialized stack, heap, or page allocations in the kernel. All new local variables in the verifier code are properly initialized before use. Consequently, there are no uninitialized memory access or info-leak risks that would necessitate a dedicated KMSAN fuzzing session.",
  "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 1121dd1c7c4c1347066df764307b88c0ccdd6f83
Author: syz-cluster <triage@syzkaller.com>
Date:   Sat Oct 24 15:12:00 2026 +0000

    syz-cluster: applied patch under review

diff --git a/Documentation/bpf/bpf_iterators.rst b/Documentation/bpf/bpf_iterators.rst
index 189e3ec1c6c8e..72435e32ffa16 100644
--- a/Documentation/bpf/bpf_iterators.rst
+++ b/Documentation/bpf/bpf_iterators.rst
@@ -86,6 +86,16 @@ Constructor/next/destructor implementation contract is as follows:
     resources and marks stack space used by `struct bpf_iter_<type>` as usable
     for something else. Destructor is marked with KF_ITER_DESTROY flag.
 
+The verifier treats a non-RCU, non-acquired struct result as borrowed from
+the iterator's current element. It invalidates the previous result and its
+tracked derived pointers on the next call, including when it returns NULL,
+and on destruction of the iterator. Resources borrowing that lifetime must
+be released first. A next method whose struct result has an independent
+lifetime must use ``KF_ITER_RET_INDEPENDENT``. This flag requires
+``KF_ITER_NEXT`` and a struct pointer return type, and cannot be combined
+with ``KF_ACQUIRE``. RCU-protected and acquired results retain their own
+lifetime rules.
+
 Any open-coded BPF iterator implementation has to implement at least these
 three methods. It is enforced that for any given type of iterator only
 applicable constructor/destructor/next are callable. I.e., verifier ensures
diff --git a/include/linux/btf.h b/include/linux/btf.h
index b66e20a18c54f..a18254b7521bd 100644
--- a/include/linux/btf.h
+++ b/include/linux/btf.h
@@ -82,6 +82,7 @@
 #define KF_IMPLICIT_ARGS (1 << 16) /* kfunc has implicit arguments supplied by the verifier */
 #define KF_SPINLOCK_SAFE (1 << 17) /* kfunc is allowed inside bpf_spin_lock-ed region */
 #define KF_PERFMON      (1 << 18) /* kfunc requires CAP_PERFMON */
+#define KF_ITER_RET_INDEPENDENT (1 << 19) /* next result outlives the current element */
 
 /*
  * Tag marking a kernel function as a kfunc. This is meant to minimize the
diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
index 538129ed24188..e360c0aefc375 100644
--- a/kernel/bpf/btf.c
+++ b/kernel/bpf/btf.c
@@ -9716,6 +9716,10 @@ static int btf_check_iter_kfuncs(struct btf *btf, const char *func_name,
 	if (!flags || (flags & (flags - 1)))
 		return -EINVAL;
 
+	if ((func_flags & KF_ITER_RET_INDEPENDENT) &&
+	    (!(flags & KF_ITER_NEXT) || (func_flags & KF_ACQUIRE)))
+		return -EINVAL;
+
 	/* any BPF iter kfunc should have `struct bpf_iter_<type> *` first arg */
 	nr_args = btf_type_vlen(func);
 	if (nr_args < 1)
@@ -9756,6 +9760,12 @@ static int btf_check_iter_kfuncs(struct btf *btf, const char *func_name,
 		t = btf_type_skip_modifiers(btf, func->type, NULL);
 		if (!t || !btf_type_is_ptr(t))
 			return -EINVAL;
+		/* The opt-out applies only to non-acquired struct results. */
+		if (func_flags & KF_ITER_RET_INDEPENDENT) {
+			t = btf_type_skip_modifiers(btf, t->type, NULL);
+			if (!t || !__btf_type_is_struct(t))
+				return -EINVAL;
+		}
 	}
 
 	if (flags & KF_ITER_DESTROY) {
@@ -9822,7 +9832,8 @@ static int btf_check_kfunc_protos(struct btf *btf, u32 func_id, u32 func_flags)
 	if (!func || !btf_type_is_func_proto(func))
 		return -EINVAL;
 
-	if (func_flags & (KF_ITER_NEW | KF_ITER_NEXT | KF_ITER_DESTROY)) {
+	if (func_flags & (KF_ITER_NEW | KF_ITER_NEXT | KF_ITER_DESTROY |
+			  KF_ITER_RET_INDEPENDENT)) {
 		err = btf_check_iter_kfuncs(btf, func_name, func, func_flags);
 		if (err)
 			return err;
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index 5601d20562186..c223bf3bc9cdb 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -211,6 +211,9 @@ static int acquire_reference(struct bpf_verifier_env *env, int insn_idx, int par
 static int __release_reference_nomark(struct bpf_verifier_state *state, int id);
 static int release_reference_nomark(struct bpf_verifier_env *env, int id);
 static int release_reference(struct bpf_verifier_env *env, int id);
+static int invalidate_reference(struct bpf_verifier_env *env, int id);
+static u32 reg_lifetime_id(struct bpf_verifier_env *env,
+			   const struct bpf_reg_state *reg);
 static void invalidate_non_owning_refs(struct bpf_verifier_env *env);
 static void invalidate_rcu_protected_refs(struct bpf_verifier_env *env);
 static bool in_rbtree_lock_required_cb(struct bpf_verifier_env *env);
@@ -793,8 +796,8 @@ static int mark_stack_slots_dynptr(struct bpf_verifier_env *env, struct bpf_reg_
 		if (err)
 			return err;
 
-		/* Track parent's id if the parent is a referenced object */
-		parent_id = ref_obj->id;
+		/* All non-clone constructors take their backing object in R1. */
+		parent_id = reg_lifetime_id(env, &cur_regs(env)[BPF_REG_1]);
 
 		if (dynptr_type_referenced(type)) {
 			int id;
@@ -1074,7 +1077,7 @@ static int unmark_stack_slots_iter(struct bpf_verifier_env *env,
 				   struct bpf_reg_state *reg, int nr_slots)
 {
 	struct bpf_func_state *state = bpf_func(env, reg);
-	int spi, i, j;
+	int spi, i, j, err;
 
 	spi = iter_get_spi(env, reg, nr_slots);
 	if (spi < 0)
@@ -1084,8 +1087,11 @@ static int unmark_stack_slots_iter(struct bpf_verifier_env *env,
 		struct bpf_stack_state *slot = bpf_stack_slot(state, spi - i);
 		struct bpf_reg_state *st = &slot->spilled_ptr;
 
-		if (i == 0)
-			WARN_ON_ONCE(release_reference(env, st->id));
+		if (i == 0) {
+			err = release_reference(env, st->id);
+			if (err)
+				return err;
+		}
 
 		bpf_mark_reg_not_init(env, st);
 
@@ -1627,6 +1633,12 @@ static bool reg_is_referenced(struct bpf_verifier_env *env, const struct bpf_reg
 	return find_reference_state(env->cur_state, reg->id);
 }
 
+static u32 reg_lifetime_id(struct bpf_verifier_env *env,
+			   const struct bpf_reg_state *reg)
+{
+	return reg_is_referenced(env, reg) ? reg->id : reg->parent_id;
+}
+
 static int release_lock_state(struct bpf_verifier_env *env, int type, int id, void *ptr)
 {
 	struct bpf_verifier_state *state = env->cur_state;
@@ -6848,9 +6860,14 @@ static int check_ptr_to_btf_access(struct bpf_verifier_env *env,
 		flag &= ~PTR_MAYBE_NULL;
 
 	if (atype == BPF_READ && value_regno >= 0) {
+		u32 parent_id = reg_lifetime_id(env, reg);
+
 		ret = mark_btf_ld_reg(env, regs, value_regno, ret, reg->btf, btf_id, flag);
 		if (ret < 0)
 			return ret;
+		if ((regs[value_regno].type & PTR_TRUSTED) &&
+		    !(regs[value_regno].type & (MEM_RCU | MEM_PERCPU | MEM_USER)))
+			regs[value_regno].parent_id = parent_id;
 	}
 
 	return 0;
@@ -8636,6 +8653,21 @@ static bool is_iter_destroy_kfunc(struct bpf_call_arg_meta *meta)
 	return meta->kfunc_flags & KF_ITER_DESTROY;
 }
 
+static bool iter_next_borrows_struct(struct bpf_call_arg_meta *meta)
+{
+	const struct btf_type *t;
+
+	if (!(meta->kfunc_flags & KF_ITER_NEXT) ||
+	    (meta->kfunc_flags & (KF_ITER_RET_INDEPENDENT | KF_ACQUIRE)))
+		return false;
+
+	t = btf_type_skip_modifiers(meta->btf, meta->func_proto->type, NULL);
+	if (!t || !btf_type_is_ptr(t))
+		return false;
+	t = btf_type_skip_modifiers(meta->btf, t->type, NULL);
+	return t && __btf_type_is_struct(t);
+}
+
 static bool is_kfunc_arg_iter(struct bpf_call_arg_meta *meta, int arg_idx,
 			      const struct btf_param *arg)
 {
@@ -8746,6 +8778,13 @@ static int process_iter_arg(struct bpf_verifier_env *env, struct bpf_reg_state *
 		meta->iter.frameno = reg->frameno;
 		update_ref_obj(&meta->ref_obj, &bpf_stack_slot(state, spi)->spilled_ptr);
 
+		/* The iterator stays. What was borrowed from the previous element goes. */
+		if (iter_next_borrows_struct(meta)) {
+			err = invalidate_reference(env, meta->ref_obj.id);
+			if (err)
+				return err;
+		}
+
 		if (is_iter_destroy_kfunc(meta)) {
 			err = unmark_stack_slots_iter(env, reg, nr_slots);
 			if (err)
@@ -11073,8 +11112,8 @@ static int idstack_pop(struct bpf_idmap *idmap)
 	return idmap->map[--idmap->cnt].old;
 }
 
-/* Release id and objects derived from it iteratively in a DFS manner */
-static int release_reference(struct bpf_verifier_env *env, int id)
+/* Invalidate id and objects derived from it iteratively in a DFS manner */
+static int invalidate_reference(struct bpf_verifier_env *env, int id)
 {
 	u32 mask = (1 << STACK_SPILL) | (1 << STACK_DYNPTR);
 	struct bpf_verifier_state *vstate = env->cur_state;
@@ -11089,11 +11128,6 @@ static int release_reference(struct bpf_verifier_env *env, int id)
 	if (err)
 		return err;
 
-	if (find_reference_state(vstate, id)) {
-		err = release_reference_nomark(env, id);
-		WARN_ON_ONCE(err);
-	}
-
 	while ((id = idstack_pop(idstack))) {
 		/*
 		 * Child references are inaccessible after parent is released,
@@ -11145,6 +11179,14 @@ static int release_reference(struct bpf_verifier_env *env, int id)
 	return 0;
 }
 
+static int release_reference(struct bpf_verifier_env *env, int id)
+{
+	if (find_reference_state(env->cur_state, id))
+		WARN_ON_ONCE(release_reference_nomark(env, id));
+
+	return invalidate_reference(env, id);
+}
+
 static void invalidate_non_owning_refs(struct bpf_verifier_env *env)
 {
 	struct bpf_func_state *unused;
@@ -15822,6 +15864,8 @@ static int check_kfunc_call(struct bpf_verifier_env *env, struct bpf_insn *insn,
 			regs[BPF_REG_0].btf = desc_btf;
 			regs[BPF_REG_0].type = type;
 			regs[BPF_REG_0].btf_id = ptr_type_id;
+			if (iter_next_borrows_struct(&meta) && !(type & MEM_RCU))
+				regs[BPF_REG_0].parent_id = meta.ref_obj.id;
 		}
 
 		if (is_kfunc_ret_null(&meta)) {
diff --git a/tools/testing/selftests/bpf/progs/iters_testmod.c b/tools/testing/selftests/bpf/progs/iters_testmod.c
index 145750bb64ef8..8896335668b47 100644
--- a/tools/testing/selftests/bpf/progs/iters_testmod.c
+++ b/tools/testing/selftests/bpf/progs/iters_testmod.c
@@ -8,6 +8,44 @@
 
 char _license[] SEC("license") = "GPL";
 
+struct bpf_iter_testmod_current {
+	u64 __opaque;
+};
+
+SEC("raw_tp/sys_enter")
+__success
+int iter_independent_lifetime_after_next(const void *ctx)
+{
+	struct bpf_iter_testmod_current it;
+	struct task_struct *task;
+
+	bpf_iter_testmod_current_new(&it);
+	task = bpf_iter_testmod_current_next(&it);
+	if (!task)
+		goto out;
+
+	bpf_iter_testmod_current_next(&it);
+	bpf_kfunc_trusted_task_test(task);
+out:
+	bpf_iter_testmod_current_destroy(&it);
+	return 0;
+}
+
+SEC("raw_tp/sys_enter")
+__success
+int iter_independent_lifetime_after_destroy(const void *ctx)
+{
+	struct bpf_iter_testmod_current it;
+	struct task_struct *task;
+
+	bpf_iter_testmod_current_new(&it);
+	task = bpf_iter_testmod_current_next(&it);
+	bpf_iter_testmod_current_destroy(&it);
+	if (task)
+		bpf_kfunc_trusted_task_test(task);
+	return 0;
+}
+
 SEC("raw_tp/sys_enter")
 __success
 int iter_next_trusted(const void *ctx)
@@ -28,6 +66,298 @@ int iter_next_trusted(const void *ctx)
 	return 0;
 }
 
+SEC("raw_tp/sys_enter")
+__failure __msg("invalid mem access 'scalar'")
+int iter_next_trusted_after_destroy(const void *ctx)
+{
+	struct task_struct *cur_task = bpf_get_current_task_btf();
+	struct bpf_iter_task_vma vma_it;
+	struct vm_area_struct *vma_ptr;
+
+	bpf_iter_task_vma_new(&vma_it, cur_task, 0);
+
+	vma_ptr = bpf_iter_task_vma_next(&vma_it);
+	if (!vma_ptr)
+		goto out;
+
+	bpf_iter_task_vma_destroy(&vma_it);
+	return vma_ptr->vm_start;
+out:
+	bpf_iter_task_vma_destroy(&vma_it);
+	return 0;
+}
+
+SEC("raw_tp/sys_enter")
+__failure __msg("invalid mem access 'scalar'")
+int iter_next_trusted_after_next(const void *ctx)
+{
+	struct task_struct *cur_task = bpf_get_current_task_btf();
+	struct bpf_iter_task_vma vma_it;
+	struct vm_area_struct *vma_ptr, *next_vma_ptr;
+	u64 vm_start;
+
+	bpf_iter_task_vma_new(&vma_it, cur_task, 0);
+
+	vma_ptr = bpf_iter_task_vma_next(&vma_it);
+	if (!vma_ptr)
+		goto out;
+
+	next_vma_ptr = bpf_iter_task_vma_next(&vma_it);
+	if (!next_vma_ptr)
+		goto out;
+
+	vm_start = vma_ptr->vm_start;
+	bpf_iter_task_vma_destroy(&vma_it);
+	return vm_start;
+out:
+	bpf_iter_task_vma_destroy(&vma_it);
+	return 0;
+}
+
+SEC("raw_tp/sys_enter")
+__failure __msg("invalid mem access 'scalar'")
+int iter_next_trusted_after_next_null(const void *ctx)
+{
+	struct task_struct *cur_task = bpf_get_current_task_btf();
+	struct bpf_iter_task_vma vma_it;
+	struct vm_area_struct *vma_ptr, *next_vma_ptr;
+	u64 vm_start;
+
+	bpf_iter_task_vma_new(&vma_it, cur_task, 0);
+
+	vma_ptr = bpf_iter_task_vma_next(&vma_it);
+	if (!vma_ptr)
+		goto out;
+
+	next_vma_ptr = bpf_iter_task_vma_next(&vma_it);
+	if (next_vma_ptr)
+		goto out;
+
+	vm_start = vma_ptr->vm_start;
+	bpf_iter_task_vma_destroy(&vma_it);
+	return vm_start;
+out:
+	bpf_iter_task_vma_destroy(&vma_it);
+	return 0;
+}
+
+SEC("raw_tp/sys_enter")
+__failure __msg("invalid mem access 'scalar'")
+int iter_next_trusted_field_after_destroy(const void *ctx)
+{
+	struct task_struct *cur_task = bpf_get_current_task_btf();
+	struct bpf_iter_task_vma vma_it;
+	struct vm_area_struct *vma_ptr;
+	struct file *file_ptr;
+
+	bpf_iter_task_vma_new(&vma_it, cur_task, 0);
+
+	vma_ptr = bpf_iter_task_vma_next(&vma_it);
+	if (!vma_ptr)
+		goto out;
+
+	file_ptr = vma_ptr->vm_file;
+	bpf_iter_task_vma_destroy(&vma_it);
+	if (file_ptr)
+		return file_ptr->f_mode;
+	return 0;
+out:
+	bpf_iter_task_vma_destroy(&vma_it);
+	return 0;
+}
+
+SEC("raw_tp/sys_enter")
+__failure __msg("invalid mem access 'scalar'")
+int iter_next_trusted_field_after_next(const void *ctx)
+{
+	struct task_struct *cur_task = bpf_get_current_task_btf();
+	struct bpf_iter_task_vma vma_it;
+	struct vm_area_struct *vma_ptr, *next_vma_ptr;
+	struct file *file_ptr;
+	u32 mode;
+
+	bpf_iter_task_vma_new(&vma_it, cur_task, 0);
+
+	vma_ptr = bpf_iter_task_vma_next(&vma_it);
+	if (!vma_ptr)
+		goto out;
+
+	file_ptr = vma_ptr->vm_file;
+	if (!file_ptr)
+		goto out;
+
+	next_vma_ptr = bpf_iter_task_vma_next(&vma_it);
+	if (!next_vma_ptr)
+		goto out;
+
+	mode = file_ptr->f_mode;
+	bpf_iter_task_vma_destroy(&vma_it);
+	return mode;
+out:
+	bpf_iter_task_vma_destroy(&vma_it);
+	return 0;
+}
+
+SEC("raw_tp/sys_enter")
+__failure __msg("Leaking reference id=")
+int iter_next_file_dynptr_after_next(const void *ctx)
+{
+	struct task_struct *cur_task = bpf_get_current_task_btf();
+	struct bpf_iter_task_vma vma_it;
+	struct vm_area_struct *vma_ptr;
+	struct bpf_dynptr dynptr;
+	struct file *file_ptr;
+
+	bpf_iter_task_vma_new(&vma_it, cur_task, 0);
+
+	vma_ptr = bpf_iter_task_vma_next(&vma_it);
+	if (!vma_ptr)
+		goto out;
+
+	file_ptr = vma_ptr->vm_file;
+	if (!file_ptr)
+		goto out;
+
+	bpf_dynptr_from_file(file_ptr, 0, &dynptr);
+	bpf_iter_task_vma_next(&vma_it);
+	bpf_dynptr_file_discard(&dynptr);
+out:
+	bpf_iter_task_vma_destroy(&vma_it);
+	return 0;
+}
+
+SEC("raw_tp/sys_enter")
+__failure __msg("Leaking reference id=")
+int iter_next_file_dynptr_after_destroy(const void *ctx)
+{
+	struct task_struct *cur_task = bpf_get_current_task_btf();
+	struct bpf_iter_task_vma vma_it;
+	struct vm_area_struct *vma_ptr;
+	struct bpf_dynptr dynptr;
+	struct file *file_ptr;
+
+	bpf_iter_task_vma_new(&vma_it, cur_task, 0);
+
+	vma_ptr = bpf_iter_task_vma_next(&vma_it);
+	if (!vma_ptr)
+		goto out;
+
+	file_ptr = vma_ptr->vm_file;
+	if (!file_ptr)
+		goto out;
+
+	bpf_dynptr_from_file(file_ptr, 0, &dynptr);
+	bpf_iter_task_vma_destroy(&vma_it);
+	bpf_dynptr_file_discard(&dynptr);
+	return 0;
+out:
+	bpf_iter_task_vma_destroy(&vma_it);
+	return 0;
+}
+
+SEC("raw_tp/sys_enter")
+__success
+int iter_next_file_dynptr_discard_before_advance(const void *ctx)
+{
+	struct task_struct *cur_task = bpf_get_current_task_btf();
+	struct bpf_iter_task_vma vma_it;
+	struct vm_area_struct *vma_ptr;
+	struct bpf_dynptr dynptr;
+	struct file *file_ptr;
+
+	bpf_iter_task_vma_new(&vma_it, cur_task, 0);
+
+	vma_ptr = bpf_iter_task_vma_next(&vma_it);
+	if (!vma_ptr)
+		goto out;
+
+	file_ptr = vma_ptr->vm_file;
+	if (!file_ptr)
+		goto out;
+
+	bpf_dynptr_from_file(file_ptr, 0, &dynptr);
+	bpf_dynptr_file_discard(&dynptr);
+	bpf_iter_task_vma_next(&vma_it);
+out:
+	bpf_iter_task_vma_destroy(&vma_it);
+	return 0;
+}
+
+SEC("raw_tp/sys_enter")
+__success
+int iter_next_trusted_current_after_next(const void *ctx)
+{
+	struct task_struct *cur_task = bpf_get_current_task_btf();
+	struct bpf_iter_task_vma vma_it;
+	struct vm_area_struct *vma_ptr;
+
+	bpf_iter_task_vma_new(&vma_it, cur_task, 0);
+
+	vma_ptr = bpf_iter_task_vma_next(&vma_it);
+	if (!vma_ptr)
+		goto out;
+
+	vma_ptr = bpf_iter_task_vma_next(&vma_it);
+	if (vma_ptr)
+		bpf_kfunc_trusted_vma_test(vma_ptr);
+out:
+	bpf_iter_task_vma_destroy(&vma_it);
+	return 0;
+}
+
+SEC("raw_tp/sys_enter")
+__success
+int iter_next_trusted_rcu_field_after_destroy(const void *ctx)
+{
+	struct task_struct *cur_task = bpf_get_current_task_btf();
+	struct bpf_iter_task_vma vma_it;
+	struct vm_area_struct *vma_ptr;
+	struct mm_struct *mm_ptr;
+	struct file *file_ptr = NULL;
+
+	bpf_iter_task_vma_new(&vma_it, cur_task, 0);
+
+	vma_ptr = bpf_iter_task_vma_next(&vma_it);
+	if (vma_ptr) {
+		mm_ptr = vma_ptr->vm_mm;
+		/* exe_file has RCU protection independent of the iterator. */
+		if (mm_ptr)
+			file_ptr = mm_ptr->exe_file;
+	}
+
+	bpf_iter_task_vma_destroy(&vma_it);
+	if (file_ptr)
+		return file_ptr->f_mode;
+	return 0;
+}
+
+SEC("raw_tp/sys_enter")
+__success
+int iter_next_trusted_rcu_field_after_next(const void *ctx)
+{
+	struct task_struct *cur_task = bpf_get_current_task_btf();
+	struct bpf_iter_task_vma vma_it;
+	struct vm_area_struct *vma_ptr;
+	struct mm_struct *mm_ptr;
+	struct file *file_ptr = NULL;
+	u32 mode = 0;
+
+	bpf_iter_task_vma_new(&vma_it, cur_task, 0);
+
+	vma_ptr = bpf_iter_task_vma_next(&vma_it);
+	if (vma_ptr) {
+		mm_ptr = vma_ptr->vm_mm;
+		if (mm_ptr)
+			file_ptr = mm_ptr->exe_file;
+	}
+
+	bpf_iter_task_vma_next(&vma_it);
+	if (file_ptr)
+		mode = file_ptr->f_mode;
+	bpf_iter_task_vma_destroy(&vma_it);
+	return mode;
+}
+
 SEC("raw_tp/sys_enter")
 __failure __msg("Possibly NULL pointer passed to trusted R1")
 int iter_next_trusted_or_null(const void *ctx)
@@ -77,6 +407,46 @@ int iter_next_rcu(const void *ctx)
 	return 0;
 }
 
+SEC("raw_tp/sys_enter")
+__success
+int iter_next_rcu_after_destroy(const void *ctx)
+{
+	struct task_struct *cur_task = bpf_get_current_task_btf();
+	struct bpf_iter_task task_it;
+	struct task_struct *task_ptr;
+
+	bpf_iter_task_new(&task_it, cur_task, 0);
+
+	task_ptr = bpf_iter_task_next(&task_it);
+	bpf_iter_task_destroy(&task_it);
+	if (!task_ptr)
+		return 0;
+
+	bpf_kfunc_rcu_task_test(task_ptr);
+	return 0;
+}
+
+SEC("raw_tp/sys_enter")
+__success
+int iter_next_rcu_after_next(const void *ctx)
+{
+	struct task_struct *cur_task = bpf_get_current_task_btf();
+	struct bpf_iter_task task_it;
+	struct task_struct *task_ptr;
+
+	bpf_iter_task_new(&task_it, cur_task, 0);
+
+	task_ptr = bpf_iter_task_next(&task_it);
+	if (!task_ptr)
+		goto out;
+
+	bpf_iter_task_next(&task_it);
+	bpf_kfunc_rcu_task_test(task_ptr);
+out:
+	bpf_iter_task_destroy(&task_it);
+	return 0;
+}
+
 SEC("raw_tp/sys_enter")
 __failure __msg("Possibly NULL pointer passed to trusted R1")
 int iter_next_rcu_or_null(const void *ctx)
diff --git a/tools/testing/selftests/bpf/progs/verifier_vfs_accept.c b/tools/testing/selftests/bpf/progs/verifier_vfs_accept.c
index 55398c04290a8..25f37a3dd7cfb 100644
--- a/tools/testing/selftests/bpf/progs/verifier_vfs_accept.c
+++ b/tools/testing/selftests/bpf/progs/verifier_vfs_accept.c
@@ -11,6 +11,23 @@
 
 static char buf[64];
 
+SEC("lsm.s/file_open")
+__success
+int BPF_PROG(inode_field_before_file_put)
+{
+	struct file *file;
+	ino_t ino;
+
+	file = bpf_get_task_exe_file(bpf_get_current_task_btf());
+	if (!file)
+		return 0;
+
+	ino = file->f_inode->i_ino;
+	bpf_put_file(file);
+	__sink(ino);
+	return 0;
+}
+
 SEC("lsm.s/file_open")
 __success
 int BPF_PROG(get_task_exe_file_and_put_kfunc_from_current_sleepable)
diff --git a/tools/testing/selftests/bpf/progs/verifier_vfs_reject.c b/tools/testing/selftests/bpf/progs/verifier_vfs_reject.c
index b5f456d57669e..ed2bd2faebf36 100644
--- a/tools/testing/selftests/bpf/progs/verifier_vfs_reject.c
+++ b/tools/testing/selftests/bpf/progs/verifier_vfs_reject.c
@@ -12,6 +12,25 @@
 
 static char buf[PATH_MAX];
 
+SEC("lsm.s/file_open")
+__failure __msg("invalid mem access 'scalar'")
+int BPF_PROG(inode_field_after_file_put)
+{
+	struct inode *inode;
+	struct file *file;
+	ino_t ino;
+
+	file = bpf_get_task_exe_file(bpf_get_current_task_btf());
+	if (!file)
+		return 0;
+
+	inode = file->f_inode;
+	bpf_put_file(file);
+	ino = inode->i_ino;
+	__sink(ino);
+	return 0;
+}
+
 SEC("lsm.s/file_open")
 __failure __msg("Possibly NULL pointer passed to trusted R1")
 int BPF_PROG(get_task_exe_file_kfunc_null)
diff --git a/tools/testing/selftests/bpf/test_kmods/bpf_testmod.c b/tools/testing/selftests/bpf/test_kmods/bpf_testmod.c
index 6380f52f4dd2c..76fbe64755ef9 100644
--- a/tools/testing/selftests/bpf/test_kmods/bpf_testmod.c
+++ b/tools/testing/selftests/bpf/test_kmods/bpf_testmod.c
@@ -281,6 +281,27 @@ __bpf_kfunc void bpf_iter_testmod_seq_destroy(struct bpf_iter_testmod_seq *it)
 	it->cnt = 0;
 }
 
+__bpf_kfunc int bpf_iter_testmod_current_new(struct bpf_iter_testmod_current *it)
+{
+	it->remaining = 2;
+	return 0;
+}
+
+__bpf_kfunc struct task_struct *
+bpf_iter_testmod_current_next(struct bpf_iter_testmod_current *it)
+{
+	if (!it->remaining)
+		return NULL;
+	it->remaining--;
+	/* current remains alive independently of the iterator. */
+	return current;
+}
+
+__bpf_kfunc void bpf_iter_testmod_current_destroy(struct bpf_iter_testmod_current *it)
+{
+	it->remaining = 0;
+}
+
 __bpf_kfunc void bpf_kfunc_common_test(void)
 {
 }
@@ -1016,6 +1037,10 @@ BTF_ID_FLAGS(func, bpf_iter_testmod_seq_new, KF_ITER_NEW)
 BTF_ID_FLAGS(func, bpf_iter_testmod_seq_next, KF_ITER_NEXT | KF_RET_NULL)
 BTF_ID_FLAGS(func, bpf_iter_testmod_seq_destroy, KF_ITER_DESTROY)
 BTF_ID_FLAGS(func, bpf_iter_testmod_seq_value)
+BTF_ID_FLAGS(func, bpf_iter_testmod_current_new, KF_ITER_NEW)
+BTF_ID_FLAGS(func, bpf_iter_testmod_current_next,
+	     KF_ITER_NEXT | KF_RET_NULL | KF_ITER_RET_INDEPENDENT)
+BTF_ID_FLAGS(func, bpf_iter_testmod_current_destroy, KF_ITER_DESTROY)
 BTF_ID_FLAGS(func, bpf_kfunc_common_test)
 BTF_ID_FLAGS(func, bpf_kfunc_arena_arg_test)
 BTF_ID_FLAGS(func, bpf_kfunc_arena_cap_test)
diff --git a/tools/testing/selftests/bpf/test_kmods/bpf_testmod.h b/tools/testing/selftests/bpf/test_kmods/bpf_testmod.h
index 4ba9def74404b..aef780261ef4f 100644
--- a/tools/testing/selftests/bpf/test_kmods/bpf_testmod.h
+++ b/tools/testing/selftests/bpf/test_kmods/bpf_testmod.h
@@ -31,6 +31,10 @@ struct bpf_iter_testmod_seq {
 	int cnt;
 };
 
+struct bpf_iter_testmod_current {
+	u64 remaining;
+};
+
 struct bpf_testmod_ops {
 	int (*test_1)(void);
 	void (*test_2)(int a, int b);
diff --git a/tools/testing/selftests/bpf/test_kmods/bpf_testmod_kfunc.h b/tools/testing/selftests/bpf/test_kmods/bpf_testmod_kfunc.h
index 3b810f1e438f7..e9902e651d72b 100644
--- a/tools/testing/selftests/bpf/test_kmods/bpf_testmod_kfunc.h
+++ b/tools/testing/selftests/bpf/test_kmods/bpf_testmod_kfunc.h
@@ -33,6 +33,11 @@ struct prog_test_ref_kfunc {
 #endif
 
 struct bpf_iter_testmod_seq;
+struct bpf_iter_testmod_current;
+
+int bpf_iter_testmod_current_new(struct bpf_iter_testmod_current *it) __ksym;
+struct task_struct *bpf_iter_testmod_current_next(struct bpf_iter_testmod_current *it) __ksym;
+void bpf_iter_testmod_current_destroy(struct bpf_iter_testmod_current *it) __ksym;
 
 struct prog_test_pass1 {
 	int x0;

23/3 2026/10/24 15:13 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 12213
							output: 224
							thoughts: 2343
						

Thoughts:
**KMSAN Evaluation: BPF Iterator Lifetime Tracking**

Okay, let's break this down. My goal is to determine if this patch series warrants a dedicated KMSAN fuzzing session. The rules are clear: KMSAN is expensive, and should *only* be used if the patch introduces or exposes risks of *uninitialized* memory usage that KASAN, LOCKDEP, or other standard detectors would miss. This patch series focuses on improving BPF iterator lifetime tracking within the verifier. So, it is important to check whether the changes introduce uninitialized memory reads or potentially leak uninitialized memory to user space.

I've carefully reviewed the patch diff. It mainly concerns itself with how the BPF verifier handles pointers returned by open-coded iterators, specifically when a struct is borrowed by an iterator. Before the patch, there was a risk that a BPF program could hold onto a pointer after its intended lifetime, leading to use-after-free or dangling pointer issues. This patch aims to tighten the reference and lifetime tracking to prevent these problems.

The code modifications involve changes to how the verifier tracks references, invalidates pointers, and handles the "next" and "destroy" operations of iterators. Notably, the patch touches `invalidate_reference`, `reg_lifetime_id`, and various helper functions related to iterator behavior and argument handling.

Now, the crucial question: does this patch introduce uninitialized memory access or leaks? Let's go through the key areas. I've looked at the variables introduced: `parent_id`, `err`, `t`. All of the variables introduced seem to be initialized before use. The patch does *not* modify any kernel-to-user memory copy logic, it does not add or introduce uninitialized variables in any way. The patch does *not* change how `reg_lifetime_id` is defined and used, so previous checks on this also stand. Also I checked for changes in the abstract interpretation of the verifier, but it only tracks registers in the verifier's internal state.

The primary change is preventing use-after-free and dangling pointer issues. These are classic memory corruption bugs. And, these types of problems are precisely what KASAN is designed to detect. Verifier bugs that *allow* access to invalid pointers are already caught by KASAN.

The patch aims to fix and prevent memory safety issues by tightening the verifier's tracking of iterator-borrowed pointers. The bugs this fixes/prevents are classic memory corruption bugs: KASAN is the appropriate tool for detecting them, not KMSAN.

In summary, this patch is fixing a lifetime issue. It doesn't introduce uninitialized memory. There's no risk of uninitialized memory reads or leaks to userspace. All of the variables are initialized before use. The verifier tracks registers, not kernel memory. It prevents use-after-free and dangling pointer issues which are detectable by KASAN. Therefore, a KMSAN session is not necessary. The `NeedsKMSAN` flag should be set to `false`.



24/3 2026/10/24 15:13 tool set-results
0m Args:
{
  "KMSANReasoning": "The patch series modifies the BPF verifier and BTF metadata to track and invalidate borrowed struct references returned by open-coded iterator next functions (bpf_iter_\u003ctype\u003e_next) upon subsequent next calls or iterator destruction. \n\nThis change addresses pointer lifetime tracking within the BPF verifier to prevent BPF programs from accessing stale or freed kernel objects (use-after-free or dangling pointer dereferences). These types of memory safety violations in BPF programs are detected at runtime by KASAN (out-of-bounds, use-after-free).\n\nThe patch does not introduce new kernel-to-user memory transfers, ioctls, or padding exposure, nor does it create or read uninitialized stack, heap, or page allocations in the kernel. All new local variables in the verifier code are properly initialized before use. Consequently, there are no uninitialized memory access or info-leak risks that would necessitate a dedicated KMSAN fuzzing session.",
  "NeedsKMSAN": false
}

Results:
{
  "KMSANReasoning": "The patch series modifies the BPF verifier and BTF metadata to track and invalidate borrowed struct references returned by open-coded iterator next functions (bpf_iter_\u003ctype\u003e_next) upon subsequent next calls or iterator destruction. \n\nThis change addresses pointer lifetime tracking within the BPF verifier to prevent BPF programs from accessing stale or freed kernel objects (use-after-free or dangling pointer dereferences). These types of memory safety violations in BPF programs are detected at runtime by KASAN (out-of-bounds, use-after-free).\n\nThe patch does not introduce new kernel-to-user memory transfers, ioctls, or padding exposure, nor does it create or read uninitialized stack, heap, or page allocations in the kernel. All new local variables in the verifier code are properly initialized before use. Consequently, there are no uninitialized memory access or info-leak risks that would necessitate a dedicated KMSAN fuzzing session.",
  "NeedsKMSAN": false
}

LLM Calls Summary:
Total Calls Total Tokens Avg Tokens Total Duration (Seconds) Avg Duration (Seconds)
Tool Calls Summary:
Total Calls Total Duration (Seconds) Avg Duration (Seconds)