| Seq | Timestamp | Type | Name | Duration |
|---|---|---|---|---|
| 0/0 | 2026/09/06 11:23 | flow | patch-triage |
1mArgs:null Results: {
"EnableConfigs": [
"BPF_SYSCALL"
],
"FocusSymbols": [
"bpf_check_cfg",
"push_insn",
"bpf_patch_insn_data",
"verifier_remove_insns",
"check_pkt_ptr_ids",
"regsafe",
"bpf_is_state_visited",
"map_set_for_each_callback_args",
"set_timer_callback_state",
"set_task_work_schedule_callback_state"
],
"KMSANReasoning": "The patch series modifies the BPF verifier and CFG analysis in several areas:\n1. Adds packet pointer displacement tracking across state equivalence checks in `kernel/bpf/states.c` (using `check_pkt_ptr_ids` and initializing `pkt_ptr_delta_set` in `check_ids`).\n2. Validates subprogram boundaries on fall-through edges in `kernel/bpf/cfg.c`.\n3. Adds fatal signal checks (`bpf_rewrite_must_abort`) to prevent non-killable loops during post-verification instruction patching/removal in `kernel/bpf/fixups.c`.\n4. Ensures distinct register IDs for callback map values that may point to spin locks unless the map has static identity in `kernel/bpf/verifier.c`.\n\nNone of these changes allocate or manipulate uninitialized memory buffers, copy uninitialized data to user space, or alter buffer lengths in ways that expose uninitialized stack or heap data. All struct fields added (`pkt_ptr_delta`, `pkt_ptr_delta_set`) are explicitly initialized before read operations. The changes are strictly verifier logic, control-flow validation, and signal-handling improvements. Therefore, a dedicated KMSAN fuzzing session is not required.",
"NeedsKMSAN": false,
"Reasoning": "The patch touches core BPF verifier execution paths, including control flow graph (CFG) subprogram boundary checks, signal-aware instruction rewriting/removal passes, packet pointer state equivalence comparison (regsafe), and lock identity tracking for callback arguments. These changes are reachable via the bpf(BPF_PROG_LOAD, ...) syscall and directly affect verification correctness and safety invariants.",
"WorthFuzzing": true
} |
| 1/1 | 2026/09/06 11:23 | action | read-patch-diff |
0mArgs:null Results: {
"PatchDiff": "commit 62ec2a38e983ba002431ffb5bb17707c7360dce2\nAuthor: syz-cluster \u003ctriage@syzkaller.com\u003e\nDate: Sun Sep 6 11:23:12 2026 +0000\n\n syz-cluster: applied patch under review\n\ndiff --git a/include/linux/bpf_verifier.h b/include/linux/bpf_verifier.h\nindex 36b65797877d0..5cf92ce185204 100644\n--- a/include/linux/bpf_verifier.h\n+++ b/include/linux/bpf_verifier.h\n@@ -854,6 +854,8 @@ struct backtrack_state {\n struct bpf_id_pair {\n \tu32 old;\n \tu32 cur;\n+\ts32 pkt_ptr_delta;\n+\tbool pkt_ptr_delta_set;\n };\n \n struct bpf_idmap {\ndiff --git a/kernel/bpf/cfg.c b/kernel/bpf/cfg.c\nindex 842c7d1eabccc..e3c904328ede0 100644\n--- a/kernel/bpf/cfg.c\n+++ b/kernel/bpf/cfg.c\n@@ -102,6 +102,7 @@ enum {\n */\n static int push_insn(int t, int w, int e, struct bpf_verifier_env *env)\n {\n+\tstruct bpf_subprog_info *subprog;\n \tint *insn_stack = env-\u003ecfg.insn_stack;\n \tint *insn_state = env-\u003ecfg.insn_state;\n \n@@ -121,6 +122,26 @@ static int push_insn(int t, int w, int e, struct bpf_verifier_env *env)\n \t\treturn -EINVAL;\n \t}\n \n+\t/*\n+\t * check_subprogs() prevents control flow from falling through a\n+\t * subprogram boundary, but runs before CO-RE relocations can rewrite an\n+\t * instruction. Reestablish the invariant on the final instruction stream\n+\t * before constructing the CFG used by later per-subprogram passes.\n+\t */\n+\tif (e == FALLTHROUGH) {\n+\t\tsubprog = bpf_find_containing_subprog(env, t);\n+\t\tif (w \u003c subprog-\u003estart || w \u003e= (subprog + 1)-\u003estart) {\n+\t\t\tverbose_linfo(env, t, \"%d: \", t);\n+\t\t\tverbose(env, \"fall-through out of subprog from insn %d to %d\\n\", t, w);\n+\t\t\tbpf_diag_program_structure(\n+\t\t\t\tenv, t, \"fall-through leaves subprogram\",\n+\t\t\t\t\"Keep fall-through control flow inside the current subprogram.\",\n+\t\t\t\t\"Instruction %d falls through to instruction %d outside its subprogram.\",\n+\t\t\t\tt, w);\n+\t\t\treturn -EINVAL;\n+\t\t}\n+\t}\n+\n \tif (e == BRANCH) {\n \t\t/* mark branch target for state pruning */\n \t\tmark_prune_point(env, w);\ndiff --git a/kernel/bpf/fixups.c b/kernel/bpf/fixups.c\nindex 52d3cec336727..9401fffcedfd6 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@@ -2666,4 +2686,3 @@ int bpf_remove_fastcall_spills_fills(struct bpf_verifier_env *env)\n \n \treturn 0;\n }\n-\ndiff --git a/kernel/bpf/states.c b/kernel/bpf/states.c\nindex 66fb11b6c6a76..2f8f3fe164b01 100644\n--- a/kernel/bpf/states.c\n+++ b/kernel/bpf/states.c\n@@ -339,6 +339,7 @@ static bool check_ids(u32 old_id, u32 cur_id, struct bpf_idmap *idmap)\n \tif (idmap-\u003ecnt \u003c BPF_ID_MAP_SIZE) {\n \t\tmap[idmap-\u003ecnt].old = old_id;\n \t\tmap[idmap-\u003ecnt].cur = cur_id;\n+\t\tmap[idmap-\u003ecnt].pkt_ptr_delta_set = false;\n \t\tidmap-\u003ecnt++;\n \t\treturn true;\n \t}\n@@ -352,6 +353,43 @@ static bool check_ids(u32 old_id, u32 cur_id, struct bpf_idmap *idmap)\n \treturn false;\n }\n \n+static bool check_pkt_ptr_ids(const struct bpf_reg_state *old,\n+\t\t\t const struct bpf_reg_state *cur,\n+\t\t\t struct bpf_idmap *idmap)\n+{\n+\tstruct bpf_id_pair *map = idmap-\u003emap;\n+\ts64 delta;\n+\tunsigned int i;\n+\n+\tif (!check_ids(old-\u003eid, cur-\u003eid, idmap))\n+\t\treturn false;\n+\tif (!old-\u003eid)\n+\t\treturn true;\n+\n+\t/*\n+\t * Packet range is shared by all pointers with the same ID. Preserve\n+\t * their relative displacement, while allowing the whole class to move.\n+\t * Packet pointer offsets are bounded by BPF_MAX_VAR_OFF, so the delta\n+\t * between two valid offsets fits in s32.\n+\t */\n+\tdelta = (s64)(cur-\u003er64.base - old-\u003er64.base);\n+\tif (delta \u003c S32_MIN || delta \u003e S32_MAX)\n+\t\treturn false;\n+\n+\tfor (i = 0; i \u003c idmap-\u003ecnt; i++) {\n+\t\tif (map[i].old != old-\u003eid)\n+\t\t\tcontinue;\n+\t\tif (!map[i].pkt_ptr_delta_set) {\n+\t\t\tmap[i].pkt_ptr_delta = delta;\n+\t\t\tmap[i].pkt_ptr_delta_set = true;\n+\t\t\treturn true;\n+\t\t}\n+\t\treturn map[i].pkt_ptr_delta == delta;\n+\t}\n+\n+\treturn false;\n+}\n+\n /*\n * Compare scalar register IDs for state equivalence.\n *\n@@ -632,8 +670,8 @@ static bool regsafe(struct bpf_verifier_env *env, struct bpf_reg_state *rold,\n \t\t} else if (rold-\u003erange \u003e rcur-\u003erange) {\n \t\t\treturn false;\n \t\t}\n-\t\t/* id relations must be preserved */\n-\t\tif (!check_ids(rold-\u003eid, rcur-\u003eid, idmap))\n+\t\t/* id relations and intra-class displacement must be preserved */\n+\t\tif (!check_pkt_ptr_ids(rold, rcur, idmap))\n \t\t\treturn false;\n \t\t/* new val must satisfy old val knowledge */\n \t\treturn range_within(rold, rcur) \u0026\u0026\ndiff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c\nindex 1c3039f3fc323..b08501734ddfa 100644\n--- a/kernel/bpf/verifier.c\n+++ b/kernel/bpf/verifier.c\n@@ -447,6 +447,11 @@ static bool reg_may_point_to_spin_lock(const struct bpf_reg_state *reg)\n \treturn btf_record_has_field(reg_btf_record(reg), BPF_SPIN_LOCK | BPF_RES_SPIN_LOCK);\n }\n \n+static bool map_value_has_static_identity(const struct bpf_map *map)\n+{\n+\treturn map-\u003emap_type == BPF_MAP_TYPE_ARRAY \u0026\u0026 map-\u003emax_entries == 1;\n+}\n+\n static bool type_is_rdonly_mem(u32 type)\n {\n \treturn type \u0026 MEM_RDONLY;\n@@ -10035,6 +10040,9 @@ 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+\tif (reg_may_point_to_spin_lock(\u0026callee-\u003eregs[BPF_REG_3]) \u0026\u0026\n+\t !map_value_has_static_identity(callee-\u003eregs[BPF_REG_3].map_ptr))\n+\t\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@@ -10131,6 +10139,9 @@ 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+\tif (reg_may_point_to_spin_lock(\u0026callee-\u003eregs[BPF_REG_3]) \u0026\u0026\n+\t !map_value_has_static_identity(callee-\u003eregs[BPF_REG_3].map_ptr))\n+\t\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@@ -10249,6 +10260,9 @@ 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+\tif (reg_may_point_to_spin_lock(\u0026callee-\u003eregs[BPF_REG_3]) \u0026\u0026\n+\t !map_value_has_static_identity(callee-\u003eregs[BPF_REG_3].map_ptr))\n+\t\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]);\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..c350fbb958455 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,117 @@\n \n static char log[16 * 1024];\n \n+static int load_core_relo_subprog(int btf_fd, int main_id, int sub_id,\n+\t\t\t\t int enum_id, int access_str_off, bool relocate)\n+{\n+\tstruct bpf_insn insns[] = {\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[] = {\n+\t\t{ .insn_off = 0, .type_id = main_id },\n+\t\t{ .insn_off = 3, .type_id = sub_id },\n+\t};\n+\tstruct bpf_core_relo relo = {\n+\t\t.insn_off = 2 * 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 = ARRAY_SIZE(insns),\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 = 1,\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 = ARRAY_SIZE(funcs),\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_poisoned_subprog_terminator(void)\n+{\n+\tconst void *raw_btf;\n+\tstruct btf *btf = NULL;\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;\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_subprog_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+\n+\t/* The same two-subprogram program is valid before the relocation. */\n+\tprog_fd = load_core_relo_subprog(btf_fd, main_id, sub_id, enum_id,\n+\t\t\t\t\t access_str_off, false);\n+\tif (!ASSERT_GE(prog_fd, 0, \"control_load\"))\n+\t\tgoto cleanup;\n+\tclose(prog_fd);\n+\tprog_fd = -1;\n+\n+\t/*\n+\t * Poison the first subprogram's terminal exit. The verifier must reject\n+\t * the resulting control flow across the subprogram boundary in the CFG.\n+\t */\n+\tprog_fd = load_core_relo_subprog(btf_fd, main_id, sub_id, enum_id,\n+\t\t\t\t\t access_str_off, true);\n+\tif (!ASSERT_LT(prog_fd, 0, \"poisoned_load\"))\n+\t\tgoto cleanup;\n+\tASSERT_HAS_SUBSTR(log, \"fall-through out of subprog from insn 2 to 3\",\n+\t\t\t \"poisoned_load_log\");\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 +231,8 @@ static void test_bad_local_id(void)\n \n void test_core_reloc_raw(void)\n {\n+\tif (test__start_subtest(\"poisoned_subprog_terminator\"))\n+\t\ttest_poisoned_subprog_terminator();\n \tif (test__start_subtest(\"bad_local_id\"))\n \t\ttest_bad_local_id();\n }\ndiff --git a/tools/testing/selftests/bpf/prog_tests/prog_load_signal.c b/tools/testing/selftests/bpf/prog_tests/prog_load_signal.c\nnew file mode 100644\nindex 0000000000000..0f78db3bccc76\n--- /dev/null\n+++ b/tools/testing/selftests/bpf/prog_tests/prog_load_signal.c\n@@ -0,0 +1,131 @@\n+// SPDX-License-Identifier: GPL-2.0\n+/* Copyright (c) 2026 Meta Platforms, Inc. and affiliates. */\n+#include \u003ctest_progs.h\u003e\n+\n+#define NOP_CNT\t\t32768\n+#define MIN_KILL_DELAY_NS\t(100ULL * 1000 * 1000)\n+#define REAP_TIMEOUT_NS\t\t(1000ULL * 1000 * 1000)\n+\n+static __u64 monotonic_ns(void)\n+{\n+\tstruct timespec ts;\n+\n+\tclock_gettime(CLOCK_MONOTONIC, \u0026ts);\n+\treturn ts.tv_sec * 1000000000ULL + ts.tv_nsec;\n+}\n+\n+static void sleep_ns(__u64 duration)\n+{\n+\tstruct timespec ts = {\n+\t\t.tv_sec = duration / 1000000000ULL,\n+\t\t.tv_nsec = duration % 1000000000ULL,\n+\t};\n+\n+\twhile (nanosleep(\u0026ts, \u0026ts) \u0026\u0026 errno == EINTR)\n+\t\t;\n+}\n+\n+static int waitpid_timeout(pid_t pid, int *status, __u64 timeout)\n+{\n+\t__u64 deadline = monotonic_ns() + timeout;\n+\tint ret;\n+\n+\tdo {\n+\t\tret = waitpid(pid, status, WNOHANG);\n+\t\tif (ret)\n+\t\t\treturn ret;\n+\t\tusleep(1000);\n+\t} while (monotonic_ns() \u003c deadline);\n+\n+\treturn 0;\n+}\n+\n+void test_prog_load_signal(void)\n+{\n+\tstruct bpf_insn *insns = NULL;\n+\t__u64 start, control_time, kill_delay;\n+\tint pipefd[2] = { -1, -1 };\n+\tint prog_fd = -1, status = 0;\n+\tpid_t pid = -1;\n+\tchar byte;\n+\tint i, ret;\n+\n+\tinsns = calloc(NOP_CNT + 2, sizeof(*insns));\n+\tif (!ASSERT_OK_PTR(insns, \"calloc\"))\n+\t\treturn;\n+\n+\tfor (i = 0; i \u003c NOP_CNT; i++)\n+\t\tinsns[i] = BPF_MOV64_REG(BPF_REG_1, BPF_REG_1);\n+\tinsns[NOP_CNT] = BPF_MOV64_IMM(BPF_REG_0, 0);\n+\tinsns[NOP_CNT + 1] = BPF_EXIT_INSN();\n+\n+\tstart = monotonic_ns();\n+\tprog_fd = bpf_prog_load(BPF_PROG_TYPE_SOCKET_FILTER, NULL, \"GPL\",\n+\t\t\t\tinsns, NOP_CNT + 2, NULL);\n+\tcontrol_time = monotonic_ns() - start;\n+\tif (!ASSERT_GE(prog_fd, 0, \"control_prog_load\"))\n+\t\tgoto cleanup;\n+\tclose(prog_fd);\n+\tprog_fd = -1;\n+\n+\tfor (i = 0; i \u003c NOP_CNT; i++)\n+\t\tinsns[i] = BPF_JMP_IMM(BPF_JA, 0, 0, 0);\n+\n+\tif (!ASSERT_OK(pipe(pipefd), \"pipe\"))\n+\t\tgoto cleanup;\n+\n+\tpid = fork();\n+\tif (!ASSERT_GE(pid, 0, \"fork\"))\n+\t\tgoto cleanup;\n+\tif (!pid) {\n+\t\tclose(pipefd[0]);\n+\t\tif (write(pipefd[1], \"x\", 1) != 1)\n+\t\t\t_exit(1);\n+\t\tclose(pipefd[1]);\n+\t\tprog_fd = bpf_prog_load(BPF_PROG_TYPE_SOCKET_FILTER, NULL, \"GPL\",\n+\t\t\t\t\tinsns, NOP_CNT + 2, NULL);\n+\t\tif (prog_fd \u003e= 0)\n+\t\t\tclose(prog_fd);\n+\t\t_exit(prog_fd \u003c 0);\n+\t}\n+\n+\tclose(pipefd[1]);\n+\tpipefd[1] = -1;\n+\tret = read(pipefd[0], \u0026byte, 1);\n+\tif (!ASSERT_EQ(ret, 1, \"child_ready\"))\n+\t\tgoto cleanup;\n+\n+\t/*\n+\t * Allow linear verification to finish before sending SIGKILL. The nop\n+\t * removal pass is quadratic, so four control-load times still leaves a\n+\t * wide window in which an affected kernel is rewriting instructions.\n+\t */\n+\tkill_delay = MAX(control_time * 4, MIN_KILL_DELAY_NS);\n+\tsleep_ns(kill_delay);\n+\tif (!ASSERT_OK(kill(pid, SIGKILL), \"kill\"))\n+\t\tgoto cleanup;\n+\n+\tstart = monotonic_ns();\n+\tret = waitpid_timeout(pid, \u0026status, REAP_TIMEOUT_NS);\n+\tif (!ASSERT_EQ(ret, pid, \"prog_load_killable\")) {\n+\t\tfprintf(stderr, \"control load %llu us, child still alive %llu us after SIGKILL\\n\",\n+\t\t\tcontrol_time / 1000, (monotonic_ns() - start) / 1000);\n+\t\tgoto cleanup;\n+\t}\n+\tpid = -1;\n+\tASSERT_TRUE(WIFSIGNALED(status) \u0026\u0026 WTERMSIG(status) == SIGKILL,\n+\t\t \"killed_by_sigkill\");\n+\n+cleanup:\n+\tif (prog_fd \u003e= 0)\n+\t\tclose(prog_fd);\n+\tif (pipefd[0] \u003e= 0)\n+\t\tclose(pipefd[0]);\n+\tif (pipefd[1] \u003e= 0)\n+\t\tclose(pipefd[1]);\n+\tif (pid \u003e 0) {\n+\t\tkill(pid, SIGKILL);\n+\t\twaitpid(pid, \u0026status, 0);\n+\t}\n+\tfree(insns);\n+}\ndiff --git a/tools/testing/selftests/bpf/prog_tests/verifier.c b/tools/testing/selftests/bpf/prog_tests/verifier.c\nindex 64ac49ad67e63..5c572dd725e75 100644\n--- a/tools/testing/selftests/bpf/prog_tests/verifier.c\n+++ b/tools/testing/selftests/bpf/prog_tests/verifier.c\n@@ -25,6 +25,7 @@\n #include \"verifier_btf_ctx_access.skel.h\"\n #include \"verifier_btf_unreliable_prog.skel.h\"\n #include \"verifier_call_large_imm.skel.h\"\n+#include \"verifier_callback_lock.skel.h\"\n #include \"verifier_cfg.skel.h\"\n #include \"verifier_cgroup_inv_retcode.skel.h\"\n #include \"verifier_cgroup_skb.skel.h\"\n@@ -188,6 +189,7 @@ void test_verifier_bswap(void) { RUN(verifier_bswap); }\n void test_verifier_btf_ctx_access(void) { RUN(verifier_btf_ctx_access); }\n void test_verifier_btf_unreliable_prog(void) { RUN(verifier_btf_unreliable_prog); }\n void test_verifier_call_large_imm(void) { RUN(verifier_call_large_imm); }\n+void test_verifier_callback_lock(void) { RUN(verifier_callback_lock); }\n void test_verifier_cfg(void) { RUN(verifier_cfg); }\n void test_verifier_cgroup_inv_retcode(void) { RUN(verifier_cgroup_inv_retcode); }\n void test_verifier_cgroup_skb(void) { RUN(verifier_cgroup_skb); }\ndiff --git a/tools/testing/selftests/bpf/progs/verifier_callback_lock.c b/tools/testing/selftests/bpf/progs/verifier_callback_lock.c\nnew file mode 100644\nindex 0000000000000..ee09dd66f4678\n--- /dev/null\n+++ b/tools/testing/selftests/bpf/progs/verifier_callback_lock.c\n@@ -0,0 +1,73 @@\n+// SPDX-License-Identifier: GPL-2.0\n+#include \u003clinux/bpf.h\u003e\n+#include \u003cbpf/bpf_helpers.h\u003e\n+#include \"bpf_misc.h\"\n+\n+struct bpf_map;\n+\n+struct lock_value {\n+\tstruct bpf_spin_lock lock;\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 lock_value);\n+} lock_map SEC(\".maps\");\n+\n+struct callback_ctx {\n+\tstruct lock_value *value;\n+};\n+\n+static long lock_different_value(struct bpf_map *map, int *key,\n+\t\t\t\t struct lock_value *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 lock_value *value, void *data)\n+{\n+\tstruct callback_ctx ctx = { .value = value };\n+\n+\tbpf_for_each_map_elem(\u0026lock_map, lock_different_value, \u0026ctx, 0);\n+\treturn 0;\n+}\n+\n+SEC(\"?tc\")\n+__description(\"callback map value has a distinct lock identity\")\n+__failure __msg(\"bpf_spin_unlock of different lock\")\n+int callback_value_lock_identity(void *ctx)\n+{\n+\tbpf_for_each_map_elem(\u0026lock_map, nest_lock_different_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 lock_value *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 lock_value *value, void *data)\n+{\n+\tbpf_for_each_map_elem(\u0026lock_map, lock_same_value, NULL, 0);\n+\treturn 0;\n+}\n+\n+SEC(\"?tc\")\n+__description(\"nested callback can lock its own map value\")\n+__success\n+int callback_value_lock_identity_same(void *ctx)\n+{\n+\tbpf_for_each_map_elem(\u0026lock_map, nest_lock_same_value, NULL, 0);\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..692a8468f3d74 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@@ -5,6 +5,50 @@\n #include \u003cbpf/bpf_helpers.h\u003e\n #include \"bpf_misc.h\"\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)\n+__naked void pkt_regsafe_class_displacement(void)\n+{\n+\tasm volatile (\"\\\n+\tr8 = *(u32 *)(r1 + %[xdp_md_data_end]);\\\n+\tr9 = *(u32 *)(r1 + %[xdp_md_data]);\\\n+\tr6 = r9;\\\n+\tr6 += 8;\\\n+\tif r6 \u003e r8 goto l_exit_%=;\\\n+\tr0 = *(u64 *)(r9 + 0);\\\n+\tr4 = r0;\\\n+\tr4 \u0026= 15;\\\n+\tr7 = r0;\\\n+\tr7 \u003e\u003e= 63;\\\n+\tif r7 != 0 goto l_path_b_%=;\\\n+\tr2 = r9;\\\n+\tr2 += r4;\\\n+\tr3 = r2;\\\n+\tr3 += 4;\\\n+\tgoto l_join_%=;\\\n+l_path_b_%=: \\\n+\tr4 \u0026= 3;\\\n+\tr4 += 8;\\\n+\tr2 = r9;\\\n+\tr2 += r4;\\\n+\tr3 = r2;\\\n+\tr3 -= 4;\\\n+l_join_%=: \\\n+\tr5 = r3;\\\n+\tr5 += 4;\\\n+\tif r5 \u003e r8 goto l_exit_%=;\\\n+\tr0 = *(u64 *)(r2 + 0);\\\n+l_exit_%=: \\\n+\tr0 = 0;\\\n+\texit;\\\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: __clobber_all);\n+}\n+\n SEC(\"xdp\")\n __description(\"XDP pkt read, pkt_end mangling, bad access 1\")\n __failure __msg(\"R3 pointer arithmetic on pkt_end\")\n"
} |
| 2/1 | 2026/09/06 11:23 | agent | patch-evaluator |
0mModel:core Args: null Results: {
"EnableConfigs": [
"BPF_SYSCALL"
],
"FocusSymbols": [
"bpf_check_cfg",
"push_insn",
"bpf_patch_insn_data",
"verifier_remove_insns",
"check_pkt_ptr_ids",
"regsafe",
"bpf_is_state_visited",
"map_set_for_each_callback_args",
"set_timer_callback_state",
"set_task_work_schedule_callback_state"
],
"Reasoning": "The patch touches core BPF verifier execution paths, including control flow graph (CFG) subprogram boundary checks, signal-aware instruction rewriting/removal passes, packet pointer state equivalence comparison (regsafe), and lock identity tracking for callback arguments. These changes are reachable via the bpf(BPF_PROG_LOAD, ...) syscall and directly affect verification correctness and safety invariants.",
"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 62ec2a38e983ba002431ffb5bb17707c7360dce2
Author: syz-cluster <triage@syzkaller.com>
Date: Sun Sep 6 11:23:12 2026 +0000
syz-cluster: applied patch under review
diff --git a/include/linux/bpf_verifier.h b/include/linux/bpf_verifier.h
index 36b65797877d0..5cf92ce185204 100644
--- a/include/linux/bpf_verifier.h
+++ b/include/linux/bpf_verifier.h
@@ -854,6 +854,8 @@ struct backtrack_state {
struct bpf_id_pair {
u32 old;
u32 cur;
+ s32 pkt_ptr_delta;
+ bool pkt_ptr_delta_set;
};
struct bpf_idmap {
diff --git a/kernel/bpf/cfg.c b/kernel/bpf/cfg.c
index 842c7d1eabccc..e3c904328ede0 100644
--- a/kernel/bpf/cfg.c
+++ b/kernel/bpf/cfg.c
@@ -102,6 +102,7 @@ enum {
*/
static int push_insn(int t, int w, int e, struct bpf_verifier_env *env)
{
+ struct bpf_subprog_info *subprog;
int *insn_stack = env->cfg.insn_stack;
int *insn_state = env->cfg.insn_state;
@@ -121,6 +122,26 @@ static int push_insn(int t, int w, int e, struct bpf_verifier_env *env)
return -EINVAL;
}
+ /*
+ * check_subprogs() prevents control flow from falling through a
+ * subprogram boundary, but runs before CO-RE relocations can rewrite an
+ * instruction. Reestablish the invariant on the final instruction stream
+ * before constructing the CFG used by later per-subprogram passes.
+ */
+ if (e == FALLTHROUGH) {
+ subprog = bpf_find_containing_subprog(env, t);
+ if (w < subprog->start || w >= (subprog + 1)->start) {
+ verbose_linfo(env, t, "%d: ", t);
+ verbose(env, "fall-through out of subprog from insn %d to %d\n", t, w);
+ bpf_diag_program_structure(
+ env, t, "fall-through leaves subprogram",
+ "Keep fall-through control flow inside the current subprogram.",
+ "Instruction %d falls through to instruction %d outside its subprogram.",
+ t, w);
+ return -EINVAL;
+ }
+ }
+
if (e == BRANCH) {
/* mark branch target for state pruning */
mark_prune_point(env, w);
diff --git a/kernel/bpf/fixups.c b/kernel/bpf/fixups.c
index 52d3cec336727..9401fffcedfd6 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);
@@ -2666,4 +2686,3 @@ int bpf_remove_fastcall_spills_fills(struct bpf_verifier_env *env)
return 0;
}
-
diff --git a/kernel/bpf/states.c b/kernel/bpf/states.c
index 66fb11b6c6a76..2f8f3fe164b01 100644
--- a/kernel/bpf/states.c
+++ b/kernel/bpf/states.c
@@ -339,6 +339,7 @@ static bool check_ids(u32 old_id, u32 cur_id, struct bpf_idmap *idmap)
if (idmap->cnt < BPF_ID_MAP_SIZE) {
map[idmap->cnt].old = old_id;
map[idmap->cnt].cur = cur_id;
+ map[idmap->cnt].pkt_ptr_delta_set = false;
idmap->cnt++;
return true;
}
@@ -352,6 +353,43 @@ static bool check_ids(u32 old_id, u32 cur_id, struct bpf_idmap *idmap)
return false;
}
+static bool check_pkt_ptr_ids(const struct bpf_reg_state *old,
+ const struct bpf_reg_state *cur,
+ struct bpf_idmap *idmap)
+{
+ struct bpf_id_pair *map = idmap->map;
+ s64 delta;
+ unsigned int i;
+
+ if (!check_ids(old->id, cur->id, idmap))
+ return false;
+ if (!old->id)
+ return true;
+
+ /*
+ * Packet range is shared by all pointers with the same ID. Preserve
+ * their relative displacement, while allowing the whole class to move.
+ * Packet pointer offsets are bounded by BPF_MAX_VAR_OFF, so the delta
+ * between two valid offsets fits in s32.
+ */
+ delta = (s64)(cur->r64.base - old->r64.base);
+ if (delta < S32_MIN || delta > S32_MAX)
+ return false;
+
+ for (i = 0; i < idmap->cnt; i++) {
+ if (map[i].old != old->id)
+ continue;
+ if (!map[i].pkt_ptr_delta_set) {
+ map[i].pkt_ptr_delta = delta;
+ map[i].pkt_ptr_delta_set = true;
+ return true;
+ }
+ return map[i].pkt_ptr_delta == delta;
+ }
+
+ return false;
+}
+
/*
* Compare scalar register IDs for state equivalence.
*
@@ -632,8 +670,8 @@ static bool regsafe(struct bpf_verifier_env *env, struct bpf_reg_state *rold,
} else if (rold->range > rcur->range) {
return false;
}
- /* id relations must be preserved */
- if (!check_ids(rold->id, rcur->id, idmap))
+ /* id relations and intra-class displacement must be preserved */
+ if (!check_pkt_ptr_ids(rold, rcur, idmap))
return false;
/* new val must satisfy old val knowledge */
return range_within(rold, rcur) &&
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index 1c3039f3fc323..b08501734ddfa 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -447,6 +447,11 @@ static bool reg_may_point_to_spin_lock(const struct bpf_reg_state *reg)
return btf_record_has_field(reg_btf_record(reg), BPF_SPIN_LOCK | BPF_RES_SPIN_LOCK);
}
+static bool map_value_has_static_identity(const struct bpf_map *map)
+{
+ return map->map_type == BPF_MAP_TYPE_ARRAY && map->max_entries == 1;
+}
+
static bool type_is_rdonly_mem(u32 type)
{
return type & MEM_RDONLY;
@@ -10035,6 +10040,9 @@ 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;
+ if (reg_may_point_to_spin_lock(&callee->regs[BPF_REG_3]) &&
+ !map_value_has_static_identity(callee->regs[BPF_REG_3].map_ptr))
+ callee->regs[BPF_REG_3].id = ++env->id_gen;
/* pointer to stack or null */
callee->regs[BPF_REG_4] = caller->regs[BPF_REG_3];
@@ -10131,6 +10139,9 @@ 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;
+ if (reg_may_point_to_spin_lock(&callee->regs[BPF_REG_3]) &&
+ !map_value_has_static_identity(callee->regs[BPF_REG_3].map_ptr))
+ callee->regs[BPF_REG_3].id = ++env->id_gen;
/* unused */
bpf_mark_reg_not_init(env, &callee->regs[BPF_REG_4]);
@@ -10249,6 +10260,9 @@ 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;
+ if (reg_may_point_to_spin_lock(&callee->regs[BPF_REG_3]) &&
+ !map_value_has_static_identity(callee->regs[BPF_REG_3].map_ptr))
+ callee->regs[BPF_REG_3].id = ++env->id_gen;
/* unused */
bpf_mark_reg_not_init(env, &callee->regs[BPF_REG_4]);
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..c350fbb958455 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,117 @@
static char log[16 * 1024];
+static int load_core_relo_subprog(int btf_fd, int main_id, int sub_id,
+ int enum_id, int access_str_off, bool relocate)
+{
+ struct bpf_insn insns[] = {
+ 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[] = {
+ { .insn_off = 0, .type_id = main_id },
+ { .insn_off = 3, .type_id = sub_id },
+ };
+ struct bpf_core_relo relo = {
+ .insn_off = 2 * 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 = ARRAY_SIZE(insns),
+ .insns = (__u64)insns,
+ .license = (__u64)"GPL",
+ .log_buf = (__u64)log,
+ .log_size = sizeof(log),
+ .log_level = 1,
+ .prog_btf_fd = btf_fd,
+ .func_info_rec_size = sizeof(struct bpf_func_info),
+ .func_info = (__u64)funcs,
+ .func_info_cnt = ARRAY_SIZE(funcs),
+ };
+
+ 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_poisoned_subprog_terminator(void)
+{
+ const void *raw_btf;
+ struct btf *btf = NULL;
+ __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;
+
+ 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_subprog_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;
+
+ /* The same two-subprogram program is valid before the relocation. */
+ prog_fd = load_core_relo_subprog(btf_fd, main_id, sub_id, enum_id,
+ access_str_off, false);
+ if (!ASSERT_GE(prog_fd, 0, "control_load"))
+ goto cleanup;
+ close(prog_fd);
+ prog_fd = -1;
+
+ /*
+ * Poison the first subprogram's terminal exit. The verifier must reject
+ * the resulting control flow across the subprogram boundary in the CFG.
+ */
+ prog_fd = load_core_relo_subprog(btf_fd, main_id, sub_id, enum_id,
+ access_str_off, true);
+ if (!ASSERT_LT(prog_fd, 0, "poisoned_load"))
+ goto cleanup;
+ ASSERT_HAS_SUBSTR(log, "fall-through out of subprog from insn 2 to 3",
+ "poisoned_load_log");
+
+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 +231,8 @@ static void test_bad_local_id(void)
void test_core_reloc_raw(void)
{
+ if (test__start_subtest("poisoned_subprog_terminator"))
+ test_poisoned_subprog_terminator();
if (test__start_subtest("bad_local_id"))
test_bad_local_id();
}
diff --git a/tools/testing/selftests/bpf/prog_tests/prog_load_signal.c b/tools/testing/selftests/bpf/prog_tests/prog_load_signal.c
new file mode 100644
index 0000000000000..0f78db3bccc76
--- /dev/null
+++ b/tools/testing/selftests/bpf/prog_tests/prog_load_signal.c
@@ -0,0 +1,131 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (c) 2026 Meta Platforms, Inc. and affiliates. */
+#include <test_progs.h>
+
+#define NOP_CNT 32768
+#define MIN_KILL_DELAY_NS (100ULL * 1000 * 1000)
+#define REAP_TIMEOUT_NS (1000ULL * 1000 * 1000)
+
+static __u64 monotonic_ns(void)
+{
+ struct timespec ts;
+
+ clock_gettime(CLOCK_MONOTONIC, &ts);
+ return ts.tv_sec * 1000000000ULL + ts.tv_nsec;
+}
+
+static void sleep_ns(__u64 duration)
+{
+ struct timespec ts = {
+ .tv_sec = duration / 1000000000ULL,
+ .tv_nsec = duration % 1000000000ULL,
+ };
+
+ while (nanosleep(&ts, &ts) && errno == EINTR)
+ ;
+}
+
+static int waitpid_timeout(pid_t pid, int *status, __u64 timeout)
+{
+ __u64 deadline = monotonic_ns() + timeout;
+ int ret;
+
+ do {
+ ret = waitpid(pid, status, WNOHANG);
+ if (ret)
+ return ret;
+ usleep(1000);
+ } while (monotonic_ns() < deadline);
+
+ return 0;
+}
+
+void test_prog_load_signal(void)
+{
+ struct bpf_insn *insns = NULL;
+ __u64 start, control_time, kill_delay;
+ int pipefd[2] = { -1, -1 };
+ int prog_fd = -1, status = 0;
+ pid_t pid = -1;
+ char byte;
+ int i, ret;
+
+ insns = calloc(NOP_CNT + 2, sizeof(*insns));
+ if (!ASSERT_OK_PTR(insns, "calloc"))
+ return;
+
+ for (i = 0; i < NOP_CNT; i++)
+ insns[i] = BPF_MOV64_REG(BPF_REG_1, BPF_REG_1);
+ insns[NOP_CNT] = BPF_MOV64_IMM(BPF_REG_0, 0);
+ insns[NOP_CNT + 1] = BPF_EXIT_INSN();
+
+ start = monotonic_ns();
+ prog_fd = bpf_prog_load(BPF_PROG_TYPE_SOCKET_FILTER, NULL, "GPL",
+ insns, NOP_CNT + 2, NULL);
+ control_time = monotonic_ns() - start;
+ if (!ASSERT_GE(prog_fd, 0, "control_prog_load"))
+ goto cleanup;
+ close(prog_fd);
+ prog_fd = -1;
+
+ for (i = 0; i < NOP_CNT; i++)
+ insns[i] = BPF_JMP_IMM(BPF_JA, 0, 0, 0);
+
+ if (!ASSERT_OK(pipe(pipefd), "pipe"))
+ goto cleanup;
+
+ pid = fork();
+ if (!ASSERT_GE(pid, 0, "fork"))
+ goto cleanup;
+ if (!pid) {
+ close(pipefd[0]);
+ if (write(pipefd[1], "x", 1) != 1)
+ _exit(1);
+ close(pipefd[1]);
+ prog_fd = bpf_prog_load(BPF_PROG_TYPE_SOCKET_FILTER, NULL, "GPL",
+ insns, NOP_CNT + 2, NULL);
+ if (prog_fd >= 0)
+ close(prog_fd);
+ _exit(prog_fd < 0);
+ }
+
+ close(pipefd[1]);
+ pipefd[1] = -1;
+ ret = read(pipefd[0], &byte, 1);
+ if (!ASSERT_EQ(ret, 1, "child_ready"))
+ goto cleanup;
+
+ /*
+ * Allow linear verification to finish before sending SIGKILL. The nop
+ * removal pass is quadratic, so four control-load times still leaves a
+ * wide window in which an affected kernel is rewriting instructions.
+ */
+ kill_delay = MAX(control_time * 4, MIN_KILL_DELAY_NS);
+ sleep_ns(kill_delay);
+ if (!ASSERT_OK(kill(pid, SIGKILL), "kill"))
+ goto cleanup;
+
+ start = monotonic_ns();
+ ret = waitpid_timeout(pid, &status, REAP_TIMEOUT_NS);
+ if (!ASSERT_EQ(ret, pid, "prog_load_killable")) {
+ fprintf(stderr, "control load %llu us, child still alive %llu us after SIGKILL\n",
+ control_time / 1000, (monotonic_ns() - start) / 1000);
+ goto cleanup;
+ }
+ pid = -1;
+ ASSERT_TRUE(WIFSIGNALED(status) && WTERMSIG(status) == SIGKILL,
+ "killed_by_sigkill");
+
+cleanup:
+ if (prog_fd >= 0)
+ close(prog_fd);
+ if (pipefd[0] >= 0)
+ close(pipefd[0]);
+ if (pipefd[1] >= 0)
+ close(pipefd[1]);
+ if (pid > 0) {
+ kill(pid, SIGKILL);
+ waitpid(pid, &status, 0);
+ }
+ free(insns);
+}
diff --git a/tools/testing/selftests/bpf/prog_tests/verifier.c b/tools/testing/selftests/bpf/prog_tests/verifier.c
index 64ac49ad67e63..5c572dd725e75 100644
--- a/tools/testing/selftests/bpf/prog_tests/verifier.c
+++ b/tools/testing/selftests/bpf/prog_tests/verifier.c
@@ -25,6 +25,7 @@
#include "verifier_btf_ctx_access.skel.h"
#include "verifier_btf_unreliable_prog.skel.h"
#include "verifier_call_large_imm.skel.h"
+#include "verifier_callback_lock.skel.h"
#include "verifier_cfg.skel.h"
#include "verifier_cgroup_inv_retcode.skel.h"
#include "verifier_cgroup_skb.skel.h"
@@ -188,6 +189,7 @@ void test_verifier_bswap(void) { RUN(verifier_bswap); }
void test_verifier_btf_ctx_access(void) { RUN(verifier_btf_ctx_access); }
void test_verifier_btf_unreliable_prog(void) { RUN(verifier_btf_unreliable_prog); }
void test_verifier_call_large_imm(void) { RUN(verifier_call_large_imm); }
+void test_verifier_callback_lock(void) { RUN(verifier_callback_lock); }
void test_verifier_cfg(void) { RUN(verifier_cfg); }
void test_verifier_cgroup_inv_retcode(void) { RUN(verifier_cgroup_inv_retcode); }
void test_verifier_cgroup_skb(void) { RUN(verifier_cgroup_skb); }
diff --git a/tools/testing/selftests/bpf/progs/verifier_callback_lock.c b/tools/testing/selftests/bpf/progs/verifier_callback_lock.c
new file mode 100644
index 0000000000000..ee09dd66f4678
--- /dev/null
+++ b/tools/testing/selftests/bpf/progs/verifier_callback_lock.c
@@ -0,0 +1,73 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <linux/bpf.h>
+#include <bpf/bpf_helpers.h>
+#include "bpf_misc.h"
+
+struct bpf_map;
+
+struct lock_value {
+ struct bpf_spin_lock lock;
+};
+
+struct {
+ __uint(type, BPF_MAP_TYPE_ARRAY);
+ __uint(max_entries, 2);
+ __type(key, int);
+ __type(value, struct lock_value);
+} lock_map SEC(".maps");
+
+struct callback_ctx {
+ struct lock_value *value;
+};
+
+static long lock_different_value(struct bpf_map *map, int *key,
+ struct lock_value *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 lock_value *value, void *data)
+{
+ struct callback_ctx ctx = { .value = value };
+
+ bpf_for_each_map_elem(&lock_map, lock_different_value, &ctx, 0);
+ return 0;
+}
+
+SEC("?tc")
+__description("callback map value has a distinct lock identity")
+__failure __msg("bpf_spin_unlock of different lock")
+int callback_value_lock_identity(void *ctx)
+{
+ bpf_for_each_map_elem(&lock_map, nest_lock_different_value, NULL, 0);
+ return 0;
+}
+
+static long lock_same_value(struct bpf_map *map, int *key,
+ struct lock_value *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 lock_value *value, void *data)
+{
+ bpf_for_each_map_elem(&lock_map, lock_same_value, NULL, 0);
+ return 0;
+}
+
+SEC("?tc")
+__description("nested callback can lock its own map value")
+__success
+int callback_value_lock_identity_same(void *ctx)
+{
+ bpf_for_each_map_elem(&lock_map, nest_lock_same_value, NULL, 0);
+ 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..692a8468f3d74 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
@@ -5,6 +5,50 @@
#include <bpf/bpf_helpers.h>
#include "bpf_misc.h"
+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)
+__naked void pkt_regsafe_class_displacement(void)
+{
+ asm volatile ("\
+ r8 = *(u32 *)(r1 + %[xdp_md_data_end]);\
+ r9 = *(u32 *)(r1 + %[xdp_md_data]);\
+ r6 = r9;\
+ r6 += 8;\
+ if r6 > r8 goto l_exit_%=;\
+ r0 = *(u64 *)(r9 + 0);\
+ r4 = r0;\
+ r4 &= 15;\
+ r7 = r0;\
+ r7 >>= 63;\
+ if r7 != 0 goto l_path_b_%=;\
+ r2 = r9;\
+ r2 += r4;\
+ r3 = r2;\
+ r3 += 4;\
+ goto l_join_%=;\
+l_path_b_%=: \
+ r4 &= 3;\
+ r4 += 8;\
+ r2 = r9;\
+ r2 += r4;\
+ r3 = r2;\
+ r3 -= 4;\
+l_join_%=: \
+ r5 = r3;\
+ r5 += 4;\
+ if r5 > r8 goto l_exit_%=;\
+ r0 = *(u64 *)(r2 + 0);\
+l_exit_%=: \
+ 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))
+ : __clobber_all);
+}
+
SEC("xdp")
__description("XDP pkt read, pkt_end mangling, bad access 1")
__failure __msg("R3 pointer arithmetic on pkt_end")
|
| 3/2 | 2026/09/06 11:23 | llm | patch-evaluator |
0mModel:gemini-3.7-flash Args: null Results: null Tokens: input: 11513 output: 38 thoughts: 503 Thoughts: **Analyzing the BPF Patch Series for Syzkaller Fuzzing** Okay, let's dive into this patch series. My initial thought is to figure out if this warrants a syzkaller fuzzing campaign for the amd64 target. First, I need to understand what's actually changed. I'm seeing additions to `bpf_id_pair` in `bpf_verifier.h` and modifications across several core BPF files: `cfg.c`, `fixups.c`, `states.c`, and `verifier.c`. The additions of `s32 pkt_ptr_delta; bool pkt_ptr_delta_set;` in `bpf_id_pair` seem like a potential pointer-related change, which always raises a flag. Then, modifications to `push_insn()` in `cfg.c` with fallthrough checks look interesting. `fixups.c` now includes a `bpf_rewrite_must_abort()` function with checks for `fatal_signal_pending` and `cond_resched()`, indicating potential interruption mechanisms. `states.c` introduces `check_pkt_ptr_ids()`, so we're seeing more pointer handling. Finally, `verifier.c` includes a `map_value_has_static_identity()` function that is used in multiple places including setting register ids. Now, the important question: Does this patch modify executable kernel code that's reachable? Absolutely. We're talking about the BPF subsystem, which is core and directly accessible via the `bpf()` syscall. Changes to the verifier are always prime targets for fuzzing. The BPF verifier is notorious for having subtle flaws, and these changes seem to touch on critical areas. My gut feeling is that this is absolutely worth fuzzing. The changes are concentrated, the subsystem is important, and pointer/state/control-flow modifications are strong indicators. Now, I need to pinpoint the relevant kernel configurations and maybe some key symbols related to these new changes. I’ll use `grepper` or check the Kconfig files for the kernel/bpf files to get that information. I'm ready to craft some good syzkaller configurations based on these findings. |
| 4/2 | 2026/09/06 11:23 | tool | grepper |
0mArgs:{
"Expression": "obj-\\$\\(CONFIG_BPF_SYSCALL\\)",
"PathPrefix": "kernel/bpf/"
}Results: {
"Output": "kernel/bpf/Makefile=7=CFLAGS_core.o += -Wno-override-init $(cflags-nogcse-yy)\nkernel/bpf/Makefile-8-\nkernel/bpf/Makefile:9:obj-$(CONFIG_BPF_SYSCALL) += syscall.o verifier.o inode.o helpers.o tnum.o cnum.o log.o token.o liveness.o const_fold.o diagnostics.o\nkernel/bpf/Makefile:10:obj-$(CONFIG_BPF_SYSCALL) += bpf_iter.o map_iter.o task_iter.o prog_iter.o link_iter.o\nkernel/bpf/Makefile:11:obj-$(CONFIG_BPF_SYSCALL) += hashtab.o arraymap.o percpu_freelist.o bpf_lru_list.o lpm_trie.o map_in_map.o bloom_filter.o\nkernel/bpf/Makefile:12:obj-$(CONFIG_BPF_SYSCALL) += local_storage.o queue_stack_maps.o ringbuf.o bpf_insn_array.o\nkernel/bpf/Makefile:13:obj-$(CONFIG_BPF_SYSCALL) += bpf_local_storage.o bpf_task_storage.o\nkernel/bpf/Makefile:14:obj-$(CONFIG_BPF_SYSCALL) += fixups.o cfg.o states.o backtrack.o check_btf.o\nkernel/bpf/Makefile-15-obj-${CONFIG_BPF_LSM}\t += bpf_inode_storage.o\nkernel/bpf/Makefile:16:obj-$(CONFIG_BPF_SYSCALL) += disasm.o mprog.o\nkernel/bpf/Makefile-17-obj-$(CONFIG_BPF_JIT) += trampoline.o\nkernel/bpf/Makefile:18:obj-$(CONFIG_BPF_SYSCALL) += btf.o memalloc.o rqspinlock.o stream.o\nkernel/bpf/Makefile-19-ifeq ($(CONFIG_MMU)$(CONFIG_64BIT),yy)\nkernel/bpf/Makefile:20:obj-$(CONFIG_BPF_SYSCALL) += arena.o range_tree.o\nkernel/bpf/Makefile-21-endif\n--\nkernel/bpf/Makefile=23=ifeq ($(CONFIG_NET),y)\nkernel/bpf/Makefile:24:obj-$(CONFIG_BPF_SYSCALL) += devmap.o\nkernel/bpf/Makefile:25:obj-$(CONFIG_BPF_SYSCALL) += cpumap.o\nkernel/bpf/Makefile:26:obj-$(CONFIG_BPF_SYSCALL) += offload.o\nkernel/bpf/Makefile:27:obj-$(CONFIG_BPF_SYSCALL) += net_namespace.o\nkernel/bpf/Makefile:28:obj-$(CONFIG_BPF_SYSCALL) += tcx.o\nkernel/bpf/Makefile-29-endif\nkernel/bpf/Makefile=30=ifeq ($(CONFIG_PERF_EVENTS),y)\nkernel/bpf/Makefile:31:obj-$(CONFIG_BPF_SYSCALL) += stackmap.o\nkernel/bpf/Makefile-32-endif\nkernel/bpf/Makefile=33=ifeq ($(CONFIG_CGROUPS),y)\nkernel/bpf/Makefile:34:obj-$(CONFIG_BPF_SYSCALL) += cgroup_iter.o bpf_cgrp_storage.o\nkernel/bpf/Makefile-35-endif\n--\nkernel/bpf/Makefile=37=ifeq ($(CONFIG_INET),y)\nkernel/bpf/Makefile:38:obj-$(CONFIG_BPF_SYSCALL) += reuseport_array.o\nkernel/bpf/Makefile-39-endif\n--\nkernel/bpf/Makefile=43=ifeq ($(CONFIG_BPF_JIT),y)\nkernel/bpf/Makefile:44:obj-$(CONFIG_BPF_SYSCALL) += bpf_struct_ops.o\nkernel/bpf/Makefile:45:obj-$(CONFIG_BPF_SYSCALL) += cpumask.o\nkernel/bpf/Makefile-46-# bpf_lsm_proto.o must precede bpf_lsm.o. The current pahole logic\n--\nkernel/bpf/Makefile=58=ifneq ($(CONFIG_CRYPTO),)\nkernel/bpf/Makefile:59:obj-$(CONFIG_BPF_SYSCALL) += crypto.o\nkernel/bpf/Makefile-60-endif\nkernel/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\nkernel/bpf/Makefile:65:obj-$(CONFIG_BPF_SYSCALL) += btf_relocate.o\nkernel/bpf/Makefile:66:obj-$(CONFIG_BPF_SYSCALL) += kmem_cache_iter.o\nkernel/bpf/Makefile-67-ifeq ($(CONFIG_DMA_SHARED_BUFFER),y)\nkernel/bpf/Makefile:68:obj-$(CONFIG_BPF_SYSCALL) += dmabuf_iter.o\nkernel/bpf/Makefile-69-endif\n"
} |
| 5/2 | 2026/09/06 11:23 | llm | patch-evaluator |
0mModel:gemini-3.7-flash Args: null Results: null Tokens: input: 13872 output: 31 thoughts: 15 Thoughts: Here's my attempt at summarizing the thought process, tailored for an expert audience: **Investigating BPF_SYSCALL Dependencies in Kconfig** Okay, so I need to understand the configuration dependencies for `BPF_SYSCALL`. I'm going to dive into the Kconfig files now. My initial goal is to identify any pre-requisites that would affect the availability of BPF syscall functionality. I'm thinking about things like other BPF-related configurations, potentially kernel hardening options, or even architecture-specific settings that might influence whether `BPF_SYSCALL` is even *present* as a configuration option. I'll need to trace through the relevant `depends on` statements and ensure I haven't missed anything. I'll pay close attention to the hierarchy and how different features interact with it. The objective is to ensure the configurations are consistent for my environment. |
| 6/2 | 2026/09/06 11:23 | tool | grepper |
0mError:no matches Args: {
"Expression": "config BPF_SYSCALL",
"PathPrefix": "init/Kconfig"
}Results: {
"error": "no matches"
} |
| 7/2 | 2026/09/06 11:23 | llm | patch-evaluator |
0mModel:gemini-3.7-flash Args: null Results: null Tokens: input: 14120 output: 21 thoughts: 17 Thoughts: Here's my attempt at summarizing the thought process, tailored for an expert audience: **Investigating `config BPF_SYSCALL`** Alright, let's track down the definition of `config BPF_SYSCALL`. I need to figure out where this is actually set. I'm going to dig into the kernel configuration files. My immediate thought is to start with the Kconfig files, likely within the architecture or feature directories. I’ll probably need to use `find` combined with `grep` (or possibly `ack` or `ripgrep` for speed) to locate it efficiently. I'll be looking for where this symbol is either explicitly defined or referenced within dependency expressions. I'll need to pay close attention to the surrounding context to understand its purpose and possible implications. Knowing this will give insight into the functionality guarded by that config, and how to enable/disable it. I'll also be mindful of any potential dependencies on other configurations or features – that's often where the real subtlety lies. |
| 8/2 | 2026/09/06 11:23 | tool | grepper |
0mArgs:{
"Expression": "config BPF_SYSCALL"
}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"
} |
| 9/2 | 2026/09/06 11:23 | llm | patch-evaluator |
0mModel:gemini-3.7-flash Args: null Results: null Tokens: input: 14457 output: 34 thoughts: 20 Thoughts: Here's my take on those thoughts, tailored for an expert audience: **Kernel BPF Kconfig Dependency Check** Okay, so I'm thinking, before I dive too deep into this BPF situation, I need to ground myself in the kernel configuration. Line 25 of `kernel/bpf/Kconfig` specifically... that's probably where the key dependencies for the BPF subsystem are declared. I want to check how the BPF features are gated by other configurations. I'm assuming that it’s probably a good starting point to confirm assumptions about the base requirements, and any dependencies on things like security models, CPU architecture features or other subsystems are clearly specified. I can check this quickly. I need to make sure I understand the conditional compilation paths before going further. This'll help me avoid wasting time later on by chasing down red herrings related to unmet prerequisites. Let’s do it. |
| 10/2 | 2026/09/06 11:23 | tool | read-file |
0mArgs:{
"File": "kernel/bpf/Kconfig",
"FirstLine": 25,
"LineCount": 40
}Results: {
"Contents": " 25:\tmenu \"BPF subsystem\"\n 26:\t\n 27:\tconfig BPF_SYSCALL\n 28:\t\tbool \"Enable bpf() system call\"\n 29:\t\tselect BPF\n 30:\t\tselect IRQ_WORK\n 31:\t\tselect NEED_TASKS_RCU\n 32:\t\tselect TASKS_TRACE_RCU\n 33:\t\tselect BINARY_PRINTF\n 34:\t\tselect NET_SOCK_MSG if NET\n 35:\t\tselect NET_XGRESS if NET\n 36:\t\tselect PAGE_POOL if NET\n 37:\t\tdefault n\n 38:\t\thelp\n 39:\t\t Enable the bpf() system call that allows to manipulate BPF programs\n 40:\t\t and maps via file descriptors.\n 41:\t\n 42:\tconfig BPF_JIT\n 43:\t\tbool \"Enable BPF Just In Time compiler\"\n 44:\t\tdepends on BPF\n 45:\t\tdepends on HAVE_CBPF_JIT || HAVE_EBPF_JIT\n 46:\t\tselect EXECMEM\n 47:\t\thelp\n 48:\t\t BPF programs are normally handled by a BPF interpreter. This option\n 49:\t\t allows the kernel to generate native code when a program is loaded\n 50:\t\t into the kernel. This will significantly speed-up processing of BPF\n 51:\t\t programs.\n 52:\t\n 53:\t\t Note, an admin should enable this feature changing:\n 54:\t\t /proc/sys/net/core/bpf_jit_enable\n 55:\t\t /proc/sys/net/core/bpf_jit_harden (optional)\n 56:\t\t /proc/sys/net/core/bpf_jit_kallsyms (optional)\n 57:\t\n 58:\tconfig BPF_JIT_ALWAYS_ON\n 59:\t\tbool \"Permanently enable BPF JIT and remove BPF interpreter\"\n 60:\t\tdepends on BPF_SYSCALL \u0026\u0026 HAVE_EBPF_JIT \u0026\u0026 BPF_JIT\n 61:\t\thelp\n 62:\t\t Enables BPF JIT and removes BPF interpreter to avoid speculative\n 63:\t\t execution of BPF instructions by the interpreter.\n 64:\t\n"
} |
| 11/2 | 2026/09/06 11:23 | llm | patch-evaluator |
0mModel:gemini-3.7-flash Args: null Results: null Tokens: input: 15286 output: 32 thoughts: 181 Thoughts: **Analyzing the BPF Patch** Alright, let's dive into this patch and understand the modifications. My initial focus is on the file and symbol changes. It looks like we have two key areas: First, in `include/linux/bpf_verifier.h`, there's a modification to the `struct bpf_id_pair`. A new field, `pkt_ptr_delta`, a signed 32-bit integer, and a boolean flag `pkt_ptr_delta_set` have been introduced. This suggests we're dealing with pointer delta calculations within the BPF context, probably related to packet data manipulation. My immediate thought is this impacts how we track and manage offsets within the packet buffer. The addition of a boolean flag suggests conditional usage, implying this delta isn't always relevant. It'll be interesting to see how this interacts with other parts of the verifier. Then, looking at `kernel/bpf/cfg.c`, the `push_insn` function has been changed. Specifically, there's a boundary check related to fallthrough (`e == FALLTHROUGH`). That catches my eye. We're explicitly guarding against something when we're dealing with a fallthrough scenario, which is usually a critical path for control flow. I need to understand what this check prevents. To do that, I'll need to figure out the context of `push_insn`. I'll have to quickly check where this function is called from within `kernel/bpf/cfg.c`. I need to understand how the code is structured and how this specific check will affect the overall BPF verifier behavior. I suspect it's preventing some kind of potentially invalid state during instruction push operations within the BPF control flow graph. |
| 12/2 | 2026/09/06 11:23 | tool | grepper |
0mArgs:{
"Expression": "push_insn",
"PathPrefix": "kernel/bpf/cfg.c"
}Results: {
"Output": "kernel/bpf/cfg.c=93=enum {\n--\nkernel/bpf/cfg.c-102- */\nkernel/bpf/cfg.c:103:static int push_insn(int t, int w, int e, struct bpf_verifier_env *env)\nkernel/bpf/cfg.c-104-{\n--\nkernel/bpf/cfg.c=182=static int visit_func_call_insn(int t, struct bpf_insn *insns,\n--\nkernel/bpf/cfg.c-189-\tinsn_sz = bpf_is_ldimm64(\u0026insns[t]) ? 2 : 1;\nkernel/bpf/cfg.c:190:\tret = push_insn(t, t + insn_sz, FALLTHROUGH, env);\nkernel/bpf/cfg.c-191-\tif (ret)\n--\nkernel/bpf/cfg.c-201-\t\tmerge_callee_effects(env, t, w);\nkernel/bpf/cfg.c:202:\t\tret = push_insn(t, w, BRANCH, env);\nkernel/bpf/cfg.c-203-\t}\n--\nkernel/bpf/cfg.c=474=static int visit_insn(int t, struct bpf_verifier_env *env)\n--\nkernel/bpf/cfg.c-492-\t\tinsn_sz = bpf_is_ldimm64(insn) ? 2 : 1;\nkernel/bpf/cfg.c:493:\t\treturn push_insn(t, t + insn_sz, FALLTHROUGH, env);\nkernel/bpf/cfg.c-494-\t}\n--\nkernel/bpf/cfg.c-583-\t\t/* unconditional jump with single edge */\nkernel/bpf/cfg.c:584:\t\tret = push_insn(t, t + off + 1, FALLTHROUGH, env);\nkernel/bpf/cfg.c-585-\t\tif (ret)\n--\nkernel/bpf/cfg.c-599-\nkernel/bpf/cfg.c:600:\t\tret = push_insn(t, t + 1, FALLTHROUGH, env);\nkernel/bpf/cfg.c-601-\t\tif (ret)\n--\nkernel/bpf/cfg.c-603-\nkernel/bpf/cfg.c:604:\t\treturn push_insn(t, t + insn-\u003eoff + 1, BRANCH, env);\nkernel/bpf/cfg.c-605-\t}\n"
} |
| 13/2 | 2026/09/06 11:23 | llm | patch-evaluator |
0mModel:gemini-3.7-flash Args: null Results: null Tokens: input: 16536 output: 38 thoughts: 13 Thoughts: Here's my attempt at summarizing the thought process, tailored for an expert audience: **Entry Point Analysis in `cfg.c`** Okay, so I'm diving into `cfg.c` and immediately, I'm thinking about the entry points. Where does the execution begin, and what functions are the core, the building blocks? I need to quickly identify the key functions that handle the configuration loading, parsing, and application. I'm going to look for the obvious candidates: initialization functions, parsing routines, and functions responsible for interacting with the configuration data structures. I'll be paying close attention to any external dependencies as well – calls to other modules or libraries that are crucial for the proper operation of the module. Understanding how `cfg.c` interfaces with the rest of the system is just as important as the internals of the module itself. |
| 14/2 | 2026/09/06 11:23 | tool | grepper |
0mArgs:{
"Expression": "^[a-zA-Z_].*\\(",
"PathPrefix": "kernel/bpf/cfg.c"
}Results: {
"Output": "kernel/bpf/cfg.c=45=enum {\n--\nkernel/bpf/cfg.c-51-\nkernel/bpf/cfg.c:52:static void mark_subprog_changes_pkt_data(struct bpf_verifier_env *env, int off)\nkernel/bpf/cfg.c-53-{\n--\nkernel/bpf/cfg.c-59-\nkernel/bpf/cfg.c:60:static void mark_subprog_might_sleep(struct bpf_verifier_env *env, int off)\nkernel/bpf/cfg.c-61-{\n--\nkernel/bpf/cfg.c-67-\nkernel/bpf/cfg.c:68:static void mark_subprog_might_throw(struct bpf_verifier_env *env, int off)\nkernel/bpf/cfg.c-69-{\n--\nkernel/bpf/cfg.c-81- */\nkernel/bpf/cfg.c:82:static void merge_callee_effects(struct bpf_verifier_env *env, int t, int w)\nkernel/bpf/cfg.c-83-{\n--\nkernel/bpf/cfg.c=93=enum {\n--\nkernel/bpf/cfg.c-102- */\nkernel/bpf/cfg.c:103:static int push_insn(int t, int w, int e, struct bpf_verifier_env *env)\nkernel/bpf/cfg.c-104-{\n--\nkernel/bpf/cfg.c-181-\nkernel/bpf/cfg.c:182:static int visit_func_call_insn(int t, struct bpf_insn *insns,\nkernel/bpf/cfg.c-183-\t\t\t\tstruct bpf_verifier_env *env,\n--\nkernel/bpf/cfg.c-206-\nkernel/bpf/cfg.c:207:struct bpf_iarray *bpf_iarray_realloc(struct bpf_iarray *old, size_t n_elem)\nkernel/bpf/cfg.c-208-{\n--\nkernel/bpf/cfg.c-222-\nkernel/bpf/cfg.c:223:static int copy_insn_array(struct bpf_map *map, u32 start, u32 end, u32 *items)\nkernel/bpf/cfg.c-224-{\n--\nkernel/bpf/cfg.c-242-\nkernel/bpf/cfg.c:243:static int cmp_ptr_to_u32(const void *a, const void *b)\nkernel/bpf/cfg.c-244-{\n--\nkernel/bpf/cfg.c-247-\nkernel/bpf/cfg.c:248:static int sort_insn_array_uniq(u32 *items, int cnt)\nkernel/bpf/cfg.c-249-{\n--\nkernel/bpf/cfg.c-264- */\nkernel/bpf/cfg.c:265:int bpf_copy_insn_array_uniq(struct bpf_map *map, u32 start, u32 end, u32 *off)\nkernel/bpf/cfg.c-266-{\n--\nkernel/bpf/cfg.c-279- */\nkernel/bpf/cfg.c:280:static struct bpf_iarray *jt_from_map(struct bpf_map *map)\nkernel/bpf/cfg.c-281-{\n--\nkernel/bpf/cfg.c-310- */\nkernel/bpf/cfg.c:311:static struct bpf_iarray *jt_from_subprog(struct bpf_verifier_env *env,\nkernel/bpf/cfg.c-312-\t\t\t\t\t int subprog_start, int subprog_end)\n--\nkernel/bpf/cfg.c=363=static struct bpf_iarray *\nkernel/bpf/cfg.c:364:create_jt(int t, struct bpf_verifier_env *env)\nkernel/bpf/cfg.c-365-{\n--\nkernel/bpf/cfg.c-396-/* \"conditional jump with N edges\" */\nkernel/bpf/cfg.c:397:static int visit_gotox_insn(int t, struct bpf_verifier_env *env)\nkernel/bpf/cfg.c-398-{\n--\nkernel/bpf/cfg.c-449- */\nkernel/bpf/cfg.c:450:static int visit_abnormal_return_insn(struct bpf_verifier_env *env, int t)\nkernel/bpf/cfg.c-451-{\n--\nkernel/bpf/cfg.c-473- */\nkernel/bpf/cfg.c:474:static int visit_insn(int t, struct bpf_verifier_env *env)\nkernel/bpf/cfg.c-475-{\n--\nkernel/bpf/cfg.c-610- */\nkernel/bpf/cfg.c:611:int bpf_check_cfg(struct bpf_verifier_env *env)\nkernel/bpf/cfg.c-612-{\n--\nkernel/bpf/cfg.c-712- */\nkernel/bpf/cfg.c:713:int bpf_compute_postorder(struct bpf_verifier_env *env)\nkernel/bpf/cfg.c-714-{\n--\nkernel/bpf/cfg.c-765- */\nkernel/bpf/cfg.c:766:int bpf_compute_scc(struct bpf_verifier_env *env)\nkernel/bpf/cfg.c-767-{\n"
} |
| 15/2 | 2026/09/06 11:23 | llm | patch-evaluator |
0mModel:gemini-3.7-flash Args: null Results: null Tokens: input: 18210 output: 43 thoughts: 146 Thoughts: **BPF Verifier Flow and Fixup Concerns** Okay, so I'm trying to wrap my head around this BPF verifier and how it handles instruction modifications. I see that the `bpf_check_cfg(struct bpf_verifier_env *env)` function is key; it calls `visit_insn`, which then pushes instructions using `push_insn`. That's the core of the validation process. Now I need to understand how we deal with patching and removing instructions during verification. Let's delve into `kernel/bpf/fixups.c`. I need to understand the relationship between `bpf_patch_insn_data()` and `verifier_remove_insns()`. Both of them are interesting since they have `bpf_rewrite_must_abort()`. That looks like a critical point where we might need to abort the verification. Okay, I'll examine `bpf_patch_insn_data` and `verifier_remove_insns` more closely. I should check their callers, and whether they are static or have broader visibility. I'll reach for `grep` and hunt them down in the codebase. That's the best way to determine if there are dependencies, or unexpected uses. Let's get to the bottom of this. |
| 16/2 | 2026/09/06 11:23 | tool | grepper |
0mArgs:{
"Expression": "(bpf_patch_insn_data|verifier_remove_insns)",
"PathPrefix": "kernel/bpf/"
}Results: {
"Output": "kernel/bpf/core.c=1562=struct bpf_prog *bpf_jit_blind_constants(struct bpf_verifier_env *env, struct bpf_prog *prog)\n--\nkernel/bpf/core.c-1576-\nkernel/bpf/core.c:1577:\t/* make sure bpf_patch_insn_data() patches the correct prog */\nkernel/bpf/core.c-1578-\tif (env)\n--\nkernel/bpf/core.c-1608-\t\tif (env)\nkernel/bpf/core.c:1609:\t\t\ttmp = bpf_patch_insn_data(env, i, insn_buff, rewritten);\nkernel/bpf/core.c-1610-\t\telse\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=523=void bpf_clear_insn_aux_data(struct bpf_verifier_env *env, int start, int len)\n--\nkernel/bpf/fixups.c-536-\nkernel/bpf/fixups.c:537:static int verifier_remove_insns(struct bpf_verifier_env *env, u32 off, u32 cnt)\nkernel/bpf/fixups.c-538-{\n--\nkernel/bpf/fixups.c=615=int bpf_opt_remove_dead_code(struct bpf_verifier_env *env)\n--\nkernel/bpf/fixups.c-629-\nkernel/bpf/fixups.c:630:\t\terr = verifier_remove_insns(env, i, j);\nkernel/bpf/fixups.c-631-\t\tif (err)\n--\nkernel/bpf/fixups.c=639=int bpf_opt_remove_nops(struct bpf_verifier_env *env)\n--\nkernel/bpf/fixups.c-652-\nkernel/bpf/fixups.c:653:\t\terr = verifier_remove_insns(env, i, 1);\nkernel/bpf/fixups.c-654-\t\tif (err)\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-1516-\t * ones for the hidden subprog. Hence all of the adjustment operations\nkernel/bpf/fixups.c:1517:\t * in bpf_patch_insn_data are no-ops.\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"
} |
| 17/2 | 2026/09/06 11:23 | llm | patch-evaluator |
0mModel:gemini-3.7-flash Args: null Results: null Tokens: input: 22514 output: 28 thoughts: 60 Thoughts: **Investigating the BPF State Handling** Okay, so I need to dig into the BPF state management, specifically focusing on `kernel/bpf/states.c`. The immediate concern is the `check_pkt_ptr_ids` function, since it's called from `regsafe`. My next step is to trace the call chain. I need to understand where `regsafe` is being called from and, importantly, what the entry points or key functions within `states.c` are that might be interacting with or triggering this behavior. I'm looking for a clear picture of the flow of execution and how these functions connect to each other. Understanding this will hopefully give me context for `check_pkt_ptr_ids`'s role. |
| 18/2 | 2026/09/06 11:23 | tool | grepper |
0mArgs:{
"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=535=enum exact_level {\n--\nkernel/bpf/states.c-541-/* Returns true if (rold safe implies rcur safe) */\nkernel/bpf/states.c:542:static bool regsafe(struct bpf_verifier_env *env, struct bpf_reg_state *rold,\nkernel/bpf/states.c-543-\t\t struct bpf_reg_state *rcur, struct bpf_idmap *idmap,\n--\nkernel/bpf/states.c=737=static bool stacksafe(struct bpf_verifier_env *env, struct bpf_func_state *old,\n--\nkernel/bpf/states.c-784-\t\t * Construct a fake register for such stack and call\nkernel/bpf/states.c:785:\t\t * regsafe() to ensure scalar ids are compared.\nkernel/bpf/states.c-786-\t\t */\n--\nkernel/bpf/states.c-790-\t\t\tif (old_reg \u0026\u0026 cur_reg) {\nkernel/bpf/states.c:791:\t\t\t\tif (!regsafe(env, old_reg, cur_reg, idmap, exact))\nkernel/bpf/states.c-792-\t\t\t\t\treturn false;\n--\nkernel/bpf/states.c-827-\t\t\t */\nkernel/bpf/states.c:828:\t\t\tif (!regsafe(env, \u0026old-\u003estack[spi].spilled_ptr,\nkernel/bpf/states.c-829-\t\t\t\t \u0026cur-\u003estack[spi].spilled_ptr, idmap, exact))\n--\nkernel/bpf/states.c=882=static bool stack_arg_safe(struct bpf_verifier_env *env, struct bpf_func_state *old,\n--\nkernel/bpf/states.c-896-\t\t\t \u0026cur-\u003estack_arg_regs[i] : \u0026not_init;\nkernel/bpf/states.c:897:\t\tif (!regsafe(env, old_arg, cur_arg, idmap, exact))\nkernel/bpf/states.c-898-\t\t\treturn false;\n--\nkernel/bpf/states.c=980=static bool func_states_equal(struct bpf_verifier_env *env, struct bpf_func_state *old,\n--\nkernel/bpf/states.c-993-\t\tif (((1 \u003c\u003c i) \u0026 live_regs) \u0026\u0026\nkernel/bpf/states.c:994:\t\t !regsafe(env, \u0026old-\u003eregs[i], \u0026cur-\u003eregs[i],\nkernel/bpf/states.c-995-\t\t\t \u0026env-\u003eidmap_scratch, exact))\n"
} |
| 19/2 | 2026/09/06 11:23 | llm | patch-evaluator |
0mModel:gemini-3.7-flash Args: null Results: null Tokens: input: 23632 output: 33 thoughts: 27 Thoughts: Here's my take on those thoughts, tailored for an expert audience: **Analyzing `states.c` for `func_states_equal` and `regsafe` Usage** Alright, let's dive in. I need to pinpoint the non-static functions within `states.c` that are actually *using* `func_states_equal` or `regsafe`. This isn't just about a grep search; I want to understand the *context* of these calls. I'm assuming there's a reason we're examining this specifically – likely a potential area for optimization, a security concern, or perhaps just a code review to ensure consistent usage of these function. Static functions are, by definition, internal to the file. I am looking for something more visible to the outside world, and am focusing on this first. So, I'll go through the functions, noting *where* these comparisons or safetly checks are happening. I'll need to remember the purpose of those functions - what is it that they are being used for? What states are we working with? What is the function trying to validate or secure? Are there any potential code smells? Are the implementations of these functions what I would expect, given the constraints of the system? Any obvious bottlenecks or vulnerabilities would be a high priority. I want to build a quick mental model of the control flow around these calls. Once that context is understood, it's easier to assess whether the usage is sound or if there's room for improvement, such as changing the way that some states are validated in the first place. |
| 20/2 | 2026/09/06 11:23 | tool | grepper |
0mArgs:{
"Expression": "func_states_equal",
"PathPrefix": "kernel/bpf/states.c"
}Results: {
"Output": "kernel/bpf/states.c=904=static bool refsafe(struct bpf_verifier_state *old, struct bpf_verifier_state *cur,\n--\nkernel/bpf/states.c-979- */\nkernel/bpf/states.c:980:static bool func_states_equal(struct bpf_verifier_env *env, struct bpf_func_state *old,\nkernel/bpf/states.c-981-\t\t\t struct bpf_func_state *cur, u32 insn_idx, enum exact_level exact)\n--\nkernel/bpf/states.c=1015=static bool states_equal(struct bpf_verifier_env *env,\n--\nkernel/bpf/states.c-1046-\t\t\treturn false;\nkernel/bpf/states.c:1047:\t\tif (!func_states_equal(env, old-\u003eframe[i], cur-\u003eframe[i], insn_idx, exact))\nkernel/bpf/states.c-1048-\t\t\treturn false;\n"
} |
| 21/2 | 2026/09/06 11:23 | llm | patch-evaluator |
0mModel:gemini-3.7-flash Args: null Results: null Tokens: input: 24292 output: 28 thoughts: 13 Thoughts: Here's my attempt at summarizing the thought process, tailored for an expert audience: **Analyzing `states_equal` Call Sites** Alright, let's dive in. My immediate thought is, "Where exactly is this `states_equal` function being used?" To truly understand its impact and behavior, I need to know the context of its calls. I'm going to start by tracing those call sites. This information will immediately tell me what parts of the system are relying on its comparison logic. Depending on the scale of the codebase, I'll be looking for cross-references, maybe using an IDE's "find usages" feature, or a more sophisticated code analysis tool if this is a large project. The goal here isn't just a list; I'm after the *types* of contexts. Are we comparing states in a simulation loop, in validation checks, in serialization routines, or what? Knowing the application context is key to understanding the potential implications of any change to `states_equal`. Understanding this could also reveal potential performance bottlenecks or subtle bugs stemming from the function's logic. Let's see what we can find. |
| 22/2 | 2026/09/06 11:23 | tool | grepper |
0mArgs:{
"Expression": "states_equal",
"PathPrefix": "kernel/bpf/"
}Results: {
"Output": "kernel/bpf/states.c=904=static bool refsafe(struct bpf_verifier_state *old, struct bpf_verifier_state *cur,\n--\nkernel/bpf/states.c-979- */\nkernel/bpf/states.c:980:static bool func_states_equal(struct bpf_verifier_env *env, struct bpf_func_state *old,\nkernel/bpf/states.c-981-\t\t\t struct bpf_func_state *cur, u32 insn_idx, enum exact_level exact)\n--\nkernel/bpf/states.c=1007=static void reset_idmap_scratch(struct bpf_verifier_env *env)\n--\nkernel/bpf/states.c-1014-\nkernel/bpf/states.c:1015:static bool states_equal(struct bpf_verifier_env *env,\nkernel/bpf/states.c-1016-\t\t\t struct bpf_verifier_state *old,\n--\nkernel/bpf/states.c-1046-\t\t\treturn false;\nkernel/bpf/states.c:1047:\t\tif (!func_states_equal(env, old-\u003eframe[i], cur-\u003eframe[i], insn_idx, exact))\nkernel/bpf/states.c-1048-\t\t\treturn false;\n--\nkernel/bpf/states.c=1274=int bpf_is_state_visited(struct bpf_verifier_env *env, int insn_idx)\n--\nkernel/bpf/states.c-1367-\t\t\tif (is_iter_next_insn(env, insn_idx)) {\nkernel/bpf/states.c:1368:\t\t\t\tif (states_equal(env, \u0026sl-\u003estate, cur, RANGE_WITHIN)) {\nkernel/bpf/states.c-1369-\t\t\t\t\tstruct bpf_func_state *cur_frame;\n--\nkernel/bpf/states.c-1377-\t\t\t\t\titer_reg = \u0026cur_frame-\u003eregs[BPF_REG_1];\nkernel/bpf/states.c:1378:\t\t\t\t\t/* current state is valid due to states_equal(),\nkernel/bpf/states.c-1379-\t\t\t\t\t * so we can assume valid iter and reg state,\n--\nkernel/bpf/states.c-1392-\t\t\t\tif (sl-\u003estate.may_goto_depth != cur-\u003emay_goto_depth \u0026\u0026\nkernel/bpf/states.c:1393:\t\t\t\t states_equal(env, \u0026sl-\u003estate, cur, RANGE_WITHIN)) {\nkernel/bpf/states.c-1394-\t\t\t\t\tloop = true;\n--\nkernel/bpf/states.c-1398-\t\t\tif (bpf_calls_callback(env, insn_idx)) {\nkernel/bpf/states.c:1399:\t\t\t\tif (states_equal(env, \u0026sl-\u003estate, cur, RANGE_WITHIN)) {\nkernel/bpf/states.c-1400-\t\t\t\t\tloop = true;\n--\nkernel/bpf/states.c-1406-\t\t\tif (states_maybe_looping(\u0026sl-\u003estate, cur) \u0026\u0026\nkernel/bpf/states.c:1407:\t\t\t states_equal(env, \u0026sl-\u003estate, cur, EXACT) \u0026\u0026\nkernel/bpf/states.c-1408-\t\t\t !iter_active_depths_differ(\u0026sl-\u003estate, cur) \u0026\u0026\n--\nkernel/bpf/states.c-1439-\t\tloop = incomplete_read_marks(env, \u0026sl-\u003estate);\nkernel/bpf/states.c:1440:\t\tif (states_equal(env, \u0026sl-\u003estate, cur, loop ? RANGE_WITHIN : NOT_EXACT)) {\nkernel/bpf/states.c-1441-hit:\n--\nkernel/bpf/states.c-1479-\t\t\t *\nkernel/bpf/states.c:1480:\t\t\t * - When a verification path encounters a `states_equal(...,\nkernel/bpf/states.c-1481-\t\t\t * RANGE_WITHIN)` condition, there exists a call chain describing the\n"
} |
| 23/2 | 2026/09/06 11:23 | llm | patch-evaluator |
0mModel:gemini-3.7-flash Args: null Results: null Tokens: input: 25613 output: 58 thoughts: 156 Thoughts: **Analyzing BPF State Visitation** Okay, so `bpf_is_state_visited` in `states.c` is the primary function we're dealing with here, that's the starting point. Time to dive into `kernel/bpf/verifier.c`. What changes were made in the verifier code that relate to this state management? Looks like `map_set_for_each_callback_args()`, `set_timer_callback_state()`, `set_task_work_schedule_callback_state()`, and that helper, `map_value_has_static_identity()`, were all touched. Now, the critical question: are these functions static or non-static? I need to quickly determine their scope because that'll tell me if they're directly accessible or if they're internal to their respective files. Let's fire up `grep` and find out. |
| 24/2 | 2026/09/06 11:23 | tool | grepper |
0mArgs:{
"Expression": "(map_set_for_each_callback_args|set_timer_callback_state|set_task_work_schedule_callback_state)",
"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/fixups.c=1533=int bpf_do_misc_fixups(struct bpf_verifier_env *env)\n--\nkernel/bpf/fixups.c-2018-\t\t\t * with different maps and the register states prepared by\nkernel/bpf/fixups.c:2019:\t\t\t * set_timer_callback_state will be accurate.\nkernel/bpf/fixups.c-2020-\t\t\t *\n--\nkernel/bpf/hashtab.c=2361=const struct bpf_map_ops htab_map_ops = {\n--\nkernel/bpf/hashtab.c-2373-\t.map_seq_show_elem = htab_map_seq_show_elem,\nkernel/bpf/hashtab.c:2374:\t.map_set_for_each_callback_args = map_set_for_each_callback_args,\nkernel/bpf/hashtab.c-2375-\t.map_for_each_callback = bpf_for_each_hash_elem,\n--\nkernel/bpf/hashtab.c=2383=const struct bpf_map_ops htab_lru_map_ops = {\n--\nkernel/bpf/hashtab.c-2396-\t.map_seq_show_elem = htab_map_seq_show_elem,\nkernel/bpf/hashtab.c:2397:\t.map_set_for_each_callback_args = map_set_for_each_callback_args,\nkernel/bpf/hashtab.c-2398-\t.map_for_each_callback = bpf_for_each_hash_elem,\n--\nkernel/bpf/hashtab.c=2564=const struct bpf_map_ops htab_percpu_map_ops = {\n--\nkernel/bpf/hashtab.c-2576-\t.map_seq_show_elem = htab_percpu_map_seq_show_elem,\nkernel/bpf/hashtab.c:2577:\t.map_set_for_each_callback_args = map_set_for_each_callback_args,\nkernel/bpf/hashtab.c-2578-\t.map_for_each_callback = bpf_for_each_hash_elem,\n--\nkernel/bpf/hashtab.c=2586=const struct bpf_map_ops htab_lru_percpu_map_ops = {\n--\nkernel/bpf/hashtab.c-2597-\t.map_seq_show_elem = htab_percpu_map_seq_show_elem,\nkernel/bpf/hashtab.c:2598:\t.map_set_for_each_callback_args = map_set_for_each_callback_args,\nkernel/bpf/hashtab.c-2599-\t.map_for_each_callback = bpf_for_each_hash_elem,\n--\nkernel/bpf/hashtab.c=3508=const struct bpf_map_ops rhtab_map_ops = {\n--\nkernel/bpf/hashtab.c-3521-\t.map_seq_show_elem = rhtab_map_seq_show_elem,\nkernel/bpf/hashtab.c:3522:\t.map_set_for_each_callback_args = map_set_for_each_callback_args,\nkernel/bpf/hashtab.c-3523-\t.map_for_each_callback = bpf_each_rhash_elem,\n--\nkernel/bpf/verifier.c=9906=static int check_func_call(struct bpf_verifier_env *env, struct bpf_insn *insn,\n--\nkernel/bpf/verifier.c-10022-\nkernel/bpf/verifier.c:10023:int map_set_for_each_callback_args(struct bpf_verifier_env *env,\nkernel/bpf/verifier.c-10024-\t\t\t\t struct bpf_func_state *caller,\n--\nkernel/bpf/verifier.c=10069=static int set_map_elem_callback_state(struct bpf_verifier_env *env,\n--\nkernel/bpf/verifier.c-10079-\tmap = insn_aux-\u003emap_ptr_state.map_ptr;\nkernel/bpf/verifier.c:10080:\tif (!map-\u003eops-\u003emap_set_for_each_callback_args ||\nkernel/bpf/verifier.c-10081-\t !map-\u003eops-\u003emap_for_each_callback) {\n--\nkernel/bpf/verifier.c-10085-\nkernel/bpf/verifier.c:10086:\terr = map-\u003eops-\u003emap_set_for_each_callback_args(env, caller, callee);\nkernel/bpf/verifier.c-10087-\tif (err)\n--\nkernel/bpf/verifier.c=10095=static int set_loop_callback_state(struct bpf_verifier_env *env,\n--\nkernel/bpf/verifier.c-10116-\nkernel/bpf/verifier.c:10117:static int set_timer_callback_state(struct bpf_verifier_env *env,\nkernel/bpf/verifier.c-10118-\t\t\t\t struct bpf_func_state *caller,\n--\nkernel/bpf/verifier.c=10205=static int set_rbtree_add_callback_state(struct bpf_verifier_env *env,\n--\nkernel/bpf/verifier.c-10237-\nkernel/bpf/verifier.c:10238:static int set_task_work_schedule_callback_state(struct bpf_verifier_env *env,\nkernel/bpf/verifier.c-10239-\t\t\t\t\t\t struct bpf_func_state *caller,\n--\nkernel/bpf/verifier.c=10826=static int check_helper_call(struct bpf_verifier_env *env, struct bpf_insn *insn,\n--\nkernel/bpf/verifier.c-10972-\t\terr = push_callback_call(env, insn, insn_idx, meta.subprogno,\nkernel/bpf/verifier.c:10973:\t\t\t\t\t set_timer_callback_state);\nkernel/bpf/verifier.c-10974-\t\tbreak;\n--\nkernel/bpf/verifier.c=13768=static int check_kfunc_call(struct bpf_verifier_env *env, struct bpf_insn *insn,\n--\nkernel/bpf/verifier.c-13894-\t\terr = push_callback_call(env, insn, insn_idx, meta.subprogno,\nkernel/bpf/verifier.c:13895:\t\t\t\t\t set_timer_callback_state);\nkernel/bpf/verifier.c-13896-\t\tif (err) {\n--\nkernel/bpf/verifier.c-13904-\t\terr = push_callback_call(env, insn, insn_idx, meta.subprogno,\nkernel/bpf/verifier.c:13905:\t\t\t\t\t set_task_work_schedule_callback_state);\nkernel/bpf/verifier.c-13906-\t\tif (err) {\n"
} |
| 25/2 | 2026/09/06 11:23 | llm | patch-evaluator |
0mModel:gemini-3.7-flash Args: null Results: null Tokens: input: 28175 output: 217 thoughts: 1496 Thoughts: **Focusing on BPF Verifier Modifications for Fuzzing** Alright, let's get down to brass tacks. I need to figure out the right approach for fuzzing this patch, and the key is pinpointing the most relevant code. First, the main entry point for the verifier is `bpf_check`, but that's a general function. I need to identify specific functions modified or directly relevant to the changes to list in `FocusSymbols`. I'll start by checking the modified functions, and it looks like: * In `kernel/bpf/cfg.c`, I'm looking at `bpf_check_cfg` (which calls `visit_insn` which calls `push_insn`). * Then in `kernel/bpf/fixups.c`, there's `bpf_patch_insn_data`, `verifier_remove_insns`, `bpf_opt_remove_dead_code`, and `bpf_opt_remove_nops`. * Moving on to `kernel/bpf/states.c`, I have `check_pkt_ptr_ids`, `regsafe`, and `bpf_is_state_visited`. * Finally, in `kernel/bpf/verifier.c`, I need to look at `map_set_for_each_callback_args`, `set_timer_callback_state`, `set_task_work_schedule_callback_state`, and `bpf_check` (again). Now, I need to figure out if these symbols are in `vmlinux` or if they get inlined. With non-static functions, they're definitely exported. Static functions are a bit trickier, they may or may not be inlined depending on the compiler's optimizations. So, to be safe, I'll list both non-static symbols as well as static ones if they aren't static inline in headers. Section 4 confirms this: I need to target *specific feature logic* and entrypoints, and account for static inlines. So, let's nail down this list, confirming that all the code from the diff is included: 1. `push_insn` and `bpf_check_cfg` in `cfg.c` 2. `bpf_patch_insn_data`, `verifier_remove_insns`, `bpf_rewrite_must_abort` in `fixups.c` 3. `check_pkt_ptr_ids`, `regsafe`, and `bpf_is_state_visited` in `states.c` 4. `map_set_for_each_callback_args`, `set_timer_callback_state`, `set_task_work_schedule_callback_state` and `map_value_has_static_identity` in `verifier.c` Next, I need to check any dependencies on configurations. It looks like `CONFIG_BPF_SYSCALL` is the primary one, and it's a simple boolean. Checking the code for ifdefs in `cfg.c`, `fixups.c`, `states.c`, and `verifier.c`, I can confirm that there aren't any. `BPF_SYSCALL` seems to be all I need, and it selects BPF. Now the million-dollar question: Is this `WorthFuzzing=true`? Absolutely. These changes are impacting the BPF verifier's control flow graph construction, instruction rewriting, packet pointer state checks, and lock ID assignment. This all touches core, reachable logic, and the BPF system call is the primary entry point. Okay, let's make a final, accurate list of `FocusSymbols`: * `bpf_check_cfg` * `push_insn` * `bpf_patch_insn_data` * `verifier_remove_insns` * `check_pkt_ptr_ids` * `regsafe` * `bpf_is_state_visited` * `map_set_for_each_callback_args` * `set_timer_callback_state` * `set_task_work_schedule_callback_state` I need to make sure none of these are generic or ubiquitous functions. They are specific to the BPF verifier subsystem and not general kernel lifecycle functions, which is good. Finally, I can quickly summarise my reasoning: This patch series is modifying core BPF verifier logic involved in validating control flow, signal handling, pointer comparison, and unique lock ID assignment. These changes are exercised through the `bpf(BPF_PROG_LOAD)` syscall, so |
| 26/2 | 2026/09/06 11:23 | tool | set-results |
0mArgs:{
"EnableConfigs": [
"BPF_SYSCALL"
],
"FocusSymbols": [
"bpf_check_cfg",
"push_insn",
"bpf_patch_insn_data",
"verifier_remove_insns",
"check_pkt_ptr_ids",
"regsafe",
"bpf_is_state_visited",
"map_set_for_each_callback_args",
"set_timer_callback_state",
"set_task_work_schedule_callback_state"
],
"Reasoning": "The patch touches core BPF verifier execution paths, including control flow graph (CFG) subprogram boundary checks, signal-aware instruction rewriting/removal passes, packet pointer state equivalence comparison (regsafe), and lock identity tracking for callback arguments. These changes are reachable via the bpf(BPF_PROG_LOAD, ...) syscall and directly affect verification correctness and safety invariants.",
"WorthFuzzing": true
}Results: {
"EnableConfigs": [
"BPF_SYSCALL"
],
"FocusSymbols": [
"bpf_check_cfg",
"push_insn",
"bpf_patch_insn_data",
"verifier_remove_insns",
"check_pkt_ptr_ids",
"regsafe",
"bpf_is_state_visited",
"map_set_for_each_callback_args",
"set_timer_callback_state",
"set_task_work_schedule_callback_state"
],
"Reasoning": "The patch touches core BPF verifier execution paths, including control flow graph (CFG) subprogram boundary checks, signal-aware instruction rewriting/removal passes, packet pointer state equivalence comparison (regsafe), and lock identity tracking for callback arguments. These changes are reachable via the bpf(BPF_PROG_LOAD, ...) syscall and directly affect verification correctness and safety invariants.",
"WorthFuzzing": true
} |
| 27/1 | 2026/09/06 11:23 | action | If |
0mArgs:{
"WorthFuzzing": true
}Results: null |
| 28/2 | 2026/09/06 11:23 | agent | kmsan-evaluator |
0mModel:core Args: null Results: {
"KMSANReasoning": "The patch series modifies the BPF verifier and CFG analysis in several areas:\n1. Adds packet pointer displacement tracking across state equivalence checks in `kernel/bpf/states.c` (using `check_pkt_ptr_ids` and initializing `pkt_ptr_delta_set` in `check_ids`).\n2. Validates subprogram boundaries on fall-through edges in `kernel/bpf/cfg.c`.\n3. Adds fatal signal checks (`bpf_rewrite_must_abort`) to prevent non-killable loops during post-verification instruction patching/removal in `kernel/bpf/fixups.c`.\n4. Ensures distinct register IDs for callback map values that may point to spin locks unless the map has static identity in `kernel/bpf/verifier.c`.\n\nNone of these changes allocate or manipulate uninitialized memory buffers, copy uninitialized data to user space, or alter buffer lengths in ways that expose uninitialized stack or heap data. All struct fields added (`pkt_ptr_delta`, `pkt_ptr_delta_set`) are explicitly initialized before read operations. The changes are strictly verifier logic, control-flow validation, and signal-handling improvements. Therefore, a dedicated KMSAN fuzzing session is not required.",
"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 62ec2a38e983ba002431ffb5bb17707c7360dce2
Author: syz-cluster <triage@syzkaller.com>
Date: Sun Sep 6 11:23:12 2026 +0000
syz-cluster: applied patch under review
diff --git a/include/linux/bpf_verifier.h b/include/linux/bpf_verifier.h
index 36b65797877d0..5cf92ce185204 100644
--- a/include/linux/bpf_verifier.h
+++ b/include/linux/bpf_verifier.h
@@ -854,6 +854,8 @@ struct backtrack_state {
struct bpf_id_pair {
u32 old;
u32 cur;
+ s32 pkt_ptr_delta;
+ bool pkt_ptr_delta_set;
};
struct bpf_idmap {
diff --git a/kernel/bpf/cfg.c b/kernel/bpf/cfg.c
index 842c7d1eabccc..e3c904328ede0 100644
--- a/kernel/bpf/cfg.c
+++ b/kernel/bpf/cfg.c
@@ -102,6 +102,7 @@ enum {
*/
static int push_insn(int t, int w, int e, struct bpf_verifier_env *env)
{
+ struct bpf_subprog_info *subprog;
int *insn_stack = env->cfg.insn_stack;
int *insn_state = env->cfg.insn_state;
@@ -121,6 +122,26 @@ static int push_insn(int t, int w, int e, struct bpf_verifier_env *env)
return -EINVAL;
}
+ /*
+ * check_subprogs() prevents control flow from falling through a
+ * subprogram boundary, but runs before CO-RE relocations can rewrite an
+ * instruction. Reestablish the invariant on the final instruction stream
+ * before constructing the CFG used by later per-subprogram passes.
+ */
+ if (e == FALLTHROUGH) {
+ subprog = bpf_find_containing_subprog(env, t);
+ if (w < subprog->start || w >= (subprog + 1)->start) {
+ verbose_linfo(env, t, "%d: ", t);
+ verbose(env, "fall-through out of subprog from insn %d to %d\n", t, w);
+ bpf_diag_program_structure(
+ env, t, "fall-through leaves subprogram",
+ "Keep fall-through control flow inside the current subprogram.",
+ "Instruction %d falls through to instruction %d outside its subprogram.",
+ t, w);
+ return -EINVAL;
+ }
+ }
+
if (e == BRANCH) {
/* mark branch target for state pruning */
mark_prune_point(env, w);
diff --git a/kernel/bpf/fixups.c b/kernel/bpf/fixups.c
index 52d3cec336727..9401fffcedfd6 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);
@@ -2666,4 +2686,3 @@ int bpf_remove_fastcall_spills_fills(struct bpf_verifier_env *env)
return 0;
}
-
diff --git a/kernel/bpf/states.c b/kernel/bpf/states.c
index 66fb11b6c6a76..2f8f3fe164b01 100644
--- a/kernel/bpf/states.c
+++ b/kernel/bpf/states.c
@@ -339,6 +339,7 @@ static bool check_ids(u32 old_id, u32 cur_id, struct bpf_idmap *idmap)
if (idmap->cnt < BPF_ID_MAP_SIZE) {
map[idmap->cnt].old = old_id;
map[idmap->cnt].cur = cur_id;
+ map[idmap->cnt].pkt_ptr_delta_set = false;
idmap->cnt++;
return true;
}
@@ -352,6 +353,43 @@ static bool check_ids(u32 old_id, u32 cur_id, struct bpf_idmap *idmap)
return false;
}
+static bool check_pkt_ptr_ids(const struct bpf_reg_state *old,
+ const struct bpf_reg_state *cur,
+ struct bpf_idmap *idmap)
+{
+ struct bpf_id_pair *map = idmap->map;
+ s64 delta;
+ unsigned int i;
+
+ if (!check_ids(old->id, cur->id, idmap))
+ return false;
+ if (!old->id)
+ return true;
+
+ /*
+ * Packet range is shared by all pointers with the same ID. Preserve
+ * their relative displacement, while allowing the whole class to move.
+ * Packet pointer offsets are bounded by BPF_MAX_VAR_OFF, so the delta
+ * between two valid offsets fits in s32.
+ */
+ delta = (s64)(cur->r64.base - old->r64.base);
+ if (delta < S32_MIN || delta > S32_MAX)
+ return false;
+
+ for (i = 0; i < idmap->cnt; i++) {
+ if (map[i].old != old->id)
+ continue;
+ if (!map[i].pkt_ptr_delta_set) {
+ map[i].pkt_ptr_delta = delta;
+ map[i].pkt_ptr_delta_set = true;
+ return true;
+ }
+ return map[i].pkt_ptr_delta == delta;
+ }
+
+ return false;
+}
+
/*
* Compare scalar register IDs for state equivalence.
*
@@ -632,8 +670,8 @@ static bool regsafe(struct bpf_verifier_env *env, struct bpf_reg_state *rold,
} else if (rold->range > rcur->range) {
return false;
}
- /* id relations must be preserved */
- if (!check_ids(rold->id, rcur->id, idmap))
+ /* id relations and intra-class displacement must be preserved */
+ if (!check_pkt_ptr_ids(rold, rcur, idmap))
return false;
/* new val must satisfy old val knowledge */
return range_within(rold, rcur) &&
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index 1c3039f3fc323..b08501734ddfa 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -447,6 +447,11 @@ static bool reg_may_point_to_spin_lock(const struct bpf_reg_state *reg)
return btf_record_has_field(reg_btf_record(reg), BPF_SPIN_LOCK | BPF_RES_SPIN_LOCK);
}
+static bool map_value_has_static_identity(const struct bpf_map *map)
+{
+ return map->map_type == BPF_MAP_TYPE_ARRAY && map->max_entries == 1;
+}
+
static bool type_is_rdonly_mem(u32 type)
{
return type & MEM_RDONLY;
@@ -10035,6 +10040,9 @@ 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;
+ if (reg_may_point_to_spin_lock(&callee->regs[BPF_REG_3]) &&
+ !map_value_has_static_identity(callee->regs[BPF_REG_3].map_ptr))
+ callee->regs[BPF_REG_3].id = ++env->id_gen;
/* pointer to stack or null */
callee->regs[BPF_REG_4] = caller->regs[BPF_REG_3];
@@ -10131,6 +10139,9 @@ 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;
+ if (reg_may_point_to_spin_lock(&callee->regs[BPF_REG_3]) &&
+ !map_value_has_static_identity(callee->regs[BPF_REG_3].map_ptr))
+ callee->regs[BPF_REG_3].id = ++env->id_gen;
/* unused */
bpf_mark_reg_not_init(env, &callee->regs[BPF_REG_4]);
@@ -10249,6 +10260,9 @@ 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;
+ if (reg_may_point_to_spin_lock(&callee->regs[BPF_REG_3]) &&
+ !map_value_has_static_identity(callee->regs[BPF_REG_3].map_ptr))
+ callee->regs[BPF_REG_3].id = ++env->id_gen;
/* unused */
bpf_mark_reg_not_init(env, &callee->regs[BPF_REG_4]);
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..c350fbb958455 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,117 @@
static char log[16 * 1024];
+static int load_core_relo_subprog(int btf_fd, int main_id, int sub_id,
+ int enum_id, int access_str_off, bool relocate)
+{
+ struct bpf_insn insns[] = {
+ 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[] = {
+ { .insn_off = 0, .type_id = main_id },
+ { .insn_off = 3, .type_id = sub_id },
+ };
+ struct bpf_core_relo relo = {
+ .insn_off = 2 * 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 = ARRAY_SIZE(insns),
+ .insns = (__u64)insns,
+ .license = (__u64)"GPL",
+ .log_buf = (__u64)log,
+ .log_size = sizeof(log),
+ .log_level = 1,
+ .prog_btf_fd = btf_fd,
+ .func_info_rec_size = sizeof(struct bpf_func_info),
+ .func_info = (__u64)funcs,
+ .func_info_cnt = ARRAY_SIZE(funcs),
+ };
+
+ 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_poisoned_subprog_terminator(void)
+{
+ const void *raw_btf;
+ struct btf *btf = NULL;
+ __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;
+
+ 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_subprog_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;
+
+ /* The same two-subprogram program is valid before the relocation. */
+ prog_fd = load_core_relo_subprog(btf_fd, main_id, sub_id, enum_id,
+ access_str_off, false);
+ if (!ASSERT_GE(prog_fd, 0, "control_load"))
+ goto cleanup;
+ close(prog_fd);
+ prog_fd = -1;
+
+ /*
+ * Poison the first subprogram's terminal exit. The verifier must reject
+ * the resulting control flow across the subprogram boundary in the CFG.
+ */
+ prog_fd = load_core_relo_subprog(btf_fd, main_id, sub_id, enum_id,
+ access_str_off, true);
+ if (!ASSERT_LT(prog_fd, 0, "poisoned_load"))
+ goto cleanup;
+ ASSERT_HAS_SUBSTR(log, "fall-through out of subprog from insn 2 to 3",
+ "poisoned_load_log");
+
+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 +231,8 @@ static void test_bad_local_id(void)
void test_core_reloc_raw(void)
{
+ if (test__start_subtest("poisoned_subprog_terminator"))
+ test_poisoned_subprog_terminator();
if (test__start_subtest("bad_local_id"))
test_bad_local_id();
}
diff --git a/tools/testing/selftests/bpf/prog_tests/prog_load_signal.c b/tools/testing/selftests/bpf/prog_tests/prog_load_signal.c
new file mode 100644
index 0000000000000..0f78db3bccc76
--- /dev/null
+++ b/tools/testing/selftests/bpf/prog_tests/prog_load_signal.c
@@ -0,0 +1,131 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (c) 2026 Meta Platforms, Inc. and affiliates. */
+#include <test_progs.h>
+
+#define NOP_CNT 32768
+#define MIN_KILL_DELAY_NS (100ULL * 1000 * 1000)
+#define REAP_TIMEOUT_NS (1000ULL * 1000 * 1000)
+
+static __u64 monotonic_ns(void)
+{
+ struct timespec ts;
+
+ clock_gettime(CLOCK_MONOTONIC, &ts);
+ return ts.tv_sec * 1000000000ULL + ts.tv_nsec;
+}
+
+static void sleep_ns(__u64 duration)
+{
+ struct timespec ts = {
+ .tv_sec = duration / 1000000000ULL,
+ .tv_nsec = duration % 1000000000ULL,
+ };
+
+ while (nanosleep(&ts, &ts) && errno == EINTR)
+ ;
+}
+
+static int waitpid_timeout(pid_t pid, int *status, __u64 timeout)
+{
+ __u64 deadline = monotonic_ns() + timeout;
+ int ret;
+
+ do {
+ ret = waitpid(pid, status, WNOHANG);
+ if (ret)
+ return ret;
+ usleep(1000);
+ } while (monotonic_ns() < deadline);
+
+ return 0;
+}
+
+void test_prog_load_signal(void)
+{
+ struct bpf_insn *insns = NULL;
+ __u64 start, control_time, kill_delay;
+ int pipefd[2] = { -1, -1 };
+ int prog_fd = -1, status = 0;
+ pid_t pid = -1;
+ char byte;
+ int i, ret;
+
+ insns = calloc(NOP_CNT + 2, sizeof(*insns));
+ if (!ASSERT_OK_PTR(insns, "calloc"))
+ return;
+
+ for (i = 0; i < NOP_CNT; i++)
+ insns[i] = BPF_MOV64_REG(BPF_REG_1, BPF_REG_1);
+ insns[NOP_CNT] = BPF_MOV64_IMM(BPF_REG_0, 0);
+ insns[NOP_CNT + 1] = BPF_EXIT_INSN();
+
+ start = monotonic_ns();
+ prog_fd = bpf_prog_load(BPF_PROG_TYPE_SOCKET_FILTER, NULL, "GPL",
+ insns, NOP_CNT + 2, NULL);
+ control_time = monotonic_ns() - start;
+ if (!ASSERT_GE(prog_fd, 0, "control_prog_load"))
+ goto cleanup;
+ close(prog_fd);
+ prog_fd = -1;
+
+ for (i = 0; i < NOP_CNT; i++)
+ insns[i] = BPF_JMP_IMM(BPF_JA, 0, 0, 0);
+
+ if (!ASSERT_OK(pipe(pipefd), "pipe"))
+ goto cleanup;
+
+ pid = fork();
+ if (!ASSERT_GE(pid, 0, "fork"))
+ goto cleanup;
+ if (!pid) {
+ close(pipefd[0]);
+ if (write(pipefd[1], "x", 1) != 1)
+ _exit(1);
+ close(pipefd[1]);
+ prog_fd = bpf_prog_load(BPF_PROG_TYPE_SOCKET_FILTER, NULL, "GPL",
+ insns, NOP_CNT + 2, NULL);
+ if (prog_fd >= 0)
+ close(prog_fd);
+ _exit(prog_fd < 0);
+ }
+
+ close(pipefd[1]);
+ pipefd[1] = -1;
+ ret = read(pipefd[0], &byte, 1);
+ if (!ASSERT_EQ(ret, 1, "child_ready"))
+ goto cleanup;
+
+ /*
+ * Allow linear verification to finish before sending SIGKILL. The nop
+ * removal pass is quadratic, so four control-load times still leaves a
+ * wide window in which an affected kernel is rewriting instructions.
+ */
+ kill_delay = MAX(control_time * 4, MIN_KILL_DELAY_NS);
+ sleep_ns(kill_delay);
+ if (!ASSERT_OK(kill(pid, SIGKILL), "kill"))
+ goto cleanup;
+
+ start = monotonic_ns();
+ ret = waitpid_timeout(pid, &status, REAP_TIMEOUT_NS);
+ if (!ASSERT_EQ(ret, pid, "prog_load_killable")) {
+ fprintf(stderr, "control load %llu us, child still alive %llu us after SIGKILL\n",
+ control_time / 1000, (monotonic_ns() - start) / 1000);
+ goto cleanup;
+ }
+ pid = -1;
+ ASSERT_TRUE(WIFSIGNALED(status) && WTERMSIG(status) == SIGKILL,
+ "killed_by_sigkill");
+
+cleanup:
+ if (prog_fd >= 0)
+ close(prog_fd);
+ if (pipefd[0] >= 0)
+ close(pipefd[0]);
+ if (pipefd[1] >= 0)
+ close(pipefd[1]);
+ if (pid > 0) {
+ kill(pid, SIGKILL);
+ waitpid(pid, &status, 0);
+ }
+ free(insns);
+}
diff --git a/tools/testing/selftests/bpf/prog_tests/verifier.c b/tools/testing/selftests/bpf/prog_tests/verifier.c
index 64ac49ad67e63..5c572dd725e75 100644
--- a/tools/testing/selftests/bpf/prog_tests/verifier.c
+++ b/tools/testing/selftests/bpf/prog_tests/verifier.c
@@ -25,6 +25,7 @@
#include "verifier_btf_ctx_access.skel.h"
#include "verifier_btf_unreliable_prog.skel.h"
#include "verifier_call_large_imm.skel.h"
+#include "verifier_callback_lock.skel.h"
#include "verifier_cfg.skel.h"
#include "verifier_cgroup_inv_retcode.skel.h"
#include "verifier_cgroup_skb.skel.h"
@@ -188,6 +189,7 @@ void test_verifier_bswap(void) { RUN(verifier_bswap); }
void test_verifier_btf_ctx_access(void) { RUN(verifier_btf_ctx_access); }
void test_verifier_btf_unreliable_prog(void) { RUN(verifier_btf_unreliable_prog); }
void test_verifier_call_large_imm(void) { RUN(verifier_call_large_imm); }
+void test_verifier_callback_lock(void) { RUN(verifier_callback_lock); }
void test_verifier_cfg(void) { RUN(verifier_cfg); }
void test_verifier_cgroup_inv_retcode(void) { RUN(verifier_cgroup_inv_retcode); }
void test_verifier_cgroup_skb(void) { RUN(verifier_cgroup_skb); }
diff --git a/tools/testing/selftests/bpf/progs/verifier_callback_lock.c b/tools/testing/selftests/bpf/progs/verifier_callback_lock.c
new file mode 100644
index 0000000000000..ee09dd66f4678
--- /dev/null
+++ b/tools/testing/selftests/bpf/progs/verifier_callback_lock.c
@@ -0,0 +1,73 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <linux/bpf.h>
+#include <bpf/bpf_helpers.h>
+#include "bpf_misc.h"
+
+struct bpf_map;
+
+struct lock_value {
+ struct bpf_spin_lock lock;
+};
+
+struct {
+ __uint(type, BPF_MAP_TYPE_ARRAY);
+ __uint(max_entries, 2);
+ __type(key, int);
+ __type(value, struct lock_value);
+} lock_map SEC(".maps");
+
+struct callback_ctx {
+ struct lock_value *value;
+};
+
+static long lock_different_value(struct bpf_map *map, int *key,
+ struct lock_value *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 lock_value *value, void *data)
+{
+ struct callback_ctx ctx = { .value = value };
+
+ bpf_for_each_map_elem(&lock_map, lock_different_value, &ctx, 0);
+ return 0;
+}
+
+SEC("?tc")
+__description("callback map value has a distinct lock identity")
+__failure __msg("bpf_spin_unlock of different lock")
+int callback_value_lock_identity(void *ctx)
+{
+ bpf_for_each_map_elem(&lock_map, nest_lock_different_value, NULL, 0);
+ return 0;
+}
+
+static long lock_same_value(struct bpf_map *map, int *key,
+ struct lock_value *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 lock_value *value, void *data)
+{
+ bpf_for_each_map_elem(&lock_map, lock_same_value, NULL, 0);
+ return 0;
+}
+
+SEC("?tc")
+__description("nested callback can lock its own map value")
+__success
+int callback_value_lock_identity_same(void *ctx)
+{
+ bpf_for_each_map_elem(&lock_map, nest_lock_same_value, NULL, 0);
+ 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..692a8468f3d74 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
@@ -5,6 +5,50 @@
#include <bpf/bpf_helpers.h>
#include "bpf_misc.h"
+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)
+__naked void pkt_regsafe_class_displacement(void)
+{
+ asm volatile ("\
+ r8 = *(u32 *)(r1 + %[xdp_md_data_end]);\
+ r9 = *(u32 *)(r1 + %[xdp_md_data]);\
+ r6 = r9;\
+ r6 += 8;\
+ if r6 > r8 goto l_exit_%=;\
+ r0 = *(u64 *)(r9 + 0);\
+ r4 = r0;\
+ r4 &= 15;\
+ r7 = r0;\
+ r7 >>= 63;\
+ if r7 != 0 goto l_path_b_%=;\
+ r2 = r9;\
+ r2 += r4;\
+ r3 = r2;\
+ r3 += 4;\
+ goto l_join_%=;\
+l_path_b_%=: \
+ r4 &= 3;\
+ r4 += 8;\
+ r2 = r9;\
+ r2 += r4;\
+ r3 = r2;\
+ r3 -= 4;\
+l_join_%=: \
+ r5 = r3;\
+ r5 += 4;\
+ if r5 > r8 goto l_exit_%=;\
+ r0 = *(u64 *)(r2 + 0);\
+l_exit_%=: \
+ 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))
+ : __clobber_all);
+}
+
SEC("xdp")
__description("XDP pkt read, pkt_end mangling, bad access 1")
__failure __msg("R3 pointer arithmetic on pkt_end")
|
| 29/3 | 2026/09/06 11:23 | llm | kmsan-evaluator |
0mModel:gemini-3.7-flash Args: null Results: null Tokens: input: 10725 output: 20 thoughts: 1330 Thoughts: **KMSAN Analysis of BPF Patch Series** Okay, let's dive into this patch series. My immediate goal is to determine if this requires a dedicated KMSAN session – `NeedsKMSAN = true/false` – and to document the reasoning behind that decision (`KMSANReasoning`). I need to carefully scrutinize these changes across the files provided. First, I see a new member, `pkt_ptr_delta`, and `pkt_ptr_delta_set` added to `struct bpf_id_pair` in `include/linux/bpf_verifier.h`. This is interesting; it suggests tracking relative displacements of packet pointers. I'll need to see how these fields are used to determine potential data races. In `kernel/bpf/cfg.c`, a check has been added to the Control Flow Graph (CFG) validation to reject fallthrough out of subprograms. This seems like a good, solid defensive measure against control-flow errors. It's unlikely to be a KMSAN concern directly, but a flawed CFG could lead to other issues. Next, in `kernel/bpf/fixups.c`, the `bpf_patch_insn_data` and `verifier_remove_insns` functions now abort if a fatal signal is pending. This is a crucial safety check during instruction manipulation. While handling signals is generally good practice, I'm not immediately seeing a strong KMSAN implication here, unless the abort leaves something in an unsafe state. `kernel/bpf/states.c` introduces `check_pkt_ptr_ids` and updates `regsafe`. The addition of the `check_pkt_ptr_ids` function and the logic to track packet pointer displacement within `struct bpf_id_pair` are the most interesting so far. This appears to be aimed at maintaining relative displacement of packet pointers across BPF program transformations, and this might introduce some potential risks. The explicit checks for `S32_MIN` and `S32_MAX` for the delta are good. The `check_ids` function seems like it might be an older construct that this change builds upon. Let me examine where `struct bpf_idmap` is allocated and initialized. This is crucial for understanding the lifetime and scope of this new packet pointer tracking. I'll use `grepper` to search the kernel code for allocations and uses of this structure. I need to figure out where it's populated and deallocated and who has access to it. Any uninitialized memory usage or data access risks within the structure could be a major concern for KMSAN. I'll also need to check for any potential race conditions during the population of this map. This is where I'll be focusing my KMSAN analysis. Finally, in `kernel/bpf/verifier.c`, I see a function `map_value_has_static_identity`. It appears to address lock identity in callbacks and how it interacts with array maps. It checks to see if there is only one element in the map and the map is of type `BPF_MAP_TYPE_ARRAY`. I see the addition of `callee->regs[BPF_REG_3].id = ++env->id_gen;` to assign an ID to a register pointing to a spinlock in a callback function if the map doesn't have a static identity. This appears relevant for protecting spinlocks in the context of callbacks. The KMSAN implications are less obvious here, but I must not discount the interaction with pointer manipulation. The selftests are a good sign; I'll need to review them to see what scenarios they cover. Tests for signal handling during program load, callback lock identity, core reloc raw, and xdp regsafe all seem relevant to potential data race issues. Overall, the packet pointer tracking and the spinlock protection seem like the most likely areas to require careful scrutiny for KMSAN, and my `grepper` search for `struct bpf_idmap` will be crucial to determining the appropriate `NeedsKMSAN` value and writing the `KMSANReasoning`. |
| 30/3 | 2026/09/06 11:24 | tool | grepper |
0mArgs:{
"Expression": "struct bpf_idmap"
}Results: {
"Output": "include/linux/bpf_verifier.h=854=struct bpf_id_pair {\n--\ninclude/linux/bpf_verifier.h-860-\ninclude/linux/bpf_verifier.h:861:struct bpf_idmap {\ninclude/linux/bpf_verifier.h-862-\tu32 tmp_id_gen;\n--\ninclude/linux/bpf_verifier.h=920=struct bpf_verifier_env {\n--\ninclude/linux/bpf_verifier.h-967-\tunion {\ninclude/linux/bpf_verifier.h:968:\t\tstruct bpf_idmap idmap_scratch;\ninclude/linux/bpf_verifier.h-969-\t\tstruct bpf_idset idset_scratch;\n--\nkernel/bpf/states.c=302=static bool range_within(const struct bpf_reg_state *old,\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=356=static bool check_pkt_ptr_ids(const struct bpf_reg_state *old,\nkernel/bpf/states.c-357-\t\t\t const struct bpf_reg_state *cur,\nkernel/bpf/states.c:358:\t\t\t struct bpf_idmap *idmap)\nkernel/bpf/states.c-359-{\n--\nkernel/bpf/states.c-417- */\nkernel/bpf/states.c:418:static bool check_scalar_ids(u32 old_id, u32 cur_id, struct bpf_idmap *idmap)\nkernel/bpf/states.c-419-{\n--\nkernel/bpf/states.c=526=static bool regs_exact(const struct bpf_reg_state *rold,\nkernel/bpf/states.c-527-\t\t const struct bpf_reg_state *rcur,\nkernel/bpf/states.c:528:\t\t struct bpf_idmap *idmap)\nkernel/bpf/states.c-529-{\n--\nkernel/bpf/states.c=542=static bool regsafe(struct bpf_verifier_env *env, struct bpf_reg_state *rold,\nkernel/bpf/states.c:543:\t\t struct bpf_reg_state *rcur, struct bpf_idmap *idmap,\nkernel/bpf/states.c-544-\t\t enum exact_level exact)\n--\nkernel/bpf/states.c=737=static bool stacksafe(struct bpf_verifier_env *env, struct bpf_func_state *old,\nkernel/bpf/states.c:738:\t\t struct bpf_func_state *cur, struct bpf_idmap *idmap,\nkernel/bpf/states.c-739-\t\t enum exact_level exact)\n--\nkernel/bpf/states.c=882=static bool stack_arg_safe(struct bpf_verifier_env *env, struct bpf_func_state *old,\nkernel/bpf/states.c:883:\t\t\t struct bpf_func_state *cur, struct bpf_idmap *idmap,\nkernel/bpf/states.c-884-\t\t\t enum exact_level exact)\n--\nkernel/bpf/states.c=904=static bool refsafe(struct bpf_verifier_state *old, struct bpf_verifier_state *cur,\nkernel/bpf/states.c:905:\t\t struct bpf_idmap *idmap)\nkernel/bpf/states.c-906-{\n--\nkernel/bpf/states.c=1007=static void reset_idmap_scratch(struct bpf_verifier_env *env)\nkernel/bpf/states.c-1008-{\nkernel/bpf/states.c:1009:\tstruct bpf_idmap *idmap = \u0026env-\u003eidmap_scratch;\nkernel/bpf/states.c-1010-\n--\nkernel/bpf/verifier.c=9427=static int release_reference_nomark(struct bpf_verifier_env *env, int id)\n--\nkernel/bpf/verifier.c-9436-\nkernel/bpf/verifier.c:9437:static int idstack_push(struct bpf_idmap *idmap, u32 id)\nkernel/bpf/verifier.c-9438-{\n--\nkernel/bpf/verifier.c-9454-\nkernel/bpf/verifier.c:9455:static int idstack_pop(struct bpf_idmap *idmap)\nkernel/bpf/verifier.c-9456-{\n--\nkernel/bpf/verifier.c=9464=static int release_reference(struct bpf_verifier_env *env, int id)\n--\nkernel/bpf/verifier.c-9467-\tstruct bpf_verifier_state *vstate = env-\u003ecur_state;\nkernel/bpf/verifier.c:9468:\tstruct bpf_idmap *idstack = \u0026env-\u003eidmap_scratch;\nkernel/bpf/verifier.c-9469-\tstruct bpf_stack_state *stack;\n"
} |
| 31/3 | 2026/09/06 11:24 | llm | kmsan-evaluator |
0mModel:gemini-3.7-flash Args: null Results: null Tokens: input: 14327 output: 36 thoughts: 29 Thoughts: Here's my summary, as though I'm thinking through this process: **Diving into Kernel BPF State Management** Okay, time to get my hands dirty. I need to take a look at the interplay between `check_ids` and `reset_idmap_scratch`. These functions are crucial for understanding how the BPF kernel is managing its internal state, specifically within the context of ID mapping. I'm going to head straight into `kernel/bpf/states.c` and start digging. I know this is where the core logic for checking and potentially resetting the ID map scratch area lives. I need to pinpoint exactly how these functions interact. I'm looking for the intricacies of how IDs are validated, potentially re-mapped, and how temporary scratch space is handled to keep the BPF execution environment clean and correct. Understanding this will be key to identifying any potential vulnerabilities or performance bottlenecks in the BPF subsystem. I’m thinking about the implications for secure and efficient BPF program execution; this is where the rubber meets the road. |
| 32/3 | 2026/09/06 11:24 | tool | read-file |
0mArgs:{
"File": "kernel/bpf/states.c",
"FirstLine": 320,
"LineCount": 40
}Results: {
"Contents": " 320:\t{\n 321:\t\tstruct bpf_id_pair *map = idmap-\u003emap;\n 322:\t\tunsigned int i;\n 323:\t\n 324:\t\t/* either both IDs should be set or both should be zero */\n 325:\t\tif (!!old_id != !!cur_id)\n 326:\t\t\treturn false;\n 327:\t\n 328:\t\tif (old_id == 0) /* cur_id == 0 as well */\n 329:\t\t\treturn true;\n 330:\t\n 331:\t\tfor (i = 0; i \u003c idmap-\u003ecnt; i++) {\n 332:\t\t\tif (map[i].old == old_id)\n 333:\t\t\t\treturn map[i].cur == cur_id;\n 334:\t\t\tif (map[i].cur == cur_id)\n 335:\t\t\t\treturn false;\n 336:\t\t}\n 337:\t\n 338:\t\t/* Reached the end of known mappings; haven't seen this id before */\n 339:\t\tif (idmap-\u003ecnt \u003c BPF_ID_MAP_SIZE) {\n 340:\t\t\tmap[idmap-\u003ecnt].old = old_id;\n 341:\t\t\tmap[idmap-\u003ecnt].cur = cur_id;\n 342:\t\t\tmap[idmap-\u003ecnt].pkt_ptr_delta_set = false;\n 343:\t\t\tidmap-\u003ecnt++;\n 344:\t\t\treturn true;\n 345:\t\t}\n 346:\t\n 347:\t\t/*\n 348:\t\t * idmap slots are bounded by the number of registers and stack slots.\n 349:\t\t * Since referenced dynptrs acquire intermediate references that do\n 350:\t\t * not live in either, so the map can be exhausted. Since it is unlikely,\n 351:\t\t * fail the verification by treating the states as not equivalent.\n 352:\t\t */\n 353:\t\treturn false;\n 354:\t}\n 355:\t\n 356:\tstatic bool check_pkt_ptr_ids(const struct bpf_reg_state *old,\n 357:\t\t\t\t const struct bpf_reg_state *cur,\n 358:\t\t\t\t struct bpf_idmap *idmap)\n 359:\t{\n"
} |
| 33/3 | 2026/09/06 11:24 | llm | kmsan-evaluator |
0mModel:gemini-3.7-flash Args: null Results: null Tokens: input: 15223 output: 37 thoughts: 15 Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience: **Checking `reset_idmap_scratch`** Right, before I get too deep into this, I need to make a mental note, and I really mean it, to also scrutinize `reset_idmap_scratch`. It's easy to focus on the primary issue, but experience has taught me that these seemingly peripheral functions can often harbor hidden dependencies or side effects that ultimately bite you in the rear later. My immediate instinct is to focus on the core logic, but a quick sanity check of `reset_idmap_scratch` could prevent a world of hurt down the line, especially if it's involved in any critical initialization or cleanup procedures. I can't just assume it's working as expected, even if it seems unrelated at first glance. It's a fundamental piece of the puzzle and that warrants an inspection. |
| 34/3 | 2026/09/06 11:24 | tool | read-file |
0mArgs:{
"File": "kernel/bpf/states.c",
"FirstLine": 1005,
"LineCount": 20
}Results: {
"Contents": "1005:\t}\n1006:\t\n1007:\tstatic void reset_idmap_scratch(struct bpf_verifier_env *env)\n1008:\t{\n1009:\t\tstruct bpf_idmap *idmap = \u0026env-\u003eidmap_scratch;\n1010:\t\n1011:\t\tidmap-\u003etmp_id_gen = env-\u003eid_gen;\n1012:\t\tidmap-\u003ecnt = 0;\n1013:\t}\n1014:\t\n1015:\tstatic bool states_equal(struct bpf_verifier_env *env,\n1016:\t\t\t\t struct bpf_verifier_state *old,\n1017:\t\t\t\t struct bpf_verifier_state *cur,\n1018:\t\t\t\t enum exact_level exact)\n1019:\t{\n1020:\t\tu32 insn_idx;\n1021:\t\tint i;\n1022:\t\n1023:\t\tif (old-\u003ecurframe != cur-\u003ecurframe)\n1024:\t\t\treturn false;\n"
} |
| 35/3 | 2026/09/06 11:24 | llm | kmsan-evaluator |
0mModel:gemini-3.7-flash Args: null Results: null Tokens: input: 15751 output: 37 thoughts: 25 Thoughts: Here's a summary of my thought process, as requested: **Deconstructing `idstack_push` and `idstack_pop` with Respect to `idmap_scratch`** Okay, so I'm diving into how `idstack_push` and `idstack_pop` interact with `idmap_scratch`. My immediate focus is on understanding the data flow and any potential dependencies or concurrency issues that might arise. I'm already anticipating that `idmap_scratch` likely serves as a temporary storage area, but I need to pinpoint *how* it's being utilized within these stack operations. Is it a staging area for IDs before being placed on the stack? Is it used for validation or conflict detection during push/pop operations? Or perhaps it handles temporary storage of elements that are being "popped" and later put somewhere else? I'm specifically looking for any subtle hints regarding potential race conditions. Could concurrent calls to these stack functions lead to corruption of data in `idmap_scratch`? Are there any locking mechanisms in place, or other concurrency control measures? The presence or absence of these things will guide my assessment of thread safety and the overall design soundness. I'm also going to see if any of these functions will alter the value, in any way, of `idmap_scratch`. This will tell me more about its expected behaviour. Essentially, I want to map out the control flow and data dependencies, focusing on how `idmap_scratch` is accessed and modified in relation to the stack manipulation. This is probably going to be pretty straightforward. But I need to be exact, so that I can then apply this knowledge to other parts of the system and see if it is used anywhere else in a similar way. |
| 36/3 | 2026/09/06 11:24 | tool | read-file |
0mArgs:{
"File": "kernel/bpf/verifier.c",
"FirstLine": 9430,
"LineCount": 40
}Results: {
"Contents": "9430:\t\n9431:\t\terr = __release_reference_nomark(env-\u003ecur_state, id);\n9432:\t\tif (!err)\n9433:\t\t\tbpf_diag_record_ref_release(env, env-\u003einsn_idx, id);\n9434:\t\treturn err;\n9435:\t}\n9436:\t\n9437:\tstatic int idstack_push(struct bpf_idmap *idmap, u32 id)\n9438:\t{\n9439:\t\tint i;\n9440:\t\n9441:\t\tif (!id)\n9442:\t\t\treturn 0;\n9443:\t\n9444:\t\tfor (i = 0; i \u003c idmap-\u003ecnt; i++)\n9445:\t\t\tif (idmap-\u003emap[i].old == id)\n9446:\t\t\t\treturn 0;\n9447:\t\n9448:\t\tif (WARN_ON_ONCE(idmap-\u003ecnt \u003e= BPF_ID_MAP_SIZE))\n9449:\t\t\treturn -EFAULT;\n9450:\t\n9451:\t\tidmap-\u003emap[idmap-\u003ecnt++].old = id;\n9452:\t\treturn 0;\n9453:\t}\n9454:\t\n9455:\tstatic int idstack_pop(struct bpf_idmap *idmap)\n9456:\t{\n9457:\t\tif (!idmap-\u003ecnt)\n9458:\t\t\treturn 0;\n9459:\t\n9460:\t\treturn idmap-\u003emap[--idmap-\u003ecnt].old;\n9461:\t}\n9462:\t\n9463:\t/* Release id and objects derived from it iteratively in a DFS manner */\n9464:\tstatic int release_reference(struct bpf_verifier_env *env, int id)\n9465:\t{\n9466:\t\tu32 mask = (1 \u003c\u003c STACK_SPILL) | (1 \u003c\u003c STACK_DYNPTR);\n9467:\t\tstruct bpf_verifier_state *vstate = env-\u003ecur_state;\n9468:\t\tstruct bpf_idmap *idstack = \u0026env-\u003eidmap_scratch;\n9469:\t\tstruct bpf_stack_state *stack;\n"
} |
| 37/3 | 2026/09/06 11:24 | llm | kmsan-evaluator |
0mModel:gemini-3.7-flash Args: null Results: null Tokens: input: 16781 output: 291 thoughts: 826 Thoughts: **KMSAN Evaluation: No Uninitialized Memory Risks Detected** Alright, let's break down these changes piece by piece and assess their potential impact from a memory safety perspective, specifically concerning KMSAN. My analysis focuses on the risk of uninitialized memory being read, leaked to userspace, or leading to unexpected behavior. First, the `bpf_id_pair` structure updates, including the new fields `pkt_ptr_delta` and `pkt_ptr_delta_set`, seem safe. The initialization of `pkt_ptr_delta_set` to `false` within `check_ids` and the subsequent setting of `pkt_ptr_delta` within `check_pkt_ptr_ids` ensures that the code correctly sets these fields. There's no scenario where these fields are accessed before initialization, and the `idmap` is properly managed within `env->idmap_scratch`. So, no concerns here regarding uninitialized memory reads. Next, the modification to `kernel/bpf/cfg.c` with the `push_insn()` logic, which is just standard logic validation on the BPF CFG, doesn't seem to introduce any memory safety vulnerabilities. It's just a control flow verification. The addition of `bpf_rewrite_must_abort()` within `kernel/bpf/fixups.c` and its use in `bpf_patch_insn_data()` and `verifier_remove_insns()` is all about handling potential signal interruptions. The primary purpose is to avoid long stalls and prevent the system from getting stuck. This doesn't involve any uninitialized memory operations, either. The changes in `kernel/bpf/verifier.c`, which introduce distinct `id` assignments for callback map pointers when specific conditions are met, are all about state tracking within the verifier. This is a crucial mechanism to prevent potential incorrect unlocking of spin locks. The conditions where it sets these IDs are carefully verified. So, the introduction of a distinct `id` based on `reg_may_point_to_spin_lock` and the map value not being a one-element array, also appears safe and focused on tracking verifier state. The inclusion of the selftests covering the changes and the signal handling during `bpf_prog_load` is important but confirms the expected behavior based on the described logic. Finally, the KMSAN criteria. After considering these changes: I am confident that these patches **do not** introduce or expose any uninitialized memory risks that KMSAN would specifically target. There's no risk of kernel structures being sent to userspace with uninitialized fields, no conditional branching based on uninitialized data, and no complex data structure allocation with later uninitialized reads. The changes involve logical validation, verifier state tracking, and signal handling during BPF operations, not raw memory manipulation. The BPF verifier itself enforces type safety and bounds checks on BPF programs, which is a very robust mechanism for ensuring overall memory safety. Standard KASAN fuzzing and testing will be sufficient here. I'm comfortable setting `NeedsKMSAN: false` in the set-results tool. |
| 38/3 | 2026/09/06 11:24 | tool | set-results |
0mArgs:{
"KMSANReasoning": "The patch series modifies the BPF verifier and CFG analysis in several areas:\n1. Adds packet pointer displacement tracking across state equivalence checks in `kernel/bpf/states.c` (using `check_pkt_ptr_ids` and initializing `pkt_ptr_delta_set` in `check_ids`).\n2. Validates subprogram boundaries on fall-through edges in `kernel/bpf/cfg.c`.\n3. Adds fatal signal checks (`bpf_rewrite_must_abort`) to prevent non-killable loops during post-verification instruction patching/removal in `kernel/bpf/fixups.c`.\n4. Ensures distinct register IDs for callback map values that may point to spin locks unless the map has static identity in `kernel/bpf/verifier.c`.\n\nNone of these changes allocate or manipulate uninitialized memory buffers, copy uninitialized data to user space, or alter buffer lengths in ways that expose uninitialized stack or heap data. All struct fields added (`pkt_ptr_delta`, `pkt_ptr_delta_set`) are explicitly initialized before read operations. The changes are strictly verifier logic, control-flow validation, and signal-handling improvements. Therefore, a dedicated KMSAN fuzzing session is not required.",
"NeedsKMSAN": false
}Results: {
"KMSANReasoning": "The patch series modifies the BPF verifier and CFG analysis in several areas:\n1. Adds packet pointer displacement tracking across state equivalence checks in `kernel/bpf/states.c` (using `check_pkt_ptr_ids` and initializing `pkt_ptr_delta_set` in `check_ids`).\n2. Validates subprogram boundaries on fall-through edges in `kernel/bpf/cfg.c`.\n3. Adds fatal signal checks (`bpf_rewrite_must_abort`) to prevent non-killable loops during post-verification instruction patching/removal in `kernel/bpf/fixups.c`.\n4. Ensures distinct register IDs for callback map values that may point to spin locks unless the map has static identity in `kernel/bpf/verifier.c`.\n\nNone of these changes allocate or manipulate uninitialized memory buffers, copy uninitialized data to user space, or alter buffer lengths in ways that expose uninitialized stack or heap data. All struct fields added (`pkt_ptr_delta`, `pkt_ptr_delta_set`) are explicitly initialized before read operations. The changes are strictly verifier logic, control-flow validation, and signal-handling improvements. Therefore, a dedicated KMSAN fuzzing session is not required.",
"NeedsKMSAN": false
} |
| Total Calls | Total Tokens | Avg Tokens | Total Duration (Seconds) | Avg Duration (Seconds) |
|---|
| Total Calls | Total Duration (Seconds) | Avg Duration (Seconds) |
|---|