AI Trajectory


Trajectory: (Expand/Collapse All)
Seq Timestamp Type Name Duration
0/0 2026/09/15 00:03 flow patch-triage
9m Args:
null

Results:
{
  "EnableConfigs": [
    "BPF_SYSCALL",
    "BPF_JIT",
    "DEBUG_INFO_BTF"
  ],
  "FocusSymbols": [
    "bpf_check_core_relo",
    "bpf_core_apply",
    "bpf_core_patch_insn",
    "bpf_patch_insn_data",
    "bpf_jit_blind_constants",
    "bpf_is_state_visited",
    "map_set_for_each_callback_args"
  ],
  "KMSANReasoning": "The patch series addresses several distinct issues within the BPF subsystem:\n1. Bounds checking in CO-RE relocation (`bpf_core_patch_insn`): Adds a bounds check to ensure `insn[1]` is within bounds before handling 64-bit immediate instructions (`LDIMM64`), preventing out-of-bounds memory accesses on truncated instructions. Any such OOB bug is detectable by KASAN.\n2. Packet pointer displacement check in `regsafe`: Restricts state pruning when packet pointers sharing an ID have different base displacements (`r64.base`). This fixes a verifier soundness flaw where out-of-bounds packet accesses could be accepted, which is an OOB issue caught by KASAN.\n3. Inner map UID tracking in `bpf_reg_state`: Moves `map_uid` out of the metadata union so it participates in ID mapping during state equivalence checks (`regs_exact` and `regsafe`), preventing incorrect lock identity matching. The register structures are fully zeroed upon allocation and in initialization helpers (`__mark_reg_known`, `bpf_mark_reg_unknown_imprecise`), leaving no uninitialized fields or padding.\n4. Signal interruption in JIT blinding and instruction rewrite passes: Adds fatal signal checks (`fatal_signal_pending`) and clean error returns (`-EINTR`) during post-verification fixups.\n5. CO-RE pass reordering: Invokes `bpf_check_core_relo` before discovering subprograms to ensure the subprogram layout matches the rewritten instructions.\n\nNone of these modifications introduce reads of uninitialized stack or heap memory, info-leaks to userspace, or branching on uninitialized data. Standard KASAN, LOCKDEP, and existing verifier assertions provide full coverage for the hazards touched by this patch series. Therefore, a dedicated KMSAN fuzzing session is not warranted.",
  "NeedsKMSAN": false,
  "Reasoning": "The patch series modifies core BPF verifier, CO-RE relocation, instruction patching, and JIT compilation logic. Specifically, it shifts CO-RE relocation processing earlier in bpf_check() prior to subprogram discovery, adds bounds checking for truncated LDIMM64 instructions in bpf_core_patch_insn(), introduces fatal signal abort handling during instruction rewrites and constant blinding (bpf_patch_insn_data, verifier_remove_insns, bpf_jit_blind_constants), moves map_uid in bpf_reg_state to enforce ID comparison in regsafe() and regs_exact(), preserves register base displacements across shared IDs in regsafe(), and updates callback register state ID generation. These paths are fully reachable via the bpf(BPF_PROG_LOAD) system call and warrant fuzzing for verifier state pruning regressions, assertion failures, and memory safety issues.",
  "WorthFuzzing": true
}

1/1 2026/09/15 00:03 action read-patch-diff
0m Args:
null

Results:
{
  "PatchDiff": "commit 4ce8c96f29bca22d19f9affe4d12f9f87256f289\nAuthor: syz-cluster \u003ctriage@syzkaller.com\u003e\nDate:   Tue Sep 15 00:03:16 2026 +0000\n\n    syz-cluster: applied patch under review\n\ndiff --git a/include/linux/bpf.h b/include/linux/bpf.h\nindex e57af902560c3..62155d87ce31b 100644\n--- a/include/linux/bpf.h\n+++ b/include/linux/bpf.h\n@@ -3196,7 +3196,7 @@ bool btf_type_ids_nocast_alias(struct bpf_verifier_log *log,\n \t\t\t       const struct btf *arg_btf, u32 arg_id);\n \n int bpf_core_apply(struct bpf_core_ctx *ctx, const struct bpf_core_relo *relo,\n-\t\t   int relo_idx, void *insn);\n+\t\t   int relo_idx, void *insn, size_t insn_cnt);\n \n static inline bool unprivileged_ebpf_enabled(void)\n {\ndiff --git a/include/linux/bpf_verifier.h b/include/linux/bpf_verifier.h\nindex 36b65797877d0..1aa245faa30e2 100644\n--- a/include/linux/bpf_verifier.h\n+++ b/include/linux/bpf_verifier.h\n@@ -46,17 +46,10 @@ struct bpf_reg_state {\n \t\t/* valid when type == PTR_TO_PACKET */\n \t\tint range;\n \n-\t\t/* valid when type == CONST_PTR_TO_MAP | PTR_TO_MAP_VALUE |\n-\t\t *   PTR_TO_MAP_VALUE_OR_NULL\n+\t\t/*\n+\t\t * For CONST_PTR_TO_MAP, PTR_TO_MAP_KEY and PTR_TO_MAP_VALUE.\n \t\t */\n-\t\tstruct {\n-\t\t\tstruct bpf_map *map_ptr;\n-\t\t\t/* To distinguish map lookups from outer map\n-\t\t\t * the map_uid is non-zero for registers\n-\t\t\t * pointing to inner maps.\n-\t\t\t */\n-\t\t\tu32 map_uid;\n-\t\t};\n+\t\tstruct bpf_map *map_ptr;\n \n \t\t/* for PTR_TO_BTF_ID */\n \t\tstruct {\n@@ -155,13 +148,20 @@ struct bpf_reg_state {\n \t * gets parent_id set to the dynptr's id.\n \t */\n \tu32 parent_id;\n-\t/* Inside the callee two registers can be both PTR_TO_STACK like\n+\t/*\n+\t * Distinguishes inner-map lookups and their keys and values. Zero for\n+\t * other registers. Kept outside the metadata union for ID remapping\n+\t * during state comparisons.\n+\t */\n+\tu32 map_uid;\n+\t/*\n+\t * Inside the callee two registers can be both PTR_TO_STACK like\n \t * R1=fp-8 and R2=fp-8, but one of them points to this function stack\n \t * while another to the caller's stack. To differentiate them 'frameno'\n \t * is used which is an index in bpf_verifier_state-\u003eframe[] array\n \t * pointing to bpf_func_state.\n \t */\n-\tu32 frameno;\n+\tu8 frameno;\n \t/* if (!precise \u0026\u0026 SCALAR_VALUE) min/max/tnum don't affect safety */\n \tbool precise;\n };\n@@ -1197,6 +1197,8 @@ static inline void bpf_trampoline_unpack_key(u64 key, u32 *obj_id, u32 *btf_id)\n \n int bpf_prepare_btf_info(struct bpf_verifier_env *env,\n \t\t\t const union bpf_attr *attr, bpfptr_t uattr);\n+int bpf_check_core_relo(struct bpf_verifier_env *env,\n+\t\t\tconst union bpf_attr *attr, bpfptr_t uattr);\n int bpf_check_btf_info(struct bpf_verifier_env *env,\n \t\t       const union bpf_attr *attr, bpfptr_t uattr);\n \ndiff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c\nindex d67a169ba2bb3..78cd9661cdbd2 100644\n--- a/kernel/bpf/btf.c\n+++ b/kernel/bpf/btf.c\n@@ -9729,7 +9729,7 @@ bpf_core_find_cands(struct bpf_core_ctx *ctx, u32 local_type_id)\n }\n \n int bpf_core_apply(struct bpf_core_ctx *ctx, const struct bpf_core_relo *relo,\n-\t\t   int relo_idx, void *insn)\n+\t\t   int relo_idx, void *insn, size_t insn_cnt)\n {\n \tbool need_cands = relo-\u003ekind != BPF_CORE_TYPE_ID_LOCAL;\n \tstruct bpf_core_cand_list cands = {};\n@@ -9793,8 +9793,8 @@ int bpf_core_apply(struct bpf_core_ctx *ctx, const struct bpf_core_relo *relo,\n \tif (err)\n \t\tgoto out;\n \n-\terr = bpf_core_patch_insn((void *)ctx-\u003elog, insn, relo-\u003einsn_off / 8, relo, relo_idx,\n-\t\t\t\t  \u0026targ_res);\n+\terr = bpf_core_patch_insn((void *)ctx-\u003elog, insn, insn_cnt, relo-\u003einsn_off / 8,\n+\t\t\t\t  relo, relo_idx, \u0026targ_res);\n \n out:\n \tkfree(specs);\ndiff --git a/kernel/bpf/check_btf.c b/kernel/bpf/check_btf.c\nindex 0e8b3ccc7a5b9..63d0375f5bb07 100644\n--- a/kernel/bpf/check_btf.c\n+++ b/kernel/bpf/check_btf.c\n@@ -338,9 +338,9 @@ static int check_btf_line(struct bpf_verifier_env *env,\n #define MIN_CORE_RELO_SIZE\tsizeof(struct bpf_core_relo)\n #define MAX_CORE_RELO_SIZE\tMAX_FUNCINFO_REC_SIZE\n \n-static int check_core_relo(struct bpf_verifier_env *env,\n-\t\t\t   const union bpf_attr *attr,\n-\t\t\t   bpfptr_t uattr)\n+int bpf_check_core_relo(struct bpf_verifier_env *env,\n+\t\t\tconst union bpf_attr *attr,\n+\t\t\tbpfptr_t uattr)\n {\n \tu32 i, nr_core_relo, ncopy, expected_size, rec_size;\n \tstruct bpf_core_relo core_relo = {};\n@@ -399,7 +399,7 @@ static int check_core_relo(struct bpf_verifier_env *env,\n \t\t}\n \n \t\terr = bpf_core_apply(\u0026ctx, \u0026core_relo, i,\n-\t\t\t\t     \u0026prog-\u003einsnsi[core_relo.insn_off / 8]);\n+\t\t\t\t     \u0026prog-\u003einsnsi[core_relo.insn_off / 8], prog-\u003elen);\n \t\tif (err)\n \t\t\tbreak;\n \t\tbpfptr_add(\u0026u_core_relo, rec_size);\n@@ -414,7 +414,7 @@ int bpf_prepare_btf_info(struct bpf_verifier_env *env,\n \tstruct btf *btf;\n \tint err;\n \n-\tif (!attr-\u003efunc_info_cnt \u0026\u0026 !attr-\u003eline_info_cnt) {\n+\tif (!attr-\u003efunc_info_cnt \u0026\u0026 !attr-\u003eline_info_cnt \u0026\u0026 !attr-\u003ecore_relo_cnt) {\n \t\tif (check_abnormal_return(env))\n \t\t\treturn -EINVAL;\n \t\treturn 0;\n@@ -455,9 +455,5 @@ int bpf_check_btf_info(struct bpf_verifier_env *env,\n \tif (err)\n \t\treturn err;\n \n-\terr = check_core_relo(env, attr, uattr);\n-\tif (err)\n-\t\treturn err;\n-\n \treturn 0;\n }\ndiff --git a/kernel/bpf/core.c b/kernel/bpf/core.c\nindex 8b294dfc1ad4d..2e3bf8113ae9b 100644\n--- a/kernel/bpf/core.c\n+++ b/kernel/bpf/core.c\n@@ -19,6 +19,7 @@\n \n #include \u003cuapi/linux/btf.h\u003e\n #include \u003clinux/filter.h\u003e\n+#include \u003clinux/sched/signal.h\u003e\n #include \u003clinux/skbuff.h\u003e\n #include \u003clinux/static_call.h\u003e\n #include \u003clinux/vmalloc.h\u003e\n@@ -1619,6 +1620,8 @@ struct bpf_prog *bpf_jit_blind_constants(struct bpf_verifier_env *env, struct bp\n \t\t\t * fix it up here on error.\n \t\t\t */\n \t\t\tbpf_jit_prog_release_other(prog, clone);\n+\t\t\tif (env \u0026\u0026 fatal_signal_pending(current))\n+\t\t\t\treturn ERR_PTR(-EINTR);\n \t\t\treturn IS_ERR(tmp) ? tmp : ERR_PTR(-ENOMEM);\n \t\t}\n \n@@ -2636,11 +2639,14 @@ static struct bpf_prog *bpf_prog_jit_compile(struct bpf_verifier_env *env, struc\n \torig_prog = prog;\n \tprog = bpf_jit_blind_constants(env, prog);\n \t/*\n-\t * If blinding was requested and we failed during blinding, we must fall\n-\t * back to the interpreter.\n+\t * Fall back to the interpreter after blinding failures, except when\n+\t * the loader was killed.\n \t */\n-\tif (IS_ERR(prog))\n+\tif (IS_ERR(prog)) {\n+\t\tif (PTR_ERR(prog) == -EINTR)\n+\t\t\treturn prog;\n \t\tgoto out_restore;\n+\t}\n \n \tprog = bpf_int_jit_compile(env, prog);\n \tif (prog-\u003ejited) {\n@@ -2659,6 +2665,8 @@ static struct bpf_prog *bpf_prog_jit_compile(struct bpf_verifier_env *env, struc\n struct bpf_prog *__bpf_prog_select_runtime(struct bpf_verifier_env *env, struct bpf_prog *fp,\n \t\t\t\t\t   int *err)\n {\n+\tstruct bpf_prog *jit_prog;\n+\n \t/* In case of BPF to BPF calls, verifier did all the prep\n \t * work with regards to JITing, etc.\n \t */\n@@ -2681,7 +2689,12 @@ struct bpf_prog *__bpf_prog_select_runtime(struct bpf_verifier_env *env, struct\n \t\tif (*err)\n \t\t\treturn fp;\n \n-\t\tfp = bpf_prog_jit_compile(env, fp);\n+\t\tjit_prog = bpf_prog_jit_compile(env, fp);\n+\t\tif (IS_ERR(jit_prog)) {\n+\t\t\t*err = PTR_ERR(jit_prog);\n+\t\t\treturn fp;\n+\t\t}\n+\t\tfp = jit_prog;\n \t\tbpf_prog_jit_attempt_done(fp);\n \t\tif (!fp-\u003ejited \u0026\u0026 jit_needed) {\n \t\t\t*err = -ENOTSUPP;\ndiff --git a/kernel/bpf/fixups.c b/kernel/bpf/fixups.c\nindex 52d3cec336727..d6f83521fc78e 100644\n--- a/kernel/bpf/fixups.c\n+++ b/kernel/bpf/fixups.c\n@@ -8,6 +8,7 @@\n #include \u003clinux/bsearch.h\u003e\n #include \u003clinux/sort.h\u003e\n #include \u003clinux/perf_event.h\u003e\n+#include \u003clinux/sched/signal.h\u003e\n #include \u003cnet/xdp.h\u003e\n #include \"disasm.h\"\n \n@@ -306,12 +307,28 @@ static void adjust_poke_descs(struct bpf_prog *prog, u32 off, u32 len)\n \t}\n }\n \n+/*\n+ * Some post-verification instruction rewriting passes require an\n+ * O(prog-\u003elen) operation per instruction. Keep their shared primitives\n+ * killable and preemptible.\n+ */\n+static bool bpf_rewrite_must_abort(void)\n+{\n+\tif (fatal_signal_pending(current))\n+\t\treturn true;\n+\tcond_resched();\n+\treturn false;\n+}\n+\n struct bpf_prog *bpf_patch_insn_data(struct bpf_verifier_env *env, u32 off,\n \t\t\t\t     const struct bpf_insn *patch, u32 len)\n {\n \tstruct bpf_prog *new_prog;\n \tstruct bpf_insn_aux_data *new_data = NULL;\n \n+\tif (bpf_rewrite_must_abort())\n+\t\treturn NULL;\n+\n \tif (len \u003e 1) {\n \t\tnew_data = vrealloc(env-\u003einsn_aux_data,\n \t\t\t\t    array_size(env-\u003eprog-\u003elen + len - 1,\n@@ -523,6 +540,9 @@ static int verifier_remove_insns(struct bpf_verifier_env *env, u32 off, u32 cnt)\n \tunsigned int orig_prog_len = env-\u003eprog-\u003elen;\n \tint err;\n \n+\tif (bpf_rewrite_must_abort())\n+\t\treturn -EINTR;\n+\n \tif (bpf_prog_is_offloaded(env-\u003eprog-\u003eaux))\n \t\tbpf_prog_offload_remove_insns(env, off, cnt);\n \n@@ -1356,7 +1376,7 @@ int bpf_jit_subprogs(struct bpf_verifier_env *env)\n \t\t}\n \t\tprog = bpf_jit_blind_constants(env, prog);\n \t\tif (IS_ERR(prog)) {\n-\t\t\terr = -ENOMEM;\n+\t\t\terr = PTR_ERR(prog);\n \t\t\tprog = orig_prog;\n \t\t\tgoto out_restore;\n \t\t}\n@@ -1433,7 +1453,7 @@ int bpf_fixup_call_args(struct bpf_verifier_env *env)\n \t\terr = bpf_jit_subprogs(env);\n \t\tif (err == 0)\n \t\t\treturn 0;\n-\t\tif (err == -EFAULT)\n+\t\tif (err == -EFAULT || err == -EINTR)\n \t\t\treturn err;\n \t}\n #ifndef CONFIG_BPF_JIT_ALWAYS_ON\ndiff --git a/kernel/bpf/states.c b/kernel/bpf/states.c\nindex 66fb11b6c6a76..e4ec007f7fa61 100644\n--- a/kernel/bpf/states.c\n+++ b/kernel/bpf/states.c\n@@ -491,7 +491,8 @@ static bool regs_exact(const struct bpf_reg_state *rold,\n {\n \treturn memcmp(rold, rcur, offsetof(struct bpf_reg_state, id)) == 0 \u0026\u0026\n \t       check_ids(rold-\u003eid, rcur-\u003eid, idmap) \u0026\u0026\n-\t       check_ids(rold-\u003eparent_id, rcur-\u003eparent_id, idmap);\n+\t       check_ids(rold-\u003eparent_id, rcur-\u003eparent_id, idmap) \u0026\u0026\n+\t       check_ids(rold-\u003emap_uid, rcur-\u003emap_uid, idmap);\n }\n \n enum exact_level {\n@@ -616,7 +617,8 @@ static bool regsafe(struct bpf_verifier_env *env, struct bpf_reg_state *rold,\n \t\t       range_within(rold, rcur) \u0026\u0026\n \t\t       tnum_in(rold-\u003evar_off, rcur-\u003evar_off) \u0026\u0026\n \t\t       check_ids(rold-\u003eid, rcur-\u003eid, idmap) \u0026\u0026\n-\t\t       check_ids(rold-\u003eparent_id, rcur-\u003eparent_id, idmap);\n+\t\t       check_ids(rold-\u003eparent_id, rcur-\u003eparent_id, idmap) \u0026\u0026\n+\t\t       check_ids(rold-\u003emap_uid, rcur-\u003emap_uid, idmap);\n \tcase PTR_TO_PACKET_META:\n \tcase PTR_TO_PACKET:\n \t\t/* We must have at least as much range as the old ptr\n@@ -635,6 +637,9 @@ static bool regsafe(struct bpf_verifier_env *env, struct bpf_reg_state *rold,\n \t\t/* id relations must be preserved */\n \t\tif (!check_ids(rold-\u003eid, rcur-\u003eid, idmap))\n \t\t\treturn false;\n+\t\t/* Preserve displacements between pointers sharing an ID. */\n+\t\tif (rold-\u003eid \u0026\u0026 rold-\u003er64.base != rcur-\u003er64.base)\n+\t\t\treturn false;\n \t\t/* new val must satisfy old val knowledge */\n \t\treturn range_within(rold, rcur) \u0026\u0026\n \t\t       tnum_in(rold-\u003evar_off, rcur-\u003evar_off);\ndiff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c\nindex ddba53eaa3331..a39d13a6614d7 100644\n--- a/kernel/bpf/verifier.c\n+++ b/kernel/bpf/verifier.c\n@@ -1864,6 +1864,7 @@ static void __mark_reg_known(struct bpf_reg_state *reg, u64 imm)\n \t       offsetof(struct bpf_reg_state, var_off) - sizeof(reg-\u003etype));\n \treg-\u003eid = 0;\n \treg-\u003eparent_id = 0;\n+\treg-\u003emap_uid = 0;\n \t___mark_reg_known(reg, imm);\n }\n \n@@ -1925,17 +1926,18 @@ static void refine_map_lookup_value(struct bpf_reg_state *reg)\n \tif (map-\u003einner_map_meta) {\n \t\treg-\u003etype = CONST_PTR_TO_MAP | maybe_null;\n \t\treg-\u003emap_ptr = map-\u003einner_map_meta;\n-\t\t/* transfer reg's id which is unique for every map_lookup_elem\n+\t\t/*\n+\t\t * transfer reg's id which is unique for every map_lookup_elem\n \t\t * as UID of the inner map.\n \t\t */\n-\t\tif (btf_record_has_field(map-\u003einner_map_meta-\u003erecord,\n-\t\t\t\t\t BPF_TIMER | BPF_WORKQUEUE | BPF_TASK_WORK))\n-\t\t\treg-\u003emap_uid = reg-\u003eid;\n+\t\treg-\u003emap_uid = reg-\u003eid;\n \t} else if (map-\u003emap_type == BPF_MAP_TYPE_XSKMAP) {\n \t\treg-\u003etype = PTR_TO_XDP_SOCK | maybe_null;\n+\t\treg-\u003emap_uid = 0;\n \t} else if (map-\u003emap_type == BPF_MAP_TYPE_SOCKMAP ||\n \t\t   map-\u003emap_type == BPF_MAP_TYPE_SOCKHASH) {\n \t\treg-\u003etype = PTR_TO_SOCKET | maybe_null;\n+\t\treg-\u003emap_uid = 0;\n \t}\n }\n \n@@ -10048,6 +10050,7 @@ int map_set_for_each_callback_args(struct bpf_verifier_env *env,\n \t__mark_reg_known_zero(\u0026callee-\u003eregs[BPF_REG_3]);\n \tcallee-\u003eregs[BPF_REG_3].map_ptr = caller-\u003eregs[BPF_REG_1].map_ptr;\n \tcallee-\u003eregs[BPF_REG_3].map_uid = caller-\u003eregs[BPF_REG_1].map_uid;\n+\tcallee-\u003eregs[BPF_REG_3].id = ++env-\u003eid_gen;\n \n \t/* pointer to stack or null */\n \tcallee-\u003eregs[BPF_REG_4] = caller-\u003eregs[BPF_REG_3];\n@@ -10144,6 +10147,7 @@ static int set_timer_callback_state(struct bpf_verifier_env *env,\n \t__mark_reg_known_zero(\u0026callee-\u003eregs[BPF_REG_3]);\n \tcallee-\u003eregs[BPF_REG_3].map_ptr = map_ptr;\n \tcallee-\u003eregs[BPF_REG_3].map_uid = map_uid;\n+\tcallee-\u003eregs[BPF_REG_3].id = ++env-\u003eid_gen;\n \n \t/* unused */\n \tbpf_mark_reg_not_init(env, \u0026callee-\u003eregs[BPF_REG_4]);\n@@ -10262,6 +10266,7 @@ static int set_task_work_schedule_callback_state(struct bpf_verifier_env *env,\n \t__mark_reg_known_zero(\u0026callee-\u003eregs[BPF_REG_3]);\n \tcallee-\u003eregs[BPF_REG_3].map_ptr = map_ptr;\n \tcallee-\u003eregs[BPF_REG_3].map_uid = map_uid;\n+\tcallee-\u003eregs[BPF_REG_3].id = ++env-\u003eid_gen;\n \n \t/* unused */\n \tbpf_mark_reg_not_init(env, \u0026callee-\u003eregs[BPF_REG_4]);\n@@ -21271,6 +21276,11 @@ int bpf_check(struct bpf_prog **prog, union bpf_attr *attr, bpfptr_t uattr,\n \tif (ret \u003c 0)\n \t\tgoto skip_full_check;\n \n+\t/* Apply CO-RE before validating the program's instruction layout. */\n+\tret = bpf_check_core_relo(env, attr, uattr);\n+\tif (ret \u003c 0)\n+\t\tgoto skip_full_check;\n+\n \t/* Discover all subprograms before validating their layout and BTF. */\n \tret = add_subprogs(env);\n \tif (ret \u003c 0)\n@@ -21280,7 +21290,7 @@ int bpf_check(struct bpf_prog **prog, union bpf_attr *attr, bpfptr_t uattr,\n \tif (ret \u003c 0)\n \t\tgoto skip_full_check;\n \n-\t/* Validate BTF against the complete subprogram layout and apply CO-RE. */\n+\t/* Validate BTF against the complete subprogram layout. */\n \tret = bpf_check_btf_info(env, attr, uattr);\n \tif (ret \u003c 0)\n \t\tgoto skip_full_check;\ndiff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c\nindex b749c01742ee0..619e664f0c00f 100644\n--- a/tools/lib/bpf/libbpf.c\n+++ b/tools/lib/bpf/libbpf.c\n@@ -6223,7 +6223,8 @@ bpf_object__relocate_core(struct bpf_object *obj, const char *targ_btf_path)\n \t\t\t\tgoto out;\n \t\t\t}\n \n-\t\t\terr = bpf_core_patch_insn(prog-\u003ename, insn, insn_idx, rec, i, \u0026targ_res);\n+\t\t\terr = bpf_core_patch_insn(prog-\u003ename, insn, prog-\u003einsns_cnt, insn_idx,\n+\t\t\t\t\t\t  rec, i, \u0026targ_res);\n \t\t\tif (err) {\n \t\t\t\tpr_warn(\"prog '%s': relo #%d: failed to patch insn #%d: %s\\n\",\n \t\t\t\t\tprog-\u003ename, i, insn_idx, errstr(err));\ndiff --git a/tools/lib/bpf/relo_core.c b/tools/lib/bpf/relo_core.c\nindex 8ad2715721cfd..92ff923f0d137 100644\n--- a/tools/lib/bpf/relo_core.c\n+++ b/tools/lib/bpf/relo_core.c\n@@ -980,23 +980,30 @@ static int bpf_core_calc_relo(const char *prog_name,\n }\n \n /*\n- * Turn instruction for which CO_RE relocation failed into invalid one with\n+ * Turn instruction for which CO-RE relocation failed into invalid one with\n  * distinct signature.\n  */\n-static void bpf_core_poison_insn(const char *prog_name, int relo_idx,\n-\t\t\t\t int insn_idx, struct bpf_insn *insn)\n+static int bpf_core_poison_insn(const char *prog_name, int relo_idx,\n+\t\t\t\tstruct bpf_insn *insn, int insn_idx)\n {\n-\tpr_debug(\"prog '%s': relo #%d: substituting insn #%d w/ invalid insn\\n\",\n-\t\t prog_name, relo_idx, insn_idx);\n-\tinsn-\u003ecode = BPF_JMP | BPF_CALL;\n-\tinsn-\u003edst_reg = 0;\n-\tinsn-\u003esrc_reg = 0;\n-\tinsn-\u003eoff = 0;\n-\t/* if this instruction is reachable (not a dead code),\n-\t * verifier will complain with the following message:\n-\t * invalid func unknown#195896080\n-\t */\n-\tinsn-\u003eimm = 195896080; /* =\u003e 0xbad2310 =\u003e \"bad relo\" */\n+\tint insn_cnt = is_ldimm64_insn(insn) ? 2 : 1;\n+\tint i;\n+\n+\tfor (i = 0; i \u003c insn_cnt; i++) {\n+\t\tpr_debug(\"prog '%s': relo #%d: substituting insn #%d w/ invalid insn\\n\",\n+\t\t\t prog_name, relo_idx, insn_idx + i);\n+\t\tinsn[i].code = BPF_JMP | BPF_CALL;\n+\t\tinsn[i].dst_reg = 0;\n+\t\tinsn[i].src_reg = 0;\n+\t\tinsn[i].off = 0;\n+\t\t/*\n+\t\t * If this instruction is reachable (not dead code), the verifier\n+\t\t * will complain with \"invalid func unknown#195896080\".\n+\t\t */\n+\t\tinsn[i].imm = 195896080; /* =\u003e 0xbad2310 =\u003e \"bad relo\" */\n+\t}\n+\n+\treturn 0;\n }\n \n static int insn_bpf_size_to_bytes(struct bpf_insn *insn)\n@@ -1039,25 +1046,21 @@ static int insn_bytes_to_bpf_size(__u32 sz)\n  * 6. *(T *)(rX + \u003coff\u003e) = \u003cimm\u003e, where T is one of {u8, u16, u32, u64}.\n  */\n int bpf_core_patch_insn(const char *prog_name, struct bpf_insn *insn,\n-\t\t\tint insn_idx, const struct bpf_core_relo *relo,\n-\t\t\tint relo_idx, const struct bpf_core_relo_res *res)\n+\t\t\tsize_t insn_cnt, int insn_idx,\n+\t\t\tconst struct bpf_core_relo *relo, int relo_idx,\n+\t\t\tconst struct bpf_core_relo_res *res)\n {\n \t__u64 orig_val, new_val;\n \t__u8 class;\n \n-\tclass = BPF_CLASS(insn-\u003ecode);\n-\n-\tif (res-\u003epoison) {\n-poison:\n-\t\t/* poison second part of ldimm64 to avoid confusing error from\n-\t\t * verifier about \"unknown opcode 00\"\n-\t\t */\n-\t\tif (is_ldimm64_insn(insn))\n-\t\t\tbpf_core_poison_insn(prog_name, relo_idx, insn_idx + 1, insn + 1);\n-\t\tbpf_core_poison_insn(prog_name, relo_idx, insn_idx, insn);\n-\t\treturn 0;\n+\tif (is_ldimm64_insn(insn) \u0026\u0026 (size_t)insn_idx + 1 \u003e= insn_cnt) {\n+\t\tpr_warn(\"prog '%s': relo #%d: insn #%d (LDIMM64) is truncated\\n\",\n+\t\t\tprog_name, relo_idx, insn_idx);\n+\t\treturn -EINVAL;\n \t}\n \n+\tclass = BPF_CLASS(insn-\u003ecode);\n+\n \torig_val = res-\u003eorig_val;\n \tnew_val = res-\u003enew_val;\n \n@@ -1065,7 +1068,9 @@ int bpf_core_patch_insn(const char *prog_name, struct bpf_insn *insn,\n \tcase BPF_ALU:\n \tcase BPF_ALU64:\n \t\tif (BPF_SRC(insn-\u003ecode) != BPF_K)\n-\t\t\treturn -EINVAL;\n+\t\t\tgoto bad_insn;\n+\t\tif (res-\u003epoison)\n+\t\t\treturn bpf_core_poison_insn(prog_name, relo_idx, insn, insn_idx);\n \t\tif (res-\u003evalidate \u0026\u0026 insn-\u003eimm != orig_val) {\n \t\t\tpr_warn(\"prog '%s': relo #%d: unexpected insn #%d (ALU/ALU64) value: got %d, exp %llu -\u003e %llu\\n\",\n \t\t\t\tprog_name, relo_idx,\n@@ -1082,6 +1087,8 @@ int bpf_core_patch_insn(const char *prog_name, struct bpf_insn *insn,\n \tcase BPF_LDX:\n \tcase BPF_ST:\n \tcase BPF_STX:\n+\t\tif (res-\u003epoison)\n+\t\t\treturn bpf_core_poison_insn(prog_name, relo_idx, insn, insn_idx);\n \t\tif (res-\u003evalidate \u0026\u0026 insn-\u003eoff != orig_val) {\n \t\t\tpr_warn(\"prog '%s': relo #%d: unexpected insn #%d (LDX/ST/STX) value: got %d, exp %llu -\u003e %llu\\n\",\n \t\t\t\tprog_name, relo_idx, insn_idx, insn-\u003eoff, (unsigned long long)orig_val,\n@@ -1097,7 +1104,7 @@ int bpf_core_patch_insn(const char *prog_name, struct bpf_insn *insn,\n \t\t\tpr_warn(\"prog '%s': relo #%d: insn #%d (LDX/ST/STX) accesses field incorrectly. \"\n \t\t\t\t\"Make sure you are accessing pointers, unsigned integers, or fields of matching type and size.\\n\",\n \t\t\t\tprog_name, relo_idx, insn_idx);\n-\t\t\tgoto poison;\n+\t\t\treturn bpf_core_poison_insn(prog_name, relo_idx, insn, insn_idx);\n \t\t}\n \n \t\torig_val = insn-\u003eoff;\n@@ -1140,6 +1147,9 @@ int bpf_core_patch_insn(const char *prog_name, struct bpf_insn *insn,\n \t\t\treturn -EINVAL;\n \t\t}\n \n+\t\tif (res-\u003epoison)\n+\t\t\treturn bpf_core_poison_insn(prog_name, relo_idx, insn, insn_idx);\n+\n \t\timm = (__u32)insn[0].imm | ((__u64)insn[1].imm \u003c\u003c 32);\n \t\tif (res-\u003evalidate \u0026\u0026 imm != orig_val) {\n \t\t\tpr_warn(\"prog '%s': relo #%d: unexpected insn #%d (LDIMM64) value: got %llu, exp %llu -\u003e %llu\\n\",\n@@ -1157,6 +1167,7 @@ int bpf_core_patch_insn(const char *prog_name, struct bpf_insn *insn,\n \t\tbreak;\n \t}\n \tdefault:\n+bad_insn:\n \t\tpr_warn(\"prog '%s': relo #%d: trying to relocate unrecognized insn #%d, code:0x%x, src:0x%x, dst:0x%x, off:0x%x, imm:0x%x\\n\",\n \t\t\tprog_name, relo_idx, insn_idx, insn-\u003ecode,\n \t\t\t(unsigned)insn-\u003esrc_reg, (unsigned)insn-\u003edst_reg, (unsigned)insn-\u003eoff, (unsigned)insn-\u003eimm);\ndiff --git a/tools/lib/bpf/relo_core.h b/tools/lib/bpf/relo_core.h\nindex 1c0566daf8e88..db2e106dc73db 100644\n--- a/tools/lib/bpf/relo_core.h\n+++ b/tools/lib/bpf/relo_core.h\n@@ -87,8 +87,9 @@ int bpf_core_calc_relo_insn(const char *prog_name,\n \t\t\t    struct bpf_core_relo_res *targ_res);\n \n int bpf_core_patch_insn(const char *prog_name, struct bpf_insn *insn,\n-\t\t\tint insn_idx, const struct bpf_core_relo *relo,\n-\t\t\tint relo_idx, const struct bpf_core_relo_res *res);\n+\t\t\tsize_t insn_cnt, int insn_idx,\n+\t\t\tconst struct bpf_core_relo *relo, int relo_idx,\n+\t\t\tconst struct bpf_core_relo_res *res);\n \n int bpf_core_parse_spec(const char *prog_name, const struct btf *btf,\n \t\t        const struct bpf_core_relo *relo,\ndiff --git a/tools/testing/selftests/bpf/prog_tests/cb_refs.c b/tools/testing/selftests/bpf/prog_tests/cb_refs.c\nindex 78566b817fd70..490e15e7126d9 100644\n--- a/tools/testing/selftests/bpf/prog_tests/cb_refs.c\n+++ b/tools/testing/selftests/bpf/prog_tests/cb_refs.c\n@@ -13,7 +13,7 @@ struct {\n } cb_refs_tests[] = {\n \t{ \"underflow_prog\", \"release kfunc bpf_kfunc_call_test_release expects referenced PTR_TO_BTF_ID passed to R1\" },\n \t{ \"leak_prog\", \"Possibly NULL pointer passed to helper R2\" },\n-\t{ \"nested_cb\", \"Unreleased reference id=4 alloc_insn=2\" }, /* alloc_insn=2{4,5} */\n+\t{ \"nested_cb\", \"Unreleased reference id=5 alloc_insn=2\" }, /* alloc_insn=2{4,5} */\n \t{ \"non_cb_transfer_ref\", \"Unreleased reference id=4 alloc_insn=1\" }, /* alloc_insn=1{1,2} */\n };\n \ndiff --git a/tools/testing/selftests/bpf/prog_tests/core_reloc_raw.c b/tools/testing/selftests/bpf/prog_tests/core_reloc_raw.c\nindex a18d3680fb169..90f1ea85354d0 100644\n--- a/tools/testing/selftests/bpf/prog_tests/core_reloc_raw.c\n+++ b/tools/testing/selftests/bpf/prog_tests/core_reloc_raw.c\n@@ -14,6 +14,197 @@\n \n static char log[16 * 1024];\n \n+static int load_core_relo_insns(int btf_fd, struct bpf_insn *insns, int insn_cnt,\n+\t\t\t\tstruct bpf_func_info *funcs, int func_cnt,\n+\t\t\t\tint enum_id, int access_str_off, int insn_idx,\n+\t\t\t\tbool relocate)\n+{\n+\tstruct bpf_core_relo relo = {\n+\t\t.insn_off = insn_idx * sizeof(struct bpf_insn),\n+\t\t.type_id = enum_id,\n+\t\t.access_str_off = access_str_off,\n+\t\t.kind = BPF_CORE_ENUMVAL_VALUE,\n+\t};\n+\tunion bpf_attr attr = {\n+\t\t.prog_type = BPF_PROG_TYPE_SOCKET_FILTER,\n+\t\t.insn_cnt = insn_cnt,\n+\t\t.insns = (__u64)insns,\n+\t\t.license = (__u64)\"GPL\",\n+\t\t.log_buf = (__u64)log,\n+\t\t.log_size = sizeof(log),\n+\t\t.log_level = 2,\n+\t\t.prog_btf_fd = btf_fd,\n+\t\t.func_info_rec_size = sizeof(struct bpf_func_info),\n+\t\t.func_info = (__u64)funcs,\n+\t\t.func_info_cnt = func_cnt,\n+\t};\n+\n+\tif (relocate) {\n+\t\tattr.core_relo_cnt = 1;\n+\t\tattr.core_relos = (__u64)\u0026relo;\n+\t\tattr.core_relo_rec_size = sizeof(relo);\n+\t}\n+\tmemset(log, 0, sizeof(log));\n+\treturn sys_bpf_prog_load(\u0026attr, sizeof(attr), 1);\n+}\n+\n+static void test_early_core_relo(void)\n+{\n+\tstatic const char unrecognized[] = \"trying to relocate unrecognized insn #2\";\n+\tstatic const struct {\n+\t\tconst char *name;\n+\t\tstruct bpf_insn insns[2];\n+\t\tconst char *err_msg;\n+\t} tests[] = {\n+\t\t{ \"poison_exit\", { BPF_EXIT_INSN() }, unrecognized },\n+\t\t{ \"poison_ja\", { BPF_JMP_A(1) }, unrecognized },\n+\t\t{ \"poison_jmp\", { BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 1) }, unrecognized },\n+\t\t{ \"poison_jmp32\", { BPF_JMP32_IMM(BPF_JEQ, BPF_REG_0, 0, 1) }, unrecognized },\n+\t\t{ \"poison_call\", { BPF_EMIT_CALL(BPF_FUNC_get_prandom_u32) }, unrecognized },\n+\t\t{ \"poison_alu_reg\", { BPF_MOV32_REG(BPF_REG_0, BPF_REG_1) }, unrecognized },\n+\t\t{ \"poison_alu64_reg\", { BPF_MOV64_REG(BPF_REG_0, BPF_REG_1) }, unrecognized },\n+\t\t{ \"poison_ld_abs\", { BPF_LD_ABS(BPF_W, 0) },\n+\t\t  \"insn #2 (LDIMM64) has unexpected form\" },\n+\t\t{ \"poison_alu_imm\", { BPF_MOV32_IMM(BPF_REG_0, 0) } },\n+\t\t{ \"poison_alu64_imm\", { BPF_MOV64_IMM(BPF_REG_0, 0) } },\n+\t\t{ \"poison_ldx\", { BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1, 0) } },\n+\t\t{ \"poison_st\", { BPF_ST_MEM(BPF_W, BPF_REG_10, -4, 0) } },\n+\t\t{ \"poison_stx\", { BPF_STX_MEM(BPF_W, BPF_REG_10, BPF_REG_0, -4) } },\n+\t\t{ \"poison_ldimm64\", { BPF_LD_IMM64(BPF_REG_0, 0) } },\n+\t};\n+\tstruct bpf_insn core_only[] = {\n+\t\tBPF_MOV64_IMM(BPF_REG_0, 0),\n+\t\tBPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 1),\n+\t\tBPF_MOV64_IMM(BPF_REG_0, 0),\n+\t\tBPF_EXIT_INSN(),\n+\t};\n+\tstruct bpf_insn subprog[] = {\n+\t\tBPF_CALL_REL(2),\n+\t\tBPF_MOV64_IMM(BPF_REG_0, 0),\n+\t\tBPF_EXIT_INSN(),\n+\t\tBPF_MOV64_IMM(BPF_REG_0, 0),\n+\t\tBPF_EXIT_INSN(),\n+\t};\n+\tstruct bpf_func_info funcs[2];\n+\tconst void *raw_btf;\n+\tstruct btf *btf;\n+\t__u32 raw_btf_size;\n+\tint access_str_off, btf_fd = -1, enum_id;\n+\tint int_id, main_id, prog_fd = -1, proto_id, sub_id, i;\n+\n+\tbtf = btf__new_empty();\n+\tif (!ASSERT_OK_PTR(btf, \"btf_new_empty\"))\n+\t\treturn;\n+\tint_id = btf__add_int(btf, \"int\", 4, BTF_INT_SIGNED);\n+\tif (!ASSERT_GT(int_id, 0, \"add_int\"))\n+\t\tgoto cleanup;\n+\tproto_id = btf__add_func_proto(btf, int_id);\n+\tif (!ASSERT_GT(proto_id, 0, \"add_func_proto\"))\n+\t\tgoto cleanup;\n+\tmain_id = btf__add_func(btf, \"main_fn\", BTF_FUNC_STATIC, proto_id);\n+\tif (!ASSERT_GT(main_id, 0, \"add_main_func\"))\n+\t\tgoto cleanup;\n+\tsub_id = btf__add_func(btf, \"sub_fn\", BTF_FUNC_STATIC, proto_id);\n+\tif (!ASSERT_GT(sub_id, 0, \"add_sub_func\"))\n+\t\tgoto cleanup;\n+\tenum_id = btf__add_enum(btf, \"core_relo_poison_missing\", 4);\n+\tif (!ASSERT_GT(enum_id, 0, \"add_enum\") ||\n+\t    !ASSERT_OK(btf__add_enum_value(btf, \"value\", 0), \"add_enum_value\"))\n+\t\tgoto cleanup;\n+\taccess_str_off = btf__add_str(btf, \"0\");\n+\tif (!ASSERT_GT(access_str_off, 0, \"add_access_str\"))\n+\t\tgoto cleanup;\n+\n+\traw_btf = btf__raw_data(btf, \u0026raw_btf_size);\n+\tif (!ASSERT_OK_PTR(raw_btf, \"raw_btf\"))\n+\t\tgoto cleanup;\n+\tbtf_fd = bpf_btf_load(raw_btf, raw_btf_size, NULL);\n+\tif (!ASSERT_GE(btf_fd, 0, \"btf_load\"))\n+\t\tgoto cleanup;\n+\tfuncs[0] = (struct bpf_func_info) { .insn_off = 0, .type_id = main_id };\n+\tfuncs[1] = (struct bpf_func_info) { .insn_off = 3, .type_id = sub_id };\n+\n+\tif (test__start_subtest(\"without_func_info\")) {\n+\t\tprog_fd = load_core_relo_insns(btf_fd, core_only, ARRAY_SIZE(core_only), NULL, 0,\n+\t\t\t\t\t       enum_id, access_str_off, 2, false);\n+\t\tif (!ASSERT_GE(prog_fd, 0, \"control_load\"))\n+\t\t\tgoto cleanup;\n+\t\tclose(prog_fd);\n+\t\tprog_fd = load_core_relo_insns(btf_fd, core_only, ARRAY_SIZE(core_only), NULL, 0,\n+\t\t\t\t\t       enum_id, access_str_off, 2, true);\n+\t\tif (!ASSERT_GE(prog_fd, 0, \"poisoned_load\"))\n+\t\t\tgoto cleanup;\n+\t\tASSERT_HAS_SUBSTR(log, \"substituting insn #2\", \"poison_log\");\n+\t\tclose(prog_fd);\n+\t\tprog_fd = -1;\n+\t}\n+\n+\tif (test__start_subtest(\"poisoned_subprog_terminator\")) {\n+\t\tprog_fd = load_core_relo_insns(btf_fd, subprog, ARRAY_SIZE(subprog), funcs, 2,\n+\t\t\t\t\t       enum_id, access_str_off, 2, false);\n+\t\tif (!ASSERT_GE(prog_fd, 0, \"control_load\"))\n+\t\t\tgoto cleanup;\n+\t\tclose(prog_fd);\n+\t\tprog_fd = load_core_relo_insns(btf_fd, subprog, ARRAY_SIZE(subprog), funcs, 2,\n+\t\t\t\t\t       enum_id, access_str_off, 2, true);\n+\t\tif (!ASSERT_LT(prog_fd, 0, \"poisoned_load\"))\n+\t\t\tgoto cleanup;\n+\t\tASSERT_HAS_SUBSTR(log, unrecognized, \"poisoned_load_log\");\n+\t}\n+\n+\tfor (i = 0; i \u003c ARRAY_SIZE(tests); i++) {\n+\t\tstruct bpf_insn insns[] = {\n+\t\t\tBPF_MOV64_IMM(BPF_REG_0, 0),\n+\t\t\tBPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 2),\n+\t\t\ttests[i].insns[0],\n+\t\t\tBPF_MOV64_IMM(BPF_REG_0, 0),\n+\t\t\tBPF_MOV64_IMM(BPF_REG_0, 0),\n+\t\t\tBPF_EXIT_INSN(),\n+\t\t};\n+\t\tbool is_ldimm64 = insns[2].code == (BPF_LD | BPF_DW | BPF_IMM);\n+\t\tint insn_cnt = ARRAY_SIZE(insns);\n+\n+\t\tif (!test__start_subtest(tests[i].name))\n+\t\t\tcontinue;\n+\t\tif (is_ldimm64) {\n+\t\t\tinsns[3] = tests[i].insns[1];\n+\t\t} else {\n+\t\t\tinsns[1].off = 1;\n+\t\t\tinsns[4] = BPF_EXIT_INSN();\n+\t\t\tinsn_cnt--;\n+\t\t}\n+\t\tprog_fd = load_core_relo_insns(btf_fd, insns, insn_cnt, funcs, 1,\n+\t\t\t\t\t       enum_id, access_str_off, 2, false);\n+\t\tif (!ASSERT_GE(prog_fd, 0, \"control_load\"))\n+\t\t\tgoto cleanup;\n+\t\tclose(prog_fd);\n+\t\tprog_fd = load_core_relo_insns(btf_fd, insns, insn_cnt, funcs, 1,\n+\t\t\t\t\t       enum_id, access_str_off, 2, true);\n+\t\tif (!tests[i].err_msg) {\n+\t\t\tASSERT_GE(prog_fd, 0, \"dead_poison_load\");\n+\t\t\tASSERT_HAS_SUBSTR(log, \"substituting insn #2\", \"poison_log\");\n+\t\t\tif (is_ldimm64)\n+\t\t\t\tASSERT_HAS_SUBSTR(log, \"substituting insn #3\", \"poison_ldimm64_log\");\n+\t\t} else {\n+\t\t\tASSERT_LT(prog_fd, 0, \"invalid_poison_load\");\n+\t\t\tASSERT_HAS_SUBSTR(log, tests[i].err_msg, \"invalid_poison_log\");\n+\t\t\tASSERT_NULL(strstr(log, \"substituting insn\"), \"invalid_poison_substitution\");\n+\t\t}\n+\t\tclose(prog_fd);\n+\t\tprog_fd = -1;\n+\t}\n+\n+cleanup:\n+\tif (env.verbosity \u003e VERBOSE_NORMAL \u0026\u0026 log[0]) {\n+\t\tprintf(\"-------- program load log start --------\\n\");\n+\t\tprintf(\"%s\", log);\n+\t\tprintf(\"-------- program load log end ----------\\n\");\n+\t}\n+\tclose(prog_fd);\n+\tclose(btf_fd);\n+\tbtf__free(btf);\n+}\n+\n /* Check that verifier rejects BPF program containing relocation\n  * pointing to non-existent BTF type.\n  */\n@@ -120,6 +311,7 @@ static void test_bad_local_id(void)\n \n void test_core_reloc_raw(void)\n {\n+\ttest_early_core_relo();\n \tif (test__start_subtest(\"bad_local_id\"))\n \t\ttest_bad_local_id();\n }\ndiff --git a/tools/testing/selftests/bpf/prog_tests/core_reloc_truncated_ldimm64.c b/tools/testing/selftests/bpf/prog_tests/core_reloc_truncated_ldimm64.c\nnew file mode 100644\nindex 0000000000000..b70c8874241de\n--- /dev/null\n+++ b/tools/testing/selftests/bpf/prog_tests/core_reloc_truncated_ldimm64.c\n@@ -0,0 +1,82 @@\n+// SPDX-License-Identifier: GPL-2.0\n+/* Copyright (c) 2026 Meta Platforms, Inc. and affiliates. */\n+\n+#include \u003celf.h\u003e\n+#include \u003ctest_progs.h\u003e\n+\n+#include \"core_reloc_truncated_ldimm64.skel.h\"\n+\n+static bool truncate_ldimm64_prog(void *elf_data, size_t elf_sz, const char *prog_name)\n+{\n+\tElf64_Ehdr *ehdr = elf_data;\n+\tElf64_Shdr *shdrs;\n+\tElf64_Sym *syms;\n+\tconst char *strs;\n+\tsize_t i, j;\n+\n+\tif (elf_sz \u003c sizeof(*ehdr) || ehdr-\u003ee_shoff \u003e elf_sz ||\n+\t    ehdr-\u003ee_shnum \u003e (elf_sz - ehdr-\u003ee_shoff) / sizeof(*shdrs))\n+\t\treturn false;\n+\n+\tshdrs = elf_data + ehdr-\u003ee_shoff;\n+\tfor (i = 0; i \u003c ehdr-\u003ee_shnum; i++) {\n+\t\tif (shdrs[i].sh_type != SHT_SYMTAB)\n+\t\t\tcontinue;\n+\t\tsyms = elf_data + shdrs[i].sh_offset;\n+\t\tstrs = elf_data + shdrs[shdrs[i].sh_link].sh_offset;\n+\t\tfor (j = 0; j \u003c shdrs[i].sh_size / sizeof(*syms); j++) {\n+\t\t\tif (ELF64_ST_TYPE(syms[j].st_info) == STT_FUNC \u0026\u0026\n+\t\t\t    !strcmp(strs + syms[j].st_name, prog_name)) {\n+\t\t\t\tsyms[j].st_size = sizeof(struct bpf_insn);\n+\t\t\t\treturn true;\n+\t\t\t}\n+\t\t}\n+\t}\n+\n+\treturn false;\n+}\n+\n+static void run_test(const char *prog_name)\n+{\n+\tconst void *elf_bytes;\n+\tsize_t elf_sz;\n+\tstruct bpf_object *obj = NULL;\n+\tvoid *elf_data = NULL;\n+\tchar *log = NULL;\n+\tint err;\n+\n+\telf_bytes = core_reloc_truncated_ldimm64__elf_bytes(\u0026elf_sz);\n+\tif (!ASSERT_OK_PTR(elf_bytes, \"elf_bytes\"))\n+\t\treturn;\n+\n+\telf_data = malloc(elf_sz);\n+\tif (!ASSERT_OK_PTR(elf_data, \"elf_data\"))\n+\t\treturn;\n+\tmemcpy(elf_data, elf_bytes, elf_sz);\n+\tif (!ASSERT_TRUE(truncate_ldimm64_prog(elf_data, elf_sz, prog_name), \"truncate_prog\"))\n+\t\tgoto cleanup;\n+\n+\tobj = bpf_object__open_mem(elf_data, elf_sz, NULL);\n+\tif (!ASSERT_OK_PTR(obj, \"obj_open\"))\n+\t\tgoto cleanup;\n+\n+\tif (start_libbpf_log_capture())\n+\t\tgoto cleanup;\n+\terr = bpf_object__prepare(obj);\n+\tlog = stop_libbpf_log_capture();\n+\tASSERT_EQ(err, -EINVAL, \"obj_prepare\");\n+\tASSERT_HAS_SUBSTR(log, \"insn #0 (LDIMM64) is truncated\", \"libbpf_log\");\n+\n+cleanup:\n+\tfree(log);\n+\tbpf_object__close(obj);\n+\tfree(elf_data);\n+}\n+\n+void test_core_reloc_truncated_ldimm64(void)\n+{\n+\tif (test__start_subtest(\"resolved\"))\n+\t\trun_test(\"core_reloc_truncated_ldimm64_resolved\");\n+\tif (test__start_subtest(\"poison\"))\n+\t\trun_test(\"core_reloc_truncated_ldimm64_poison\");\n+}\ndiff --git a/tools/testing/selftests/bpf/prog_tests/spin_lock.c b/tools/testing/selftests/bpf/prog_tests/spin_lock.c\nindex 5c3579438427d..d49f52a8f8223 100644\n--- a/tools/testing/selftests/bpf/prog_tests/spin_lock.c\n+++ b/tools/testing/selftests/bpf/prog_tests/spin_lock.c\n@@ -10,8 +10,8 @@ static char log_buf[1024 * 1024];\n \n static struct {\n \tconst char *prog_name;\n-\tconst char *err_msg;\n-} spin_lock_fail_tests[] = {\n+\tconst char *err_msg; /* NULL if loading should succeed. */\n+} spin_lock_tests[] = {\n \t{ \"lock_id_kptr_preserve\",\n \t  \"[0-9]\\\\+: (bf) r1 = r0                       ; R0=ptr_foo(id=2)\"\n \t  \" R1=ptr_foo(id=2) refs=2\\n\"\n@@ -54,6 +54,22 @@ static struct {\n \t{ \"lock_global_sleepable_helper_subprog\", \"global function calls are not allowed while holding a lock\" },\n \t{ \"lock_global_sleepable_kfunc_subprog\", \"global function calls are not allowed while holding a lock\" },\n \t{ \"lock_global_sleepable_subprog_indirect\", \"global function calls are not allowed while holding a lock\" },\n+\t{ \"callback_value_lock_identity\", \"bpf_spin_unlock of different lock\" },\n+\t{ \"callback_inner_map_value_lock_identity\", \"bpf_spin_unlock of different lock\" },\n+\t{ \"callback_value_lock_identity_same\", NULL },\n+\t{ \"callback_single_value_lock_identity_same\", NULL },\n+\t{ \"lock_id_timer_preserve\",\n+\t  \"R1=map_value(id=[1-9][0-9]*,map=async_lock_map,[^\\n]*\\n\"\n+\t  \"[0-9]\\\\+: (85) call bpf_this_cpu_ptr#154\\n\"\n+\t  \"R1 type=map_value expected=percpu_ptr_\" },\n+\t{ \"lock_id_wq_preserve\",\n+\t  \"R1=map_value(id=[1-9][0-9]*,map=async_lock_map,[^\\n]*\\n\"\n+\t  \"[0-9]\\\\+: (85) call bpf_this_cpu_ptr#154\\n\"\n+\t  \"R1 type=map_value expected=percpu_ptr_\" },\n+\t{ \"lock_id_task_work_preserve\",\n+\t  \"R1=map_value(id=[1-9][0-9]*,map=async_lock_map,[^\\n]*\\n\"\n+\t  \"[0-9]\\\\+: (85) call bpf_this_cpu_ptr#154\\n\"\n+\t  \"R1 type=map_value expected=percpu_ptr_\" },\n };\n \n static int match_regex(const char *pattern, const char *string)\n@@ -74,7 +90,7 @@ static int match_regex(const char *pattern, const char *string)\n \treturn rc == 0 ? 1 : 0;\n }\n \n-static void test_spin_lock_fail_prog(const char *prog_name, const char *err_msg)\n+static void test_spin_lock_prog(const char *prog_name, const char *err_msg)\n {\n \tLIBBPF_OPTS(bpf_object_open_opts, opts, .kernel_log_buf = log_buf,\n \t\t\t\t\t\t.kernel_log_size = sizeof(log_buf),\n@@ -94,6 +110,10 @@ static void test_spin_lock_fail_prog(const char *prog_name, const char *err_msg)\n \tbpf_program__set_autoload(prog, true);\n \n \tret = test_spin_lock_fail__load(skel);\n+\tif (!err_msg) {\n+\t\tASSERT_OK(ret, \"test_spin_lock_fail__load\");\n+\t\tgoto end;\n+\t}\n \tif (!ASSERT_ERR(ret, \"test_spin_lock_fail__load must fail\"))\n \t\tgoto end;\n \n@@ -166,10 +186,9 @@ void test_spin_lock(void)\n \n \ttest_spin_lock_success();\n \n-\tfor (i = 0; i \u003c ARRAY_SIZE(spin_lock_fail_tests); i++) {\n-\t\tif (!test__start_subtest(spin_lock_fail_tests[i].prog_name))\n+\tfor (i = 0; i \u003c ARRAY_SIZE(spin_lock_tests); i++) {\n+\t\tif (!test__start_subtest(spin_lock_tests[i].prog_name))\n \t\t\tcontinue;\n-\t\ttest_spin_lock_fail_prog(spin_lock_fail_tests[i].prog_name,\n-\t\t\t\t\t spin_lock_fail_tests[i].err_msg);\n+\t\ttest_spin_lock_prog(spin_lock_tests[i].prog_name, spin_lock_tests[i].err_msg);\n \t}\n }\ndiff --git a/tools/testing/selftests/bpf/progs/core_reloc_truncated_ldimm64.c b/tools/testing/selftests/bpf/progs/core_reloc_truncated_ldimm64.c\nnew file mode 100644\nindex 0000000000000..d8d9a3650fe0d\n--- /dev/null\n+++ b/tools/testing/selftests/bpf/progs/core_reloc_truncated_ldimm64.c\n@@ -0,0 +1,27 @@\n+// SPDX-License-Identifier: GPL-2.0\n+/* Copyright (c) 2026 Meta Platforms, Inc. and affiliates. */\n+\n+#include \"vmlinux.h\"\n+\n+#include \u003cbpf/bpf_helpers.h\u003e\n+#include \u003cbpf/bpf_core_read.h\u003e\n+\n+enum core_reloc_truncated_ldimm64 {\n+\tCORE_RELOC_TRUNCATED_LDIMM64_VALUE,\n+};\n+\n+SEC(\"raw_tracepoint/sys_enter\")\n+int core_reloc_truncated_ldimm64_resolved(void *ctx)\n+{\n+\treturn bpf_core_enum_value_exists(enum core_reloc_truncated_ldimm64,\n+\t\t\t\t\t  CORE_RELOC_TRUNCATED_LDIMM64_VALUE);\n+}\n+\n+SEC(\"raw_tracepoint/sys_exit\")\n+int core_reloc_truncated_ldimm64_poison(void *ctx)\n+{\n+\treturn bpf_core_enum_value(enum core_reloc_truncated_ldimm64,\n+\t\t\t\t   CORE_RELOC_TRUNCATED_LDIMM64_VALUE);\n+}\n+\n+char LICENSE[] SEC(\"license\") = \"GPL\";\ndiff --git a/tools/testing/selftests/bpf/progs/test_spin_lock_fail.c b/tools/testing/selftests/bpf/progs/test_spin_lock_fail.c\nindex f678ee6bd7eaf..a27bbbe3523fb 100644\n--- a/tools/testing/selftests/bpf/progs/test_spin_lock_fail.c\n+++ b/tools/testing/selftests/bpf/progs/test_spin_lock_fail.c\n@@ -14,17 +14,18 @@ struct array_map {\n \t__type(key, int);\n \t__type(value, struct foo);\n \t__uint(max_entries, 1);\n-} array_map SEC(\".maps\");\n+} array_map SEC(\".maps\"), array_map_b SEC(\".maps\");\n \n struct {\n \t__uint(type, BPF_MAP_TYPE_ARRAY_OF_MAPS);\n-\t__uint(max_entries, 1);\n+\t__uint(max_entries, 2);\n \t__type(key, int);\n \t__type(value, int);\n \t__array(values, struct array_map);\n } map_of_maps SEC(\".maps\") = {\n \t.values = {\n \t\t[0] = \u0026array_map,\n+\t\t[1] = \u0026array_map_b,\n \t},\n };\n \n@@ -314,4 +315,166 @@ int lock_global_sleepable_subprog_indirect(struct __sk_buff *ctx)\n \treturn ret;\n }\n \n+struct {\n+\t__uint(type, BPF_MAP_TYPE_ARRAY);\n+\t__uint(max_entries, 2);\n+\t__type(key, int);\n+\t__type(value, struct foo);\n+} callback_array_map SEC(\".maps\");\n+\n+struct callback_ctx {\n+\tstruct foo *value;\n+};\n+\n+static long lock_different_value(struct bpf_map *map, int *key,\n+\t\t\t\t struct foo *value, struct callback_ctx *ctx)\n+{\n+\tbpf_spin_lock(\u0026value-\u003elock);\n+\tbpf_spin_unlock(\u0026ctx-\u003evalue-\u003elock);\n+\treturn 0;\n+}\n+\n+static long nest_lock_different_value(struct bpf_map *map, int *key,\n+\t\t\t\t      struct foo *value, void *data)\n+{\n+\tstruct callback_ctx ctx = { .value = value };\n+\n+\tbpf_for_each_map_elem(\u0026callback_array_map, lock_different_value, \u0026ctx, 0);\n+\treturn 0;\n+}\n+\n+SEC(\"?tc\")\n+int callback_value_lock_identity(void *ctx)\n+{\n+\tbpf_for_each_map_elem(\u0026callback_array_map, nest_lock_different_value, NULL, 0);\n+\treturn 0;\n+}\n+\n+static long nest_lock_different_inner_value(struct bpf_map *map, int *key,\n+\t\t\t\t\t    struct foo *value, void *data)\n+{\n+\tstruct callback_ctx ctx = { .value = value };\n+\tint inner_key = 1;\n+\tvoid *inner_map;\n+\n+\tinner_map = bpf_map_lookup_elem(\u0026map_of_maps, \u0026inner_key);\n+\tif (!inner_map)\n+\t\treturn 0;\n+\tbpf_for_each_map_elem(inner_map, lock_different_value, \u0026ctx, 0);\n+\treturn 0;\n+}\n+\n+SEC(\"?tc\")\n+int callback_inner_map_value_lock_identity(void *ctx)\n+{\n+\tint inner_key = 0;\n+\tvoid *inner_map;\n+\n+\tinner_map = bpf_map_lookup_elem(\u0026map_of_maps, \u0026inner_key);\n+\tif (!inner_map)\n+\t\treturn 0;\n+\tbpf_for_each_map_elem(inner_map, nest_lock_different_inner_value, NULL, 0);\n+\treturn 0;\n+}\n+\n+static long lock_same_value(struct bpf_map *map, int *key,\n+\t\t\t    struct foo *value, void *data)\n+{\n+\tbpf_spin_lock(\u0026value-\u003elock);\n+\tbpf_spin_unlock(\u0026value-\u003elock);\n+\treturn 0;\n+}\n+\n+static long nest_lock_same_value(struct bpf_map *map, int *key,\n+\t\t\t\t struct foo *value, void *data)\n+{\n+\tbpf_for_each_map_elem(\u0026callback_array_map, lock_same_value, NULL, 0);\n+\treturn 0;\n+}\n+\n+SEC(\"?tc\")\n+int callback_value_lock_identity_same(void *ctx)\n+{\n+\tbpf_for_each_map_elem(\u0026callback_array_map, nest_lock_same_value, NULL, 0);\n+\treturn 0;\n+}\n+\n+SEC(\"?tc\")\n+int callback_single_value_lock_identity_same(void *ctx)\n+{\n+\tbpf_for_each_map_elem(\u0026array_map, lock_same_value, NULL, 0);\n+\treturn 0;\n+}\n+\n+struct async_lock_value {\n+\tstruct bpf_spin_lock lock;\n+\tstruct bpf_timer timer;\n+\tstruct bpf_wq work;\n+\tstruct bpf_task_work task_work;\n+\tint counter;\n+};\n+\n+struct {\n+\t__uint(type, BPF_MAP_TYPE_ARRAY);\n+\t__uint(max_entries, 2);\n+\t__type(key, int);\n+\t__type(value, struct async_lock_value);\n+} async_lock_map SEC(\".maps\");\n+\n+/*\n+ * Expose the callback value ID in the verifier log, as in lock_id_mapval_preserve().\n+ */\n+static int async_lock_id_preserve(void *map, int *key, void *data)\n+{\n+\tstruct async_lock_value *value = data;\n+\n+\tbpf_spin_lock(\u0026value-\u003elock);\n+\tvalue-\u003ecounter++;\n+\tbpf_spin_unlock(\u0026value-\u003elock);\n+\tbpf_this_cpu_ptr(value);\n+\treturn 0;\n+}\n+\n+SEC(\"?tc\")\n+int lock_id_timer_preserve(void *ctx)\n+{\n+\tstruct async_lock_value *value;\n+\tint key = 0;\n+\n+\tvalue = bpf_map_lookup_elem(\u0026async_lock_map, \u0026key);\n+\tif (value \u0026\u0026 !bpf_timer_init(\u0026value-\u003etimer, \u0026async_lock_map, 1))\n+\t\tbpf_timer_set_callback(\u0026value-\u003etimer, async_lock_id_preserve);\n+\treturn 0;\n+}\n+\n+SEC(\"?tc\")\n+int lock_id_wq_preserve(void *ctx)\n+{\n+\tstruct async_lock_value *value;\n+\tint key = 0;\n+\n+\tvalue = bpf_map_lookup_elem(\u0026async_lock_map, \u0026key);\n+\tif (value \u0026\u0026 !bpf_wq_init(\u0026value-\u003ework, \u0026async_lock_map, 0))\n+\t\tbpf_wq_set_callback(\u0026value-\u003ework, async_lock_id_preserve, 0);\n+\treturn 0;\n+}\n+\n+static int task_work_lock_id_preserve(struct bpf_map *map, void *key, void *data)\n+{\n+\treturn async_lock_id_preserve(map, key, data);\n+}\n+\n+SEC(\"?tc\")\n+int lock_id_task_work_preserve(void *ctx)\n+{\n+\tstruct async_lock_value *value;\n+\tint key = 0;\n+\n+\tvalue = bpf_map_lookup_elem(\u0026async_lock_map, \u0026key);\n+\tif (value)\n+\t\tbpf_task_work_schedule_resume(bpf_get_current_task_btf(), \u0026value-\u003etask_work,\n+\t\t\t\t\t      \u0026async_lock_map, task_work_lock_id_preserve);\n+\treturn 0;\n+}\n+\n char _license[] SEC(\"license\") = \"GPL\";\ndiff --git a/tools/testing/selftests/bpf/progs/verifier_xdp_direct_packet_access.c b/tools/testing/selftests/bpf/progs/verifier_xdp_direct_packet_access.c\nindex 0b86d95a41335..9866bc154194a 100644\n--- a/tools/testing/selftests/bpf/progs/verifier_xdp_direct_packet_access.c\n+++ b/tools/testing/selftests/bpf/progs/verifier_xdp_direct_packet_access.c\n@@ -1719,4 +1719,39 @@ l0_%=:\tr0 = 0;\t\t\t\t\t\t\\\n \t: __clobber_all);\n }\n \n+SEC(\"xdp\")\n+__description(\"XDP pkt regsafe preserves packet pointer class displacement\")\n+__failure __msg(\"R2 min value is outside of the allowed memory range\")\n+__flag(BPF_F_ANY_ALIGNMENT) __flag(BPF_F_TEST_STATE_FREQ)\n+__naked void pkt_regsafe_class_displacement(void)\n+{\n+\tasm volatile (\"\t\t\t\t\t\\\n+\tr8 = *(u32 *)(r1 + %[xdp_md_data_end]);\t\t\\\n+\tr9 = *(u32 *)(r1 + %[xdp_md_data]);\t\t\\\n+\tr4 = *(u32 *)(r1 + %[xdp_md_rx_queue_index]);\t\\\n+\tr4 \u0026= 15;\t\t\t\t\t\\\n+\tr0 = *(u32 *)(r1 + %[xdp_md_ingress_ifindex]);\t\\\n+\tif r0 != 0 goto l0_%=;\t\t\t\t\\\n+\tr2 = r9;\t\t\t\t\t\\\n+\tr2 += r4;\t\t\t\t\t\\\n+\tr3 = r2;\t\t\t\t\t\\\n+\tr3 += 8;\t\t\t\t\t\\\n+\tgoto l1_%=;\t\t\t\t\t\\\n+l0_%=:\tr4 \u0026= 3;\t\t\t\t\t\\\n+\tr4 += 8;\t\t\t\t\t\\\n+\tr2 = r9;\t\t\t\t\t\\\n+\tr2 += r4;\t\t\t\t\t\\\n+\tr3 = r2;\t\t\t\t\t\\\n+l1_%=:\tif r3 \u003e r8 goto l2_%=;\t\t\t\t\\\n+\tr0 = *(u64 *)(r2 + 0);\t\t\t\t\\\n+l2_%=:\tr0 = 0;\t\t\t\t\t\t\\\n+\texit;\t\t\t\t\t\t\\\n+\"\t:\n+\t: __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),\n+\t  __imm_const(xdp_md_data_end, offsetof(struct xdp_md, data_end)),\n+\t  __imm_const(xdp_md_rx_queue_index, offsetof(struct xdp_md, rx_queue_index)),\n+\t  __imm_const(xdp_md_ingress_ifindex, offsetof(struct xdp_md, ingress_ifindex))\n+\t: __clobber_all);\n+}\n+\n char _license[] SEC(\"license\") = \"GPL\";\n"
}

2/1 2026/09/15 00:03 agent patch-evaluator
5m Model:
core

Args:
null

Results:
{
  "EnableConfigs": [
    "BPF_SYSCALL",
    "BPF_JIT",
    "DEBUG_INFO_BTF"
  ],
  "FocusSymbols": [
    "bpf_check_core_relo",
    "bpf_core_apply",
    "bpf_core_patch_insn",
    "bpf_patch_insn_data",
    "bpf_jit_blind_constants",
    "bpf_is_state_visited",
    "map_set_for_each_callback_args"
  ],
  "Reasoning": "The patch series modifies core BPF verifier, CO-RE relocation, instruction patching, and JIT compilation logic. Specifically, it shifts CO-RE relocation processing earlier in bpf_check() prior to subprogram discovery, adds bounds checking for truncated LDIMM64 instructions in bpf_core_patch_insn(), introduces fatal signal abort handling during instruction rewrites and constant blinding (bpf_patch_insn_data, verifier_remove_insns, bpf_jit_blind_constants), moves map_uid in bpf_reg_state to enforce ID comparison in regsafe() and regs_exact(), preserves register base displacements across shared IDs in regsafe(), and updates callback register state ID generation. These paths are fully reachable via the bpf(BPF_PROG_LOAD) system call and warrant fuzzing for verifier state pruning regressions, assertion failures, and memory safety issues.",
  "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 4ce8c96f29bca22d19f9affe4d12f9f87256f289
Author: syz-cluster <triage@syzkaller.com>
Date:   Tue Sep 15 00:03:16 2026 +0000

    syz-cluster: applied patch under review

diff --git a/include/linux/bpf.h b/include/linux/bpf.h
index e57af902560c3..62155d87ce31b 100644
--- a/include/linux/bpf.h
+++ b/include/linux/bpf.h
@@ -3196,7 +3196,7 @@ bool btf_type_ids_nocast_alias(struct bpf_verifier_log *log,
 			       const struct btf *arg_btf, u32 arg_id);
 
 int bpf_core_apply(struct bpf_core_ctx *ctx, const struct bpf_core_relo *relo,
-		   int relo_idx, void *insn);
+		   int relo_idx, void *insn, size_t insn_cnt);
 
 static inline bool unprivileged_ebpf_enabled(void)
 {
diff --git a/include/linux/bpf_verifier.h b/include/linux/bpf_verifier.h
index 36b65797877d0..1aa245faa30e2 100644
--- a/include/linux/bpf_verifier.h
+++ b/include/linux/bpf_verifier.h
@@ -46,17 +46,10 @@ struct bpf_reg_state {
 		/* valid when type == PTR_TO_PACKET */
 		int range;
 
-		/* valid when type == CONST_PTR_TO_MAP | PTR_TO_MAP_VALUE |
-		 *   PTR_TO_MAP_VALUE_OR_NULL
+		/*
+		 * For CONST_PTR_TO_MAP, PTR_TO_MAP_KEY and PTR_TO_MAP_VALUE.
 		 */
-		struct {
-			struct bpf_map *map_ptr;
-			/* To distinguish map lookups from outer map
-			 * the map_uid is non-zero for registers
-			 * pointing to inner maps.
-			 */
-			u32 map_uid;
-		};
+		struct bpf_map *map_ptr;
 
 		/* for PTR_TO_BTF_ID */
 		struct {
@@ -155,13 +148,20 @@ struct bpf_reg_state {
 	 * gets parent_id set to the dynptr's id.
 	 */
 	u32 parent_id;
-	/* Inside the callee two registers can be both PTR_TO_STACK like
+	/*
+	 * Distinguishes inner-map lookups and their keys and values. Zero for
+	 * other registers. Kept outside the metadata union for ID remapping
+	 * during state comparisons.
+	 */
+	u32 map_uid;
+	/*
+	 * Inside the callee two registers can be both PTR_TO_STACK like
 	 * R1=fp-8 and R2=fp-8, but one of them points to this function stack
 	 * while another to the caller's stack. To differentiate them 'frameno'
 	 * is used which is an index in bpf_verifier_state->frame[] array
 	 * pointing to bpf_func_state.
 	 */
-	u32 frameno;
+	u8 frameno;
 	/* if (!precise && SCALAR_VALUE) min/max/tnum don't affect safety */
 	bool precise;
 };
@@ -1197,6 +1197,8 @@ static inline void bpf_trampoline_unpack_key(u64 key, u32 *obj_id, u32 *btf_id)
 
 int bpf_prepare_btf_info(struct bpf_verifier_env *env,
 			 const union bpf_attr *attr, bpfptr_t uattr);
+int bpf_check_core_relo(struct bpf_verifier_env *env,
+			const union bpf_attr *attr, bpfptr_t uattr);
 int bpf_check_btf_info(struct bpf_verifier_env *env,
 		       const union bpf_attr *attr, bpfptr_t uattr);
 
diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
index d67a169ba2bb3..78cd9661cdbd2 100644
--- a/kernel/bpf/btf.c
+++ b/kernel/bpf/btf.c
@@ -9729,7 +9729,7 @@ bpf_core_find_cands(struct bpf_core_ctx *ctx, u32 local_type_id)
 }
 
 int bpf_core_apply(struct bpf_core_ctx *ctx, const struct bpf_core_relo *relo,
-		   int relo_idx, void *insn)
+		   int relo_idx, void *insn, size_t insn_cnt)
 {
 	bool need_cands = relo->kind != BPF_CORE_TYPE_ID_LOCAL;
 	struct bpf_core_cand_list cands = {};
@@ -9793,8 +9793,8 @@ int bpf_core_apply(struct bpf_core_ctx *ctx, const struct bpf_core_relo *relo,
 	if (err)
 		goto out;
 
-	err = bpf_core_patch_insn((void *)ctx->log, insn, relo->insn_off / 8, relo, relo_idx,
-				  &targ_res);
+	err = bpf_core_patch_insn((void *)ctx->log, insn, insn_cnt, relo->insn_off / 8,
+				  relo, relo_idx, &targ_res);
 
 out:
 	kfree(specs);
diff --git a/kernel/bpf/check_btf.c b/kernel/bpf/check_btf.c
index 0e8b3ccc7a5b9..63d0375f5bb07 100644
--- a/kernel/bpf/check_btf.c
+++ b/kernel/bpf/check_btf.c
@@ -338,9 +338,9 @@ static int check_btf_line(struct bpf_verifier_env *env,
 #define MIN_CORE_RELO_SIZE	sizeof(struct bpf_core_relo)
 #define MAX_CORE_RELO_SIZE	MAX_FUNCINFO_REC_SIZE
 
-static int check_core_relo(struct bpf_verifier_env *env,
-			   const union bpf_attr *attr,
-			   bpfptr_t uattr)
+int bpf_check_core_relo(struct bpf_verifier_env *env,
+			const union bpf_attr *attr,
+			bpfptr_t uattr)
 {
 	u32 i, nr_core_relo, ncopy, expected_size, rec_size;
 	struct bpf_core_relo core_relo = {};
@@ -399,7 +399,7 @@ static int check_core_relo(struct bpf_verifier_env *env,
 		}
 
 		err = bpf_core_apply(&ctx, &core_relo, i,
-				     &prog->insnsi[core_relo.insn_off / 8]);
+				     &prog->insnsi[core_relo.insn_off / 8], prog->len);
 		if (err)
 			break;
 		bpfptr_add(&u_core_relo, rec_size);
@@ -414,7 +414,7 @@ int bpf_prepare_btf_info(struct bpf_verifier_env *env,
 	struct btf *btf;
 	int err;
 
-	if (!attr->func_info_cnt && !attr->line_info_cnt) {
+	if (!attr->func_info_cnt && !attr->line_info_cnt && !attr->core_relo_cnt) {
 		if (check_abnormal_return(env))
 			return -EINVAL;
 		return 0;
@@ -455,9 +455,5 @@ int bpf_check_btf_info(struct bpf_verifier_env *env,
 	if (err)
 		return err;
 
-	err = check_core_relo(env, attr, uattr);
-	if (err)
-		return err;
-
 	return 0;
 }
diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
index 8b294dfc1ad4d..2e3bf8113ae9b 100644
--- a/kernel/bpf/core.c
+++ b/kernel/bpf/core.c
@@ -19,6 +19,7 @@
 
 #include <uapi/linux/btf.h>
 #include <linux/filter.h>
+#include <linux/sched/signal.h>
 #include <linux/skbuff.h>
 #include <linux/static_call.h>
 #include <linux/vmalloc.h>
@@ -1619,6 +1620,8 @@ struct bpf_prog *bpf_jit_blind_constants(struct bpf_verifier_env *env, struct bp
 			 * fix it up here on error.
 			 */
 			bpf_jit_prog_release_other(prog, clone);
+			if (env && fatal_signal_pending(current))
+				return ERR_PTR(-EINTR);
 			return IS_ERR(tmp) ? tmp : ERR_PTR(-ENOMEM);
 		}
 
@@ -2636,11 +2639,14 @@ static struct bpf_prog *bpf_prog_jit_compile(struct bpf_verifier_env *env, struc
 	orig_prog = prog;
 	prog = bpf_jit_blind_constants(env, prog);
 	/*
-	 * If blinding was requested and we failed during blinding, we must fall
-	 * back to the interpreter.
+	 * Fall back to the interpreter after blinding failures, except when
+	 * the loader was killed.
 	 */
-	if (IS_ERR(prog))
+	if (IS_ERR(prog)) {
+		if (PTR_ERR(prog) == -EINTR)
+			return prog;
 		goto out_restore;
+	}
 
 	prog = bpf_int_jit_compile(env, prog);
 	if (prog->jited) {
@@ -2659,6 +2665,8 @@ static struct bpf_prog *bpf_prog_jit_compile(struct bpf_verifier_env *env, struc
 struct bpf_prog *__bpf_prog_select_runtime(struct bpf_verifier_env *env, struct bpf_prog *fp,
 					   int *err)
 {
+	struct bpf_prog *jit_prog;
+
 	/* In case of BPF to BPF calls, verifier did all the prep
 	 * work with regards to JITing, etc.
 	 */
@@ -2681,7 +2689,12 @@ struct bpf_prog *__bpf_prog_select_runtime(struct bpf_verifier_env *env, struct
 		if (*err)
 			return fp;
 
-		fp = bpf_prog_jit_compile(env, fp);
+		jit_prog = bpf_prog_jit_compile(env, fp);
+		if (IS_ERR(jit_prog)) {
+			*err = PTR_ERR(jit_prog);
+			return fp;
+		}
+		fp = jit_prog;
 		bpf_prog_jit_attempt_done(fp);
 		if (!fp->jited && jit_needed) {
 			*err = -ENOTSUPP;
diff --git a/kernel/bpf/fixups.c b/kernel/bpf/fixups.c
index 52d3cec336727..d6f83521fc78e 100644
--- a/kernel/bpf/fixups.c
+++ b/kernel/bpf/fixups.c
@@ -8,6 +8,7 @@
 #include <linux/bsearch.h>
 #include <linux/sort.h>
 #include <linux/perf_event.h>
+#include <linux/sched/signal.h>
 #include <net/xdp.h>
 #include "disasm.h"
 
@@ -306,12 +307,28 @@ static void adjust_poke_descs(struct bpf_prog *prog, u32 off, u32 len)
 	}
 }
 
+/*
+ * Some post-verification instruction rewriting passes require an
+ * O(prog->len) operation per instruction. Keep their shared primitives
+ * killable and preemptible.
+ */
+static bool bpf_rewrite_must_abort(void)
+{
+	if (fatal_signal_pending(current))
+		return true;
+	cond_resched();
+	return false;
+}
+
 struct bpf_prog *bpf_patch_insn_data(struct bpf_verifier_env *env, u32 off,
 				     const struct bpf_insn *patch, u32 len)
 {
 	struct bpf_prog *new_prog;
 	struct bpf_insn_aux_data *new_data = NULL;
 
+	if (bpf_rewrite_must_abort())
+		return NULL;
+
 	if (len > 1) {
 		new_data = vrealloc(env->insn_aux_data,
 				    array_size(env->prog->len + len - 1,
@@ -523,6 +540,9 @@ static int verifier_remove_insns(struct bpf_verifier_env *env, u32 off, u32 cnt)
 	unsigned int orig_prog_len = env->prog->len;
 	int err;
 
+	if (bpf_rewrite_must_abort())
+		return -EINTR;
+
 	if (bpf_prog_is_offloaded(env->prog->aux))
 		bpf_prog_offload_remove_insns(env, off, cnt);
 
@@ -1356,7 +1376,7 @@ int bpf_jit_subprogs(struct bpf_verifier_env *env)
 		}
 		prog = bpf_jit_blind_constants(env, prog);
 		if (IS_ERR(prog)) {
-			err = -ENOMEM;
+			err = PTR_ERR(prog);
 			prog = orig_prog;
 			goto out_restore;
 		}
@@ -1433,7 +1453,7 @@ int bpf_fixup_call_args(struct bpf_verifier_env *env)
 		err = bpf_jit_subprogs(env);
 		if (err == 0)
 			return 0;
-		if (err == -EFAULT)
+		if (err == -EFAULT || err == -EINTR)
 			return err;
 	}
 #ifndef CONFIG_BPF_JIT_ALWAYS_ON
diff --git a/kernel/bpf/states.c b/kernel/bpf/states.c
index 66fb11b6c6a76..e4ec007f7fa61 100644
--- a/kernel/bpf/states.c
+++ b/kernel/bpf/states.c
@@ -491,7 +491,8 @@ static bool regs_exact(const struct bpf_reg_state *rold,
 {
 	return memcmp(rold, rcur, offsetof(struct bpf_reg_state, id)) == 0 &&
 	       check_ids(rold->id, rcur->id, idmap) &&
-	       check_ids(rold->parent_id, rcur->parent_id, idmap);
+	       check_ids(rold->parent_id, rcur->parent_id, idmap) &&
+	       check_ids(rold->map_uid, rcur->map_uid, idmap);
 }
 
 enum exact_level {
@@ -616,7 +617,8 @@ static bool regsafe(struct bpf_verifier_env *env, struct bpf_reg_state *rold,
 		       range_within(rold, rcur) &&
 		       tnum_in(rold->var_off, rcur->var_off) &&
 		       check_ids(rold->id, rcur->id, idmap) &&
-		       check_ids(rold->parent_id, rcur->parent_id, idmap);
+		       check_ids(rold->parent_id, rcur->parent_id, idmap) &&
+		       check_ids(rold->map_uid, rcur->map_uid, idmap);
 	case PTR_TO_PACKET_META:
 	case PTR_TO_PACKET:
 		/* We must have at least as much range as the old ptr
@@ -635,6 +637,9 @@ static bool regsafe(struct bpf_verifier_env *env, struct bpf_reg_state *rold,
 		/* id relations must be preserved */
 		if (!check_ids(rold->id, rcur->id, idmap))
 			return false;
+		/* Preserve displacements between pointers sharing an ID. */
+		if (rold->id && rold->r64.base != rcur->r64.base)
+			return false;
 		/* new val must satisfy old val knowledge */
 		return range_within(rold, rcur) &&
 		       tnum_in(rold->var_off, rcur->var_off);
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index ddba53eaa3331..a39d13a6614d7 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -1864,6 +1864,7 @@ static void __mark_reg_known(struct bpf_reg_state *reg, u64 imm)
 	       offsetof(struct bpf_reg_state, var_off) - sizeof(reg->type));
 	reg->id = 0;
 	reg->parent_id = 0;
+	reg->map_uid = 0;
 	___mark_reg_known(reg, imm);
 }
 
@@ -1925,17 +1926,18 @@ static void refine_map_lookup_value(struct bpf_reg_state *reg)
 	if (map->inner_map_meta) {
 		reg->type = CONST_PTR_TO_MAP | maybe_null;
 		reg->map_ptr = map->inner_map_meta;
-		/* transfer reg's id which is unique for every map_lookup_elem
+		/*
+		 * transfer reg's id which is unique for every map_lookup_elem
 		 * as UID of the inner map.
 		 */
-		if (btf_record_has_field(map->inner_map_meta->record,
-					 BPF_TIMER | BPF_WORKQUEUE | BPF_TASK_WORK))
-			reg->map_uid = reg->id;
+		reg->map_uid = reg->id;
 	} else if (map->map_type == BPF_MAP_TYPE_XSKMAP) {
 		reg->type = PTR_TO_XDP_SOCK | maybe_null;
+		reg->map_uid = 0;
 	} else if (map->map_type == BPF_MAP_TYPE_SOCKMAP ||
 		   map->map_type == BPF_MAP_TYPE_SOCKHASH) {
 		reg->type = PTR_TO_SOCKET | maybe_null;
+		reg->map_uid = 0;
 	}
 }
 
@@ -10048,6 +10050,7 @@ int map_set_for_each_callback_args(struct bpf_verifier_env *env,
 	__mark_reg_known_zero(&callee->regs[BPF_REG_3]);
 	callee->regs[BPF_REG_3].map_ptr = caller->regs[BPF_REG_1].map_ptr;
 	callee->regs[BPF_REG_3].map_uid = caller->regs[BPF_REG_1].map_uid;
+	callee->regs[BPF_REG_3].id = ++env->id_gen;
 
 	/* pointer to stack or null */
 	callee->regs[BPF_REG_4] = caller->regs[BPF_REG_3];
@@ -10144,6 +10147,7 @@ static int set_timer_callback_state(struct bpf_verifier_env *env,
 	__mark_reg_known_zero(&callee->regs[BPF_REG_3]);
 	callee->regs[BPF_REG_3].map_ptr = map_ptr;
 	callee->regs[BPF_REG_3].map_uid = map_uid;
+	callee->regs[BPF_REG_3].id = ++env->id_gen;
 
 	/* unused */
 	bpf_mark_reg_not_init(env, &callee->regs[BPF_REG_4]);
@@ -10262,6 +10266,7 @@ static int set_task_work_schedule_callback_state(struct bpf_verifier_env *env,
 	__mark_reg_known_zero(&callee->regs[BPF_REG_3]);
 	callee->regs[BPF_REG_3].map_ptr = map_ptr;
 	callee->regs[BPF_REG_3].map_uid = map_uid;
+	callee->regs[BPF_REG_3].id = ++env->id_gen;
 
 	/* unused */
 	bpf_mark_reg_not_init(env, &callee->regs[BPF_REG_4]);
@@ -21271,6 +21276,11 @@ int bpf_check(struct bpf_prog **prog, union bpf_attr *attr, bpfptr_t uattr,
 	if (ret < 0)
 		goto skip_full_check;
 
+	/* Apply CO-RE before validating the program's instruction layout. */
+	ret = bpf_check_core_relo(env, attr, uattr);
+	if (ret < 0)
+		goto skip_full_check;
+
 	/* Discover all subprograms before validating their layout and BTF. */
 	ret = add_subprogs(env);
 	if (ret < 0)
@@ -21280,7 +21290,7 @@ int bpf_check(struct bpf_prog **prog, union bpf_attr *attr, bpfptr_t uattr,
 	if (ret < 0)
 		goto skip_full_check;
 
-	/* Validate BTF against the complete subprogram layout and apply CO-RE. */
+	/* Validate BTF against the complete subprogram layout. */
 	ret = bpf_check_btf_info(env, attr, uattr);
 	if (ret < 0)
 		goto skip_full_check;
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index b749c01742ee0..619e664f0c00f 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -6223,7 +6223,8 @@ bpf_object__relocate_core(struct bpf_object *obj, const char *targ_btf_path)
 				goto out;
 			}
 
-			err = bpf_core_patch_insn(prog->name, insn, insn_idx, rec, i, &targ_res);
+			err = bpf_core_patch_insn(prog->name, insn, prog->insns_cnt, insn_idx,
+						  rec, i, &targ_res);
 			if (err) {
 				pr_warn("prog '%s': relo #%d: failed to patch insn #%d: %s\n",
 					prog->name, i, insn_idx, errstr(err));
diff --git a/tools/lib/bpf/relo_core.c b/tools/lib/bpf/relo_core.c
index 8ad2715721cfd..92ff923f0d137 100644
--- a/tools/lib/bpf/relo_core.c
+++ b/tools/lib/bpf/relo_core.c
@@ -980,23 +980,30 @@ static int bpf_core_calc_relo(const char *prog_name,
 }
 
 /*
- * Turn instruction for which CO_RE relocation failed into invalid one with
+ * Turn instruction for which CO-RE relocation failed into invalid one with
  * distinct signature.
  */
-static void bpf_core_poison_insn(const char *prog_name, int relo_idx,
-				 int insn_idx, struct bpf_insn *insn)
+static int bpf_core_poison_insn(const char *prog_name, int relo_idx,
+				struct bpf_insn *insn, int insn_idx)
 {
-	pr_debug("prog '%s': relo #%d: substituting insn #%d w/ invalid insn\n",
-		 prog_name, relo_idx, insn_idx);
-	insn->code = BPF_JMP | BPF_CALL;
-	insn->dst_reg = 0;
-	insn->src_reg = 0;
-	insn->off = 0;
-	/* if this instruction is reachable (not a dead code),
-	 * verifier will complain with the following message:
-	 * invalid func unknown#195896080
-	 */
-	insn->imm = 195896080; /* => 0xbad2310 => "bad relo" */
+	int insn_cnt = is_ldimm64_insn(insn) ? 2 : 1;
+	int i;
+
+	for (i = 0; i < insn_cnt; i++) {
+		pr_debug("prog '%s': relo #%d: substituting insn #%d w/ invalid insn\n",
+			 prog_name, relo_idx, insn_idx + i);
+		insn[i].code = BPF_JMP | BPF_CALL;
+		insn[i].dst_reg = 0;
+		insn[i].src_reg = 0;
+		insn[i].off = 0;
+		/*
+		 * If this instruction is reachable (not dead code), the verifier
+		 * will complain with "invalid func unknown#195896080".
+		 */
+		insn[i].imm = 195896080; /* => 0xbad2310 => "bad relo" */
+	}
+
+	return 0;
 }
 
 static int insn_bpf_size_to_bytes(struct bpf_insn *insn)
@@ -1039,25 +1046,21 @@ static int insn_bytes_to_bpf_size(__u32 sz)
  * 6. *(T *)(rX + <off>) = <imm>, where T is one of {u8, u16, u32, u64}.
  */
 int bpf_core_patch_insn(const char *prog_name, struct bpf_insn *insn,
-			int insn_idx, const struct bpf_core_relo *relo,
-			int relo_idx, const struct bpf_core_relo_res *res)
+			size_t insn_cnt, int insn_idx,
+			const struct bpf_core_relo *relo, int relo_idx,
+			const struct bpf_core_relo_res *res)
 {
 	__u64 orig_val, new_val;
 	__u8 class;
 
-	class = BPF_CLASS(insn->code);
-
-	if (res->poison) {
-poison:
-		/* poison second part of ldimm64 to avoid confusing error from
-		 * verifier about "unknown opcode 00"
-		 */
-		if (is_ldimm64_insn(insn))
-			bpf_core_poison_insn(prog_name, relo_idx, insn_idx + 1, insn + 1);
-		bpf_core_poison_insn(prog_name, relo_idx, insn_idx, insn);
-		return 0;
+	if (is_ldimm64_insn(insn) && (size_t)insn_idx + 1 >= insn_cnt) {
+		pr_warn("prog '%s': relo #%d: insn #%d (LDIMM64) is truncated\n",
+			prog_name, relo_idx, insn_idx);
+		return -EINVAL;
 	}
 
+	class = BPF_CLASS(insn->code);
+
 	orig_val = res->orig_val;
 	new_val = res->new_val;
 
@@ -1065,7 +1068,9 @@ int bpf_core_patch_insn(const char *prog_name, struct bpf_insn *insn,
 	case BPF_ALU:
 	case BPF_ALU64:
 		if (BPF_SRC(insn->code) != BPF_K)
-			return -EINVAL;
+			goto bad_insn;
+		if (res->poison)
+			return bpf_core_poison_insn(prog_name, relo_idx, insn, insn_idx);
 		if (res->validate && insn->imm != orig_val) {
 			pr_warn("prog '%s': relo #%d: unexpected insn #%d (ALU/ALU64) value: got %d, exp %llu -> %llu\n",
 				prog_name, relo_idx,
@@ -1082,6 +1087,8 @@ int bpf_core_patch_insn(const char *prog_name, struct bpf_insn *insn,
 	case BPF_LDX:
 	case BPF_ST:
 	case BPF_STX:
+		if (res->poison)
+			return bpf_core_poison_insn(prog_name, relo_idx, insn, insn_idx);
 		if (res->validate && insn->off != orig_val) {
 			pr_warn("prog '%s': relo #%d: unexpected insn #%d (LDX/ST/STX) value: got %d, exp %llu -> %llu\n",
 				prog_name, relo_idx, insn_idx, insn->off, (unsigned long long)orig_val,
@@ -1097,7 +1104,7 @@ int bpf_core_patch_insn(const char *prog_name, struct bpf_insn *insn,
 			pr_warn("prog '%s': relo #%d: insn #%d (LDX/ST/STX) accesses field incorrectly. "
 				"Make sure you are accessing pointers, unsigned integers, or fields of matching type and size.\n",
 				prog_name, relo_idx, insn_idx);
-			goto poison;
+			return bpf_core_poison_insn(prog_name, relo_idx, insn, insn_idx);
 		}
 
 		orig_val = insn->off;
@@ -1140,6 +1147,9 @@ int bpf_core_patch_insn(const char *prog_name, struct bpf_insn *insn,
 			return -EINVAL;
 		}
 
+		if (res->poison)
+			return bpf_core_poison_insn(prog_name, relo_idx, insn, insn_idx);
+
 		imm = (__u32)insn[0].imm | ((__u64)insn[1].imm << 32);
 		if (res->validate && imm != orig_val) {
 			pr_warn("prog '%s': relo #%d: unexpected insn #%d (LDIMM64) value: got %llu, exp %llu -> %llu\n",
@@ -1157,6 +1167,7 @@ int bpf_core_patch_insn(const char *prog_name, struct bpf_insn *insn,
 		break;
 	}
 	default:
+bad_insn:
 		pr_warn("prog '%s': relo #%d: trying to relocate unrecognized insn #%d, code:0x%x, src:0x%x, dst:0x%x, off:0x%x, imm:0x%x\n",
 			prog_name, relo_idx, insn_idx, insn->code,
 			(unsigned)insn->src_reg, (unsigned)insn->dst_reg, (unsigned)insn->off, (unsigned)insn->imm);
diff --git a/tools/lib/bpf/relo_core.h b/tools/lib/bpf/relo_core.h
index 1c0566daf8e88..db2e106dc73db 100644
--- a/tools/lib/bpf/relo_core.h
+++ b/tools/lib/bpf/relo_core.h
@@ -87,8 +87,9 @@ int bpf_core_calc_relo_insn(const char *prog_name,
 			    struct bpf_core_relo_res *targ_res);
 
 int bpf_core_patch_insn(const char *prog_name, struct bpf_insn *insn,
-			int insn_idx, const struct bpf_core_relo *relo,
-			int relo_idx, const struct bpf_core_relo_res *res);
+			size_t insn_cnt, int insn_idx,
+			const struct bpf_core_relo *relo, int relo_idx,
+			const struct bpf_core_relo_res *res);
 
 int bpf_core_parse_spec(const char *prog_name, const struct btf *btf,
 		        const struct bpf_core_relo *relo,
diff --git a/tools/testing/selftests/bpf/prog_tests/cb_refs.c b/tools/testing/selftests/bpf/prog_tests/cb_refs.c
index 78566b817fd70..490e15e7126d9 100644
--- a/tools/testing/selftests/bpf/prog_tests/cb_refs.c
+++ b/tools/testing/selftests/bpf/prog_tests/cb_refs.c
@@ -13,7 +13,7 @@ struct {
 } cb_refs_tests[] = {
 	{ "underflow_prog", "release kfunc bpf_kfunc_call_test_release expects referenced PTR_TO_BTF_ID passed to R1" },
 	{ "leak_prog", "Possibly NULL pointer passed to helper R2" },
-	{ "nested_cb", "Unreleased reference id=4 alloc_insn=2" }, /* alloc_insn=2{4,5} */
+	{ "nested_cb", "Unreleased reference id=5 alloc_insn=2" }, /* alloc_insn=2{4,5} */
 	{ "non_cb_transfer_ref", "Unreleased reference id=4 alloc_insn=1" }, /* alloc_insn=1{1,2} */
 };
 
diff --git a/tools/testing/selftests/bpf/prog_tests/core_reloc_raw.c b/tools/testing/selftests/bpf/prog_tests/core_reloc_raw.c
index a18d3680fb169..90f1ea85354d0 100644
--- a/tools/testing/selftests/bpf/prog_tests/core_reloc_raw.c
+++ b/tools/testing/selftests/bpf/prog_tests/core_reloc_raw.c
@@ -14,6 +14,197 @@
 
 static char log[16 * 1024];
 
+static int load_core_relo_insns(int btf_fd, struct bpf_insn *insns, int insn_cnt,
+				struct bpf_func_info *funcs, int func_cnt,
+				int enum_id, int access_str_off, int insn_idx,
+				bool relocate)
+{
+	struct bpf_core_relo relo = {
+		.insn_off = insn_idx * sizeof(struct bpf_insn),
+		.type_id = enum_id,
+		.access_str_off = access_str_off,
+		.kind = BPF_CORE_ENUMVAL_VALUE,
+	};
+	union bpf_attr attr = {
+		.prog_type = BPF_PROG_TYPE_SOCKET_FILTER,
+		.insn_cnt = insn_cnt,
+		.insns = (__u64)insns,
+		.license = (__u64)"GPL",
+		.log_buf = (__u64)log,
+		.log_size = sizeof(log),
+		.log_level = 2,
+		.prog_btf_fd = btf_fd,
+		.func_info_rec_size = sizeof(struct bpf_func_info),
+		.func_info = (__u64)funcs,
+		.func_info_cnt = func_cnt,
+	};
+
+	if (relocate) {
+		attr.core_relo_cnt = 1;
+		attr.core_relos = (__u64)&relo;
+		attr.core_relo_rec_size = sizeof(relo);
+	}
+	memset(log, 0, sizeof(log));
+	return sys_bpf_prog_load(&attr, sizeof(attr), 1);
+}
+
+static void test_early_core_relo(void)
+{
+	static const char unrecognized[] = "trying to relocate unrecognized insn #2";
+	static const struct {
+		const char *name;
+		struct bpf_insn insns[2];
+		const char *err_msg;
+	} tests[] = {
+		{ "poison_exit", { BPF_EXIT_INSN() }, unrecognized },
+		{ "poison_ja", { BPF_JMP_A(1) }, unrecognized },
+		{ "poison_jmp", { BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 1) }, unrecognized },
+		{ "poison_jmp32", { BPF_JMP32_IMM(BPF_JEQ, BPF_REG_0, 0, 1) }, unrecognized },
+		{ "poison_call", { BPF_EMIT_CALL(BPF_FUNC_get_prandom_u32) }, unrecognized },
+		{ "poison_alu_reg", { BPF_MOV32_REG(BPF_REG_0, BPF_REG_1) }, unrecognized },
+		{ "poison_alu64_reg", { BPF_MOV64_REG(BPF_REG_0, BPF_REG_1) }, unrecognized },
+		{ "poison_ld_abs", { BPF_LD_ABS(BPF_W, 0) },
+		  "insn #2 (LDIMM64) has unexpected form" },
+		{ "poison_alu_imm", { BPF_MOV32_IMM(BPF_REG_0, 0) } },
+		{ "poison_alu64_imm", { BPF_MOV64_IMM(BPF_REG_0, 0) } },
+		{ "poison_ldx", { BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1, 0) } },
+		{ "poison_st", { BPF_ST_MEM(BPF_W, BPF_REG_10, -4, 0) } },
+		{ "poison_stx", { BPF_STX_MEM(BPF_W, BPF_REG_10, BPF_REG_0, -4) } },
+		{ "poison_ldimm64", { BPF_LD_IMM64(BPF_REG_0, 0) } },
+	};
+	struct bpf_insn core_only[] = {
+		BPF_MOV64_IMM(BPF_REG_0, 0),
+		BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 1),
+		BPF_MOV64_IMM(BPF_REG_0, 0),
+		BPF_EXIT_INSN(),
+	};
+	struct bpf_insn subprog[] = {
+		BPF_CALL_REL(2),
+		BPF_MOV64_IMM(BPF_REG_0, 0),
+		BPF_EXIT_INSN(),
+		BPF_MOV64_IMM(BPF_REG_0, 0),
+		BPF_EXIT_INSN(),
+	};
+	struct bpf_func_info funcs[2];
+	const void *raw_btf;
+	struct btf *btf;
+	__u32 raw_btf_size;
+	int access_str_off, btf_fd = -1, enum_id;
+	int int_id, main_id, prog_fd = -1, proto_id, sub_id, i;
+
+	btf = btf__new_empty();
+	if (!ASSERT_OK_PTR(btf, "btf_new_empty"))
+		return;
+	int_id = btf__add_int(btf, "int", 4, BTF_INT_SIGNED);
+	if (!ASSERT_GT(int_id, 0, "add_int"))
+		goto cleanup;
+	proto_id = btf__add_func_proto(btf, int_id);
+	if (!ASSERT_GT(proto_id, 0, "add_func_proto"))
+		goto cleanup;
+	main_id = btf__add_func(btf, "main_fn", BTF_FUNC_STATIC, proto_id);
+	if (!ASSERT_GT(main_id, 0, "add_main_func"))
+		goto cleanup;
+	sub_id = btf__add_func(btf, "sub_fn", BTF_FUNC_STATIC, proto_id);
+	if (!ASSERT_GT(sub_id, 0, "add_sub_func"))
+		goto cleanup;
+	enum_id = btf__add_enum(btf, "core_relo_poison_missing", 4);
+	if (!ASSERT_GT(enum_id, 0, "add_enum") ||
+	    !ASSERT_OK(btf__add_enum_value(btf, "value", 0), "add_enum_value"))
+		goto cleanup;
+	access_str_off = btf__add_str(btf, "0");
+	if (!ASSERT_GT(access_str_off, 0, "add_access_str"))
+		goto cleanup;
+
+	raw_btf = btf__raw_data(btf, &raw_btf_size);
+	if (!ASSERT_OK_PTR(raw_btf, "raw_btf"))
+		goto cleanup;
+	btf_fd = bpf_btf_load(raw_btf, raw_btf_size, NULL);
+	if (!ASSERT_GE(btf_fd, 0, "btf_load"))
+		goto cleanup;
+	funcs[0] = (struct bpf_func_info) { .insn_off = 0, .type_id = main_id };
+	funcs[1] = (struct bpf_func_info) { .insn_off = 3, .type_id = sub_id };
+
+	if (test__start_subtest("without_func_info")) {
+		prog_fd = load_core_relo_insns(btf_fd, core_only, ARRAY_SIZE(core_only), NULL, 0,
+					       enum_id, access_str_off, 2, false);
+		if (!ASSERT_GE(prog_fd, 0, "control_load"))
+			goto cleanup;
+		close(prog_fd);
+		prog_fd = load_core_relo_insns(btf_fd, core_only, ARRAY_SIZE(core_only), NULL, 0,
+					       enum_id, access_str_off, 2, true);
+		if (!ASSERT_GE(prog_fd, 0, "poisoned_load"))
+			goto cleanup;
+		ASSERT_HAS_SUBSTR(log, "substituting insn #2", "poison_log");
+		close(prog_fd);
+		prog_fd = -1;
+	}
+
+	if (test__start_subtest("poisoned_subprog_terminator")) {
+		prog_fd = load_core_relo_insns(btf_fd, subprog, ARRAY_SIZE(subprog), funcs, 2,
+					       enum_id, access_str_off, 2, false);
+		if (!ASSERT_GE(prog_fd, 0, "control_load"))
+			goto cleanup;
+		close(prog_fd);
+		prog_fd = load_core_relo_insns(btf_fd, subprog, ARRAY_SIZE(subprog), funcs, 2,
+					       enum_id, access_str_off, 2, true);
+		if (!ASSERT_LT(prog_fd, 0, "poisoned_load"))
+			goto cleanup;
+		ASSERT_HAS_SUBSTR(log, unrecognized, "poisoned_load_log");
+	}
+
+	for (i = 0; i < ARRAY_SIZE(tests); i++) {
+		struct bpf_insn insns[] = {
+			BPF_MOV64_IMM(BPF_REG_0, 0),
+			BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 2),
+			tests[i].insns[0],
+			BPF_MOV64_IMM(BPF_REG_0, 0),
+			BPF_MOV64_IMM(BPF_REG_0, 0),
+			BPF_EXIT_INSN(),
+		};
+		bool is_ldimm64 = insns[2].code == (BPF_LD | BPF_DW | BPF_IMM);
+		int insn_cnt = ARRAY_SIZE(insns);
+
+		if (!test__start_subtest(tests[i].name))
+			continue;
+		if (is_ldimm64) {
+			insns[3] = tests[i].insns[1];
+		} else {
+			insns[1].off = 1;
+			insns[4] = BPF_EXIT_INSN();
+			insn_cnt--;
+		}
+		prog_fd = load_core_relo_insns(btf_fd, insns, insn_cnt, funcs, 1,
+					       enum_id, access_str_off, 2, false);
+		if (!ASSERT_GE(prog_fd, 0, "control_load"))
+			goto cleanup;
+		close(prog_fd);
+		prog_fd = load_core_relo_insns(btf_fd, insns, insn_cnt, funcs, 1,
+					       enum_id, access_str_off, 2, true);
+		if (!tests[i].err_msg) {
+			ASSERT_GE(prog_fd, 0, "dead_poison_load");
+			ASSERT_HAS_SUBSTR(log, "substituting insn #2", "poison_log");
+			if (is_ldimm64)
+				ASSERT_HAS_SUBSTR(log, "substituting insn #3", "poison_ldimm64_log");
+		} else {
+			ASSERT_LT(prog_fd, 0, "invalid_poison_load");
+			ASSERT_HAS_SUBSTR(log, tests[i].err_msg, "invalid_poison_log");
+			ASSERT_NULL(strstr(log, "substituting insn"), "invalid_poison_substitution");
+		}
+		close(prog_fd);
+		prog_fd = -1;
+	}
+
+cleanup:
+	if (env.verbosity > VERBOSE_NORMAL && log[0]) {
+		printf("-------- program load log start --------\n");
+		printf("%s", log);
+		printf("-------- program load log end ----------\n");
+	}
+	close(prog_fd);
+	close(btf_fd);
+	btf__free(btf);
+}
+
 /* Check that verifier rejects BPF program containing relocation
  * pointing to non-existent BTF type.
  */
@@ -120,6 +311,7 @@ static void test_bad_local_id(void)
 
 void test_core_reloc_raw(void)
 {
+	test_early_core_relo();
 	if (test__start_subtest("bad_local_id"))
 		test_bad_local_id();
 }
diff --git a/tools/testing/selftests/bpf/prog_tests/core_reloc_truncated_ldimm64.c b/tools/testing/selftests/bpf/prog_tests/core_reloc_truncated_ldimm64.c
new file mode 100644
index 0000000000000..b70c8874241de
--- /dev/null
+++ b/tools/testing/selftests/bpf/prog_tests/core_reloc_truncated_ldimm64.c
@@ -0,0 +1,82 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (c) 2026 Meta Platforms, Inc. and affiliates. */
+
+#include <elf.h>
+#include <test_progs.h>
+
+#include "core_reloc_truncated_ldimm64.skel.h"
+
+static bool truncate_ldimm64_prog(void *elf_data, size_t elf_sz, const char *prog_name)
+{
+	Elf64_Ehdr *ehdr = elf_data;
+	Elf64_Shdr *shdrs;
+	Elf64_Sym *syms;
+	const char *strs;
+	size_t i, j;
+
+	if (elf_sz < sizeof(*ehdr) || ehdr->e_shoff > elf_sz ||
+	    ehdr->e_shnum > (elf_sz - ehdr->e_shoff) / sizeof(*shdrs))
+		return false;
+
+	shdrs = elf_data + ehdr->e_shoff;
+	for (i = 0; i < ehdr->e_shnum; i++) {
+		if (shdrs[i].sh_type != SHT_SYMTAB)
+			continue;
+		syms = elf_data + shdrs[i].sh_offset;
+		strs = elf_data + shdrs[shdrs[i].sh_link].sh_offset;
+		for (j = 0; j < shdrs[i].sh_size / sizeof(*syms); j++) {
+			if (ELF64_ST_TYPE(syms[j].st_info) == STT_FUNC &&
+			    !strcmp(strs + syms[j].st_name, prog_name)) {
+				syms[j].st_size = sizeof(struct bpf_insn);
+				return true;
+			}
+		}
+	}
+
+	return false;
+}
+
+static void run_test(const char *prog_name)
+{
+	const void *elf_bytes;
+	size_t elf_sz;
+	struct bpf_object *obj = NULL;
+	void *elf_data = NULL;
+	char *log = NULL;
+	int err;
+
+	elf_bytes = core_reloc_truncated_ldimm64__elf_bytes(&elf_sz);
+	if (!ASSERT_OK_PTR(elf_bytes, "elf_bytes"))
+		return;
+
+	elf_data = malloc(elf_sz);
+	if (!ASSERT_OK_PTR(elf_data, "elf_data"))
+		return;
+	memcpy(elf_data, elf_bytes, elf_sz);
+	if (!ASSERT_TRUE(truncate_ldimm64_prog(elf_data, elf_sz, prog_name), "truncate_prog"))
+		goto cleanup;
+
+	obj = bpf_object__open_mem(elf_data, elf_sz, NULL);
+	if (!ASSERT_OK_PTR(obj, "obj_open"))
+		goto cleanup;
+
+	if (start_libbpf_log_capture())
+		goto cleanup;
+	err = bpf_object__prepare(obj);
+	log = stop_libbpf_log_capture();
+	ASSERT_EQ(err, -EINVAL, "obj_prepare");
+	ASSERT_HAS_SUBSTR(log, "insn #0 (LDIMM64) is truncated", "libbpf_log");
+
+cleanup:
+	free(log);
+	bpf_object__close(obj);
+	free(elf_data);
+}
+
+void test_core_reloc_truncated_ldimm64(void)
+{
+	if (test__start_subtest("resolved"))
+		run_test("core_reloc_truncated_ldimm64_resolved");
+	if (test__start_subtest("poison"))
+		run_test("core_reloc_truncated_ldimm64_poison");
+}
diff --git a/tools/testing/selftests/bpf/prog_tests/spin_lock.c b/tools/testing/selftests/bpf/prog_tests/spin_lock.c
index 5c3579438427d..d49f52a8f8223 100644
--- a/tools/testing/selftests/bpf/prog_tests/spin_lock.c
+++ b/tools/testing/selftests/bpf/prog_tests/spin_lock.c
@@ -10,8 +10,8 @@ static char log_buf[1024 * 1024];
 
 static struct {
 	const char *prog_name;
-	const char *err_msg;
-} spin_lock_fail_tests[] = {
+	const char *err_msg; /* NULL if loading should succeed. */
+} spin_lock_tests[] = {
 	{ "lock_id_kptr_preserve",
 	  "[0-9]\\+: (bf) r1 = r0                       ; R0=ptr_foo(id=2)"
 	  " R1=ptr_foo(id=2) refs=2\n"
@@ -54,6 +54,22 @@ static struct {
 	{ "lock_global_sleepable_helper_subprog", "global function calls are not allowed while holding a lock" },
 	{ "lock_global_sleepable_kfunc_subprog", "global function calls are not allowed while holding a lock" },
 	{ "lock_global_sleepable_subprog_indirect", "global function calls are not allowed while holding a lock" },
+	{ "callback_value_lock_identity", "bpf_spin_unlock of different lock" },
+	{ "callback_inner_map_value_lock_identity", "bpf_spin_unlock of different lock" },
+	{ "callback_value_lock_identity_same", NULL },
+	{ "callback_single_value_lock_identity_same", NULL },
+	{ "lock_id_timer_preserve",
+	  "R1=map_value(id=[1-9][0-9]*,map=async_lock_map,[^\n]*\n"
+	  "[0-9]\\+: (85) call bpf_this_cpu_ptr#154\n"
+	  "R1 type=map_value expected=percpu_ptr_" },
+	{ "lock_id_wq_preserve",
+	  "R1=map_value(id=[1-9][0-9]*,map=async_lock_map,[^\n]*\n"
+	  "[0-9]\\+: (85) call bpf_this_cpu_ptr#154\n"
+	  "R1 type=map_value expected=percpu_ptr_" },
+	{ "lock_id_task_work_preserve",
+	  "R1=map_value(id=[1-9][0-9]*,map=async_lock_map,[^\n]*\n"
+	  "[0-9]\\+: (85) call bpf_this_cpu_ptr#154\n"
+	  "R1 type=map_value expected=percpu_ptr_" },
 };
 
 static int match_regex(const char *pattern, const char *string)
@@ -74,7 +90,7 @@ static int match_regex(const char *pattern, const char *string)
 	return rc == 0 ? 1 : 0;
 }
 
-static void test_spin_lock_fail_prog(const char *prog_name, const char *err_msg)
+static void test_spin_lock_prog(const char *prog_name, const char *err_msg)
 {
 	LIBBPF_OPTS(bpf_object_open_opts, opts, .kernel_log_buf = log_buf,
 						.kernel_log_size = sizeof(log_buf),
@@ -94,6 +110,10 @@ static void test_spin_lock_fail_prog(const char *prog_name, const char *err_msg)
 	bpf_program__set_autoload(prog, true);
 
 	ret = test_spin_lock_fail__load(skel);
+	if (!err_msg) {
+		ASSERT_OK(ret, "test_spin_lock_fail__load");
+		goto end;
+	}
 	if (!ASSERT_ERR(ret, "test_spin_lock_fail__load must fail"))
 		goto end;
 
@@ -166,10 +186,9 @@ void test_spin_lock(void)
 
 	test_spin_lock_success();
 
-	for (i = 0; i < ARRAY_SIZE(spin_lock_fail_tests); i++) {
-		if (!test__start_subtest(spin_lock_fail_tests[i].prog_name))
+	for (i = 0; i < ARRAY_SIZE(spin_lock_tests); i++) {
+		if (!test__start_subtest(spin_lock_tests[i].prog_name))
 			continue;
-		test_spin_lock_fail_prog(spin_lock_fail_tests[i].prog_name,
-					 spin_lock_fail_tests[i].err_msg);
+		test_spin_lock_prog(spin_lock_tests[i].prog_name, spin_lock_tests[i].err_msg);
 	}
 }
diff --git a/tools/testing/selftests/bpf/progs/core_reloc_truncated_ldimm64.c b/tools/testing/selftests/bpf/progs/core_reloc_truncated_ldimm64.c
new file mode 100644
index 0000000000000..d8d9a3650fe0d
--- /dev/null
+++ b/tools/testing/selftests/bpf/progs/core_reloc_truncated_ldimm64.c
@@ -0,0 +1,27 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (c) 2026 Meta Platforms, Inc. and affiliates. */
+
+#include "vmlinux.h"
+
+#include <bpf/bpf_helpers.h>
+#include <bpf/bpf_core_read.h>
+
+enum core_reloc_truncated_ldimm64 {
+	CORE_RELOC_TRUNCATED_LDIMM64_VALUE,
+};
+
+SEC("raw_tracepoint/sys_enter")
+int core_reloc_truncated_ldimm64_resolved(void *ctx)
+{
+	return bpf_core_enum_value_exists(enum core_reloc_truncated_ldimm64,
+					  CORE_RELOC_TRUNCATED_LDIMM64_VALUE);
+}
+
+SEC("raw_tracepoint/sys_exit")
+int core_reloc_truncated_ldimm64_poison(void *ctx)
+{
+	return bpf_core_enum_value(enum core_reloc_truncated_ldimm64,
+				   CORE_RELOC_TRUNCATED_LDIMM64_VALUE);
+}
+
+char LICENSE[] SEC("license") = "GPL";
diff --git a/tools/testing/selftests/bpf/progs/test_spin_lock_fail.c b/tools/testing/selftests/bpf/progs/test_spin_lock_fail.c
index f678ee6bd7eaf..a27bbbe3523fb 100644
--- a/tools/testing/selftests/bpf/progs/test_spin_lock_fail.c
+++ b/tools/testing/selftests/bpf/progs/test_spin_lock_fail.c
@@ -14,17 +14,18 @@ struct array_map {
 	__type(key, int);
 	__type(value, struct foo);
 	__uint(max_entries, 1);
-} array_map SEC(".maps");
+} array_map SEC(".maps"), array_map_b SEC(".maps");
 
 struct {
 	__uint(type, BPF_MAP_TYPE_ARRAY_OF_MAPS);
-	__uint(max_entries, 1);
+	__uint(max_entries, 2);
 	__type(key, int);
 	__type(value, int);
 	__array(values, struct array_map);
 } map_of_maps SEC(".maps") = {
 	.values = {
 		[0] = &array_map,
+		[1] = &array_map_b,
 	},
 };
 
@@ -314,4 +315,166 @@ int lock_global_sleepable_subprog_indirect(struct __sk_buff *ctx)
 	return ret;
 }
 
+struct {
+	__uint(type, BPF_MAP_TYPE_ARRAY);
+	__uint(max_entries, 2);
+	__type(key, int);
+	__type(value, struct foo);
+} callback_array_map SEC(".maps");
+
+struct callback_ctx {
+	struct foo *value;
+};
+
+static long lock_different_value(struct bpf_map *map, int *key,
+				 struct foo *value, struct callback_ctx *ctx)
+{
+	bpf_spin_lock(&value->lock);
+	bpf_spin_unlock(&ctx->value->lock);
+	return 0;
+}
+
+static long nest_lock_different_value(struct bpf_map *map, int *key,
+				      struct foo *value, void *data)
+{
+	struct callback_ctx ctx = { .value = value };
+
+	bpf_for_each_map_elem(&callback_array_map, lock_different_value, &ctx, 0);
+	return 0;
+}
+
+SEC("?tc")
+int callback_value_lock_identity(void *ctx)
+{
+	bpf_for_each_map_elem(&callback_array_map, nest_lock_different_value, NULL, 0);
+	return 0;
+}
+
+static long nest_lock_different_inner_value(struct bpf_map *map, int *key,
+					    struct foo *value, void *data)
+{
+	struct callback_ctx ctx = { .value = value };
+	int inner_key = 1;
+	void *inner_map;
+
+	inner_map = bpf_map_lookup_elem(&map_of_maps, &inner_key);
+	if (!inner_map)
+		return 0;
+	bpf_for_each_map_elem(inner_map, lock_different_value, &ctx, 0);
+	return 0;
+}
+
+SEC("?tc")
+int callback_inner_map_value_lock_identity(void *ctx)
+{
+	int inner_key = 0;
+	void *inner_map;
+
+	inner_map = bpf_map_lookup_elem(&map_of_maps, &inner_key);
+	if (!inner_map)
+		return 0;
+	bpf_for_each_map_elem(inner_map, nest_lock_different_inner_value, NULL, 0);
+	return 0;
+}
+
+static long lock_same_value(struct bpf_map *map, int *key,
+			    struct foo *value, void *data)
+{
+	bpf_spin_lock(&value->lock);
+	bpf_spin_unlock(&value->lock);
+	return 0;
+}
+
+static long nest_lock_same_value(struct bpf_map *map, int *key,
+				 struct foo *value, void *data)
+{
+	bpf_for_each_map_elem(&callback_array_map, lock_same_value, NULL, 0);
+	return 0;
+}
+
+SEC("?tc")
+int callback_value_lock_identity_same(void *ctx)
+{
+	bpf_for_each_map_elem(&callback_array_map, nest_lock_same_value, NULL, 0);
+	return 0;
+}
+
+SEC("?tc")
+int callback_single_value_lock_identity_same(void *ctx)
+{
+	bpf_for_each_map_elem(&array_map, lock_same_value, NULL, 0);
+	return 0;
+}
+
+struct async_lock_value {
+	struct bpf_spin_lock lock;
+	struct bpf_timer timer;
+	struct bpf_wq work;
+	struct bpf_task_work task_work;
+	int counter;
+};
+
+struct {
+	__uint(type, BPF_MAP_TYPE_ARRAY);
+	__uint(max_entries, 2);
+	__type(key, int);
+	__type(value, struct async_lock_value);
+} async_lock_map SEC(".maps");
+
+/*
+ * Expose the callback value ID in the verifier log, as in lock_id_mapval_preserve().
+ */
+static int async_lock_id_preserve(void *map, int *key, void *data)
+{
+	struct async_lock_value *value = data;
+
+	bpf_spin_lock(&value->lock);
+	value->counter++;
+	bpf_spin_unlock(&value->lock);
+	bpf_this_cpu_ptr(value);
+	return 0;
+}
+
+SEC("?tc")
+int lock_id_timer_preserve(void *ctx)
+{
+	struct async_lock_value *value;
+	int key = 0;
+
+	value = bpf_map_lookup_elem(&async_lock_map, &key);
+	if (value && !bpf_timer_init(&value->timer, &async_lock_map, 1))
+		bpf_timer_set_callback(&value->timer, async_lock_id_preserve);
+	return 0;
+}
+
+SEC("?tc")
+int lock_id_wq_preserve(void *ctx)
+{
+	struct async_lock_value *value;
+	int key = 0;
+
+	value = bpf_map_lookup_elem(&async_lock_map, &key);
+	if (value && !bpf_wq_init(&value->work, &async_lock_map, 0))
+		bpf_wq_set_callback(&value->work, async_lock_id_preserve, 0);
+	return 0;
+}
+
+static int task_work_lock_id_preserve(struct bpf_map *map, void *key, void *data)
+{
+	return async_lock_id_preserve(map, key, data);
+}
+
+SEC("?tc")
+int lock_id_task_work_preserve(void *ctx)
+{
+	struct async_lock_value *value;
+	int key = 0;
+
+	value = bpf_map_lookup_elem(&async_lock_map, &key);
+	if (value)
+		bpf_task_work_schedule_resume(bpf_get_current_task_btf(), &value->task_work,
+					      &async_lock_map, task_work_lock_id_preserve);
+	return 0;
+}
+
 char _license[] SEC("license") = "GPL";
diff --git a/tools/testing/selftests/bpf/progs/verifier_xdp_direct_packet_access.c b/tools/testing/selftests/bpf/progs/verifier_xdp_direct_packet_access.c
index 0b86d95a41335..9866bc154194a 100644
--- a/tools/testing/selftests/bpf/progs/verifier_xdp_direct_packet_access.c
+++ b/tools/testing/selftests/bpf/progs/verifier_xdp_direct_packet_access.c
@@ -1719,4 +1719,39 @@ l0_%=:	r0 = 0;						\
 	: __clobber_all);
 }
 
+SEC("xdp")
+__description("XDP pkt regsafe preserves packet pointer class displacement")
+__failure __msg("R2 min value is outside of the allowed memory range")
+__flag(BPF_F_ANY_ALIGNMENT) __flag(BPF_F_TEST_STATE_FREQ)
+__naked void pkt_regsafe_class_displacement(void)
+{
+	asm volatile ("					\
+	r8 = *(u32 *)(r1 + %[xdp_md_data_end]);		\
+	r9 = *(u32 *)(r1 + %[xdp_md_data]);		\
+	r4 = *(u32 *)(r1 + %[xdp_md_rx_queue_index]);	\
+	r4 &= 15;					\
+	r0 = *(u32 *)(r1 + %[xdp_md_ingress_ifindex]);	\
+	if r0 != 0 goto l0_%=;				\
+	r2 = r9;					\
+	r2 += r4;					\
+	r3 = r2;					\
+	r3 += 8;					\
+	goto l1_%=;					\
+l0_%=:	r4 &= 3;					\
+	r4 += 8;					\
+	r2 = r9;					\
+	r2 += r4;					\
+	r3 = r2;					\
+l1_%=:	if r3 > r8 goto l2_%=;				\
+	r0 = *(u64 *)(r2 + 0);				\
+l2_%=:	r0 = 0;						\
+	exit;						\
+"	:
+	: __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
+	  __imm_const(xdp_md_data_end, offsetof(struct xdp_md, data_end)),
+	  __imm_const(xdp_md_rx_queue_index, offsetof(struct xdp_md, rx_queue_index)),
+	  __imm_const(xdp_md_ingress_ifindex, offsetof(struct xdp_md, ingress_ifindex))
+	: __clobber_all);
+}
+
 char _license[] SEC("license") = "GPL";

3/2 2026/09/15 00:03 llm patch-evaluator
3m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 21143
							output: 49
							thoughts: 280
						

Thoughts:
**My Initial Assessment of the BPF Patch Series**

Okay, so they want me to dig into this patch series on the Linux kernel. The HEAD is at `4ce8c96f29bca22d19f9affe4d12f9f87256f289`, and it's all running on `amd64`. Right, so this is going to be a BPF-focused set of changes. A quick glance at the file list is enough to confirm that. We're talking `bpf.h`, the verifier, BTF, core functionality, fixups, states, and of course, verifier code, sprinkled with some tooling changes in `libbpf` and relevant selftests.

My immediate reaction is that this is potentially a fairly substantial patch set, given the breadth of the files touched. It looks like it could be a significant refactor, bug fix, or new feature introduction related to BPF core functionality or verification.

Before I go too far down the rabbit hole, I need to get a better handle on the *what* and the *why*. First thing's first, I need to examine the commit message and any accompanying documentation. I'll need to use `git log` to get a good description of the changes from the developers.



4/2 2026/09/15 00:06 tool grepper
0m Error:
no matches

Args:
{
  "Expression": "4ce8c96f29bca22d19f9affe4d12f9f87256f289"
}

Results:
{
  "error": "no matches"
}

5/2 2026/09/15 00:06 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 21767
							output: 32
							thoughts: 1711
						

Thoughts:
**Analyzing a BPF CO-RE Patch for Fuzzing Potential**

Okay, let's break this down. First, I need to get a handle on what this patch actually *does*. I don't have direct access to `git log` here, but the diff is provided, so I'll work with that. It looks like it's a BPF CO-RE (Compile Once, Run Everywhere) patch. Let's see...

From looking at the diff, it seems that the patch makes changes related to BPF core relocation handling and register state comparisons. `bpf_core_apply` now takes an instruction count (`insn_cnt`), suggesting more precise control during relocation application. I see `map_uid` being moved from a union in `bpf_reg_state` to be its own dedicated field. This has an impact on the register state comparisons and how they are handled. A new function, `bpf_check_core_relo`, is declared and used, and `bpf_rewrite_must_abort` is introduced to handle potential signal interruptions and scheduling. There is also extensive modification to how the verifier handles the register state, especially with respect to map lookups, ID generation, and CO-RE application order. CO-RE is now applied *before* subprogram checks. The tools code also contains modifications for `ldimm64` and instruction handling.

Given the scope of these changes, my expert intuition tells me this is significant. This touches the BPF verifier logic directly, especially how it handles register states, instruction patching, and CO-RE relocations.

My initial assessment is that these changes, particularly the verifier and JIT-related modifications, are definitely reachable code in standard virtualized environments. The `bpf()` syscall is the key. The BPF subsystem is a core part of the kernel, and these changes affect memory management, instruction handling, register state comparisons, CO-RE, and potentially JIT compilation, so `WorthFuzzing` is a definitive "true" on the scale.

Next, I need to zero in on specific configuration requirements and candidate FocusSymbols to guide fuzzing efforts. I should look into the Kconfig options related to BPF, BTF, CO-RE, and the verifier to determine what features need to be enabled for this code to be active. I'll need to scrutinize the file and function interactions, to determine which functions are relevant to focus upon.



6/2 2026/09/15 00:06 tool grepper
0m Args:
{
  "Expression": "config BPF_SYSCALL",
  "PathPrefix": "kernel/bpf/"
}

Results:
{
  "Output": "kernel/bpf/Kconfig=25=menu \"BPF subsystem\"\nkernel/bpf/Kconfig-26-\nkernel/bpf/Kconfig:27:config BPF_SYSCALL\nkernel/bpf/Kconfig-28-\tbool \"Enable bpf() system call\"\n"
}

7/2 2026/09/15 00:06 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 24110
							output: 32
							thoughts: 53
						

Thoughts:
Okay, let's dive into this. I need to understand how some crucial BPF components are built within the kernel. My initial thought is to navigate straight to the source of truth for BPF compilation: the `kernel/bpf/Makefile`. This is the place where I'll find the directives that govern the build process for `check_btf.c`, `btf.c`, `verifier.c`, `fixups.c`, `states.c`, and `core.c`. Knowing the build process for those is key to understanding how these are pulled together, so I can see what goes into the dependencies and the overall compilation process of the BPF toolchain. This should give me a solid handle on how these foundational BPF components interact during build time.



8/2 2026/09/15 00:06 tool read-file
0m Args:
{
  "File": "kernel/bpf/Makefile",
  "FirstLine": 1,
  "LineCount": 50
}

Results:
{
  "Contents": "   1:\t# SPDX-License-Identifier: GPL-2.0\n   2:\tobj-y := core.o\n   3:\tifneq ($(CONFIG_BPF_JIT_ALWAYS_ON),y)\n   4:\t# ___bpf_prog_run() needs GCSE disabled on x86; see 3193c0836f203 for details\n   5:\tcflags-nogcse-$(CONFIG_X86)$(CONFIG_CC_IS_GCC) := -fno-gcse\n   6:\tendif\n   7:\tCFLAGS_core.o += -Wno-override-init $(cflags-nogcse-yy)\n   8:\t\n   9:\tobj-$(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\n  10:\tobj-$(CONFIG_BPF_SYSCALL) += bpf_iter.o map_iter.o task_iter.o prog_iter.o link_iter.o\n  11:\tobj-$(CONFIG_BPF_SYSCALL) += hashtab.o arraymap.o percpu_freelist.o bpf_lru_list.o lpm_trie.o map_in_map.o bloom_filter.o\n  12:\tobj-$(CONFIG_BPF_SYSCALL) += local_storage.o queue_stack_maps.o ringbuf.o bpf_insn_array.o\n  13:\tobj-$(CONFIG_BPF_SYSCALL) += bpf_local_storage.o bpf_task_storage.o\n  14:\tobj-$(CONFIG_BPF_SYSCALL) += fixups.o cfg.o states.o backtrack.o check_btf.o\n  15:\tobj-${CONFIG_BPF_LSM}\t  += bpf_inode_storage.o\n  16:\tobj-$(CONFIG_BPF_SYSCALL) += disasm.o mprog.o\n  17:\tobj-$(CONFIG_BPF_JIT) += trampoline.o\n  18:\tobj-$(CONFIG_BPF_SYSCALL) += btf.o memalloc.o rqspinlock.o stream.o\n  19:\tifeq ($(CONFIG_MMU)$(CONFIG_64BIT),yy)\n  20:\tobj-$(CONFIG_BPF_SYSCALL) += arena.o range_tree.o\n  21:\tendif\n  22:\tobj-$(CONFIG_BPF_JIT) += dispatcher.o\n  23:\tifeq ($(CONFIG_NET),y)\n  24:\tobj-$(CONFIG_BPF_SYSCALL) += devmap.o\n  25:\tobj-$(CONFIG_BPF_SYSCALL) += cpumap.o\n  26:\tobj-$(CONFIG_BPF_SYSCALL) += offload.o\n  27:\tobj-$(CONFIG_BPF_SYSCALL) += net_namespace.o\n  28:\tobj-$(CONFIG_BPF_SYSCALL) += tcx.o\n  29:\tendif\n  30:\tifeq ($(CONFIG_PERF_EVENTS),y)\n  31:\tobj-$(CONFIG_BPF_SYSCALL) += stackmap.o\n  32:\tendif\n  33:\tifeq ($(CONFIG_CGROUPS),y)\n  34:\tobj-$(CONFIG_BPF_SYSCALL) += cgroup_iter.o bpf_cgrp_storage.o\n  35:\tendif\n  36:\tobj-$(CONFIG_CGROUP_BPF) += cgroup.o\n  37:\tifeq ($(CONFIG_INET),y)\n  38:\tobj-$(CONFIG_BPF_SYSCALL) += reuseport_array.o\n  39:\tendif\n  40:\tifeq ($(CONFIG_SYSFS),y)\n  41:\tobj-$(CONFIG_DEBUG_INFO_BTF) += sysfs_btf.o\n  42:\tendif\n  43:\tifeq ($(CONFIG_BPF_JIT),y)\n  44:\tobj-$(CONFIG_BPF_SYSCALL) += bpf_struct_ops.o\n  45:\tobj-$(CONFIG_BPF_SYSCALL) += cpumask.o\n  46:\t# bpf_lsm_proto.o must precede bpf_lsm.o. The current pahole logic\n  47:\t# deduplicates function prototypes within\n  48:\t# btf_encoder__add_saved_func() by keeping the first instance seen. We\n  49:\t# need the function prototype(s) in bpf_lsm_proto.o to take precedence\n  50:\t# over those within bpf_lsm.o. Having bpf_lsm_proto.o precede\n"
}

9/2 2026/09/15 00:06 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 25557
							output: 33
							thoughts: 95
						

Thoughts:
Here's my thinking process:

**Dependencies and the Big Picture**

Okay, so I'm looking at these object files – `verifier.o`, `btf.o`, `check_btf.o`, `fixups.o`, and `states.o` – and they're all clearly contingent on `CONFIG_BPF_SYSCALL`. That makes sense; the syscall interface is fundamental. `core.o` is marked as `obj-y`, so it's statically linked. My immediate question is, what about the JIT? I can't just assume everything related to BPF is controlled by just one option. The JIT is a performance-critical piece, and it probably has its own conditional build rules.

Let's check `bpf_jit_blind_constants` within `kernel/bpf/core.c` and see where that leads us. We need to understand the relationship between `CONFIG_BPF_JIT` and this particular constant-blinding feature.



10/2 2026/09/15 00:06 tool grepper
0m Args:
{
  "Expression": "bpf_jit_blind_constants",
  "PathPrefix": "kernel/bpf/"
}

Results:
{
  "Output": "kernel/bpf/core.c=1548=void bpf_jit_prog_release_other(struct bpf_prog *fp, struct bpf_prog *fp_other)\n--\nkernel/bpf/core.c-1562- */\nkernel/bpf/core.c:1563:struct bpf_prog *bpf_jit_blind_constants(struct bpf_verifier_env *env, struct bpf_prog *prog)\nkernel/bpf/core.c-1564-{\n--\nkernel/bpf/core.c=2631=static struct bpf_prog *bpf_prog_jit_compile(struct bpf_verifier_env *env, struct bpf_prog *prog)\n--\nkernel/bpf/core.c-2639-\torig_prog = prog;\nkernel/bpf/core.c:2640:\tprog = bpf_jit_blind_constants(env, prog);\nkernel/bpf/core.c-2641-\t/*\n--\nkernel/bpf/fixups.c=1359=int bpf_jit_subprogs(struct bpf_verifier_env *env)\n--\nkernel/bpf/fixups.c-1376-\t\t}\nkernel/bpf/fixups.c:1377:\t\tprog = bpf_jit_blind_constants(env, prog);\nkernel/bpf/fixups.c-1378-\t\tif (IS_ERR(prog)) {\n"
}

11/2 2026/09/15 00:06 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 26278
							output: 37
							thoughts: 60
						

Thoughts:
Here's my take on those lines of code...

**Digging into BPF JIT Compilation and Constant Handling**

Okay, so I'm diving into the BPF code again. Specifically, I'm focusing on the `bpf_prog_jit_compile` and `bpf_jit_blind_constants` functions. They're both nestled in `kernel/bpf/core.c`, so I'm heading there. Let's start around line 2630 – that's usually a good starting point for getting context on these specific functions. I need to get a clear picture of how BPF programs are actually compiled and how constants are handled during that compilation process. It's time to dig in and remind myself of those details.



12/2 2026/09/15 00:07 tool read-file
0m Args:
{
  "File": "kernel/bpf/core.c",
  "FirstLine": 2630,
  "LineCount": 50
}

Results:
{
  "Contents": "2630:\t\n2631:\tstatic struct bpf_prog *bpf_prog_jit_compile(struct bpf_verifier_env *env, struct bpf_prog *prog)\n2632:\t{\n2633:\t#ifdef CONFIG_BPF_JIT\n2634:\t\tstruct bpf_prog *orig_prog;\n2635:\t\n2636:\t\tif (!bpf_prog_need_blind(prog))\n2637:\t\t\treturn bpf_int_jit_compile(env, prog);\n2638:\t\n2639:\t\torig_prog = prog;\n2640:\t\tprog = bpf_jit_blind_constants(env, prog);\n2641:\t\t/*\n2642:\t\t * Fall back to the interpreter after blinding failures, except when\n2643:\t\t * the loader was killed.\n2644:\t\t */\n2645:\t\tif (IS_ERR(prog)) {\n2646:\t\t\tif (PTR_ERR(prog) == -EINTR)\n2647:\t\t\t\treturn prog;\n2648:\t\t\tgoto out_restore;\n2649:\t\t}\n2650:\t\n2651:\t\tprog = bpf_int_jit_compile(env, prog);\n2652:\t\tif (prog-\u003ejited) {\n2653:\t\t\tbpf_jit_prog_release_other(prog, orig_prog);\n2654:\t\t\treturn prog;\n2655:\t\t}\n2656:\t\n2657:\t\tbpf_jit_prog_release_other(orig_prog, prog);\n2658:\t\n2659:\tout_restore:\n2660:\t\tprog = orig_prog;\n2661:\t#endif\n2662:\t\treturn prog;\n2663:\t}\n2664:\t\n2665:\tstruct bpf_prog *__bpf_prog_select_runtime(struct bpf_verifier_env *env, struct bpf_prog *fp,\n2666:\t\t\t\t\t\t   int *err)\n2667:\t{\n2668:\t\tstruct bpf_prog *jit_prog;\n2669:\t\n2670:\t\t/* In case of BPF to BPF calls, verifier did all the prep\n2671:\t\t * work with regards to JITing, etc.\n2672:\t\t */\n2673:\t\tbool jit_needed = fp-\u003ejit_required;\n2674:\t\n2675:\t\tif (fp-\u003ebpf_func)\n2676:\t\t\tgoto finalize;\n2677:\t\n2678:\t\tif (!bpf_prog_select_interpreter(fp))\n2679:\t\t\tjit_needed = true;\n"
}

13/2 2026/09/15 00:07 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 27251
							output: 31
							thoughts: 111
						

Thoughts:
**My BPF Configuration Inquiry**

Okay, so I'm looking at this code and immediately my attention is drawn to line 2633 with the `#ifdef CONFIG_BPF_JIT`. That signals to me that `bpf_prog_jit_compile` and JIT blinding depend on `CONFIG_BPF_JIT`. That makes sense. But it gets me thinking about a larger picture – how does this relate to BTF and CO-RE? I need to quickly determine if there are dependencies or interactions.

My next step is clear: let's get a handle on `bpf_check_core_relo` and the associated BTF configurations. I need to understand how these pieces fit together. Then, I'll perform a quick search for `BPF_SYSCALL` and `DEBUG_INFO_BTF`, specifically within the `kernel/bpf/` directory, or in `init/Kconfig`. Those keywords should illuminate the configuration options I need to grasp to fully understand the JIT blinding context with regards to BTF and CO-RE.



14/2 2026/09/15 00:07 tool grepper
0m Args:
{
  "Expression": "config BPF_JIT",
  "PathPrefix": "kernel/bpf/"
}

Results:
{
  "Output": "kernel/bpf/Kconfig=27=config BPF_SYSCALL\n--\nkernel/bpf/Kconfig-41-\nkernel/bpf/Kconfig:42:config BPF_JIT\nkernel/bpf/Kconfig-43-\tbool \"Enable BPF Just In Time compiler\"\n--\nkernel/bpf/Kconfig-57-\nkernel/bpf/Kconfig:58:config BPF_JIT_ALWAYS_ON\nkernel/bpf/Kconfig-59-\tbool \"Permanently enable BPF JIT and remove BPF interpreter\"\n--\nkernel/bpf/Kconfig-68-\nkernel/bpf/Kconfig:69:config BPF_JIT_DEFAULT_ON\nkernel/bpf/Kconfig-70-\tdef_bool ARCH_WANT_DEFAULT_BPF_JIT || BPF_JIT_ALWAYS_ON\n"
}

15/2 2026/09/15 00:07 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 27847
							output: 31
							thoughts: 196
						

Thoughts:
**Investigating BTF Compilation and Dependencies**

Okay, so I need to clarify something about the BTF compilation process. My initial question is whether `DEBUG_INFO_BTF` is a hard requirement, or if the BTF information is automatically included in `btf.o` whenever `CONFIG_BPF_SYSCALL` is enabled. It makes sense to verify this as I am starting a project in this area.

Looking at the `kernel/bpf/Makefile`, it appears that `btf.o` is indeed built when `CONFIG_BPF_SYSCALL` is enabled. Excellent. Also, the `check_btf.o` file is also included when `CONFIG_BPF_SYSCALL` is enabled. That confirms the first part of the question.

However, I'm now wondering about the role of `DEBUG_INFO_BTF` in relation to `bpf_core_apply` and CO-RE. Does core relocation *require* `DEBUG_INFO_BTF`, or is it independent? I need to check the code related to those features and how they interact with BTF data to determine that.



16/2 2026/09/15 00:07 tool grepper
0m Args:
{
  "Expression": "bpf_core_apply",
  "PathPrefix": "kernel/bpf/"
}

Results:
{
  "Output": "kernel/bpf/btf.c=9644=bpf_core_find_cands(struct bpf_core_ctx *ctx, u32 local_type_id)\n--\nkernel/bpf/btf.c-9730-\nkernel/bpf/btf.c:9731:int bpf_core_apply(struct bpf_core_ctx *ctx, const struct bpf_core_relo *relo,\nkernel/bpf/btf.c-9732-\t\t   int relo_idx, void *insn, size_t insn_cnt)\n--\nkernel/bpf/check_btf.c=341=int bpf_check_core_relo(struct bpf_verifier_env *env,\n--\nkernel/bpf/check_btf.c-400-\nkernel/bpf/check_btf.c:401:\t\terr = bpf_core_apply(\u0026ctx, \u0026core_relo, i,\nkernel/bpf/check_btf.c-402-\t\t\t\t     \u0026prog-\u003einsnsi[core_relo.insn_off / 8], prog-\u003elen);\n"
}

17/2 2026/09/15 00:07 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 28616
							output: 39
							thoughts: 42
						

Thoughts:
Okay, let's dive into this `bpf_check_core_relo` function and figure out the origins of this target BTF. My immediate instinct is to crack open `check_btf.c`, and I'm guessing around line 340 might hold the key. Time to get my hands dirty and track down where this data is actually coming from within that code section. It's a key piece in this relocation process, so I need to understand it thoroughly.



18/2 2026/09/15 00:07 tool read-file
0m Args:
{
  "File": "kernel/bpf/check_btf.c",
  "FirstLine": 340,
  "LineCount": 60
}

Results:
{
  "Contents": " 340:\t\n 341:\tint bpf_check_core_relo(struct bpf_verifier_env *env,\n 342:\t\t\t\tconst union bpf_attr *attr,\n 343:\t\t\t\tbpfptr_t uattr)\n 344:\t{\n 345:\t\tu32 i, nr_core_relo, ncopy, expected_size, rec_size;\n 346:\t\tstruct bpf_core_relo core_relo = {};\n 347:\t\tstruct bpf_prog *prog = env-\u003eprog;\n 348:\t\tconst struct btf *btf = prog-\u003eaux-\u003ebtf;\n 349:\t\tstruct bpf_core_ctx ctx = {\n 350:\t\t\t.log = \u0026env-\u003elog,\n 351:\t\t\t.btf = btf,\n 352:\t\t};\n 353:\t\tbpfptr_t u_core_relo;\n 354:\t\tint err;\n 355:\t\n 356:\t\tnr_core_relo = attr-\u003ecore_relo_cnt;\n 357:\t\tif (!nr_core_relo)\n 358:\t\t\treturn 0;\n 359:\t\tif (nr_core_relo \u003e INT_MAX / sizeof(struct bpf_core_relo))\n 360:\t\t\treturn -EINVAL;\n 361:\t\n 362:\t\trec_size = attr-\u003ecore_relo_rec_size;\n 363:\t\tif (rec_size \u003c MIN_CORE_RELO_SIZE ||\n 364:\t\t    rec_size \u003e MAX_CORE_RELO_SIZE ||\n 365:\t\t    rec_size % sizeof(u32))\n 366:\t\t\treturn -EINVAL;\n 367:\t\n 368:\t\tu_core_relo = make_bpfptr(attr-\u003ecore_relos, uattr.is_kernel);\n 369:\t\texpected_size = sizeof(struct bpf_core_relo);\n 370:\t\tncopy = min_t(u32, expected_size, rec_size);\n 371:\t\n 372:\t\t/* Unlike func_info and line_info, copy and apply each CO-RE\n 373:\t\t * relocation record one at a time.\n 374:\t\t */\n 375:\t\tfor (i = 0; i \u003c nr_core_relo; i++) {\n 376:\t\t\t/* future proofing when sizeof(bpf_core_relo) changes */\n 377:\t\t\terr = bpf_check_uarg_tail_zero(u_core_relo, expected_size, rec_size);\n 378:\t\t\tif (err) {\n 379:\t\t\t\tif (err == -E2BIG) {\n 380:\t\t\t\t\tverbose(env, \"nonzero tailing record in core_relo\");\n 381:\t\t\t\t\tif (copy_to_bpfptr_offset(uattr,\n 382:\t\t\t\t\t\t\t\t  offsetof(union bpf_attr, core_relo_rec_size),\n 383:\t\t\t\t\t\t\t\t  \u0026expected_size, sizeof(expected_size)))\n 384:\t\t\t\t\t\terr = -EFAULT;\n 385:\t\t\t\t}\n 386:\t\t\t\tbreak;\n 387:\t\t\t}\n 388:\t\n 389:\t\t\tif (copy_from_bpfptr(\u0026core_relo, u_core_relo, ncopy)) {\n 390:\t\t\t\terr = -EFAULT;\n 391:\t\t\t\tbreak;\n 392:\t\t\t}\n 393:\t\n 394:\t\t\tif (core_relo.insn_off % 8 || core_relo.insn_off / 8 \u003e= prog-\u003elen) {\n 395:\t\t\t\tverbose(env, \"Invalid core_relo[%u].insn_off:%u prog-\u003elen:%u\\n\",\n 396:\t\t\t\t\ti, core_relo.insn_off, prog-\u003elen);\n 397:\t\t\t\terr = -EINVAL;\n 398:\t\t\t\tbreak;\n 399:\t\t\t}\n"
}

19/2 2026/09/15 00:07 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 29852
							output: 38
							thoughts: 69
						

Thoughts:
Here's my summary, as though I'm thinking through this process:

**Diving into BTF Candidate Search**

Okay, so I need to understand how the kernel's BTF (BPF Type Format) information is being handled in the search for potential candidates. Specifically, I'm going to focus on the `bpf_core_find_cands` function, located in `kernel/bpf/btf.c`. This is where the magic should be happening, presumably. Let's start by zeroing in around line 9644 in that file; I want to see if we're dealing with the `btf_vmlinux` global variable. That's the primary kernel BTF object, which should be pretty key to the whole process. I need to understand how it is being used to find these candidates. This is a crucial area to explore.



20/2 2026/09/15 00:07 tool read-file
0m Args:
{
  "File": "kernel/bpf/btf.c",
  "FirstLine": 9644,
  "LineCount": 40
}

Results:
{
  "Contents": "9644:\tbpf_core_find_cands(struct bpf_core_ctx *ctx, u32 local_type_id)\n9645:\t{\n9646:\t\tstruct bpf_cand_cache *cands, *cc, local_cand = {};\n9647:\t\tconst struct btf *local_btf = ctx-\u003ebtf;\n9648:\t\tconst struct btf_type *local_type;\n9649:\t\tconst struct btf *main_btf;\n9650:\t\tsize_t local_essent_len;\n9651:\t\tstruct btf *mod_btf;\n9652:\t\tconst char *name;\n9653:\t\tint id;\n9654:\t\n9655:\t\tmain_btf = bpf_get_btf_vmlinux();\n9656:\t\tif (IS_ERR(main_btf))\n9657:\t\t\treturn ERR_CAST(main_btf);\n9658:\t\tif (!main_btf)\n9659:\t\t\treturn ERR_PTR(-EINVAL);\n9660:\t\n9661:\t\tlocal_type = btf_type_by_id(local_btf, local_type_id);\n9662:\t\tif (!local_type)\n9663:\t\t\treturn ERR_PTR(-EINVAL);\n9664:\t\n9665:\t\tname = btf_name_by_offset(local_btf, local_type-\u003ename_off);\n9666:\t\tif (str_is_empty(name))\n9667:\t\t\treturn ERR_PTR(-EINVAL);\n9668:\t\tlocal_essent_len = bpf_core_essential_name_len(name);\n9669:\t\n9670:\t\tcands = \u0026local_cand;\n9671:\t\tcands-\u003ename = name;\n9672:\t\tcands-\u003ekind = btf_kind(local_type);\n9673:\t\tcands-\u003ename_len = local_essent_len;\n9674:\t\n9675:\t\tcc = check_cand_cache(cands, vmlinux_cand_cache, VMLINUX_CAND_CACHE_SIZE);\n9676:\t\t/* cands is a pointer to stack here */\n9677:\t\tif (cc) {\n9678:\t\t\tif (cc-\u003ecnt)\n9679:\t\t\t\treturn cc;\n9680:\t\t\tgoto check_modules;\n9681:\t\t}\n9682:\t\n9683:\t\t/* Attempt to find target candidates in vmlinux BTF first */\n"
}

21/2 2026/09/15 00:07 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 30824
							output: 36
							thoughts: 44
						

Thoughts:
Okay, here's my take on those thoughts, tailored for an expert audience:

**Investigating `bpf_get_btf_vmlinux()` Dependency**

Alright, that little `bpf_get_btf_vmlinux()` call just sparked an immediate thought process. My first question: where *exactly* is this function defined within the kernel sources? And, even more critically, which configuration options are involved? I need to quickly establish the preconditions for its availability. I need to figure out what config options I need enabled to use this! Let's get to work on determining that now.



22/2 2026/09/15 00:07 tool grepper
0m Args:
{
  "Expression": "bpf_get_btf_vmlinux",
  "PathPrefix": "kernel/bpf/"
}

Results:
{
  "Output": "kernel/bpf/bpf_struct_ops.c=1084=static struct bpf_map *bpf_struct_ops_map_alloc(union bpf_attr *attr)\n--\nkernel/bpf/bpf_struct_ops.c-1112-\t} else {\nkernel/bpf/bpf_struct_ops.c:1113:\t\tbtf = bpf_get_btf_vmlinux();\nkernel/bpf/bpf_struct_ops.c-1114-\t\tif (IS_ERR(btf))\n--\nkernel/bpf/btf.c=679=s32 bpf_find_btf_id(const char *name, u32 kind, struct btf **btf_p)\n--\nkernel/bpf/btf.c-684-\nkernel/bpf/btf.c:685:\tbtf = bpf_get_btf_vmlinux();\nkernel/bpf/btf.c-686-\tif (IS_ERR(btf))\n--\nkernel/bpf/btf.c=6495=static struct btf *btf_parse_module(const char *module_name, const void *data,\n--\nkernel/bpf/btf.c-6503-\nkernel/bpf/btf.c:6504:\tvmlinux_btf = bpf_get_btf_vmlinux();\nkernel/bpf/btf.c-6505-\tif (IS_ERR(vmlinux_btf))\n--\nkernel/bpf/btf.c=8016=int btf_prepare_func_args(struct bpf_verifier_env *env, int subprog)\n--\nkernel/bpf/btf.c-8179-\nkernel/bpf/btf.c:8180:\t\t\tvmlinux_btf = bpf_get_btf_vmlinux();\nkernel/bpf/btf.c-8181-\t\t\tref_t = btf_type_by_id(vmlinux_btf, kern_type_id);\n--\nkernel/bpf/btf.c=8682=struct btf *btf_get_module_btf(const struct module *module)\n--\nkernel/bpf/btf.c-8689-\tif (!module) {\nkernel/bpf/btf.c:8690:\t\tbtf = bpf_get_btf_vmlinux();\nkernel/bpf/btf.c-8691-\t\tif (!IS_ERR_OR_NULL(btf))\n--\nkernel/bpf/btf.c=8860=static int btf_check_kfunc_name(struct btf *btf, const char *func_name, u32 kind)\n--\nkernel/bpf/btf.c-8869-\nkernel/bpf/btf.c:8870:\tid = btf_find_by_name_kind(bpf_get_btf_vmlinux(), func_name, kind);\nkernel/bpf/btf.c-8871-\tif (id \u003e= 0) {\n--\nkernel/bpf/btf.c=9644=bpf_core_find_cands(struct bpf_core_ctx *ctx, u32 local_type_id)\n--\nkernel/bpf/btf.c-9654-\nkernel/bpf/btf.c:9655:\tmain_btf = bpf_get_btf_vmlinux();\nkernel/bpf/btf.c-9656-\tif (IS_ERR(main_btf))\n--\nkernel/bpf/inode.c=661=static int find_bpffs_btf_enums(struct bpffs_btf_enums *info)\n--\nkernel/bpf/inode.c-676-\nkernel/bpf/inode.c:677:\tbtf = bpf_get_btf_vmlinux();\nkernel/bpf/inode.c-678-\tif (IS_ERR(btf))\n--\nkernel/bpf/syscall.c=2917=static int bpf_prog_load(union bpf_attr *attr, bpfptr_t uattr, struct bpf_log_attr *attr_log)\n--\nkernel/bpf/syscall.c-3017-\t\t/* fall back to vmlinux BTF, if BTF type ID is specified */\nkernel/bpf/syscall.c:3018:\t\tattach_btf = bpf_get_btf_vmlinux();\nkernel/bpf/syscall.c-3019-\t\tif (IS_ERR(attach_btf)) {\n--\nkernel/bpf/verifier.c=19455=static int do_check_common(struct bpf_verifier_env *env, int subprog)\n--\nkernel/bpf/verifier.c-19549-\t\t\t\tmark_reg_known_zero(env, regs, i);\nkernel/bpf/verifier.c:19550:\t\t\t\treg-\u003ebtf = bpf_get_btf_vmlinux(); /* can't fail at this point */\nkernel/bpf/verifier.c-19551-\t\t\t\treg-\u003ebtf_id = arg-\u003ebtf_id;\n--\nkernel/bpf/verifier.c=20591=int bpf_check_attach_btf_id_multi(struct btf *btf, struct bpf_prog *prog, u32 btf_id,\n--\nkernel/bpf/verifier.c-20647-\nkernel/bpf/verifier.c:20648:struct btf *bpf_get_btf_vmlinux(void)\nkernel/bpf/verifier.c-20649-{\n--\nkernel/bpf/verifier.c=21163=int bpf_check(struct bpf_prog **prog, union bpf_attr *attr, bpfptr_t uattr,\n--\nkernel/bpf/verifier.c-21224-\nkernel/bpf/verifier.c:21225:\tbpf_get_btf_vmlinux();\nkernel/bpf/verifier.c-21226-\n"
}

23/2 2026/09/15 00:07 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 32605
							output: 38
							thoughts: 20
						

Thoughts:
Here's my attempt at summarizing the thought process, tailored for an expert audience:

**Diving into `bpf_get_btf_vmlinux`**

Okay, so I need to refresh my memory on `bpf_get_btf_vmlinux`. Let's clarify its purpose and function. My initial hunch is that it's likely responsible for fetching the BTF (BPF Type Format) information from the running kernel. But I can't just assume anything, especially when it comes to kernel-level details. This sounds like an API call. What's it doing with the vmlinux image? Is it loading information or requesting it, and what are the implications of each approach? My mind races with questions around how this function interfaces with the BPF subsystem, and if it interacts with things like kprobes or uprobes. What are the security considerations here? How does this work under the hood? And how does this function handle versioning and compatibility concerns? Let's get the official definition so I can get a better picture. I should also check its related functions, as it is likely not working alone. I'd like to understand what's in the box, before I start unwrapping it, so to speak.



24/2 2026/09/15 00:07 tool read-file
0m Args:
{
  "File": "kernel/bpf/verifier.c",
  "FirstLine": 20647,
  "LineCount": 30
}

Results:
{
  "Contents": "20647:\t\n20648:\tstruct btf *bpf_get_btf_vmlinux(void)\n20649:\t{\n20650:\t\t/* Pairs with the smp_store_release() on the parse path below. */\n20651:\t\tstruct btf *btf = smp_load_acquire(\u0026btf_vmlinux);\n20652:\t\n20653:\t\tif (!btf \u0026\u0026 IS_ENABLED(CONFIG_DEBUG_INFO_BTF)) {\n20654:\t\t\tmutex_lock(\u0026btf_vmlinux_lock);\n20655:\t\t\tbtf = btf_vmlinux;\n20656:\t\t\tif (!btf) {\n20657:\t\t\t\tbtf = btf_parse_vmlinux();\n20658:\t\t\t\t/*\n20659:\t\t\t\t * Order the parsed BTF contents and the globals the\n20660:\t\t\t\t * parse populated (e.g. bpf_ctx_convert.t) before\n20661:\t\t\t\t * the pointer publication. Pairs with the acquire\n20662:\t\t\t\t * on the lockless fast path above.\n20663:\t\t\t\t */\n20664:\t\t\t\tsmp_store_release(\u0026btf_vmlinux, btf);\n20665:\t\t\t}\n20666:\t\t\tmutex_unlock(\u0026btf_vmlinux_lock);\n20667:\t\t}\n20668:\t\treturn btf;\n20669:\t}\n20670:\t\n20671:\t/*\n20672:\t * The add_fd_from_fd_array() is executed only if fd_array_cnt is non-zero. In\n20673:\t * this case expect that every file descriptor in the array is either a map or\n20674:\t * a BTF. Everything else is considered to be trash.\n20675:\t */\n20676:\tstatic int add_fd_from_fd_array(struct bpf_verifier_env *env, u32 idx, int fd)\n"
}

25/2 2026/09/15 00:07 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 33472
							output: 21
							thoughts: 84
						

Thoughts:
Here's my thought process, distilled:

**Checking BTF Availability for Core BPF Functionality**

Okay, so I'm digging into how `bpf_core_find_cands` actually locates the vmlinux BTF candidates, and it's looking like `bpf_get_btf_vmlinux()` is the key function to examine. Right off the bat, I see that this function checks for `IS_ENABLED(CONFIG_DEBUG_INFO_BTF)`. Aha! That's the gatekeeper. It seems pretty obvious that *without* this configuration option enabled, `bpf_core_find_cands` won't be able to do its thing and find those BTF candidates in vmlinux. That makes sense, but let's just confirm that assumption, by checking what `CONFIG_DEBUG_INFO_BTF` actually *means*. Time to pop open the Kconfig file!



26/2 2026/09/15 00:07 tool grepper
0m Args:
{
  "Expression": "config DEBUG_INFO_BTF"
}

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=419=config PAHOLE_HAS_LANG_EXCLUDE\n--\nlib/Kconfig.debug-427-\nlib/Kconfig.debug:428:config DEBUG_INFO_BTF_MODULES\nlib/Kconfig.debug-429-\tbool \"Generate BTF type information for kernel modules\"\n"
}

27/2 2026/09/15 00:07 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 33946
							output: 34
							thoughts: 16
						

Thoughts:
Here's my summary, as though I were thinking through the problem:

**Delving into the Dependencies of DEBUG_INFO_BTF**

Okay, so I need to understand the dependencies of `DEBUG_INFO_BTF`. It's a critical component, and understanding its role within the larger system is paramount. I'm going to start by tracing its dependencies, looking at what other components rely on it, and what it itself relies on. I'll need to identify the build configurations, headers, and libraries that either provide support for BTF or depend upon it. This kind of analysis is pretty standard, but the specific implementation details here are what I'm interested in to get a complete picture. Once I know exactly what needs to be in place for `DEBUG_INFO_BTF` to function correctly, I can better understand its function and its impact on the system.



28/2 2026/09/15 00:07 tool read-file
0m Args:
{
  "File": "lib/Kconfig.debug",
  "FirstLine": 395,
  "LineCount": 30
}

Results:
{
  "Contents": " 395:\t\t  to know about the .dwo files and include them.\n 396:\t\t  Incompatible with older versions of ccache.\n 397:\t\n 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"
}

29/2 2026/09/15 00:07 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 34719
							output: 20
							thoughts: 178
						

Thoughts:
**My Initial Assessment of the BPF Configuration Landscape**

Okay, so I'm looking at `BPF_SYSCALL`, `BPF_JIT`, and `DEBUG_INFO_BTF`. My first thought is to ensure I haven't missed any relevant configurations. I need to make sure I have a complete picture. Regarding the JIT, is `BPF_JIT_ALWAYS_ON` actually needed? No, as long as `BPF_JIT` is enabled, that should be sufficient. Now, the next step is to examine the changes to symbols, to understand the scope of the updates. I see that `bpf_check_core_relo` in `kernel/bpf/check_btf.c` and `bpf_core_apply` in `kernel/bpf/btf.c` have been modified, and `bpf_core_patch_insn` in `kernel/bpf/relo_core.c` has also been altered. But hold on, I need to verify how `relo_core.c` is being compiled. It's important to track the build process and dependencies for a complete understanding.



30/2 2026/09/15 00:07 tool grepper
0m Args:
{
  "Expression": "relo_core\\.c"
}

Results:
{
  "Output": "kernel/bpf/relo_core.c-1-// SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)\nkernel/bpf/relo_core.c:2:#include \"../../tools/lib/bpf/relo_core.c\"\n"
}

31/2 2026/09/15 00:07 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 35248
							output: 29
							thoughts: 66
						

Thoughts:
**A Quick Deduction**

Right, so I see `kernel/bpf/relo_core.c` includes `../../tools/lib/bpf/relo_core.c`. This is interesting; usually I'd just expect the core functionality to be within the same directory. Now, the key question is how this particular file is compiled. To understand that, I need to check the build process. I'll need to dive into `kernel/bpf/Makefile` to see how everything fits together. Time to see what the build system is doing behind the scenes!



32/2 2026/09/15 00:07 tool grepper
0m Args:
{
  "Expression": "relo_core",
  "PathPrefix": "kernel/bpf/"
}

Results:
{
  "Output": "kernel/bpf/Makefile=61=obj-$(CONFIG_BPF_PRELOAD) += preload/\nkernel/bpf/Makefile-62-\nkernel/bpf/Makefile:63:obj-$(CONFIG_BPF_SYSCALL) += relo_core.o\nkernel/bpf/Makefile-64-obj-$(CONFIG_BPF_SYSCALL) += btf_iter.o\n--\nkernel/bpf/btf.c-36-#include \u003cnet/xdp.h\u003e\nkernel/bpf/btf.c:37:#include \"../tools/lib/bpf/relo_core.h\"\nkernel/bpf/btf.c-38-\n--\nkernel/bpf/relo_core.c-1-// SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)\nkernel/bpf/relo_core.c:2:#include \"../../tools/lib/bpf/relo_core.c\"\n"
}

33/2 2026/09/15 00:07 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 35709
							output: 27
							thoughts: 1232
						

Thoughts:
**My Analysis of BPF Core Relocation Changes**

Okay, so with `CONFIG_BPF_SYSCALL` enabled, `tools/lib/bpf/relo_core.c` is directly compiled into the kernel as `kernel/bpf/relo_core.o`. That means `bpf_core_patch_insn` is *in* the kernel now, which is a key point. Let's also keep an eye on `bpf_core_poison_insn`, even though it's static within `relo_core.c`.

Now, I'm going to systematically walk through the changed functions across the kernel, focusing on those directly touched by the relocation logic.

1.  `kernel/bpf/btf.c`: The signature of `bpf_core_apply` has changed, and it's called by `bpf_check_core_relo`.
2.  `tools/lib/bpf/relo_core.c`: Here's where it gets interesting, with `bpf_core_patch_insn` having a changed signature and modifications to the ldimm64 check and poison handling. Also, `bpf_core_poison_insn` is updated for 2-insn ldimm64.
3.  `kernel/bpf/check_btf.c`: `bpf_check_core_relo` is no longer static, and is now called from `bpf_check`. Both `bpf_prepare_btf_info` and `bpf_check_btf_info` have been modified, with the former now checking `!attr->core_relo_cnt`.
4.  `kernel/bpf/core.c`: Several functions are modified, including `bpf_jit_blind_constants`, `bpf_prog_jit_compile`, and `__bpf_prog_select_runtime`. They all seem to relate to the JIT compilation and error handling.
5.  `kernel/bpf/fixups.c`: New helper `bpf_rewrite_must_abort()` is introduced, used by `bpf_patch_insn_data` and `verifier_remove_insns`. `bpf_jit_subprogs` also preserves `PTR_ERR(prog)`, and `bpf_fixup_call_args` handles `-EINTR`.
6.  `kernel/bpf/states.c`: The code has added `rold->map_uid` and `rcur->map_uid` checks to `regs_exact` and `regsafe`, the latter of which additionally checks `rold->id && rold->r64.base != rcur->r64.base`.
7.  `kernel/bpf/verifier.c`: Many changes within, but the significant changes seem to be in the map ID handling. `__mark_reg_known` clears `reg->map_uid`, `refine_map_lookup_value` unconditionally sets the `reg->map_uid` for inner maps. `map_set_for_each_callback_args`, `set_timer_callback_state` and `set_task_work_schedule_callback_state` now allocate IDs, and crucially, `bpf_check` now calls `bpf_check_core_relo` earlier in the process, before `add_subprogs`.

I need to focus my fuzzing targets on the most specific changes, so I'll need to avoid the ubiquitous functions.

So, according to my review of the instructions, I need to focus on the non-static and exported functions that are specific to the modified logic, so I can ignore those ubiquitous lifecycle functions:
My target functions are:
*   `bpf_check_core_relo`
*   `bpf_core_apply`
*   `bpf_core_patch_insn`
*   `regsafe` (wait, is it static? Let me confirm... Okay, it's not. I'll include it.



34/2 2026/09/15 00:07 tool grepper
0m Args:
{
  "Expression": "regsafe",
  "PathPrefix": "kernel/bpf/"
}

Results:
{
  "Output": "kernel/bpf/backtrack.c=665=void bpf_mark_all_scalars_precise(struct bpf_verifier_env *env,\n--\nkernel/bpf/backtrack.c-735- * In the former case, precise markings in current state are completely\nkernel/bpf/backtrack.c:736: * ignored by state comparison code (see regsafe() for details). Only\nkernel/bpf/backtrack.c-737- * checkpointed (\"old\") state precise markings are important, and if old\nkernel/bpf/backtrack.c:738: * state's register/slot is precise, regsafe() assumes current state's\nkernel/bpf/backtrack.c-739- * register/slot as precise and checks value ranges exactly and precisely. If\n--\nkernel/bpf/states.c=498=enum exact_level {\n--\nkernel/bpf/states.c-504-/* Returns true if (rold safe implies rcur safe) */\nkernel/bpf/states.c:505:static bool regsafe(struct bpf_verifier_env *env, struct bpf_reg_state *rold,\nkernel/bpf/states.c-506-\t\t    struct bpf_reg_state *rcur, struct bpf_idmap *idmap,\n--\nkernel/bpf/states.c=704=static bool stacksafe(struct bpf_verifier_env *env, struct bpf_func_state *old,\n--\nkernel/bpf/states.c-751-\t\t * Construct a fake register for such stack and call\nkernel/bpf/states.c:752:\t\t * regsafe() to ensure scalar ids are compared.\nkernel/bpf/states.c-753-\t\t */\n--\nkernel/bpf/states.c-757-\t\t\tif (old_reg \u0026\u0026 cur_reg) {\nkernel/bpf/states.c:758:\t\t\t\tif (!regsafe(env, old_reg, cur_reg, idmap, exact))\nkernel/bpf/states.c-759-\t\t\t\t\treturn false;\n--\nkernel/bpf/states.c-794-\t\t\t */\nkernel/bpf/states.c:795:\t\t\tif (!regsafe(env, \u0026old-\u003estack[spi].spilled_ptr,\nkernel/bpf/states.c-796-\t\t\t\t     \u0026cur-\u003estack[spi].spilled_ptr, idmap, exact))\n--\nkernel/bpf/states.c=849=static bool stack_arg_safe(struct bpf_verifier_env *env, struct bpf_func_state *old,\n--\nkernel/bpf/states.c-863-\t\t\t  \u0026cur-\u003estack_arg_regs[i] : \u0026not_init;\nkernel/bpf/states.c:864:\t\tif (!regsafe(env, old_arg, cur_arg, idmap, exact))\nkernel/bpf/states.c-865-\t\t\treturn false;\n--\nkernel/bpf/states.c=947=static bool func_states_equal(struct bpf_verifier_env *env, struct bpf_func_state *old,\n--\nkernel/bpf/states.c-960-\t\tif (((1 \u003c\u003c i) \u0026 live_regs) \u0026\u0026\nkernel/bpf/states.c:961:\t\t    !regsafe(env, \u0026old-\u003eregs[i], \u0026cur-\u003eregs[i],\nkernel/bpf/states.c-962-\t\t\t     \u0026env-\u003eidmap_scratch, exact))\n"
}

35/2 2026/09/15 00:07 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 38731
							output: 30
							thoughts: 57
						

Thoughts:
Okay, let's see, my initial thought is about this `regsafe` function, and how it's defined. Right, it's static within `kernel/bpf/states.c`, which immediately raises a question in my mind: who's using this thing? And is it only internal to that file, or is it potentially exposed elsewhere?

I'm thinking I should really look at how the code uses `regsafe`. Specifically, I need to trace the calls, right? Things like `func_states_equal`, and `states_equal` - those seem like logical places to start poking around in `states.c`. I need to figure out what functions are calling `regsafe` and, ultimately, is `regsafe` exported, or is it deliberately private to that compilation unit? I need to understand its scope to really grasp its role in this system.



36/2 2026/09/15 00:07 tool grepper
0m Args:
{
  "Expression": "func_states_equal",
  "PathPrefix": "kernel/bpf/"
}

Results:
{
  "Output": "kernel/bpf/states.c=871=static bool refsafe(struct bpf_verifier_state *old, struct bpf_verifier_state *cur,\n--\nkernel/bpf/states.c-946- */\nkernel/bpf/states.c:947:static bool func_states_equal(struct bpf_verifier_env *env, struct bpf_func_state *old,\nkernel/bpf/states.c-948-\t\t\t      struct bpf_func_state *cur, u32 insn_idx, enum exact_level exact)\n--\nkernel/bpf/states.c=982=static bool states_equal(struct bpf_verifier_env *env,\n--\nkernel/bpf/states.c-1013-\t\t\treturn false;\nkernel/bpf/states.c:1014:\t\tif (!func_states_equal(env, old-\u003eframe[i], cur-\u003eframe[i], insn_idx, exact))\nkernel/bpf/states.c-1015-\t\t\treturn false;\n"
}

37/2 2026/09/15 00:07 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 39270
							output: 38
							thoughts: 15
						

Thoughts:
Here's a summary of my thought process, as requested:

**Deconstructing `states.c`**

Alright, let's dive into `states.c`. My primary focus is on identifying what *isn't* static. I'm operating on the assumption that a static element is, by definition, less interesting in the grand scheme of things, especially if I'm looking for dynamic behavior or points of interaction. My immediate goal is to understand the changing elements, the variables that influence behavior over time, and the structures that are accessed and modified from elsewhere in the system. I need to understand how this module interacts with the larger architecture and where its dependencies lie, and where its outputs are consumed. Static elements are largely defined at compile-time, so they are not what I need to focus on. So, anything that's static is, initially, less important than what isn't static.



38/2 2026/09/15 00:07 tool grepper
0m Args:
{
  "Expression": "^[a-zA-Z_].*\\(",
  "PathPrefix": "kernel/bpf/states.c"
}

Results:
{
  "Output": "kernel/bpf/states.c-11-\nkernel/bpf/states.c:12:static bool is_may_goto_insn_at(struct bpf_verifier_env *env, int insn_idx)\nkernel/bpf/states.c-13-{\n--\nkernel/bpf/states.c-16-\nkernel/bpf/states.c:17:static bool is_iter_next_insn(struct bpf_verifier_env *env, int insn_idx)\nkernel/bpf/states.c-18-{\n--\nkernel/bpf/states.c-21-\nkernel/bpf/states.c:22:static void update_peak_states(struct bpf_verifier_env *env)\nkernel/bpf/states.c-23-{\n--\nkernel/bpf/states.c-33- */\nkernel/bpf/states.c:34:static struct bpf_verifier_state_list *state_parent_as_list(struct bpf_verifier_state *st)\nkernel/bpf/states.c-35-{\n--\nkernel/bpf/states.c-40-\nkernel/bpf/states.c:41:static bool incomplete_read_marks(struct bpf_verifier_env *env,\nkernel/bpf/states.c-42-\t\t\t\t  struct bpf_verifier_state *st);\n--\nkernel/bpf/states.c-47- */\nkernel/bpf/states.c:48:static void maybe_free_verifier_state(struct bpf_verifier_env *env,\nkernel/bpf/states.c-49-\t\t\t\t      struct bpf_verifier_state_list *sl)\n--\nkernel/bpf/states.c-73- */\nkernel/bpf/states.c:74:static bool compute_scc_callchain(struct bpf_verifier_env *env,\nkernel/bpf/states.c-75-\t\t\t\t  struct bpf_verifier_state *st,\n--\nkernel/bpf/states.c-96-/* Check if bpf_scc_visit instance for @callchain exists. */\nkernel/bpf/states.c:97:static struct bpf_scc_visit *scc_visit_lookup(struct bpf_verifier_env *env,\nkernel/bpf/states.c-98-\t\t\t\t\t      struct bpf_scc_callchain *callchain)\n--\nkernel/bpf/states.c-115- */\nkernel/bpf/states.c:116:static struct bpf_scc_visit *scc_visit_alloc(struct bpf_verifier_env *env,\nkernel/bpf/states.c-117-\t\t\t\t\t     struct bpf_scc_callchain *callchain)\n--\nkernel/bpf/states.c-139-/* Form a string '(callsite#1,callsite#2,...,scc)' in env-\u003etmp_str_buf */\nkernel/bpf/states.c:140:static char *format_callchain(struct bpf_verifier_env *env, struct bpf_scc_callchain *callchain)\nkernel/bpf/states.c-141-{\n--\nkernel/bpf/states.c-159- */\nkernel/bpf/states.c:160:static int maybe_enter_scc(struct bpf_verifier_env *env, struct bpf_verifier_state *st)\nkernel/bpf/states.c-161-{\n--\nkernel/bpf/states.c-178-\nkernel/bpf/states.c:179:static int propagate_backedges(struct bpf_verifier_env *env, struct bpf_scc_visit *visit);\nkernel/bpf/states.c-180-\n--\nkernel/bpf/states.c-184- */\nkernel/bpf/states.c:185:static int maybe_exit_scc(struct bpf_verifier_env *env, struct bpf_verifier_state *st)\nkernel/bpf/states.c-186-{\n--\nkernel/bpf/states.c-226- */\nkernel/bpf/states.c:227:static int add_scc_backedge(struct bpf_verifier_env *env,\nkernel/bpf/states.c-228-\t\t\t    struct bpf_verifier_state *st,\n--\nkernel/bpf/states.c-258- */\nkernel/bpf/states.c:259:static bool incomplete_read_marks(struct bpf_verifier_env *env,\nkernel/bpf/states.c-260-\t\t\t\t  struct bpf_verifier_state *st)\n--\nkernel/bpf/states.c-272-\nkernel/bpf/states.c:273:int bpf_update_branch_counts(struct bpf_verifier_env *env, struct bpf_verifier_state *st)\nkernel/bpf/states.c-274-{\n--\nkernel/bpf/states.c-301-/* check %cur's range satisfies %old's */\nkernel/bpf/states.c:302:static bool range_within(const struct bpf_reg_state *old,\nkernel/bpf/states.c-303-\t\t\t const struct bpf_reg_state *cur)\n--\nkernel/bpf/states.c-318- */\nkernel/bpf/states.c:319:static bool check_ids(u32 old_id, u32 cur_id, struct bpf_idmap *idmap)\nkernel/bpf/states.c-320-{\n--\nkernel/bpf/states.c-379- */\nkernel/bpf/states.c:380:static bool check_scalar_ids(u32 old_id, u32 cur_id, struct bpf_idmap *idmap)\nkernel/bpf/states.c-381-{\n--\nkernel/bpf/states.c-397-\nkernel/bpf/states.c:398:static void __clean_func_state(struct bpf_verifier_env *env,\nkernel/bpf/states.c-399-\t\t\t       struct bpf_func_state *st,\n--\nkernel/bpf/states.c-470-\nkernel/bpf/states.c:471:static int clean_verifier_state(struct bpf_verifier_env *env,\nkernel/bpf/states.c-472-\t\t\t\t struct bpf_verifier_state *st)\n--\nkernel/bpf/states.c-487-\nkernel/bpf/states.c:488:static bool regs_exact(const struct bpf_reg_state *rold,\nkernel/bpf/states.c-489-\t\t       const struct bpf_reg_state *rcur,\n--\nkernel/bpf/states.c=498=enum exact_level {\n--\nkernel/bpf/states.c-504-/* Returns true if (rold safe implies rcur safe) */\nkernel/bpf/states.c:505:static bool regsafe(struct bpf_verifier_env *env, struct bpf_reg_state *rold,\nkernel/bpf/states.c-506-\t\t    struct bpf_reg_state *rcur, struct bpf_idmap *idmap,\n--\nkernel/bpf/states.c=661=static struct bpf_reg_state unbound_reg;\nkernel/bpf/states.c-662-\nkernel/bpf/states.c:663:static __init int unbound_reg_init(void)\nkernel/bpf/states.c-664-{\n--\nkernel/bpf/states.c-667-}\nkernel/bpf/states.c:668:late_initcall(unbound_reg_init);\nkernel/bpf/states.c-669-\nkernel/bpf/states.c:670:static bool is_spilled_scalar_after(const struct bpf_stack_state *stack, int im)\nkernel/bpf/states.c-671-{\n--\nkernel/bpf/states.c-675-\nkernel/bpf/states.c:676:static bool is_stack_misc_after(struct bpf_verifier_env *env,\nkernel/bpf/states.c-677-\t\t\t\tstruct bpf_stack_state *stack, int im)\n--\nkernel/bpf/states.c-691-\nkernel/bpf/states.c:692:static struct bpf_reg_state *scalar_reg_for_stack(struct bpf_verifier_env *env,\nkernel/bpf/states.c-693-\t\t\t\t\t\t  struct bpf_stack_state *stack, int im)\n--\nkernel/bpf/states.c-703-\nkernel/bpf/states.c:704:static bool stacksafe(struct bpf_verifier_env *env, struct bpf_func_state *old,\nkernel/bpf/states.c-705-\t\t      struct bpf_func_state *cur, struct bpf_idmap *idmap,\n--\nkernel/bpf/states.c-848- */\nkernel/bpf/states.c:849:static bool stack_arg_safe(struct bpf_verifier_env *env, struct bpf_func_state *old,\nkernel/bpf/states.c-850-\t\t\t   struct bpf_func_state *cur, struct bpf_idmap *idmap,\n--\nkernel/bpf/states.c-870-\nkernel/bpf/states.c:871:static bool refsafe(struct bpf_verifier_state *old, struct bpf_verifier_state *cur,\nkernel/bpf/states.c-872-\t\t    struct bpf_idmap *idmap)\n--\nkernel/bpf/states.c-946- */\nkernel/bpf/states.c:947:static bool func_states_equal(struct bpf_verifier_env *env, struct bpf_func_state *old,\nkernel/bpf/states.c-948-\t\t\t      struct bpf_func_state *cur, u32 insn_idx, enum exact_level exact)\n--\nkernel/bpf/states.c-973-\nkernel/bpf/states.c:974:static void reset_idmap_scratch(struct bpf_verifier_env *env)\nkernel/bpf/states.c-975-{\n--\nkernel/bpf/states.c-981-\nkernel/bpf/states.c:982:static bool states_equal(struct bpf_verifier_env *env,\nkernel/bpf/states.c-983-\t\t\t struct bpf_verifier_state *old,\n--\nkernel/bpf/states.c-1022- */\nkernel/bpf/states.c:1023:static int propagate_precision(struct bpf_verifier_env *env,\nkernel/bpf/states.c-1024-\t\t\t       const struct bpf_verifier_state *old,\n--\nkernel/bpf/states.c-1086- */\nkernel/bpf/states.c:1087:static int propagate_backedges(struct bpf_verifier_env *env, struct bpf_scc_visit *visit)\nkernel/bpf/states.c-1088-{\n--\nkernel/bpf/states.c-1115-\nkernel/bpf/states.c:1116:static bool states_maybe_looping(struct bpf_verifier_state *old,\nkernel/bpf/states.c-1117-\t\t\t\t struct bpf_verifier_state *cur)\n--\nkernel/bpf/states.c-1191- */\nkernel/bpf/states.c:1192:static bool iter_active_depths_differ(struct bpf_verifier_state *old, struct bpf_verifier_state *cur)\nkernel/bpf/states.c-1193-{\n--\nkernel/bpf/states.c-1215-\nkernel/bpf/states.c:1216:static void mark_all_scalars_imprecise(struct bpf_verifier_env *env, struct bpf_verifier_state *st)\nkernel/bpf/states.c-1217-{\n--\nkernel/bpf/states.c-1240-\nkernel/bpf/states.c:1241:int bpf_is_state_visited(struct bpf_verifier_env *env, int insn_idx)\nkernel/bpf/states.c-1242-{\n"
}

39/2 2026/09/15 00:07 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 42651
							output: 36
							thoughts: 1318
						

Thoughts:
**Analyzing Potential BPF Fuzzing Targets**

Okay, let's see, I need to figure out the best function to focus on for this fuzzing effort, considering the constraints. I see `bpf_is_state_visited`, and that leads me down a rabbit hole. Inside `states.c`, it calls `clean_verifier_state`, `states_equal`, which then calls `func_states_equal`, which itself then calls `regsafe`. I'm immediately interested in `regsafe` and how the compiler handles static functions. `regsafe` is pretty substantial, around 150 lines, so whether it's inlined or not is key. I need to know if it's got a distinct symbol address. Checking, it *is* static: `static bool regsafe(...)`. Wait, in GCC/Clang, static functions in `.c` files *do* get local symbols in vmlinux, unless inlined. That's good to know.

I should re-read Section 4 of the instructions very carefully. Ah, the note about avoiding ubiquitous functions, especially those in hot-paths. I'm looking for feature-specific logic and entrypoints. I see it specifically talks about "STATIC INLINE FUNCTIONS IN HEADERS (.h)", not `.c` files, so `regsafe` is a potential target. This is useful, but is there *better* choice?

I need to methodically check which function is the best. Let's look at the functions touched by the diff.
1.  `bpf_check_core_relo`: Defined in `kernel/bpf/check_btf.c`. Exported/non-static, sounds interesting, it is called by `bpf_check` so it is a direct entrypoint.
2.  `bpf_core_apply`: Defined in `kernel/bpf/btf.c`. Exported/non-static, declared in `include/linux/bpf.h`.
3.  `bpf_core_patch_insn`: Defined in `tools/lib/bpf/relo_core.c` (included in `kernel/bpf/relo_core.c`). It's non-static and core.
4.  `bpf_patch_insn_data`: Defined in `kernel/bpf/fixups.c`. Non-static and directly modified (added `bpf_rewrite_must_abort()`).
5.  `bpf_jit_blind_constants`: Defined in `kernel/bpf/core.c`. Non-static and directly modified (added fatal_signal check).
6.  `bpf_prog_jit_compile`: Static in `kernel/bpf/core.c`, called by `__bpf_prog_select_runtime`.
7.  `__bpf_prog_select_runtime`: Defined in `kernel/bpf/core.c`.
8.  `regsafe`: Defined in `kernel/bpf/states.c`. It is static so it is less attractive.
9.  `refine_map_lookup_value`: Static in `kernel/bpf/verifier.c`.
10. `map_set_for_each_callback_args`: Non-static in `kernel/bpf/verifier.c`.

Okay, I'm thinking I have some good options here: `bpf_check_core_relo`, `bpf_core_apply`, `bpf_core_patch_insn`, `bpf_patch_insn_data`, and `bpf_jit_blind_constants`. I'll consider these more closely.



40/2 2026/09/15 00:08 tool grepper
0m Args:
{
  "Expression": "map_set_for_each_callback_args",
  "PathPrefix": "kernel/bpf/"
}

Results:
{
  "Output": "kernel/bpf/arraymap.c=859=const struct bpf_map_ops array_map_ops = {\n--\nkernel/bpf/arraymap.c-877-\t.map_update_batch = generic_map_update_batch,\nkernel/bpf/arraymap.c:878:\t.map_set_for_each_callback_args = map_set_for_each_callback_args,\nkernel/bpf/arraymap.c-879-\t.map_for_each_callback = bpf_for_each_array_elem,\n--\nkernel/bpf/arraymap.c=886=const struct bpf_map_ops percpu_array_map_ops = {\n--\nkernel/bpf/arraymap.c-902-\t.map_update_batch = generic_map_update_batch,\nkernel/bpf/arraymap.c:903:\t.map_set_for_each_callback_args = map_set_for_each_callback_args,\nkernel/bpf/arraymap.c-904-\t.map_for_each_callback = bpf_for_each_array_elem,\n--\nkernel/bpf/hashtab.c=2379=const struct bpf_map_ops htab_map_ops = {\n--\nkernel/bpf/hashtab.c-2391-\t.map_seq_show_elem = htab_map_seq_show_elem,\nkernel/bpf/hashtab.c:2392:\t.map_set_for_each_callback_args = map_set_for_each_callback_args,\nkernel/bpf/hashtab.c-2393-\t.map_for_each_callback = bpf_for_each_hash_elem,\n--\nkernel/bpf/hashtab.c=2401=const struct bpf_map_ops htab_lru_map_ops = {\n--\nkernel/bpf/hashtab.c-2414-\t.map_seq_show_elem = htab_map_seq_show_elem,\nkernel/bpf/hashtab.c:2415:\t.map_set_for_each_callback_args = map_set_for_each_callback_args,\nkernel/bpf/hashtab.c-2416-\t.map_for_each_callback = bpf_for_each_hash_elem,\n--\nkernel/bpf/hashtab.c=2582=const struct bpf_map_ops htab_percpu_map_ops = {\n--\nkernel/bpf/hashtab.c-2594-\t.map_seq_show_elem = htab_percpu_map_seq_show_elem,\nkernel/bpf/hashtab.c:2595:\t.map_set_for_each_callback_args = map_set_for_each_callback_args,\nkernel/bpf/hashtab.c-2596-\t.map_for_each_callback = bpf_for_each_hash_elem,\n--\nkernel/bpf/hashtab.c=2604=const struct bpf_map_ops htab_lru_percpu_map_ops = {\n--\nkernel/bpf/hashtab.c-2615-\t.map_seq_show_elem = htab_percpu_map_seq_show_elem,\nkernel/bpf/hashtab.c:2616:\t.map_set_for_each_callback_args = map_set_for_each_callback_args,\nkernel/bpf/hashtab.c-2617-\t.map_for_each_callback = bpf_for_each_hash_elem,\n--\nkernel/bpf/hashtab.c=3526=const struct bpf_map_ops rhtab_map_ops = {\n--\nkernel/bpf/hashtab.c-3539-\t.map_seq_show_elem = rhtab_map_seq_show_elem,\nkernel/bpf/hashtab.c:3540:\t.map_set_for_each_callback_args = map_set_for_each_callback_args,\nkernel/bpf/hashtab.c-3541-\t.map_for_each_callback = bpf_each_rhash_elem,\n--\nkernel/bpf/verifier.c=9916=static int check_func_call(struct bpf_verifier_env *env, struct bpf_insn *insn,\n--\nkernel/bpf/verifier.c-10032-\nkernel/bpf/verifier.c:10033:int map_set_for_each_callback_args(struct bpf_verifier_env *env,\nkernel/bpf/verifier.c-10034-\t\t\t\t   struct bpf_func_state *caller,\n--\nkernel/bpf/verifier.c=10077=static int set_map_elem_callback_state(struct bpf_verifier_env *env,\n--\nkernel/bpf/verifier.c-10087-\tmap = insn_aux-\u003emap_ptr_state.map_ptr;\nkernel/bpf/verifier.c:10088:\tif (!map-\u003eops-\u003emap_set_for_each_callback_args ||\nkernel/bpf/verifier.c-10089-\t    !map-\u003eops-\u003emap_for_each_callback) {\n--\nkernel/bpf/verifier.c-10093-\nkernel/bpf/verifier.c:10094:\terr = map-\u003eops-\u003emap_set_for_each_callback_args(env, caller, callee);\nkernel/bpf/verifier.c-10095-\tif (err)\n"
}

41/2 2026/09/15 00:08 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 46230
							output: 33
							thoughts: 968
						

Thoughts:
**CO-RE and BPF Verifier Analysis**

Okay, so here's the lay of the land, as I understand it. I've pinpointed several key functions related to CO-RE (Compile Once, Run Everywhere) and the BPF verifier that are relevant to this review.

Specifically, I've identified:
*   `map_set_for_each_callback_args` (non-static, `kernel/bpf/verifier.c`) - Sets callback arguments for `map_for_each` calls, important due to the modification to the ID to prevent lock collisions.
*   `bpf_check_core_relo` (in `kernel/bpf/check_btf.c`) - The entry point for CO-RE relocation validation and application within the verifier.
*   `bpf_core_apply` (in `kernel/bpf/btf.c`) - Responsible for applying CO-RE relocations to the instructions.
*   `bpf_core_patch_insn` (in `kernel/bpf/relo_core.c` and via `tools/lib/bpf/relo_core.c`) - Patches instructions for CO-RE relocation and poisoning.
*   `bpf_jit_blind_constants` (in `kernel/bpf/core.c`) - The constant blinding JIT pass.
*   `bpf_patch_insn_data` (in `kernel/bpf/fixups.c`) - Instruction patching logic, including abortion checks.
*   `bpf_is_state_visited` (in `kernel/bpf/states.c`, and linked to `regsafe` and `regs_exact`) - State comparison and equivalence checking. This is the entry point for comparing BPF states, and is the core comparison logic. `do_check` in `kernel/bpf/verifier.c` calls `is_state_visited` which then calls `bpf_is_state_visited`.

Now, the crucial point is to identify the functions that are *specifically* implementing this new logic, versus those that are just generally called during BPF program execution. I'm focusing on those entrypoints that directly pertain to the changes. With this in mind, the key functions that directly implement the new logic are: `bpf_check_core_relo`, `bpf_core_apply`, `bpf_core_patch_insn`, `bpf_jit_blind_constants`, `bpf_patch_insn_data`, `map_set_for_each_callback_args` and `bpf_is_state_visited`

I've also checked the static/non-static status of a few functions: `verifier_remove_insns` is static; `bpf_jit_subprogs` is non-static (both in `kernel/bpf/fixups.c`).

From an overall perspective, `bpf_check`, the top-level verifier function, is too high-level because it is invoked on *every* BPF program load, it isn't specific to this change.

Finally, I've confirmed that the necessary configs are: `BPF_SYSCALL`, `BPF_JIT`, and `DEBUG_INFO_BTF`. I need to double-check `bpf_core_apply` and `bpf_check_core_relo` for any conditional compilation (`#ifdef`, `CONFIG_`). I'll search `kernel/bpf/check_btf.c` for any related configurations.



42/2 2026/09/15 00:08 tool grepper
0m Error:
no matches

Args:
{
  "Expression": "CONFIG_",
  "PathPrefix": "kernel/bpf/check_btf.c"
}

Results:
{
  "error": "no matches"
}

43/2 2026/09/15 00:08 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 48025
							output: 38
							thoughts: 77
						

Thoughts:
**Investigating BTF and Configuration Dependencies**

Okay, so I'm digging into BTF (BPF Type Format) code and I've hit a small snag. My initial observation is that `check_btf.c` seems to be completely devoid of any conditional compilation directives related to kernel configuration options (`#ifdef CONFIG_`). That's a bit unusual, and it's making me wonder about the broader picture.

I need to confirm if this lack of conditional compilation is consistent across the BTF codebase. So, the next logical place to look is `kernel/bpf/btf.c`. I need to understand how the core BTF application mechanisms are affected by configurations. Specifically, I'm concerned about whether `bpf_core_apply` is conditionally compiled. Let's focus on lines 9720 to 9810 within that file. I'll need to carefully examine that section for any `#ifdef` statements. It's crucial to understand which configurations could potentially enable or disable this core functionality, since this impacts the portability of tools and programs relying on BTF.



44/2 2026/09/15 00:08 tool read-file
0m Args:
{
  "File": "kernel/bpf/btf.c",
  "FirstLine": 9725,
  "LineCount": 40
}

Results:
{
  "Contents": "9725:\t\t * Copy it into the cache even when cands-\u003ecnt == 0 and\n9726:\t\t * return the result.\n9727:\t\t */\n9728:\t\treturn populate_cand_cache(cands, module_cand_cache, MODULE_CAND_CACHE_SIZE);\n9729:\t}\n9730:\t\n9731:\tint bpf_core_apply(struct bpf_core_ctx *ctx, const struct bpf_core_relo *relo,\n9732:\t\t\t   int relo_idx, void *insn, size_t insn_cnt)\n9733:\t{\n9734:\t\tbool need_cands = relo-\u003ekind != BPF_CORE_TYPE_ID_LOCAL;\n9735:\t\tstruct bpf_core_cand_list cands = {};\n9736:\t\tstruct bpf_core_relo_res targ_res;\n9737:\t\tstruct bpf_core_spec *specs;\n9738:\t\tconst struct btf_type *type;\n9739:\t\tint err;\n9740:\t\n9741:\t\t/* ~4k of temp memory necessary to convert LLVM spec like \"0:1:0:5\"\n9742:\t\t * into arrays of btf_ids of struct fields and array indices.\n9743:\t\t */\n9744:\t\tspecs = kzalloc_objs(*specs, 3, GFP_KERNEL_ACCOUNT);\n9745:\t\tif (!specs)\n9746:\t\t\treturn -ENOMEM;\n9747:\t\n9748:\t\ttype = btf_type_by_id(ctx-\u003ebtf, relo-\u003etype_id);\n9749:\t\tif (!type) {\n9750:\t\t\tbpf_log(ctx-\u003elog, \"relo #%u: bad type id %u\\n\",\n9751:\t\t\t\trelo_idx, relo-\u003etype_id);\n9752:\t\t\tkfree(specs);\n9753:\t\t\treturn -EINVAL;\n9754:\t\t}\n9755:\t\n9756:\t\tif (need_cands) {\n9757:\t\t\tstruct bpf_cand_cache *cc;\n9758:\t\t\tint i;\n9759:\t\n9760:\t\t\tmutex_lock(\u0026cand_cache_mutex);\n9761:\t\t\tcc = bpf_core_find_cands(ctx, relo-\u003etype_id);\n9762:\t\t\tif (IS_ERR(cc)) {\n9763:\t\t\t\tbpf_log(ctx-\u003elog, \"target candidate search failed for %d\\n\",\n9764:\t\t\t\t\trelo-\u003etype_id);\n"
}

45/2 2026/09/15 00:08 llm patch-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 49062
							output: 325
							thoughts: 889
						

Thoughts:
**My Assessment of the Patch's Impact and Testability**

Okay, let's break this down. First, `bpf_core_find_cands` relies on having kernel BTF available, which means `CONFIG_DEBUG_INFO_BTF` needs to be enabled. I know from experience that `BPF_SYSCALL` is essential for compiling several key files like `btf.c` and `verifier.c`, and we'll need `BPF_JIT` for the JIT compilation functions. I checked if we need anything else, like `DEBUG_INFO_BTF_MODULES`, and while that *could* be useful for module BTF candidates, we're really covered with the big three: `BPF_SYSCALL`, `BPF_JIT`, and `DEBUG_INFO_BTF`.

So, the patch itself is making some pretty significant changes. It's altering the CO-RE relocation order, calling `bpf_check_core_relo()` *before* validating subprogram layouts and ensuring the bounds checking is done in `bpf_core_patch_insn()`. It also introduces interruptibility checks, so we can propagate `-EINTR` through constant blinding and JIT compilation. Plus, it's restructuring `struct bpf_reg_state` for better map handling. These are changes deep in the heart of the eBPF verifier, instruction patching, and JIT compilation paths – all triggered directly from userspace via the `bpf()` syscall. That's a textbook case for thorough fuzzing, and syzkaller is absolutely the tool for the job.

I reviewed the "FocusSymbols" list carefully. These are all specific, non-ubiquitous symbols within the kernel. For example, `bpf_core_patch_insn`, is indeed a global symbol in `relo_core.c`.
Everything looks good to me, so I'm going to set these results.



46/2 2026/09/15 00:08 tool set-results
0m Args:
{
  "EnableConfigs": [
    "BPF_SYSCALL",
    "BPF_JIT",
    "DEBUG_INFO_BTF"
  ],
  "FocusSymbols": [
    "bpf_check_core_relo",
    "bpf_core_apply",
    "bpf_core_patch_insn",
    "bpf_patch_insn_data",
    "bpf_jit_blind_constants",
    "bpf_is_state_visited",
    "map_set_for_each_callback_args"
  ],
  "Reasoning": "The patch series modifies core BPF verifier, CO-RE relocation, instruction patching, and JIT compilation logic. Specifically, it shifts CO-RE relocation processing earlier in bpf_check() prior to subprogram discovery, adds bounds checking for truncated LDIMM64 instructions in bpf_core_patch_insn(), introduces fatal signal abort handling during instruction rewrites and constant blinding (bpf_patch_insn_data, verifier_remove_insns, bpf_jit_blind_constants), moves map_uid in bpf_reg_state to enforce ID comparison in regsafe() and regs_exact(), preserves register base displacements across shared IDs in regsafe(), and updates callback register state ID generation. These paths are fully reachable via the bpf(BPF_PROG_LOAD) system call and warrant fuzzing for verifier state pruning regressions, assertion failures, and memory safety issues.",
  "WorthFuzzing": true
}

Results:
{
  "EnableConfigs": [
    "BPF_SYSCALL",
    "BPF_JIT",
    "DEBUG_INFO_BTF"
  ],
  "FocusSymbols": [
    "bpf_check_core_relo",
    "bpf_core_apply",
    "bpf_core_patch_insn",
    "bpf_patch_insn_data",
    "bpf_jit_blind_constants",
    "bpf_is_state_visited",
    "map_set_for_each_callback_args"
  ],
  "Reasoning": "The patch series modifies core BPF verifier, CO-RE relocation, instruction patching, and JIT compilation logic. Specifically, it shifts CO-RE relocation processing earlier in bpf_check() prior to subprogram discovery, adds bounds checking for truncated LDIMM64 instructions in bpf_core_patch_insn(), introduces fatal signal abort handling during instruction rewrites and constant blinding (bpf_patch_insn_data, verifier_remove_insns, bpf_jit_blind_constants), moves map_uid in bpf_reg_state to enforce ID comparison in regsafe() and regs_exact(), preserves register base displacements across shared IDs in regsafe(), and updates callback register state ID generation. These paths are fully reachable via the bpf(BPF_PROG_LOAD) system call and warrant fuzzing for verifier state pruning regressions, assertion failures, and memory safety issues.",
  "WorthFuzzing": true
}

47/1 2026/09/15 00:08 action If
3m Args:
{
  "WorthFuzzing": true
}

Results:
null

48/2 2026/09/15 00:08 agent kmsan-evaluator
3m Model:
core

Args:
null

Results:
{
  "KMSANReasoning": "The patch series addresses several distinct issues within the BPF subsystem:\n1. Bounds checking in CO-RE relocation (`bpf_core_patch_insn`): Adds a bounds check to ensure `insn[1]` is within bounds before handling 64-bit immediate instructions (`LDIMM64`), preventing out-of-bounds memory accesses on truncated instructions. Any such OOB bug is detectable by KASAN.\n2. Packet pointer displacement check in `regsafe`: Restricts state pruning when packet pointers sharing an ID have different base displacements (`r64.base`). This fixes a verifier soundness flaw where out-of-bounds packet accesses could be accepted, which is an OOB issue caught by KASAN.\n3. Inner map UID tracking in `bpf_reg_state`: Moves `map_uid` out of the metadata union so it participates in ID mapping during state equivalence checks (`regs_exact` and `regsafe`), preventing incorrect lock identity matching. The register structures are fully zeroed upon allocation and in initialization helpers (`__mark_reg_known`, `bpf_mark_reg_unknown_imprecise`), leaving no uninitialized fields or padding.\n4. Signal interruption in JIT blinding and instruction rewrite passes: Adds fatal signal checks (`fatal_signal_pending`) and clean error returns (`-EINTR`) during post-verification fixups.\n5. CO-RE pass reordering: Invokes `bpf_check_core_relo` before discovering subprograms to ensure the subprogram layout matches the rewritten instructions.\n\nNone of these modifications introduce reads of uninitialized stack or heap memory, info-leaks to userspace, or branching on uninitialized data. Standard KASAN, LOCKDEP, and existing verifier assertions provide full coverage for the hazards touched by this patch series. Therefore, a dedicated KMSAN fuzzing session is not warranted.",
  "NeedsKMSAN": false
}

Instruction:
You are an expert Linux kernel security engineer specializing in kernel memory
error detectors (KASAN and KMSAN). Your job is to review the provided patch series and
determine if the code changes justify spawning a dedicated KMSAN (KernelMemorySanitizer)
fuzzing session in addition to standard KASAN fuzzing.

CRITICAL DISTINCTION BETWEEN KASAN AND KMSAN:
- Standard KASAN kernel builds (upstream-apparmor-kasan.config) already enable
  a comprehensive suite of debugging tools and sanitizers, including KASAN
  (out-of-bounds accesses, use-after-free, double free, invalid free), LOCKDEP
  (locking bugs and deadlocks), UB-sanitizers, and memory corruption checks.
- KMSAN (KernelMemorySanitizer) detects reads of UNINITIALIZED memory (stack, heap,
  or page allocations) and kernel-to-user memory info-leaks.

Rule: THERE IS NO SENSE IN RUNNING A KMSAN SESSION IF A BUG CAN BE CAUGHT BY KASAN,
LOCKDEP, OR OTHER STANDARD BUG DETECTORS.
A dedicated KMSAN fuzzing session incurs significant resource costs. You must ONLY
set NeedsKMSAN=true if the code changes introduce or expose UNINITIALIZED MEMORY risks
that are detected ONLY by KMSAN.

Look holistically at the patch series and surrounding code. Even if no direct
uninitialized field accesses or new buffer allocations are added in the diff itself,
a patch may alter control flow, bounds checking, or data length calculations in ways
that change how the rest of the code operates on existing buffers (e.g. allowing
uninitialized stack/heap memory to be read, copied to user space, or used in control
flow). Do not hesitate to use your code access tools to inspect the surrounding code,
called functions, and callers.

Set NeedsKMSAN=true ONLY IF the patch introduces or modifies:
1. Kernel structures sent to user space (via copy_to_user, put_user, netlink skb
   attributes, ioctl output arguments, socket options, or BPF buffers) where fields
   or structure padding might not be fully initialized/zeroed.
2. Conditional logic or branching that depends on potentially uninitialized variables
   or struct fields.
3. Allocation or initialization of complex data structures where uninitialized fields
   could be read later in reachable code paths.
4. Bounds checks, lengths, or logic in a way that allows surrounding code to access
   uninitialized bytes of existing buffers.

Set NeedsKMSAN=false IF:
- The code changes primarily risk out-of-bounds access, array overflows, NULL pointer
  dereferences, locking deadlocks, or use-after-free bugs (these are already caught
  by KASAN, LOCKDEP, or standard bug detectors).
- All stack/heap structures touched or introduced by the patch are fully zeroed
  or initialized (e.g. using = {0}, memset, kzalloc) before being read or copied.
- The patch does not introduce any risk of uninitialized memory usage or info-leaks.

Use your code access tools to inspect the surrounding code if necessary, then provide
detailed KMSANReasoning contrasting KASAN vs KMSAN applicability for this patch.
Prefer calling several tools at the same time to save round-trips.


Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.

Prompt:
Target architecture: amd64

For your convenience, here is the diff of the changes:
commit 4ce8c96f29bca22d19f9affe4d12f9f87256f289
Author: syz-cluster <triage@syzkaller.com>
Date:   Tue Sep 15 00:03:16 2026 +0000

    syz-cluster: applied patch under review

diff --git a/include/linux/bpf.h b/include/linux/bpf.h
index e57af902560c3..62155d87ce31b 100644
--- a/include/linux/bpf.h
+++ b/include/linux/bpf.h
@@ -3196,7 +3196,7 @@ bool btf_type_ids_nocast_alias(struct bpf_verifier_log *log,
 			       const struct btf *arg_btf, u32 arg_id);
 
 int bpf_core_apply(struct bpf_core_ctx *ctx, const struct bpf_core_relo *relo,
-		   int relo_idx, void *insn);
+		   int relo_idx, void *insn, size_t insn_cnt);
 
 static inline bool unprivileged_ebpf_enabled(void)
 {
diff --git a/include/linux/bpf_verifier.h b/include/linux/bpf_verifier.h
index 36b65797877d0..1aa245faa30e2 100644
--- a/include/linux/bpf_verifier.h
+++ b/include/linux/bpf_verifier.h
@@ -46,17 +46,10 @@ struct bpf_reg_state {
 		/* valid when type == PTR_TO_PACKET */
 		int range;
 
-		/* valid when type == CONST_PTR_TO_MAP | PTR_TO_MAP_VALUE |
-		 *   PTR_TO_MAP_VALUE_OR_NULL
+		/*
+		 * For CONST_PTR_TO_MAP, PTR_TO_MAP_KEY and PTR_TO_MAP_VALUE.
 		 */
-		struct {
-			struct bpf_map *map_ptr;
-			/* To distinguish map lookups from outer map
-			 * the map_uid is non-zero for registers
-			 * pointing to inner maps.
-			 */
-			u32 map_uid;
-		};
+		struct bpf_map *map_ptr;
 
 		/* for PTR_TO_BTF_ID */
 		struct {
@@ -155,13 +148,20 @@ struct bpf_reg_state {
 	 * gets parent_id set to the dynptr's id.
 	 */
 	u32 parent_id;
-	/* Inside the callee two registers can be both PTR_TO_STACK like
+	/*
+	 * Distinguishes inner-map lookups and their keys and values. Zero for
+	 * other registers. Kept outside the metadata union for ID remapping
+	 * during state comparisons.
+	 */
+	u32 map_uid;
+	/*
+	 * Inside the callee two registers can be both PTR_TO_STACK like
 	 * R1=fp-8 and R2=fp-8, but one of them points to this function stack
 	 * while another to the caller's stack. To differentiate them 'frameno'
 	 * is used which is an index in bpf_verifier_state->frame[] array
 	 * pointing to bpf_func_state.
 	 */
-	u32 frameno;
+	u8 frameno;
 	/* if (!precise && SCALAR_VALUE) min/max/tnum don't affect safety */
 	bool precise;
 };
@@ -1197,6 +1197,8 @@ static inline void bpf_trampoline_unpack_key(u64 key, u32 *obj_id, u32 *btf_id)
 
 int bpf_prepare_btf_info(struct bpf_verifier_env *env,
 			 const union bpf_attr *attr, bpfptr_t uattr);
+int bpf_check_core_relo(struct bpf_verifier_env *env,
+			const union bpf_attr *attr, bpfptr_t uattr);
 int bpf_check_btf_info(struct bpf_verifier_env *env,
 		       const union bpf_attr *attr, bpfptr_t uattr);
 
diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
index d67a169ba2bb3..78cd9661cdbd2 100644
--- a/kernel/bpf/btf.c
+++ b/kernel/bpf/btf.c
@@ -9729,7 +9729,7 @@ bpf_core_find_cands(struct bpf_core_ctx *ctx, u32 local_type_id)
 }
 
 int bpf_core_apply(struct bpf_core_ctx *ctx, const struct bpf_core_relo *relo,
-		   int relo_idx, void *insn)
+		   int relo_idx, void *insn, size_t insn_cnt)
 {
 	bool need_cands = relo->kind != BPF_CORE_TYPE_ID_LOCAL;
 	struct bpf_core_cand_list cands = {};
@@ -9793,8 +9793,8 @@ int bpf_core_apply(struct bpf_core_ctx *ctx, const struct bpf_core_relo *relo,
 	if (err)
 		goto out;
 
-	err = bpf_core_patch_insn((void *)ctx->log, insn, relo->insn_off / 8, relo, relo_idx,
-				  &targ_res);
+	err = bpf_core_patch_insn((void *)ctx->log, insn, insn_cnt, relo->insn_off / 8,
+				  relo, relo_idx, &targ_res);
 
 out:
 	kfree(specs);
diff --git a/kernel/bpf/check_btf.c b/kernel/bpf/check_btf.c
index 0e8b3ccc7a5b9..63d0375f5bb07 100644
--- a/kernel/bpf/check_btf.c
+++ b/kernel/bpf/check_btf.c
@@ -338,9 +338,9 @@ static int check_btf_line(struct bpf_verifier_env *env,
 #define MIN_CORE_RELO_SIZE	sizeof(struct bpf_core_relo)
 #define MAX_CORE_RELO_SIZE	MAX_FUNCINFO_REC_SIZE
 
-static int check_core_relo(struct bpf_verifier_env *env,
-			   const union bpf_attr *attr,
-			   bpfptr_t uattr)
+int bpf_check_core_relo(struct bpf_verifier_env *env,
+			const union bpf_attr *attr,
+			bpfptr_t uattr)
 {
 	u32 i, nr_core_relo, ncopy, expected_size, rec_size;
 	struct bpf_core_relo core_relo = {};
@@ -399,7 +399,7 @@ static int check_core_relo(struct bpf_verifier_env *env,
 		}
 
 		err = bpf_core_apply(&ctx, &core_relo, i,
-				     &prog->insnsi[core_relo.insn_off / 8]);
+				     &prog->insnsi[core_relo.insn_off / 8], prog->len);
 		if (err)
 			break;
 		bpfptr_add(&u_core_relo, rec_size);
@@ -414,7 +414,7 @@ int bpf_prepare_btf_info(struct bpf_verifier_env *env,
 	struct btf *btf;
 	int err;
 
-	if (!attr->func_info_cnt && !attr->line_info_cnt) {
+	if (!attr->func_info_cnt && !attr->line_info_cnt && !attr->core_relo_cnt) {
 		if (check_abnormal_return(env))
 			return -EINVAL;
 		return 0;
@@ -455,9 +455,5 @@ int bpf_check_btf_info(struct bpf_verifier_env *env,
 	if (err)
 		return err;
 
-	err = check_core_relo(env, attr, uattr);
-	if (err)
-		return err;
-
 	return 0;
 }
diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
index 8b294dfc1ad4d..2e3bf8113ae9b 100644
--- a/kernel/bpf/core.c
+++ b/kernel/bpf/core.c
@@ -19,6 +19,7 @@
 
 #include <uapi/linux/btf.h>
 #include <linux/filter.h>
+#include <linux/sched/signal.h>
 #include <linux/skbuff.h>
 #include <linux/static_call.h>
 #include <linux/vmalloc.h>
@@ -1619,6 +1620,8 @@ struct bpf_prog *bpf_jit_blind_constants(struct bpf_verifier_env *env, struct bp
 			 * fix it up here on error.
 			 */
 			bpf_jit_prog_release_other(prog, clone);
+			if (env && fatal_signal_pending(current))
+				return ERR_PTR(-EINTR);
 			return IS_ERR(tmp) ? tmp : ERR_PTR(-ENOMEM);
 		}
 
@@ -2636,11 +2639,14 @@ static struct bpf_prog *bpf_prog_jit_compile(struct bpf_verifier_env *env, struc
 	orig_prog = prog;
 	prog = bpf_jit_blind_constants(env, prog);
 	/*
-	 * If blinding was requested and we failed during blinding, we must fall
-	 * back to the interpreter.
+	 * Fall back to the interpreter after blinding failures, except when
+	 * the loader was killed.
 	 */
-	if (IS_ERR(prog))
+	if (IS_ERR(prog)) {
+		if (PTR_ERR(prog) == -EINTR)
+			return prog;
 		goto out_restore;
+	}
 
 	prog = bpf_int_jit_compile(env, prog);
 	if (prog->jited) {
@@ -2659,6 +2665,8 @@ static struct bpf_prog *bpf_prog_jit_compile(struct bpf_verifier_env *env, struc
 struct bpf_prog *__bpf_prog_select_runtime(struct bpf_verifier_env *env, struct bpf_prog *fp,
 					   int *err)
 {
+	struct bpf_prog *jit_prog;
+
 	/* In case of BPF to BPF calls, verifier did all the prep
 	 * work with regards to JITing, etc.
 	 */
@@ -2681,7 +2689,12 @@ struct bpf_prog *__bpf_prog_select_runtime(struct bpf_verifier_env *env, struct
 		if (*err)
 			return fp;
 
-		fp = bpf_prog_jit_compile(env, fp);
+		jit_prog = bpf_prog_jit_compile(env, fp);
+		if (IS_ERR(jit_prog)) {
+			*err = PTR_ERR(jit_prog);
+			return fp;
+		}
+		fp = jit_prog;
 		bpf_prog_jit_attempt_done(fp);
 		if (!fp->jited && jit_needed) {
 			*err = -ENOTSUPP;
diff --git a/kernel/bpf/fixups.c b/kernel/bpf/fixups.c
index 52d3cec336727..d6f83521fc78e 100644
--- a/kernel/bpf/fixups.c
+++ b/kernel/bpf/fixups.c
@@ -8,6 +8,7 @@
 #include <linux/bsearch.h>
 #include <linux/sort.h>
 #include <linux/perf_event.h>
+#include <linux/sched/signal.h>
 #include <net/xdp.h>
 #include "disasm.h"
 
@@ -306,12 +307,28 @@ static void adjust_poke_descs(struct bpf_prog *prog, u32 off, u32 len)
 	}
 }
 
+/*
+ * Some post-verification instruction rewriting passes require an
+ * O(prog->len) operation per instruction. Keep their shared primitives
+ * killable and preemptible.
+ */
+static bool bpf_rewrite_must_abort(void)
+{
+	if (fatal_signal_pending(current))
+		return true;
+	cond_resched();
+	return false;
+}
+
 struct bpf_prog *bpf_patch_insn_data(struct bpf_verifier_env *env, u32 off,
 				     const struct bpf_insn *patch, u32 len)
 {
 	struct bpf_prog *new_prog;
 	struct bpf_insn_aux_data *new_data = NULL;
 
+	if (bpf_rewrite_must_abort())
+		return NULL;
+
 	if (len > 1) {
 		new_data = vrealloc(env->insn_aux_data,
 				    array_size(env->prog->len + len - 1,
@@ -523,6 +540,9 @@ static int verifier_remove_insns(struct bpf_verifier_env *env, u32 off, u32 cnt)
 	unsigned int orig_prog_len = env->prog->len;
 	int err;
 
+	if (bpf_rewrite_must_abort())
+		return -EINTR;
+
 	if (bpf_prog_is_offloaded(env->prog->aux))
 		bpf_prog_offload_remove_insns(env, off, cnt);
 
@@ -1356,7 +1376,7 @@ int bpf_jit_subprogs(struct bpf_verifier_env *env)
 		}
 		prog = bpf_jit_blind_constants(env, prog);
 		if (IS_ERR(prog)) {
-			err = -ENOMEM;
+			err = PTR_ERR(prog);
 			prog = orig_prog;
 			goto out_restore;
 		}
@@ -1433,7 +1453,7 @@ int bpf_fixup_call_args(struct bpf_verifier_env *env)
 		err = bpf_jit_subprogs(env);
 		if (err == 0)
 			return 0;
-		if (err == -EFAULT)
+		if (err == -EFAULT || err == -EINTR)
 			return err;
 	}
 #ifndef CONFIG_BPF_JIT_ALWAYS_ON
diff --git a/kernel/bpf/states.c b/kernel/bpf/states.c
index 66fb11b6c6a76..e4ec007f7fa61 100644
--- a/kernel/bpf/states.c
+++ b/kernel/bpf/states.c
@@ -491,7 +491,8 @@ static bool regs_exact(const struct bpf_reg_state *rold,
 {
 	return memcmp(rold, rcur, offsetof(struct bpf_reg_state, id)) == 0 &&
 	       check_ids(rold->id, rcur->id, idmap) &&
-	       check_ids(rold->parent_id, rcur->parent_id, idmap);
+	       check_ids(rold->parent_id, rcur->parent_id, idmap) &&
+	       check_ids(rold->map_uid, rcur->map_uid, idmap);
 }
 
 enum exact_level {
@@ -616,7 +617,8 @@ static bool regsafe(struct bpf_verifier_env *env, struct bpf_reg_state *rold,
 		       range_within(rold, rcur) &&
 		       tnum_in(rold->var_off, rcur->var_off) &&
 		       check_ids(rold->id, rcur->id, idmap) &&
-		       check_ids(rold->parent_id, rcur->parent_id, idmap);
+		       check_ids(rold->parent_id, rcur->parent_id, idmap) &&
+		       check_ids(rold->map_uid, rcur->map_uid, idmap);
 	case PTR_TO_PACKET_META:
 	case PTR_TO_PACKET:
 		/* We must have at least as much range as the old ptr
@@ -635,6 +637,9 @@ static bool regsafe(struct bpf_verifier_env *env, struct bpf_reg_state *rold,
 		/* id relations must be preserved */
 		if (!check_ids(rold->id, rcur->id, idmap))
 			return false;
+		/* Preserve displacements between pointers sharing an ID. */
+		if (rold->id && rold->r64.base != rcur->r64.base)
+			return false;
 		/* new val must satisfy old val knowledge */
 		return range_within(rold, rcur) &&
 		       tnum_in(rold->var_off, rcur->var_off);
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index ddba53eaa3331..a39d13a6614d7 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -1864,6 +1864,7 @@ static void __mark_reg_known(struct bpf_reg_state *reg, u64 imm)
 	       offsetof(struct bpf_reg_state, var_off) - sizeof(reg->type));
 	reg->id = 0;
 	reg->parent_id = 0;
+	reg->map_uid = 0;
 	___mark_reg_known(reg, imm);
 }
 
@@ -1925,17 +1926,18 @@ static void refine_map_lookup_value(struct bpf_reg_state *reg)
 	if (map->inner_map_meta) {
 		reg->type = CONST_PTR_TO_MAP | maybe_null;
 		reg->map_ptr = map->inner_map_meta;
-		/* transfer reg's id which is unique for every map_lookup_elem
+		/*
+		 * transfer reg's id which is unique for every map_lookup_elem
 		 * as UID of the inner map.
 		 */
-		if (btf_record_has_field(map->inner_map_meta->record,
-					 BPF_TIMER | BPF_WORKQUEUE | BPF_TASK_WORK))
-			reg->map_uid = reg->id;
+		reg->map_uid = reg->id;
 	} else if (map->map_type == BPF_MAP_TYPE_XSKMAP) {
 		reg->type = PTR_TO_XDP_SOCK | maybe_null;
+		reg->map_uid = 0;
 	} else if (map->map_type == BPF_MAP_TYPE_SOCKMAP ||
 		   map->map_type == BPF_MAP_TYPE_SOCKHASH) {
 		reg->type = PTR_TO_SOCKET | maybe_null;
+		reg->map_uid = 0;
 	}
 }
 
@@ -10048,6 +10050,7 @@ int map_set_for_each_callback_args(struct bpf_verifier_env *env,
 	__mark_reg_known_zero(&callee->regs[BPF_REG_3]);
 	callee->regs[BPF_REG_3].map_ptr = caller->regs[BPF_REG_1].map_ptr;
 	callee->regs[BPF_REG_3].map_uid = caller->regs[BPF_REG_1].map_uid;
+	callee->regs[BPF_REG_3].id = ++env->id_gen;
 
 	/* pointer to stack or null */
 	callee->regs[BPF_REG_4] = caller->regs[BPF_REG_3];
@@ -10144,6 +10147,7 @@ static int set_timer_callback_state(struct bpf_verifier_env *env,
 	__mark_reg_known_zero(&callee->regs[BPF_REG_3]);
 	callee->regs[BPF_REG_3].map_ptr = map_ptr;
 	callee->regs[BPF_REG_3].map_uid = map_uid;
+	callee->regs[BPF_REG_3].id = ++env->id_gen;
 
 	/* unused */
 	bpf_mark_reg_not_init(env, &callee->regs[BPF_REG_4]);
@@ -10262,6 +10266,7 @@ static int set_task_work_schedule_callback_state(struct bpf_verifier_env *env,
 	__mark_reg_known_zero(&callee->regs[BPF_REG_3]);
 	callee->regs[BPF_REG_3].map_ptr = map_ptr;
 	callee->regs[BPF_REG_3].map_uid = map_uid;
+	callee->regs[BPF_REG_3].id = ++env->id_gen;
 
 	/* unused */
 	bpf_mark_reg_not_init(env, &callee->regs[BPF_REG_4]);
@@ -21271,6 +21276,11 @@ int bpf_check(struct bpf_prog **prog, union bpf_attr *attr, bpfptr_t uattr,
 	if (ret < 0)
 		goto skip_full_check;
 
+	/* Apply CO-RE before validating the program's instruction layout. */
+	ret = bpf_check_core_relo(env, attr, uattr);
+	if (ret < 0)
+		goto skip_full_check;
+
 	/* Discover all subprograms before validating their layout and BTF. */
 	ret = add_subprogs(env);
 	if (ret < 0)
@@ -21280,7 +21290,7 @@ int bpf_check(struct bpf_prog **prog, union bpf_attr *attr, bpfptr_t uattr,
 	if (ret < 0)
 		goto skip_full_check;
 
-	/* Validate BTF against the complete subprogram layout and apply CO-RE. */
+	/* Validate BTF against the complete subprogram layout. */
 	ret = bpf_check_btf_info(env, attr, uattr);
 	if (ret < 0)
 		goto skip_full_check;
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index b749c01742ee0..619e664f0c00f 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -6223,7 +6223,8 @@ bpf_object__relocate_core(struct bpf_object *obj, const char *targ_btf_path)
 				goto out;
 			}
 
-			err = bpf_core_patch_insn(prog->name, insn, insn_idx, rec, i, &targ_res);
+			err = bpf_core_patch_insn(prog->name, insn, prog->insns_cnt, insn_idx,
+						  rec, i, &targ_res);
 			if (err) {
 				pr_warn("prog '%s': relo #%d: failed to patch insn #%d: %s\n",
 					prog->name, i, insn_idx, errstr(err));
diff --git a/tools/lib/bpf/relo_core.c b/tools/lib/bpf/relo_core.c
index 8ad2715721cfd..92ff923f0d137 100644
--- a/tools/lib/bpf/relo_core.c
+++ b/tools/lib/bpf/relo_core.c
@@ -980,23 +980,30 @@ static int bpf_core_calc_relo(const char *prog_name,
 }
 
 /*
- * Turn instruction for which CO_RE relocation failed into invalid one with
+ * Turn instruction for which CO-RE relocation failed into invalid one with
  * distinct signature.
  */
-static void bpf_core_poison_insn(const char *prog_name, int relo_idx,
-				 int insn_idx, struct bpf_insn *insn)
+static int bpf_core_poison_insn(const char *prog_name, int relo_idx,
+				struct bpf_insn *insn, int insn_idx)
 {
-	pr_debug("prog '%s': relo #%d: substituting insn #%d w/ invalid insn\n",
-		 prog_name, relo_idx, insn_idx);
-	insn->code = BPF_JMP | BPF_CALL;
-	insn->dst_reg = 0;
-	insn->src_reg = 0;
-	insn->off = 0;
-	/* if this instruction is reachable (not a dead code),
-	 * verifier will complain with the following message:
-	 * invalid func unknown#195896080
-	 */
-	insn->imm = 195896080; /* => 0xbad2310 => "bad relo" */
+	int insn_cnt = is_ldimm64_insn(insn) ? 2 : 1;
+	int i;
+
+	for (i = 0; i < insn_cnt; i++) {
+		pr_debug("prog '%s': relo #%d: substituting insn #%d w/ invalid insn\n",
+			 prog_name, relo_idx, insn_idx + i);
+		insn[i].code = BPF_JMP | BPF_CALL;
+		insn[i].dst_reg = 0;
+		insn[i].src_reg = 0;
+		insn[i].off = 0;
+		/*
+		 * If this instruction is reachable (not dead code), the verifier
+		 * will complain with "invalid func unknown#195896080".
+		 */
+		insn[i].imm = 195896080; /* => 0xbad2310 => "bad relo" */
+	}
+
+	return 0;
 }
 
 static int insn_bpf_size_to_bytes(struct bpf_insn *insn)
@@ -1039,25 +1046,21 @@ static int insn_bytes_to_bpf_size(__u32 sz)
  * 6. *(T *)(rX + <off>) = <imm>, where T is one of {u8, u16, u32, u64}.
  */
 int bpf_core_patch_insn(const char *prog_name, struct bpf_insn *insn,
-			int insn_idx, const struct bpf_core_relo *relo,
-			int relo_idx, const struct bpf_core_relo_res *res)
+			size_t insn_cnt, int insn_idx,
+			const struct bpf_core_relo *relo, int relo_idx,
+			const struct bpf_core_relo_res *res)
 {
 	__u64 orig_val, new_val;
 	__u8 class;
 
-	class = BPF_CLASS(insn->code);
-
-	if (res->poison) {
-poison:
-		/* poison second part of ldimm64 to avoid confusing error from
-		 * verifier about "unknown opcode 00"
-		 */
-		if (is_ldimm64_insn(insn))
-			bpf_core_poison_insn(prog_name, relo_idx, insn_idx + 1, insn + 1);
-		bpf_core_poison_insn(prog_name, relo_idx, insn_idx, insn);
-		return 0;
+	if (is_ldimm64_insn(insn) && (size_t)insn_idx + 1 >= insn_cnt) {
+		pr_warn("prog '%s': relo #%d: insn #%d (LDIMM64) is truncated\n",
+			prog_name, relo_idx, insn_idx);
+		return -EINVAL;
 	}
 
+	class = BPF_CLASS(insn->code);
+
 	orig_val = res->orig_val;
 	new_val = res->new_val;
 
@@ -1065,7 +1068,9 @@ int bpf_core_patch_insn(const char *prog_name, struct bpf_insn *insn,
 	case BPF_ALU:
 	case BPF_ALU64:
 		if (BPF_SRC(insn->code) != BPF_K)
-			return -EINVAL;
+			goto bad_insn;
+		if (res->poison)
+			return bpf_core_poison_insn(prog_name, relo_idx, insn, insn_idx);
 		if (res->validate && insn->imm != orig_val) {
 			pr_warn("prog '%s': relo #%d: unexpected insn #%d (ALU/ALU64) value: got %d, exp %llu -> %llu\n",
 				prog_name, relo_idx,
@@ -1082,6 +1087,8 @@ int bpf_core_patch_insn(const char *prog_name, struct bpf_insn *insn,
 	case BPF_LDX:
 	case BPF_ST:
 	case BPF_STX:
+		if (res->poison)
+			return bpf_core_poison_insn(prog_name, relo_idx, insn, insn_idx);
 		if (res->validate && insn->off != orig_val) {
 			pr_warn("prog '%s': relo #%d: unexpected insn #%d (LDX/ST/STX) value: got %d, exp %llu -> %llu\n",
 				prog_name, relo_idx, insn_idx, insn->off, (unsigned long long)orig_val,
@@ -1097,7 +1104,7 @@ int bpf_core_patch_insn(const char *prog_name, struct bpf_insn *insn,
 			pr_warn("prog '%s': relo #%d: insn #%d (LDX/ST/STX) accesses field incorrectly. "
 				"Make sure you are accessing pointers, unsigned integers, or fields of matching type and size.\n",
 				prog_name, relo_idx, insn_idx);
-			goto poison;
+			return bpf_core_poison_insn(prog_name, relo_idx, insn, insn_idx);
 		}
 
 		orig_val = insn->off;
@@ -1140,6 +1147,9 @@ int bpf_core_patch_insn(const char *prog_name, struct bpf_insn *insn,
 			return -EINVAL;
 		}
 
+		if (res->poison)
+			return bpf_core_poison_insn(prog_name, relo_idx, insn, insn_idx);
+
 		imm = (__u32)insn[0].imm | ((__u64)insn[1].imm << 32);
 		if (res->validate && imm != orig_val) {
 			pr_warn("prog '%s': relo #%d: unexpected insn #%d (LDIMM64) value: got %llu, exp %llu -> %llu\n",
@@ -1157,6 +1167,7 @@ int bpf_core_patch_insn(const char *prog_name, struct bpf_insn *insn,
 		break;
 	}
 	default:
+bad_insn:
 		pr_warn("prog '%s': relo #%d: trying to relocate unrecognized insn #%d, code:0x%x, src:0x%x, dst:0x%x, off:0x%x, imm:0x%x\n",
 			prog_name, relo_idx, insn_idx, insn->code,
 			(unsigned)insn->src_reg, (unsigned)insn->dst_reg, (unsigned)insn->off, (unsigned)insn->imm);
diff --git a/tools/lib/bpf/relo_core.h b/tools/lib/bpf/relo_core.h
index 1c0566daf8e88..db2e106dc73db 100644
--- a/tools/lib/bpf/relo_core.h
+++ b/tools/lib/bpf/relo_core.h
@@ -87,8 +87,9 @@ int bpf_core_calc_relo_insn(const char *prog_name,
 			    struct bpf_core_relo_res *targ_res);
 
 int bpf_core_patch_insn(const char *prog_name, struct bpf_insn *insn,
-			int insn_idx, const struct bpf_core_relo *relo,
-			int relo_idx, const struct bpf_core_relo_res *res);
+			size_t insn_cnt, int insn_idx,
+			const struct bpf_core_relo *relo, int relo_idx,
+			const struct bpf_core_relo_res *res);
 
 int bpf_core_parse_spec(const char *prog_name, const struct btf *btf,
 		        const struct bpf_core_relo *relo,
diff --git a/tools/testing/selftests/bpf/prog_tests/cb_refs.c b/tools/testing/selftests/bpf/prog_tests/cb_refs.c
index 78566b817fd70..490e15e7126d9 100644
--- a/tools/testing/selftests/bpf/prog_tests/cb_refs.c
+++ b/tools/testing/selftests/bpf/prog_tests/cb_refs.c
@@ -13,7 +13,7 @@ struct {
 } cb_refs_tests[] = {
 	{ "underflow_prog", "release kfunc bpf_kfunc_call_test_release expects referenced PTR_TO_BTF_ID passed to R1" },
 	{ "leak_prog", "Possibly NULL pointer passed to helper R2" },
-	{ "nested_cb", "Unreleased reference id=4 alloc_insn=2" }, /* alloc_insn=2{4,5} */
+	{ "nested_cb", "Unreleased reference id=5 alloc_insn=2" }, /* alloc_insn=2{4,5} */
 	{ "non_cb_transfer_ref", "Unreleased reference id=4 alloc_insn=1" }, /* alloc_insn=1{1,2} */
 };
 
diff --git a/tools/testing/selftests/bpf/prog_tests/core_reloc_raw.c b/tools/testing/selftests/bpf/prog_tests/core_reloc_raw.c
index a18d3680fb169..90f1ea85354d0 100644
--- a/tools/testing/selftests/bpf/prog_tests/core_reloc_raw.c
+++ b/tools/testing/selftests/bpf/prog_tests/core_reloc_raw.c
@@ -14,6 +14,197 @@
 
 static char log[16 * 1024];
 
+static int load_core_relo_insns(int btf_fd, struct bpf_insn *insns, int insn_cnt,
+				struct bpf_func_info *funcs, int func_cnt,
+				int enum_id, int access_str_off, int insn_idx,
+				bool relocate)
+{
+	struct bpf_core_relo relo = {
+		.insn_off = insn_idx * sizeof(struct bpf_insn),
+		.type_id = enum_id,
+		.access_str_off = access_str_off,
+		.kind = BPF_CORE_ENUMVAL_VALUE,
+	};
+	union bpf_attr attr = {
+		.prog_type = BPF_PROG_TYPE_SOCKET_FILTER,
+		.insn_cnt = insn_cnt,
+		.insns = (__u64)insns,
+		.license = (__u64)"GPL",
+		.log_buf = (__u64)log,
+		.log_size = sizeof(log),
+		.log_level = 2,
+		.prog_btf_fd = btf_fd,
+		.func_info_rec_size = sizeof(struct bpf_func_info),
+		.func_info = (__u64)funcs,
+		.func_info_cnt = func_cnt,
+	};
+
+	if (relocate) {
+		attr.core_relo_cnt = 1;
+		attr.core_relos = (__u64)&relo;
+		attr.core_relo_rec_size = sizeof(relo);
+	}
+	memset(log, 0, sizeof(log));
+	return sys_bpf_prog_load(&attr, sizeof(attr), 1);
+}
+
+static void test_early_core_relo(void)
+{
+	static const char unrecognized[] = "trying to relocate unrecognized insn #2";
+	static const struct {
+		const char *name;
+		struct bpf_insn insns[2];
+		const char *err_msg;
+	} tests[] = {
+		{ "poison_exit", { BPF_EXIT_INSN() }, unrecognized },
+		{ "poison_ja", { BPF_JMP_A(1) }, unrecognized },
+		{ "poison_jmp", { BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 1) }, unrecognized },
+		{ "poison_jmp32", { BPF_JMP32_IMM(BPF_JEQ, BPF_REG_0, 0, 1) }, unrecognized },
+		{ "poison_call", { BPF_EMIT_CALL(BPF_FUNC_get_prandom_u32) }, unrecognized },
+		{ "poison_alu_reg", { BPF_MOV32_REG(BPF_REG_0, BPF_REG_1) }, unrecognized },
+		{ "poison_alu64_reg", { BPF_MOV64_REG(BPF_REG_0, BPF_REG_1) }, unrecognized },
+		{ "poison_ld_abs", { BPF_LD_ABS(BPF_W, 0) },
+		  "insn #2 (LDIMM64) has unexpected form" },
+		{ "poison_alu_imm", { BPF_MOV32_IMM(BPF_REG_0, 0) } },
+		{ "poison_alu64_imm", { BPF_MOV64_IMM(BPF_REG_0, 0) } },
+		{ "poison_ldx", { BPF_LDX_MEM(BPF_W, BPF_REG_0, BPF_REG_1, 0) } },
+		{ "poison_st", { BPF_ST_MEM(BPF_W, BPF_REG_10, -4, 0) } },
+		{ "poison_stx", { BPF_STX_MEM(BPF_W, BPF_REG_10, BPF_REG_0, -4) } },
+		{ "poison_ldimm64", { BPF_LD_IMM64(BPF_REG_0, 0) } },
+	};
+	struct bpf_insn core_only[] = {
+		BPF_MOV64_IMM(BPF_REG_0, 0),
+		BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 1),
+		BPF_MOV64_IMM(BPF_REG_0, 0),
+		BPF_EXIT_INSN(),
+	};
+	struct bpf_insn subprog[] = {
+		BPF_CALL_REL(2),
+		BPF_MOV64_IMM(BPF_REG_0, 0),
+		BPF_EXIT_INSN(),
+		BPF_MOV64_IMM(BPF_REG_0, 0),
+		BPF_EXIT_INSN(),
+	};
+	struct bpf_func_info funcs[2];
+	const void *raw_btf;
+	struct btf *btf;
+	__u32 raw_btf_size;
+	int access_str_off, btf_fd = -1, enum_id;
+	int int_id, main_id, prog_fd = -1, proto_id, sub_id, i;
+
+	btf = btf__new_empty();
+	if (!ASSERT_OK_PTR(btf, "btf_new_empty"))
+		return;
+	int_id = btf__add_int(btf, "int", 4, BTF_INT_SIGNED);
+	if (!ASSERT_GT(int_id, 0, "add_int"))
+		goto cleanup;
+	proto_id = btf__add_func_proto(btf, int_id);
+	if (!ASSERT_GT(proto_id, 0, "add_func_proto"))
+		goto cleanup;
+	main_id = btf__add_func(btf, "main_fn", BTF_FUNC_STATIC, proto_id);
+	if (!ASSERT_GT(main_id, 0, "add_main_func"))
+		goto cleanup;
+	sub_id = btf__add_func(btf, "sub_fn", BTF_FUNC_STATIC, proto_id);
+	if (!ASSERT_GT(sub_id, 0, "add_sub_func"))
+		goto cleanup;
+	enum_id = btf__add_enum(btf, "core_relo_poison_missing", 4);
+	if (!ASSERT_GT(enum_id, 0, "add_enum") ||
+	    !ASSERT_OK(btf__add_enum_value(btf, "value", 0), "add_enum_value"))
+		goto cleanup;
+	access_str_off = btf__add_str(btf, "0");
+	if (!ASSERT_GT(access_str_off, 0, "add_access_str"))
+		goto cleanup;
+
+	raw_btf = btf__raw_data(btf, &raw_btf_size);
+	if (!ASSERT_OK_PTR(raw_btf, "raw_btf"))
+		goto cleanup;
+	btf_fd = bpf_btf_load(raw_btf, raw_btf_size, NULL);
+	if (!ASSERT_GE(btf_fd, 0, "btf_load"))
+		goto cleanup;
+	funcs[0] = (struct bpf_func_info) { .insn_off = 0, .type_id = main_id };
+	funcs[1] = (struct bpf_func_info) { .insn_off = 3, .type_id = sub_id };
+
+	if (test__start_subtest("without_func_info")) {
+		prog_fd = load_core_relo_insns(btf_fd, core_only, ARRAY_SIZE(core_only), NULL, 0,
+					       enum_id, access_str_off, 2, false);
+		if (!ASSERT_GE(prog_fd, 0, "control_load"))
+			goto cleanup;
+		close(prog_fd);
+		prog_fd = load_core_relo_insns(btf_fd, core_only, ARRAY_SIZE(core_only), NULL, 0,
+					       enum_id, access_str_off, 2, true);
+		if (!ASSERT_GE(prog_fd, 0, "poisoned_load"))
+			goto cleanup;
+		ASSERT_HAS_SUBSTR(log, "substituting insn #2", "poison_log");
+		close(prog_fd);
+		prog_fd = -1;
+	}
+
+	if (test__start_subtest("poisoned_subprog_terminator")) {
+		prog_fd = load_core_relo_insns(btf_fd, subprog, ARRAY_SIZE(subprog), funcs, 2,
+					       enum_id, access_str_off, 2, false);
+		if (!ASSERT_GE(prog_fd, 0, "control_load"))
+			goto cleanup;
+		close(prog_fd);
+		prog_fd = load_core_relo_insns(btf_fd, subprog, ARRAY_SIZE(subprog), funcs, 2,
+					       enum_id, access_str_off, 2, true);
+		if (!ASSERT_LT(prog_fd, 0, "poisoned_load"))
+			goto cleanup;
+		ASSERT_HAS_SUBSTR(log, unrecognized, "poisoned_load_log");
+	}
+
+	for (i = 0; i < ARRAY_SIZE(tests); i++) {
+		struct bpf_insn insns[] = {
+			BPF_MOV64_IMM(BPF_REG_0, 0),
+			BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 2),
+			tests[i].insns[0],
+			BPF_MOV64_IMM(BPF_REG_0, 0),
+			BPF_MOV64_IMM(BPF_REG_0, 0),
+			BPF_EXIT_INSN(),
+		};
+		bool is_ldimm64 = insns[2].code == (BPF_LD | BPF_DW | BPF_IMM);
+		int insn_cnt = ARRAY_SIZE(insns);
+
+		if (!test__start_subtest(tests[i].name))
+			continue;
+		if (is_ldimm64) {
+			insns[3] = tests[i].insns[1];
+		} else {
+			insns[1].off = 1;
+			insns[4] = BPF_EXIT_INSN();
+			insn_cnt--;
+		}
+		prog_fd = load_core_relo_insns(btf_fd, insns, insn_cnt, funcs, 1,
+					       enum_id, access_str_off, 2, false);
+		if (!ASSERT_GE(prog_fd, 0, "control_load"))
+			goto cleanup;
+		close(prog_fd);
+		prog_fd = load_core_relo_insns(btf_fd, insns, insn_cnt, funcs, 1,
+					       enum_id, access_str_off, 2, true);
+		if (!tests[i].err_msg) {
+			ASSERT_GE(prog_fd, 0, "dead_poison_load");
+			ASSERT_HAS_SUBSTR(log, "substituting insn #2", "poison_log");
+			if (is_ldimm64)
+				ASSERT_HAS_SUBSTR(log, "substituting insn #3", "poison_ldimm64_log");
+		} else {
+			ASSERT_LT(prog_fd, 0, "invalid_poison_load");
+			ASSERT_HAS_SUBSTR(log, tests[i].err_msg, "invalid_poison_log");
+			ASSERT_NULL(strstr(log, "substituting insn"), "invalid_poison_substitution");
+		}
+		close(prog_fd);
+		prog_fd = -1;
+	}
+
+cleanup:
+	if (env.verbosity > VERBOSE_NORMAL && log[0]) {
+		printf("-------- program load log start --------\n");
+		printf("%s", log);
+		printf("-------- program load log end ----------\n");
+	}
+	close(prog_fd);
+	close(btf_fd);
+	btf__free(btf);
+}
+
 /* Check that verifier rejects BPF program containing relocation
  * pointing to non-existent BTF type.
  */
@@ -120,6 +311,7 @@ static void test_bad_local_id(void)
 
 void test_core_reloc_raw(void)
 {
+	test_early_core_relo();
 	if (test__start_subtest("bad_local_id"))
 		test_bad_local_id();
 }
diff --git a/tools/testing/selftests/bpf/prog_tests/core_reloc_truncated_ldimm64.c b/tools/testing/selftests/bpf/prog_tests/core_reloc_truncated_ldimm64.c
new file mode 100644
index 0000000000000..b70c8874241de
--- /dev/null
+++ b/tools/testing/selftests/bpf/prog_tests/core_reloc_truncated_ldimm64.c
@@ -0,0 +1,82 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (c) 2026 Meta Platforms, Inc. and affiliates. */
+
+#include <elf.h>
+#include <test_progs.h>
+
+#include "core_reloc_truncated_ldimm64.skel.h"
+
+static bool truncate_ldimm64_prog(void *elf_data, size_t elf_sz, const char *prog_name)
+{
+	Elf64_Ehdr *ehdr = elf_data;
+	Elf64_Shdr *shdrs;
+	Elf64_Sym *syms;
+	const char *strs;
+	size_t i, j;
+
+	if (elf_sz < sizeof(*ehdr) || ehdr->e_shoff > elf_sz ||
+	    ehdr->e_shnum > (elf_sz - ehdr->e_shoff) / sizeof(*shdrs))
+		return false;
+
+	shdrs = elf_data + ehdr->e_shoff;
+	for (i = 0; i < ehdr->e_shnum; i++) {
+		if (shdrs[i].sh_type != SHT_SYMTAB)
+			continue;
+		syms = elf_data + shdrs[i].sh_offset;
+		strs = elf_data + shdrs[shdrs[i].sh_link].sh_offset;
+		for (j = 0; j < shdrs[i].sh_size / sizeof(*syms); j++) {
+			if (ELF64_ST_TYPE(syms[j].st_info) == STT_FUNC &&
+			    !strcmp(strs + syms[j].st_name, prog_name)) {
+				syms[j].st_size = sizeof(struct bpf_insn);
+				return true;
+			}
+		}
+	}
+
+	return false;
+}
+
+static void run_test(const char *prog_name)
+{
+	const void *elf_bytes;
+	size_t elf_sz;
+	struct bpf_object *obj = NULL;
+	void *elf_data = NULL;
+	char *log = NULL;
+	int err;
+
+	elf_bytes = core_reloc_truncated_ldimm64__elf_bytes(&elf_sz);
+	if (!ASSERT_OK_PTR(elf_bytes, "elf_bytes"))
+		return;
+
+	elf_data = malloc(elf_sz);
+	if (!ASSERT_OK_PTR(elf_data, "elf_data"))
+		return;
+	memcpy(elf_data, elf_bytes, elf_sz);
+	if (!ASSERT_TRUE(truncate_ldimm64_prog(elf_data, elf_sz, prog_name), "truncate_prog"))
+		goto cleanup;
+
+	obj = bpf_object__open_mem(elf_data, elf_sz, NULL);
+	if (!ASSERT_OK_PTR(obj, "obj_open"))
+		goto cleanup;
+
+	if (start_libbpf_log_capture())
+		goto cleanup;
+	err = bpf_object__prepare(obj);
+	log = stop_libbpf_log_capture();
+	ASSERT_EQ(err, -EINVAL, "obj_prepare");
+	ASSERT_HAS_SUBSTR(log, "insn #0 (LDIMM64) is truncated", "libbpf_log");
+
+cleanup:
+	free(log);
+	bpf_object__close(obj);
+	free(elf_data);
+}
+
+void test_core_reloc_truncated_ldimm64(void)
+{
+	if (test__start_subtest("resolved"))
+		run_test("core_reloc_truncated_ldimm64_resolved");
+	if (test__start_subtest("poison"))
+		run_test("core_reloc_truncated_ldimm64_poison");
+}
diff --git a/tools/testing/selftests/bpf/prog_tests/spin_lock.c b/tools/testing/selftests/bpf/prog_tests/spin_lock.c
index 5c3579438427d..d49f52a8f8223 100644
--- a/tools/testing/selftests/bpf/prog_tests/spin_lock.c
+++ b/tools/testing/selftests/bpf/prog_tests/spin_lock.c
@@ -10,8 +10,8 @@ static char log_buf[1024 * 1024];
 
 static struct {
 	const char *prog_name;
-	const char *err_msg;
-} spin_lock_fail_tests[] = {
+	const char *err_msg; /* NULL if loading should succeed. */
+} spin_lock_tests[] = {
 	{ "lock_id_kptr_preserve",
 	  "[0-9]\\+: (bf) r1 = r0                       ; R0=ptr_foo(id=2)"
 	  " R1=ptr_foo(id=2) refs=2\n"
@@ -54,6 +54,22 @@ static struct {
 	{ "lock_global_sleepable_helper_subprog", "global function calls are not allowed while holding a lock" },
 	{ "lock_global_sleepable_kfunc_subprog", "global function calls are not allowed while holding a lock" },
 	{ "lock_global_sleepable_subprog_indirect", "global function calls are not allowed while holding a lock" },
+	{ "callback_value_lock_identity", "bpf_spin_unlock of different lock" },
+	{ "callback_inner_map_value_lock_identity", "bpf_spin_unlock of different lock" },
+	{ "callback_value_lock_identity_same", NULL },
+	{ "callback_single_value_lock_identity_same", NULL },
+	{ "lock_id_timer_preserve",
+	  "R1=map_value(id=[1-9][0-9]*,map=async_lock_map,[^\n]*\n"
+	  "[0-9]\\+: (85) call bpf_this_cpu_ptr#154\n"
+	  "R1 type=map_value expected=percpu_ptr_" },
+	{ "lock_id_wq_preserve",
+	  "R1=map_value(id=[1-9][0-9]*,map=async_lock_map,[^\n]*\n"
+	  "[0-9]\\+: (85) call bpf_this_cpu_ptr#154\n"
+	  "R1 type=map_value expected=percpu_ptr_" },
+	{ "lock_id_task_work_preserve",
+	  "R1=map_value(id=[1-9][0-9]*,map=async_lock_map,[^\n]*\n"
+	  "[0-9]\\+: (85) call bpf_this_cpu_ptr#154\n"
+	  "R1 type=map_value expected=percpu_ptr_" },
 };
 
 static int match_regex(const char *pattern, const char *string)
@@ -74,7 +90,7 @@ static int match_regex(const char *pattern, const char *string)
 	return rc == 0 ? 1 : 0;
 }
 
-static void test_spin_lock_fail_prog(const char *prog_name, const char *err_msg)
+static void test_spin_lock_prog(const char *prog_name, const char *err_msg)
 {
 	LIBBPF_OPTS(bpf_object_open_opts, opts, .kernel_log_buf = log_buf,
 						.kernel_log_size = sizeof(log_buf),
@@ -94,6 +110,10 @@ static void test_spin_lock_fail_prog(const char *prog_name, const char *err_msg)
 	bpf_program__set_autoload(prog, true);
 
 	ret = test_spin_lock_fail__load(skel);
+	if (!err_msg) {
+		ASSERT_OK(ret, "test_spin_lock_fail__load");
+		goto end;
+	}
 	if (!ASSERT_ERR(ret, "test_spin_lock_fail__load must fail"))
 		goto end;
 
@@ -166,10 +186,9 @@ void test_spin_lock(void)
 
 	test_spin_lock_success();
 
-	for (i = 0; i < ARRAY_SIZE(spin_lock_fail_tests); i++) {
-		if (!test__start_subtest(spin_lock_fail_tests[i].prog_name))
+	for (i = 0; i < ARRAY_SIZE(spin_lock_tests); i++) {
+		if (!test__start_subtest(spin_lock_tests[i].prog_name))
 			continue;
-		test_spin_lock_fail_prog(spin_lock_fail_tests[i].prog_name,
-					 spin_lock_fail_tests[i].err_msg);
+		test_spin_lock_prog(spin_lock_tests[i].prog_name, spin_lock_tests[i].err_msg);
 	}
 }
diff --git a/tools/testing/selftests/bpf/progs/core_reloc_truncated_ldimm64.c b/tools/testing/selftests/bpf/progs/core_reloc_truncated_ldimm64.c
new file mode 100644
index 0000000000000..d8d9a3650fe0d
--- /dev/null
+++ b/tools/testing/selftests/bpf/progs/core_reloc_truncated_ldimm64.c
@@ -0,0 +1,27 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (c) 2026 Meta Platforms, Inc. and affiliates. */
+
+#include "vmlinux.h"
+
+#include <bpf/bpf_helpers.h>
+#include <bpf/bpf_core_read.h>
+
+enum core_reloc_truncated_ldimm64 {
+	CORE_RELOC_TRUNCATED_LDIMM64_VALUE,
+};
+
+SEC("raw_tracepoint/sys_enter")
+int core_reloc_truncated_ldimm64_resolved(void *ctx)
+{
+	return bpf_core_enum_value_exists(enum core_reloc_truncated_ldimm64,
+					  CORE_RELOC_TRUNCATED_LDIMM64_VALUE);
+}
+
+SEC("raw_tracepoint/sys_exit")
+int core_reloc_truncated_ldimm64_poison(void *ctx)
+{
+	return bpf_core_enum_value(enum core_reloc_truncated_ldimm64,
+				   CORE_RELOC_TRUNCATED_LDIMM64_VALUE);
+}
+
+char LICENSE[] SEC("license") = "GPL";
diff --git a/tools/testing/selftests/bpf/progs/test_spin_lock_fail.c b/tools/testing/selftests/bpf/progs/test_spin_lock_fail.c
index f678ee6bd7eaf..a27bbbe3523fb 100644
--- a/tools/testing/selftests/bpf/progs/test_spin_lock_fail.c
+++ b/tools/testing/selftests/bpf/progs/test_spin_lock_fail.c
@@ -14,17 +14,18 @@ struct array_map {
 	__type(key, int);
 	__type(value, struct foo);
 	__uint(max_entries, 1);
-} array_map SEC(".maps");
+} array_map SEC(".maps"), array_map_b SEC(".maps");
 
 struct {
 	__uint(type, BPF_MAP_TYPE_ARRAY_OF_MAPS);
-	__uint(max_entries, 1);
+	__uint(max_entries, 2);
 	__type(key, int);
 	__type(value, int);
 	__array(values, struct array_map);
 } map_of_maps SEC(".maps") = {
 	.values = {
 		[0] = &array_map,
+		[1] = &array_map_b,
 	},
 };
 
@@ -314,4 +315,166 @@ int lock_global_sleepable_subprog_indirect(struct __sk_buff *ctx)
 	return ret;
 }
 
+struct {
+	__uint(type, BPF_MAP_TYPE_ARRAY);
+	__uint(max_entries, 2);
+	__type(key, int);
+	__type(value, struct foo);
+} callback_array_map SEC(".maps");
+
+struct callback_ctx {
+	struct foo *value;
+};
+
+static long lock_different_value(struct bpf_map *map, int *key,
+				 struct foo *value, struct callback_ctx *ctx)
+{
+	bpf_spin_lock(&value->lock);
+	bpf_spin_unlock(&ctx->value->lock);
+	return 0;
+}
+
+static long nest_lock_different_value(struct bpf_map *map, int *key,
+				      struct foo *value, void *data)
+{
+	struct callback_ctx ctx = { .value = value };
+
+	bpf_for_each_map_elem(&callback_array_map, lock_different_value, &ctx, 0);
+	return 0;
+}
+
+SEC("?tc")
+int callback_value_lock_identity(void *ctx)
+{
+	bpf_for_each_map_elem(&callback_array_map, nest_lock_different_value, NULL, 0);
+	return 0;
+}
+
+static long nest_lock_different_inner_value(struct bpf_map *map, int *key,
+					    struct foo *value, void *data)
+{
+	struct callback_ctx ctx = { .value = value };
+	int inner_key = 1;
+	void *inner_map;
+
+	inner_map = bpf_map_lookup_elem(&map_of_maps, &inner_key);
+	if (!inner_map)
+		return 0;
+	bpf_for_each_map_elem(inner_map, lock_different_value, &ctx, 0);
+	return 0;
+}
+
+SEC("?tc")
+int callback_inner_map_value_lock_identity(void *ctx)
+{
+	int inner_key = 0;
+	void *inner_map;
+
+	inner_map = bpf_map_lookup_elem(&map_of_maps, &inner_key);
+	if (!inner_map)
+		return 0;
+	bpf_for_each_map_elem(inner_map, nest_lock_different_inner_value, NULL, 0);
+	return 0;
+}
+
+static long lock_same_value(struct bpf_map *map, int *key,
+			    struct foo *value, void *data)
+{
+	bpf_spin_lock(&value->lock);
+	bpf_spin_unlock(&value->lock);
+	return 0;
+}
+
+static long nest_lock_same_value(struct bpf_map *map, int *key,
+				 struct foo *value, void *data)
+{
+	bpf_for_each_map_elem(&callback_array_map, lock_same_value, NULL, 0);
+	return 0;
+}
+
+SEC("?tc")
+int callback_value_lock_identity_same(void *ctx)
+{
+	bpf_for_each_map_elem(&callback_array_map, nest_lock_same_value, NULL, 0);
+	return 0;
+}
+
+SEC("?tc")
+int callback_single_value_lock_identity_same(void *ctx)
+{
+	bpf_for_each_map_elem(&array_map, lock_same_value, NULL, 0);
+	return 0;
+}
+
+struct async_lock_value {
+	struct bpf_spin_lock lock;
+	struct bpf_timer timer;
+	struct bpf_wq work;
+	struct bpf_task_work task_work;
+	int counter;
+};
+
+struct {
+	__uint(type, BPF_MAP_TYPE_ARRAY);
+	__uint(max_entries, 2);
+	__type(key, int);
+	__type(value, struct async_lock_value);
+} async_lock_map SEC(".maps");
+
+/*
+ * Expose the callback value ID in the verifier log, as in lock_id_mapval_preserve().
+ */
+static int async_lock_id_preserve(void *map, int *key, void *data)
+{
+	struct async_lock_value *value = data;
+
+	bpf_spin_lock(&value->lock);
+	value->counter++;
+	bpf_spin_unlock(&value->lock);
+	bpf_this_cpu_ptr(value);
+	return 0;
+}
+
+SEC("?tc")
+int lock_id_timer_preserve(void *ctx)
+{
+	struct async_lock_value *value;
+	int key = 0;
+
+	value = bpf_map_lookup_elem(&async_lock_map, &key);
+	if (value && !bpf_timer_init(&value->timer, &async_lock_map, 1))
+		bpf_timer_set_callback(&value->timer, async_lock_id_preserve);
+	return 0;
+}
+
+SEC("?tc")
+int lock_id_wq_preserve(void *ctx)
+{
+	struct async_lock_value *value;
+	int key = 0;
+
+	value = bpf_map_lookup_elem(&async_lock_map, &key);
+	if (value && !bpf_wq_init(&value->work, &async_lock_map, 0))
+		bpf_wq_set_callback(&value->work, async_lock_id_preserve, 0);
+	return 0;
+}
+
+static int task_work_lock_id_preserve(struct bpf_map *map, void *key, void *data)
+{
+	return async_lock_id_preserve(map, key, data);
+}
+
+SEC("?tc")
+int lock_id_task_work_preserve(void *ctx)
+{
+	struct async_lock_value *value;
+	int key = 0;
+
+	value = bpf_map_lookup_elem(&async_lock_map, &key);
+	if (value)
+		bpf_task_work_schedule_resume(bpf_get_current_task_btf(), &value->task_work,
+					      &async_lock_map, task_work_lock_id_preserve);
+	return 0;
+}
+
 char _license[] SEC("license") = "GPL";
diff --git a/tools/testing/selftests/bpf/progs/verifier_xdp_direct_packet_access.c b/tools/testing/selftests/bpf/progs/verifier_xdp_direct_packet_access.c
index 0b86d95a41335..9866bc154194a 100644
--- a/tools/testing/selftests/bpf/progs/verifier_xdp_direct_packet_access.c
+++ b/tools/testing/selftests/bpf/progs/verifier_xdp_direct_packet_access.c
@@ -1719,4 +1719,39 @@ l0_%=:	r0 = 0;						\
 	: __clobber_all);
 }
 
+SEC("xdp")
+__description("XDP pkt regsafe preserves packet pointer class displacement")
+__failure __msg("R2 min value is outside of the allowed memory range")
+__flag(BPF_F_ANY_ALIGNMENT) __flag(BPF_F_TEST_STATE_FREQ)
+__naked void pkt_regsafe_class_displacement(void)
+{
+	asm volatile ("					\
+	r8 = *(u32 *)(r1 + %[xdp_md_data_end]);		\
+	r9 = *(u32 *)(r1 + %[xdp_md_data]);		\
+	r4 = *(u32 *)(r1 + %[xdp_md_rx_queue_index]);	\
+	r4 &= 15;					\
+	r0 = *(u32 *)(r1 + %[xdp_md_ingress_ifindex]);	\
+	if r0 != 0 goto l0_%=;				\
+	r2 = r9;					\
+	r2 += r4;					\
+	r3 = r2;					\
+	r3 += 8;					\
+	goto l1_%=;					\
+l0_%=:	r4 &= 3;					\
+	r4 += 8;					\
+	r2 = r9;					\
+	r2 += r4;					\
+	r3 = r2;					\
+l1_%=:	if r3 > r8 goto l2_%=;				\
+	r0 = *(u64 *)(r2 + 0);				\
+l2_%=:	r0 = 0;						\
+	exit;						\
+"	:
+	: __imm_const(xdp_md_data, offsetof(struct xdp_md, data)),
+	  __imm_const(xdp_md_data_end, offsetof(struct xdp_md, data_end)),
+	  __imm_const(xdp_md_rx_queue_index, offsetof(struct xdp_md, rx_queue_index)),
+	  __imm_const(xdp_md_ingress_ifindex, offsetof(struct xdp_md, ingress_ifindex))
+	: __clobber_all);
+}
+
 char _license[] SEC("license") = "GPL";

49/3 2026/09/15 00:08 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 20355
							output: 25
							thoughts: 1427
						

Thoughts:
**KMSAN Fuzzing Justification: BPF Kernel Patch Analysis**

Alright, let's dissect this BPF patch series and determine if it warrants spinning up a dedicated KMSAN fuzzing session, in addition to our KASAN efforts. First, I need a solid understanding of these changes.

Looking at the patch breakdown, there are a number of areas I need to consider, from the BPF core code to the verifier, and the tools.

*   **Core and Relocation Handling:** The changes to `bpf_core_apply`, the handling of signals, fatal signals, and errors during JIT compilation are interesting. Ensuring proper error propagation using `-EINTR` is always good hygiene. The introduction of `insn_cnt` seems like an important addition.

*   **Fixups and Interrupts:** The fixup improvements and handling for `fatal_signal_pending` and `cond_resched()` in `bpf_rewrite_must_abort`, and the `-EINTR` propagation in `bpf_jit_subprogs` and `bpf_fixup_call_args` could expose new paths under stress.

*   **`struct bpf_reg_state` Changes and `frameno`:** The refactoring of `struct bpf_reg_state` is a critical point. The movement of `map_uid` out of the union and the introduction of `frameno` for stack frame differentiation require very close scrutiny. Specifically, I need to check how these changes impact state comparison and register tracking, particularly in conjunction with the `id` field. The `regs_exact` function concerns me. It seems to have a `memcmp` that could be impacted by the changes in `struct bpf_reg_state`. I need to figure out the layout of `struct bpf_reg_state` around `id` and `memcmp`. I'll need to double check the structure definitions and how they are used.

*   **Verifier Enhancements:** Changes in the verifier's behavior, especially the unconditional `reg->map_uid` assignment and the adjustments in `bpf_check` with the reordering of `bpf_check_core_relo`, are potential areas for concern. The changes in `bpf_prepare_btf_info` and the removal of `check_core_relo` from `bpf_check_btf_info` also catch my attention.

*   **Tools and Poisoning:** Improvements in the tooling, including truncation checks for `ldimm64` and poisoning handling, represent a positive step.

The focus should be on how the `struct bpf_reg_state` and the use of the `frameno` are interacting with the verifier state management, especially the comparisons and updates.

I'm now going to use `read-file` or `grepper` to find the exact layout of `struct bpf_reg_state` to see if there is potential for KMSAN issues. I need to be sure. If there are likely changes, I need to see if the changes are going to change the code execution paths in a way that KASAN won't capture. If this structure layout change has the potential to cause memory issues, or if the verifier changes could cause incorrect state management, then I'll definitely recommend a KMSAN session.



50/3 2026/09/15 00:09 tool grepper
0m Args:
{
  "Expression": "offsetof\\(struct bpf_reg_state, id"
}

Results:
{
  "Output": "kernel/bpf/states.c=488=static bool regs_exact(const struct bpf_reg_state *rold,\n--\nkernel/bpf/states.c-491-{\nkernel/bpf/states.c:492:\treturn memcmp(rold, rcur, offsetof(struct bpf_reg_state, id)) == 0 \u0026\u0026\nkernel/bpf/states.c-493-\t       check_ids(rold-\u003eid, rcur-\u003eid, idmap) \u0026\u0026\n--\nkernel/bpf/states.c=505=static bool regsafe(struct bpf_verifier_env *env, struct bpf_reg_state *rold,\n--\nkernel/bpf/states.c-545-\t\t\t */\nkernel/bpf/states.c:546:\t\t\treturn memcmp(rold, rcur, offsetof(struct bpf_reg_state, id)) == 0 \u0026\u0026\nkernel/bpf/states.c-547-\t\t\t       check_scalar_ids(rold-\u003eid, rcur-\u003eid, idmap);\n--\nkernel/bpf/verifier.c=7886=static bool scalars_exact_for_widen(const struct bpf_reg_state *rold,\n--\nkernel/bpf/verifier.c-7888-{\nkernel/bpf/verifier.c:7889:\treturn !memcmp(rold, rcur, offsetof(struct bpf_reg_state, id));\nkernel/bpf/verifier.c-7890-}\n"
}

51/3 2026/09/15 00:09 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 22902
							output: 38
							thoughts: 29
						

Thoughts:
Okay, here's my take on those thoughts, tailored for an expert audience:

**Diving into the BPF Verifier's Heart**

Alright, time to get my hands dirty. I'm going to start by taking a close look at the declaration of `struct bpf_reg_state`. Specifically, I'm heading straight to `include/linux/bpf_verifier.h`. It's foundational to understanding how the verifier actually reasons about register state, which, of course, is the lynchpin of BPF program safety and correctness. I want to see exactly how the verifier models registers, how it tracks their contents (potentially including constant values, ranges, pointers to maps, and so on), and, critically, how it handles things like immutability and potential side effects. I'm especially interested in whether they've made any significant changes from previous kernel versions. I'll be looking for nuances to impact performance or security.



52/3 2026/09/15 00:09 tool read-file
0m Args:
{
  "File": "include/linux/bpf_verifier.h",
  "FirstLine": 135,
  "LineCount": 40
}

Results:
{
  "Contents": " 135:\t\t * r1 += 10;   r1-\u003eid == N | BPF_ADD_CONST and r1-\u003edelta == 10\n 136:\t\t * r3 = r2;    both will have r3-\u003eid == r2-\u003eid == N\n 137:\t\t * w3 += 10;   r3-\u003eid == N | BPF_ADD_CONST32 and r3-\u003edelta == 10\n 138:\t\t */\n 139:\t#define BPF_ADD_CONST64 (1U \u003c\u003c 31)\n 140:\t#define BPF_ADD_CONST32 (1U \u003c\u003c 30)\n 141:\t#define BPF_ADD_CONST (BPF_ADD_CONST64 | BPF_ADD_CONST32)\n 142:\t\tu32 id;\n 143:\t\t/*\n 144:\t\t * Tracks the parent object this register was derived from.\n 145:\t\t * Used for cascading invalidation: when the parent object is\n 146:\t\t * released or invalidated, all registers with matching parent_id\n 147:\t\t * are also invalidated. For example, a slice from bpf_dynptr_data()\n 148:\t\t * gets parent_id set to the dynptr's id.\n 149:\t\t */\n 150:\t\tu32 parent_id;\n 151:\t\t/*\n 152:\t\t * Distinguishes inner-map lookups and their keys and values. Zero for\n 153:\t\t * other registers. Kept outside the metadata union for ID remapping\n 154:\t\t * during state comparisons.\n 155:\t\t */\n 156:\t\tu32 map_uid;\n 157:\t\t/*\n 158:\t\t * Inside the callee two registers can be both PTR_TO_STACK like\n 159:\t\t * R1=fp-8 and R2=fp-8, but one of them points to this function stack\n 160:\t\t * while another to the caller's stack. To differentiate them 'frameno'\n 161:\t\t * is used which is an index in bpf_verifier_state-\u003eframe[] array\n 162:\t\t * pointing to bpf_func_state.\n 163:\t\t */\n 164:\t\tu8 frameno;\n 165:\t\t/* if (!precise \u0026\u0026 SCALAR_VALUE) min/max/tnum don't affect safety */\n 166:\t\tbool precise;\n 167:\t};\n 168:\t\n 169:\tstatic inline s64 reg_smin(const struct bpf_reg_state *reg)\n 170:\t{\n 171:\t\treturn cnum64_smin(reg-\u003er64);\n 172:\t}\n 173:\t\n 174:\tstatic inline s64 reg_smax(const struct bpf_reg_state *reg)\n"
}

53/3 2026/09/15 00:09 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 23918
							output: 37
							thoughts: 16
						

Thoughts:
Here's my attempt at summarizing the thought process, tailored for an expert audience:

**Diving into `struct bpf_reg_state`**

Alright, let's get down to brass tacks. Time to dissect `struct bpf_reg_state`. I need to refresh my memory on the foundational elements of BPF register tracking. The goal here is to understand how the verifier models the state of registers at any given point in a program's execution, right? So, first things first, let's hit the definition and see what we're working with. I want to look at the beginning of the struct as a starting point. That initial structure holds the keys to understanding how the verifier understands register contents, type, and potential constraints. I'm focusing on that, because the initial definitions often offer key insights into overall design and intended use of the struct. This is where the core representation begins, and that will establish the foundation.



54/3 2026/09/15 00:09 tool read-file
0m Args:
{
  "File": "include/linux/bpf_verifier.h",
  "FirstLine": 30,
  "LineCount": 50
}

Results:
{
  "Contents": "  30:\t#define ITER_PREFIX \"bpf_iter_\"\n  31:\t\n  32:\tenum bpf_iter_state {\n  33:\t\tBPF_ITER_STATE_INVALID, /* for non-first slot */\n  34:\t\tBPF_ITER_STATE_ACTIVE,\n  35:\t\tBPF_ITER_STATE_DRAINED,\n  36:\t};\n  37:\t\n  38:\tstruct bpf_reg_state {\n  39:\t\t/* Ordering of fields matters.  See states_equal() */\n  40:\t\tenum bpf_reg_type type;\n  41:\t\t/*\n  42:\t\t * Constant delta between \"linked\" scalars with the same ID.\n  43:\t\t */\n  44:\t\ts32 delta;\n  45:\t\tunion {\n  46:\t\t\t/* valid when type == PTR_TO_PACKET */\n  47:\t\t\tint range;\n  48:\t\n  49:\t\t\t/*\n  50:\t\t\t * For CONST_PTR_TO_MAP, PTR_TO_MAP_KEY and PTR_TO_MAP_VALUE.\n  51:\t\t\t */\n  52:\t\t\tstruct bpf_map *map_ptr;\n  53:\t\n  54:\t\t\t/* for PTR_TO_BTF_ID */\n  55:\t\t\tstruct {\n  56:\t\t\t\tstruct btf *btf;\n  57:\t\t\t\tu32 btf_id;\n  58:\t\t\t};\n  59:\t\n  60:\t\t\tstruct { /* for PTR_TO_MEM | PTR_TO_MEM_OR_NULL */\n  61:\t\t\t\tu32 mem_size;\n  62:\t\t\t};\n  63:\t\n  64:\t\t\t/* For dynptr stack slots */\n  65:\t\t\tstruct {\n  66:\t\t\t\tenum bpf_dynptr_type type;\n  67:\t\t\t\t/* A dynptr is 16 bytes so it takes up 2 stack slots.\n  68:\t\t\t\t * We need to track which slot is the first slot\n  69:\t\t\t\t * to protect against cases where the user may try to\n  70:\t\t\t\t * pass in an address starting at the second slot of the\n  71:\t\t\t\t * dynptr.\n  72:\t\t\t\t */\n  73:\t\t\t\tbool first_slot;\n  74:\t\t\t} dynptr;\n  75:\t\n  76:\t\t\t/* For bpf_iter stack slots */\n  77:\t\t\tstruct {\n  78:\t\t\t\t/* BTF container and BTF type ID describing\n  79:\t\t\t\t * struct bpf_iter_\u003ctype\u003e of an iterator state\n"
}

55/3 2026/09/15 00:09 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 24820
							output: 37
							thoughts: 434
						

Thoughts:
**My Analysis of a Potential BPF Verifier Issue**

Okay, let's break this down. I'm looking at lines 38-40 in this `bpf_reg_state` struct definition, and it's immediately apparent that the field ordering *matters*, as the comment says, especially when comparing states. Specifically, `id` comes after a `union` and several other fields. The `memcmp` call uses `offsetof` on `id`, meaning it compares everything *before* that field.

Hold on... did this recent patch I'm examining actually change anything in that `memcmp`-ed region? That's the critical question here.

Now, let's examine the `union` itself. It was modified:
```diff
-		/* valid when type == CONST_PTR_TO_MAP | PTR_TO_MAP_VALUE |
-		 *   PTR_TO_MAP_VALUE_OR_NULL
+		/*
+		 * For CONST_PTR_TO_MAP, PTR_TO_MAP_KEY and PTR_TO_MAP_VALUE.
 		 */
-		struct {
-			struct bpf_map *map_ptr;
-			/* To distinguish map lookups from outer map
-			 * the map_uid is non-zero for registers
-			 * pointing to inner maps.
-			 */
-			u32 map_uid;
-		};
+		struct bpf_map *map_ptr;
```

Previously, the union included a nested struct containing `map_ptr` and `map_uid`.  This means that when the `type` was `CONST_PTR_TO_MAP` (and related types), the union's size was at least the size of a pointer to `bpf_map` plus 4 bytes, with likely padding - often 16 bytes on 64-bit systems. Now, it's just a single pointer.

So, the key here is what is the largest member of this union and what is now being compared? I need to check the full definition of that union to be sure. Time to dig into lines 75-135 of `include/linux/bpf_verifier.h` to confirm the largest member and ensure `memcmp` is correctly comparing the fields that have been changed by this diff.



56/3 2026/09/15 00:09 tool read-file
0m Args:
{
  "File": "include/linux/bpf_verifier.h",
  "FirstLine": 75,
  "LineCount": 60
}

Results:
{
  "Contents": "  75:\t\n  76:\t\t\t/* For bpf_iter stack slots */\n  77:\t\t\tstruct {\n  78:\t\t\t\t/* BTF container and BTF type ID describing\n  79:\t\t\t\t * struct bpf_iter_\u003ctype\u003e of an iterator state\n  80:\t\t\t\t */\n  81:\t\t\t\tstruct btf *btf;\n  82:\t\t\t\tu32 btf_id;\n  83:\t\t\t\t/* packing following two fields to fit iter state into 16 bytes */\n  84:\t\t\t\tenum bpf_iter_state state:2;\n  85:\t\t\t\tint depth:30;\n  86:\t\t\t} iter;\n  87:\t\n  88:\t\t\t/* For irq stack slots */\n  89:\t\t\tstruct {\n  90:\t\t\t\tenum {\n  91:\t\t\t\t\tIRQ_NATIVE_KFUNC,\n  92:\t\t\t\t\tIRQ_LOCK_KFUNC,\n  93:\t\t\t\t} kfunc_class;\n  94:\t\t\t} irq;\n  95:\t\n  96:\t\t\t/* Max size from any of the above. */\n  97:\t\t\tstruct {\n  98:\t\t\t\tunsigned long raw1;\n  99:\t\t\t\tunsigned long raw2;\n 100:\t\t\t} raw;\n 101:\t\n 102:\t\t\tu32 subprogno; /* for PTR_TO_FUNC */\n 103:\t\t};\n 104:\t\t/* For scalar types (SCALAR_VALUE), this represents our knowledge of\n 105:\t\t * the actual value.\n 106:\t\t * For pointer types, this represents the variable part of the offset\n 107:\t\t * from the pointed-to object, and is shared with all bpf_reg_states\n 108:\t\t * with the same id as us.\n 109:\t\t */\n 110:\t\tstruct tnum var_off;\n 111:\t\t/* Used to determine if any memory access using this register will\n 112:\t\t * result in a bad access.\n 113:\t\t * These refer to the same value as var_off, not necessarily the actual\n 114:\t\t * contents of the register.\n 115:\t\t */\n 116:\t\tstruct cnum64 r64; /* 64-bit range as circular number */\n 117:\t\tstruct cnum32 r32; /* 32-bit range as circular number */\n 118:\t\t/* For PTR_TO_PACKET, used to find other pointers with the same variable\n 119:\t\t * offset, so they can share range knowledge.\n 120:\t\t * For PTR_TO_MAP_VALUE_OR_NULL this is used to share which map value we\n 121:\t\t * came from, when one is tested for != NULL.\n 122:\t\t * For PTR_TO_MEM_OR_NULL this is used to identify memory allocation\n 123:\t\t * for the purpose of tracking that it's freed.\n 124:\t\t * For PTR_TO_SOCKET this is used to share which pointers retain the\n 125:\t\t * same reference to the socket, to determine proper reference freeing.\n 126:\t\t * For stack slots that are dynptrs, this is used to track references to\n 127:\t\t * the dynptr to determine proper reference freeing.\n 128:\t\t * Similarly to dynptrs, we use ID to track \"belonging\" of a reference\n 129:\t\t * to a specific instance of bpf_iter.\n 130:\t\t */\n 131:\t\t/*\n 132:\t\t * Upper bit of ID is used to remember relationship between \"linked\"\n 133:\t\t * registers. Example:\n 134:\t\t * r1 = r2;    both will have r1-\u003eid == r2-\u003eid == N\n"
}

57/3 2026/09/15 00:09 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 26741
							output: 33
							thoughts: 279
						

Thoughts:
**Analyzing the bpf_reg_state Structure**

Okay, so the `union` originally had `raw`, which consists of two `unsigned long` values, totaling 16 bytes. That means the union itself has always been, and continues to be, 16 bytes. Now, we've got this new structure where `map_uid` has been added after the `id` and `parent_id` fields.

Let's break down the changes. Before the patch, `frameno` was a `u32`, taking up 4 bytes. Now, we have `map_uid` as a `u32` (4 bytes), `frameno` as a `u8` (1 byte), and `precise` as a `bool` (1 byte). Aha, there's also padding after `precise` to ensure proper alignment of the structure. I suspect the padding is 2 bytes, but I'll need to double check the struct alignment rules.

The critical question now is how the `bpf_reg_state` is initialized. Where are these values coming from? I need to understand where the allocation or initialization of `bpf_reg_state` is occurring. To do that, I'm going to track its use in the code. I'll focus on the registers within `bpf_verifier_state` and `bpf_func_state`. Let's search for instances of `bpf_func_state`, as well as look for usages of functions like `__mark_reg_not_init` or `__mark_reg_known`, as that might reveal where the register state is managed.



58/3 2026/09/15 00:09 tool grepper
0m Error:
no matches

Args:
{
  "Expression": "__mark_reg_not_init",
  "PathPrefix": "kernel/bpf/"
}

Results:
{
  "error": "no matches"
}

59/3 2026/09/15 00:09 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 27418
							output: 32
							thoughts: 23
						

Thoughts:
Here's my thought process, summarized as you requested:

**Navigating the Register State Quandary**

Okay, so I need to dig into something related to register initialization. My gut tells me that the problem likely centers around the way the BPF verifier handles register states. So, my first step is to see if I can find some relevant code. I'm going to kick off a search for either `mark_reg_not_init` or `bpf_reg_state`. These keywords should surface the key areas within the codebase. I expect one or both of them will lead me straight to the heart of the issue – specifically, how the verifier tracks and interprets the states of BPF registers, or perhaps a function that handles marking a register as uninitialized.



60/3 2026/09/15 00:09 tool grepper
0m Args:
{
  "Expression": "mark_reg_not_init",
  "PathPrefix": "kernel/bpf/"
}

Results:
{
  "Output": "kernel/bpf/states.c=398=static void __clean_func_state(struct bpf_verifier_env *env,\n--\nkernel/bpf/states.c-409-\t\t\t */\nkernel/bpf/states.c:410:\t\t\tbpf_mark_reg_not_init(env, \u0026st-\u003eregs[i]);\nkernel/bpf/states.c-411-\t}\n--\nkernel/bpf/states.c-462-\t\t\t\t}\nkernel/bpf/states.c:463:\t\t\t\tbpf_mark_reg_not_init(env, spill);\nkernel/bpf/states.c-464-\t\t\t}\n--\nkernel/bpf/verifier.c=740=static void invalidate_dynptr(struct bpf_verifier_env *env, struct bpf_stack_state *stack)\n--\nkernel/bpf/verifier.c-748-\nkernel/bpf/verifier.c:749:\tbpf_mark_reg_not_init(env, \u0026stack[0].spilled_ptr);\nkernel/bpf/verifier.c:750:\tbpf_mark_reg_not_init(env, \u0026stack[1].spilled_ptr);\nkernel/bpf/verifier.c-751-}\n--\nkernel/bpf/verifier.c=776=static void mark_reg_invalid(const struct bpf_verifier_env *env, struct bpf_reg_state *reg)\n--\nkernel/bpf/verifier.c-778-\tif (!env-\u003eallow_ptr_leaks)\nkernel/bpf/verifier.c:779:\t\tbpf_mark_reg_not_init(env, reg);\nkernel/bpf/verifier.c-780-\telse\n--\nkernel/bpf/verifier.c=976=static int unmark_stack_slots_iter(struct bpf_verifier_env *env,\n--\nkernel/bpf/verifier.c-992-\nkernel/bpf/verifier.c:993:\t\tbpf_mark_reg_not_init(env, st);\nkernel/bpf/verifier.c-994-\n--\nkernel/bpf/verifier.c=1099=static int unmark_stack_slot_irq_flag(struct bpf_verifier_env *env, struct bpf_reg_state *reg,\n--\nkernel/bpf/verifier.c-1154-\nkernel/bpf/verifier.c:1155:\tbpf_mark_reg_not_init(env, st);\nkernel/bpf/verifier.c-1156-\n--\nkernel/bpf/verifier.c=2217=static int __mark_reg_s32_range(struct bpf_verifier_env *env,\n--\nkernel/bpf/verifier.c-2236-\nkernel/bpf/verifier.c:2237:void bpf_mark_reg_not_init(const struct bpf_verifier_env *env,\nkernel/bpf/verifier.c-2238-\t\t\t   struct bpf_reg_state *reg)\n--\nkernel/bpf/verifier.c=2273=static void init_reg_state(struct bpf_verifier_env *env,\n--\nkernel/bpf/verifier.c-2279-\tfor (i = 0; i \u003c MAX_BPF_REG; i++) {\nkernel/bpf/verifier.c:2280:\t\tbpf_mark_reg_not_init(env, \u0026regs[i]);\nkernel/bpf/verifier.c-2281-\t}\n--\nkernel/bpf/verifier.c=9600=static void clear_caller_saved_regs(struct bpf_verifier_env *env,\n--\nkernel/bpf/verifier.c-9608-\tfor (i = 0; i \u003c CALLER_SAVED_REGS; i++) {\nkernel/bpf/verifier.c:9609:\t\tbpf_mark_reg_not_init(env, \u0026regs[caller_saved[i]]);\nkernel/bpf/verifier.c-9610-\t\t__check_reg_arg(env, regs, caller_saved[i], DST_OP_NO_MARK);\n--\nkernel/bpf/verifier.c=9614=static void invalidate_outgoing_stack_args(struct bpf_verifier_env *env,\n--\nkernel/bpf/verifier.c-9620-\t\tbpf_diag_record_scrub(env, \u0026state-\u003estack_arg_regs[i], BPF_DIAG_MOD_CALLER_SAVED);\nkernel/bpf/verifier.c:9621:\t\tbpf_mark_reg_not_init(env, \u0026state-\u003estack_arg_regs[i]);\nkernel/bpf/verifier.c-9622-\t}\n--\nkernel/bpf/verifier.c=10033=int map_set_for_each_callback_args(struct bpf_verifier_env *env,\n--\nkernel/bpf/verifier.c-10058-\t/* unused */\nkernel/bpf/verifier.c:10059:\tbpf_mark_reg_not_init(env, \u0026callee-\u003eregs[BPF_REG_5]);\nkernel/bpf/verifier.c-10060-\treturn 0;\n--\nkernel/bpf/verifier.c=10103=static int set_loop_callback_state(struct bpf_verifier_env *env,\n--\nkernel/bpf/verifier.c-10115-\t/* unused */\nkernel/bpf/verifier.c:10116:\tbpf_mark_reg_not_init(env, \u0026callee-\u003eregs[BPF_REG_3]);\nkernel/bpf/verifier.c:10117:\tbpf_mark_reg_not_init(env, \u0026callee-\u003eregs[BPF_REG_4]);\nkernel/bpf/verifier.c:10118:\tbpf_mark_reg_not_init(env, \u0026callee-\u003eregs[BPF_REG_5]);\nkernel/bpf/verifier.c-10119-\n--\nkernel/bpf/verifier.c=10125=static int set_timer_callback_state(struct bpf_verifier_env *env,\n--\nkernel/bpf/verifier.c-10152-\t/* unused */\nkernel/bpf/verifier.c:10153:\tbpf_mark_reg_not_init(env, \u0026callee-\u003eregs[BPF_REG_4]);\nkernel/bpf/verifier.c:10154:\tbpf_mark_reg_not_init(env, \u0026callee-\u003eregs[BPF_REG_5]);\nkernel/bpf/verifier.c-10155-\tcallee-\u003ein_async_callback_fn = true;\n--\nkernel/bpf/verifier.c=10160=static int set_find_vma_callback_state(struct bpf_verifier_env *env,\n--\nkernel/bpf/verifier.c-10180-\t/* unused */\nkernel/bpf/verifier.c:10181:\tbpf_mark_reg_not_init(env, \u0026callee-\u003eregs[BPF_REG_4]);\nkernel/bpf/verifier.c:10182:\tbpf_mark_reg_not_init(env, \u0026callee-\u003eregs[BPF_REG_5]);\nkernel/bpf/verifier.c-10183-\tcallee-\u003ein_callback_fn = true;\n--\nkernel/bpf/verifier.c=10188=static int set_user_ringbuf_callback_state(struct bpf_verifier_env *env,\n--\nkernel/bpf/verifier.c-10196-\t */\nkernel/bpf/verifier.c:10197:\tbpf_mark_reg_not_init(env, \u0026callee-\u003eregs[BPF_REG_0]);\nkernel/bpf/verifier.c-10198-\tmark_dynptr_cb_reg(env, \u0026callee-\u003eregs[BPF_REG_1], BPF_DYNPTR_TYPE_LOCAL);\n--\nkernel/bpf/verifier.c-10201-\t/* unused */\nkernel/bpf/verifier.c:10202:\tbpf_mark_reg_not_init(env, \u0026callee-\u003eregs[BPF_REG_3]);\nkernel/bpf/verifier.c:10203:\tbpf_mark_reg_not_init(env, \u0026callee-\u003eregs[BPF_REG_4]);\nkernel/bpf/verifier.c:10204:\tbpf_mark_reg_not_init(env, \u0026callee-\u003eregs[BPF_REG_5]);\nkernel/bpf/verifier.c-10205-\n--\nkernel/bpf/verifier.c=10211=static int set_rbtree_add_callback_state(struct bpf_verifier_env *env,\n--\nkernel/bpf/verifier.c-10235-\nkernel/bpf/verifier.c:10236:\tbpf_mark_reg_not_init(env, \u0026callee-\u003eregs[BPF_REG_3]);\nkernel/bpf/verifier.c:10237:\tbpf_mark_reg_not_init(env, \u0026callee-\u003eregs[BPF_REG_4]);\nkernel/bpf/verifier.c:10238:\tbpf_mark_reg_not_init(env, \u0026callee-\u003eregs[BPF_REG_5]);\nkernel/bpf/verifier.c-10239-\tcallee-\u003ein_callback_fn = true;\n--\nkernel/bpf/verifier.c=10244=static int set_task_work_schedule_callback_state(struct bpf_verifier_env *env,\n--\nkernel/bpf/verifier.c-10271-\t/* unused */\nkernel/bpf/verifier.c:10272:\tbpf_mark_reg_not_init(env, \u0026callee-\u003eregs[BPF_REG_4]);\nkernel/bpf/verifier.c:10273:\tbpf_mark_reg_not_init(env, \u0026callee-\u003eregs[BPF_REG_5]);\nkernel/bpf/verifier.c-10274-\tcallee-\u003ein_async_callback_fn = true;\n--\nkernel/bpf/verifier.c=10830=static int check_helper_call(struct bpf_verifier_env *env, struct bpf_insn *insn,\n--\nkernel/bpf/verifier.c-11100-\tfor (i = 0; i \u003c CALLER_SAVED_REGS; i++) {\nkernel/bpf/verifier.c:11101:\t\tbpf_mark_reg_not_init(env, \u0026regs[caller_saved[i]]);\nkernel/bpf/verifier.c-11102-\t\tcheck_reg_arg(env, caller_saved[i], DST_OP_NO_MARK);\n--\nkernel/bpf/verifier.c=13777=static int check_kfunc_call(struct bpf_verifier_env *env, struct bpf_insn *insn,\n--\nkernel/bpf/verifier.c-13836-\t\tfor (i = 0; i \u003c CALLER_SAVED_REGS; i++)\nkernel/bpf/verifier.c:13837:\t\t\tbpf_mark_reg_not_init(env, \u0026regs[caller_saved[i]]);\nkernel/bpf/verifier.c-13838-\n--\nkernel/bpf/verifier.c-14033-\nkernel/bpf/verifier.c:14034:\t\tbpf_mark_reg_not_init(env, \u0026regs[regno]);\nkernel/bpf/verifier.c-14035-\t}\n--\nkernel/bpf/verifier.c=17319=static int check_ld_abs(struct bpf_verifier_env *env, struct bpf_insn *insn)\n--\nkernel/bpf/verifier.c-17377-\tfor (i = 0; i \u003c CALLER_SAVED_REGS; i++) {\nkernel/bpf/verifier.c:17378:\t\tbpf_mark_reg_not_init(env, \u0026regs[caller_saved[i]]);\nkernel/bpf/verifier.c-17379-\t\tcheck_reg_arg(env, caller_saved[i], DST_OP_NO_MARK);\n"
}

61/3 2026/09/15 00:09 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 30786
							output: 37
							thoughts: 16
						

Thoughts:
Okay, let's dive into this. Here's my take on those thoughts, as if they're my own:

**Analyzing `bpf_mark_reg_not_init`**

Alright, so I'm thinking about `bpf_mark_reg_not_init`. What's this related to? Immediately, I'm picturing eBPF registers and their initialization. It's a common area for errors in BPF programs – uninitialized registers leading to undefined behavior, crashes, or potential security vulnerabilities. `bpf_mark_reg_not_init` is likely a mechanism, either at compile time or runtime, to flag situations where a register is being used before it's been properly initialized with a known value.

Is this a kernel-side check? Is it a helper function within the BPF verifier? Perhaps it's a compile-time optimization flag or a debug feature. Knowing the context is key. If it's the verifier, I'm expecting it to be pretty comprehensive, ensuring data dependencies are satisfied before any register is read. If it's runtime, it might be a more targeted check, maybe for specific register classes or potentially dangerous operations like dereferencing an uninitialized pointer.

I need to understand *how* it's being used. Is it a return code? A log message? A triggered breakpoint? This impacts my understanding of its severity and how it affects BPF program execution. Is this part of a broader set of checks to catch a class of errors, which, if so, is good. What's the trade-off here? Does it add a performance penalty? What are the limitations, the cases it can't detect? And the next thing I'd want to know is what are the actions that it permits? What are the consequences of this happening, and how can the program's code be fixed?

Ultimately, my goal would be to trace its usage in the source code, see where it's being called, and analyze the surrounding logic. Then I'd want to see how it fits into the broader BPF framework – is it part of the verifier, the JIT compiler, or some other component? This all helps me understand the bigger picture, the role it plays in ensuring eBPF program safety and stability.



62/3 2026/09/15 00:09 tool read-file
0m Args:
{
  "File": "kernel/bpf/verifier.c",
  "FirstLine": 2235,
  "LineCount": 40
}

Results:
{
  "Contents": "2235:\t}\n2236:\t\n2237:\tvoid bpf_mark_reg_not_init(const struct bpf_verifier_env *env,\n2238:\t\t\t\t   struct bpf_reg_state *reg)\n2239:\t{\n2240:\t\t__mark_reg_unknown(env, reg);\n2241:\t\treg-\u003etype = NOT_INIT;\n2242:\t}\n2243:\t\n2244:\tstatic int mark_btf_ld_reg(struct bpf_verifier_env *env,\n2245:\t\t\t\t   struct bpf_reg_state *regs, u32 regno,\n2246:\t\t\t\t   enum bpf_reg_type reg_type,\n2247:\t\t\t\t   struct btf *btf, u32 btf_id,\n2248:\t\t\t\t   enum bpf_type_flag flag)\n2249:\t{\n2250:\t\tswitch (reg_type) {\n2251:\t\tcase SCALAR_VALUE:\n2252:\t\t\tmark_reg_unknown(env, regs, regno);\n2253:\t\t\treturn 0;\n2254:\t\tcase PTR_TO_BTF_ID:\n2255:\t\t\tmark_reg_known_zero(env, regs, regno);\n2256:\t\t\tregs[regno].type = PTR_TO_BTF_ID | flag;\n2257:\t\t\tregs[regno].btf = btf;\n2258:\t\t\tregs[regno].btf_id = btf_id;\n2259:\t\t\tif (type_may_be_null(flag))\n2260:\t\t\t\tregs[regno].id = ++env-\u003eid_gen;\n2261:\t\t\treturn 0;\n2262:\t\tcase PTR_TO_MEM:\n2263:\t\t\tmark_reg_known_zero(env, regs, regno);\n2264:\t\t\tregs[regno].type = PTR_TO_MEM | flag;\n2265:\t\t\tregs[regno].mem_size = 0;\n2266:\t\t\treturn 0;\n2267:\t\tdefault:\n2268:\t\t\tverifier_bug(env, \"unexpected reg_type %d in %s\\n\", reg_type, __func__);\n2269:\t\t\treturn -EFAULT;\n2270:\t\t}\n2271:\t}\n2272:\t\n2273:\tstatic void init_reg_state(struct bpf_verifier_env *env,\n2274:\t\t\t\t   struct bpf_func_state *state)\n"
}

63/3 2026/09/15 00:09 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 31992
							output: 37
							thoughts: 21
						

Thoughts:
Here's my attempt at summarizing those thoughts, presented as a first-person expert perspective:

**Diving into Register Marking Functions**

Okay, so I'm looking at `__mark_reg_unknown` and `__mark_reg_known`. These are probably critical for the register allocation and optimization phase, likely at the low-level intermediate representation or assembly generation stage. I'm guessing `__mark_reg_unknown` signifies that a register's contents are undefined or irrelevant at a specific program point. It’s the starting state, maybe right before the register is assigned or the beginning of a code block. Then, `__mark_reg_known` is the opposite: We now *know* what’s in that register, that it contains a specific value, pointer or whatever. This transition between known and unknown must be how the system keeps track of the register's validity, and what sort of value is held at any given time. This seems fundamental to doing anything that involves using and re-using registers in a meaningful way to improve performance. I need to understand the implications of calling these functions, the side-effects they have on the register metadata, and how they play into the overall register allocation strategy. I bet they're tightly coupled with the liveness analysis and the spilling/reloading mechanisms. Let's see how these are used in the broader picture.



64/3 2026/09/15 00:10 tool read-file
0m Args:
{
  "File": "kernel/bpf/verifier.c",
  "FirstLine": 1860,
  "LineCount": 40
}

Results:
{
  "Contents": "1860:\tstatic void __mark_reg_known(struct bpf_reg_state *reg, u64 imm)\n1861:\t{\n1862:\t\t/* Clear off and union(map_ptr, range) */\n1863:\t\tmemset(((u8 *)reg) + sizeof(reg-\u003etype), 0,\n1864:\t\t       offsetof(struct bpf_reg_state, var_off) - sizeof(reg-\u003etype));\n1865:\t\treg-\u003eid = 0;\n1866:\t\treg-\u003eparent_id = 0;\n1867:\t\treg-\u003emap_uid = 0;\n1868:\t\t___mark_reg_known(reg, imm);\n1869:\t}\n1870:\t\n1871:\tstatic void __mark_reg32_known(struct bpf_reg_state *reg, u64 imm)\n1872:\t{\n1873:\t\treg-\u003evar_off = tnum_const_subreg(reg-\u003evar_off, imm);\n1874:\t\treg-\u003er32 = cnum32_from_urange((u32)imm, (u32)imm);\n1875:\t}\n1876:\t\n1877:\t/* Mark the 'variable offset' part of a register as zero.  This should be\n1878:\t * used only on registers holding a pointer type.\n1879:\t */\n1880:\tstatic void __mark_reg_known_zero(struct bpf_reg_state *reg)\n1881:\t{\n1882:\t\t__mark_reg_known(reg, 0);\n1883:\t}\n1884:\t\n1885:\tstatic void __mark_reg_const_zero(const struct bpf_verifier_env *env, struct bpf_reg_state *reg)\n1886:\t{\n1887:\t\t__mark_reg_known(reg, 0);\n1888:\t\treg-\u003etype = SCALAR_VALUE;\n1889:\t\t/* all scalars are assumed imprecise initially (unless unprivileged,\n1890:\t\t * in which case everything is forced to be precise)\n1891:\t\t */\n1892:\t\treg-\u003eprecise = !env-\u003ebpf_capable;\n1893:\t}\n1894:\t\n1895:\tstatic void mark_reg_known_zero(struct bpf_verifier_env *env,\n1896:\t\t\t\t\tstruct bpf_reg_state *regs, u32 regno)\n1897:\t{\n1898:\t\t__mark_reg_known_zero(regs + regno);\n1899:\t}\n"
}

65/3 2026/09/15 00:10 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 33029
							output: 32
							thoughts: 12
						

Thoughts:
Okay, here's my interpretation of that.

**Analyzing `__mark_reg_unknown`**

Right, let's dive into this `__mark_reg_unknown` thing. I'm assuming, given the naming convention, this is related to a system for register management, most likely within a compiler or an assembly environment, or perhaps even in a microarchitecture context. It's almost certainly internal, indicated by the double underscores, and it's probably intended to flag a register as being in an indeterminate or undefined state.

So, the key questions I'm immediately asking myself are: What constitutes "unknown" here? Is it truly *unknown*, meaning the register's contents are genuinely unpredictable, or is it more of a "not initialized," "potentially garbage," or "in use by another process/thread" kind of unknown? The level of detail here is important as it has implications for optimization and debugging.

I'm thinking about how this function might be used. Is it called during register allocation, spill/fill operations, or maybe even within the code generator? What are the calling conventions? What's the impact on data dependency graphs and potential hazards? Is there a corresponding "unmark" function, or is the intention that "unknown" persists until explicit reassignment?

Given my expertise, I'm already formulating questions about the underlying data structures. Is this a bitfield, a separate data structure entry, or is the "unknown" state encoded in the register's metadata? Is it thread-safe? How does it interact with potential register renaming, or other optimizations that depend on register tracking? Does the "unknown" state trigger any specific compiler diagnostics, or generate specific assembly instructions, such as potentially a `MOV` with an immediate zero/null, or an explicit exception, to indicate that it's uninitialized?

Finally, what are the implications on exception handling? Will an "unknown" register value impact the behavior of any debugging or error traps? I need to know the entire context to fully understand the design decisions within this function.



66/3 2026/09/15 00:10 tool grepper
0m Args:
{
  "Expression": "__mark_reg_unknown\\(",
  "PathPrefix": "kernel/bpf/"
}

Results:
{
  "Output": "kernel/bpf/verifier.c=753=static int unmark_stack_slots_dynptr(struct bpf_verifier_env *env, struct bpf_reg_state *reg)\n--\nkernel/bpf/verifier.c-772-\nkernel/bpf/verifier.c:773:static void __mark_reg_unknown(const struct bpf_verifier_env *env,\nkernel/bpf/verifier.c-774-\t\t\t       struct bpf_reg_state *reg);\n--\nkernel/bpf/verifier.c=776=static void mark_reg_invalid(const struct bpf_verifier_env *env, struct bpf_reg_state *reg)\n--\nkernel/bpf/verifier.c-780-\telse\nkernel/bpf/verifier.c:781:\t\t__mark_reg_unknown(env, reg);\nkernel/bpf/verifier.c-782-}\n--\nkernel/bpf/verifier.c=2193=void bpf_mark_reg_unknown_imprecise(struct bpf_reg_state *reg)\n--\nkernel/bpf/verifier.c-2203- */\nkernel/bpf/verifier.c:2204:static void __mark_reg_unknown(const struct bpf_verifier_env *env,\nkernel/bpf/verifier.c-2205-\t\t\t       struct bpf_reg_state *reg)\n--\nkernel/bpf/verifier.c=2211=static void mark_reg_unknown(struct bpf_verifier_env *env,\n--\nkernel/bpf/verifier.c-2213-{\nkernel/bpf/verifier.c:2214:\t__mark_reg_unknown(env, regs + regno);\nkernel/bpf/verifier.c-2215-}\n--\nkernel/bpf/verifier.c=2237=void bpf_mark_reg_not_init(const struct bpf_verifier_env *env,\n--\nkernel/bpf/verifier.c-2239-{\nkernel/bpf/verifier.c:2240:\t__mark_reg_unknown(env, reg);\nkernel/bpf/verifier.c-2241-\treg-\u003etype = NOT_INIT;\n--\nkernel/bpf/verifier.c=6895=static int check_stack_range_initialized(\n--\nkernel/bpf/verifier.c-6985-\t\t\tif (clobber) {\nkernel/bpf/verifier.c:6986:\t\t\t\t__mark_reg_unknown(env, \u0026state-\u003estack[spi].spilled_ptr);\nkernel/bpf/verifier.c-6987-\t\t\t\tfor (j = 0; j \u003c BPF_REG_SIZE; j++)\n--\nkernel/bpf/verifier.c=7892=static void maybe_widen_reg(struct bpf_verifier_env *env,\n--\nkernel/bpf/verifier.c-7900-\t\treturn;\nkernel/bpf/verifier.c:7901:\t__mark_reg_unknown(env, rcur);\nkernel/bpf/verifier.c-7902-}\n--\nkernel/bpf/verifier.c=14571=static int adjust_ptr_min_max_vals(struct bpf_verifier_env *env, struct bpf_insn *insn,\n--\nkernel/bpf/verifier.c-14593-\t\t */\nkernel/bpf/verifier.c:14594:\t\t__mark_reg_unknown(env, dst_reg);\nkernel/bpf/verifier.c-14595-\t\treturn 0;\n--\nkernel/bpf/verifier.c-14600-\t\tif (opcode == BPF_SUB \u0026\u0026 env-\u003eallow_ptr_leaks) {\nkernel/bpf/verifier.c:14601:\t\t\t__mark_reg_unknown(env, dst_reg);\nkernel/bpf/verifier.c-14602-\t\t\treturn 0;\n--\nkernel/bpf/verifier.c=15572=static int adjust_scalar_min_max_vals(struct bpf_verifier_env *env,\n--\nkernel/bpf/verifier.c-15582-\tif (!is_safe_to_compute_dst_reg_range(insn, \u0026src_reg)) {\nkernel/bpf/verifier.c:15583:\t\t__mark_reg_unknown(env, dst_reg);\nkernel/bpf/verifier.c-15584-\t\treturn 0;\n--\nkernel/bpf/verifier.c=17182=static int check_ld_imm(struct bpf_verifier_env *env, struct bpf_insn *insn)\n--\nkernel/bpf/verifier.c-17267-\t\tif (map-\u003emap_type == BPF_MAP_TYPE_ARENA) {\nkernel/bpf/verifier.c:17268:\t\t\t__mark_reg_unknown(env, dst_reg);\nkernel/bpf/verifier.c-17269-\t\t\tdst_reg-\u003emap_ptr = map;\n"
}

67/3 2026/09/15 00:10 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 34771
							output: 37
							thoughts: 20
						

Thoughts:
Okay, here's my interpretation of that thought process, assuming I'm deep in my code and familiar with it, speaking directly to myself:

**Diving into the Unknown: Line 2204**

Alright, time to get my head back in this. Let's get right to it - I need to check out `__mark_reg_unknown`. Yep, line 2204. That rings a bell, I think I know where that is in the codebase, but I need to be sure. Time to jump in there and get my head around what's happening. Probably some register state I need to understand, maybe how the stack is being managed, or a potential source of memory corruption. Let's see what's what.



68/3 2026/09/15 00:10 tool read-file
0m Args:
{
  "File": "kernel/bpf/verifier.c",
  "FirstLine": 2190,
  "LineCount": 35
}

Results:
{
  "Contents": "2190:\t}\n2191:\t\n2192:\t/* Mark a register as having a completely unknown (scalar) value. */\n2193:\tvoid bpf_mark_reg_unknown_imprecise(struct bpf_reg_state *reg)\n2194:\t{\n2195:\t\tmemset(reg, 0, sizeof(*reg));\n2196:\t\treg-\u003etype = SCALAR_VALUE;\n2197:\t\treg-\u003evar_off = tnum_unknown;\n2198:\t\t__mark_reg_unbounded(reg);\n2199:\t}\n2200:\t\n2201:\t/* Mark a register as having a completely unknown (scalar) value,\n2202:\t * initialize .precise as true when not bpf capable.\n2203:\t */\n2204:\tstatic void __mark_reg_unknown(const struct bpf_verifier_env *env,\n2205:\t\t\t\t       struct bpf_reg_state *reg)\n2206:\t{\n2207:\t\tbpf_mark_reg_unknown_imprecise(reg);\n2208:\t\treg-\u003eprecise = !env-\u003ebpf_capable;\n2209:\t}\n2210:\t\n2211:\tstatic void mark_reg_unknown(struct bpf_verifier_env *env,\n2212:\t\t\t\t     struct bpf_reg_state *regs, u32 regno)\n2213:\t{\n2214:\t\t__mark_reg_unknown(env, regs + regno);\n2215:\t}\n2216:\t\n2217:\tstatic int __mark_reg_s32_range(struct bpf_verifier_env *env,\n2218:\t\t\t\t\tstruct bpf_reg_state *regs,\n2219:\t\t\t\t\tu32 regno,\n2220:\t\t\t\t\ts32 s32_min,\n2221:\t\t\t\t\ts32 s32_max)\n2222:\t{\n2223:\t\tstruct bpf_reg_state *reg = regs + regno;\n2224:\t\n"
}

69/3 2026/09/15 00:10 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 35534
							output: 20
							thoughts: 2740
						

Thoughts:
**Deep Dive into BPF Verifier and JIT Enhancements**

Okay, let's break this down. My goal is to ensure the integrity and safety of BPF programs, and these changes are all about that.

First, I see a clear focus on preventing out-of-bounds access in the instruction handling, particularly with `LDIMM64`. The introduction of the `size_t insn_cnt` and the check `if (is_ldimm64_insn(insn) && (size_t)insn_idx + 1 >= insn_cnt)` in `bpf_core_patch_insn` is crucial. This directly addresses a KASAN-identified vulnerability where accessing `insn + 1` of an `LDIMM64` instruction could lead to reads/writes beyond the program bounds if it was the last instruction. The `bpf_core_poison_insn` function now carefully poisons both instructions of the `ldimm64` instruction as well. Verifying core relocations *before* adding subprograms and instruction layout verification is a good move to catch issues early. The `!attr->core_relo_cnt` check in `bpf_prepare_btf_info` also makes sense; it likely ensures we don't proceed if core relocations are missing or incomplete.

Next, I see a lot of work to improve signal handling, or rather, to make it more robust within the JIT and fixup process. The changes in `bpf_jit_blind_constants`, `bpf_prog_jit_compile`, `__bpf_prog_select_runtime`, `bpf_rewrite_must_abort`, `bpf_jit_subprogs`, and `bpf_fixup_call_args` are all centered around gracefully handling fatal signals. This is critical. The use of `fatal_signal_pending(current)` and `-EINTR` propagation prevents indefinite stalls or CPU hogging during fixup passes, especially in extremely large BPF programs, which is a good thing to prevent denial of service (DoS) conditions. Aborting fixups and JIT compilation on a fatal signal is the right approach.

Now, the most interesting and important part - the `map_uid` changes. Moving `map_uid` out of the union within `struct bpf_reg_state` is a critical fix. Previously, it was prone to integer comparisons using `memcmp` which could incorrectly identify or mishandle inner map lookups during state comparisons and ID remapping, particularly when comparing two BPF registers, each pointing to an inner map with an ID generated in a different branch. This change ensures proper ID remapping through `idmap`, preventing potential mis-identification of map lookups. This also fixes the verifier soundness bug where packet pointers sharing an ID had different base displacements, which could allow out-of-bounds packet access. The check in `regs_exact` and `regsafe` is vital to ensure that `map_uid` is compared properly during state comparisons and the `id` relations are correctly preserved, which is important for register safety. The tests in `test_spin_lock_fail.c` likely exposed these issues. The `callback_value_lock_identity`, `callback_inner_map_value_lock_identity` tests verify that lock identity in inner maps are preserved as intended.

I need to confirm there is no information leakage to userspace or any issues with uninitialized reads. Based on the rules, it looks like most of these changes are about fixing bugs like out-of-bounds, etc, which are handled by KASAN and standard detectors. However, I have to ensure that all introduced structures are fully initialized.

Overall, it's a well-thought-out set of changes to improve the BPF verifier's robustness, prevent out-of-bounds errors, and improve signal handling. The critical change for the `map_uid` is the most significant. This patch is a good improvement for the verifier.



70/3 2026/09/15 00:10 tool grepper
0m Args:
{
  "Expression": "MAX_CALL_FRAMES"
}

Results:
{
  "Output": "drivers/net/ethernet/netronome/nfp/bpf/verifier.c=698=static unsigned int nfp_bpf_get_stack_usage(struct nfp_prog *nfp_prog)\n--\ndrivers/net/ethernet/netronome/nfp/bpf/verifier.c-701-\tunsigned int max_depth = 0, depth = 0, frame = 0;\ndrivers/net/ethernet/netronome/nfp/bpf/verifier.c:702:\tstruct nfp_insn_meta *ret_insn[MAX_CALL_FRAMES];\ndrivers/net/ethernet/netronome/nfp/bpf/verifier.c:703:\tunsigned short frame_depths[MAX_CALL_FRAMES];\ndrivers/net/ethernet/netronome/nfp/bpf/verifier.c:704:\tunsigned short ret_prog[MAX_CALL_FRAMES];\ndrivers/net/ethernet/netronome/nfp/bpf/verifier.c-705-\tunsigned short idx = meta-\u003esubprog_idx;\n--\ndrivers/net/ethernet/netronome/nfp/bpf/verifier.c-710-\t * prevented by the kernel verifier, this algorithm only needs a local\ndrivers/net/ethernet/netronome/nfp/bpf/verifier.c:711:\t * stack of MAX_CALL_FRAMES to remember callsites.\ndrivers/net/ethernet/netronome/nfp/bpf/verifier.c-712-\t */\n--\ninclude/linux/bpf_verifier.h=348=struct bpf_func_state {\n--\ninclude/linux/bpf_verifier.h-408-\ninclude/linux/bpf_verifier.h:409:#define MAX_CALL_FRAMES 16\ninclude/linux/bpf_verifier.h-410-\n--\ninclude/linux/bpf_verifier.h=423=struct bpf_jmp_history_entry {\n--\ninclude/linux/bpf_verifier.h-439-\ninclude/linux/bpf_verifier.h:440:static_assert(MAX_CALL_FRAMES \u003c= (1 \u003c\u003c 4));\ninclude/linux/bpf_verifier.h-441-static_assert(MAX_BPF_STACK / 8 \u003c= (1 \u003c\u003c 6));\n--\ninclude/linux/bpf_verifier.h-445-#define BPF_ID_MAP_SIZE ((MAX_BPF_REG + MAX_BPF_STACK / BPF_REG_SIZE + \\\ninclude/linux/bpf_verifier.h:446:\t\t\t  MAX_STACK_ARG_SLOTS) * MAX_CALL_FRAMES)\ninclude/linux/bpf_verifier.h-447-struct bpf_verifier_state {\ninclude/linux/bpf_verifier.h-448-\t/* call stack tracking */\ninclude/linux/bpf_verifier.h:449:\tstruct bpf_func_state *frame[MAX_CALL_FRAMES];\ninclude/linux/bpf_verifier.h-450-\tstruct bpf_verifier_state *parent;\n--\ninclude/linux/bpf_verifier.h=846=struct backtrack_state {\n--\ninclude/linux/bpf_verifier.h-848-\tu32 frame;\ninclude/linux/bpf_verifier.h:849:\tu32 reg_masks[MAX_CALL_FRAMES];\ninclude/linux/bpf_verifier.h:850:\tu64 stack_masks[MAX_CALL_FRAMES];\ninclude/linux/bpf_verifier.h:851:\tu8 stack_arg_masks[MAX_CALL_FRAMES];\ninclude/linux/bpf_verifier.h-852-};\n--\ninclude/linux/bpf_verifier.h=874=struct bpf_scc_callchain {\ninclude/linux/bpf_verifier.h-875-\t/* call sites from bpf_verifier_state-\u003eframe[*]-\u003ecallsite leading to this SCC */\ninclude/linux/bpf_verifier.h:876:\tu32 callsites[MAX_CALL_FRAMES - 1];\ninclude/linux/bpf_verifier.h-877-\t/* last frame in a chain is identified by SCC id */\n--\nkernel/bpf/backtrack.c=147=static inline int bt_subprog_enter(struct backtrack_state *bt)\nkernel/bpf/backtrack.c-148-{\nkernel/bpf/backtrack.c:149:\tif (bt-\u003eframe == MAX_CALL_FRAMES - 1) {\nkernel/bpf/backtrack.c-150-\t\tverifier_bug(bt-\u003eenv, \"subprog enter from frame %d\", bt-\u003eframe);\n--\nkernel/bpf/liveness.c=24=struct func_instance {\n--\nkernel/bpf/liveness.c-31-\t/* Per frame, per instruction masks, frames allocated lazily. */\nkernel/bpf/liveness.c:32:\tstruct per_frame_masks *frames[MAX_CALL_FRAMES];\nkernel/bpf/liveness.c-33-\tbool must_write_initialized;\n--\nkernel/bpf/liveness.c=36=struct live_stack_query {\nkernel/bpf/liveness.c:37:\tstruct func_instance *instances[MAX_CALL_FRAMES]; /* valid in range [0..curframe] */\nkernel/bpf/liveness.c:38:\tu32 callsites[MAX_CALL_FRAMES]; /* callsite[i] = insn calling frame i+1 */\nkernel/bpf/liveness.c-39-\tu32 curframe;\n--\nkernel/bpf/liveness.c=1840=static int analyze_subprog(struct bpf_verifier_env *env,\n--\nkernel/bpf/liveness.c-1939-\nkernel/bpf/liveness.c:1940:\t\tif (depth == MAX_CALL_FRAMES - 1) {\nkernel/bpf/liveness.c-1941-\t\t\terr = -EINVAL;\n--\nkernel/bpf/liveness.c=1985=int bpf_compute_subprog_arg_access(struct bpf_verifier_env *env)\nkernel/bpf/liveness.c-1986-{\nkernel/bpf/liveness.c:1987:\tu32 callsites[MAX_CALL_FRAMES] = {};\nkernel/bpf/liveness.c-1988-\tint insn_cnt = env-\u003eprog-\u003elen;\n--\nkernel/bpf/verifier.c=3230=static void mark_indirect_target(struct bpf_verifier_env *env, int idx)\n--\nkernel/bpf/verifier.c-3245-\nkernel/bpf/verifier.c:3246:static_assert(MAX_CALL_FRAMES \u003c= (1 \u003c\u003c LR_FRAMENO_BITS));\nkernel/bpf/verifier.c-3247-static_assert(LINKED_REGS_MAX \u003c (1 \u003c\u003c LR_SIZE_BITS));\n--\nkernel/bpf/verifier.c=5322=static int check_max_stack_depth_subprog(struct bpf_verifier_env *env, int idx,\n--\nkernel/bpf/verifier.c-5470-\t\tframe = bpf_subprog_is_global(env, idx) ? 0 : frame + 1;\nkernel/bpf/verifier.c:5471:\t\tif (frame \u003e= MAX_CALL_FRAMES) {\nkernel/bpf/verifier.c-5472-\t\t\tverbose(env, \"the call stack of %d frames is too deep !\\n\",\n--\nkernel/bpf/verifier.c=9634=static int setup_func_entry(struct bpf_verifier_env *env, int subprog, int callsite,\n--\nkernel/bpf/verifier.c-9640-\nkernel/bpf/verifier.c:9641:\tif (state-\u003ecurframe + 1 \u003e= MAX_CALL_FRAMES) {\nkernel/bpf/verifier.c-9642-\t\tverbose(env, \"the call stack of %d frames is too deep\\n\",\n--\ntools/testing/selftests/bpf/progs/verifier_liveness_exp.c-17- *\ntools/testing/selftests/bpf/progs/verifier_liveness_exp.c:18: * This test chains 8 subprograms (within the MAX_CALL_FRAMES limit).  Each\ntools/testing/selftests/bpf/progs/verifier_liveness_exp.c-19- * intermediate function calls the next one 50 times, each time with a\n"
}

71/3 2026/09/15 00:10 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 41311
							output: 27
							thoughts: 376
						

Thoughts:
**Analyzing `regs_exact` and Frame Number Handling**

Okay, so `MAX_CALL_FRAMES` is 16, which fits perfectly within a `u8` (0 to 15) – that's good from a memory perspective. Now, I'm diving into the `regs_exact` function. Let's see... it uses `memcmp` on `struct bpf_reg_state`. I need to be sure about what `memcmp` actually compares here. It's comparing up to `offsetof(struct bpf_reg_state, id)`. Right, so that's the crucial point: Does this include everything *before* `id`? Yes, it does. Okay, that makes sense.

Now, what comes *after* `id` in the `struct bpf_reg_state` definition? Let me check… ah, there it is. We have `u32 id;`, then `u32 parent_id;`, then `u32 map_uid;`, *then* `u8 frameno;` and finally `bool precise;`.

The important thing now is: are `frameno` or `precise` ever considered in `regs_exact`? Or, more generally, how are they handled in relation to `regs_exact` and `regsafe`? I need to check how these values are used, or *not* used, within those functions. Let's investigate further.



72/3 2026/09/15 00:10 tool grepper
0m Args:
{
  "Expression": "frameno",
  "PathPrefix": "kernel/bpf/"
}

Results:
{
  "Output": "kernel/bpf/diagnostics.c=47=struct bpf_diag_mod_target {\n--\nkernel/bpf/diagnostics.c-57-\t};\nkernel/bpf/diagnostics.c:58:\tu8 frameno;\nkernel/bpf/diagnostics.c-59-\tu8 kind;\n--\nkernel/bpf/diagnostics.c-61-\nkernel/bpf/diagnostics.c:62:static struct bpf_diag_mod_target diag_reg_target(u32 frame_id, u8 frameno, u8 regno)\nkernel/bpf/diagnostics.c-63-{\n--\nkernel/bpf/diagnostics.c-65-\t\t.frame_id = frame_id,\nkernel/bpf/diagnostics.c:66:\t\t.frameno = frameno,\nkernel/bpf/diagnostics.c-67-\t\t.kind = BPF_DIAG_MOD_TARGET_REG,\n--\nkernel/bpf/diagnostics.c-71-\nkernel/bpf/diagnostics.c:72:static struct bpf_diag_mod_target diag_stack_arg_target(u32 frame_id, u8 frameno, u8 slot)\nkernel/bpf/diagnostics.c-73-{\n--\nkernel/bpf/diagnostics.c-75-\t\t.frame_id = frame_id,\nkernel/bpf/diagnostics.c:76:\t\t.frameno = frameno,\nkernel/bpf/diagnostics.c-77-\t\t.kind = BPF_DIAG_MOD_TARGET_STACK_ARG,\n--\nkernel/bpf/diagnostics.c-81-\nkernel/bpf/diagnostics.c:82:static struct bpf_diag_mod_target diag_stack_slot_target(u32 frame_id, u8 frameno, u16 spi)\nkernel/bpf/diagnostics.c-83-{\n--\nkernel/bpf/diagnostics.c-85-\t\t.frame_id = frame_id,\nkernel/bpf/diagnostics.c:86:\t\t.frameno = frameno,\nkernel/bpf/diagnostics.c-87-\t\t.kind = BPF_DIAG_MOD_TARGET_STACK_SLOT,\n--\nkernel/bpf/diagnostics.c-91-\nkernel/bpf/diagnostics.c:92:static struct bpf_diag_mod_target diag_stack_range_target(u32 frame_id, u8 frameno,\nkernel/bpf/diagnostics.c-93-\t\t\t\t\t\t\t  s16 min_off, s16 max_off)\n--\nkernel/bpf/diagnostics.c-96-\t\t.frame_id = frame_id,\nkernel/bpf/diagnostics.c:97:\t\t.frameno = frameno,\nkernel/bpf/diagnostics.c-98-\t\t.kind = BPF_DIAG_MOD_TARGET_STACK_RANGE,\n--\nkernel/bpf/diagnostics.c=154=struct bpf_diag_history_opts {\n--\nkernel/bpf/diagnostics.c-156-\tu32 frame_id;\nkernel/bpf/diagnostics.c:157:\tu32 frameno;\nkernel/bpf/diagnostics.c-158-\tint regno;\n--\nkernel/bpf/diagnostics.c=906=void bpf_diag_register_type(struct bpf_verifier_env *env, u32 insn_idx, int regno,\n--\nkernel/bpf/diagnostics.c-912-\t\t.frame_id = frame-\u003ediag_frame_id,\nkernel/bpf/diagnostics.c:913:\t\t.frameno = frame-\u003eframeno,\nkernel/bpf/diagnostics.c-914-\t\t.regno = regno,\n--\nkernel/bpf/diagnostics.c=995=void bpf_diag_call_type(struct bpf_verifier_env *env, u32 insn_idx, int argno, int regno,\n--\nkernel/bpf/diagnostics.c-1001-\t\t.frame_id = frame-\u003ediag_frame_id,\nkernel/bpf/diagnostics.c:1002:\t\t.frameno = frame-\u003eframeno,\nkernel/bpf/diagnostics.c-1003-\t};\n--\nkernel/bpf/diagnostics.c=1232=void bpf_diag_invalid_deref(struct bpf_verifier_env *env, u32 insn_idx, int regno,\n--\nkernel/bpf/diagnostics.c-1239-\t\t.frame_id = frame-\u003ediag_frame_id,\nkernel/bpf/diagnostics.c:1240:\t\t.frameno = frame-\u003eframeno,\nkernel/bpf/diagnostics.c-1241-\t\t.regno = regno,\n--\nkernel/bpf/diagnostics.c=1299=void bpf_diag_unreadable_reg(struct bpf_verifier_env *env, u32 insn_idx, int regno)\n--\nkernel/bpf/diagnostics.c-1304-\t\t.frame_id = frame-\u003ediag_frame_id,\nkernel/bpf/diagnostics.c:1305:\t\t.frameno = frame-\u003eframeno,\nkernel/bpf/diagnostics.c-1306-\t\t.regno = regno,\n--\nkernel/bpf/diagnostics.c-1312-\nkernel/bpf/diagnostics.c:1313:\ttarget = diag_reg_target(opts.frame_id, opts.frameno, regno);\nkernel/bpf/diagnostics.c-1314-\tfor (i = log ? log-\u003ecnt : 0; i \u003e 0; i--) {\n--\nkernel/bpf/diagnostics.c=1377=void bpf_diag_stack_arg_uninit(struct bpf_verifier_env *env, u32 insn_idx, int nargs,\n--\nkernel/bpf/diagnostics.c-1384-\t\t.frame_id = frame-\u003ediag_frame_id,\nkernel/bpf/diagnostics.c:1385:\t\t.frameno = frame-\u003eframeno,\nkernel/bpf/diagnostics.c-1386-\t\t.stack_arg_slot = stack_arg_slot,\n--\nkernel/bpf/diagnostics.c=1455=static bool diag_mod_insn_origin(struct bpf_verifier_env *env, u32 insn_idx,\n--\nkernel/bpf/diagnostics.c-1464-\t    BPF_OP(insn-\u003ecode) == BPF_MOV \u0026\u0026 BPF_SRC(insn-\u003ecode) == BPF_X) {\nkernel/bpf/diagnostics.c:1465:\t\t*origin = diag_reg_target(target-\u003eframe_id, target-\u003eframeno, insn-\u003esrc_reg);\nkernel/bpf/diagnostics.c-1466-\t\treturn true;\n--\nkernel/bpf/diagnostics.c-1474-\tstate = env-\u003ecur_state-\u003eframe[env-\u003ecur_state-\u003ecurframe];\nkernel/bpf/diagnostics.c:1475:\t*origin = diag_reg_target(state-\u003ediag_frame_id, state-\u003eframeno, insn-\u003esrc_reg);\nkernel/bpf/diagnostics.c-1476-\treturn true;\n--\nkernel/bpf/diagnostics.c=1548=static struct bpf_reg_state *target_to_reg(struct bpf_verifier_env *env,\n--\nkernel/bpf/diagnostics.c-1553-\nkernel/bpf/diagnostics.c:1554:\tstate = target-\u003eframeno \u003c= vstate-\u003ecurframe ? vstate-\u003eframe[target-\u003eframeno] : NULL;\nkernel/bpf/diagnostics.c-1555-\n--\nkernel/bpf/diagnostics.c=1579=static bool reg_to_target(struct bpf_verifier_env *env, const struct bpf_reg_state *reg,\n--\nkernel/bpf/diagnostics.c-1594-\t\tif (addr \u003e= start \u0026\u0026 addr \u003c end) {\nkernel/bpf/diagnostics.c:1595:\t\t\t*target = diag_reg_target(state-\u003ediag_frame_id, state-\u003eframeno,\nkernel/bpf/diagnostics.c-1596-\t\t\t\t\t\t  reg - state-\u003eregs);\n--\nkernel/bpf/diagnostics.c-1602-\t\tif (state-\u003eout_stack_arg_cnt \u0026\u0026 addr \u003e= start \u0026\u0026 addr \u003c end) {\nkernel/bpf/diagnostics.c:1603:\t\t\t*target = diag_stack_arg_target(state-\u003ediag_frame_id, state-\u003eframeno,\nkernel/bpf/diagnostics.c-1604-\t\t\t\t\t\t\treg - state-\u003estack_arg_regs);\n--\nkernel/bpf/diagnostics.c-1612-\t\t\t      sizeof(*state-\u003estack);\nkernel/bpf/diagnostics.c:1613:\t\t\t*target = diag_stack_slot_target(state-\u003ediag_frame_id, state-\u003eframeno, spi);\nkernel/bpf/diagnostics.c-1614-\t\t\treturn true;\n--\nkernel/bpf/diagnostics.c=1666=void bpf_diag_record_scrub_stack(struct bpf_verifier_env *env,\n--\nkernel/bpf/diagnostics.c-1670-\tdiag_record_mod(env, env-\u003einsn_idx,\nkernel/bpf/diagnostics.c:1671:\t\t\tdiag_stack_range_target(state-\u003ediag_frame_id, state-\u003eframeno, min_off, max_off),\nkernel/bpf/diagnostics.c-1672-\t\t\treason, NULL, NULL, NULL);\n--\nkernel/bpf/diagnostics.c=1750=static bool diag_target_matches(const struct bpf_diag_mod_target *event_target,\n--\nkernel/bpf/diagnostics.c-1754-\nkernel/bpf/diagnostics.c:1755:\tif (event_target-\u003eframe_id != target-\u003eframe_id || event_target-\u003eframeno != target-\u003eframeno)\nkernel/bpf/diagnostics.c-1756-\t\treturn false;\n--\nkernel/bpf/diagnostics.c=1780=static void diag_build_lineage(struct bpf_verifier_env *env, struct bpf_diag_log *log,\n--\nkernel/bpf/diagnostics.c-1790-\tif (opts-\u003escope == BPF_DIAG_HISTORY_SCOPE_REG)\nkernel/bpf/diagnostics.c:1791:\t\ttarget = diag_reg_target(opts-\u003eframe_id, opts-\u003eframeno, opts-\u003eregno);\nkernel/bpf/diagnostics.c-1792-\telse if (opts-\u003escope == BPF_DIAG_HISTORY_SCOPE_STACK_ARG)\nkernel/bpf/diagnostics.c:1793:\t\ttarget = diag_stack_arg_target(opts-\u003eframe_id, opts-\u003eframeno,\nkernel/bpf/diagnostics.c-1794-\t\t\t\t\t       opts-\u003estack_arg_slot);\n--\nkernel/bpf/diagnostics.c=1952=void bpf_diag_mem_bounds(struct bpf_verifier_env *env, u32 insn_idx, int regno,\n--\nkernel/bpf/diagnostics.c-1959-\t\t.frame_id = frame-\u003ediag_frame_id,\nkernel/bpf/diagnostics.c:1960:\t\t.frameno = frame-\u003eframeno,\nkernel/bpf/diagnostics.c-1961-\t\t.regno = regno,\n--\nkernel/bpf/liveness.c=101=static struct func_instance *lookup_instance(struct bpf_verifier_env *env,\nkernel/bpf/liveness.c-102-\t\t\t\t\t     struct bpf_verifier_state *st,\nkernel/bpf/liveness.c:103:\t\t\t\t\t     u32 frameno)\nkernel/bpf/liveness.c-104-{\n--\nkernel/bpf/liveness.c-108-\nkernel/bpf/liveness.c:109:\tsubprog_start = env-\u003esubprog_info[st-\u003eframe[frameno]-\u003esubprogno].start;\nkernel/bpf/liveness.c:110:\tcallsite = frameno \u003e 0 ? st-\u003eframe[frameno]-\u003ecallsite : subprog_start;\nkernel/bpf/liveness.c-111-\nkernel/bpf/liveness.c:112:\tfor (depth = frameno; ; depth--) {\nkernel/bpf/liveness.c-113-\t\tkey = depth \u003e 0 ? callsite : subprog_start;\n--\nkernel/bpf/liveness.c=306=static void update_instance(struct bpf_verifier_env *env, struct func_instance *instance)\n--\nkernel/bpf/liveness.c-329-\nkernel/bpf/liveness.c:330:static bool is_live_before(struct func_instance *instance, u32 insn_idx, u32 frameno, u32 half_spi)\nkernel/bpf/liveness.c-331-{\n--\nkernel/bpf/liveness.c-333-\nkernel/bpf/liveness.c:334:\tmasks = get_frame_masks(instance, frameno, insn_idx);\nkernel/bpf/liveness.c-335-\treturn masks \u0026\u0026 spis_test_bit(masks-\u003elive_before, half_spi);\n--\nkernel/bpf/liveness.c=338=int bpf_live_stack_query_init(struct bpf_verifier_env *env, struct bpf_verifier_state *st)\n--\nkernel/bpf/liveness.c-358-\nkernel/bpf/liveness.c:359:bool bpf_stack_slot_alive(struct bpf_verifier_env *env, u32 frameno, u32 half_spi)\nkernel/bpf/liveness.c-360-{\n--\nkernel/bpf/liveness.c-376-\tcur_delta = (int)curframe_instance-\u003edepth - (int)q-\u003ecurframe;\nkernel/bpf/liveness.c:377:\trel = frameno + cur_delta;\nkernel/bpf/liveness.c-378-\tif (rel \u003c= curframe_instance-\u003edepth)\n--\nkernel/bpf/liveness.c-383-\nkernel/bpf/liveness.c:384:\tfor (i = frameno; i \u003c q-\u003ecurframe; i++) {\nkernel/bpf/liveness.c-385-\t\tinstance = q-\u003einstances[i];\n--\nkernel/bpf/liveness.c-387-\t\t\treturn true;\nkernel/bpf/liveness.c:388:\t\t/* Map actual frameno to frame index within this instance */\nkernel/bpf/liveness.c-389-\t\tdelta = (int)instance-\u003edepth - (int)i;\nkernel/bpf/liveness.c:390:\t\trel = frameno + delta;\nkernel/bpf/liveness.c-391-\t\tif (rel \u003e instance-\u003edepth)\n--\nkernel/bpf/log.c=624=static void print_reg_state(struct bpf_verifier_env *env,\n--\nkernel/bpf/log.c-642-\tif (t == PTR_TO_STACK) {\nkernel/bpf/log.c:643:\t\tif (state-\u003eframeno != reg-\u003eframeno)\nkernel/bpf/log.c:644:\t\t\tverbose(env, \"[%d]\", reg-\u003eframeno);\nkernel/bpf/log.c-645-\t\tif (tnum_is_const(reg-\u003evar_off)) {\n--\nkernel/bpf/log.c=700=void print_verifier_state(struct bpf_verifier_env *env, const struct bpf_verifier_state *vstate,\nkernel/bpf/log.c:701:\t\t\t  u32 frameno, bool print_all)\nkernel/bpf/log.c-702-{\nkernel/bpf/log.c:703:\tconst struct bpf_func_state *state = vstate-\u003eframe[frameno];\nkernel/bpf/log.c-704-\tconst struct bpf_reg_state *reg;\n--\nkernel/bpf/log.c-706-\nkernel/bpf/log.c:707:\tif (state-\u003eframeno)\nkernel/bpf/log.c:708:\t\tverbose(env, \" frame%d:\", state-\u003eframeno);\nkernel/bpf/log.c-709-\tfor (i = 0; i \u003c MAX_BPF_REG; i++) {\n--\nkernel/bpf/log.c=803=void print_insn_state(struct bpf_verifier_env *env, const struct bpf_verifier_state *vstate,\nkernel/bpf/log.c:804:\t\t      u32 frameno)\nkernel/bpf/log.c-805-{\n--\nkernel/bpf/log.c-812-\t}\nkernel/bpf/log.c:813:\tprint_verifier_state(env, vstate, frameno, false);\nkernel/bpf/log.c-814-}\n--\nkernel/bpf/states.c=505=static bool regsafe(struct bpf_verifier_env *env, struct bpf_reg_state *rold,\n--\nkernel/bpf/states.c-649-\t\t */\nkernel/bpf/states.c:650:\t\treturn regs_exact(rold, rcur, idmap) \u0026\u0026 rold-\u003eframeno == rcur-\u003eframeno;\nkernel/bpf/states.c-651-\tcase PTR_TO_ARENA:\n--\nkernel/bpf/states.c=1116=static bool states_maybe_looping(struct bpf_verifier_state *old,\n--\nkernel/bpf/states.c-1128-\t\tif (memcmp(\u0026fold-\u003eregs[i], \u0026fcur-\u003eregs[i],\nkernel/bpf/states.c:1129:\t\t\t   offsetof(struct bpf_reg_state, frameno)))\nkernel/bpf/states.c-1130-\t\t\treturn false;\n--\nkernel/bpf/verifier.c=2273=static void init_reg_state(struct bpf_verifier_env *env,\n--\nkernel/bpf/verifier.c-2285-\tmark_reg_known_zero(env, regs, BPF_REG_FP);\nkernel/bpf/verifier.c:2286:\tregs[BPF_REG_FP].frameno = state-\u003eframeno;\nkernel/bpf/verifier.c-2287-}\n--\nkernel/bpf/verifier.c=2298=static void init_func_state(struct bpf_verifier_env *env,\nkernel/bpf/verifier.c-2299-\t\t\t    struct bpf_func_state *state,\nkernel/bpf/verifier.c:2300:\t\t\t    int callsite, int frameno, int subprogno)\nkernel/bpf/verifier.c-2301-{\nkernel/bpf/verifier.c-2302-\tstate-\u003ecallsite = callsite;\nkernel/bpf/verifier.c:2303:\tstate-\u003eframeno = frameno;\nkernel/bpf/verifier.c-2304-\tbpf_diag_init_frame(env, state);\n--\nkernel/bpf/verifier.c=2312=static struct bpf_verifier_state *push_async_cb(struct bpf_verifier_env *env,\n--\nkernel/bpf/verifier.c-2347-\t\t\tBPF_MAIN_FUNC /* callsite */,\nkernel/bpf/verifier.c:2348:\t\t\t0 /* frameno within this callchain */,\nkernel/bpf/verifier.c-2349-\t\t\tsubprog /* subprog number within this prog */);\n--\nkernel/bpf/verifier.c=3250=struct linked_reg {\nkernel/bpf/verifier.c:3251:\tu8 frameno;\nkernel/bpf/verifier.c-3252-\tunion {\n--\nkernel/bpf/verifier.c=3264=static struct linked_reg *linked_regs_push(struct linked_regs *s)\n--\nkernel/bpf/verifier.c-3275- * Pack one history entry for linked registers as 11 bits in the following format:\nkernel/bpf/verifier.c:3276: * - 4-bits frameno\nkernel/bpf/verifier.c-3277- * - 6-bits spi_or_reg\n--\nkernel/bpf/verifier.c=3280=static u64 linked_regs_pack(struct linked_regs *s)\n--\nkernel/bpf/verifier.c-3288-\nkernel/bpf/verifier.c:3289:\t\ttmp |= e-\u003eframeno;\nkernel/bpf/verifier.c-3290-\t\ttmp |= e-\u003espi \u003c\u003c LR_SPI_OFF;\n--\nkernel/bpf/verifier.c=3301=static void linked_regs_unpack(u64 val, struct linked_regs *s)\n--\nkernel/bpf/verifier.c-3310-\nkernel/bpf/verifier.c:3311:\t\te-\u003eframeno =  val \u0026 LR_FRAMENO_MASK;\nkernel/bpf/verifier.c-3312-\t\te-\u003espi     = (val \u003e\u003e LR_SPI_OFF) \u0026 LR_SPI_MASK;\n--\nkernel/bpf/verifier.c=3350=void bpf_bt_sync_linked_regs(struct backtrack_state *bt, struct bpf_jmp_history_entry *hist)\n--\nkernel/bpf/verifier.c-3362-\nkernel/bpf/verifier.c:3363:\t\tif ((e-\u003eis_reg \u0026\u0026 bt_is_frame_reg_set(bt, e-\u003eframeno, e-\u003eregno)) ||\nkernel/bpf/verifier.c:3364:\t\t    (!e-\u003eis_reg \u0026\u0026 bt_is_frame_slot_set(bt, e-\u003eframeno, e-\u003espi))) {\nkernel/bpf/verifier.c-3365-\t\t\tsome_precise = true;\n--\nkernel/bpf/verifier.c-3376-\t\tif (e-\u003eis_reg)\nkernel/bpf/verifier.c:3377:\t\t\tbpf_bt_set_frame_reg(bt, e-\u003eframeno, e-\u003eregno);\nkernel/bpf/verifier.c-3378-\t\telse\nkernel/bpf/verifier.c:3379:\t\t\tbpf_bt_set_frame_slot(bt, e-\u003eframeno, e-\u003espi);\nkernel/bpf/verifier.c-3380-\t}\n--\nkernel/bpf/verifier.c=3521=static int check_stack_write_fixed_off(struct bpf_verifier_env *env,\n--\nkernel/bpf/verifier.c-3531-\tint insn_flags = INSN_F_STACK_ACCESS;\nkernel/bpf/verifier.c:3532:\tint hist_spi = spi, hist_frame = state-\u003eframeno;\nkernel/bpf/verifier.c-3533-\n--\nkernel/bpf/verifier.c=3796=static int mark_reg_stack_read(struct bpf_verifier_env *env,\n--\nkernel/bpf/verifier.c-3830-\t\tif (zero_spill_mask) {\nkernel/bpf/verifier.c:3831:\t\t\tbpf_bt_set_frame_slot_mask(\u0026env-\u003ebt, ptr_state-\u003eframeno, zero_spill_mask);\nkernel/bpf/verifier.c-3832-\t\t\treturn mark_chain_precision_batch(env, env-\u003ecur_state);\n--\nkernel/bpf/verifier.c=3866=static int check_stack_read_fixed_off(struct bpf_verifier_env *env,\n--\nkernel/bpf/verifier.c-3877-\tint insn_flags = INSN_F_STACK_ACCESS;\nkernel/bpf/verifier.c:3878:\tint hist_spi = spi, hist_frame = reg_state-\u003eframeno;\nkernel/bpf/verifier.c-3879-\n--\nkernel/bpf/verifier.c=4245=static int mark_stack_arg_precision(struct bpf_verifier_env *env, int arg_idx)\n--\nkernel/bpf/verifier.c-4249-\nkernel/bpf/verifier.c:4250:\tbt_set_frame_stack_arg_slot(\u0026env-\u003ebt, caller-\u003eframeno, spi);\nkernel/bpf/verifier.c-4251-\treturn mark_chain_precision_batch(env, env-\u003ecur_state);\n--\nkernel/bpf/verifier.c=7748=static int process_iter_arg(struct bpf_verifier_env *env, struct bpf_reg_state *reg, argno_t argno, int insn_idx,\n--\nkernel/bpf/verifier.c-7841-\t\tmeta-\u003eiter.spi = spi;\nkernel/bpf/verifier.c:7842:\t\tmeta-\u003eiter.frameno = reg-\u003eframeno;\nkernel/bpf/verifier.c-7843-\t\tupdate_ref_obj(\u0026meta-\u003eref_obj, \u0026state-\u003estack[spi].spilled_ptr);\n--\nkernel/bpf/verifier.c=7935=static struct bpf_reg_state *get_iter_from_state(struct bpf_verifier_state *cur_st,\n--\nkernel/bpf/verifier.c-7937-{\nkernel/bpf/verifier.c:7938:\tint iter_frameno = meta-\u003eiter.frameno;\nkernel/bpf/verifier.c-7939-\tint iter_spi = meta-\u003eiter.spi;\nkernel/bpf/verifier.c-7940-\nkernel/bpf/verifier.c:7941:\treturn \u0026cur_st-\u003eframe[iter_frameno]-\u003estack[iter_spi].spilled_ptr;\nkernel/bpf/verifier.c-7942-}\n--\nkernel/bpf/verifier.c=8638=static int get_constant_map_key(struct bpf_verifier_env *env,\n--\nkernel/bpf/verifier.c-8688-\t */\nkernel/bpf/verifier.c:8689:\tbpf_bt_set_frame_slot(\u0026env-\u003ebt, key-\u003eframeno, spi);\nkernel/bpf/verifier.c-8690-\terr = mark_chain_precision_batch(env, env-\u003ecur_state);\n--\nkernel/bpf/verifier.c=9634=static int setup_func_entry(struct bpf_verifier_env *env, int subprog, int callsite,\n--\nkernel/bpf/verifier.c-9664-\t\t\tcallsite,\nkernel/bpf/verifier.c:9665:\t\t\tstate-\u003ecurframe + 1 /* frameno within this callchain */,\nkernel/bpf/verifier.c-9666-\t\t\tsubprog /* subprog number within this prog */);\n--\nkernel/bpf/verifier.c=9916=static int check_func_call(struct bpf_verifier_env *env, struct bpf_insn *insn,\n--\nkernel/bpf/verifier.c-10024-\t\tverbose(env, \"caller:\\n\");\nkernel/bpf/verifier.c:10025:\t\tprint_verifier_state(env, state, caller-\u003eframeno, true);\nkernel/bpf/verifier.c-10026-\t\tverbose(env, \"callee:\\n\");\n--\nkernel/bpf/verifier.c=10351=static int prepare_func_exit(struct bpf_verifier_env *env, int *insn_idx)\n--\nkernel/bpf/verifier.c-10413-\t\tverbose(env, \"returning from callee:\\n\");\nkernel/bpf/verifier.c:10414:\t\tprint_verifier_state(env, state, callee-\u003eframeno, true);\nkernel/bpf/verifier.c-10415-\t\tverbose(env, \"to caller at %d:\\n\", *insn_idx);\nkernel/bpf/verifier.c:10416:\t\tprint_verifier_state(env, state, caller-\u003eframeno, true);\nkernel/bpf/verifier.c-10417-\t}\n--\nkernel/bpf/verifier.c=10583=static int check_reference_leak(struct bpf_verifier_env *env, bool exception_exit)\n--\nkernel/bpf/verifier.c-10590-\nkernel/bpf/verifier.c:10591:\tif (!exception_exit \u0026\u0026 cur_func(env)-\u003eframeno)\nkernel/bpf/verifier.c-10592-\t\treturn 0;\n--\nkernel/bpf/verifier.c=16817=static void __collect_linked_regs(struct linked_regs *reg_set, struct bpf_reg_state *reg,\nkernel/bpf/verifier.c:16818:\t\t\t\t  u32 id, u32 frameno, u32 spi_or_reg, bool is_reg)\nkernel/bpf/verifier.c-16819-{\n--\nkernel/bpf/verifier.c-16826-\tif (e) {\nkernel/bpf/verifier.c:16827:\t\te-\u003eframeno = frameno;\nkernel/bpf/verifier.c-16828-\t\te-\u003eis_reg = is_reg;\n--\nkernel/bpf/verifier.c=16872=static void sync_linked_regs(struct bpf_verifier_env *env, struct bpf_verifier_state *vstate,\n--\nkernel/bpf/verifier.c-16881-\t\te = \u0026linked_regs-\u003eentries[i];\nkernel/bpf/verifier.c:16882:\t\treg = e-\u003eis_reg ? \u0026vstate-\u003eframe[e-\u003eframeno]-\u003eregs[e-\u003eregno]\nkernel/bpf/verifier.c:16883:\t\t\t\t: \u0026vstate-\u003eframe[e-\u003eframeno]-\u003estack[e-\u003espi].spilled_ptr;\nkernel/bpf/verifier.c-16884-\t\tif (reg-\u003etype != SCALAR_VALUE || reg == known_reg)\n--\nkernel/bpf/verifier.c=19455=static int do_check_common(struct bpf_verifier_env *env, int subprog)\n--\nkernel/bpf/verifier.c-19482-\t\t\tBPF_MAIN_FUNC /* callsite */,\nkernel/bpf/verifier.c:19483:\t\t\t0 /* frameno */,\nkernel/bpf/verifier.c-19484-\t\t\tsubprog);\n"
}

73/3 2026/09/15 00:10 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 49836
							output: 37
							thoughts: 164
						

Thoughts:
**Analyzing Potential BPF Loop Detection**

Okay, so I'm diving into the `kernel/bpf/states.c` file again. Specifically, I'm focusing on the `states_maybe_looping` function. I need to understand this part of the BPF verifier in detail. Let me just glance at this bit of code, looks like it's in the loop:

```c
	for (i = 0; i < MAX_BPF_REG; i++) {
		if (memcmp(&fold->regs[i], &fcur->regs[i],
			   offsetof(struct bpf_reg_state, frameno)))
			return false;
```

Hmm... I see it's comparing register states between two verification states. The `memcmp` call is the key here. It seems to be checking if the register states are identical up to the `frameno` field. *Wait a second...* I need to focus. I'm going to look closer at line 1128 and reread the function to ensure I understand how the loop is implemented. I need to be sure that this comparison is working correctly and is as efficient as it can be.



74/3 2026/09/15 00:10 tool read-file
0m Args:
{
  "File": "kernel/bpf/states.c",
  "FirstLine": 1115,
  "LineCount": 35
}

Results:
{
  "Contents": "1115:\t\n1116:\tstatic bool states_maybe_looping(struct bpf_verifier_state *old,\n1117:\t\t\t\t\t struct bpf_verifier_state *cur)\n1118:\t{\n1119:\t\tstruct bpf_func_state *fold, *fcur;\n1120:\t\tint i, fr = cur-\u003ecurframe;\n1121:\t\n1122:\t\tif (old-\u003ecurframe != fr)\n1123:\t\t\treturn false;\n1124:\t\n1125:\t\tfold = old-\u003eframe[fr];\n1126:\t\tfcur = cur-\u003eframe[fr];\n1127:\t\tfor (i = 0; i \u003c MAX_BPF_REG; i++)\n1128:\t\t\tif (memcmp(\u0026fold-\u003eregs[i], \u0026fcur-\u003eregs[i],\n1129:\t\t\t\t   offsetof(struct bpf_reg_state, frameno)))\n1130:\t\t\t\treturn false;\n1131:\t\treturn true;\n1132:\t}\n1133:\t\n1134:\t/* is_state_visited() handles iter_next() (see process_iter_next_call() for\n1135:\t * terminology) calls specially: as opposed to bounded BPF loops, it *expects*\n1136:\t * states to match, which otherwise would look like an infinite loop. So while\n1137:\t * iter_next() calls are taken care of, we still need to be careful and\n1138:\t * prevent erroneous and too eager declaration of \"infinite loop\", when\n1139:\t * iterators are involved.\n1140:\t *\n1141:\t * Here's a situation in pseudo-BPF assembly form:\n1142:\t *\n1143:\t *   0: again:                          ; set up iter_next() call args\n1144:\t *   1:   r1 = \u0026it                      ; \u003cCHECKPOINT HERE\u003e\n1145:\t *   2:   call bpf_iter_num_next        ; this is iter_next() call\n1146:\t *   3:   if r0 == 0 goto done\n1147:\t *   4:   ... something useful here ...\n1148:\t *   5:   goto again                    ; another iteration\n1149:\t *   6: done:\n"
}

75/3 2026/09/15 00:10 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 50900
							output: 33
							thoughts: 534
						

Thoughts:
**Analyzing Potential Side Effects of a BPF Patch**

Okay, so I'm looking at this BPF code, specifically the change related to `states_maybe_looping` and the `struct bpf_reg_state`. My initial thought is to really nail down the subtle changes. Before, the `memcmp` in `states_maybe_looping` was comparing up to `frameno`, which followed `parent_id`. Now, `map_uid` has been inserted *before* `frameno`. This is a crucial detail because of how memory comparisons like `memcmp` work.

The critical thing is to verify if there's any unintentional consequence to the addition of `map_uid` being included in the memory comparison. I need to make sure I understand the memory layout precisely. `parent_id` is a `u32` (4 bytes), and `map_uid` is also a `u32`. This means `map_uid` is naturally 4-byte aligned. Crucially, `frameno` is only a `u8` (1 byte). So, is there padding between `map_uid` and `frameno`? No! They are adjacent.

This is where the potential for a subtle bug might exist. `states_maybe_looping` is now comparing memory that *includes* `map_uid` where before it didn't. However, the entire `bpf_reg_state` is zero-initialized anyway, so the values shouldn't be random. That said, I need to trace how `map_uid` is populated relative to the comparison. That would be the crucial thing here.

My next step is to examine the error handling in `__bpf_prog_select_runtime`. I need to see how the code handles cases where JIT compilation fails. Specifically, the snippet from `kernel/bpf/core.c`: I notice that when JIT compilation fails (`IS_ERR(jit_prog)`), it returns the original `fp` pointer. Importantly, the `bpf_prog_jit_attempt_done` function may be called with a NULL `fp`, so I need to make sure that the returned `fp` is always a valid pointer, even if there's a JIT compilation error. I'm going to track calls to these functions to better understand how things are connected.



76/3 2026/09/15 00:10 tool grepper
0m Args:
{
  "Expression": "bpf_prog_select_runtime",
  "PathPrefix": "kernel/bpf/"
}

Results:
{
  "Output": "kernel/bpf/core.c=2631=static struct bpf_prog *bpf_prog_jit_compile(struct bpf_verifier_env *env, struct bpf_prog *prog)\n--\nkernel/bpf/core.c-2664-\nkernel/bpf/core.c:2665:struct bpf_prog *__bpf_prog_select_runtime(struct bpf_verifier_env *env, struct bpf_prog *fp,\nkernel/bpf/core.c-2666-\t\t\t\t\t   int *err)\n--\nkernel/bpf/core.c-2724-/**\nkernel/bpf/core.c:2725: *\tbpf_prog_select_runtime - select exec runtime for BPF program\nkernel/bpf/core.c-2726- *\t@fp: bpf_prog populated with BPF program\n--\nkernel/bpf/core.c-2734- */\nkernel/bpf/core.c:2735:struct bpf_prog *bpf_prog_select_runtime(struct bpf_prog *fp, int *err)\nkernel/bpf/core.c-2736-{\nkernel/bpf/core.c:2737:\treturn __bpf_prog_select_runtime(NULL, fp, err);\nkernel/bpf/core.c-2738-}\nkernel/bpf/core.c:2739:EXPORT_SYMBOL_GPL(bpf_prog_select_runtime);\nkernel/bpf/core.c-2740-\n--\nkernel/bpf/verifier.c=21163=int bpf_check(struct bpf_prog **prog, union bpf_attr *attr, bpfptr_t uattr,\n--\nkernel/bpf/verifier.c-21462-\nkernel/bpf/verifier.c:21463:\tenv-\u003eprog = __bpf_prog_select_runtime(env, env-\u003eprog, \u0026ret);\nkernel/bpf/verifier.c-21464-\n"
}

77/3 2026/09/15 00:10 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 52488
							output: 38
							thoughts: 21
						

Thoughts:
Here's my attempt at summarizing the thought process, tailored for an expert audience:

**Analyzing the `bpf_check` Caller at Line 21462**

Okay, so I'm digging into this BPF code again. The immediate focus is around `bpf_check` and I need to understand its call stack. Specifically, I'm tracing execution and pinpointing the calling context around line 21462. This suggests a potentially critical point, either a specific check being performed, or perhaps the entry to the BPF verifier in a certain scenario. The line number is important because it could be a specific function call, code block, or variable access within a larger structure. I'm already formulating hypotheses: is it an input validation check, a resource limit constraint, or something else entirely? Time to dig in and understand the surrounding context, and perhaps instrument that section to gather live data.



78/3 2026/09/15 00:10 tool read-file
0m Args:
{
  "File": "kernel/bpf/verifier.c",
  "FirstLine": 21455,
  "LineCount": 25
}

Results:
{
  "Contents": "21455:\t\tadjust_btf_func(env);\n21456:\t\n21457:\t\t/* extension progs temporarily inherit the attach_type of their targets\n21458:\t\t   for verification purposes, so set it back to zero before returning\n21459:\t\t */\n21460:\t\tif (env-\u003eprog-\u003etype == BPF_PROG_TYPE_EXT)\n21461:\t\t\tenv-\u003eprog-\u003eexpected_attach_type = 0;\n21462:\t\n21463:\t\tenv-\u003eprog = __bpf_prog_select_runtime(env, env-\u003eprog, \u0026ret);\n21464:\t\n21465:\terr_release_maps:\n21466:\t\tif (ret)\n21467:\t\t\trelease_insn_arrays(env);\n21468:\t\tif (!env-\u003eprog-\u003eaux-\u003eused_maps)\n21469:\t\t\t/* if we didn't copy map pointers into bpf_prog_info, release\n21470:\t\t\t * them now. Otherwise free_used_maps() will release them.\n21471:\t\t\t */\n21472:\t\t\trelease_maps(env);\n21473:\t\tif (!env-\u003eprog-\u003eaux-\u003eused_btfs)\n21474:\t\t\trelease_btfs(env);\n21475:\t\n21476:\t\t*prog = env-\u003eprog;\n21477:\t\n21478:\t\tmodule_put(env-\u003eattach_btf_mod);\n21479:\t\tif (!is_priv)\n"
}

79/3 2026/09/15 00:10 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 53160
							output: 35
							thoughts: 177
						

Thoughts:
**Investigating Potential Null Pointer Issues in BPF Patching**

Alright, let's dive into this. I'm looking at `kernel/bpf/fixups.c`, specifically the `bpf_patch_insn_data` function. The code itself seems straightforward enough; it's designed to patch instructions within a BPF program. I see the function signature, and the basic setup, including the `bpf_rewrite_must_abort()` check, which is good. But something immediately sparks my attention: what happens if `bpf_patch_insn_data` actually returns `NULL`? I know this function is crucial for program modification, and a `NULL` return would signify a failure, I assume, but how is this failure handled up the stack? I'm going to quickly shift my focus and start examining the callers of this function to see what checks, or lack thereof, are in place to handle the scenario where `bpf_patch_insn_data` might return `NULL`. We can't afford any missed checks here.



80/3 2026/09/15 00:10 tool grepper
0m Args:
{
  "Expression": "bpf_patch_insn_data\\(",
  "PathPrefix": "kernel/bpf/"
}

Results:
{
  "Output": "kernel/bpf/core.c=1563=struct bpf_prog *bpf_jit_blind_constants(struct bpf_verifier_env *env, struct bpf_prog *prog)\n--\nkernel/bpf/core.c-1577-\nkernel/bpf/core.c:1578:\t/* make sure bpf_patch_insn_data() patches the correct prog */\nkernel/bpf/core.c-1579-\tif (env)\n--\nkernel/bpf/core.c-1609-\t\tif (env)\nkernel/bpf/core.c:1610:\t\t\ttmp = bpf_patch_insn_data(env, i, insn_buff, rewritten);\nkernel/bpf/core.c-1611-\t\telse\n--\nkernel/bpf/fixups.c=315=static bool bpf_rewrite_must_abort(void)\n--\nkernel/bpf/fixups.c-322-\nkernel/bpf/fixups.c:323:struct bpf_prog *bpf_patch_insn_data(struct bpf_verifier_env *env, u32 off,\nkernel/bpf/fixups.c-324-\t\t\t\t     const struct bpf_insn *patch, u32 len)\n--\nkernel/bpf/fixups.c=664=int bpf_opt_subreg_zext_lo32_rnd_hi32(struct bpf_verifier_env *env,\n--\nkernel/bpf/fixups.c-748-apply_patch_buffer:\nkernel/bpf/fixups.c:749:\t\tnew_prog = bpf_patch_insn_data(env, adj_idx, patch, patch_len);\nkernel/bpf/fixups.c-750-\t\tif (!new_prog)\n--\nkernel/bpf/fixups.c=766=int bpf_convert_ctx_accesses(struct bpf_verifier_env *env)\n--\nkernel/bpf/fixups.c-793-\t\t\tinsn_buf[cnt++] = env-\u003eprog-\u003einsnsi[0];\nkernel/bpf/fixups.c:794:\t\t\tnew_prog = bpf_patch_insn_data(env, 0, insn_buf, cnt);\nkernel/bpf/fixups.c-795-\t\t\tif (!new_prog)\n--\nkernel/bpf/fixups.c-816-\t\t} else if (cnt) {\nkernel/bpf/fixups.c:817:\t\t\tnew_prog = bpf_patch_insn_data(env, 0, insn_buf, cnt);\nkernel/bpf/fixups.c-818-\t\t\tif (!new_prog)\n--\nkernel/bpf/fixups.c-849-\t\t\tcnt = patch - insn_buf;\nkernel/bpf/fixups.c:850:\t\t\tnew_prog = bpf_patch_insn_data(env, i + delta, insn_buf, cnt);\nkernel/bpf/fixups.c-851-\t\t\tif (!new_prog)\n--\nkernel/bpf/fixups.c-922-\t\t\tcnt = patch - insn_buf;\nkernel/bpf/fixups.c:923:\t\t\tnew_prog = bpf_patch_insn_data(env, i + delta, insn_buf, cnt);\nkernel/bpf/fixups.c-924-\t\t\tif (!new_prog)\n--\nkernel/bpf/fixups.c-1056-patch_insn_buf:\nkernel/bpf/fixups.c:1057:\t\tnew_prog = bpf_patch_insn_data(env, i + delta, insn_buf, cnt);\nkernel/bpf/fixups.c-1058-\t\tif (!new_prog)\n--\nkernel/bpf/fixups.c=1504=static int add_hidden_subprog(struct bpf_verifier_env *env, struct bpf_insn *patch, int len)\n--\nkernel/bpf/fixups.c-1518-\t */\nkernel/bpf/fixups.c:1519:\tprog = bpf_patch_insn_data(env, env-\u003eprog-\u003elen - 1, patch, len);\nkernel/bpf/fixups.c-1520-\tif (!prog)\n--\nkernel/bpf/fixups.c=1533=int bpf_do_misc_fixups(struct bpf_verifier_env *env)\n--\nkernel/bpf/fixups.c-1600-\nkernel/bpf/fixups.c:1601:\t\t\tnew_prog = bpf_patch_insn_data(env, i + delta, insn_buf, cnt);\nkernel/bpf/fixups.c-1602-\t\t\tif (!new_prog)\n--\nkernel/bpf/fixups.c-1691-\nkernel/bpf/fixups.c:1692:\t\t\tnew_prog = bpf_patch_insn_data(env, i + delta, insn_buf, cnt);\nkernel/bpf/fixups.c-1693-\t\t\tif (!new_prog)\n--\nkernel/bpf/fixups.c-1721-\t\t\tcnt = patch - insn_buf;\nkernel/bpf/fixups.c:1722:\t\t\tnew_prog = bpf_patch_insn_data(env, i + delta, insn_buf, cnt);\nkernel/bpf/fixups.c-1723-\t\t\tif (!new_prog)\n--\nkernel/bpf/fixups.c-1741-\nkernel/bpf/fixups.c:1742:\t\t\tnew_prog = bpf_patch_insn_data(env, i + delta, insn_buf, cnt);\nkernel/bpf/fixups.c-1743-\t\t\tif (!new_prog)\n--\nkernel/bpf/fixups.c-1794-\nkernel/bpf/fixups.c:1795:\t\t\tnew_prog = bpf_patch_insn_data(env, i + delta, insn_buf, cnt);\nkernel/bpf/fixups.c-1796-\t\t\tif (!new_prog)\n--\nkernel/bpf/fixups.c-1839-\nkernel/bpf/fixups.c:1840:\t\t\tnew_prog = bpf_patch_insn_data(env, i + delta, insn_buf, cnt);\nkernel/bpf/fixups.c-1841-\t\t\tif (!new_prog)\n--\nkernel/bpf/fixups.c-1860-\nkernel/bpf/fixups.c:1861:\t\t\tnew_prog = bpf_patch_insn_data(env, i + delta, insn_buf, cnt);\nkernel/bpf/fixups.c-1862-\t\t\tif (!new_prog)\n--\nkernel/bpf/fixups.c-1887-\t\t\t * with that same half + mov64_percpu_reg insn.\nkernel/bpf/fixups.c:1888:\t\t\t * All because bpf_patch_insn_data() can only\nkernel/bpf/fixups.c-1889-\t\t\t * replace one 8-byte insn, which does not work\n--\nkernel/bpf/fixups.c-1897-\t\t\ti++;\nkernel/bpf/fixups.c:1898:\t\t\tnew_prog = bpf_patch_insn_data(env, i + delta, insn_buf, cnt);\nkernel/bpf/fixups.c-1899-\t\t\tif (!new_prog)\n--\nkernel/bpf/fixups.c-1918-\nkernel/bpf/fixups.c:1919:\t\t\tnew_prog = bpf_patch_insn_data(env, i + delta, insn_buf, cnt);\nkernel/bpf/fixups.c-1920-\t\t\tif (!new_prog)\n--\nkernel/bpf/fixups.c-2005-\t\t\tcnt = 3;\nkernel/bpf/fixups.c:2006:\t\t\tnew_prog = bpf_patch_insn_data(env, i + delta, insn_buf, cnt);\nkernel/bpf/fixups.c-2007-\t\t\tif (!new_prog)\n--\nkernel/bpf/fixups.c-2038-\nkernel/bpf/fixups.c:2039:\t\t\tnew_prog = bpf_patch_insn_data(env, i + delta, insn_buf, cnt);\nkernel/bpf/fixups.c-2040-\t\t\tif (!new_prog)\n--\nkernel/bpf/fixups.c-2057-\nkernel/bpf/fixups.c:2058:\t\t\tnew_prog = bpf_patch_insn_data(env, i + delta, insn_buf, cnt);\nkernel/bpf/fixups.c-2059-\t\t\tif (!new_prog)\n--\nkernel/bpf/fixups.c-2100-\nkernel/bpf/fixups.c:2101:\t\t\t\tnew_prog = bpf_patch_insn_data(env, i + delta,\nkernel/bpf/fixups.c-2102-\t\t\t\t\t\t\t       insn_buf, cnt);\n--\nkernel/bpf/fixups.c-2183-\nkernel/bpf/fixups.c:2184:\t\t\tnew_prog = bpf_patch_insn_data(env, i + delta, insn_buf,\nkernel/bpf/fixups.c-2185-\t\t\t\t\t\t       cnt);\n--\nkernel/bpf/fixups.c-2213-#endif\nkernel/bpf/fixups.c:2214:\t\t\tnew_prog = bpf_patch_insn_data(env, i + delta, insn_buf, cnt);\nkernel/bpf/fixups.c-2215-\t\t\tif (!new_prog)\n--\nkernel/bpf/fixups.c-2232-\nkernel/bpf/fixups.c:2233:\t\t\tnew_prog = bpf_patch_insn_data(env, i + delta, insn_buf, cnt);\nkernel/bpf/fixups.c-2234-\t\t\tif (!new_prog)\n--\nkernel/bpf/fixups.c-2266-\nkernel/bpf/fixups.c:2267:\t\t\tnew_prog = bpf_patch_insn_data(env, i + delta, insn_buf, cnt);\nkernel/bpf/fixups.c-2268-\t\t\tif (!new_prog)\n--\nkernel/bpf/fixups.c-2298-\nkernel/bpf/fixups.c:2299:\t\t\tnew_prog = bpf_patch_insn_data(env, i + delta, insn_buf, cnt);\nkernel/bpf/fixups.c-2300-\t\t\tif (!new_prog)\n--\nkernel/bpf/fixups.c-2324-\nkernel/bpf/fixups.c:2325:\t\t\tnew_prog = bpf_patch_insn_data(env, i + delta, insn_buf, cnt);\nkernel/bpf/fixups.c-2326-\t\t\tif (!new_prog)\n--\nkernel/bpf/fixups.c-2340-\nkernel/bpf/fixups.c:2341:\t\t\tnew_prog = bpf_patch_insn_data(env, i + delta, insn_buf, 1);\nkernel/bpf/fixups.c-2342-\t\t\tif (!new_prog)\n--\nkernel/bpf/fixups.c-2395-\nkernel/bpf/fixups.c:2396:\t\t\tnew_prog = bpf_patch_insn_data(env, i + delta, insn_buf, cnt);\nkernel/bpf/fixups.c-2397-\t\t\tif (!new_prog)\n--\nkernel/bpf/fixups.c-2413-\nkernel/bpf/fixups.c:2414:\t\t\tnew_prog = bpf_patch_insn_data(env, i + delta, insn_buf, cnt);\nkernel/bpf/fixups.c-2415-\t\t\tif (!new_prog)\n--\nkernel/bpf/fixups.c-2481-\nkernel/bpf/fixups.c:2482:\t\tnew_prog = bpf_patch_insn_data(env, subprog_start, insn_buf, cnt);\nkernel/bpf/fixups.c-2483-\t\tif (!new_prog)\n--\nkernel/bpf/fixups.c-2489-\t\t * to insn after BPF_ST that inits may_goto count.\nkernel/bpf/fixups.c:2490:\t\t * Adjustment will succeed because bpf_patch_insn_data() didn't fail.\nkernel/bpf/fixups.c-2491-\t\t */\n--\nkernel/bpf/fixups.c=2519=static struct bpf_prog *inline_bpf_loop(struct bpf_verifier_env *env,\n--\nkernel/bpf/fixups.c-2580-\t*total_cnt = cnt;\nkernel/bpf/fixups.c:2581:\tnew_prog = bpf_patch_insn_data(env, position, insn_buf, cnt);\nkernel/bpf/fixups.c-2582-\tif (!new_prog)\n"
}

81/3 2026/09/15 00:10 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 57033
							output: 39
							thoughts: 889
						

Thoughts:
**Analyzing the BPF CO-RE Relocation Order**

Okay, so I'm digging into this BPF code, and it's got my attention.  I see that every caller of `bpf_patch_insn_data` is explicitly checking for `!new_prog` and handling the `-ENOMEM` case. That's good defensive programming.

Now, I'm focusing on the change in the call order of `bpf_check_core_relo`. I'm looking at `bpf_check_core_relo` in `check_btf.c` and comparing it to `bpf_check` in `verifier.c`.  I see that `bpf_check_core_relo` has this call:

```c
err = bpf_core_apply(&ctx, &core_relo, i,
			 &prog->insnsi[core_relo.insn_off / 8], prog->len);
```

The real question is how the call order changed. Before, `bpf_check_core_relo` was called *after* `add_subprogs` and `check_subprogs` and before the BTF validation:

```c
/* Discover all subprograms before validating their layout and BTF. */
ret = add_subprogs(env);
if (ret < 0)
    goto skip_full_check;

ret = check_subprogs(env);
if (ret < 0)
    goto skip_full_check;

/* Validate BTF against the complete subprogram layout and apply CO-RE. */
ret = bpf_check_btf_info(env, attr, uattr);
if (ret < 0)
    goto skip_full_check;
```
Now, it's called *before*:

```c
/* Apply CO-RE before validating the program's instruction layout. */
ret = bpf_check_core_relo(env, attr, uattr);
if (ret < 0)
    goto skip_full_check;

/* Discover all subprograms before validating their layout and BTF. */
ret = add_subprogs(env);
if (ret < 0)
    goto skip_full_check;

ret = check_subprogs(env);
if (ret < 0)
    goto skip_full_check;

/* Validate BTF against the complete subprogram layout. */
ret = bpf_check_btf_info(env, attr, uattr);
if (ret < 0)
    goto skip_full_check;
```

Ah, that's it! The crucial point is that CO-RE relocation can *modify* instructions. It can patch or even insert `BPF_CALL bad_relo` instructions. By doing this *before* discovering subprograms, we ensure the program structure is based on the *relocated* instructions, not the original ones.  This is essential for correct subprogram discovery and validation.

And let's go over the other change, which is in `bpf_prepare_btf_info`:

```c
-	if (!attr->func_info_cnt && !attr->line_info_cnt) {
+	if (!attr->func_info_cnt && !attr->line_info_cnt && !attr->core_relo_cnt) {
```

Previously, if there were core relocations (`core_relo_cnt > 0`) but no function or line information, `bpf_prepare_btf_info` was skipped entirely!  This change makes sure we *always* prepare BTF when CO-RE relocations are present.

Now, I need to really dig into `bpf_check_core_relo` in detail. Let's start reading around that part of the code in `kernel/bpf/check_btf.c`.



82/3 2026/09/15 00:11 tool read-file
0m Args:
{
  "File": "kernel/bpf/check_btf.c",
  "FirstLine": 340,
  "LineCount": 70
}

Results:
{
  "Contents": " 340:\t\n 341:\tint bpf_check_core_relo(struct bpf_verifier_env *env,\n 342:\t\t\t\tconst union bpf_attr *attr,\n 343:\t\t\t\tbpfptr_t uattr)\n 344:\t{\n 345:\t\tu32 i, nr_core_relo, ncopy, expected_size, rec_size;\n 346:\t\tstruct bpf_core_relo core_relo = {};\n 347:\t\tstruct bpf_prog *prog = env-\u003eprog;\n 348:\t\tconst struct btf *btf = prog-\u003eaux-\u003ebtf;\n 349:\t\tstruct bpf_core_ctx ctx = {\n 350:\t\t\t.log = \u0026env-\u003elog,\n 351:\t\t\t.btf = btf,\n 352:\t\t};\n 353:\t\tbpfptr_t u_core_relo;\n 354:\t\tint err;\n 355:\t\n 356:\t\tnr_core_relo = attr-\u003ecore_relo_cnt;\n 357:\t\tif (!nr_core_relo)\n 358:\t\t\treturn 0;\n 359:\t\tif (nr_core_relo \u003e INT_MAX / sizeof(struct bpf_core_relo))\n 360:\t\t\treturn -EINVAL;\n 361:\t\n 362:\t\trec_size = attr-\u003ecore_relo_rec_size;\n 363:\t\tif (rec_size \u003c MIN_CORE_RELO_SIZE ||\n 364:\t\t    rec_size \u003e MAX_CORE_RELO_SIZE ||\n 365:\t\t    rec_size % sizeof(u32))\n 366:\t\t\treturn -EINVAL;\n 367:\t\n 368:\t\tu_core_relo = make_bpfptr(attr-\u003ecore_relos, uattr.is_kernel);\n 369:\t\texpected_size = sizeof(struct bpf_core_relo);\n 370:\t\tncopy = min_t(u32, expected_size, rec_size);\n 371:\t\n 372:\t\t/* Unlike func_info and line_info, copy and apply each CO-RE\n 373:\t\t * relocation record one at a time.\n 374:\t\t */\n 375:\t\tfor (i = 0; i \u003c nr_core_relo; i++) {\n 376:\t\t\t/* future proofing when sizeof(bpf_core_relo) changes */\n 377:\t\t\terr = bpf_check_uarg_tail_zero(u_core_relo, expected_size, rec_size);\n 378:\t\t\tif (err) {\n 379:\t\t\t\tif (err == -E2BIG) {\n 380:\t\t\t\t\tverbose(env, \"nonzero tailing record in core_relo\");\n 381:\t\t\t\t\tif (copy_to_bpfptr_offset(uattr,\n 382:\t\t\t\t\t\t\t\t  offsetof(union bpf_attr, core_relo_rec_size),\n 383:\t\t\t\t\t\t\t\t  \u0026expected_size, sizeof(expected_size)))\n 384:\t\t\t\t\t\terr = -EFAULT;\n 385:\t\t\t\t}\n 386:\t\t\t\tbreak;\n 387:\t\t\t}\n 388:\t\n 389:\t\t\tif (copy_from_bpfptr(\u0026core_relo, u_core_relo, ncopy)) {\n 390:\t\t\t\terr = -EFAULT;\n 391:\t\t\t\tbreak;\n 392:\t\t\t}\n 393:\t\n 394:\t\t\tif (core_relo.insn_off % 8 || core_relo.insn_off / 8 \u003e= prog-\u003elen) {\n 395:\t\t\t\tverbose(env, \"Invalid core_relo[%u].insn_off:%u prog-\u003elen:%u\\n\",\n 396:\t\t\t\t\ti, core_relo.insn_off, prog-\u003elen);\n 397:\t\t\t\terr = -EINVAL;\n 398:\t\t\t\tbreak;\n 399:\t\t\t}\n 400:\t\n 401:\t\t\terr = bpf_core_apply(\u0026ctx, \u0026core_relo, i,\n 402:\t\t\t\t\t     \u0026prog-\u003einsnsi[core_relo.insn_off / 8], prog-\u003elen);\n 403:\t\t\tif (err)\n 404:\t\t\t\tbreak;\n 405:\t\t\tbpfptr_add(\u0026u_core_relo, rec_size);\n 406:\t\t}\n 407:\t\treturn err;\n 408:\t}\n 409:\t\n"
}

83/3 2026/09/15 00:11 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 60024
							output: 36
							thoughts: 739
						

Thoughts:
**Decoding the BPF Core Relocation Logic**

Okay, here's what's running through my mind as I dig into this BPF code. I'm in `bpf_check_core_relo` and immediately spot something that needs a closer look. Specifically, the call to `bpf_core_apply`. I see that `&prog->insnsi[core_relo.insn_off / 8]` is being passed as the `insn` argument, and `prog->len` is going in as `insn_cnt`. That immediately sets off an alarm.

I need to confirm if I understand the arguments passed to `bpf_core_apply`. So, I'm now cross-referencing this with the `kernel/bpf/btf.c` implementation. The code in `bpf_core_apply` confirms my suspicions. It calls `bpf_core_patch_insn`, with `insn_cnt` passed as `insn_cnt`!

Now I'm diving deeper into `bpf_core_patch_insn`. I zero in on this check: `if (is_ldimm64_insn(insn) && (size_t)insn_idx + 1 >= insn_cnt)`. This feels important. Essentially, it appears to be guarding against truncating a `LDIMM64` instruction during the patching process.

My mind flashes back to `tools/lib/bpf/libbpf.c`, and the `bpf_object__relocate_core` function. Here I am, re-examining the code, where `insn` is `prog->insns`! The base of the instruction set. I feel a bit more confident in my understanding of the relationship between the arguments here. Now I need to circle back to around line 6223 in `libbpf.c` for any missing pieces of context, because I'm not entirely satisfied. There is a lot to think about here, but it's shaping up to be a key area for understanding how these BPF core relocations are handled!



84/3 2026/09/15 00:11 tool grepper
0m Args:
{
  "Expression": "bpf_core_patch_insn",
  "PathPrefix": "tools/lib/bpf/"
}

Results:
{
  "Output": "tools/lib/bpf/libbpf.c=6131=bpf_object__relocate_core(struct bpf_object *obj, const char *targ_btf_path)\n--\ntools/lib/bpf/libbpf.c-6225-\ntools/lib/bpf/libbpf.c:6226:\t\t\terr = bpf_core_patch_insn(prog-\u003ename, insn, prog-\u003einsns_cnt, insn_idx,\ntools/lib/bpf/libbpf.c-6227-\t\t\t\t\t\t  rec, i, \u0026targ_res);\n--\ntools/lib/bpf/relo_core.c=1020=static int insn_bytes_to_bpf_size(__u32 sz)\n--\ntools/lib/bpf/relo_core.c-1047- */\ntools/lib/bpf/relo_core.c:1048:int bpf_core_patch_insn(const char *prog_name, struct bpf_insn *insn,\ntools/lib/bpf/relo_core.c-1049-\t\t\tsize_t insn_cnt, int insn_idx,\n--\ntools/lib/bpf/relo_core.c=1308=int bpf_core_calc_relo_insn(const char *prog_name,\n--\ntools/lib/bpf/relo_core.c-1430-\t * code) if relocation can't be resolved. This is handled in\ntools/lib/bpf/relo_core.c:1431:\t * bpf_core_patch_insn() uniformly by replacing that instruction with\ntools/lib/bpf/relo_core.c-1432-\t * BPF helper call insn (using invalid helper ID). If that instruction\n--\ntools/lib/bpf/relo_core.h=82=int bpf_core_calc_relo_insn(const char *prog_name,\n--\ntools/lib/bpf/relo_core.h-88-\ntools/lib/bpf/relo_core.h:89:int bpf_core_patch_insn(const char *prog_name, struct bpf_insn *insn,\ntools/lib/bpf/relo_core.h-90-\t\t\tsize_t insn_cnt, int insn_idx,\n"
}

85/3 2026/09/15 00:11 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 61865
							output: 34
							thoughts: 68
						

Thoughts:
Here's my summary, as the expert, of those thoughts:

**Analyzing Kernel BPF Relocation Code**

Okay, hold on a second. Something just pinged my radar. Let me zoom in on this – I'm seeing a reference to `kernel/bpf/relo_core.c`. My immediate thought is, "Wait, is this code internal to the BPF subsystem, or is it a shared utility used across the broader kernel?" Is there another `relo_core.c` hanging around somewhere, like maybe a top-level `kernel/relo_core.c`? Gotta clarify that context. This is the kind of detail that's critical to understanding the dependency structure and potential impacts of any changes to this relocation logic. Time to go dig around the kernel source and figure out precisely where this file is located in the directory structure. Gotta make sure I fully grasp the scope.



86/3 2026/09/15 00:11 tool grepper
0m Args:
{
  "Expression": "bpf_core_patch_insn",
  "PathPrefix": "kernel/bpf/"
}

Results:
{
  "Output": "kernel/bpf/btf.c=9731=int bpf_core_apply(struct bpf_core_ctx *ctx, const struct bpf_core_relo *relo,\n--\nkernel/bpf/btf.c-9795-\nkernel/bpf/btf.c:9796:\terr = bpf_core_patch_insn((void *)ctx-\u003elog, insn, insn_cnt, relo-\u003einsn_off / 8,\nkernel/bpf/btf.c-9797-\t\t\t\t  relo, relo_idx, \u0026targ_res);\n"
}

87/3 2026/09/15 00:11 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 62319
							output: 23
							thoughts: 44
						

Thoughts:
**Debugging a Kernel Compilation Mystery**

Okay, hold on a second. I'm hitting a snag in the kernel compilation process. I'm getting an undefined symbol error, and the culprit appears to be `bpf_core_patch_insn`. The compiler's complaining, and my gut tells me this function *should* be available. Where is this thing defined? It's time to fire up `git grep`. I need to scour the entire kernel source tree. Let's see if I can pinpoint where `bpf_core_patch_insn` is declared and if its inclusion is conditional on some configuration setting I've overlooked. Time to get digging!



88/3 2026/09/15 00:11 tool grepper
0m Args:
{
  "Expression": "bpf_core_patch_insn"
}

Results:
{
  "Output": "kernel/bpf/btf.c=9731=int bpf_core_apply(struct bpf_core_ctx *ctx, const struct bpf_core_relo *relo,\n--\nkernel/bpf/btf.c-9795-\nkernel/bpf/btf.c:9796:\terr = bpf_core_patch_insn((void *)ctx-\u003elog, insn, insn_cnt, relo-\u003einsn_off / 8,\nkernel/bpf/btf.c-9797-\t\t\t\t  relo, relo_idx, \u0026targ_res);\n--\ntools/lib/bpf/libbpf.c=6131=bpf_object__relocate_core(struct bpf_object *obj, const char *targ_btf_path)\n--\ntools/lib/bpf/libbpf.c-6225-\ntools/lib/bpf/libbpf.c:6226:\t\t\terr = bpf_core_patch_insn(prog-\u003ename, insn, prog-\u003einsns_cnt, insn_idx,\ntools/lib/bpf/libbpf.c-6227-\t\t\t\t\t\t  rec, i, \u0026targ_res);\n--\ntools/lib/bpf/relo_core.c=1020=static int insn_bytes_to_bpf_size(__u32 sz)\n--\ntools/lib/bpf/relo_core.c-1047- */\ntools/lib/bpf/relo_core.c:1048:int bpf_core_patch_insn(const char *prog_name, struct bpf_insn *insn,\ntools/lib/bpf/relo_core.c-1049-\t\t\tsize_t insn_cnt, int insn_idx,\n--\ntools/lib/bpf/relo_core.c=1308=int bpf_core_calc_relo_insn(const char *prog_name,\n--\ntools/lib/bpf/relo_core.c-1430-\t * code) if relocation can't be resolved. This is handled in\ntools/lib/bpf/relo_core.c:1431:\t * bpf_core_patch_insn() uniformly by replacing that instruction with\ntools/lib/bpf/relo_core.c-1432-\t * BPF helper call insn (using invalid helper ID). If that instruction\n--\ntools/lib/bpf/relo_core.h=82=int bpf_core_calc_relo_insn(const char *prog_name,\n--\ntools/lib/bpf/relo_core.h-88-\ntools/lib/bpf/relo_core.h:89:int bpf_core_patch_insn(const char *prog_name, struct bpf_insn *insn,\ntools/lib/bpf/relo_core.h-90-\t\t\tsize_t insn_cnt, int insn_idx,\n"
}

89/3 2026/09/15 00:11 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 63285
							output: 20
							thoughts: 40
						

Thoughts:
**Kernel Inclusion Conundrum**

Alright, hold on a second. I'm taking a look at this and something's just not clicking. How *exactly* does the kernel manage to bring in `tools/lib/bpf/relo_core.c`? It's a kernel component, but I'm not seeing the usual obvious `#include` statement jumping out at me in the main code. This seems a bit non-standard.

Okay, deep breath. Let's get down to brass tacks. Best approach here, given my experience, is to run a targeted search. I'm going to scan the code for any instances of `#include` directives followed by something that looks like `relo_core.c`. Hopefully, this will shed some light on the exact mechanisms at play in incorporating this particular piece of code into the kernel build. That's the first place to look when trying to understand these kinds of things.



90/3 2026/09/15 00:11 tool grepper
0m Args:
{
  "Expression": "relo_core.c"
}

Results:
{
  "Output": "kernel/bpf/relo_core.c-1-// SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)\nkernel/bpf/relo_core.c:2:#include \"../../tools/lib/bpf/relo_core.c\"\n"
}

91/3 2026/09/15 00:11 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 63622
							output: 41
							thoughts: 587
						

Thoughts:
**Deep Dive into eBPF Core Relocation Logic**

Okay, here's what's running through my head as I dig into this eBPF core relocation code. First, I see that `kernel/bpf/relo_core.c` thoughtfully includes the equivalent in the tools directory, which is a good sign for consistency. I'm focusing on `bpf_core_patch_insn`. My immediate thought is, what's happening with the `insn` argument when `bpf_core_patch_insn` gets called?

I know `bpf_core_patch_insn` gets called from `kernel/bpf/btf.c`, so I check that out. Then, I see `bpf_core_apply` called from `kernel/bpf/check_btf.c`, and inside `bpf_core_apply`, `bpf_core_patch_insn` is called again! Now I'm getting into the meat of it.

I see in `kernel/bpf/check_btf.c`, the `insn` argument is `&prog->insnsi[core_relo.insn_off / 8]`. But, in `kernel/bpf/btf.c`, when `bpf_core_patch_insn` is called, `insn` is passed directly from the `bpf_core_apply` function! And the `insn_idx` passed in is `relo->insn_off / 8`. I need to figure out how these relate!

Then, I remember, I need to look at `libbpf.c`! Here, `insn` is `prog->insns`, which is the start of all instructions! This whole thing is coming together now. Let's see how `libbpf.c` actually uses these functions.



92/3 2026/09/15 00:11 tool read-file
0m Args:
{
  "File": "tools/lib/bpf/libbpf.c",
  "FirstLine": 6215,
  "LineCount": 25
}

Results:
{
  "Contents": "6215:\t\n6216:\t\t\t\tif (prog-\u003eobj-\u003egen_loader)\n6217:\t\t\t\t\tcontinue;\n6218:\t\n6219:\t\t\t\terr = bpf_core_resolve_relo(prog, rec, i, obj-\u003ebtf, cand_cache, \u0026targ_res);\n6220:\t\t\t\tif (err) {\n6221:\t\t\t\t\tpr_warn(\"prog '%s': relo #%d: failed to relocate: %s\\n\",\n6222:\t\t\t\t\t\tprog-\u003ename, i, errstr(err));\n6223:\t\t\t\t\tgoto out;\n6224:\t\t\t\t}\n6225:\t\n6226:\t\t\t\terr = bpf_core_patch_insn(prog-\u003ename, insn, prog-\u003einsns_cnt, insn_idx,\n6227:\t\t\t\t\t\t\t  rec, i, \u0026targ_res);\n6228:\t\t\t\tif (err) {\n6229:\t\t\t\t\tpr_warn(\"prog '%s': relo #%d: failed to patch insn #%d: %s\\n\",\n6230:\t\t\t\t\t\tprog-\u003ename, i, insn_idx, errstr(err));\n6231:\t\t\t\t\tgoto out;\n6232:\t\t\t\t}\n6233:\t\t\t}\n6234:\t\t}\n6235:\t\n6236:\tout:\n6237:\t\t/* obj-\u003ebtf_vmlinux and module BTFs are freed after object load */\n6238:\t\tbtf__free(obj-\u003ebtf_vmlinux_override);\n6239:\t\tobj-\u003ebtf_vmlinux_override = NULL;\n"
}

93/3 2026/09/15 00:11 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 65079
							output: 41
							thoughts: 45
						

Thoughts:
Here's my take on the thought process:

**Where's That Dang Variable?!**

Okay, hold on a second. I'm in `bpf_object__relocate_core` and I'm looking at this code, but I can't quite place where `insn` is actually defined. I know I've seen it used here, but I need to quickly refresh my memory. Let me see... I'm pretty sure I remember it being in that area of `libbpf.c`, so let me go straight to lines 6200-6215. Time to track down that elusive definition and get this sorted out!



94/3 2026/09/15 00:11 tool read-file
0m Args:
{
  "File": "tools/lib/bpf/libbpf.c",
  "FirstLine": 6200,
  "LineCount": 20
}

Results:
{
  "Contents": "6200:\t\t\t\t/* adjust insn_idx from section frame of reference to the local\n6201:\t\t\t\t * program's frame of reference; (sub-)program code is not yet\n6202:\t\t\t\t * relocated, so it's enough to just subtract in-section offset\n6203:\t\t\t\t */\n6204:\t\t\t\tinsn_idx = insn_idx - prog-\u003esec_insn_off;\n6205:\t\t\t\tif (insn_idx \u003e= prog-\u003einsns_cnt)\n6206:\t\t\t\t\treturn -EINVAL;\n6207:\t\t\t\tinsn = \u0026prog-\u003einsns[insn_idx];\n6208:\t\n6209:\t\t\t\terr = record_relo_core(prog, rec, insn_idx);\n6210:\t\t\t\tif (err) {\n6211:\t\t\t\t\tpr_warn(\"prog '%s': relo #%d: failed to record relocation: %s\\n\",\n6212:\t\t\t\t\t\tprog-\u003ename, i, errstr(err));\n6213:\t\t\t\t\tgoto out;\n6214:\t\t\t\t}\n6215:\t\n6216:\t\t\t\tif (prog-\u003eobj-\u003egen_loader)\n6217:\t\t\t\t\tcontinue;\n6218:\t\n6219:\t\t\t\terr = bpf_core_resolve_relo(prog, rec, i, obj-\u003ebtf, cand_cache, \u0026targ_res);\n"
}

95/3 2026/09/15 00:11 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 65665
							output: 31
							thoughts: 1856
						

Thoughts:
**Analyzing Potential Uninitialized Memory Access in the BPF Patch**

Okay, let's break this down. Line 6207 and 6226 in `libbpf.c` grabbed my attention. I'm looking at `bpf_core_patch_insn` and immediately see that `insn[1]` is accessed within the `is_ldimm64_insn` check.  Specifically, if the instruction at `insn_idx` is a `LDIMM64` instruction and is the *very last* instruction in the program (`insn_idx + 1 >= insn_cnt`), that access would be out of bounds. The code now includes a crucial check to prevent this. Previously, KASAN would've likely flagged this, and the added check avoids this.

The question then becomes, are there *any* remaining uninitialized memory access issues introduced or changed by this patch series? Let's go category by category.

**Category 1: Kernel Structures to Userspace**
I'm scanning for `copy_to_user`, `put_user`, netlink SKB attributes, ioctl output arguments, and socket options within this diff. Nothing there. However, I did catch that `bpf_check_core_relo` has some potential issues. `copy_to_bpfptr_offset` is used to copy `expected_size` to a user-provided location. But wait a moment - `expected_size` is initialized to the `sizeof(struct bpf_core_relo)` which is definitely not uninitialized.

**Category 2: Conditional Logic or Branching**

Now, I'm checking introduced or modified branches.
1. In `kernel/bpf/core.c`: I see conditionals using `fatal_signal_pending(current)`, `PTR_ERR(prog) == -EINTR`, and `IS_ERR(jit_prog)`.  `fatal_signal_pending` is standard. The error checks use the standard kernel APIs and return values.

2. `kernel/bpf/fixups.c`: Uses `bpf_rewrite_must_abort()`, `fatal_signal_pending`, and an error check. The abort and error checks are standard and don't seem like the source of uninitialized memory.

3. `kernel/bpf/states.c`: The `check_ids(rold->map_uid, rcur->map_uid, idmap)` call is key. Where do `rold->map_uid` and `rcur->map_uid` come from? I'm tracing register initialization. All the registers and associated `map_uid` field are initialized!

4. Also, regarding `regsafe`, the code checks `rold->id` and `r64.base`. The `r64` field is initialized with the register.

5. Finally, in `kernel/bpf/check_btf.c`: The code checks `attr->func_info_cnt`, `attr->line_info_cnt`, and `attr->core_relo_cnt`.  `attr` comes from userspace, so how is this handled? It's copied from userspace by `bpf_prog_load` using `copy_from_bpfptr` and `copy_from_user` with zero-padding. I must look into how `bpf_prog_load` handles the copying of the `union bpf_attr`. If the userspace struct is shorter, will the `core_relo_cnt` member be properly handled? I will need to verify the code path in `bpf_prog_load` to confirm.



96/3 2026/09/15 00:12 tool grepper
0m Args:
{
  "Expression": "core_relo_cnt",
  "PathPrefix": "kernel/bpf/"
}

Results:
{
  "Output": "kernel/bpf/check_btf.c=341=int bpf_check_core_relo(struct bpf_verifier_env *env,\n--\nkernel/bpf/check_btf.c-355-\nkernel/bpf/check_btf.c:356:\tnr_core_relo = attr-\u003ecore_relo_cnt;\nkernel/bpf/check_btf.c-357-\tif (!nr_core_relo)\n--\nkernel/bpf/check_btf.c=410=int bpf_prepare_btf_info(struct bpf_verifier_env *env,\n--\nkernel/bpf/check_btf.c-416-\nkernel/bpf/check_btf.c:417:\tif (!attr-\u003efunc_info_cnt \u0026\u0026 !attr-\u003eline_info_cnt \u0026\u0026 !attr-\u003ecore_relo_cnt) {\nkernel/bpf/check_btf.c-418-\t\tif (check_abnormal_return(env))\n"
}

97/3 2026/09/15 00:12 llm kmsan-evaluator
0m Model:
gemini-3.8-flash

Args:
null

Results:
null

Tokens:
							input: 68611
							output: 421
							thoughts: 1845
						

Thoughts:
**KMSAN Assessment: A Deep Dive into BPF Verifier Changes**

Okay, let's break this down. First, I'm looking at `bpf_prog_load` and the `bpf` syscall. I see that the `attr` struct is fully zeroed out using `memset` *before* any data is copied into it from user space. No issues there.

Next, I examined `relo_core.c` and specifically the `is_ldimm64_insn` check. The code makes it very explicit about the values of `insn_cnt` and `insn_idx` – they are passed as explicit integer parameters. Furthermore, `insn_cnt` is explicitly set within the function itself based on `is_ldimm64_insn(insn)`. No potential for uninitialized memory here, all variables initialized and passed properly.

Now, we get to the core of the matter, Category 3: uninitialized fields in complex data structures. This seems to be where the KMSAN concerns are targeted. Let's delve into `struct bpf_reg_state`. The `map_uid` is properly zeroed explicitly in several places, and it is explicitly set in all code paths. The `memcmp` use on the `struct bpf_reg_state` is critical here. The patch moved `map_uid` *after* `id`.

I had to double check the struct definition in `include/linux/bpf_verifier.h` to see if there was any padding before the `id` field that `memcmp` might inadvertently include. I see that the `type` and `delta` are 4 bytes each, then the union of potential fields. That union is 16 bytes in size and starts at offset 8. The patch itself just swapped a union element. In fact, `__mark_reg_known` uses `memset` to zero out the area from `type` to `var_off`, which means `delta` *and* the entire union are zeroed out, so no uninitialized values within the union are possible. No padding, no problem!

Category 4 focuses on bounds checks and potential for uninitialized byte access. First, the bounds check in `bpf_core_patch_insn` is *explicitly* added to prevent out-of-bounds access. The KASAN is designed to catch it if an out of bounds access occurs. Similarly, the `regsafe` for `PTR_TO_PACKET` check prevents an unsafe state pruning which could have led to a verifier accepting an out-of-bounds packet access, which is also KASAN-caught. Moving `bpf_check_core_relo` earlier also prevents state inconsistencies. Signal handling is performed correctly by handling `-EINTR`, so no uninitialized memory concerns there either.

I'm very confident based on the defined criteria: *All* stack/heap structures are zeroed or initialized. The patches introduce or expose no risk of uninitialized memory usage or info-leaks, and mainly risk bugs caught by KASAN. Instructions bound-checking, verifier packet displacement checking, verifier register mapping improvements, and CO-RE relocation ordering all address potential bugs that are *not* KMSAN-specific.

Based on the evidence, the criteria for setting `NeedsKMSAN=false` are fully met. I'm ready to proceed with the `set-results` tool.



98/3 2026/09/15 00:12 tool set-results
0m Args:
{
  "KMSANReasoning": "The patch series addresses several distinct issues within the BPF subsystem:\n1. Bounds checking in CO-RE relocation (`bpf_core_patch_insn`): Adds a bounds check to ensure `insn[1]` is within bounds before handling 64-bit immediate instructions (`LDIMM64`), preventing out-of-bounds memory accesses on truncated instructions. Any such OOB bug is detectable by KASAN.\n2. Packet pointer displacement check in `regsafe`: Restricts state pruning when packet pointers sharing an ID have different base displacements (`r64.base`). This fixes a verifier soundness flaw where out-of-bounds packet accesses could be accepted, which is an OOB issue caught by KASAN.\n3. Inner map UID tracking in `bpf_reg_state`: Moves `map_uid` out of the metadata union so it participates in ID mapping during state equivalence checks (`regs_exact` and `regsafe`), preventing incorrect lock identity matching. The register structures are fully zeroed upon allocation and in initialization helpers (`__mark_reg_known`, `bpf_mark_reg_unknown_imprecise`), leaving no uninitialized fields or padding.\n4. Signal interruption in JIT blinding and instruction rewrite passes: Adds fatal signal checks (`fatal_signal_pending`) and clean error returns (`-EINTR`) during post-verification fixups.\n5. CO-RE pass reordering: Invokes `bpf_check_core_relo` before discovering subprograms to ensure the subprogram layout matches the rewritten instructions.\n\nNone of these modifications introduce reads of uninitialized stack or heap memory, info-leaks to userspace, or branching on uninitialized data. Standard KASAN, LOCKDEP, and existing verifier assertions provide full coverage for the hazards touched by this patch series. Therefore, a dedicated KMSAN fuzzing session is not warranted.",
  "NeedsKMSAN": false
}

Results:
{
  "KMSANReasoning": "The patch series addresses several distinct issues within the BPF subsystem:\n1. Bounds checking in CO-RE relocation (`bpf_core_patch_insn`): Adds a bounds check to ensure `insn[1]` is within bounds before handling 64-bit immediate instructions (`LDIMM64`), preventing out-of-bounds memory accesses on truncated instructions. Any such OOB bug is detectable by KASAN.\n2. Packet pointer displacement check in `regsafe`: Restricts state pruning when packet pointers sharing an ID have different base displacements (`r64.base`). This fixes a verifier soundness flaw where out-of-bounds packet accesses could be accepted, which is an OOB issue caught by KASAN.\n3. Inner map UID tracking in `bpf_reg_state`: Moves `map_uid` out of the metadata union so it participates in ID mapping during state equivalence checks (`regs_exact` and `regsafe`), preventing incorrect lock identity matching. The register structures are fully zeroed upon allocation and in initialization helpers (`__mark_reg_known`, `bpf_mark_reg_unknown_imprecise`), leaving no uninitialized fields or padding.\n4. Signal interruption in JIT blinding and instruction rewrite passes: Adds fatal signal checks (`fatal_signal_pending`) and clean error returns (`-EINTR`) during post-verification fixups.\n5. CO-RE pass reordering: Invokes `bpf_check_core_relo` before discovering subprograms to ensure the subprogram layout matches the rewritten instructions.\n\nNone of these modifications introduce reads of uninitialized stack or heap memory, info-leaks to userspace, or branching on uninitialized data. Standard KASAN, LOCKDEP, and existing verifier assertions provide full coverage for the hazards touched by this patch series. Therefore, a dedicated KMSAN fuzzing session is not warranted.",
  "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)