| Seq | Timestamp | Type | Name | Duration |
|---|---|---|---|---|
| 0/0 | 2026/08/11 00:34 | flow | patch-triage |
1mArgs:null Results: {
"EnableConfigs": [
"BPF_SYSCALL",
"BPF_JIT"
],
"FocusSymbols": [
"bpf_insn_def32",
"ex_handler_bpf",
"bpf_jit_emit_insn",
"bpf_int_jit_compile",
"bpf_check"
],
"KMSANReasoning": "The patch fixes the BPF exception handler for arena accesses to correctly identify read-modify-write atomic operations (like BPF_XCHG and BPF_CMPXCHG) as writes, and to properly clear the destination register (e.g., BPF_REG_0 for CMPXCHG) when a page fault occurs. If the register is not cleared, the BPF program simply retains the previous value of that register. This does not involve uninitialized kernel memory, nor does it expose kernel stack/heap memory to user space. The issue is a logic bug in BPF JIT exception handling, which does not introduce risks of uninitialized memory usage that would require KMSAN to detect. Standard testing and BPF selftests (as included in the patch) are sufficient to verify the fix.",
"NeedsKMSAN": false,
"Reasoning": "The patch modifies the BPF JIT compilers (x86, arm64, riscv, s390) and the BPF verifier to correctly handle exceptions for atomic operations in the BPF arena. It introduces `bpf_atomic_load_reg` to identify the register that needs to be cleared when an atomic instruction faults, and ensures that read-modify-write operations are correctly reported as writes. These are functional changes to reachable core kernel logic (BPF subsystem) and should be fuzzed.",
"WorthFuzzing": true
} |
| 1/1 | 2026/08/11 00:34 | action | read-patch-diff |
0mArgs:null Results: {
"PatchDiff": "commit f4aa7521f85803fd3a1bae14519da0abdc1df01f\nAuthor: syz-cluster \u003ctriage@syzkaller.com\u003e\nDate: Tue Aug 11 00:34:18 2026 +0000\n\n syz-cluster: applied patch under review\n\ndiff --git a/arch/arm64/net/bpf_jit_comp.c b/arch/arm64/net/bpf_jit_comp.c\nindex d14d297ebb967..74b4083791da3 100644\n--- a/arch/arm64/net/bpf_jit_comp.c\n+++ b/arch/arm64/net/bpf_jit_comp.c\n@@ -1082,23 +1082,27 @@ static void build_epilogue(struct jit_ctx *ctx, bool was_classic)\n *\n * Bit layout of `fixup` (32-bit):\n *\n- * +-----------+--------+-----------+-----------+----------+\n- * | 31-27 | 26-22 | 21 | 20-16 | 15-0 |\n- * | | | | | |\n- * | FIXUP_REG | Unused | ARENA_ACC | ARENA_REG | OFFSET |\n- * +-----------+--------+-----------+-----------+----------+\n+ * +-----------+--------+-------------+-----------+-----------+----------+\n+ * | 31-27 | 26-23 | 22 | 21 | 20-16 | 15-0 |\n+ * | | | | | | |\n+ * | FIXUP_REG | Unused | ARENA_WRITE | ARENA_ACC | ARENA_REG | OFFSET |\n+ * +-----------+--------+-------------+-----------+-----------+----------+\n *\n * - OFFSET (16 bits): Offset used to compute address for Load/Store instruction.\n * - ARENA_REG (5 bits): Register that is used to calculate the address for load/store when\n * accessing the arena region.\n * - ARENA_ACCESS (1 bit): This bit is set when the faulting instruction accessed the arena region.\n+ * - ARENA_WRITE (1 bit): This bit is set when the faulting instruction wrote to the arena region.\n+ * It is independent of FIXUP_REG, since a read-modify-write both writes to\n+ * memory and reads the old value into a register.\n * - FIXUP_REG (5 bits): Destination register for the load instruction (cleared on fault) or set to\n- * DONT_CLEAR if it is a store instruction.\n+ * DONT_CLEAR if the instruction does not read into a register.\n */\n \n #define BPF_FIXUP_OFFSET_MASK GENMASK(15, 0)\n #define BPF_FIXUP_ARENA_REG_MASK GENMASK(20, 16)\n #define BPF_ARENA_ACCESS BIT(21)\n+#define BPF_ARENA_WRITE BIT(22)\n #define BPF_FIXUP_REG_MASK\tGENMASK(31, 27)\n #define DONT_CLEAR 5 /* Unused ARM64 register from BPF's POV */\n \n@@ -1109,7 +1113,7 @@ bool ex_handler_bpf(const struct exception_table_entry *ex,\n \ts16 off = FIELD_GET(BPF_FIXUP_OFFSET_MASK, ex-\u003efixup);\n \tint arena_reg = FIELD_GET(BPF_FIXUP_ARENA_REG_MASK, ex-\u003efixup);\n \tbool is_arena = !!(ex-\u003efixup \u0026 BPF_ARENA_ACCESS);\n-\tbool is_write = (dst_reg == DONT_CLEAR);\n+\tbool is_write = !!(ex-\u003efixup \u0026 BPF_ARENA_WRITE);\n \tunsigned long addr;\n \n \tif (is_arena) {\n@@ -1132,7 +1136,7 @@ static int add_exception_handler(const struct bpf_insn *insn,\n {\n \toff_t ins_offset;\n \ts16 off = insn-\u003eoff;\n-\tbool is_arena;\n+\tbool is_arena, is_write;\n \tint arena_reg;\n \tunsigned long pc;\n \tstruct exception_table_entry *ex;\n@@ -1181,15 +1185,18 @@ static int add_exception_handler(const struct bpf_insn *insn,\n \t/*\n \t * A load-acquire is of BPF_STX class, but reads from src_reg into\n \t * dst_reg like a BPF_LDX does, hence it must not be treated as a store\n-\t * here.\n+\t * here. A read-modify-write carrying BPF_FETCH is reported as a write\n+\t * even though it does have a register to clear, see the callers.\n \t */\n-\tif (BPF_CLASS(insn-\u003ecode) != BPF_LDX \u0026\u0026 !bpf_atomic_is_load_acq(insn))\n-\t\tdst_reg = DONT_CLEAR;\n+\tis_write = BPF_CLASS(insn-\u003ecode) != BPF_LDX \u0026\u0026\n+\t\t !bpf_atomic_is_load_acq(insn);\n \n \tex-\u003efixup = FIELD_PREP(BPF_FIXUP_REG_MASK, dst_reg);\n \n \tif (is_arena) {\n \t\tex-\u003efixup |= BPF_ARENA_ACCESS;\n+\t\tif (is_write)\n+\t\t\tex-\u003efixup |= BPF_ARENA_WRITE;\n \t\t/*\n \t\t * insn-\u003esrc_reg/dst_reg holds the address in the arena region with upper 32-bits\n \t\t * being zero because of a preceding addr_space_cast(r\u003cn\u003e, 0x0, 0x1) instruction.\n@@ -1889,7 +1896,7 @@ static int build_insn(const struct bpf_verifier_env *env, const struct bpf_insn\n \t\t\tbreak;\n \t\t}\n \n-\t\tret = add_exception_handler(insn, ctx, dst);\n+\t\tret = add_exception_handler(insn, ctx, DONT_CLEAR);\n \t\tif (ret)\n \t\t\treturn ret;\n \t\tbreak;\n@@ -1956,7 +1963,7 @@ static int build_insn(const struct bpf_verifier_env *env, const struct bpf_insn\n \t\t\tbreak;\n \t\t}\n \n-\t\tret = add_exception_handler(insn, ctx, dst);\n+\t\tret = add_exception_handler(insn, ctx, DONT_CLEAR);\n \t\tif (ret)\n \t\t\treturn ret;\n \t\tbreak;\n@@ -1979,7 +1986,16 @@ static int build_insn(const struct bpf_verifier_env *env, const struct bpf_insn\n \t\t\treturn ret;\n \n \t\tif (BPF_MODE(insn-\u003ecode) == BPF_PROBE_ATOMIC) {\n-\t\t\tret = add_exception_handler(insn, ctx, dst);\n+\t\t\t/*\n+\t\t\t * A load-acquire reads into dst_reg, and a read-modify-write\n+\t\t\t * carrying BPF_FETCH reads the old value into src_reg, or into\n+\t\t\t * r0 for a BPF_CMPXCHG. Clear that register on fault, the\n+\t\t\t * remaining atomics have no destination register.\n+\t\t\t */\n+\t\t\tint load_reg = bpf_atomic_load_reg(insn);\n+\n+\t\t\tret = add_exception_handler(insn, ctx, load_reg \u003c 0 ?\n+\t\t\t\t\t\t DONT_CLEAR : bpf2a64[load_reg]);\n \t\t\tif (ret)\n \t\t\t\treturn ret;\n \t\t}\ndiff --git a/arch/riscv/net/bpf_jit_comp64.c b/arch/riscv/net/bpf_jit_comp64.c\nindex 6b9972b07c1b0..2504df1fa1118 100644\n--- a/arch/riscv/net/bpf_jit_comp64.c\n+++ b/arch/riscv/net/bpf_jit_comp64.c\n@@ -1992,10 +1992,19 @@ int bpf_jit_emit_insn(const struct bpf_insn *insn, struct rv_jit_context *ctx,\n \t\t\tret = emit_atomic_rmw(rd, rs, insn, ctx);\n \n \t\t/* ret can be 1 (skip-zext); extable entry still needs to be added */\n-\t\tif (ret \u003e= 0)\n-\t\t\tret = add_exception_handler(insn,\n-\t\t\t\tbpf_atomic_is_load_acq(insn) ? rd : REG_DONT_CLEAR_MARKER,\n-\t\t\t\tctx) ?: ret;\n+\t\tif (ret \u003e= 0) {\n+\t\t\t/*\n+\t\t\t * A load-acquire reads into dst_reg, and a read-modify-write\n+\t\t\t * carrying BPF_FETCH reads the old value into src_reg, or into\n+\t\t\t * r0 for a BPF_CMPXCHG. Clear that register on fault, the\n+\t\t\t * remaining atomics have no destination register.\n+\t\t\t */\n+\t\t\tint load_reg = bpf_atomic_load_reg(insn);\n+\n+\t\t\tret = add_exception_handler(insn, load_reg \u003c 0 ?\n+\t\t\t\t\tREG_DONT_CLEAR_MARKER : regmap[load_reg],\n+\t\t\t\t\tctx) ?: ret;\n+\t\t}\n \n \t\tif (ret)\n \t\t\treturn ret;\ndiff --git a/arch/s390/net/bpf_jit_comp.c b/arch/s390/net/bpf_jit_comp.c\nindex b60877478b45d..c46872b071ce7 100644\n--- a/arch/s390/net/bpf_jit_comp.c\n+++ b/arch/s390/net/bpf_jit_comp.c\n@@ -774,6 +774,8 @@ static void bpf_jit_probe_atomic_pre(struct bpf_jit *jit,\n \t\t\t\t struct bpf_insn *insn,\n \t\t\t\t struct bpf_jit_probe *probe)\n {\n+\tint load_reg;\n+\n \tif (BPF_MODE(insn-\u003ecode) != BPF_PROBE_ATOMIC)\n \t\treturn;\n \n@@ -783,6 +785,14 @@ static void bpf_jit_probe_atomic_pre(struct bpf_jit *jit,\n \tEMIT4(0xb9080000, REG_W1, insn-\u003edst_reg);\n \tprobe-\u003earena_reg = REG_W1;\n \tprobe-\u003eprg = jit-\u003eprg;\n+\t/*\n+\t * A read-modify-write carrying BPF_FETCH reads the old value into\n+\t * src_reg, or into r0 for a BPF_CMPXCHG. Clear that register on\n+\t * fault, the remaining atomics only write memory.\n+\t */\n+\tload_reg = bpf_atomic_load_reg(insn);\n+\tif (load_reg \u003e= 0)\n+\t\tprobe-\u003ereg = reg2hex[load_reg];\n }\n \n static int bpf_jit_probe_post(struct bpf_jit *jit, struct bpf_prog *fp,\n@@ -1684,6 +1694,7 @@ static noinline int bpf_jit_insn(struct bpf_jit *jit, struct bpf_prog *fp,\n \t\t\tif (load_probe.prg != -1) {\n \t\t\t\tprobe.prg = jit-\u003eprg;\n \t\t\t\tprobe.arena_reg = load_probe.arena_reg;\n+\t\t\t\tprobe.reg = load_probe.reg;\n \t\t\t}\n \t\t\tloop_start = jit-\u003eprg;\n \t\t\t/* 0: {csy|csg} %w0,%src,off(%arena) */\ndiff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c\nindex 8dddb5d7af21b..d920772af7d5f 100644\n--- a/arch/x86/net/bpf_jit_comp.c\n+++ b/arch/x86/net/bpf_jit_comp.c\n@@ -1473,17 +1473,20 @@ static int emit_atomic_ld_st_index(u8 **pprog, u32 atomic_op, u32 size,\n *\n * Bit layout of `fixup` (32-bit):\n *\n- * +-----------+--------+-----------+---------+----------+\n- * | 31 | 30-24 | 23-16 | 15-8 | 7-0 |\n- * | | | | | |\n- * | ARENA_ACC | Unused | ARENA_REG | DST_REG | INSN_LEN |\n- * +-----------+--------+-----------+---------+----------+\n+ * +-----------+-------------+--------+-----------+---------+----------+\n+ * | 31 | 30 | 29-24 | 23-16 | 15-8 | 7-0 |\n+ * | | | | | | |\n+ * | ARENA_ACC | ARENA_WRITE | Unused | ARENA_REG | DST_REG | INSN_LEN |\n+ * +-----------+-------------+--------+-----------+---------+----------+\n *\n * - INSN_LEN (8 bits): Length of faulting insn (max x86 insn = 15 bytes (fits in 8 bits)).\n * - DST_REG (8 bits): Offset of dst_reg from reg2pt_regs[] (max offset = 112 (fits in 8 bits)).\n- * This is set to DONT_CLEAR if the insn is a store.\n+ * This is set to DONT_CLEAR if the insn does not read into a register.\n * - ARENA_REG (8 bits): Offset of the register that is used to calculate the\n * address for load/store when accessing the arena region.\n+ * - ARENA_WRITE (1 bit): This bit is set when the faulting instruction wrote to the arena region.\n+ * It is independent of DST_REG, since a read-modify-write both writes to\n+ * memory and reads the old value into a register.\n * - ARENA_ACCESS (1 bit): This bit is set when the faulting instruction accessed the arena region.\n *\n * Bit layout of `data` (32-bit):\n@@ -1502,6 +1505,7 @@ static int emit_atomic_ld_st_index(u8 **pprog, u32 atomic_op, u32 size,\n #define FIXUP_INSN_LEN_MASK\tGENMASK(7, 0)\n #define FIXUP_REG_MASK\t\tGENMASK(15, 8)\n #define FIXUP_ARENA_REG_MASK\tGENMASK(23, 16)\n+#define FIXUP_ARENA_WRITE\tBIT(30)\n #define FIXUP_ARENA_ACCESS\tBIT(31)\n #define DATA_ARENA_OFFSET_MASK\tGENMASK(31, 16)\n \n@@ -1510,7 +1514,7 @@ bool ex_handler_bpf(const struct exception_table_entry *x, struct pt_regs *regs)\n \tu32 reg = FIELD_GET(FIXUP_REG_MASK, x-\u003efixup);\n \tu32 insn_len = FIELD_GET(FIXUP_INSN_LEN_MASK, x-\u003efixup);\n \tbool is_arena = !!(x-\u003efixup \u0026 FIXUP_ARENA_ACCESS);\n-\tbool is_write = (reg == DONT_CLEAR);\n+\tbool is_write = !!(x-\u003efixup \u0026 FIXUP_ARENA_WRITE);\n \tunsigned long addr;\n \ts16 off;\n \tu32 arena_reg;\n@@ -2348,6 +2352,7 @@ st:\t\t\tinsn_off = insn-\u003eoff;\n \t\t\t\tstruct exception_table_entry *ex;\n \t\t\t\tu8 *_insn = image + proglen + (start_of_ldx - temp);\n \t\t\t\tu32 arena_reg, fixup_reg;\n+\t\t\t\tbool is_write;\n \t\t\t\ts64 delta;\n \n \t\t\t\tif (!bpf_prog-\u003eaux-\u003eextable)\n@@ -2384,15 +2389,29 @@ st:\t\t\tinsn_off = insn-\u003eoff;\n \t\t\t\t bpf_atomic_is_load_acq(insn)) {\n \t\t\t\t\tarena_reg = reg2pt_regs[src_reg];\n \t\t\t\t\tfixup_reg = reg2pt_regs[dst_reg];\n+\t\t\t\t\tis_write = false;\n \t\t\t\t} else {\n+\t\t\t\t\t/*\n+\t\t\t\t\t * A store has no destination register to clear,\n+\t\t\t\t\t * except for a read-modify-write with BPF_FETCH,\n+\t\t\t\t\t * which also reads the old value into src_reg, or\n+\t\t\t\t\t * into r0 for a BPF_CMPXCHG. Either way the access\n+\t\t\t\t\t * is still reported as a write.\n+\t\t\t\t\t */\n+\t\t\t\t\tint load_reg = bpf_atomic_load_reg(insn);\n+\n \t\t\t\t\tarena_reg = reg2pt_regs[dst_reg];\n-\t\t\t\t\tfixup_reg = DONT_CLEAR;\n+\t\t\t\t\tfixup_reg = load_reg \u003c 0 ? DONT_CLEAR :\n+\t\t\t\t\t\t reg2pt_regs[load_reg];\n+\t\t\t\t\tis_write = true;\n \t\t\t\t}\n \n \t\t\t\tex-\u003efixup = FIELD_PREP(FIXUP_INSN_LEN_MASK, prog - start_of_ldx) |\n \t\t\t\t\t FIELD_PREP(FIXUP_ARENA_REG_MASK, arena_reg) |\n \t\t\t\t\t FIELD_PREP(FIXUP_REG_MASK, fixup_reg);\n \t\t\t\tex-\u003efixup |= FIXUP_ARENA_ACCESS;\n+\t\t\t\tif (is_write)\n+\t\t\t\t\tex-\u003efixup |= FIXUP_ARENA_WRITE;\n \n \t\t\t\tex-\u003edata |= FIELD_PREP(DATA_ARENA_OFFSET_MASK, insn-\u003eoff);\n \t\t\t}\ndiff --git a/include/linux/filter.h b/include/linux/filter.h\nindex 4edba8182db1b..15d83684c6e94 100644\n--- a/include/linux/filter.h\n+++ b/include/linux/filter.h\n@@ -414,6 +414,30 @@ static inline bool bpf_atomic_is_load_acq(const struct bpf_insn *insn)\n \t insn-\u003eimm == BPF_LOAD_ACQ;\n }\n \n+/*\n+ * Given an instruction @insn, return the number of the BPF register that a\n+ * BPF_ATOMIC reads the value at its memory operand into, or -1 if there is\n+ * no such register. That is the register a BPF_PROBE_ATOMIC has to clear when\n+ * the access faults. Like bpf_atomic_is_load_acq(), @insn is not assumed to\n+ * be a BPF_ATOMIC here.\n+ */\n+static inline int bpf_atomic_load_reg(const struct bpf_insn *insn)\n+{\n+\tif (BPF_CLASS(insn-\u003ecode) != BPF_STX ||\n+\t (BPF_MODE(insn-\u003ecode) != BPF_ATOMIC \u0026\u0026\n+\t BPF_MODE(insn-\u003ecode) != BPF_PROBE_ATOMIC))\n+\t\treturn -1;\n+\n+\tswitch (insn-\u003eimm) {\n+\tcase BPF_LOAD_ACQ:\n+\t\treturn insn-\u003edst_reg;\n+\tcase BPF_CMPXCHG:\n+\t\treturn BPF_REG_0;\n+\tdefault:\n+\t\treturn (insn-\u003eimm \u0026 BPF_FETCH) ? insn-\u003esrc_reg : -1;\n+\t}\n+}\n+\n /* Memory store, *(uint *) (dst_reg + off16) = imm32 */\n \n #define BPF_ST_MEM(SIZE, DST, OFF, IMM)\t\t\t\t\\\ndiff --git a/kernel/bpf/fixups.c b/kernel/bpf/fixups.c\nindex 661e2d13a6042..c4bd70befbb5c 100644\n--- a/kernel/bpf/fixups.c\n+++ b/kernel/bpf/fixups.c\n@@ -49,16 +49,7 @@ static int insn_def_regno(const struct bpf_insn *insn)\n \tcase BPF_ST:\n \t\treturn -1;\n \tcase BPF_STX:\n-\t\tif (BPF_MODE(insn-\u003ecode) == BPF_ATOMIC ||\n-\t\t BPF_MODE(insn-\u003ecode) == BPF_PROBE_ATOMIC) {\n-\t\t\tif (insn-\u003eimm == BPF_CMPXCHG)\n-\t\t\t\treturn BPF_REG_0;\n-\t\t\telse if (insn-\u003eimm == BPF_LOAD_ACQ)\n-\t\t\t\treturn insn-\u003edst_reg;\n-\t\t\telse if (insn-\u003eimm \u0026 BPF_FETCH)\n-\t\t\t\treturn insn-\u003esrc_reg;\n-\t\t}\n-\t\treturn -1;\n+\t\treturn bpf_atomic_load_reg(insn);\n \tdefault:\n \t\treturn insn-\u003edst_reg;\n \t}\ndiff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c\nindex add3affc57035..73a2e8bb1782a 100644\n--- a/kernel/bpf/verifier.c\n+++ b/kernel/bpf/verifier.c\n@@ -6485,21 +6485,16 @@ static int check_atomic_rmw(struct bpf_verifier_env *env,\n \t\treturn -EACCES;\n \t}\n \n-\tif (insn-\u003eimm \u0026 BPF_FETCH) {\n-\t\tif (insn-\u003eimm == BPF_CMPXCHG)\n-\t\t\tload_reg = BPF_REG_0;\n-\t\telse\n-\t\t\tload_reg = insn-\u003esrc_reg;\n-\n+\t/*\n+\t * A negative load_reg means that this instruction accesses a memory\n+\t * location but doesn't actually load it into a register.\n+\t */\n+\tload_reg = bpf_atomic_load_reg(insn);\n+\tif (load_reg \u003e= 0) {\n \t\t/* check and record load of old value */\n \t\terr = check_reg_arg(env, load_reg, DST_OP);\n \t\tif (err)\n \t\t\treturn err;\n-\t} else {\n-\t\t/* This instruction accesses a memory location but doesn't\n-\t\t * actually load it into a register.\n-\t\t */\n-\t\tload_reg = -1;\n \t}\n \n \tdst_reg = cur_regs(env) + insn-\u003edst_reg;\ndiff --git a/tools/testing/selftests/bpf/prog_tests/stream.c b/tools/testing/selftests/bpf/prog_tests/stream.c\nindex 15dd3ae2a84b7..e4e9374309e26 100644\n--- a/tools/testing/selftests/bpf/prog_tests/stream.c\n+++ b/tools/testing/selftests/bpf/prog_tests/stream.c\n@@ -105,6 +105,10 @@ void test_stream_arena_fault_address(void)\n \t\ttest_address(skel-\u003eprogs.stream_arena_write_fault, \u0026skel-\u003ebss-\u003efault_addr);\n \tif (test__start_subtest(\"load_acquire_fault\"))\n \t\ttest_address(skel-\u003eprogs.stream_arena_load_acquire_fault, \u0026skel-\u003ebss-\u003efault_addr);\n+\tif (test__start_subtest(\"xchg_fault\"))\n+\t\ttest_address(skel-\u003eprogs.stream_arena_xchg_fault, \u0026skel-\u003ebss-\u003efault_addr);\n+\tif (test__start_subtest(\"cmpxchg_fault\"))\n+\t\ttest_address(skel-\u003eprogs.stream_arena_cmpxchg_fault, \u0026skel-\u003ebss-\u003efault_addr);\n \n \tstream__destroy(skel);\n }\ndiff --git a/tools/testing/selftests/bpf/progs/stream.c b/tools/testing/selftests/bpf/progs/stream.c\nindex cf5533e11f39c..00a37933e411d 100644\n--- a/tools/testing/selftests/bpf/progs/stream.c\n+++ b/tools/testing/selftests/bpf/progs/stream.c\n@@ -229,6 +229,107 @@ int stream_arena_load_acquire_fault(void *ctx)\n \treturn val;\n }\n \n+SEC(\"syscall\")\n+__arch_x86_64\n+__arch_arm64\n+__success __retval(0)\n+__stderr(\"ERROR: Arena WRITE access at unmapped address 0x{{.*}}\")\n+__stderr(\"CPU: {{[0-9]+}} UID: 0 PID: {{[0-9]+}} Comm: {{.*}}\")\n+__stderr(\"Call trace:\\n\"\n+\"{{([a-zA-Z_][a-zA-Z0-9_]*\\\\+0x[0-9a-fA-F]+/0x[0-9a-fA-F]+\\n\"\n+\"|[ \\t]+[^\\n]+\\n)*}}\")\n+int stream_arena_xchg_fault(void *ctx)\n+{\n+\tstatic const struct bpf_insn xchg_insn = {\n+\t\t.code\t = 0xc3,\t/* BPF_STX | BPF_ATOMIC | BPF_W */\n+\t\t.dst_reg = 1,\t\t/* BPF_REG_1 */\n+\t\t.src_reg = 2,\t\t/* BPF_REG_2 */\n+\t\t.off\t = 0x7fff,\n+\t\t.imm\t = 0xe1,\t/* BPF_XCHG */\n+\t};\n+\tstruct bpf_arena *ptr = (void *)\u0026arena;\n+\tu64 user_vm_start, val;\n+\n+\t/*\n+\t * Prevent GCC bounds warning: casting \u0026arena to struct bpf_arena *\n+\t * triggers bounds checking since the map definition is smaller than\n+\t * struct bpf_arena. barrier_var() makes the pointer opaque to GCC,\n+\t * preventing the bounds analysis.\n+\t */\n+\tbarrier_var(ptr);\n+\tuser_vm_start = ptr-\u003euser_vm_start;\n+\tfault_addr = user_vm_start + 0x7fff;\n+\tbpf_addr_space_cast(user_vm_start, 0, 1);\n+\t/*\n+\t * A read-modify-write carrying BPF_FETCH writes to memory, so the fault\n+\t * has to be reported as a WRITE from the dst_reg address, but it also\n+\t * reads the old value into src_reg, so the exception handler has to\n+\t * clear src_reg. Poison it up front, the returned value must be 0.\n+\t */\n+\tasm volatile (\n+\t\t\"r1 = %[user_vm_start];\"\n+\t\t\"r2 = 1;\"\n+\t\t\".8byte %[xchg_insn];\" /* r2 = xchg((u32 *)(r1 + 0x7fff), r2) */\n+\t\t\"%[val] = r2;\"\n+\t\t: [val] \"=r\" (val)\n+\t\t: [user_vm_start] \"r\" (user_vm_start),\n+\t\t __imm_insn(xchg_insn, xchg_insn)\n+\t\t: \"r1\", \"r2\"\n+\t);\n+\treturn val;\n+}\n+\n+SEC(\"syscall\")\n+__arch_x86_64\n+__arch_arm64\n+__success __retval(0)\n+__stderr(\"ERROR: Arena WRITE access at unmapped address 0x{{.*}}\")\n+__stderr(\"CPU: {{[0-9]+}} UID: 0 PID: {{[0-9]+}} Comm: {{.*}}\")\n+__stderr(\"Call trace:\\n\"\n+\"{{([a-zA-Z_][a-zA-Z0-9_]*\\\\+0x[0-9a-fA-F]+/0x[0-9a-fA-F]+\\n\"\n+\"|[ \\t]+[^\\n]+\\n)*}}\")\n+int stream_arena_cmpxchg_fault(void *ctx)\n+{\n+\tstatic const struct bpf_insn cmpxchg_insn = {\n+\t\t.code\t = 0xc3,\t/* BPF_STX | BPF_ATOMIC | BPF_W */\n+\t\t.dst_reg = 1,\t\t/* BPF_REG_1 */\n+\t\t.src_reg = 2,\t\t/* BPF_REG_2 */\n+\t\t.off\t = 0x7fff,\n+\t\t.imm\t = 0xf1,\t/* BPF_CMPXCHG */\n+\t};\n+\tstruct bpf_arena *ptr = (void *)\u0026arena;\n+\tu64 user_vm_start, val;\n+\n+\t/*\n+\t * Prevent GCC bounds warning: casting \u0026arena to struct bpf_arena *\n+\t * triggers bounds checking since the map definition is smaller than\n+\t * struct bpf_arena. barrier_var() makes the pointer opaque to GCC,\n+\t * preventing the bounds analysis.\n+\t */\n+\tbarrier_var(ptr);\n+\tuser_vm_start = ptr-\u003euser_vm_start;\n+\tfault_addr = user_vm_start + 0x7fff;\n+\tbpf_addr_space_cast(user_vm_start, 0, 1);\n+\t/*\n+\t * Same as the exchange above, except that a BPF_CMPXCHG reads the old\n+\t * value into r0 rather than into src_reg, so r0 is the register the\n+\t * exception handler has to clear. It doubles as the compare value, but\n+\t * the comparison never happens since the access faults first.\n+\t */\n+\tasm volatile (\n+\t\t\"r1 = %[user_vm_start];\"\n+\t\t\"r0 = 1;\"\n+\t\t\"r2 = 2;\"\n+\t\t\".8byte %[cmpxchg_insn];\" /* r0 = cmpxchg((u32 *)(r1 + 0x7fff), r0, r2) */\n+\t\t\"%[val] = r0;\"\n+\t\t: [val] \"=r\" (val)\n+\t\t: [user_vm_start] \"r\" (user_vm_start),\n+\t\t __imm_insn(cmpxchg_insn, cmpxchg_insn)\n+\t\t: \"r0\", \"r1\", \"r2\"\n+\t);\n+\treturn val;\n+}\n+\n static __noinline void subprog(void)\n {\n \tint __arena *addr = (int __arena *)0xdeadbeef;\n"
} |
| 2/1 | 2026/08/11 00:34 | agent | patch-evaluator |
1mModel:best-expensive Args: null Results: {
"EnableConfigs": [
"BPF_SYSCALL",
"BPF_JIT"
],
"FocusSymbols": [
"bpf_insn_def32",
"ex_handler_bpf",
"bpf_jit_emit_insn",
"bpf_int_jit_compile",
"bpf_check"
],
"Reasoning": "The patch modifies the BPF JIT compilers (x86, arm64, riscv, s390) and the BPF verifier to correctly handle exceptions for atomic operations in the BPF arena. It introduces `bpf_atomic_load_reg` to identify the register that needs to be cleared when an atomic instruction faults, and ensures that read-modify-write operations are correctly reported as writes. These are functional changes to reachable core kernel logic (BPF subsystem) and should be fuzzed.",
"WorthFuzzing": true
}Instruction: You are an expert Linux kernel maintainer. Your job is to review a provided patch series and determine if it makes functional changes to the kernel that should be fuzzed. IMPORTANT: The changes have ALREADY been applied and committed as the HEAD commit in your workspace. Do NOT rely on your internal knowledge of the kernel. You must actively use your code access tools to examine the actual source code and confirm any assumptions. Return WorthFuzzing=false if the patch only contains: - Modifications to Documentation/, Kconfig files, or code comments. - Purely decorative changes, such as logging (e.g., pr_err, printk) or tracepoints. - Changes to numeric constants or macros that do not functionally alter execution flow. - Code paths that are impossible to reach in virtualized environments like GCE or QEMU, even when utilizing software-emulated hardware (e.g., usb gadget, mac80211_hwsim). - Code in vendor-specific PCIe switch, SmartNIC, or GPU drivers (e.g., mlxsw, pds_core, qed, ionic, amdgpu) that require physical PCIe hardware cards not emulated in standard QEMU. - Driver .remove, .shutdown, or pci_unregister_driver teardown callbacks (e.g., igb_remove) that are executed only during PCI hot-unplug or sysfs driver unbind operations. If it modifies reachable core kernel logic, drivers, or architectures, use your code search tools to verify the code can be executed, then return WorthFuzzing=true. When returning WorthFuzzing=true, you MUST ALSO: 1. Extract any specific kernel functions that should be heavily fuzzed into FocusSymbols. Avoid listing generic hot-path functions to prevent skewed test distributions. Prefer non-static, non-inlined API entrypoint functions over internal static helper functions (which are inlined by the compiler and do not have distinct symbol addresses). 2. Identify any specific CONFIG_ options required to properly test this new/modified feature. Go and look into the Kconfig files and check for ifdefs around the code, do not make assumptions. Also check "depends on" lines in Kconfig to include any non-standard parent subsystem configs needed for Kbuild to compile the code statically into vmlinux. List them in the EnableConfigs output array, and DO NOT add a '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: For your convenience, here is the diff of the changes:
commit f4aa7521f85803fd3a1bae14519da0abdc1df01f
Author: syz-cluster <triage@syzkaller.com>
Date: Tue Aug 11 00:34:18 2026 +0000
syz-cluster: applied patch under review
diff --git a/arch/arm64/net/bpf_jit_comp.c b/arch/arm64/net/bpf_jit_comp.c
index d14d297ebb967..74b4083791da3 100644
--- a/arch/arm64/net/bpf_jit_comp.c
+++ b/arch/arm64/net/bpf_jit_comp.c
@@ -1082,23 +1082,27 @@ static void build_epilogue(struct jit_ctx *ctx, bool was_classic)
*
* Bit layout of `fixup` (32-bit):
*
- * +-----------+--------+-----------+-----------+----------+
- * | 31-27 | 26-22 | 21 | 20-16 | 15-0 |
- * | | | | | |
- * | FIXUP_REG | Unused | ARENA_ACC | ARENA_REG | OFFSET |
- * +-----------+--------+-----------+-----------+----------+
+ * +-----------+--------+-------------+-----------+-----------+----------+
+ * | 31-27 | 26-23 | 22 | 21 | 20-16 | 15-0 |
+ * | | | | | | |
+ * | FIXUP_REG | Unused | ARENA_WRITE | ARENA_ACC | ARENA_REG | OFFSET |
+ * +-----------+--------+-------------+-----------+-----------+----------+
*
* - OFFSET (16 bits): Offset used to compute address for Load/Store instruction.
* - ARENA_REG (5 bits): Register that is used to calculate the address for load/store when
* accessing the arena region.
* - ARENA_ACCESS (1 bit): This bit is set when the faulting instruction accessed the arena region.
+ * - ARENA_WRITE (1 bit): This bit is set when the faulting instruction wrote to the arena region.
+ * It is independent of FIXUP_REG, since a read-modify-write both writes to
+ * memory and reads the old value into a register.
* - FIXUP_REG (5 bits): Destination register for the load instruction (cleared on fault) or set to
- * DONT_CLEAR if it is a store instruction.
+ * DONT_CLEAR if the instruction does not read into a register.
*/
#define BPF_FIXUP_OFFSET_MASK GENMASK(15, 0)
#define BPF_FIXUP_ARENA_REG_MASK GENMASK(20, 16)
#define BPF_ARENA_ACCESS BIT(21)
+#define BPF_ARENA_WRITE BIT(22)
#define BPF_FIXUP_REG_MASK GENMASK(31, 27)
#define DONT_CLEAR 5 /* Unused ARM64 register from BPF's POV */
@@ -1109,7 +1113,7 @@ bool ex_handler_bpf(const struct exception_table_entry *ex,
s16 off = FIELD_GET(BPF_FIXUP_OFFSET_MASK, ex->fixup);
int arena_reg = FIELD_GET(BPF_FIXUP_ARENA_REG_MASK, ex->fixup);
bool is_arena = !!(ex->fixup & BPF_ARENA_ACCESS);
- bool is_write = (dst_reg == DONT_CLEAR);
+ bool is_write = !!(ex->fixup & BPF_ARENA_WRITE);
unsigned long addr;
if (is_arena) {
@@ -1132,7 +1136,7 @@ static int add_exception_handler(const struct bpf_insn *insn,
{
off_t ins_offset;
s16 off = insn->off;
- bool is_arena;
+ bool is_arena, is_write;
int arena_reg;
unsigned long pc;
struct exception_table_entry *ex;
@@ -1181,15 +1185,18 @@ static int add_exception_handler(const struct bpf_insn *insn,
/*
* A load-acquire is of BPF_STX class, but reads from src_reg into
* dst_reg like a BPF_LDX does, hence it must not be treated as a store
- * here.
+ * here. A read-modify-write carrying BPF_FETCH is reported as a write
+ * even though it does have a register to clear, see the callers.
*/
- if (BPF_CLASS(insn->code) != BPF_LDX && !bpf_atomic_is_load_acq(insn))
- dst_reg = DONT_CLEAR;
+ is_write = BPF_CLASS(insn->code) != BPF_LDX &&
+ !bpf_atomic_is_load_acq(insn);
ex->fixup = FIELD_PREP(BPF_FIXUP_REG_MASK, dst_reg);
if (is_arena) {
ex->fixup |= BPF_ARENA_ACCESS;
+ if (is_write)
+ ex->fixup |= BPF_ARENA_WRITE;
/*
* insn->src_reg/dst_reg holds the address in the arena region with upper 32-bits
* being zero because of a preceding addr_space_cast(r<n>, 0x0, 0x1) instruction.
@@ -1889,7 +1896,7 @@ static int build_insn(const struct bpf_verifier_env *env, const struct bpf_insn
break;
}
- ret = add_exception_handler(insn, ctx, dst);
+ ret = add_exception_handler(insn, ctx, DONT_CLEAR);
if (ret)
return ret;
break;
@@ -1956,7 +1963,7 @@ static int build_insn(const struct bpf_verifier_env *env, const struct bpf_insn
break;
}
- ret = add_exception_handler(insn, ctx, dst);
+ ret = add_exception_handler(insn, ctx, DONT_CLEAR);
if (ret)
return ret;
break;
@@ -1979,7 +1986,16 @@ static int build_insn(const struct bpf_verifier_env *env, const struct bpf_insn
return ret;
if (BPF_MODE(insn->code) == BPF_PROBE_ATOMIC) {
- ret = add_exception_handler(insn, ctx, dst);
+ /*
+ * A load-acquire reads into dst_reg, and a read-modify-write
+ * carrying BPF_FETCH reads the old value into src_reg, or into
+ * r0 for a BPF_CMPXCHG. Clear that register on fault, the
+ * remaining atomics have no destination register.
+ */
+ int load_reg = bpf_atomic_load_reg(insn);
+
+ ret = add_exception_handler(insn, ctx, load_reg < 0 ?
+ DONT_CLEAR : bpf2a64[load_reg]);
if (ret)
return ret;
}
diff --git a/arch/riscv/net/bpf_jit_comp64.c b/arch/riscv/net/bpf_jit_comp64.c
index 6b9972b07c1b0..2504df1fa1118 100644
--- a/arch/riscv/net/bpf_jit_comp64.c
+++ b/arch/riscv/net/bpf_jit_comp64.c
@@ -1992,10 +1992,19 @@ int bpf_jit_emit_insn(const struct bpf_insn *insn, struct rv_jit_context *ctx,
ret = emit_atomic_rmw(rd, rs, insn, ctx);
/* ret can be 1 (skip-zext); extable entry still needs to be added */
- if (ret >= 0)
- ret = add_exception_handler(insn,
- bpf_atomic_is_load_acq(insn) ? rd : REG_DONT_CLEAR_MARKER,
- ctx) ?: ret;
+ if (ret >= 0) {
+ /*
+ * A load-acquire reads into dst_reg, and a read-modify-write
+ * carrying BPF_FETCH reads the old value into src_reg, or into
+ * r0 for a BPF_CMPXCHG. Clear that register on fault, the
+ * remaining atomics have no destination register.
+ */
+ int load_reg = bpf_atomic_load_reg(insn);
+
+ ret = add_exception_handler(insn, load_reg < 0 ?
+ REG_DONT_CLEAR_MARKER : regmap[load_reg],
+ ctx) ?: ret;
+ }
if (ret)
return ret;
diff --git a/arch/s390/net/bpf_jit_comp.c b/arch/s390/net/bpf_jit_comp.c
index b60877478b45d..c46872b071ce7 100644
--- a/arch/s390/net/bpf_jit_comp.c
+++ b/arch/s390/net/bpf_jit_comp.c
@@ -774,6 +774,8 @@ static void bpf_jit_probe_atomic_pre(struct bpf_jit *jit,
struct bpf_insn *insn,
struct bpf_jit_probe *probe)
{
+ int load_reg;
+
if (BPF_MODE(insn->code) != BPF_PROBE_ATOMIC)
return;
@@ -783,6 +785,14 @@ static void bpf_jit_probe_atomic_pre(struct bpf_jit *jit,
EMIT4(0xb9080000, REG_W1, insn->dst_reg);
probe->arena_reg = REG_W1;
probe->prg = jit->prg;
+ /*
+ * A read-modify-write carrying BPF_FETCH reads the old value into
+ * src_reg, or into r0 for a BPF_CMPXCHG. Clear that register on
+ * fault, the remaining atomics only write memory.
+ */
+ load_reg = bpf_atomic_load_reg(insn);
+ if (load_reg >= 0)
+ probe->reg = reg2hex[load_reg];
}
static int bpf_jit_probe_post(struct bpf_jit *jit, struct bpf_prog *fp,
@@ -1684,6 +1694,7 @@ static noinline int bpf_jit_insn(struct bpf_jit *jit, struct bpf_prog *fp,
if (load_probe.prg != -1) {
probe.prg = jit->prg;
probe.arena_reg = load_probe.arena_reg;
+ probe.reg = load_probe.reg;
}
loop_start = jit->prg;
/* 0: {csy|csg} %w0,%src,off(%arena) */
diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
index 8dddb5d7af21b..d920772af7d5f 100644
--- a/arch/x86/net/bpf_jit_comp.c
+++ b/arch/x86/net/bpf_jit_comp.c
@@ -1473,17 +1473,20 @@ static int emit_atomic_ld_st_index(u8 **pprog, u32 atomic_op, u32 size,
*
* Bit layout of `fixup` (32-bit):
*
- * +-----------+--------+-----------+---------+----------+
- * | 31 | 30-24 | 23-16 | 15-8 | 7-0 |
- * | | | | | |
- * | ARENA_ACC | Unused | ARENA_REG | DST_REG | INSN_LEN |
- * +-----------+--------+-----------+---------+----------+
+ * +-----------+-------------+--------+-----------+---------+----------+
+ * | 31 | 30 | 29-24 | 23-16 | 15-8 | 7-0 |
+ * | | | | | | |
+ * | ARENA_ACC | ARENA_WRITE | Unused | ARENA_REG | DST_REG | INSN_LEN |
+ * +-----------+-------------+--------+-----------+---------+----------+
*
* - INSN_LEN (8 bits): Length of faulting insn (max x86 insn = 15 bytes (fits in 8 bits)).
* - DST_REG (8 bits): Offset of dst_reg from reg2pt_regs[] (max offset = 112 (fits in 8 bits)).
- * This is set to DONT_CLEAR if the insn is a store.
+ * This is set to DONT_CLEAR if the insn does not read into a register.
* - ARENA_REG (8 bits): Offset of the register that is used to calculate the
* address for load/store when accessing the arena region.
+ * - ARENA_WRITE (1 bit): This bit is set when the faulting instruction wrote to the arena region.
+ * It is independent of DST_REG, since a read-modify-write both writes to
+ * memory and reads the old value into a register.
* - ARENA_ACCESS (1 bit): This bit is set when the faulting instruction accessed the arena region.
*
* Bit layout of `data` (32-bit):
@@ -1502,6 +1505,7 @@ static int emit_atomic_ld_st_index(u8 **pprog, u32 atomic_op, u32 size,
#define FIXUP_INSN_LEN_MASK GENMASK(7, 0)
#define FIXUP_REG_MASK GENMASK(15, 8)
#define FIXUP_ARENA_REG_MASK GENMASK(23, 16)
+#define FIXUP_ARENA_WRITE BIT(30)
#define FIXUP_ARENA_ACCESS BIT(31)
#define DATA_ARENA_OFFSET_MASK GENMASK(31, 16)
@@ -1510,7 +1514,7 @@ bool ex_handler_bpf(const struct exception_table_entry *x, struct pt_regs *regs)
u32 reg = FIELD_GET(FIXUP_REG_MASK, x->fixup);
u32 insn_len = FIELD_GET(FIXUP_INSN_LEN_MASK, x->fixup);
bool is_arena = !!(x->fixup & FIXUP_ARENA_ACCESS);
- bool is_write = (reg == DONT_CLEAR);
+ bool is_write = !!(x->fixup & FIXUP_ARENA_WRITE);
unsigned long addr;
s16 off;
u32 arena_reg;
@@ -2348,6 +2352,7 @@ st: insn_off = insn->off;
struct exception_table_entry *ex;
u8 *_insn = image + proglen + (start_of_ldx - temp);
u32 arena_reg, fixup_reg;
+ bool is_write;
s64 delta;
if (!bpf_prog->aux->extable)
@@ -2384,15 +2389,29 @@ st: insn_off = insn->off;
bpf_atomic_is_load_acq(insn)) {
arena_reg = reg2pt_regs[src_reg];
fixup_reg = reg2pt_regs[dst_reg];
+ is_write = false;
} else {
+ /*
+ * A store has no destination register to clear,
+ * except for a read-modify-write with BPF_FETCH,
+ * which also reads the old value into src_reg, or
+ * into r0 for a BPF_CMPXCHG. Either way the access
+ * is still reported as a write.
+ */
+ int load_reg = bpf_atomic_load_reg(insn);
+
arena_reg = reg2pt_regs[dst_reg];
- fixup_reg = DONT_CLEAR;
+ fixup_reg = load_reg < 0 ? DONT_CLEAR :
+ reg2pt_regs[load_reg];
+ is_write = true;
}
ex->fixup = FIELD_PREP(FIXUP_INSN_LEN_MASK, prog - start_of_ldx) |
FIELD_PREP(FIXUP_ARENA_REG_MASK, arena_reg) |
FIELD_PREP(FIXUP_REG_MASK, fixup_reg);
ex->fixup |= FIXUP_ARENA_ACCESS;
+ if (is_write)
+ ex->fixup |= FIXUP_ARENA_WRITE;
ex->data |= FIELD_PREP(DATA_ARENA_OFFSET_MASK, insn->off);
}
diff --git a/include/linux/filter.h b/include/linux/filter.h
index 4edba8182db1b..15d83684c6e94 100644
--- a/include/linux/filter.h
+++ b/include/linux/filter.h
@@ -414,6 +414,30 @@ static inline bool bpf_atomic_is_load_acq(const struct bpf_insn *insn)
insn->imm == BPF_LOAD_ACQ;
}
+/*
+ * Given an instruction @insn, return the number of the BPF register that a
+ * BPF_ATOMIC reads the value at its memory operand into, or -1 if there is
+ * no such register. That is the register a BPF_PROBE_ATOMIC has to clear when
+ * the access faults. Like bpf_atomic_is_load_acq(), @insn is not assumed to
+ * be a BPF_ATOMIC here.
+ */
+static inline int bpf_atomic_load_reg(const struct bpf_insn *insn)
+{
+ if (BPF_CLASS(insn->code) != BPF_STX ||
+ (BPF_MODE(insn->code) != BPF_ATOMIC &&
+ BPF_MODE(insn->code) != BPF_PROBE_ATOMIC))
+ return -1;
+
+ switch (insn->imm) {
+ case BPF_LOAD_ACQ:
+ return insn->dst_reg;
+ case BPF_CMPXCHG:
+ return BPF_REG_0;
+ default:
+ return (insn->imm & BPF_FETCH) ? insn->src_reg : -1;
+ }
+}
+
/* Memory store, *(uint *) (dst_reg + off16) = imm32 */
#define BPF_ST_MEM(SIZE, DST, OFF, IMM) \
diff --git a/kernel/bpf/fixups.c b/kernel/bpf/fixups.c
index 661e2d13a6042..c4bd70befbb5c 100644
--- a/kernel/bpf/fixups.c
+++ b/kernel/bpf/fixups.c
@@ -49,16 +49,7 @@ static int insn_def_regno(const struct bpf_insn *insn)
case BPF_ST:
return -1;
case BPF_STX:
- if (BPF_MODE(insn->code) == BPF_ATOMIC ||
- BPF_MODE(insn->code) == BPF_PROBE_ATOMIC) {
- if (insn->imm == BPF_CMPXCHG)
- return BPF_REG_0;
- else if (insn->imm == BPF_LOAD_ACQ)
- return insn->dst_reg;
- else if (insn->imm & BPF_FETCH)
- return insn->src_reg;
- }
- return -1;
+ return bpf_atomic_load_reg(insn);
default:
return insn->dst_reg;
}
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index add3affc57035..73a2e8bb1782a 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -6485,21 +6485,16 @@ static int check_atomic_rmw(struct bpf_verifier_env *env,
return -EACCES;
}
- if (insn->imm & BPF_FETCH) {
- if (insn->imm == BPF_CMPXCHG)
- load_reg = BPF_REG_0;
- else
- load_reg = insn->src_reg;
-
+ /*
+ * A negative load_reg means that this instruction accesses a memory
+ * location but doesn't actually load it into a register.
+ */
+ load_reg = bpf_atomic_load_reg(insn);
+ if (load_reg >= 0) {
/* check and record load of old value */
err = check_reg_arg(env, load_reg, DST_OP);
if (err)
return err;
- } else {
- /* This instruction accesses a memory location but doesn't
- * actually load it into a register.
- */
- load_reg = -1;
}
dst_reg = cur_regs(env) + insn->dst_reg;
diff --git a/tools/testing/selftests/bpf/prog_tests/stream.c b/tools/testing/selftests/bpf/prog_tests/stream.c
index 15dd3ae2a84b7..e4e9374309e26 100644
--- a/tools/testing/selftests/bpf/prog_tests/stream.c
+++ b/tools/testing/selftests/bpf/prog_tests/stream.c
@@ -105,6 +105,10 @@ void test_stream_arena_fault_address(void)
test_address(skel->progs.stream_arena_write_fault, &skel->bss->fault_addr);
if (test__start_subtest("load_acquire_fault"))
test_address(skel->progs.stream_arena_load_acquire_fault, &skel->bss->fault_addr);
+ if (test__start_subtest("xchg_fault"))
+ test_address(skel->progs.stream_arena_xchg_fault, &skel->bss->fault_addr);
+ if (test__start_subtest("cmpxchg_fault"))
+ test_address(skel->progs.stream_arena_cmpxchg_fault, &skel->bss->fault_addr);
stream__destroy(skel);
}
diff --git a/tools/testing/selftests/bpf/progs/stream.c b/tools/testing/selftests/bpf/progs/stream.c
index cf5533e11f39c..00a37933e411d 100644
--- a/tools/testing/selftests/bpf/progs/stream.c
+++ b/tools/testing/selftests/bpf/progs/stream.c
@@ -229,6 +229,107 @@ int stream_arena_load_acquire_fault(void *ctx)
return val;
}
+SEC("syscall")
+__arch_x86_64
+__arch_arm64
+__success __retval(0)
+__stderr("ERROR: Arena WRITE access at unmapped address 0x{{.*}}")
+__stderr("CPU: {{[0-9]+}} UID: 0 PID: {{[0-9]+}} Comm: {{.*}}")
+__stderr("Call trace:\n"
+"{{([a-zA-Z_][a-zA-Z0-9_]*\\+0x[0-9a-fA-F]+/0x[0-9a-fA-F]+\n"
+"|[ \t]+[^\n]+\n)*}}")
+int stream_arena_xchg_fault(void *ctx)
+{
+ static const struct bpf_insn xchg_insn = {
+ .code = 0xc3, /* BPF_STX | BPF_ATOMIC | BPF_W */
+ .dst_reg = 1, /* BPF_REG_1 */
+ .src_reg = 2, /* BPF_REG_2 */
+ .off = 0x7fff,
+ .imm = 0xe1, /* BPF_XCHG */
+ };
+ struct bpf_arena *ptr = (void *)&arena;
+ u64 user_vm_start, val;
+
+ /*
+ * Prevent GCC bounds warning: casting &arena to struct bpf_arena *
+ * triggers bounds checking since the map definition is smaller than
+ * struct bpf_arena. barrier_var() makes the pointer opaque to GCC,
+ * preventing the bounds analysis.
+ */
+ barrier_var(ptr);
+ user_vm_start = ptr->user_vm_start;
+ fault_addr = user_vm_start + 0x7fff;
+ bpf_addr_space_cast(user_vm_start, 0, 1);
+ /*
+ * A read-modify-write carrying BPF_FETCH writes to memory, so the fault
+ * has to be reported as a WRITE from the dst_reg address, but it also
+ * reads the old value into src_reg, so the exception handler has to
+ * clear src_reg. Poison it up front, the returned value must be 0.
+ */
+ asm volatile (
+ "r1 = %[user_vm_start];"
+ "r2 = 1;"
+ ".8byte %[xchg_insn];" /* r2 = xchg((u32 *)(r1 + 0x7fff), r2) */
+ "%[val] = r2;"
+ : [val] "=r" (val)
+ : [user_vm_start] "r" (user_vm_start),
+ __imm_insn(xchg_insn, xchg_insn)
+ : "r1", "r2"
+ );
+ return val;
+}
+
+SEC("syscall")
+__arch_x86_64
+__arch_arm64
+__success __retval(0)
+__stderr("ERROR: Arena WRITE access at unmapped address 0x{{.*}}")
+__stderr("CPU: {{[0-9]+}} UID: 0 PID: {{[0-9]+}} Comm: {{.*}}")
+__stderr("Call trace:\n"
+"{{([a-zA-Z_][a-zA-Z0-9_]*\\+0x[0-9a-fA-F]+/0x[0-9a-fA-F]+\n"
+"|[ \t]+[^\n]+\n)*}}")
+int stream_arena_cmpxchg_fault(void *ctx)
+{
+ static const struct bpf_insn cmpxchg_insn = {
+ .code = 0xc3, /* BPF_STX | BPF_ATOMIC | BPF_W */
+ .dst_reg = 1, /* BPF_REG_1 */
+ .src_reg = 2, /* BPF_REG_2 */
+ .off = 0x7fff,
+ .imm = 0xf1, /* BPF_CMPXCHG */
+ };
+ struct bpf_arena *ptr = (void *)&arena;
+ u64 user_vm_start, val;
+
+ /*
+ * Prevent GCC bounds warning: casting &arena to struct bpf_arena *
+ * triggers bounds checking since the map definition is smaller than
+ * struct bpf_arena. barrier_var() makes the pointer opaque to GCC,
+ * preventing the bounds analysis.
+ */
+ barrier_var(ptr);
+ user_vm_start = ptr->user_vm_start;
+ fault_addr = user_vm_start + 0x7fff;
+ bpf_addr_space_cast(user_vm_start, 0, 1);
+ /*
+ * Same as the exchange above, except that a BPF_CMPXCHG reads the old
+ * value into r0 rather than into src_reg, so r0 is the register the
+ * exception handler has to clear. It doubles as the compare value, but
+ * the comparison never happens since the access faults first.
+ */
+ asm volatile (
+ "r1 = %[user_vm_start];"
+ "r0 = 1;"
+ "r2 = 2;"
+ ".8byte %[cmpxchg_insn];" /* r0 = cmpxchg((u32 *)(r1 + 0x7fff), r0, r2) */
+ "%[val] = r0;"
+ : [val] "=r" (val)
+ : [user_vm_start] "r" (user_vm_start),
+ __imm_insn(cmpxchg_insn, cmpxchg_insn)
+ : "r0", "r1", "r2"
+ );
+ return val;
+}
+
static __noinline void subprog(void)
{
int __arena *addr = (int __arena *)0xdeadbeef;
|
| 3/2 | 2026/08/11 00:34 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 9574 output: 41 thoughts: 632 Thoughts: **Fuzzing Target Identification: BPF Atomic Operations** Okay, here's what I'm thinking. This patch series is touching some really critical parts of the kernel, specifically the BPF subsystem and several architecture-specific JIT compilers. My initial gut feeling? This is definitely something we need to subject to fuzzing. The changes are centered around how BPF arena exceptions are handled, particularly around atomic operations like `BPF_CMPXCHG` and `BPF_XCHG`. We're talking about modifications to the verifier (`kernel/bpf/verifier.c`, `kernel/bpf/fixups.c`) and the JIT compilers themselves for `arm64`, `riscv`, `s390`, and `x86`. The introduction of `bpf_atomic_load_reg` in `include/linux/filter.h` is a red flag, but a good one. Now, let's get down to brass tacks and determine the relevant configurations. The BPF JIT, obviously, requires `CONFIG_BPF_JIT`. The BPF arena part likely hinges on `CONFIG_BPF_SYSCALL`, and I should probably double-check `kernel/bpf/Kconfig` or related files to confirm that. BPF arena *might* need the `CONFIG_BPF_SYSCALL` too, so I'll check that. Next, I need to see exactly where this `bpf_atomic_load_reg` is being used. Using `grepper` is an option, but the diff itself is probably faster, since it's a relatively small change. And, yeah, the diff shows it in `kernel/bpf/fixups.c`, `kernel/bpf/verifier.c`, and within the architecture-specific JIT compilers. Okay, let's identify the potentially interesting functions. Based on the diff, these are the ones I'll focus on: * `bpf_atomic_load_reg` (although it's `static inline`, so the coverage might be limited) * `ex_handler_bpf` (x86, arm64) * `add_exception_handler` (arm64, riscv) * `check_atomic_rmw` (verifier) * `bpf_jit_probe_atomic_pre` (s390) * `emit_atomic_ld_st_index` (x86, the modifications to the `st:` label in `do_jit` or something similar are important) Specifically, I should focus on `arch/x86/net/bpf_jit_comp.c`, around line 2348, as well as the other JIT compilers that are touched. |
| 4/2 | 2026/08/11 00:34 | tool | grepper |
0mArgs:{
"Expression": "add_exception_handler",
"PathPrefix": "arch/arm64/net/bpf_jit_comp.c"
}Results: {
"Output": "arch/arm64/net/bpf_jit_comp.c=1109=bool ex_handler_bpf(const struct exception_table_entry *ex,\n--\narch/arm64/net/bpf_jit_comp.c-1132-/* For accesses to BTF pointers, add an entry to the exception table */\narch/arm64/net/bpf_jit_comp.c:1133:static int add_exception_handler(const struct bpf_insn *insn,\narch/arm64/net/bpf_jit_comp.c-1134-\t\t\t\t struct jit_ctx *ctx,\n--\narch/arm64/net/bpf_jit_comp.c=1265=static int build_insn(const struct bpf_verifier_env *env, const struct bpf_insn *insn,\n--\narch/arm64/net/bpf_jit_comp.c-1819-\narch/arm64/net/bpf_jit_comp.c:1820:\t\tret = add_exception_handler(insn, ctx, dst);\narch/arm64/net/bpf_jit_comp.c-1821-\t\tif (ret)\n--\narch/arm64/net/bpf_jit_comp.c-1898-\narch/arm64/net/bpf_jit_comp.c:1899:\t\tret = add_exception_handler(insn, ctx, DONT_CLEAR);\narch/arm64/net/bpf_jit_comp.c-1900-\t\tif (ret)\n--\narch/arm64/net/bpf_jit_comp.c-1965-\narch/arm64/net/bpf_jit_comp.c:1966:\t\tret = add_exception_handler(insn, ctx, DONT_CLEAR);\narch/arm64/net/bpf_jit_comp.c-1967-\t\tif (ret)\n--\narch/arm64/net/bpf_jit_comp.c-1996-\narch/arm64/net/bpf_jit_comp.c:1997:\t\t\tret = add_exception_handler(insn, ctx, load_reg \u003c 0 ?\narch/arm64/net/bpf_jit_comp.c-1998-\t\t\t\t\t\t DONT_CLEAR : bpf2a64[load_reg]);\n"
} |
| 5/2 | 2026/08/11 00:34 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 11464 output: 38 thoughts: 30 Thoughts: Here's my take on the thought process, from an expert's perspective: **Diving into the BPF JIT Compiler** Okay, time to get my hands dirty. I'm thinking, let's zero in on the x86 BPF JIT compiler. Specifically, I need to jog my memory and see what's happening around line 2348 in `arch/x86/net/bpf_jit_comp.c`. That area usually deals with [insert specific knowledge of what's usually located around this area of the file, e.g., register allocation, instruction emission for specific BPF opcodes, memory addressing, etc.]. I'm likely interested in [insert a guess about the context based on your expertise, e.g., how a particular instruction is being translated, how a specific optimization is handled, a bug I vaguely recall]. Time to open that file and confirm my suspicions. |
| 6/2 | 2026/08/11 00:34 | tool | grepper |
0mArgs:{
"Expression": "st:",
"PathPrefix": "arch/x86/net/bpf_jit_comp.c"
}Results: {
"Output": "arch/x86/net/bpf_jit_comp.c=1729=static int do_jit(struct bpf_verifier_env *env, struct bpf_prog *bpf_prog, int *addrs, u8 *image,\n--\narch/x86/net/bpf_jit_comp.c-2284-\narch/x86/net/bpf_jit_comp.c:2285:st:\t\t\tinsn_off = insn-\u003eoff;\narch/x86/net/bpf_jit_comp.c-2286-\t\t\tif (dst_reg == BPF_REG_PARAMS) {\n"
} |
| 7/2 | 2026/08/11 00:34 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 11900 output: 37 thoughts: 181 Thoughts: **My Observations on BPF JIT Compilation & Atomic Operations** Okay, so I'm looking at how the BPF JIT compilation process and atomic operations are handled across different architectures within the kernel. It's interesting to see the varied function names and locations for core logic. I noticed that the main entry points for the JIT compiler differ based on the architecture. For instance, in `arch/x86/net/bpf_jit_comp.c`, the work is done in `do_jit`. Over in `arch/arm64/net/bpf_jit_comp.c`, `build_insn` takes the lead. Atomic operations get some attention too, and in `kernel/bpf/verifier.c` I see that `check_atomic_rmw` handles atomic read-modify-write verifications. Then, for `arch/s390/net/bpf_jit_comp.c`, it's `bpf_jit_probe_atomic_pre`, and for `arch/riscv/net/bpf_jit_comp64.c`, it's `bpf_jit_emit_insn`. Given the mentions of atomic operations, I'm now curious about where the `bpf_atomic_load_reg` function gets used in the codebase. I should check `kernel/bpf/fixups.c` to see which function or functions rely on it. It's always beneficial to understand these dependencies when optimizing or debugging BPF-related code. |
| 8/2 | 2026/08/11 00:34 | tool | grepper |
0mArgs:{
"Expression": "bpf_atomic_load_reg",
"PathPrefix": "kernel/bpf/fixups.c"
}Results: {
"Output": "kernel/bpf/fixups.c=44=static int insn_def_regno(const struct bpf_insn *insn)\n--\nkernel/bpf/fixups.c-51-\tcase BPF_STX:\nkernel/bpf/fixups.c:52:\t\treturn bpf_atomic_load_reg(insn);\nkernel/bpf/fixups.c-53-\tdefault:\n"
} |
| 9/2 | 2026/08/11 00:34 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 12562 output: 42 thoughts: 147 Thoughts: **Analyzing Instruction Definition and JIT Compilation** Okay, so I'm looking at the `insn_def_regno` function, and my immediate instinct is to identify the critical symbols or areas that are *most* relevant. My mental checklist kicks in, and I immediately hone in on: `check_atomic_rmw`, definitely `insn_def_regno` itself, obviously, and `ex_handler_bpf` because that sounds central to handling BPF instructions. Now, I'm a little hesitant about including `do_jit` because it's *very* generic, but it *is* the JIT compiler, so it's probably important to consider in some way. I'll need to remember that. Then, I think about the platform-specific JIT components: `build_insn` for arm64 and the RISC-V and s390 specific emitters, `bpf_jit_emit_insn` and `bpf_jit_probe_atomic_pre` respectively. Those are probably going to be key pieces of the puzzle. Now, I really need to check the scope of `ex_handler_bpf` function. Is it static, is it exported? Its visibility is going to be important in understanding how the BPF code is getting handled. |
| 10/2 | 2026/08/11 00:34 | tool | grepper |
0mArgs:{
"Expression": "ex_handler_bpf",
"PathPrefix": "arch/x86/net/bpf_jit_comp.c"
}Results: {
"Output": "arch/x86/net/bpf_jit_comp.c=1447=static int emit_atomic_ld_st_index(u8 **pprog, u32 atomic_op, u32 size,\n--\narch/x86/net/bpf_jit_comp.c-1511-\narch/x86/net/bpf_jit_comp.c:1512:bool ex_handler_bpf(const struct exception_table_entry *x, struct pt_regs *regs)\narch/x86/net/bpf_jit_comp.c-1513-{\n--\narch/x86/net/bpf_jit_comp.c=2285=st:\t\t\tinsn_off = insn-\u003eoff;\n--\narch/x86/net/bpf_jit_comp.c-2381-\t\t\t\t * the reg holding the unmodified 32-bit address to\narch/x86/net/bpf_jit_comp.c:2382:\t\t\t\t * ex_handler_bpf().\narch/x86/net/bpf_jit_comp.c-2383-\t\t\t\t *\n--\narch/x86/net/bpf_jit_comp.c-2540-\t\t\t\t * Compute size of x86 insn and its target dest x86 register.\narch/x86/net/bpf_jit_comp.c:2541:\t\t\t\t * ex_handler_bpf() will use lower 8 bits to adjust\narch/x86/net/bpf_jit_comp.c-2542-\t\t\t\t * pt_regs-\u003eip to jump over this x86 instruction\n"
} |
| 11/2 | 2026/08/11 00:34 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 13449 output: 42 thoughts: 36 Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience, presented in the first person: **Navigating the BPF JIT Landscape: A Quick Check** Right, so I'm thinking about `ex_handler_bpf` and immediately I know it's a global function. My brain is already starting to scope out potential areas of interest, potential conflicts, and common usage patterns. Given my familiarity with kernel BPF and the broader architecture, my next move is clear. I need to dive into the architecture-specific implementation. Let me pull up `arch/arm64/net/bpf_jit_comp.c`. That's where the real magic (or potential issues) will reside. It's the most logical place to look for details on how this function is actually *used* within the ARM64 BPF JIT compilation flow. I'm going to start mentally tracing the calls and understand the JIT output. |
| 12/2 | 2026/08/11 00:34 | tool | grepper |
0mArgs:{
"Expression": "ex_handler_bpf",
"PathPrefix": "arch/arm64/net/bpf_jit_comp.c"
}Results: {
"Output": "arch/arm64/net/bpf_jit_comp.c=1046=static void build_epilogue(struct jit_ctx *ctx, bool was_classic)\n--\narch/arm64/net/bpf_jit_comp.c-1108-\narch/arm64/net/bpf_jit_comp.c:1109:bool ex_handler_bpf(const struct exception_table_entry *ex,\narch/arm64/net/bpf_jit_comp.c-1110-\t\t struct pt_regs *regs)\n--\narch/arm64/net/bpf_jit_comp.c=1133=static int add_exception_handler(const struct bpf_insn *insn,\n--\narch/arm64/net/bpf_jit_comp.c-1205-\t\t * memory access. Pass the reg holding the unmodified 32-bit address to\narch/arm64/net/bpf_jit_comp.c:1206:\t\t * ex_handler_bpf.\narch/arm64/net/bpf_jit_comp.c-1207-\t\t */\n"
} |
| 13/2 | 2026/08/11 00:34 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 14026 output: 36 thoughts: 37 Thoughts: Okay, here's my interpretation of those thoughts, tailored for an expert audience, presented in the first person: **Investigating the Scope of `ex_handler_bpf` and Its Relationship to Instruction Definition** Right, so `ex_handler_bpf` is a global variable. My immediate thought is, "Okay, where is this used, and how widely?" Global variables always warrant a careful look. I need to understand its scope and potential impact. My focus narrows in on that name. My next step? Dive right into the code to trace its usage. I'll head over to `kernel/bpf/fixups.c`. That file name strongly suggests it's involved in some kind of instruction fixing or patching within the BPF system. Considering that, I need to check the definition of `insn_def_regno`. The name is also suggestive. It implies some kind of register number that is a part of the instruction definition. I need to see how these two pieces of code interact, and how `ex_handler_bpf` fits into the broader picture of instruction handling. This will help me determine where the fixups are happening and how they might relate to any potential security implications or performance characteristics. |
| 14/2 | 2026/08/11 00:34 | tool | grepper |
0mArgs:{
"Expression": "insn_def_regno",
"PathPrefix": "kernel/bpf/fixups.c"
}Results: {
"Output": "kernel/bpf/fixups.c=24=static bool is_addr_space_cast32(struct bpf_prog *prog, const struct bpf_insn *insn)\n--\nkernel/bpf/fixups.c-43-/* Return the regno defined by the insn, or -1. */\nkernel/bpf/fixups.c:44:static int insn_def_regno(const struct bpf_insn *insn)\nkernel/bpf/fixups.c-45-{\n--\nkernel/bpf/fixups.c-58-/*\nkernel/bpf/fixups.c:59: * For use only in combination with insn_def_regno() \u003e= 0.\nkernel/bpf/fixups.c-60- * Returns TRUE if the destination register operates on 64-bit,\n--\nkernel/bpf/fixups.c=63=static bool bpf_is_reg64(struct bpf_prog *prog, struct bpf_insn *insn)\n--\nkernel/bpf/fixups.c-87-\nkernel/bpf/fixups.c:88:\t/* atomics, see insn_def_regno() */\nkernel/bpf/fixups.c-89-\tif (class == BPF_STX \u0026\u0026 size != BPF_DW)\n--\nkernel/bpf/fixups.c=104=int bpf_insn_def32(struct bpf_prog *prog, struct bpf_insn *insn)\nkernel/bpf/fixups.c-105-{\nkernel/bpf/fixups.c:106:\tint dst_reg = insn_def_regno(insn);\nkernel/bpf/fixups.c-107-\n--\nkernel/bpf/fixups.c=638=int bpf_opt_subreg_zext_lo32_rnd_hi32(struct bpf_verifier_env *env,\n--\nkernel/bpf/fixups.c-661-\t\tinsn = insns[adj_idx];\nkernel/bpf/fixups.c:662:\t\tload_reg = insn_def_regno(\u0026insn);\nkernel/bpf/fixups.c-663-\t\tif (!aux[adj_idx].zext_dst) {\n"
} |
| 15/2 | 2026/08/11 00:34 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 14941 output: 38 thoughts: 65 Thoughts: Here's my summary, as the expert: **Analyzing the Instruction Definition and Caller** Okay, so `insn_def_regno` is declared as static. This immediately flags a potential area for closer inspection. The relevant callers seem to be `bpf_insn_def32` and `bpf_opt_subreg_zext_lo32_rnd_hi32`. My initial thought is to dive into the definition of `bpf_insn_def32` first. Understanding how *that* function interacts with this static variable is going to be key to grasping its purpose and potential implications. I need to understand the control flow here and the data being manipulated. |
| 16/2 | 2026/08/11 00:34 | tool | grepper |
0mArgs:{
"Expression": "bpf_insn_def32",
"PathPrefix": "kernel/bpf/fixups.c"
}Results: {
"Output": "kernel/bpf/fixups.c=63=static bool bpf_is_reg64(struct bpf_prog *prog, struct bpf_insn *insn)\n--\nkernel/bpf/fixups.c-103- */\nkernel/bpf/fixups.c:104:int bpf_insn_def32(struct bpf_prog *prog, struct bpf_insn *insn)\nkernel/bpf/fixups.c-105-{\n--\nkernel/bpf/fixups.c=215=static void adjust_insn_aux_data(struct bpf_verifier_env *env,\n--\nkernel/bpf/fixups.c-227-\t */\nkernel/bpf/fixups.c:228:\tdata[off].zext_dst = bpf_insn_def32(new_prog, insn + off + cnt - 1) \u003e= 0;\nkernel/bpf/fixups.c-229-\n--\nkernel/bpf/fixups.c-239-\t\tdata[i].seen = old_seen;\nkernel/bpf/fixups.c:240:\t\tdata[i].zext_dst = bpf_insn_def32(new_prog, insn + i) \u003e= 0;\nkernel/bpf/fixups.c-241-\t}\n"
} |
| 17/2 | 2026/08/11 00:34 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 15543 output: 34 thoughts: 38 Thoughts: Here's a summary of my thought process: **BPF Instruction Analysis** Okay, so `bpf_insn_def32` β that's a global, right? Let me just confirm my understanding. Now, I need to dig into how this is used and where it's validated. My first instinct, given the nature of the instruction and potential atomic operations, is to zero in on `kernel/bpf/verifier.c`. Specifically, I'm going to look for the `check_atomic_rmw` function. That seems like the likely candidate to handle validation checks related to any read-modify-write operations, and `bpf_insn_def32` is probably tied in there somehow. Time to delve into the code! |
| 18/2 | 2026/08/11 00:34 | tool | grepper |
0mArgs:{
"Expression": "check_atomic_rmw",
"PathPrefix": "kernel/bpf/verifier.c"
}Results: {
"Output": "kernel/bpf/verifier.c=6402=static int check_store_reg(struct bpf_verifier_env *env, struct bpf_insn *insn,\n--\nkernel/bpf/verifier.c-6439-\nkernel/bpf/verifier.c:6440:static int check_atomic_rmw(struct bpf_verifier_env *env,\nkernel/bpf/verifier.c-6441-\t\t\t struct bpf_insn *insn)\n--\nkernel/bpf/verifier.c=6565=static int check_atomic(struct bpf_verifier_env *env, struct bpf_insn *insn)\n--\nkernel/bpf/verifier.c-6577-\tcase BPF_CMPXCHG:\nkernel/bpf/verifier.c:6578:\t\treturn check_atomic_rmw(env, insn);\nkernel/bpf/verifier.c-6579-\tcase BPF_LOAD_ACQ:\n"
} |
| 19/2 | 2026/08/11 00:34 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 16035 output: 31 thoughts: 29 Thoughts: Here's my thought process, as if I were analyzing this code: **Diving into the Atomic RMW Check** Okay, so I see `check_atomic_rmw` is a static function. That's good to know β it's likely scoped within a particular compilation unit and not meant for external use. The critical thing here is that `check_atomic` is the caller. That means the logic within `check_atomic_rmw` is invoked from within `check_atomic`. So, the next logical step is to dig into `check_atomic` itself. Understanding *why* it calls `check_atomic_rmw` and what inputs it's providing will be key to understanding the full picture. I need to see what the control flow is. Time to move on and investigate that `check_atomic` function in more detail. |
| 20/2 | 2026/08/11 00:34 | tool | grepper |
0mArgs:{
"Expression": "check_atomic",
"PathPrefix": "kernel/bpf/verifier.c"
}Results: {
"Output": "kernel/bpf/verifier.c=6402=static int check_store_reg(struct bpf_verifier_env *env, struct bpf_insn *insn,\n--\nkernel/bpf/verifier.c-6439-\nkernel/bpf/verifier.c:6440:static int check_atomic_rmw(struct bpf_verifier_env *env,\nkernel/bpf/verifier.c-6441-\t\t\t struct bpf_insn *insn)\n--\nkernel/bpf/verifier.c-6526-\nkernel/bpf/verifier.c:6527:static int check_atomic_load(struct bpf_verifier_env *env,\nkernel/bpf/verifier.c-6528-\t\t\t struct bpf_insn *insn)\n--\nkernel/bpf/verifier.c-6545-\nkernel/bpf/verifier.c:6546:static int check_atomic_store(struct bpf_verifier_env *env,\nkernel/bpf/verifier.c-6547-\t\t\t struct bpf_insn *insn)\n--\nkernel/bpf/verifier.c-6564-\nkernel/bpf/verifier.c:6565:static int check_atomic(struct bpf_verifier_env *env, struct bpf_insn *insn)\nkernel/bpf/verifier.c-6566-{\n--\nkernel/bpf/verifier.c-6577-\tcase BPF_CMPXCHG:\nkernel/bpf/verifier.c:6578:\t\treturn check_atomic_rmw(env, insn);\nkernel/bpf/verifier.c-6579-\tcase BPF_LOAD_ACQ:\n--\nkernel/bpf/verifier.c-6584-\t\t}\nkernel/bpf/verifier.c:6585:\t\treturn check_atomic_load(env, insn);\nkernel/bpf/verifier.c-6586-\tcase BPF_STORE_REL:\n--\nkernel/bpf/verifier.c-6591-\t\t}\nkernel/bpf/verifier.c:6592:\t\treturn check_atomic_store(env, insn);\nkernel/bpf/verifier.c-6593-\tdefault:\n--\nkernel/bpf/verifier.c=17233=static int do_check_insn(struct bpf_verifier_env *env, bool *do_print_state)\n--\nkernel/bpf/verifier.c-17250-\t\tif (BPF_MODE(insn-\u003ecode) == BPF_ATOMIC)\nkernel/bpf/verifier.c:17251:\t\t\treturn check_atomic(env, insn);\nkernel/bpf/verifier.c-17252-\t\treturn check_store_reg(env, insn, false);\n"
} |
| 21/2 | 2026/08/11 00:34 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 16994 output: 47 thoughts: 104 Thoughts: **Tracing the Execution Path of `check_atomic`** Okay, let's break this down from a systems perspective. I see that `check_atomic` is a static function. That tells me it's likely local to its compilation unit, meaning we should be able to reason about its usage in that specific context. The immediate caller of `check_atomic` is identified as `do_check_insn`. Another static function, `do_check_insn`, is called by `do_check`, which is also static. Finally, `do_check` itself is called by `bpf_check`, which is global. This means `bpf_check` is the entry point from other parts of the system. Now, based on this call chain, it is important to trace how `check_atomic` is used and ensure it is correct. I am going to check `arch/s390/net/bpf_jit_comp.c` to see how `bpf_jit_probe_atomic_pre` interacts with this flow. Understanding the `bpf_jit_probe_atomic_pre` usage is crucial here, as it might represent an interesting performance optimization or a security mitigation around atomic instructions. |
| 22/2 | 2026/08/11 00:35 | tool | grepper |
0mArgs:{
"Expression": "bpf_jit_probe_atomic_pre",
"PathPrefix": "arch/s390/net/bpf_jit_comp.c"
}Results: {
"Output": "arch/s390/net/bpf_jit_comp.c=760=static void bpf_jit_probe_store_pre(struct bpf_jit *jit, struct bpf_insn *insn,\n--\narch/s390/net/bpf_jit_comp.c-772-\narch/s390/net/bpf_jit_comp.c:773:static void bpf_jit_probe_atomic_pre(struct bpf_jit *jit,\narch/s390/net/bpf_jit_comp.c-774-\t\t\t\t struct bpf_insn *insn,\n--\narch/s390/net/bpf_jit_comp.c=955=static noinline int bpf_jit_insn(struct bpf_jit *jit, struct bpf_prog *fp,\n--\narch/s390/net/bpf_jit_comp.c-1646-#define EMIT_ATOMIC(op32, op64) do {\t\t\t\t\t\\\narch/s390/net/bpf_jit_comp.c:1647:\tbpf_jit_probe_atomic_pre(jit, insn, \u0026probe);\t\t\t\\\narch/s390/net/bpf_jit_comp.c-1648-\t/* {op32|op64} {%w0|%src},%src,off(%arena) */\t\t\t\\\n--\narch/s390/net/bpf_jit_comp.c-1686-\narch/s390/net/bpf_jit_comp.c:1687:\t\t\tbpf_jit_probe_atomic_pre(jit, insn, \u0026load_probe);\narch/s390/net/bpf_jit_comp.c-1688-\t\t\t/* {ly|lg} %w0,off(%arena) */\n--\narch/s390/net/bpf_jit_comp.c-1719-\t\tcase BPF_CMPXCHG:\narch/s390/net/bpf_jit_comp.c:1720:\t\t\tbpf_jit_probe_atomic_pre(jit, insn, \u0026probe);\narch/s390/net/bpf_jit_comp.c-1721-\t\t\t/* 0: {csy|csg} %b0,%src,off(%arena) */\n"
} |
| 23/2 | 2026/08/11 00:35 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 18010 output: 46 thoughts: 126 Thoughts: Okay, here's my understanding, formatted as requested: **Deconstructing the JIT Compilation Flow** Alright, let's break this down. It seems the compilation process traces a very specific chain of calls. `bpf_jit_probe_atomic_pre` is defined as `static`, and it's called by `bpf_jit_insn`. In turn, `bpf_jit_insn` is also `static`, and the only place it is called is within `bpf_jit_prog`. Further down the line, we have the `static` function `bpf_jit_prog`, which is only called by `bpf_int_jit_compile`. Now, `bpf_int_jit_compile` is defined as global, so it must be the entry point to this whole JIT compilation sequence. I'm going to look at `arch/riscv/net/bpf_jit_comp64.c` to look at how `bpf_jit_emit_insn` is used in this compilation. This seems like a pretty standard static to global progression, but it's important to confirm I'm following the correct chain of events. |
| 24/2 | 2026/08/11 00:35 | tool | grepper |
0mArgs:{
"Expression": "bpf_jit_emit_insn",
"PathPrefix": "arch/riscv/net/bpf_jit_comp64.c"
}Results: {
"Output": "arch/riscv/net/bpf_jit_comp64.c=1324=int arch_prepare_bpf_trampoline(struct bpf_tramp_image *im, void *ro_image,\n--\narch/riscv/net/bpf_jit_comp64.c-1360-\narch/riscv/net/bpf_jit_comp64.c:1361:int bpf_jit_emit_insn(const struct bpf_insn *insn, struct rv_jit_context *ctx,\narch/riscv/net/bpf_jit_comp64.c-1362-\t\t bool extra_pass)\n"
} |
| 25/2 | 2026/08/11 00:35 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 18613 output: 40 thoughts: 116 Thoughts: **Focusing on BPF JIT Compilation** Okay, so `bpf_jit_emit_insn` is a global function, meaning it's a key piece in this BPF JIT puzzle. That means I need to carefully examine what interacts with it. My focus will be on these core symbols: `bpf_insn_def32`, `ex_handler_bpf`, and `bpf_jit_emit_insn` itself, of course. I'll need to see how they fit into the bigger picture. I'm going to set aside `bpf_int_jit_compile` and `bpf_check` for now; they seem a bit too generic. Given that I'm working with ARM64 architecture, I should also check `arch/arm64/net/bpf_jit_comp.c`. I'm especially interested in locating the `build_insn` function within that file. That should give me the architectural specifics of how these instructions are constructed and handled within the JIT compiler. |
| 26/2 | 2026/08/11 00:35 | tool | grepper |
0mArgs:{
"Expression": "build_insn",
"PathPrefix": "arch/arm64/net/bpf_jit_comp.c"
}Results: {
"Output": "arch/arm64/net/bpf_jit_comp.c=1247=static void emit_stack_arg_store_imm(s32 imm, s16 bpf_off, const u8 tmp, struct jit_ctx *ctx)\n--\narch/arm64/net/bpf_jit_comp.c-1264- */\narch/arm64/net/bpf_jit_comp.c:1265:static int build_insn(const struct bpf_verifier_env *env, const struct bpf_insn *insn,\narch/arm64/net/bpf_jit_comp.c-1266-\t\t struct jit_ctx *ctx, bool extra_pass)\n--\narch/arm64/net/bpf_jit_comp.c=2012=static int build_body(struct bpf_verifier_env *env, struct jit_ctx *ctx, bool extra_pass)\n--\narch/arm64/net/bpf_jit_comp.c-2030-\t\tctx-\u003eoffset[i] = ctx-\u003eidx;\narch/arm64/net/bpf_jit_comp.c:2031:\t\tret = build_insn(env, insn, ctx, extra_pass);\narch/arm64/net/bpf_jit_comp.c-2032-\t\tif (ret \u003e 0) {\n"
} |
| 27/2 | 2026/08/11 00:35 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 19346 output: 39 thoughts: 60 Thoughts: Here's my summary, as though I'm thinking through this process: **Deconstructing the JIT Compilation Flow** Okay, so I'm digging into how this BPF JIT compilation works. Right, `build_insn` is a static function, meaning it's only visible within its compilation unit. That makes debugging a bit more focused, which is good. The key thing is that `build_insn` is *called* by `build_body`. And if I remember correctly, `build_body` is invoked by `bpf_int_jit_compile`. That gives me a rough idea of the call chain: `bpf_int_jit_compile` -> `build_body` -> `build_insn`. To get a clearer picture of the overall compilation process, let me check the architecture-specific implementation. I'll head over to `arch/x86/net/bpf_jit_comp.c`. I'm specifically looking for `do_jit` there, that usually contains the core JIT compilation routine. That should give me the entry point for X86 specific assembly operations. |
| 28/2 | 2026/08/11 00:35 | tool | grepper |
0mArgs:{
"Expression": "do_jit",
"PathPrefix": "arch/x86/net/bpf_jit_comp.c"
}Results: {
"Output": "arch/x86/net/bpf_jit_comp.c=1691=static int emit_kfunc_arena_args(struct bpf_prog *bpf_prog,\n--\narch/x86/net/bpf_jit_comp.c-1728-\narch/x86/net/bpf_jit_comp.c:1729:static int do_jit(struct bpf_verifier_env *env, struct bpf_prog *bpf_prog, int *addrs, u8 *image,\narch/x86/net/bpf_jit_comp.c-1730-\t\t u8 *rw_image, int oldproglen, struct jit_context *ctx, bool jmp_padding)\n--\narch/x86/net/bpf_jit_comp.c=3962=struct bpf_prog *bpf_int_jit_compile(struct bpf_verifier_env *env, struct bpf_prog *prog)\n--\narch/x86/net/bpf_jit_comp.c-4039-\t\t\tpadding = true;\narch/x86/net/bpf_jit_comp.c:4040:\t\tproglen = do_jit(env, prog, addrs, image, rw_image, oldproglen,\narch/x86/net/bpf_jit_comp.c-4041-\t\t\t\t \u0026ctx, padding);\n"
} |
| 29/2 | 2026/08/11 00:35 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 20045 output: 31 thoughts: 686 Thoughts: **Analyzing BPF JIT Compilation Focus Symbols** Okay, so I'm thinking about which symbols are the most relevant to focus on here, considering `do_jit` is static and called by `bpf_int_jit_compile`. The initial candidates that spring to mind are `bpf_insn_def32`, `ex_handler_bpf`, `bpf_jit_emit_insn`, and `bpf_int_jit_compile`. Let's start with `bpf_int_jit_compile`. That seems like a solid choice since it's the main entry point for the JIT compiler itself. `bpf_check` is also appealing as the main entry point for the verifier, though I need to keep in mind the prompt's preference for non-hotpath API entrypoints. Both seem to fit the bill as they are called on program load. Looking closer, I'll examine the calls to the other potentially interesting functions: * `bpf_insn_def32`: Digging into `kernel/bpf/fixups.c`, this is used in `adjust_insn_aux_data` and `bpf_opt_subreg_zext_lo32_rnd_hi32`. Both of those are called from `bpf_check`. * `ex_handler_bpf`: Checking `arch/x86/net/bpf_jit_comp.c` and `arch/arm64/net/bpf_jit_comp.c`, this is involved in exception handling during BPF program execution, so it's clearly relevant. * `bpf_jit_emit_insn`: This is called by `bpf_int_jit_compile` in `arch/riscv/net/bpf_jit_comp64.c`. * `bpf_int_jit_compile`: In `arch/s390/net/bpf_jit_comp.c`, this is again the primary entry point. So, the focus symbols are definitely: `bpf_insn_def32`, `ex_handler_bpf`, `bpf_jit_emit_insn`, and `bpf_int_jit_compile`. I'm going to add `bpf_check` in as well because it's a critical entry point for the verifier, and it looks like a natural companion to the JIT compiler's entry point. Finally, I need to check the required configuration options. `CONFIG_BPF_SYSCALL` is a given, obviously. And `CONFIG_BPF_JIT` is essential for the JIT compiler changes. I'll take a quick look at `kernel/bpf/Kconfig` to make sure I haven't missed anything else critical related to BPF syscalls and JIT compilation. |
| 30/2 | 2026/08/11 00:35 | tool | grepper |
0mError:no matches Args: {
"Expression": "config BPF_SYSCALL",
"PathPrefix": "init/Kconfig"
}Results: {
"error": "no matches"
} |
| 31/2 | 2026/08/11 00:35 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 21400 output: 27 thoughts: 20 Thoughts: Okay, here's my take on those thoughts, framed as an expert's internal monologue: **Investigating BPF Configuration Options** Right, so I need to figure out where these BPF configuration options are defined in the kernel's Kconfig system. My immediate instinct is to look in the more relevant configuration files. Let's see, BPF is pretty fundamental now, so I'd expect to find its core definition in either `kernel/bpf/Kconfig` or possibly even the main initialization config, `init/Kconfig`. It's pretty likely that'll be where I find the necessary settings. |
| 32/2 | 2026/08/11 00:35 | tool | grepper |
0mArgs:{
"Expression": "config BPF_SYSCALL",
"PathPrefix": ""
}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"
} |
| 33/2 | 2026/08/11 00:35 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 21662 output: 33 thoughts: 21 Thoughts: Here's my thought process, as requested: **Checking BPF_JIT Configuration** Okay, so I need to figure out the status of BPF JIT compilation within this kernel setup. My first instinct, and the standard practice, is to dive straight into the `kernel/bpf/Kconfig` file. That's the definitive source for the BPF configuration options. I'm heading there to verify the existence, current state, and any dependencies associated with `BPF_JIT`. This is the bedrock; without knowing the Kconfig settings, I can't even begin to troubleshoot any related issues or optimize BPF usage. Let's see what's what. |
| 34/2 | 2026/08/11 00:35 | tool | grepper |
0mArgs:{
"Expression": "config BPF_JIT",
"PathPrefix": "kernel/bpf/Kconfig"
}Results: {
"Output": "kernel/bpf/Kconfig=27=config BPF_SYSCALL\n--\nkernel/bpf/Kconfig-41-\nkernel/bpf/Kconfig:42:config BPF_JIT\nkernel/bpf/Kconfig-43-\tbool \"Enable BPF Just In Time compiler\"\n--\nkernel/bpf/Kconfig-57-\nkernel/bpf/Kconfig:58:config BPF_JIT_ALWAYS_ON\nkernel/bpf/Kconfig-59-\tbool \"Permanently enable BPF JIT and remove BPF interpreter\"\n--\nkernel/bpf/Kconfig-68-\nkernel/bpf/Kconfig:69:config BPF_JIT_DEFAULT_ON\nkernel/bpf/Kconfig-70-\tdef_bool ARCH_WANT_DEFAULT_BPF_JIT || BPF_JIT_ALWAYS_ON\n"
} |
| 35/2 | 2026/08/11 00:35 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 22085 output: 28 thoughts: 45 Thoughts: Okay, here's my take on those thoughts, framed as my own reasoning: **Checking BPF Configurations and Atomic Operations** Alright, so I'm focusing on these BPF configurations: `BPF_SYSCALL` and `BPF_JIT`. Those are the usual suspects, but I always want to make sure I'm not missing anything. Now, I need to see how these might be connected to the atomic operations within the BPF subsystem, since those are always a performance-critical area. Itβs a good time to double-check if `bpf_atomic_load_reg` is being utilized anywhere else within the codebase, beyond the immediate context I'm currently working in. Better to be thorough and verify that usage patterns match my current understanding. |
| 36/2 | 2026/08/11 00:35 | tool | grepper |
0mArgs:{
"Expression": "bpf_atomic_load_reg",
"PathPrefix": ""
}Results: {
"Output": "arch/arm64/net/bpf_jit_comp.c=1265=static int build_insn(const struct bpf_verifier_env *env, const struct bpf_insn *insn,\n--\narch/arm64/net/bpf_jit_comp.c-1994-\t\t\t */\narch/arm64/net/bpf_jit_comp.c:1995:\t\t\tint load_reg = bpf_atomic_load_reg(insn);\narch/arm64/net/bpf_jit_comp.c-1996-\n--\narch/riscv/net/bpf_jit_comp64.c=1361=int bpf_jit_emit_insn(const struct bpf_insn *insn, struct rv_jit_context *ctx,\n--\narch/riscv/net/bpf_jit_comp64.c-2001-\t\t\t */\narch/riscv/net/bpf_jit_comp64.c:2002:\t\t\tint load_reg = bpf_atomic_load_reg(insn);\narch/riscv/net/bpf_jit_comp64.c-2003-\n--\narch/s390/net/bpf_jit_comp.c=773=static void bpf_jit_probe_atomic_pre(struct bpf_jit *jit,\n--\narch/s390/net/bpf_jit_comp.c-792-\t */\narch/s390/net/bpf_jit_comp.c:793:\tload_reg = bpf_atomic_load_reg(insn);\narch/s390/net/bpf_jit_comp.c-794-\tif (load_reg \u003e= 0)\n--\narch/x86/net/bpf_jit_comp.c=2285=st:\t\t\tinsn_off = insn-\u003eoff;\n--\narch/x86/net/bpf_jit_comp.c-2400-\t\t\t\t\t */\narch/x86/net/bpf_jit_comp.c:2401:\t\t\t\t\tint load_reg = bpf_atomic_load_reg(insn);\narch/x86/net/bpf_jit_comp.c-2402-\n--\ninclude/linux/filter.h=409=static inline bool bpf_atomic_is_load_acq(const struct bpf_insn *insn)\n--\ninclude/linux/filter.h-423- */\ninclude/linux/filter.h:424:static inline int bpf_atomic_load_reg(const struct bpf_insn *insn)\ninclude/linux/filter.h-425-{\n--\nkernel/bpf/fixups.c=44=static int insn_def_regno(const struct bpf_insn *insn)\n--\nkernel/bpf/fixups.c-51-\tcase BPF_STX:\nkernel/bpf/fixups.c:52:\t\treturn bpf_atomic_load_reg(insn);\nkernel/bpf/fixups.c-53-\tdefault:\n--\nkernel/bpf/verifier.c=6440=static int check_atomic_rmw(struct bpf_verifier_env *env,\n--\nkernel/bpf/verifier.c-6491-\t */\nkernel/bpf/verifier.c:6492:\tload_reg = bpf_atomic_load_reg(insn);\nkernel/bpf/verifier.c-6493-\tif (load_reg \u003e= 0) {\n"
} |
| 37/2 | 2026/08/11 00:35 | llm | patch-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 23228 output: 205 thoughts: 462 Thoughts: **Analyzing the BPF Atomic Operation Exception Handling Patch** Okay, so this patch addresses a bug in BPF arena exception handling, specifically related to atomic operations. My initial thought is that this is important β atomic operations are critical for concurrency and data integrity, and a bug in their exception handling could lead to significant problems. It seems the issue centers around what happens when an atomic instruction faults. The exception handler needs to correctly clear the destination register in these cases. For instructions like `BPF_CMPXCHG`, it's `r0`, and for `BPF_FETCH`, it is `src_reg`. The patch apparently uses `bpf_atomic_load_reg` to correctly identify the register to clear, which sounds reasonable. It also correctly marks the access as a write for read-modify-write operations, which makes sense. Functionally, this impacts the BPF JIT compiler and verifier, which is to be expected given the nature of the fix. The notes indicate it is worth fuzzing, which I agree with - atomic operations are prime targets for fuzzing to uncover potential edge cases. I need to dig deeper. My focus symbols will be `bpf_insn_def32`, `ex_handler_bpf`, `bpf_jit_emit_insn`, `bpf_int_jit_compile`, and `bpf_check`. `bpf_int_jit_compile` seems like the correct main entry point for the JIT compilation across all architectures, which confirms my understanding. `ex_handler_bpf` is specific to x86 and arm64, so I need to keep that in mind. `bpf_insn_def32` is used in the verifier and fixups, and I will check it in the context of the fixups. Let's quickly check `bpf_insn_def32` and related calls. In `kernel/bpf/fixups.c`, it seems it calls `insn_def_regno`, which then calls `bpf_atomic_load_reg`. This confirms that `bpf_insn_def32` is a good choice for investigation. I'll also check `bpf_check` in `kernel/bpf/verifier.c`. This is the main verifier entry point. The static function `check_atomic_rmw` is called during verification, which is relevant to my understanding of the fix. |
| 38/2 | 2026/08/11 00:35 | tool | set-results |
0mArgs:{
"EnableConfigs": [
"BPF_SYSCALL",
"BPF_JIT"
],
"FocusSymbols": [
"bpf_insn_def32",
"ex_handler_bpf",
"bpf_jit_emit_insn",
"bpf_int_jit_compile",
"bpf_check"
],
"Reasoning": "The patch modifies the BPF JIT compilers (x86, arm64, riscv, s390) and the BPF verifier to correctly handle exceptions for atomic operations in the BPF arena. It introduces `bpf_atomic_load_reg` to identify the register that needs to be cleared when an atomic instruction faults, and ensures that read-modify-write operations are correctly reported as writes. These are functional changes to reachable core kernel logic (BPF subsystem) and should be fuzzed.",
"WorthFuzzing": true
}Results: {
"EnableConfigs": [
"BPF_SYSCALL",
"BPF_JIT"
],
"FocusSymbols": [
"bpf_insn_def32",
"ex_handler_bpf",
"bpf_jit_emit_insn",
"bpf_int_jit_compile",
"bpf_check"
],
"Reasoning": "The patch modifies the BPF JIT compilers (x86, arm64, riscv, s390) and the BPF verifier to correctly handle exceptions for atomic operations in the BPF arena. It introduces `bpf_atomic_load_reg` to identify the register that needs to be cleared when an atomic instruction faults, and ensures that read-modify-write operations are correctly reported as writes. These are functional changes to reachable core kernel logic (BPF subsystem) and should be fuzzed.",
"WorthFuzzing": true
} |
| 39/1 | 2026/08/11 00:35 | action | If |
0mArgs:{
"WorthFuzzing": true
}Results: null |
| 40/2 | 2026/08/11 00:35 | agent | kmsan-evaluator |
0mModel:best-expensive Args: null Results: {
"KMSANReasoning": "The patch fixes the BPF exception handler for arena accesses to correctly identify read-modify-write atomic operations (like BPF_XCHG and BPF_CMPXCHG) as writes, and to properly clear the destination register (e.g., BPF_REG_0 for CMPXCHG) when a page fault occurs. If the register is not cleared, the BPF program simply retains the previous value of that register. This does not involve uninitialized kernel memory, nor does it expose kernel stack/heap memory to user space. The issue is a logic bug in BPF JIT exception handling, which does not introduce risks of uninitialized memory usage that would require KMSAN to detect. Standard testing and BPF selftests (as included in the patch) are sufficient to verify the fix.",
"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: For your convenience, here is the diff of the changes:
commit f4aa7521f85803fd3a1bae14519da0abdc1df01f
Author: syz-cluster <triage@syzkaller.com>
Date: Tue Aug 11 00:34:18 2026 +0000
syz-cluster: applied patch under review
diff --git a/arch/arm64/net/bpf_jit_comp.c b/arch/arm64/net/bpf_jit_comp.c
index d14d297ebb967..74b4083791da3 100644
--- a/arch/arm64/net/bpf_jit_comp.c
+++ b/arch/arm64/net/bpf_jit_comp.c
@@ -1082,23 +1082,27 @@ static void build_epilogue(struct jit_ctx *ctx, bool was_classic)
*
* Bit layout of `fixup` (32-bit):
*
- * +-----------+--------+-----------+-----------+----------+
- * | 31-27 | 26-22 | 21 | 20-16 | 15-0 |
- * | | | | | |
- * | FIXUP_REG | Unused | ARENA_ACC | ARENA_REG | OFFSET |
- * +-----------+--------+-----------+-----------+----------+
+ * +-----------+--------+-------------+-----------+-----------+----------+
+ * | 31-27 | 26-23 | 22 | 21 | 20-16 | 15-0 |
+ * | | | | | | |
+ * | FIXUP_REG | Unused | ARENA_WRITE | ARENA_ACC | ARENA_REG | OFFSET |
+ * +-----------+--------+-------------+-----------+-----------+----------+
*
* - OFFSET (16 bits): Offset used to compute address for Load/Store instruction.
* - ARENA_REG (5 bits): Register that is used to calculate the address for load/store when
* accessing the arena region.
* - ARENA_ACCESS (1 bit): This bit is set when the faulting instruction accessed the arena region.
+ * - ARENA_WRITE (1 bit): This bit is set when the faulting instruction wrote to the arena region.
+ * It is independent of FIXUP_REG, since a read-modify-write both writes to
+ * memory and reads the old value into a register.
* - FIXUP_REG (5 bits): Destination register for the load instruction (cleared on fault) or set to
- * DONT_CLEAR if it is a store instruction.
+ * DONT_CLEAR if the instruction does not read into a register.
*/
#define BPF_FIXUP_OFFSET_MASK GENMASK(15, 0)
#define BPF_FIXUP_ARENA_REG_MASK GENMASK(20, 16)
#define BPF_ARENA_ACCESS BIT(21)
+#define BPF_ARENA_WRITE BIT(22)
#define BPF_FIXUP_REG_MASK GENMASK(31, 27)
#define DONT_CLEAR 5 /* Unused ARM64 register from BPF's POV */
@@ -1109,7 +1113,7 @@ bool ex_handler_bpf(const struct exception_table_entry *ex,
s16 off = FIELD_GET(BPF_FIXUP_OFFSET_MASK, ex->fixup);
int arena_reg = FIELD_GET(BPF_FIXUP_ARENA_REG_MASK, ex->fixup);
bool is_arena = !!(ex->fixup & BPF_ARENA_ACCESS);
- bool is_write = (dst_reg == DONT_CLEAR);
+ bool is_write = !!(ex->fixup & BPF_ARENA_WRITE);
unsigned long addr;
if (is_arena) {
@@ -1132,7 +1136,7 @@ static int add_exception_handler(const struct bpf_insn *insn,
{
off_t ins_offset;
s16 off = insn->off;
- bool is_arena;
+ bool is_arena, is_write;
int arena_reg;
unsigned long pc;
struct exception_table_entry *ex;
@@ -1181,15 +1185,18 @@ static int add_exception_handler(const struct bpf_insn *insn,
/*
* A load-acquire is of BPF_STX class, but reads from src_reg into
* dst_reg like a BPF_LDX does, hence it must not be treated as a store
- * here.
+ * here. A read-modify-write carrying BPF_FETCH is reported as a write
+ * even though it does have a register to clear, see the callers.
*/
- if (BPF_CLASS(insn->code) != BPF_LDX && !bpf_atomic_is_load_acq(insn))
- dst_reg = DONT_CLEAR;
+ is_write = BPF_CLASS(insn->code) != BPF_LDX &&
+ !bpf_atomic_is_load_acq(insn);
ex->fixup = FIELD_PREP(BPF_FIXUP_REG_MASK, dst_reg);
if (is_arena) {
ex->fixup |= BPF_ARENA_ACCESS;
+ if (is_write)
+ ex->fixup |= BPF_ARENA_WRITE;
/*
* insn->src_reg/dst_reg holds the address in the arena region with upper 32-bits
* being zero because of a preceding addr_space_cast(r<n>, 0x0, 0x1) instruction.
@@ -1889,7 +1896,7 @@ static int build_insn(const struct bpf_verifier_env *env, const struct bpf_insn
break;
}
- ret = add_exception_handler(insn, ctx, dst);
+ ret = add_exception_handler(insn, ctx, DONT_CLEAR);
if (ret)
return ret;
break;
@@ -1956,7 +1963,7 @@ static int build_insn(const struct bpf_verifier_env *env, const struct bpf_insn
break;
}
- ret = add_exception_handler(insn, ctx, dst);
+ ret = add_exception_handler(insn, ctx, DONT_CLEAR);
if (ret)
return ret;
break;
@@ -1979,7 +1986,16 @@ static int build_insn(const struct bpf_verifier_env *env, const struct bpf_insn
return ret;
if (BPF_MODE(insn->code) == BPF_PROBE_ATOMIC) {
- ret = add_exception_handler(insn, ctx, dst);
+ /*
+ * A load-acquire reads into dst_reg, and a read-modify-write
+ * carrying BPF_FETCH reads the old value into src_reg, or into
+ * r0 for a BPF_CMPXCHG. Clear that register on fault, the
+ * remaining atomics have no destination register.
+ */
+ int load_reg = bpf_atomic_load_reg(insn);
+
+ ret = add_exception_handler(insn, ctx, load_reg < 0 ?
+ DONT_CLEAR : bpf2a64[load_reg]);
if (ret)
return ret;
}
diff --git a/arch/riscv/net/bpf_jit_comp64.c b/arch/riscv/net/bpf_jit_comp64.c
index 6b9972b07c1b0..2504df1fa1118 100644
--- a/arch/riscv/net/bpf_jit_comp64.c
+++ b/arch/riscv/net/bpf_jit_comp64.c
@@ -1992,10 +1992,19 @@ int bpf_jit_emit_insn(const struct bpf_insn *insn, struct rv_jit_context *ctx,
ret = emit_atomic_rmw(rd, rs, insn, ctx);
/* ret can be 1 (skip-zext); extable entry still needs to be added */
- if (ret >= 0)
- ret = add_exception_handler(insn,
- bpf_atomic_is_load_acq(insn) ? rd : REG_DONT_CLEAR_MARKER,
- ctx) ?: ret;
+ if (ret >= 0) {
+ /*
+ * A load-acquire reads into dst_reg, and a read-modify-write
+ * carrying BPF_FETCH reads the old value into src_reg, or into
+ * r0 for a BPF_CMPXCHG. Clear that register on fault, the
+ * remaining atomics have no destination register.
+ */
+ int load_reg = bpf_atomic_load_reg(insn);
+
+ ret = add_exception_handler(insn, load_reg < 0 ?
+ REG_DONT_CLEAR_MARKER : regmap[load_reg],
+ ctx) ?: ret;
+ }
if (ret)
return ret;
diff --git a/arch/s390/net/bpf_jit_comp.c b/arch/s390/net/bpf_jit_comp.c
index b60877478b45d..c46872b071ce7 100644
--- a/arch/s390/net/bpf_jit_comp.c
+++ b/arch/s390/net/bpf_jit_comp.c
@@ -774,6 +774,8 @@ static void bpf_jit_probe_atomic_pre(struct bpf_jit *jit,
struct bpf_insn *insn,
struct bpf_jit_probe *probe)
{
+ int load_reg;
+
if (BPF_MODE(insn->code) != BPF_PROBE_ATOMIC)
return;
@@ -783,6 +785,14 @@ static void bpf_jit_probe_atomic_pre(struct bpf_jit *jit,
EMIT4(0xb9080000, REG_W1, insn->dst_reg);
probe->arena_reg = REG_W1;
probe->prg = jit->prg;
+ /*
+ * A read-modify-write carrying BPF_FETCH reads the old value into
+ * src_reg, or into r0 for a BPF_CMPXCHG. Clear that register on
+ * fault, the remaining atomics only write memory.
+ */
+ load_reg = bpf_atomic_load_reg(insn);
+ if (load_reg >= 0)
+ probe->reg = reg2hex[load_reg];
}
static int bpf_jit_probe_post(struct bpf_jit *jit, struct bpf_prog *fp,
@@ -1684,6 +1694,7 @@ static noinline int bpf_jit_insn(struct bpf_jit *jit, struct bpf_prog *fp,
if (load_probe.prg != -1) {
probe.prg = jit->prg;
probe.arena_reg = load_probe.arena_reg;
+ probe.reg = load_probe.reg;
}
loop_start = jit->prg;
/* 0: {csy|csg} %w0,%src,off(%arena) */
diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
index 8dddb5d7af21b..d920772af7d5f 100644
--- a/arch/x86/net/bpf_jit_comp.c
+++ b/arch/x86/net/bpf_jit_comp.c
@@ -1473,17 +1473,20 @@ static int emit_atomic_ld_st_index(u8 **pprog, u32 atomic_op, u32 size,
*
* Bit layout of `fixup` (32-bit):
*
- * +-----------+--------+-----------+---------+----------+
- * | 31 | 30-24 | 23-16 | 15-8 | 7-0 |
- * | | | | | |
- * | ARENA_ACC | Unused | ARENA_REG | DST_REG | INSN_LEN |
- * +-----------+--------+-----------+---------+----------+
+ * +-----------+-------------+--------+-----------+---------+----------+
+ * | 31 | 30 | 29-24 | 23-16 | 15-8 | 7-0 |
+ * | | | | | | |
+ * | ARENA_ACC | ARENA_WRITE | Unused | ARENA_REG | DST_REG | INSN_LEN |
+ * +-----------+-------------+--------+-----------+---------+----------+
*
* - INSN_LEN (8 bits): Length of faulting insn (max x86 insn = 15 bytes (fits in 8 bits)).
* - DST_REG (8 bits): Offset of dst_reg from reg2pt_regs[] (max offset = 112 (fits in 8 bits)).
- * This is set to DONT_CLEAR if the insn is a store.
+ * This is set to DONT_CLEAR if the insn does not read into a register.
* - ARENA_REG (8 bits): Offset of the register that is used to calculate the
* address for load/store when accessing the arena region.
+ * - ARENA_WRITE (1 bit): This bit is set when the faulting instruction wrote to the arena region.
+ * It is independent of DST_REG, since a read-modify-write both writes to
+ * memory and reads the old value into a register.
* - ARENA_ACCESS (1 bit): This bit is set when the faulting instruction accessed the arena region.
*
* Bit layout of `data` (32-bit):
@@ -1502,6 +1505,7 @@ static int emit_atomic_ld_st_index(u8 **pprog, u32 atomic_op, u32 size,
#define FIXUP_INSN_LEN_MASK GENMASK(7, 0)
#define FIXUP_REG_MASK GENMASK(15, 8)
#define FIXUP_ARENA_REG_MASK GENMASK(23, 16)
+#define FIXUP_ARENA_WRITE BIT(30)
#define FIXUP_ARENA_ACCESS BIT(31)
#define DATA_ARENA_OFFSET_MASK GENMASK(31, 16)
@@ -1510,7 +1514,7 @@ bool ex_handler_bpf(const struct exception_table_entry *x, struct pt_regs *regs)
u32 reg = FIELD_GET(FIXUP_REG_MASK, x->fixup);
u32 insn_len = FIELD_GET(FIXUP_INSN_LEN_MASK, x->fixup);
bool is_arena = !!(x->fixup & FIXUP_ARENA_ACCESS);
- bool is_write = (reg == DONT_CLEAR);
+ bool is_write = !!(x->fixup & FIXUP_ARENA_WRITE);
unsigned long addr;
s16 off;
u32 arena_reg;
@@ -2348,6 +2352,7 @@ st: insn_off = insn->off;
struct exception_table_entry *ex;
u8 *_insn = image + proglen + (start_of_ldx - temp);
u32 arena_reg, fixup_reg;
+ bool is_write;
s64 delta;
if (!bpf_prog->aux->extable)
@@ -2384,15 +2389,29 @@ st: insn_off = insn->off;
bpf_atomic_is_load_acq(insn)) {
arena_reg = reg2pt_regs[src_reg];
fixup_reg = reg2pt_regs[dst_reg];
+ is_write = false;
} else {
+ /*
+ * A store has no destination register to clear,
+ * except for a read-modify-write with BPF_FETCH,
+ * which also reads the old value into src_reg, or
+ * into r0 for a BPF_CMPXCHG. Either way the access
+ * is still reported as a write.
+ */
+ int load_reg = bpf_atomic_load_reg(insn);
+
arena_reg = reg2pt_regs[dst_reg];
- fixup_reg = DONT_CLEAR;
+ fixup_reg = load_reg < 0 ? DONT_CLEAR :
+ reg2pt_regs[load_reg];
+ is_write = true;
}
ex->fixup = FIELD_PREP(FIXUP_INSN_LEN_MASK, prog - start_of_ldx) |
FIELD_PREP(FIXUP_ARENA_REG_MASK, arena_reg) |
FIELD_PREP(FIXUP_REG_MASK, fixup_reg);
ex->fixup |= FIXUP_ARENA_ACCESS;
+ if (is_write)
+ ex->fixup |= FIXUP_ARENA_WRITE;
ex->data |= FIELD_PREP(DATA_ARENA_OFFSET_MASK, insn->off);
}
diff --git a/include/linux/filter.h b/include/linux/filter.h
index 4edba8182db1b..15d83684c6e94 100644
--- a/include/linux/filter.h
+++ b/include/linux/filter.h
@@ -414,6 +414,30 @@ static inline bool bpf_atomic_is_load_acq(const struct bpf_insn *insn)
insn->imm == BPF_LOAD_ACQ;
}
+/*
+ * Given an instruction @insn, return the number of the BPF register that a
+ * BPF_ATOMIC reads the value at its memory operand into, or -1 if there is
+ * no such register. That is the register a BPF_PROBE_ATOMIC has to clear when
+ * the access faults. Like bpf_atomic_is_load_acq(), @insn is not assumed to
+ * be a BPF_ATOMIC here.
+ */
+static inline int bpf_atomic_load_reg(const struct bpf_insn *insn)
+{
+ if (BPF_CLASS(insn->code) != BPF_STX ||
+ (BPF_MODE(insn->code) != BPF_ATOMIC &&
+ BPF_MODE(insn->code) != BPF_PROBE_ATOMIC))
+ return -1;
+
+ switch (insn->imm) {
+ case BPF_LOAD_ACQ:
+ return insn->dst_reg;
+ case BPF_CMPXCHG:
+ return BPF_REG_0;
+ default:
+ return (insn->imm & BPF_FETCH) ? insn->src_reg : -1;
+ }
+}
+
/* Memory store, *(uint *) (dst_reg + off16) = imm32 */
#define BPF_ST_MEM(SIZE, DST, OFF, IMM) \
diff --git a/kernel/bpf/fixups.c b/kernel/bpf/fixups.c
index 661e2d13a6042..c4bd70befbb5c 100644
--- a/kernel/bpf/fixups.c
+++ b/kernel/bpf/fixups.c
@@ -49,16 +49,7 @@ static int insn_def_regno(const struct bpf_insn *insn)
case BPF_ST:
return -1;
case BPF_STX:
- if (BPF_MODE(insn->code) == BPF_ATOMIC ||
- BPF_MODE(insn->code) == BPF_PROBE_ATOMIC) {
- if (insn->imm == BPF_CMPXCHG)
- return BPF_REG_0;
- else if (insn->imm == BPF_LOAD_ACQ)
- return insn->dst_reg;
- else if (insn->imm & BPF_FETCH)
- return insn->src_reg;
- }
- return -1;
+ return bpf_atomic_load_reg(insn);
default:
return insn->dst_reg;
}
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index add3affc57035..73a2e8bb1782a 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -6485,21 +6485,16 @@ static int check_atomic_rmw(struct bpf_verifier_env *env,
return -EACCES;
}
- if (insn->imm & BPF_FETCH) {
- if (insn->imm == BPF_CMPXCHG)
- load_reg = BPF_REG_0;
- else
- load_reg = insn->src_reg;
-
+ /*
+ * A negative load_reg means that this instruction accesses a memory
+ * location but doesn't actually load it into a register.
+ */
+ load_reg = bpf_atomic_load_reg(insn);
+ if (load_reg >= 0) {
/* check and record load of old value */
err = check_reg_arg(env, load_reg, DST_OP);
if (err)
return err;
- } else {
- /* This instruction accesses a memory location but doesn't
- * actually load it into a register.
- */
- load_reg = -1;
}
dst_reg = cur_regs(env) + insn->dst_reg;
diff --git a/tools/testing/selftests/bpf/prog_tests/stream.c b/tools/testing/selftests/bpf/prog_tests/stream.c
index 15dd3ae2a84b7..e4e9374309e26 100644
--- a/tools/testing/selftests/bpf/prog_tests/stream.c
+++ b/tools/testing/selftests/bpf/prog_tests/stream.c
@@ -105,6 +105,10 @@ void test_stream_arena_fault_address(void)
test_address(skel->progs.stream_arena_write_fault, &skel->bss->fault_addr);
if (test__start_subtest("load_acquire_fault"))
test_address(skel->progs.stream_arena_load_acquire_fault, &skel->bss->fault_addr);
+ if (test__start_subtest("xchg_fault"))
+ test_address(skel->progs.stream_arena_xchg_fault, &skel->bss->fault_addr);
+ if (test__start_subtest("cmpxchg_fault"))
+ test_address(skel->progs.stream_arena_cmpxchg_fault, &skel->bss->fault_addr);
stream__destroy(skel);
}
diff --git a/tools/testing/selftests/bpf/progs/stream.c b/tools/testing/selftests/bpf/progs/stream.c
index cf5533e11f39c..00a37933e411d 100644
--- a/tools/testing/selftests/bpf/progs/stream.c
+++ b/tools/testing/selftests/bpf/progs/stream.c
@@ -229,6 +229,107 @@ int stream_arena_load_acquire_fault(void *ctx)
return val;
}
+SEC("syscall")
+__arch_x86_64
+__arch_arm64
+__success __retval(0)
+__stderr("ERROR: Arena WRITE access at unmapped address 0x{{.*}}")
+__stderr("CPU: {{[0-9]+}} UID: 0 PID: {{[0-9]+}} Comm: {{.*}}")
+__stderr("Call trace:\n"
+"{{([a-zA-Z_][a-zA-Z0-9_]*\\+0x[0-9a-fA-F]+/0x[0-9a-fA-F]+\n"
+"|[ \t]+[^\n]+\n)*}}")
+int stream_arena_xchg_fault(void *ctx)
+{
+ static const struct bpf_insn xchg_insn = {
+ .code = 0xc3, /* BPF_STX | BPF_ATOMIC | BPF_W */
+ .dst_reg = 1, /* BPF_REG_1 */
+ .src_reg = 2, /* BPF_REG_2 */
+ .off = 0x7fff,
+ .imm = 0xe1, /* BPF_XCHG */
+ };
+ struct bpf_arena *ptr = (void *)&arena;
+ u64 user_vm_start, val;
+
+ /*
+ * Prevent GCC bounds warning: casting &arena to struct bpf_arena *
+ * triggers bounds checking since the map definition is smaller than
+ * struct bpf_arena. barrier_var() makes the pointer opaque to GCC,
+ * preventing the bounds analysis.
+ */
+ barrier_var(ptr);
+ user_vm_start = ptr->user_vm_start;
+ fault_addr = user_vm_start + 0x7fff;
+ bpf_addr_space_cast(user_vm_start, 0, 1);
+ /*
+ * A read-modify-write carrying BPF_FETCH writes to memory, so the fault
+ * has to be reported as a WRITE from the dst_reg address, but it also
+ * reads the old value into src_reg, so the exception handler has to
+ * clear src_reg. Poison it up front, the returned value must be 0.
+ */
+ asm volatile (
+ "r1 = %[user_vm_start];"
+ "r2 = 1;"
+ ".8byte %[xchg_insn];" /* r2 = xchg((u32 *)(r1 + 0x7fff), r2) */
+ "%[val] = r2;"
+ : [val] "=r" (val)
+ : [user_vm_start] "r" (user_vm_start),
+ __imm_insn(xchg_insn, xchg_insn)
+ : "r1", "r2"
+ );
+ return val;
+}
+
+SEC("syscall")
+__arch_x86_64
+__arch_arm64
+__success __retval(0)
+__stderr("ERROR: Arena WRITE access at unmapped address 0x{{.*}}")
+__stderr("CPU: {{[0-9]+}} UID: 0 PID: {{[0-9]+}} Comm: {{.*}}")
+__stderr("Call trace:\n"
+"{{([a-zA-Z_][a-zA-Z0-9_]*\\+0x[0-9a-fA-F]+/0x[0-9a-fA-F]+\n"
+"|[ \t]+[^\n]+\n)*}}")
+int stream_arena_cmpxchg_fault(void *ctx)
+{
+ static const struct bpf_insn cmpxchg_insn = {
+ .code = 0xc3, /* BPF_STX | BPF_ATOMIC | BPF_W */
+ .dst_reg = 1, /* BPF_REG_1 */
+ .src_reg = 2, /* BPF_REG_2 */
+ .off = 0x7fff,
+ .imm = 0xf1, /* BPF_CMPXCHG */
+ };
+ struct bpf_arena *ptr = (void *)&arena;
+ u64 user_vm_start, val;
+
+ /*
+ * Prevent GCC bounds warning: casting &arena to struct bpf_arena *
+ * triggers bounds checking since the map definition is smaller than
+ * struct bpf_arena. barrier_var() makes the pointer opaque to GCC,
+ * preventing the bounds analysis.
+ */
+ barrier_var(ptr);
+ user_vm_start = ptr->user_vm_start;
+ fault_addr = user_vm_start + 0x7fff;
+ bpf_addr_space_cast(user_vm_start, 0, 1);
+ /*
+ * Same as the exchange above, except that a BPF_CMPXCHG reads the old
+ * value into r0 rather than into src_reg, so r0 is the register the
+ * exception handler has to clear. It doubles as the compare value, but
+ * the comparison never happens since the access faults first.
+ */
+ asm volatile (
+ "r1 = %[user_vm_start];"
+ "r0 = 1;"
+ "r2 = 2;"
+ ".8byte %[cmpxchg_insn];" /* r0 = cmpxchg((u32 *)(r1 + 0x7fff), r0, r2) */
+ "%[val] = r0;"
+ : [val] "=r" (val)
+ : [user_vm_start] "r" (user_vm_start),
+ __imm_insn(cmpxchg_insn, cmpxchg_insn)
+ : "r0", "r1", "r2"
+ );
+ return val;
+}
+
static __noinline void subprog(void)
{
int __arena *addr = (int __arena *)0xdeadbeef;
|
| 41/3 | 2026/08/11 00:35 | llm | kmsan-evaluator |
0mModel:gemini-3.1-pro-preview Args: null Results: null Tokens: input: 9571 output: 193 thoughts: 1379 Thoughts: **BPF Exception Handling for Atomic Arena Accesses: A Deep Dive** Okay, so this patch is about exception handling in BPF JIT compilers, specifically on arm64, riscv, s390, and x86. The core issue is how we deal with faults that occur during atomic read-modify-write operations (like `BPF_XCHG`, `BPF_CMPXCHG`) when accessing the BPF arena. This arena, as I understand it, is shared memory between userspace and BPF programs. My initial thought was, "Wait, a fault? Does that mean uninitialized memory is being read?" But no, the register wouldn't contain uninitialized kernel memory *per se*. The CPU register would just have whatever value it had before the faulting instruction. If the exception handler doesn't clear the destination register on a fault, the BPF program would effectively "re-use" the previous value. But is this a security risk, specifically, a KMSAN-detectable issue? The BPF verifier already ensures registers are initialized before use, and KMSAN is looking for *uninitialized* reads, not just old values. I had to refresh my knowledge. Let's look at the bpf_atomic_load_reg function. It's purpose is to identify which register to clear in case of a fault. It considers cases like BPF_LOAD_ACQ and BPF_CMPXCHG. The patch focuses on correctly identifying the register that needs to be cleared (set to zero) during a fault. For read operations, the destination register is cleared. For read-modify-write operations, there's a fetch and the patch ensures the correct register (likely `BPF_REG_0` for `CMPXCHG`) is cleared on fault. The main concern initially was the potential for old values to linger. But since BPF programs already have their registers initialized, the register simply retains the previous value, so this isn't a kernel-memory exposure. Also, this does not expose anything from the kernel's perspective. It's just a variable in a CPU register from BPF perspective. KMSAN, which detects uninitialized memory, isn't really relevant here. The patch modifies `ex_handler_bpf` and related functions, changing how `is_write` is determined to handle read-modify-writes correctly. But it's not introducing any new uninitialized kernel memory. Even if a register isn't cleared on fault, the previous value won't be from the kernel. KMSAN does track CPU registers, but in the context of the BPF JIT, KMSAN is probably not deeply instrumenting the JITted code. It does have some support for BPF, but it's limited. KMSAN isn't the right tool here. This is a logic error that needs an error to indicate it did not complete. So, the bug here is that the BPF exception handler *wasn't* clearing the register correctly for these atomic operations. This meant the program would continue with an old value instead of a clear value. It's a logic error in BPF JIT/exception handling, not an uninitialized memory exposure. This requires no special attention from KMSAN, as the registers are not uninitialized kernel memory. It is purely a matter of BPF program integrity. Therefore, NeedsKMSAN = false. Just to be sure, I've rechecked the patch. The key change seems to be around correctly setting `is_write` and clearing the appropriate registers in case of a fault. The `BPF_ARENA_WRITE` flag is being introduced to signal an arena write. I can see that this isn't about uninitialized memory. It's a bug with how the exception handler was handling faults on atomic arena accesses and, therefore, I believe my reasoning is solid. |
| 42/3 | 2026/08/11 00:36 | tool | set-results |
0mArgs:{
"KMSANReasoning": "The patch fixes the BPF exception handler for arena accesses to correctly identify read-modify-write atomic operations (like BPF_XCHG and BPF_CMPXCHG) as writes, and to properly clear the destination register (e.g., BPF_REG_0 for CMPXCHG) when a page fault occurs. If the register is not cleared, the BPF program simply retains the previous value of that register. This does not involve uninitialized kernel memory, nor does it expose kernel stack/heap memory to user space. The issue is a logic bug in BPF JIT exception handling, which does not introduce risks of uninitialized memory usage that would require KMSAN to detect. Standard testing and BPF selftests (as included in the patch) are sufficient to verify the fix.",
"NeedsKMSAN": false
}Results: {
"KMSANReasoning": "The patch fixes the BPF exception handler for arena accesses to correctly identify read-modify-write atomic operations (like BPF_XCHG and BPF_CMPXCHG) as writes, and to properly clear the destination register (e.g., BPF_REG_0 for CMPXCHG) when a page fault occurs. If the register is not cleared, the BPF program simply retains the previous value of that register. This does not involve uninitialized kernel memory, nor does it expose kernel stack/heap memory to user space. The issue is a logic bug in BPF JIT exception handling, which does not introduce risks of uninitialized memory usage that would require KMSAN to detect. Standard testing and BPF selftests (as included in the patch) are sufficient to verify the fix.",
"NeedsKMSAN": false
} |
| Total Calls | Total Tokens | Avg Tokens | Total Duration (Seconds) | Avg Duration (Seconds) |
|---|
| Total Calls | Total Duration (Seconds) | Avg Duration (Seconds) |
|---|