| Seq | Timestamp | Type | Name | Duration |
|---|---|---|---|---|
| 0/0 | 2026/10/21 07:47 | flow | patch-triage |
3mArgs:null Results: {
"EnableConfigs": [
"BPF_SYSCALL",
"BPF_JIT"
],
"FocusSymbols": [
"check_unwind_insns",
"bpf_jit_subprogs",
"bpf_unwind_target",
"bpf_mark_subprog_exc_cb",
"bpf_throw"
],
"KMSANReasoning": "The patch adjusts BPF verifier and JIT compilation logic for BPF stack unwinding: it ensures exception callbacks cannot unwind (`bpf_prog_can_unwind()` returns false if `prog-\u003eaux-\u003eexception_cb` is set), rejects unwind instructions for offloaded BPF programs in `check_unwind_insns()`, and updates selftests.\n\nKMSAN vs. KASAN applicability:\n- The changes only modify verifier validation rules, JIT instruction selection, and comments, along with userspace selftests.\n- No new memory allocations or structures are introduced, and no kernel data is copied or leaked to user space (no copy_to_user, put_user, netlink, or ioctl output).\n- The inspected struct fields (`prog-\u003eaux-\u003eexception_cb` and `prog-\u003eaux-\u003eoffload`) reside within `struct bpf_prog_aux`, which is zero-allocated via kzalloc upon program allocation.\n- The patch does not introduce or expose any uninitialized stack or heap memory, nor does it create branching on uninitialized data. Any execution or JIT framing issues would pertain to control flow or out-of-bounds access (detectable by KASAN), not uninitialized memory reads detectable only by KMSAN.\n\nTherefore, a dedicated KMSAN fuzzing session is not needed.",
"NeedsKMSAN": false,
"Reasoning": "The patch modifies BPF verifier unwinding validation logic in check_unwind_insns() to disallow unwind instructions in offloaded programs, and updates bpf_prog_can_unwind() to prevent exception callbacks from unwinding. These paths are directly reachable from userspace via the bpf() system call when verifying and JIT-compiling BPF programs with subprograms, exception callbacks, and unwinding on x86_64.",
"WorthFuzzing": true
} |
| 1/1 | 2026/10/21 07:47 | action | read-patch-diff |
0mArgs:null Results: {
"PatchDiff": "commit a9dcc1468c3fbec1d9063fdb94dc3d5063641908\nAuthor: syz-cluster \u003ctriage@syzkaller.com\u003e\nDate: Wed Oct 21 07:47:27 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 b3efe0668e868..326e9e1dea0a7 100644\n--- a/arch/arm64/net/bpf_jit_comp.c\n+++ b/arch/arm64/net/bpf_jit_comp.c\n@@ -1273,7 +1273,7 @@ static long bpf_unwind_fixup(u64 lr)\n \te = search_bpf_extables(ptrauth_strip_kernel_insn_pac(lr) - 1);\n \t/*\n \t * The verifier made sure that unwind_goto follows a call in a prog. When\n-\t * the kernel called an async or an exception callback, it's exit.\n+\t * the kernel called an async callback, it's exit.\n \t */\n \treturn e ? e-\u003efixup : 0;\n }\ndiff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c\nindex d3ab36281144d..6a2fe3d0039d3 100644\n--- a/arch/x86/net/bpf_jit_comp.c\n+++ b/arch/x86/net/bpf_jit_comp.c\n@@ -2552,7 +2552,7 @@ static u64 bpf_unwind_target(u64 ret_addr)\n \n \t/*\n \t * The verifier made sure that unwind_goto follows a call in a prog. When\n-\t * the kernel called an async or an exception callback, it's exit.\n+\t * the kernel called an async callback, it's exit.\n \t */\n \treturn e ? ret_addr + e-\u003efixup : ret_addr;\n }\ndiff --git a/include/linux/filter.h b/include/linux/filter.h\nindex fccd8db336470..e0218e677a1dc 100644\n--- a/include/linux/filter.h\n+++ b/include/linux/filter.h\n@@ -267,9 +267,13 @@ static inline bool bpf_is_unwind_exit(const struct bpf_insn *insn)\n /*\n * The caller of the main prog doesn't tell unwind_exit from exit. An extension\n * is different: its caller is the caller of the subprog that it replaced.\n+ * An exception callback returns from the frame of the main prog. After freplace\n+ * or a tail call it returns to a prog that wasn't verified with the callback.\n */\n static inline bool bpf_prog_can_unwind(const struct bpf_prog *prog)\n {\n+\tif (prog-\u003eaux-\u003eexception_cb)\n+\t\treturn false;\n \treturn bpf_is_subprog(prog) || prog-\u003etype == BPF_PROG_TYPE_EXT;\n }\n \ndiff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c\nindex 7d7193b087f67..5601d20562186 100644\n--- a/kernel/bpf/verifier.c\n+++ b/kernel/bpf/verifier.c\n@@ -3462,7 +3462,7 @@ static int check_unwind_insns(struct bpf_verifier_env *env)\n \t}\n \tif (!seen)\n \t\treturn 0;\n-\tif (!bpf_jit_supports_unwind()) {\n+\tif (!bpf_jit_supports_unwind() || bpf_prog_is_offloaded(env-\u003eprog-\u003eaux)) {\n \t\tverbose(env, \"JIT does not support unwinding\\n\");\n \t\treturn -ENOTSUPP;\n \t}\ndiff --git a/tools/testing/selftests/bpf/prog_tests/unwind_attach.c b/tools/testing/selftests/bpf/prog_tests/unwind_attach.c\nindex ada8b3273ccb1..37e03b3e0ee80 100644\n--- a/tools/testing/selftests/bpf/prog_tests/unwind_attach.c\n+++ b/tools/testing/selftests/bpf/prog_tests/unwind_attach.c\n@@ -67,7 +67,7 @@ void test_unwind_attach(void)\n {\n \tstruct verifier_unwind *tgt;\n \tstruct bpf_program *prog;\n-\tint tgt_fd, plain_fd, err;\n+\tint tgt_fd, plain_fd, shared_fd, tail_fd, throws_fd, err, key = 0;\n \n \tif (!is_jit_enabled()) {\n \t\tprintf(\"%s:SKIP:JIT is disabled\\n\", __func__);\n@@ -79,7 +79,10 @@ void test_unwind_attach(void)\n \t\treturn;\n \tbpf_object__for_each_program(prog, tgt-\u003eobj)\n \t\tbpf_program__set_autoload(prog, prog == tgt-\u003eprogs.calls_global_unwinds ||\n-\t\t\t\t\t\tprog == tgt-\u003eprogs.calls_global_never_unwinds);\n+\t\t\t\t\t\tprog == tgt-\u003eprogs.calls_global_never_unwinds ||\n+\t\t\t\t\t\tprog == tgt-\u003eprogs.shared_pad ||\n+\t\t\t\t\t\tprog == tgt-\u003eprogs.tail_call_in_subprog ||\n+\t\t\t\t\t\tprog == tgt-\u003eprogs.exception_callback_unwinds);\n \terr = verifier_unwind__load(tgt);\n \tif (err == -ENOTSUPP) {\n \t\tprintf(\"%s:SKIP:JIT does not support unwinding\\n\", __func__);\n@@ -107,6 +110,21 @@ void test_unwind_attach(void)\n \tattach(plain_fd, \"global_never_unwinds\", \"freplace_unwinds\",\n \t \"Extension program can unwind, while original does not\", 0);\n \tASSERT_EQ(run(tgt_fd), 15, \"retval\");\n+\n+\t/*\n+\t * An exception callback returns from the frame of the main prog. Here\n+\t * that's a return to a call that unwind_goto follows. unwind_exit of\n+\t * the callback has to be exit: the pad wasn't verified with it.\n+\t */\n+\tshared_fd = bpf_program__fd(tgt-\u003eprogs.shared_pad);\n+\tattach(shared_fd, \"global_never_unwinds\", \"freplace_throws\", NULL, 3);\n+\n+\ttail_fd = bpf_program__fd(tgt-\u003eprogs.tail_call_in_subprog);\n+\tthrows_fd = bpf_program__fd(tgt-\u003eprogs.exception_callback_unwinds);\n+\terr = bpf_map__update_elem(tgt-\u003emaps.prog_array, \u0026key, sizeof(key),\n+\t\t\t\t \u0026throws_fd, sizeof(throws_fd), 0);\n+\tif (ASSERT_OK(err, \"prog_array\"))\n+\t\tASSERT_EQ(run(tail_fd), 7, \"retval\");\n out:\n \tverifier_unwind__destroy(tgt);\n }\ndiff --git a/tools/testing/selftests/bpf/progs/unwind_attach.c b/tools/testing/selftests/bpf/progs/unwind_attach.c\nindex df73c26c1ff46..9aff7c6bda238 100644\n--- a/tools/testing/selftests/bpf/progs/unwind_attach.c\n+++ b/tools/testing/selftests/bpf/progs/unwind_attach.c\n@@ -7,6 +7,13 @@\n \n /* The targets are global_unwinds() and global_never_unwinds() in verifier_unwind.c */\n \n+#define unwind_exit \".8byte %[insn_unwind_exit];\"\n+#define __imm_unwind_exit \\\n+\t__imm_insn(insn_unwind_exit, \\\n+\t\t BPF_RAW_INSN(BPF_JMP | BPF_EXIT, 0, BPF_UNWIND_EXIT, 0, 0))\n+\n+extern void bpf_throw(__u64 cookie) __ksym;\n+\n int fentry_cnt;\n \n SEC(\"?fentry/global_unwinds\")\n@@ -33,11 +40,27 @@ __naked unsigned long freplace_unwinds(void)\n {\n \tasm volatile (\n \t\t\"r0 = 3;\"\n-\t\t\".8byte %[unwind_exit];\"\n+\t\tunwind_exit\n \t\t:\n-\t\t: __imm_insn(unwind_exit,\n-\t\t\t BPF_RAW_INSN(BPF_JMP | BPF_EXIT, 0, BPF_UNWIND_EXIT, 0, 0))\n+\t\t: __imm_unwind_exit\n \t);\n }\n \n+/* Not naked: the argument has to have a name in BTF */\n+__noinline int throws_cb(__u64 cookie)\n+{\n+\tif (cookie)\n+\t\tasm volatile (\"r0 = 3;\" unwind_exit :: __imm_unwind_exit : \"r0\");\n+\treturn 0;\n+}\n+\n+/* It has no unwind_exit, so it can replace a subprog that cannot unwind */\n+SEC(\"?freplace/global_never_unwinds\")\n+__attribute__((btf_decl_tag(\"exception_callback:throws_cb\")))\n+unsigned long freplace_throws(void)\n+{\n+\tbpf_throw(1);\n+\treturn 0;\n+}\n+\n char _license[] SEC(\"license\") = \"GPL\";\ndiff --git a/tools/testing/selftests/bpf/progs/verifier_unwind.c b/tools/testing/selftests/bpf/progs/verifier_unwind.c\nindex 0a75cb8af67ff..5a21345c34d45 100644\n--- a/tools/testing/selftests/bpf/progs/verifier_unwind.c\n+++ b/tools/testing/selftests/bpf/progs/verifier_unwind.c\n@@ -611,6 +611,35 @@ __naked int calls_global_never_unwinds(void)\n \t);\n }\n \n+/*\n+ * The verifier gets to the pad from the first call only, with r6 = 1. The second\n+ * unwind_goto stays, since the pad is not dead code.\n+ */\n+SEC(\"tc\")\n+__description(\"unwind: a pad shared with a call of a subprog that cannot unwind\")\n+__arch_x86_64\n+__arch_arm64\n+__load_if_JITed()\n+__success __retval(7)\n+__naked int shared_pad(void)\n+{\n+\tasm volatile (\n+\t\t\"r6 = 1;\"\n+\t\t\"call global_returns;\"\n+\t\tunwind_goto(4)\n+\t\t\"r6 = 2;\"\n+\t\t\"call global_never_unwinds;\"\n+\t\tunwind_goto(1)\n+\t\t\"exit;\"\n+\t\t\"r0 = r6;\"\n+\t\t\"exit;\"\n+\t\t:\n+\t\t: __imm_unwind_goto(4),\n+\t\t __imm_unwind_goto(1)\n+\t\t: __clobber_all\n+\t);\n+}\n+\n SEC(\"tc\")\n __description(\"unwind: no unwind_goto after a call of a global subprog\")\n __arch_x86_64\n"
} |
| 2/1 | 2026/10/21 07:47 | agent | patch-evaluator |
2mModel:core Args: null Results: {
"EnableConfigs": [
"BPF_SYSCALL",
"BPF_JIT"
],
"FocusSymbols": [
"check_unwind_insns",
"bpf_jit_subprogs",
"bpf_unwind_target",
"bpf_mark_subprog_exc_cb",
"bpf_throw"
],
"Reasoning": "The patch modifies BPF verifier unwinding validation logic in check_unwind_insns() to disallow unwind instructions in offloaded programs, and updates bpf_prog_can_unwind() to prevent exception callbacks from unwinding. These paths are directly reachable from userspace via the bpf() system call when verifying and JIT-compiling BPF programs with subprograms, exception callbacks, and unwinding on x86_64.",
"WorthFuzzing": true
}Instruction: You are an expert Linux kernel maintainer and security engineer.
Your job is to review a provided patch series and evaluate whether it warrants fuzzing with syzkaller.
IMPORTANT: The changes have ALREADY been applied and committed as the HEAD commit in
your workspace. Do NOT rely on internal assumptions. You must actively use your code access
tools to inspect the actual source code, callers, and surrounding context.
================================================================================
1. CORE TRIAGE PHILOSOPHY
================================================================================
The goal of patch fuzzing is to discover crashes, regressions, exposed latent bugs,
and newly triggered assertions introduced by the patch series.
- REACHABILITY IS THE PRIMARY GATE:
Fuzzing can only discover bugs in code that can actually execute in standard virtualized
environments (GCE or QEMU, utilizing software-emulated devices like USB gadgets, netdev, tun/tap).
If the modified code is structurally unreachable (see Section 2), it MUST NOT be fuzzed,
regardless of whether it adds assertions or complex logic.
- DO NOT BLINDLY TRUST "NO FUNCTIONAL CHANGE" (NFCI) OR "REFACTORING" CLAIMS:
Patch authors routinely label changes as "cleanups", "refactorings", or state
"No functional change intended". Do NOT take these claims at face value.
Code refactorings that rearrange logic, introduce helper functions, or alter state management
in core subsystems frequently introduce subtle semantic shifts or uncover latent kernel bugs.
If reachable executable code is modified or refactored, it MUST be fuzzed.
- NEW OR MODIFIED ASSERTIONS IN REACHABLE CODE MUST BE FUZZED:
When a patch introduces or modifies runtime checks or assertions (e.g., WARN_ON*, VM_WARN_ON*,
BUG_ON*, lockdep_assert*) in reachable code paths, it enforces new or stricter invariants.
Even if the author believes the invariant always holds, fuzzing is essential to verify whether
an unusual sequence of operations can violate it.
================================================================================
2. WHEN TO RETURN WorthFuzzing=false (NEGATIVE CRITERIA)
================================================================================
Return WorthFuzzing=false ONLY IF all modified code falls strictly into one or more of these categories:
- Non-kernel and non-executable changes:
* Modifications to Documentation/, comments, or spelling fixes.
* User-space directories, self-tests, samples, or scripts (e.g., tools/, samples/, scripts/, usr/)
that do not affect the compiled kernel image (vmlinux) or kernel modules.
* Purely decorative logging (e.g., message strings in pr_err, printk, dev_info) or tracepoints
that do not alter control flow or data structures.
* Build system or Kconfig changes that do not alter compiled C logic.
- Structurally unreachable hardware:
* Vendor-specific PCIe switches, SmartNICs, or GPU drivers (e.g., mlxsw, pds_core, qed,
ionic, amdgpu) requiring physical ASIC/PCIe cards not emulated in standard QEMU.
- Unreachable execution paths:
* Driver teardown callbacks (.remove, .shutdown, pci_unregister_driver) executed only during
physical PCI hot-unplug or manual sysfs driver unbinding.
* Code paths exclusive to architectures other than the target architecture.
================================================================================
3. WHEN TO RETURN WorthFuzzing=true (POSITIVE CRITERIA)
================================================================================
Return WorthFuzzing=true whenever the patch touches reachable executable code, including:
- Core Subsystems:
* Any logic modifications in memory management (mm/), synchronization/locking (kernel/locking/),
BPF, scheduler, core networking, VFS, or syscall handling.
- Refactorings and Code Cleanups:
* Any restructuring of reachable data structures, helper abstractions, or algorithm flows.
- Runtime Assertions and Defensive Checks:
* Any introduction or alteration of assertions (WARN_ON*, VM_WARN_ON*, BUG_ON*, etc.) in reachable paths.
- Reachable Drivers and Protocols:
* Drivers accessible via virtual buses (virtio, USB gadget, loopback, netlink, binder, sockets, etc.).
================================================================================
4. EXTRACTING FocusSymbols (PREVENTING DILUTION)
================================================================================
When WorthFuzzing=true, you must extract specific kernel functions into FocusSymbols to guide the fuzzer:
- AVOID UBIQUITOUS LIFECYCLE HOT-PATHS:
Do NOT list generic, ubiquitous functions called by almost every program in the corpus
(including, but not limited to: general memory allocators and deallocators, page fault
and trap handlers, or core synchronization primitives; this is not an exhaustive list).
Listing ubiquitous functions causes the fuzzer to classify thousands of unrelated tests as "focused",
which severely dilutes fuzzing effort away from the actual changes.
- TARGET SPECIFIC FEATURE LOGIC AND ENTRYPOINTS:
List functions that specifically implement the logic being added or altered, or direct API entrypoints
for the subsystem feature under review.
- HANDLING STATIC INLINE FUNCTIONS IN HEADERS (.h):
Compiler-inlined static functions (such as static inlines in mm/*.h or include/linux/*.h) lack
distinct symbol addresses in vmlinux and cannot be targeted directly by symbol coverage filters.
If the changes are primarily in static inline helpers, identify non-static, feature-specific caller
functions in .c files that exercise them (avoiding ubiquitous lifecycle wrappers).
================================================================================
5. IDENTIFYING EnableConfigs
================================================================================
Identify any specific CONFIG_ options required to properly compile and reach the modified code:
- Inspect Kconfig files and #ifdef guards; do not make assumptions.
- Check "depends on" lines in Kconfig to include any non-standard parent subsystem configs needed.
- Strip any 'CONFIG_' prefix (e.g., return "NET_IPV4" instead of "CONFIG_NET_IPV4").
Prefer calling several tools at the same time to save round-trips.
Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.
Prompt: Target architecture: amd64
For your convenience, here is the diff of the changes:
commit a9dcc1468c3fbec1d9063fdb94dc3d5063641908
Author: syz-cluster <triage@syzkaller.com>
Date: Wed Oct 21 07:47:27 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 b3efe0668e868..326e9e1dea0a7 100644
--- a/arch/arm64/net/bpf_jit_comp.c
+++ b/arch/arm64/net/bpf_jit_comp.c
@@ -1273,7 +1273,7 @@ static long bpf_unwind_fixup(u64 lr)
e = search_bpf_extables(ptrauth_strip_kernel_insn_pac(lr) - 1);
/*
* The verifier made sure that unwind_goto follows a call in a prog. When
- * the kernel called an async or an exception callback, it's exit.
+ * the kernel called an async callback, it's exit.
*/
return e ? e->fixup : 0;
}
diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
index d3ab36281144d..6a2fe3d0039d3 100644
--- a/arch/x86/net/bpf_jit_comp.c
+++ b/arch/x86/net/bpf_jit_comp.c
@@ -2552,7 +2552,7 @@ static u64 bpf_unwind_target(u64 ret_addr)
/*
* The verifier made sure that unwind_goto follows a call in a prog. When
- * the kernel called an async or an exception callback, it's exit.
+ * the kernel called an async callback, it's exit.
*/
return e ? ret_addr + e->fixup : ret_addr;
}
diff --git a/include/linux/filter.h b/include/linux/filter.h
index fccd8db336470..e0218e677a1dc 100644
--- a/include/linux/filter.h
+++ b/include/linux/filter.h
@@ -267,9 +267,13 @@ static inline bool bpf_is_unwind_exit(const struct bpf_insn *insn)
/*
* The caller of the main prog doesn't tell unwind_exit from exit. An extension
* is different: its caller is the caller of the subprog that it replaced.
+ * An exception callback returns from the frame of the main prog. After freplace
+ * or a tail call it returns to a prog that wasn't verified with the callback.
*/
static inline bool bpf_prog_can_unwind(const struct bpf_prog *prog)
{
+ if (prog->aux->exception_cb)
+ return false;
return bpf_is_subprog(prog) || prog->type == BPF_PROG_TYPE_EXT;
}
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index 7d7193b087f67..5601d20562186 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -3462,7 +3462,7 @@ static int check_unwind_insns(struct bpf_verifier_env *env)
}
if (!seen)
return 0;
- if (!bpf_jit_supports_unwind()) {
+ if (!bpf_jit_supports_unwind() || bpf_prog_is_offloaded(env->prog->aux)) {
verbose(env, "JIT does not support unwinding\n");
return -ENOTSUPP;
}
diff --git a/tools/testing/selftests/bpf/prog_tests/unwind_attach.c b/tools/testing/selftests/bpf/prog_tests/unwind_attach.c
index ada8b3273ccb1..37e03b3e0ee80 100644
--- a/tools/testing/selftests/bpf/prog_tests/unwind_attach.c
+++ b/tools/testing/selftests/bpf/prog_tests/unwind_attach.c
@@ -67,7 +67,7 @@ void test_unwind_attach(void)
{
struct verifier_unwind *tgt;
struct bpf_program *prog;
- int tgt_fd, plain_fd, err;
+ int tgt_fd, plain_fd, shared_fd, tail_fd, throws_fd, err, key = 0;
if (!is_jit_enabled()) {
printf("%s:SKIP:JIT is disabled\n", __func__);
@@ -79,7 +79,10 @@ void test_unwind_attach(void)
return;
bpf_object__for_each_program(prog, tgt->obj)
bpf_program__set_autoload(prog, prog == tgt->progs.calls_global_unwinds ||
- prog == tgt->progs.calls_global_never_unwinds);
+ prog == tgt->progs.calls_global_never_unwinds ||
+ prog == tgt->progs.shared_pad ||
+ prog == tgt->progs.tail_call_in_subprog ||
+ prog == tgt->progs.exception_callback_unwinds);
err = verifier_unwind__load(tgt);
if (err == -ENOTSUPP) {
printf("%s:SKIP:JIT does not support unwinding\n", __func__);
@@ -107,6 +110,21 @@ void test_unwind_attach(void)
attach(plain_fd, "global_never_unwinds", "freplace_unwinds",
"Extension program can unwind, while original does not", 0);
ASSERT_EQ(run(tgt_fd), 15, "retval");
+
+ /*
+ * An exception callback returns from the frame of the main prog. Here
+ * that's a return to a call that unwind_goto follows. unwind_exit of
+ * the callback has to be exit: the pad wasn't verified with it.
+ */
+ shared_fd = bpf_program__fd(tgt->progs.shared_pad);
+ attach(shared_fd, "global_never_unwinds", "freplace_throws", NULL, 3);
+
+ tail_fd = bpf_program__fd(tgt->progs.tail_call_in_subprog);
+ throws_fd = bpf_program__fd(tgt->progs.exception_callback_unwinds);
+ err = bpf_map__update_elem(tgt->maps.prog_array, &key, sizeof(key),
+ &throws_fd, sizeof(throws_fd), 0);
+ if (ASSERT_OK(err, "prog_array"))
+ ASSERT_EQ(run(tail_fd), 7, "retval");
out:
verifier_unwind__destroy(tgt);
}
diff --git a/tools/testing/selftests/bpf/progs/unwind_attach.c b/tools/testing/selftests/bpf/progs/unwind_attach.c
index df73c26c1ff46..9aff7c6bda238 100644
--- a/tools/testing/selftests/bpf/progs/unwind_attach.c
+++ b/tools/testing/selftests/bpf/progs/unwind_attach.c
@@ -7,6 +7,13 @@
/* The targets are global_unwinds() and global_never_unwinds() in verifier_unwind.c */
+#define unwind_exit ".8byte %[insn_unwind_exit];"
+#define __imm_unwind_exit \
+ __imm_insn(insn_unwind_exit, \
+ BPF_RAW_INSN(BPF_JMP | BPF_EXIT, 0, BPF_UNWIND_EXIT, 0, 0))
+
+extern void bpf_throw(__u64 cookie) __ksym;
+
int fentry_cnt;
SEC("?fentry/global_unwinds")
@@ -33,11 +40,27 @@ __naked unsigned long freplace_unwinds(void)
{
asm volatile (
"r0 = 3;"
- ".8byte %[unwind_exit];"
+ unwind_exit
:
- : __imm_insn(unwind_exit,
- BPF_RAW_INSN(BPF_JMP | BPF_EXIT, 0, BPF_UNWIND_EXIT, 0, 0))
+ : __imm_unwind_exit
);
}
+/* Not naked: the argument has to have a name in BTF */
+__noinline int throws_cb(__u64 cookie)
+{
+ if (cookie)
+ asm volatile ("r0 = 3;" unwind_exit :: __imm_unwind_exit : "r0");
+ return 0;
+}
+
+/* It has no unwind_exit, so it can replace a subprog that cannot unwind */
+SEC("?freplace/global_never_unwinds")
+__attribute__((btf_decl_tag("exception_callback:throws_cb")))
+unsigned long freplace_throws(void)
+{
+ bpf_throw(1);
+ return 0;
+}
+
char _license[] SEC("license") = "GPL";
diff --git a/tools/testing/selftests/bpf/progs/verifier_unwind.c b/tools/testing/selftests/bpf/progs/verifier_unwind.c
index 0a75cb8af67ff..5a21345c34d45 100644
--- a/tools/testing/selftests/bpf/progs/verifier_unwind.c
+++ b/tools/testing/selftests/bpf/progs/verifier_unwind.c
@@ -611,6 +611,35 @@ __naked int calls_global_never_unwinds(void)
);
}
+/*
+ * The verifier gets to the pad from the first call only, with r6 = 1. The second
+ * unwind_goto stays, since the pad is not dead code.
+ */
+SEC("tc")
+__description("unwind: a pad shared with a call of a subprog that cannot unwind")
+__arch_x86_64
+__arch_arm64
+__load_if_JITed()
+__success __retval(7)
+__naked int shared_pad(void)
+{
+ asm volatile (
+ "r6 = 1;"
+ "call global_returns;"
+ unwind_goto(4)
+ "r6 = 2;"
+ "call global_never_unwinds;"
+ unwind_goto(1)
+ "exit;"
+ "r0 = r6;"
+ "exit;"
+ :
+ : __imm_unwind_goto(4),
+ __imm_unwind_goto(1)
+ : __clobber_all
+ );
+}
+
SEC("tc")
__description("unwind: no unwind_goto after a call of a global subprog")
__arch_x86_64
|
| 3/2 | 2026/10/21 07:47 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 5728 output: 45 thoughts: 250 Thoughts: **Analyzing the BPF Unwind Patch** Alright, let's dive into this patch. My immediate thought is to dissect the commit diff and understand the implications of these changes, line by line. First, I see the edits to `arch/arm64/net/bpf_jit_comp.c` and `arch/x86/net/bpf_jit_comp.c`. The comment changes for `bpf_unwind_fixup` and `bpf_unwind_target` suggest a potential clarification or enhancement to how these functions are documented, but I need to understand the implications for the overall unwind process, whether it relates to the specific architecture or a more general approach to BPF JIT unwinding. Next, the change in `include/linux/filter.h` with the addition of the `bpf_prog_can_unwind` check... that's crucial. The new check `if (prog->aux->exception_cb) return false;` hints at a conditional dependency. This suggests there are scenarios, triggered by a callback, where unwinding is not possible. I need to understand which scenarios trigger `prog->aux->exception_cb`. Is this for offloaded programs, and is this now explicitly preventing unwind for offloaded BPF programs? The modification in `kernel/bpf/verifier.c` is particularly interesting. The conditional logic in `check_unwind_insns` has changed, specifically relating to `bpf_jit_supports_unwind()` and the new addition of `bpf_prog_is_offloaded(env->prog->aux)`. This strongly suggests an integration between the JIT unwind support and offloading capabilities. We're now potentially disabling unwind for offloaded programs, even if the JIT supports it. It's vital to know *why* this change has been made. Is it a limitation of current offload implementations or a more general design decision? My hunch is it's related to the JIT and offloading not playing nicely together in terms of unwinding. Finally, the inclusion of changes in the selftests within `tools/testing/` indicates that this patch will have associated tests. These tests are key. I need to examine those to understand how the new logic is being verified and the edge cases that are being covered. Now, to get the full picture, I'll use my tools to grab the context from git and the kernel repository. I'll search for related discussions, other patches touching these files, and any relevant mailing list threads. This context is essential to understand the motivation behind this patch and any potential side effects. My goal is to determine if this is a functional improvement, a bug fix, or a necessary architectural limitation. |
| 4/2 | 2026/10/21 07:47 | tool | grepper |
0mArgs:{
"Expression": "bpf_prog_can_unwind",
"PathPrefixes": [
"include/linux/filter.h",
"kernel/bpf/"
]
}Results: {
"Output": "include/linux/filter.h=262=static inline bool bpf_is_unwind_exit(const struct bpf_insn *insn)\n--\ninclude/linux/filter.h-272- */\ninclude/linux/filter.h:273:static inline bool bpf_prog_can_unwind(const struct bpf_prog *prog)\ninclude/linux/filter.h-274-{\n"
} |
| 5/2 | 2026/10/21 07:47 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 6714 output: 23 thoughts: 22 Thoughts: Here's my thought process, summarized as you requested: **Investigating `bpf_prog_can_unwind` Usage** Alright, let's get down to brass tacks. I need to understand how `bpf_prog_can_unwind` is being utilized within the codebase. My instinct is to perform a thorough search. I'm going to leverage my familiarity with the tools at my disposal to locate every instance where this function is called. This search will be the foundation for figuring out the relationship this function has with the rest of the system. |
| 6/2 | 2026/10/21 07:47 | tool | grepper |
0mArgs:{
"Expression": "bpf_prog_can_unwind"
}Results: {
"Output": "arch/arm64/net/bpf_jit_comp.c=1432=static int build_insn(const struct bpf_verifier_env *env, const struct bpf_insn *insn,\n--\narch/arm64/net/bpf_jit_comp.c-1892-\tcase BPF_JMP | BPF_EXIT:\narch/arm64/net/bpf_jit_comp.c:1893:\t\tif (bpf_is_unwind_exit(insn) \u0026\u0026 bpf_prog_can_unwind(ctx-\u003eprog)) {\narch/arm64/net/bpf_jit_comp.c-1894-\t\t\temit_unwind_exit(ctx);\n--\narch/x86/net/bpf_jit_comp.c=2577=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-3867-\t\tcase BPF_JMP | BPF_EXIT:\narch/x86/net/bpf_jit_comp.c:3868:\t\t\tif (src_reg == BPF_UNWIND_EXIT \u0026\u0026 bpf_prog_can_unwind(bpf_prog) \u0026\u0026\narch/x86/net/bpf_jit_comp.c-3869-\t\t\t emit_unwind_ret_addr(\u0026prog, ip))\n--\ninclude/linux/filter.h=262=static inline bool bpf_is_unwind_exit(const struct bpf_insn *insn)\n--\ninclude/linux/filter.h-272- */\ninclude/linux/filter.h:273:static inline bool bpf_prog_can_unwind(const struct bpf_prog *prog)\ninclude/linux/filter.h-274-{\n"
} |
| 7/2 | 2026/10/21 07:47 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 7365 output: 37 thoughts: 33 Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience: **Diving into the BPF Verifier's Unwind Logic** Right, let's zero in on `kernel/bpf/verifier.c` and specifically how the verifier handles the `check_unwind_insns` function and its related checks for unwind exits and gotos. I need to refresh my understanding of *exactly* how the verifier ensures the correctness of unwind sequences. I know the general principles, of course: that we must ensure unwind paths lead to a valid exit, avoid loops, prevent jumps into the middle of instructions, and guarantee that stack usage is consistent. But I want to nail down the specifics of the current implementation. I'm particularly interested in how the verifier interprets `exit` and `goto` instructions within the context of unwind operations. What are the preconditions it enforces? How does it track the program counter and stack state along unwind paths? I need to clarify the interaction between instruction validity and the unwind's safety, and verify that it's robust against any new BPF features we've introduced or considered. Specifically, I'm thinking about potential edge cases or blindspots in the verifier's logic that might allow a subtle vulnerability to slip through. Time to do a thorough code review. |
| 8/2 | 2026/10/21 07:47 | tool | read-file |
0mArgs:{
"File": "kernel/bpf/verifier.c",
"FirstLine": 3450,
"LineCount": 40
}Results: {
"Contents": "3450:\t\t\tif (!bpf_is_unwind_goto(insn))\n3451:\t\t\t\tcontinue;\n3452:\t\t\tseen = true;\n3453:\t\t\tif (!i || !(bpf_pseudo_call(insn - 1) || bpf_is_callx(insn - 1))) {\n3454:\t\t\t\tverbose(env, \"unwind_goto at insn %d doesn't follow a call of a subprog\\n\",\n3455:\t\t\t\t\ti);\n3456:\t\t\t\treturn -EINVAL;\n3457:\t\t\t}\n3458:\t\t\tif (bpf_is_jump_target(env, i)) {\n3459:\t\t\t\tverbose(env, \"jump to unwind_goto at insn %d\\n\", i);\n3460:\t\t\t\treturn -EINVAL;\n3461:\t\t\t}\n3462:\t\t}\n3463:\t\tif (!seen)\n3464:\t\t\treturn 0;\n3465:\t\tif (!bpf_jit_supports_unwind() || bpf_prog_is_offloaded(env-\u003eprog-\u003eaux)) {\n3466:\t\t\tverbose(env, \"JIT does not support unwinding\\n\");\n3467:\t\t\treturn -ENOTSUPP;\n3468:\t\t}\n3469:\t\tenv-\u003eprog-\u003ejit_required = 1;\n3470:\t\tenv-\u003eprog-\u003eaux-\u003ecan_unwind = env-\u003esubprog_info[0].can_unwind;\n3471:\t\treturn 0;\n3472:\t}\n3473:\t\n3474:\t/*\n3475:\t * Sort subprogs in topological order so that leaf subprogs come first and\n3476:\t * their callers come later. This is a DFS post-order traversal of the call\n3477:\t * graph. Scan only reachable instructions (those in the computed postorder) of\n3478:\t * the current subprog to discover callees (direct subprogs and sync\n3479:\t * callbacks).\n3480:\t *\n3481:\t * The callees of callx are not known before the main verification pass.\n3482:\t * When callx is used the sort is repeated after it with the recorded callx\n3483:\t * edges added to the call graph to reject recursion through indirect calls.\n3484:\t */\n3485:\tstatic int sort_subprogs_topo(struct bpf_verifier_env *env)\n3486:\t{\n3487:\t\tstruct bpf_subprog_info *si = env-\u003esubprog_info;\n3488:\t\tint *insn_postorder = env-\u003ecfg.insn_postorder;\n3489:\t\tstruct bpf_insn *insn = env-\u003eprog-\u003einsnsi;\n"
} |
| 9/2 | 2026/10/21 07:47 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 8434 output: 45 thoughts: 122 Thoughts: Okay, let's see. My first instinct, as always, is to check the commit history. I'd typically run `git log -1` to grab the most recent commit or look directly at the commit message, but it seems I don't have that tool at my disposal. Alright, no problem. Let's see what I *do* have. Hmm, it looks like I'm limited to `grepper`, `codesearch-dir-index`, `read-file`, and `set-results`. Right, I can work with that. Given the situation, I should examine the code directly. My intuition is telling me that the relevant code will probably be in `arch/x86/net/bpf_jit_comp.c`, specifically around lines 3860-3880, and perhaps also around lines 2550-2560. I need to get a better handle on the current state of that code. Let's begin there. |
| 10/2 | 2026/10/21 07:47 | tool | read-file |
0mArgs:{
"File": "arch/x86/net/bpf_jit_comp.c",
"FirstLine": 2545,
"LineCount": 25
}Results: {
"Contents": "2545:\t\tex-\u003edata = EX_TYPE_BPF;\n2546:\t\treturn 0;\n2547:\t}\n2548:\t\n2549:\tstatic u64 bpf_unwind_target(u64 ret_addr)\n2550:\t{\n2551:\t\tconst struct exception_table_entry *e = search_bpf_extables(ret_addr - 1);\n2552:\t\n2553:\t\t/*\n2554:\t\t * The verifier made sure that unwind_goto follows a call in a prog. When\n2555:\t\t * the kernel called an async callback, it's exit.\n2556:\t\t */\n2557:\t\treturn e ? ret_addr + e-\u003efixup : ret_addr;\n2558:\t}\n2559:\t\n2560:\t/* unwind_exit: fix the return address of this frame. r0 and r2 are returned. */\n2561:\tstatic int emit_unwind_ret_addr(u8 **pprog, u8 *ip)\n2562:\t{\n2563:\t\tu8 *prog = *pprog, *start = prog;\n2564:\t\n2565:\t\tEMIT2(0x50, 0x56);\t\t\t/* push rax; push rsi */\n2566:\t\tEMIT4(0x48, 0x8B, 0x7D, 0x08);\t\t/* mov rdi, [rbp + 8] */\n2567:\t\tip += prog - start;\n2568:\t\tip += x86_call_depth_emit_accounting(\u0026prog, bpf_unwind_target, ip);\n2569:\t\tif (emit_call(\u0026prog, bpf_unwind_target, ip))\n"
} |
| 11/2 | 2026/10/21 07:47 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 9286 output: 45 thoughts: 30 Thoughts: Okay, here's my interpretation of that thought process, assuming I'm deep in the weeds of kernel networking and eBPF: **Investigating eBPF JIT Compilation in the x86 Architecture** Right, let's dive into this. The issue *must* be somewhere within the BPF JIT compilation for x86. I need to get my hands dirty. My instinct is telling me there's something amiss in the code, and I need to pinpoint the source of the problem. Time to dig into the heart of the matter. My first move will be to check `arch/x86/net/bpf_jit_comp.c`, specifically around line 3865. That area likely handles a critical piece of the JIT compilation process – perhaps register allocation, instruction emission, or some crucial optimization stage. That seems like a good starting point to hunt for the bug. Let's see what's actually going on in that section. |
| 12/2 | 2026/10/21 07:47 | tool | read-file |
0mArgs:{
"File": "arch/x86/net/bpf_jit_comp.c",
"FirstLine": 3860,
"LineCount": 20
}Results: {
"Contents": "3860:\t\t\t\t\tEMIT1_off32(0xE9, jmp_offset);\n3861:\t\t\t\t} else {\n3862:\t\t\t\t\tpr_err(\"jmp gen bug %llx\\n\", jmp_offset);\n3863:\t\t\t\t\treturn -EFAULT;\n3864:\t\t\t\t}\n3865:\t\t\t\tbreak;\n3866:\t\n3867:\t\t\tcase BPF_JMP | BPF_EXIT:\n3868:\t\t\t\tif (src_reg == BPF_UNWIND_EXIT \u0026\u0026 bpf_prog_can_unwind(bpf_prog) \u0026\u0026\n3869:\t\t\t\t emit_unwind_ret_addr(\u0026prog, ip))\n3870:\t\t\t\t\treturn -EINVAL;\n3871:\t\t\t\tif (seen_exit) {\n3872:\t\t\t\t\tjmp_offset = ctx-\u003ecleanup_addr - addrs[i];\n3873:\t\t\t\t\tgoto emit_jmp;\n3874:\t\t\t\t}\n3875:\t\t\t\tseen_exit = true;\n3876:\t\t\t\t/* Update cleanup_addr */\n3877:\t\t\t\tctx-\u003ecleanup_addr = proglen + (prog - temp);\n3878:\t\t\t\tif (bpf_prog_was_classic(bpf_prog) \u0026\u0026\n3879:\t\t\t\t !ns_capable_noaudit(\u0026init_user_ns, CAP_SYS_ADMIN)) {\n"
} |
| 13/2 | 2026/10/21 07:47 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 9921 output: 35 thoughts: 23 Thoughts: Here's my attempt at summarizing the thought process, tailored for an expert audience: **Diving into eBPF Filter Definitions** Okay, let's zero in on the core of the eBPF filter structure. My initial thought is to check the `include/linux/filter.h` header file. Specifically, I'm aiming for the region around lines 260-280. This usually contains the crucial definitions for the eBPF program structure itself, the filter instruction format (`struct sock_filter` or its equivalent if the kernel version has changed significantly), or potentially related structures that define the various actions and arguments associated with eBPF programs, specifically relating to how filters are structured and how they are handled. I'm expecting to find the key pieces there. It should be a good starting point for understanding how the kernel represents and interprets BPF instructions. |
| 14/2 | 2026/10/21 07:47 | tool | read-file |
0mArgs:{
"File": "include/linux/filter.h",
"FirstLine": 260,
"LineCount": 25
}Results: {
"Contents": " 260:\t}\n 261:\t\n 262:\tstatic inline bool bpf_is_unwind_exit(const struct bpf_insn *insn)\n 263:\t{\n 264:\t\treturn insn-\u003ecode == (BPF_JMP | BPF_EXIT) \u0026\u0026 insn-\u003esrc_reg == BPF_UNWIND_EXIT;\n 265:\t}\n 266:\t\n 267:\t/*\n 268:\t * The caller of the main prog doesn't tell unwind_exit from exit. An extension\n 269:\t * is different: its caller is the caller of the subprog that it replaced.\n 270:\t * An exception callback returns from the frame of the main prog. After freplace\n 271:\t * or a tail call it returns to a prog that wasn't verified with the callback.\n 272:\t */\n 273:\tstatic inline bool bpf_prog_can_unwind(const struct bpf_prog *prog)\n 274:\t{\n 275:\t\tif (prog-\u003eaux-\u003eexception_cb)\n 276:\t\t\treturn false;\n 277:\t\treturn bpf_is_subprog(prog) || prog-\u003etype == BPF_PROG_TYPE_EXT;\n 278:\t}\n 279:\t\n 280:\tstatic inline bool insn_is_zext(const struct bpf_insn *insn)\n 281:\t{\n 282:\t\treturn insn-\u003ecode == (BPF_ALU | BPF_MOV | BPF_X) \u0026\u0026 insn-\u003eimm == 1;\n 283:\t}\n 284:\t\n"
} |
| 15/2 | 2026/10/21 07:47 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 10605 output: 33 thoughts: 366 Thoughts: **Analyzing a BPF Patch for Unwinding Support** Okay, let's dive into this patch and see what's going on. First, I see a change in `kernel/bpf/verifier.c`, specifically within `check_unwind_insns`. It appears we're adding a check: if the JIT doesn't support unwinding *or* if the program is offloaded, then we'll return `-ENOTSUPP`. That makes sense; if the JIT can't handle it, or if it's running somewhere else, unwinding isn't an option. Next, looking at `include/linux/filter.h`, the `bpf_prog_can_unwind` function has a new condition added. Now, it seems that if the program has an `exception_cb` set, we immediately return false. Otherwise, we fall back to the existing logic – checking if it's a subprogram or an extension. This suggests some kind of exception handling interaction. Hmm, interesting. The remaining changes are just comment updates in the architecture-specific JIT compiler files (`arch/x86/net/bpf_jit_comp.c` and `arch/arm64/net/bpf_jit_comp.c`) and some updates in the selftests. Wait a second… is this code path actually reachable? Yep, it is! The BPF verifier interacts with the BPF JIT, which is relevant to my area of expertise – specifically, x86 (amd64, the target architecture). Userspace can load BPF programs using the `bpf()` syscall and `BPF_PROG_LOAD`. So, it's reasonable to expect to see a call to `check_unwind_insns` in `kernel/bpf/verifier.c`. |
| 16/2 | 2026/10/21 07:48 | tool | grepper |
0mArgs:{
"Expression": "check_unwind_insns",
"PathPrefixes": [
"kernel/bpf/"
]
}Results: {
"Output": "kernel/bpf/verifier.c=3423=static int next_callx_callee(struct bpf_verifier_env *env, int caller, int from)\n--\nkernel/bpf/verifier.c-3438- */\nkernel/bpf/verifier.c:3439:static int check_unwind_insns(struct bpf_verifier_env *env)\nkernel/bpf/verifier.c-3440-{\n--\nkernel/bpf/verifier.c=23783=int bpf_check(struct bpf_prog **prog, union bpf_attr *attr, bpfptr_t uattr,\n--\nkernel/bpf/verifier.c-23948-\nkernel/bpf/verifier.c:23949:\tret = check_unwind_insns(env);\nkernel/bpf/verifier.c-23950-\tif (ret \u003c 0)\n"
} |
| 17/2 | 2026/10/21 07:48 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 11636 output: 34 thoughts: 140 Thoughts: Okay, here's my summary, presented as a stream of thought: **BPF Program Loading and Unwinding: A Deep Dive** Right, so `bpf_check` is called during `BPF_PROG_LOAD`. Got it. That's the gatekeeper, making sure things are kosher before a program is even loaded. Now, the next question is about `bpf_prog_can_unwind`. That's an important one; it suggests the ability to back out of a program's execution, which implies some kind of error handling or control flow beyond a simple exit. I'm thinking about the JIT compilation process now, specifically in `arch/x86/net/bpf_jit_comp.c`. Okay, I see. In the `do_jit` function, when it hits the `BPF_JMP | BPF_EXIT` case... aha! There's a check: `if (src_reg == BPF_UNWIND_EXIT && bpf_prog_can_unwind(bpf_prog) && emit_unwind_ret_addr(&prog, ip))`. So, if the source register indicates a unwind exit, and the program *can* unwind, we try to emit the return address for unwinding. That's the crux of it, the mechanism. Now, I'm a bit curious. Where is `exception_cb` set? That unwind process sounds a lot like exception handling to me. I need to refresh my memory on the call stack and how exception handling is initiated. Let me go check on where that's set and called, I think that would illuminate more about the control flow of the unwind operations. |
| 18/2 | 2026/10/21 07:48 | tool | grepper |
0mArgs:{
"Expression": "exception_cb",
"PathPrefixes": [
"kernel/bpf/",
"include/"
]
}Results: {
"Output": "include/linux/bpf.h=1854=struct bpf_prog_aux {\n--\ninclude/linux/bpf.h-1892-\tbool xdp_has_frags;\ninclude/linux/bpf.h:1893:\tbool exception_cb;\ninclude/linux/bpf.h-1894-\tbool exception_boundary;\n--\ninclude/linux/bpf.h-1939-\tchar name[BPF_OBJ_NAME_LEN];\ninclude/linux/bpf.h:1940:\tu64 (*bpf_exception_cb)(u64 cookie, u64 sp, u64 bp, u64, u64);\ninclude/linux/bpf.h-1941-\tu16 stack_arg_sp_adjust;\n--\ninclude/linux/bpf_verifier.h=941=struct bpf_subprog_info {\n--\ninclude/linux/bpf_verifier.h-966-\tbool is_async_cb: 1;\ninclude/linux/bpf_verifier.h:967:\tbool is_exception_cb: 1;\ninclude/linux/bpf_verifier.h-968-\tbool args_cached: 1;\n--\ninclude/linux/filter.h=273=static inline bool bpf_prog_can_unwind(const struct bpf_prog *prog)\ninclude/linux/filter.h-274-{\ninclude/linux/filter.h:275:\tif (prog-\u003eaux-\u003eexception_cb)\ninclude/linux/filter.h-276-\t\treturn false;\n--\nkernel/bpf/fixups.c=1356=static int jit_subprogs(struct bpf_verifier_env *env)\n--\nkernel/bpf/fixups.c-1489-\t\tfunc[i]-\u003eaux-\u003etail_call_reachable = env-\u003esubprog_info[i].tail_call_reachable;\nkernel/bpf/fixups.c:1490:\t\tfunc[i]-\u003eaux-\u003eexception_cb = env-\u003esubprog_info[i].is_exception_cb;\nkernel/bpf/fixups.c-1491-\t\tfunc[i]-\u003eaux-\u003echanges_pkt_data = env-\u003esubprog_info[i].changes_pkt_data;\n--\nkernel/bpf/fixups.c-1602-\tprog-\u003eaux-\u003ereal_func_cnt = env-\u003esubprog_cnt;\nkernel/bpf/fixups.c:1603:\tprog-\u003eaux-\u003ebpf_exception_cb = (void *)func[env-\u003eexception_callback_subprog]-\u003ebpf_func;\nkernel/bpf/fixups.c-1604-\tprog-\u003eaux-\u003eexception_boundary = func[0]-\u003eaux-\u003eexception_boundary;\n--\nkernel/bpf/helpers.c=3430=__bpf_kfunc void bpf_throw(u64 cookie)\n--\nkernel/bpf/helpers.c-3446-\tkasan_unpoison_task_stack_below((void *)(long)(ctx.sp ?: ctx.bp));\nkernel/bpf/helpers.c:3447:\tctx.aux-\u003ebpf_exception_cb(cookie, ctx.sp + ctx.aux-\u003estack_arg_sp_adjust, ctx.bp, 0, 0);\nkernel/bpf/helpers.c-3448-\tWARN(1, \"A call to BPF exception callback should never return\\n\");\n--\nkernel/bpf/verifier.c=483=void bpf_mark_subprog_exc_cb(struct bpf_verifier_env *env, int subprog)\n--\nkernel/bpf/verifier.c-488-\tinfo-\u003eis_async_cb = true;\nkernel/bpf/verifier.c:489:\tinfo-\u003eis_exception_cb = true;\nkernel/bpf/verifier.c-490-}\n--\nkernel/bpf/verifier.c=492=static bool subprog_is_exc_cb(struct bpf_verifier_env *env, int subprog)\nkernel/bpf/verifier.c-493-{\nkernel/bpf/verifier.c:494:\treturn subprog_info(env, subprog)-\u003eis_exception_cb;\nkernel/bpf/verifier.c-495-}\n--\nkernel/bpf/verifier.c=5756=static int check_max_stack_depth_subprog(struct bpf_verifier_env *env, int idx,\n--\nkernel/bpf/verifier.c-5895-\t\t\t\t\tcontinue;\nkernel/bpf/verifier.c:5896:\t\t\t\tif (subprog[sidx].is_exception_cb) {\nkernel/bpf/verifier.c-5897-\t\t\t\t\tverbose(env, \"insn %d cannot call exception cb directly\", i);\n--\nkernel/bpf/verifier.c=22480=int bpf_check_attach_target(struct bpf_verifier_log *log,\n--\nkernel/bpf/verifier.c-22545-\t\t}\nkernel/bpf/verifier.c:22546:\t\tif (aux-\u003efunc \u0026\u0026 aux-\u003efunc[subprog]-\u003eaux-\u003eexception_cb) {\nkernel/bpf/verifier.c-22547-\t\t\tbpf_log(log,\n"
} |
| 19/2 | 2026/10/21 07:48 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 13491 output: 40 thoughts: 1548 Thoughts: **Analysis of BPF Unwind Behavior and Fuzzing Potential** Okay, let's break this down. My initial thought is to examine the behavior around `bpf_prog_can_unwind`. Specifically, I'm interested in how it interacts with exception callbacks and the BPF JIT compiler, especially in the context of the x86 architecture. The key here is the logic within `bpf_prog_can_unwind`. I see it returns `false` if an `exception_cb` is defined and only returns `true` for subprograms or extended BPF programs. The important call site is in `arch/x86/net/bpf_jit_comp.c`, specifically within `do_jit`. It uses `bpf_prog_can_unwind` during `BPF_JMP | BPF_EXIT` instructions to determine whether to call `emit_unwind_ret_addr`. This is the crux; if the function returns `false`, `emit_unwind_ret_addr` *isn't* emitted, essentially treating `unwind_exit` as a normal exit. This is a critical change. The commentary points out that before this patch, exception callbacks *could* have triggered the unwind behavior, but that's not what's intended. Specifically, if `bpf_prog_can_unwind` returned `true` for exception callbacks, it would have generated the code to "fix" the return address to the unwind pad. But since freplace or tail calls might be used, the verification would be incorrect. This patch prevents that erroneous fixup. Now, consider the interaction with the verifier in `kernel/bpf/verifier.c`. If the BPF program is offloaded, `check_unwind_insns` now rejects unwind instructions via `-ENOTSUPP`. This indicates a deliberate effort to control unwind functionality within offloaded contexts. Given these changes, should I consider fuzzing this area? Absolutely. BPF is explicitly listed under "Core Subsystems" in the criteria for identifying fuzzable code. The patch modifies code in both `kernel/bpf/verifier.c` and `include/linux/filter.h` (through `bpf_prog_can_unwind`, which is used in the x86 JIT compilation). `check_unwind_insns` and `do_jit` are reachable via standard fuzzing syscalls (specifically, the BPF syscalls, e.g., `BPF_PROG_LOAD`, `BPF_PROG_ATTACH`, etc.) and heavily targeted by syzkaller. Syzkaller loads BPF programs (which calls `bpf_check`), which in turn calls `check_unwind_insns`. Then, during JIT compilation, `bpf_int_jit_compile` and `do_jit` call `bpf_prog_can_unwind` and `emit_unwind_ret_addr`. At runtime, we have `bpf_throw`, exception callbacks, `unwind_exit`, and `bpf_unwind_target`. Thus, the whole flow is vulnerable to fuzzing. My primary concern, though, is with the `bpf_prog_can_unwind` inline function. It is in `include/linux/filter.h`, meaning it's an inlined function. I need to focus on where the non-static function `do_jit` calls it. From what I've seen, that's indeed the case here. This confirms that this is a good candidate for fuzzing. |
| 20/2 | 2026/10/21 07:48 | tool | grepper |
0mArgs:{
"Expression": "do_jit",
"PathPrefixes": [
"arch/x86/net/bpf_jit_comp.c"
]
}Results: {
"Output": "arch/x86/net/bpf_jit_comp.c=1812=static int emit_atomic_fetch_rmw(u8 **pprog, struct bpf_insn *insn, u32 dst_reg,\n--\narch/x86/net/bpf_jit_comp.c-1898- * of a fetching AND/OR/XOR. A sequence long enough to overflow this\narch/x86/net/bpf_jit_comp.c:1899: * field would first have to exceed BPF_MAX_INSN_SIZE, which do_jit()\narch/x86/net/bpf_jit_comp.c-1900- * rejects with -EFAULT before the image is used.\n--\narch/x86/net/bpf_jit_comp.c=2561=static int emit_unwind_ret_addr(u8 **pprog, u8 *ip)\n--\narch/x86/net/bpf_jit_comp.c-2576-\narch/x86/net/bpf_jit_comp.c:2577: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-2578-\t\t u8 *rw_image, int oldproglen, struct jit_context *ctx, bool jmp_padding)\n--\narch/x86/net/bpf_jit_comp.c=4894=struct bpf_prog *bpf_int_jit_compile(struct bpf_verifier_env *env, struct bpf_prog *prog)\n--\narch/x86/net/bpf_jit_comp.c-4987-\t\t\tpadding = true;\narch/x86/net/bpf_jit_comp.c:4988:\t\tproglen = do_jit(env, prog, addrs, image, rw_image, oldproglen,\narch/x86/net/bpf_jit_comp.c-4989-\t\t\t\t \u0026ctx, padding);\n"
} |
| 21/2 | 2026/10/21 07:48 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 16395 output: 37 thoughts: 710 Thoughts: **Analyzing BPF JIT Compilation and Verification Symbol Visibility** Okay, here's what's running through my head as I dissect this: First, `do_jit` is static, and it's called by `bpf_int_jit_compile`. Good to confirm that `bpf_int_jit_compile` has its own distinct symbol; that's the starting point. I'm going to look into `bpf_unwind_target` now. I need to know if it's got its own symbol, or if it's called some other way. Aha! Found it: `emit_call(&prog, bpf_unwind_target, ip)` in `emit_unwind_ret_addr`. Right, `bpf_unwind_target` is a plain C function, `static u64 bpf_unwind_target(u64 ret_addr)` in `arch/x86/net/bpf_jit_comp.c`. Since we're taking its address (`&bpf_unwind_target`) and passing it to `emit_call`, the compiler *has* to emit a distinct symbol for it, unless whole-program optimization inlines it, which is impossible here because the JIT is emitting calls to it at runtime. Now, let's look at `bpf_throw`. Where is that defined? Got it, `kernel/bpf/helpers.c`. And I should follow that thread, to verify its usage. Okay, let's trace from `bpf_throw` to `check_unwind_insns` in `kernel/bpf/verifier.c`. Aha, `check_unwind_insns` is static too. Let's check line 3439 of `kernel/bpf/verifier.c` to be certain. Yes, `static int check_unwind_insns(struct bpf_verifier_env *env)`. Who calls it? Right, `bpf_check` calls it, but `bpf_check` is potentially broad, although specific to BPF verification. The key question is whether static functions get symbols in `kallsyms`. In the Linux kernel, with `CONFIG_KALLSYMS=y`, static functions typically *do* appear in `kallsyms`, like `check_unwind_insns.isra.0` or just `check_unwind_insns` (unless the compiler inlines them, of course). Wait, the instruction about static inline functions is important here: "HANDLING STATIC INLINE FUNCTIONS IN HEADERS (.h)". Compiler-inlined static functions in headers *lack* distinct symbol addresses. They can't be targeted directly by symbol coverage filters, in my experience. The guidance suggests identifying non-static caller functions, which isn't the case here. Static functions in .c files, like `check_unwind_insns`, `do_jit`, and `bpf_unwind_target`, *do* often exist in `kallsyms` if they aren't inlined. The last question is whether `check_unwind_insns` can be inlined into `bpf_check`. I need to estimate the size of `check_unwind_insns` for a sanity check. |
| 22/2 | 2026/10/21 07:48 | tool | read-file |
0mArgs:{
"File": "kernel/bpf/verifier.c",
"FirstLine": 3435,
"LineCount": 40
}Results: {
"Contents": "3435:\t * 'call foo; unwind_goto pad' goes to the pad when foo left with unwind_exit.\n3436:\t * JITs don't emit a branch for it. unwind_exit finds the pad by its return\n3437:\t * address. So unwind_goto has to follow the call and nothing may jump to it.\n3438:\t */\n3439:\tstatic int check_unwind_insns(struct bpf_verifier_env *env)\n3440:\t{\n3441:\t\tstruct bpf_insn *insn = env-\u003eprog-\u003einsnsi;\n3442:\t\tbool seen = false;\n3443:\t\tint i;\n3444:\t\n3445:\t\tfor (i = 0; i \u003c env-\u003eprog-\u003elen; i++, insn++) {\n3446:\t\t\tif (bpf_is_unwind_exit(insn)) {\n3447:\t\t\t\tbpf_find_containing_subprog(env, i)-\u003ecan_unwind = true;\n3448:\t\t\t\tseen = true;\n3449:\t\t\t}\n3450:\t\t\tif (!bpf_is_unwind_goto(insn))\n3451:\t\t\t\tcontinue;\n3452:\t\t\tseen = true;\n3453:\t\t\tif (!i || !(bpf_pseudo_call(insn - 1) || bpf_is_callx(insn - 1))) {\n3454:\t\t\t\tverbose(env, \"unwind_goto at insn %d doesn't follow a call of a subprog\\n\",\n3455:\t\t\t\t\ti);\n3456:\t\t\t\treturn -EINVAL;\n3457:\t\t\t}\n3458:\t\t\tif (bpf_is_jump_target(env, i)) {\n3459:\t\t\t\tverbose(env, \"jump to unwind_goto at insn %d\\n\", i);\n3460:\t\t\t\treturn -EINVAL;\n3461:\t\t\t}\n3462:\t\t}\n3463:\t\tif (!seen)\n3464:\t\t\treturn 0;\n3465:\t\tif (!bpf_jit_supports_unwind() || bpf_prog_is_offloaded(env-\u003eprog-\u003eaux)) {\n3466:\t\t\tverbose(env, \"JIT does not support unwinding\\n\");\n3467:\t\t\treturn -ENOTSUPP;\n3468:\t\t}\n3469:\t\tenv-\u003eprog-\u003ejit_required = 1;\n3470:\t\tenv-\u003eprog-\u003eaux-\u003ecan_unwind = env-\u003esubprog_info[0].can_unwind;\n3471:\t\treturn 0;\n3472:\t}\n3473:\t\n3474:\t/*\n"
} |
| 23/2 | 2026/10/21 07:48 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 18561 output: 37 thoughts: 1210 Thoughts: **Analyzing BPF Unwinding for Fuzzing Focus** Okay, let's break this down for a fuzzing strategy. The core idea is to identify the most relevant functions to target for syzkaller. First, I need to understand the role of `bpf_unwind_target`. From my analysis, it looks like this is the function the JIT'd code calls when using `emit_unwind_ret_addr`. `emit_unwind_ret_addr` is critical because it's used by `do_jit`. Since `bpf_unwind_target` is *static*, it's likely its address is emitted directly into JIT code. The compiler *must* be generating a symbol for `bpf_unwind_target` so I can target it. Now, which callers exercise `bpf_prog_can_unwind`? Checking those references is important. It is only called in `arch/x86/net/bpf_jit_comp.c`. Both `do_jit` and, in turn, `bpf_int_jit_compile` use this. I'm wondering if `bpf_int_jit_compile` is used everywhere. This helps to determine if its a good target or not. Because `bpf_int_jit_compile` is called during BPF JIT compilation when a BPF program or subprog is JIT-compiled, the BPF program loading is a good candidate, but what about the generality of `bpf_int_jit_compile`? BPF program loading is not like `kmalloc` or `page_fault`. Now, I'm thinking about the focus symbols principle in section 4. I need to avoid ubiquitous functions and target functions that implement specific logic. This is critical for preventing fuzzing dilution. I need to focus on functions that implement the logic being added or altered. I see three primary candidates. 1. `check_unwind_insns` in `kernel/bpf/verifier.c` was directly modified. 2. `bpf_unwind_target` in `arch/x86/net/bpf_jit_comp.c` is the runtime function executed during unwind_exit in BPF programs! 3. `emit_unwind_ret_addr` in `arch/x86/net/bpf_jit_comp.c` that emits code for `unwind_exit`! Since it's *static*, this is where it's important to look for the caller. Let me examine `emit_unwind_ret_addr`. The code shows the following: ```c if (src_reg == BPF_UNWIND_EXIT && bpf_prog_can_unwind(bpf_prog) && emit_unwind_ret_addr(&prog, ip)) return -EINVAL; ``` Now, I will see if `emit_unwind_ret_addr` can be static inline or static. It is `static int emit_unwind_ret_addr(...)`. I'll check `bpf_throw` in `kernel/bpf/helpers.c` to understand its relation to exception callbacks and unwinding. |
| 24/2 | 2026/10/21 07:48 | tool | read-file |
0mArgs:{
"File": "kernel/bpf/helpers.c",
"FirstLine": 3425,
"LineCount": 35
}Results: {
"Contents": "3425:\t\tctx-\u003esp = sp;\n3426:\t\tctx-\u003ebp = bp;\n3427:\t\treturn false;\n3428:\t}\n3429:\t\n3430:\t__bpf_kfunc void bpf_throw(u64 cookie)\n3431:\t{\n3432:\t\tstruct bpf_throw_ctx ctx = {};\n3433:\t\n3434:\t\tarch_bpf_stack_walk(bpf_stack_walker, \u0026ctx);\n3435:\t\tWARN_ON_ONCE(!ctx.aux);\n3436:\t\tif (ctx.aux)\n3437:\t\t\tWARN_ON_ONCE(!ctx.aux-\u003eexception_boundary);\n3438:\t\tWARN_ON_ONCE(!ctx.bp);\n3439:\t\tWARN_ON_ONCE(!ctx.cnt);\n3440:\t\t/*\n3441:\t\t * Prevent KASAN false positives for CONFIG_KASAN_STACK by unpoisoning\n3442:\t\t * deeper stack depths than ctx.sp as we do not return from bpf_throw,\n3443:\t\t * which skips compiler generated instrumentation to do the same. Some\n3444:\t\t * architectures cannot recover sp while unwinding, so fall back to bp.\n3445:\t\t */\n3446:\t\tkasan_unpoison_task_stack_below((void *)(long)(ctx.sp ?: ctx.bp));\n3447:\t\tctx.aux-\u003ebpf_exception_cb(cookie, ctx.sp + ctx.aux-\u003estack_arg_sp_adjust, ctx.bp, 0, 0);\n3448:\t\tWARN(1, \"A call to BPF exception callback should never return\\n\");\n3449:\t}\n3450:\t\n3451:\t__bpf_kfunc int bpf_wq_init(struct bpf_wq *wq, void *p__const_map, unsigned int flags)\n3452:\t{\n3453:\t\tstruct bpf_async_kern *async = (struct bpf_async_kern *)wq;\n3454:\t\tstruct bpf_map *map = p__const_map;\n3455:\t\n3456:\t\tBUILD_BUG_ON(sizeof(struct bpf_async_kern) \u003e sizeof(struct bpf_wq));\n3457:\t\tBUILD_BUG_ON(__alignof__(struct bpf_async_kern) != __alignof__(struct bpf_wq));\n3458:\t\n3459:\t\tif (flags)\n"
} |
| 25/2 | 2026/10/21 07:48 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 21161 output: 23 thoughts: 579 Thoughts: **My Analysis of BPF Exception Handling and Unwinding** Okay, let's break this down. Line 3447-3448 of `bpf_throw`... the exception callback is called, which should *never* return, and that makes sense given the intention of the function. The selftest code highlights an interesting point with `throws_cb`. It seems we're ensuring that the exception callback has a name defined in BTF, and that it can return (or rather, *not* return) from an exception. The function, when it calls `bpf_throw`, will trigger the exception callback and unwind the stack. The comment in `include/linux/filter.h` is crucial here. It explicitly states the difference in how unwinding is handled in the main program versus an extension (via `freplace` or tail calls). Essentially, a callback returns *up* the call stack, back to a caller that might not be expecting that kind of exception-based return. This context clarifies the need for `bpf_prog_can_unwind`. If there's an `exception_cb` associated with the program, then it *cannot* unwind. It has to be an exceptional case. In other scenarios, it is either an extension or a subprog, and it *can* unwind. So, `bpf_throw`, exception callbacks, and unwinding are tightly coupled. Now, what's really important is to figure out the configuration requirements. To enable this, I need to investigate the Kconfig options. Specifically, I'll need to check what guards `bpf_int_jit_compile` in `arch/x86/net/bpf_jit_comp.c`, which gives hints regarding whether JIT is enabled. I also need to find out what Kconfig options govern BPF unwinding and the BPF verifier as a whole. Searching for `bpf_jit_supports_unwind` or general BPF JIT options should get me there. This will give me a clear picture of what needs to be enabled for this exception handling mechanism to function correctly in a given kernel configuration. |
| 26/2 | 2026/10/21 07:49 | tool | grepper |
0mArgs:{
"Expression": "bpf_jit_supports_unwind"
}Results: {
"Output": "arch/arm64/net/bpf_jit_comp.c=2550=bool bpf_jit_supports_kfunc_ret_reg_pair(void)\n--\narch/arm64/net/bpf_jit_comp.c-2554-\narch/arm64/net/bpf_jit_comp.c:2555:bool bpf_jit_supports_unwind(void)\narch/arm64/net/bpf_jit_comp.c-2556-{\n--\narch/x86/net/bpf_jit_comp.c=5119=bool bpf_jit_supports_kfunc_ret_reg_pair(void)\n--\narch/x86/net/bpf_jit_comp.c-5123-\narch/x86/net/bpf_jit_comp.c:5124:bool bpf_jit_supports_unwind(void)\narch/x86/net/bpf_jit_comp.c-5125-{\n--\ninclude/linux/filter.h=1282=bool bpf_jit_supports_kfunc_ret_reg_pair(void);\ninclude/linux/filter.h:1283:bool bpf_jit_supports_unwind(void);\ninclude/linux/filter.h-1284-bool bpf_jit_supports_stack_args(void);\n--\nkernel/bpf/core.c=3397=bool __weak bpf_jit_supports_kfunc_ret_reg_pair(void)\n--\nkernel/bpf/core.c-3402-/* unwind_goto and unwind_exit */\nkernel/bpf/core.c:3403:bool __weak bpf_jit_supports_unwind(void)\nkernel/bpf/core.c-3404-{\n--\nkernel/bpf/verifier.c=3439=static int check_unwind_insns(struct bpf_verifier_env *env)\n--\nkernel/bpf/verifier.c-3464-\t\treturn 0;\nkernel/bpf/verifier.c:3465:\tif (!bpf_jit_supports_unwind() || bpf_prog_is_offloaded(env-\u003eprog-\u003eaux)) {\nkernel/bpf/verifier.c-3466-\t\tverbose(env, \"JIT does not support unwinding\\n\");\n"
} |
| 27/2 | 2026/10/21 07:49 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 22822 output: 35 thoughts: 38 Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience: **Investigating the BPF JIT Compilation Dependency** Right, let's dive in. I need to figure out what's enabling `arch/x86/net/bpf_jit_comp.c`. My initial instinct is to check the `arch/x86/net/Makefile`. That's the logical place to look for compilation rules and dependencies related to that specific architecture's networking code. Hopefully, the relevant Kconfig options or a conditional compilation check will be immediately apparent there. I'm expecting to find a straightforward dependency, likely tied to a performance optimization or a feature enabling a more efficient BPF execution on x86. I'll be looking for something like an `#ifdef` or a Kconfig symbol evaluation, or perhaps even a more convoluted multi-layered dependency chain. It's usually pretty clear once you know where to look. Time to get to it. |
| 28/2 | 2026/10/21 07:49 | tool | grepper |
0mArgs:{
"Expression": "bpf_jit_comp",
"PathPrefixes": [
"arch/x86/net/"
]
}Results: {
"Output": "arch/x86/net/Makefile=6=ifeq ($(CONFIG_X86_32),y)\narch/x86/net/Makefile:7: obj-$(CONFIG_BPF_JIT) += bpf_jit_comp32.o\narch/x86/net/Makefile-8-else\narch/x86/net/Makefile:9: obj-$(CONFIG_BPF_JIT) += bpf_jit_comp.o bpf_timed_may_goto.o\narch/x86/net/Makefile-10-endif\n"
} |
| 29/2 | 2026/10/21 07:49 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 23249 output: 29 thoughts: 56 Thoughts: Here's my summary, as the expert: **Delving into BPF JIT Compilation** Okay, so `CONFIG_BPF_JIT` on x86_64, that's what's pulling in `bpf_jit_comp.o`. Right, right. Now, if I remember correctly, the dependencies here can be tricky, so let's check what's going on with `CONFIG_BPF_SYSCALL` – what's enabling *that* part of the BPF infrastructure? I need to quickly refresh my memory on the interactions. I'll head straight to `kernel/bpf/Makefile`, that's where the critical build configuration dependencies are defined. Hopefully, it's laid out in a clear way. |
| 30/2 | 2026/10/21 07:49 | tool | grepper |
0mArgs:{
"Expression": "verifier\\.o",
"PathPrefixes": [
"kernel/bpf/"
]
}Results: {
"Output": "kernel/bpf/Makefile=7=CFLAGS_core.o += -Wno-override-init $(cflags-nogcse-yy)\nkernel/bpf/Makefile-8-\nkernel/bpf/Makefile:9:obj-$(CONFIG_BPF_SYSCALL) += syscall.o verifier.o inode.o helpers.o tnum.o cnum.o log.o token.o liveness.o const_fold.o diagnostics.o loops.o scev.o\nkernel/bpf/Makefile-10-obj-$(CONFIG_BPF_SYSCALL) += bpf_iter.o map_iter.o task_iter.o prog_iter.o link_iter.o\n"
} |
| 31/2 | 2026/10/21 07:49 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 23671 output: 32 thoughts: 46 Thoughts: Here's my thought process, as if I were considering this issue: **Delving into BPF Compilation Dependencies** Okay, so `CONFIG_BPF_SYSCALL` is triggering the compilation of `verifier.o`. That's a key piece. Now, I need to figure out the dependencies related to `BPF_JIT`. Since the Just-In-Time compiler is fundamental to BPF performance, I'm guessing its configuration and dependencies will be defined in either the `init/Kconfig` or the `kernel/bpf/Kconfig` files. I need to see what other configs enable or affect the JIT, how it interfaces with the syscall, and if there are any subtle interactions I might be overlooking. Time to open those files and see what's what. |
| 32/2 | 2026/10/21 07:49 | tool | grepper |
0mArgs:{
"Expression": "config BPF_JIT\\b|config BPF_SYSCALL\\b"
}Results: {
"Output": "kernel/bpf/Kconfig=29=menu \"BPF subsystem\"\nkernel/bpf/Kconfig-30-\nkernel/bpf/Kconfig:31:config BPF_SYSCALL\nkernel/bpf/Kconfig-32-\tbool \"Enable bpf() system call\"\n--\nkernel/bpf/Kconfig-45-\nkernel/bpf/Kconfig:46:config BPF_JIT\nkernel/bpf/Kconfig-47-\tbool \"Enable BPF Just In Time compiler\"\n"
} |
| 33/2 | 2026/10/21 07:49 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 24055 output: 34 thoughts: 22 Thoughts: Here's my summary, as if I were thinking these thoughts: **Examining the BPF Kernel Configuration Options** Okay, let's dive into the `kernel/bpf/Kconfig` file. I'm going to focus specifically on the configuration options defined around lines 30 through 60. I need to get a better handle on the granular controls available for BPF within this particular kernel configuration. I'm especially interested in how the different features are exposed to the user. I'm assuming there will be some basic enabling/disabling of the whole BPF subsystem, which I'll be looking for first, but then I'm sure there's got to be more detailed, feature-specific controls, probably gated on other dependencies. This area of the Kconfig file should give me a good, concise overview of what's *configurable* at compile time. It will be helpful to know precisely which capabilities the user can enable or disable. I will look for any clues about the relationships between the features. |
| 34/2 | 2026/10/21 07:49 | tool | read-file |
0mArgs:{
"File": "kernel/bpf/Kconfig",
"FirstLine": 30,
"LineCount": 40
}Results: {
"Contents": " 30:\t\n 31:\tconfig BPF_SYSCALL\n 32:\t\tbool \"Enable bpf() system call\"\n 33:\t\tselect BPF\n 34:\t\tselect IRQ_WORK\n 35:\t\tselect NEED_TASKS_RCU\n 36:\t\tselect TASKS_TRACE_RCU\n 37:\t\tselect BINARY_PRINTF\n 38:\t\tselect NET_SOCK_MSG if NET\n 39:\t\tselect NET_XGRESS if NET\n 40:\t\tselect PAGE_POOL if NET\n 41:\t\tdefault n\n 42:\t\thelp\n 43:\t\t Enable the bpf() system call that allows to manipulate BPF programs\n 44:\t\t and maps via file descriptors.\n 45:\t\n 46:\tconfig BPF_JIT\n 47:\t\tbool \"Enable BPF Just In Time compiler\"\n 48:\t\tdepends on BPF\n 49:\t\tdepends on HAVE_CBPF_JIT || HAVE_EBPF_JIT\n 50:\t\tselect EXECMEM\n 51:\t\thelp\n 52:\t\t BPF programs are normally handled by a BPF interpreter. This option\n 53:\t\t allows the kernel to generate native code when a program is loaded\n 54:\t\t into the kernel. This will significantly speed-up processing of BPF\n 55:\t\t programs.\n 56:\t\n 57:\t\t Note, an admin should enable this feature changing:\n 58:\t\t /proc/sys/net/core/bpf_jit_enable\n 59:\t\t /proc/sys/net/core/bpf_jit_harden (optional)\n 60:\t\t /proc/sys/net/core/bpf_jit_kallsyms (optional)\n 61:\t\n 62:\tconfig BPF_JIT_ALWAYS_ON\n 63:\t\tbool \"Permanently enable BPF JIT and remove BPF interpreter\"\n 64:\t\tdepends on BPF_SYSCALL \u0026\u0026 HAVE_EBPF_JIT \u0026\u0026 BPF_JIT\n 65:\t\thelp\n 66:\t\t Enables BPF JIT and removes BPF interpreter to avoid speculative\n 67:\t\t execution of BPF instructions by the interpreter.\n 68:\t\n 69:\t\t When CONFIG_BPF_JIT_ALWAYS_ON is enabled, /proc/sys/net/core/bpf_jit_enable\n"
} |
| 35/2 | 2026/10/21 07:49 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 24935 output: 45 thoughts: 59 Thoughts: Okay, here's my assessment of the situation: **Investigating BPF JIT and Unwinding** Right, so I'm thinking about BPF and specifically the JIT compiler. I know that `BPF_SYSCALL` and `BPF_JIT` are the primary flags I need to consider when I'm dealing with kernel configuration and BPF. They are the initial areas to explore. Now, I'm trying to figure out if there are any related kernel configurations, specifically around exception handling or unwinding – especially if they impact the BPF JIT. I need to be thorough. I'll need to double check any configurations related to exception handling and stack unwinding. Given my platform (x86), let me see how `bpf_jit_supports_unwind` is handled. Time to dig into the relevant code. |
| 36/2 | 2026/10/21 07:49 | tool | read-file |
0mArgs:{
"File": "arch/x86/net/bpf_jit_comp.c",
"FirstLine": 5120,
"LineCount": 20
}Results: {
"Contents": "5120:\t{\n5121:\t\treturn true;\n5122:\t}\n5123:\t\n5124:\tbool bpf_jit_supports_unwind(void)\n5125:\t{\n5126:\t\treturn true;\n5127:\t}\n5128:\t\n5129:\tconst struct bpf_jit_arg_abi *bpf_jit_arg_abi(void)\n5130:\t{\n5131:\t\treturn \u0026x86_arg_abi;\n5132:\t}\n5133:\t\n5134:\tbool bpf_jit_supports_stack_args(void)\n5135:\t{\n5136:\t\treturn true;\n5137:\t}\n5138:\t\n5139:\tbool bpf_jit_supports_arena_args(void)\n"
} |
| 37/2 | 2026/10/21 07:49 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 25466 output: 23 thoughts: 40 Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience, presented in the first person: **Navigating the BPF JIT and Offload Landscape** Right, `bpf_jit_supports_unwind` on x86… that's straightforward enough; it just returns `true`. No surprises there. But, I need to understand the wider context. Now I'm thinking, I need to check how the bpf is being handled in order to fully comprehend it. The more interesting question is around whether the JIT is in use or offloaded to a hardware accelerator. Specifically, the function I need to look into is `bpf_prog_is_offloaded`. Where exactly is that thing defined? I need to trace its implementation and understand the logic that determines if a BPF program has been pushed onto an accelerator. That's the key to understanding the performance characteristics in this scenario. I need to know how the kernel is making that determination. |
| 38/2 | 2026/10/21 07:49 | tool | grepper |
0mArgs:{
"Expression": "bpf_prog_is_offloaded"
}Results: {
"Output": "drivers/net/netdevsim/bpf.c=92=static void nsim_prog_set_loaded(struct bpf_prog *prog, bool loaded)\n--\ndrivers/net/netdevsim/bpf.c-95-\ndrivers/net/netdevsim/bpf.c:96:\tif (!prog || !bpf_prog_is_offloaded(prog-\u003eaux))\ndrivers/net/netdevsim/bpf.c-97-\t\treturn;\n--\ndrivers/net/netdevsim/bpf.c=308=nsim_setup_prog_hw_checks(struct netdevsim *ns, struct netdev_bpf *bpf)\n--\ndrivers/net/netdevsim/bpf.c-314-\ndrivers/net/netdevsim/bpf.c:315:\tif (!bpf_prog_is_offloaded(bpf-\u003eprog-\u003eaux)) {\ndrivers/net/netdevsim/bpf.c-316-\t\tNSIM_EA(bpf-\u003eextack, \"xdpoffload of non-bound program\");\n--\ninclude/linux/bpf.h=3828=static inline bool bpf_prog_is_dev_bound(const struct bpf_prog_aux *aux)\n--\ninclude/linux/bpf.h-3832-\ninclude/linux/bpf.h:3833:static inline bool bpf_prog_is_offloaded(const struct bpf_prog_aux *aux)\ninclude/linux/bpf.h-3834-{\n--\ninclude/linux/bpf.h=3895=static inline bool bpf_prog_is_dev_bound(const struct bpf_prog_aux *aux)\n--\ninclude/linux/bpf.h-3899-\ninclude/linux/bpf.h:3900:static inline bool bpf_prog_is_offloaded(struct bpf_prog_aux *aux)\ninclude/linux/bpf.h-3901-{\n--\ninclude/linux/bpf_verifier.h=1446=static inline u32 bpf_prog_stack_limit(const struct bpf_prog *prog)\n--\ninclude/linux/bpf_verifier.h-1448-\t/* an offloaded program never runs on the host JIT, whatever it supports */\ninclude/linux/bpf_verifier.h:1449:\tif (prog-\u003ejit_requested \u0026\u0026 !bpf_prog_is_offloaded(prog-\u003eaux) \u0026\u0026\ninclude/linux/bpf_verifier.h-1450-\t bpf_jit_supports_large_stack() \u0026\u0026 bpf_jit_supports_subprog_tailcalls())\n--\nkernel/bpf/core.c=2731=struct bpf_prog *__bpf_prog_select_runtime(struct bpf_verifier_env *env, struct bpf_prog *fp,\n--\nkernel/bpf/core.c-2752-\t */\nkernel/bpf/core.c:2753:\tif (!bpf_prog_is_offloaded(fp-\u003eaux)) {\nkernel/bpf/core.c-2754-\t\t*err = bpf_prog_alloc_jited_linfo(fp);\n--\nkernel/bpf/fixups.c=602=static int verifier_remove_insns(struct bpf_verifier_env *env, u32 off, u32 cnt)\n--\nkernel/bpf/fixups.c-610-\nkernel/bpf/fixups.c:611:\tif (bpf_prog_is_offloaded(env-\u003eprog-\u003eaux))\nkernel/bpf/fixups.c-612-\t\tbpf_prog_offload_remove_insns(env, off, cnt);\n--\nkernel/bpf/fixups.c=657=void bpf_opt_hard_wire_dead_code_branches(struct bpf_verifier_env *env)\n--\nkernel/bpf/fixups.c-690-\nkernel/bpf/fixups.c:691:\t\tif (bpf_prog_is_offloaded(env-\u003eprog-\u003eaux))\nkernel/bpf/fixups.c-692-\t\t\tbpf_prog_offload_replace_insn(env, i, \u0026ja);\n--\nkernel/bpf/fixups.c=931=int bpf_convert_ctx_accesses(struct bpf_verifier_env *env)\n--\nkernel/bpf/fixups.c-1011-\nkernel/bpf/fixups.c:1012:\tif (bpf_prog_is_offloaded(env-\u003eprog-\u003eaux))\nkernel/bpf/fixups.c-1013-\t\treturn 0;\n--\nkernel/bpf/fixups.c=1705=int bpf_fixup_call_args(struct bpf_verifier_env *env)\n--\nkernel/bpf/fixups.c-1726-\tif (env-\u003eprog-\u003ejit_requested \u0026\u0026\nkernel/bpf/fixups.c:1727:\t !bpf_prog_is_offloaded(env-\u003eprog-\u003eaux)) {\nkernel/bpf/fixups.c-1728-\t\terr = bpf_jit_subprogs(env);\n--\nkernel/bpf/offload.c=195=static int __bpf_prog_dev_bound_init(struct bpf_prog *prog, struct net_device *netdev)\n--\nkernel/bpf/offload.c-211-\t */\nkernel/bpf/offload.c:212:\tif (bpf_prog_is_offloaded(prog-\u003eaux) \u0026\u0026 (!ondev || !ondev-\u003eoffdev)) {\nkernel/bpf/offload.c-213-\t\terr = -EINVAL;\n--\nkernel/bpf/offload.c=284=int bpf_prog_dev_bound_inherit(struct bpf_prog *new_prog, struct bpf_prog *old_prog)\n--\nkernel/bpf/offload.c-290-\nkernel/bpf/offload.c:291:\tif (bpf_prog_is_offloaded(old_prog-\u003eaux))\nkernel/bpf/offload.c-292-\t\treturn -EINVAL;\n--\nkernel/bpf/offload.c=710=static bool __bpf_offload_dev_match(struct bpf_prog *prog,\n--\nkernel/bpf/offload.c-723-\t\treturn true;\nkernel/bpf/offload.c:724:\tif (!bpf_prog_is_offloaded(prog-\u003eaux))\nkernel/bpf/offload.c-725-\t\treturn false;\n--\nkernel/bpf/offload.c=745=bool bpf_prog_dev_bound_match(const struct bpf_prog *lhs, const struct bpf_prog *rhs)\n--\nkernel/bpf/offload.c-748-\nkernel/bpf/offload.c:749:\tif (bpf_prog_is_offloaded(lhs-\u003eaux) != bpf_prog_is_offloaded(rhs-\u003eaux))\nkernel/bpf/offload.c-750-\t\treturn false;\n--\nkernel/bpf/offload.c=841=int bpf_dev_bound_kfunc_check(struct bpf_verifier_log *log,\n--\nkernel/bpf/offload.c-848-\nkernel/bpf/offload.c:849:\tif (bpf_prog_is_offloaded(prog_aux)) {\nkernel/bpf/offload.c-850-\t\tbpf_log(log, \"metadata kfuncs can't be offloaded\\n\");\n--\nkernel/bpf/syscall.c=2373=static int find_prog_type(enum bpf_prog_type type, struct bpf_prog *prog)\n--\nkernel/bpf/syscall.c-2383-\nkernel/bpf/syscall.c:2384:\tif (!bpf_prog_is_offloaded(prog-\u003eaux))\nkernel/bpf/syscall.c-2385-\t\tprog-\u003eaux-\u003eops = ops;\n--\nkernel/bpf/syscall.c=2685=bool bpf_prog_get_ok(struct bpf_prog *prog,\n--\nkernel/bpf/syscall.c-2693-\t\treturn false;\nkernel/bpf/syscall.c:2694:\tif (bpf_prog_is_offloaded(prog-\u003eaux) \u0026\u0026 !attach_drv)\nkernel/bpf/syscall.c-2695-\t\treturn false;\n--\nkernel/bpf/syscall.c=5165=static int bpf_prog_get_info_by_fd(struct file *file,\n--\nkernel/bpf/syscall.c-5260-\nkernel/bpf/syscall.c:5261:\tif (bpf_prog_is_offloaded(prog-\u003eaux)) {\nkernel/bpf/syscall.c-5262-\t\terr = bpf_prog_offload_info_fill(\u0026info, prog);\n--\nkernel/bpf/verifier.c=440=static int bpf_compute_subprog_ret_regs(struct bpf_verifier_env *env)\n--\nkernel/bpf/verifier.c-446-\nkernel/bpf/verifier.c:447:\tif (!env-\u003eprog-\u003ejit_requested || bpf_prog_is_offloaded(env-\u003eprog-\u003eaux))\nkernel/bpf/verifier.c-448-\t\treturn 0;\n--\nkernel/bpf/verifier.c=3439=static int check_unwind_insns(struct bpf_verifier_env *env)\n--\nkernel/bpf/verifier.c-3464-\t\treturn 0;\nkernel/bpf/verifier.c:3465:\tif (!bpf_jit_supports_unwind() || bpf_prog_is_offloaded(env-\u003eprog-\u003eaux)) {\nkernel/bpf/verifier.c-3466-\t\tverbose(env, \"JIT does not support unwinding\\n\");\n--\nkernel/bpf/verifier.c=20497=static int do_check(struct bpf_verifier_env *env)\n--\nkernel/bpf/verifier.c-20625-\nkernel/bpf/verifier.c:20626:\t\tif (bpf_prog_is_offloaded(env-\u003eprog-\u003eaux)) {\nkernel/bpf/verifier.c-20627-\t\t\terr = bpf_prog_offload_verify_insn(env, env-\u003einsn_idx,\n--\nkernel/bpf/verifier.c=20938=static int check_map_prog_compatibility(struct bpf_verifier_env *env,\n--\nkernel/bpf/verifier.c-20966-\nkernel/bpf/verifier.c:20967:\tif ((bpf_prog_is_offloaded(prog-\u003eaux) || bpf_map_is_offloaded(map)) \u0026\u0026\nkernel/bpf/verifier.c-20968-\t !bpf_offload_prog_map_match(prog, map)) {\n--\nkernel/bpf/verifier.c=23783=int bpf_check(struct bpf_prog **prog, union bpf_attr *attr, bpfptr_t uattr,\n--\nkernel/bpf/verifier.c-23938-\nkernel/bpf/verifier.c:23939:\tif (bpf_prog_is_offloaded(env-\u003eprog-\u003eaux)) {\nkernel/bpf/verifier.c-23940-\t\tret = bpf_prog_offload_verifier_prep(env-\u003eprog);\n--\nkernel/bpf/verifier.c-24023-\nkernel/bpf/verifier.c:24024:\tif (ret == 0 \u0026\u0026 bpf_prog_is_offloaded(env-\u003eprog-\u003eaux))\nkernel/bpf/verifier.c-24025-\t\tret = bpf_prog_offload_finalize(env);\n--\nkernel/bpf/verifier.c-24064-\t */\nkernel/bpf/verifier.c:24065:\tif (ret == 0 \u0026\u0026 !bpf_prog_is_offloaded(env-\u003eprog-\u003eaux)) {\nkernel/bpf/verifier.c-24066-\t\tret = bpf_opt_subreg_zext_lo32_rnd_hi32(env, attr);\n--\nnet/core/dev.c=10421=static int dev_xdp_install(struct net_device *dev, enum bpf_xdp_mode mode,\n--\nnet/core/dev.c-10438-\t\t}\nnet/core/dev.c:10439:\t\tif (!offload \u0026\u0026 bpf_prog_is_offloaded(prog-\u003eaux)) {\nnet/core/dev.c-10440-\t\t\tNL_SET_ERR_MSG(extack, \"Using offloaded program without HW_MODE flag is not supported\");\n--\nnet/core/filter.c=9558=static bool xdp_is_valid_access(int off, int size,\n--\nnet/core/filter.c-9570-\tif (type == BPF_WRITE) {\nnet/core/filter.c:9571:\t\tif (bpf_prog_is_offloaded(prog-\u003eaux)) {\nnet/core/filter.c-9572-\t\t\tswitch (off) {\n"
} |
| 39/2 | 2026/10/21 07:49 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 29118 output: 25 thoughts: 1888 Thoughts: **Focusing on Exception Callbacks and Unwinding in BPF JIT Compilation** Okay, so this patch is all about how BPF programs behave when they're offloaded, particularly with exception callbacks that involve unwinding. My initial thought is that the `bpf_prog_is_offloaded` flag might be the key, and it looks like netdevsim is a relevant case for this. What really matters are the changes touching `kernel/bpf/verifier.c`, `include/linux/filter.h`, and `arch/x86/net/bpf_jit_comp.c`. The core of the issue seems to be how the JIT compiler handles `unwind_exit` instructions in the context of exception callbacks. Specifically, `bpf_prog_can_unwind` is the function that determines whether `emit_unwind_ret_addr` is generated. It's skipping the generation of unwinding return addresses when `prog->aux->exception_cb` is true. This is a behavioral change because previously exception callbacks *with* `unwind_exit` had unwinding code emitted. Now it doesn't, treating `unwind_exit` like a normal exit. This is a subtle but important change in how the JIT code is generated. The verifier, `check_unwind_insns()`, is also involved. It's now rejecting offloaded programs containing unwind instructions, which is connected to this JIT behavior. The big question now is, is this code reachable? The answer is yes, given that BPF programs are loaded and executed with `sys_bpf`. Now, let's nail down what functions are relevant to the fuzzing focus. I know I need to be precise here, and avoid any functions that are part of the 'ubiquitous lifecycle hot-paths'. The candidates are, of course, the ones modified and directly related to the new behavior. * `check_unwind_insns`: This verifier function is key. It's directly modified, checks unwind instructions, and sets crucial flags like `can_unwind`. It's not *ubiquitous*, as it's only called when loading BPF programs which use unwind instructions. **Include.** * `emit_unwind_ret_addr`: The JIT helper is critical and its generation depends on `bpf_prog_can_unwind`. Though it is static, it could be inlined, but it's only called in one place in `do_jit`. **Include.** * `bpf_unwind_target`: The runtime target function called by the JIT-emitted code for unwinding. *Crucially*, its address is taken, so it cannot be inlined. It must exist as a real function, and is a strong candidate. **Include.** * `bpf_throw`: The kfunc that throws the exception. It's the mechanism that invokes exception callbacks, so it's directly relevant to the core of the patch. It's a global kfunc, which is good. **Include.** I had to consider `bpf_check_attach_target` and `bpf_mark_subprog_exc_cb`, but they aren't the primary focus. The verifier, `bpf_check`, is too general. Yes, every BPF program load goes through it, but `check_unwind_insns` is much more specific to unwinding and is modified by the patch. No point in diluting the fuzzing focus. Now I need to check if there are other functions involved in exception callbacks or unwinding - like `bpf_mark_subprog_exc_cb`. |
| 40/2 | 2026/10/21 07:49 | tool | grepper |
0mArgs:{
"Expression": "bpf_mark_subprog_exc_cb"
}Results: {
"Output": "include/linux/bpf_verifier.h=1982=struct bpf_kfunc_desc_tab {\n--\ninclude/linux/bpf_verifier.h-1997-/* Functions exported from verifier.c, used by fixups.c */\ninclude/linux/bpf_verifier.h:1998:void bpf_mark_subprog_exc_cb(struct bpf_verifier_env *env, int subprog);\ninclude/linux/bpf_verifier.h-1999-bool bpf_allow_tail_call_in_subprogs(struct bpf_verifier_env *env);\n--\nkernel/bpf/fixups.c=1834=int bpf_do_misc_fixups(struct bpf_verifier_env *env)\n--\nkernel/bpf/fixups.c-1865-\t\t/* Don't update insn_cnt, as add_hidden_subprog always appends insns */\nkernel/bpf/fixups.c:1866:\t\tbpf_mark_subprog_exc_cb(env, env-\u003eexception_callback_subprog);\nkernel/bpf/fixups.c-1867-\t}\n--\nkernel/bpf/verifier.c=472=const char *bpf_subprog_name(const struct bpf_verifier_env *env, int subprog)\n--\nkernel/bpf/verifier.c-482-\nkernel/bpf/verifier.c:483:void bpf_mark_subprog_exc_cb(struct bpf_verifier_env *env, int subprog)\nkernel/bpf/verifier.c-484-{\n--\nkernel/bpf/verifier.c=3198=static int add_subprogs(struct bpf_verifier_env *env)\n--\nkernel/bpf/verifier.c-3266-\t\t\tenv-\u003eexception_callback_subprog = i;\nkernel/bpf/verifier.c:3267:\t\t\tbpf_mark_subprog_exc_cb(env, i);\nkernel/bpf/verifier.c-3268-\t\t\tbreak;\n"
} |
| 41/2 | 2026/10/21 07:49 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 32347 output: 38 thoughts: 256 Thoughts: **BPF Exception Callback Investigation** Okay, let's dive into this `bpf_mark_subprog_exc_cb` function. It's non-static, so it's exported and I see it's used in `fixups.c`. Excellent! It looks like it marks something called `is_exception_cb` as `true` and ultimately sets `prog->aux->exception_cb`! Ah, this is precisely the field that's checked in the patch within `bpf_prog_can_unwind`. That `if (prog->aux->exception_cb) return false;` is right on point. This `bpf_mark_subprog_exc_cb` function is a great find! Now, let's explore `kernel/bpf/fixups.c` a bit further. I want to see if there are other places where this `exception_cb` is handled. Let me check lines 1489-1490 of the file... ah, there it is. In `jit_subprogs`, I see `func[i]->aux->exception_cb = env->subprog_info[i].is_exception_cb;`. I should probably check that `jit_subprogs` function more closely. |
| 42/2 | 2026/10/21 07:50 | tool | read-file |
0mArgs:{
"File": "kernel/bpf/fixups.c",
"FirstLine": 1480,
"LineCount": 25
}Results: {
"Contents": "1480:\t\t\t\t BPF_MODE(insn-\u003ecode) == BPF_PROBE_MEM32)\n1481:\t\t\t\t\tnum_exentries++;\n1482:\t\t\t\tif (BPF_CLASS(insn-\u003ecode) == BPF_STX \u0026\u0026\n1483:\t\t\t\t BPF_MODE(insn-\u003ecode) == BPF_PROBE_ATOMIC)\n1484:\t\t\t\t\tnum_exentries++;\n1485:\t\t\t\tif (bpf_is_unwind_goto(insn))\n1486:\t\t\t\t\tnum_exentries++;\n1487:\t\t\t}\n1488:\t\t\tfunc[i]-\u003eaux-\u003enum_exentries = num_exentries;\n1489:\t\t\tfunc[i]-\u003eaux-\u003etail_call_reachable = env-\u003esubprog_info[i].tail_call_reachable;\n1490:\t\t\tfunc[i]-\u003eaux-\u003eexception_cb = env-\u003esubprog_info[i].is_exception_cb;\n1491:\t\t\tfunc[i]-\u003eaux-\u003echanges_pkt_data = env-\u003esubprog_info[i].changes_pkt_data;\n1492:\t\t\tfunc[i]-\u003eaux-\u003emight_sleep = env-\u003esubprog_info[i].might_sleep;\n1493:\t\t\tfunc[i]-\u003eaux-\u003ecan_unwind = env-\u003esubprog_info[i].can_unwind;\n1494:\t\t\tfunc[i]-\u003eaux-\u003etoken = prog-\u003eaux-\u003etoken;\n1495:\t\t\tif (!i)\n1496:\t\t\t\tfunc[i]-\u003eaux-\u003eexception_boundary = env-\u003eseen_exception;\n1497:\t\t\tfunc[i] = bpf_int_jit_compile(env, func[i]);\n1498:\t\t\tif (!func[i]-\u003ejited) {\n1499:\t\t\t\terr = -ENOTSUPP;\n1500:\t\t\t\tgoto out_free;\n1501:\t\t\t}\n1502:\t\t\tcond_resched();\n1503:\t\t}\n1504:\t\n"
} |
| 43/2 | 2026/10/21 07:50 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 33425 output: 34 thoughts: 333 Thoughts: **Analyzing Potential Optimization Issues in BPF JIT Compilation** Okay, let's dive into this. I'm looking at lines 1488-1497, specifically the code snippet where `jit_subprogs` is setting up function attributes. It's assigning `env->subprog_info[i].is_exception_cb` to `func[i]->aux->exception_cb`, and then crucially, it's calling `bpf_int_jit_compile(env, func[i])`. This immediately triggers a concern. My immediate thought is that this assignment might interfere with how the JIT compiler handles unwinding. During `bpf_int_jit_compile`, `do_jit` calls `bpf_prog_can_unwind(bpf_prog)`, which seems to be the critical function. The code path that matters here is: `if (src_reg == BPF_UNWIND_EXIT && bpf_prog_can_unwind(bpf_prog) && emit_unwind_ret_addr(&prog, ip))` And now I see it, `bpf_prog_can_unwind(bpf_prog)` checks `if (prog->aux->exception_cb) return false;`. **This is where the problem lies.** If `exception_cb` is set to true *before* `bpf_int_jit_compile`, any chance for optimization during unwind code generation that would depend on `can_unwind` is *lost*, because `bpf_prog_can_unwind` will short circuit and return false when `exception_cb` is true. This potential short-circuiting in `bpf_prog_can_unwind` implies that any subprogram marked as an exception callback will *never* have unwind code generated. This makes me want to examine the calling structure. The text suggests that `bpf_jit_subprogs` is the caller of `jit_subprogs`. I'd like to check that context and see how that is set up in `bpf_jit_subprogs`. |
| 44/2 | 2026/10/21 07:50 | tool | grepper |
0mArgs:{
"Expression": "bpf_jit_subprogs",
"PathPrefixes": [
"kernel/bpf/"
]
}Results: {
"Output": "kernel/bpf/fixups.c=1356=static int jit_subprogs(struct bpf_verifier_env *env)\n--\nkernel/bpf/fixups.c-1632-\nkernel/bpf/fixups.c:1633:int bpf_jit_subprogs(struct bpf_verifier_env *env)\nkernel/bpf/fixups.c-1634-{\n--\nkernel/bpf/fixups.c=1705=int bpf_fixup_call_args(struct bpf_verifier_env *env)\n--\nkernel/bpf/fixups.c-1727-\t !bpf_prog_is_offloaded(env-\u003eprog-\u003eaux)) {\nkernel/bpf/fixups.c:1728:\t\terr = bpf_jit_subprogs(env);\nkernel/bpf/fixups.c-1729-\t\tif (err == 0)\n"
} |
| 45/2 | 2026/10/21 07:50 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 34498 output: 33 thoughts: 779 Thoughts: **My Analysis of BPF Unwinding and Exception Handling** Okay, let's break this down. My initial observation is that `bpf_jit_subprogs` isn't static in `kernel/bpf/fixups.c`, which makes it a key target. Now, I need to understand its role within the larger context of BPF exception handling and unwinding. I've got a list of relevant functions: `check_unwind_insns`, `bpf_jit_subprogs`, `bpf_unwind_target`, `bpf_mark_subprog_exc_cb`, and `bpf_throw`. Let's scrutinize each one. 1. **`check_unwind_insns`**: Found in `kernel/bpf/verifier.c`. This is directly involved in validating unwinding instructions, critical to prevent offload BPF programs from executing potentially unsafe unwinding paths. 2. **`bpf_jit_subprogs`**: This is where it gets interesting, in `kernel/bpf/fixups.c`. It's responsible for JIT-compiling subprograms; specifically, it sets up the `prog->aux->exception_cb` and calls `bpf_int_jit_compile`, which in turn involves an evaluation of `bpf_prog_can_unwind`. Seems central to the whole unwind-exception handling design. 3. **`bpf_unwind_target`**: In `arch/x86/net/bpf_jit_comp.c`. This is the runtime fixup function that gets invoked when an unwind exit is taken within the JIT-compiled code. 4. **`bpf_mark_subprog_exc_cb`**: Found in `kernel/bpf/verifier.c`. This function marks a subprogram as an exception callback (using `is_exception_cb`), which directly influences whether `bpf_prog_can_unwind` allows unwinding for that subprogram. 5. **`bpf_throw`**: This is in `kernel/bpf/helpers.c`. A simple helper function. It throws the exception, invoking the exception callback. Now, are these features always compiled, or is there a specific conditional compilation? None of these functions are ubiquitous. They're only used when BPF programs that have subprograms, use exception callbacks, or are designed to unwind are loaded and executed. That narrows down the scope quite a bit. As for the configuration requirements, I'm pretty sure we need: 1. `BPF_SYSCALL`: This is fundamental, enabling the `bpf()` syscall and the BPF verifier. 2. `BPF_JIT`: This is mandatory to turn on the BPF JIT compiler (and by extension, the x86 JIT compilation). I see no other necessary configurations for this system. No, `BPF_JIT_ALWAYS_ON` isn't required; `BPF_JIT` is sufficient (or depends on it). What about offloading? Does `bpf_prog_is_offloaded` require a config? It's defined in `include/linux/bpf.h`. Ah, there it is: Offload is only possible if `CONFIG_NETDEVSIM` or `CONFIG_NET` are enabled. Regardless, `bpf_prog_is_offloaded` builds unconditionally, though its value depends on those configs. Finally, does `bpf_throw` have any conditional compilation? In `kernel/bpf/helpers.c`, it's compiled when `CONFIG_BPF_SYSCALL` is enabled. That makes sense; it's part of the core BPF syscall interface. I think I have a good grasp of the configuration now. |
| 46/2 | 2026/10/21 07:50 | tool | grepper |
0mArgs:{
"Expression": "bpf_throw",
"PathPrefixes": [
"kernel/bpf/helpers.c"
]
}Results: {
"Output": "kernel/bpf/helpers.c=3394=__bpf_kfunc void bpf_rcu_read_unlock(void)\n--\nkernel/bpf/helpers.c-3398-\nkernel/bpf/helpers.c:3399:struct bpf_throw_ctx {\nkernel/bpf/helpers.c-3400-\tstruct bpf_prog_aux *aux;\n--\nkernel/bpf/helpers.c=3406=static bool bpf_stack_walker(void *cookie, u64 ip, u64 sp, u64 bp)\nkernel/bpf/helpers.c-3407-{\nkernel/bpf/helpers.c:3408:\tstruct bpf_throw_ctx *ctx = cookie;\nkernel/bpf/helpers.c-3409-\tstruct bpf_prog *prog;\n--\nkernel/bpf/helpers.c-3429-\nkernel/bpf/helpers.c:3430:__bpf_kfunc void bpf_throw(u64 cookie)\nkernel/bpf/helpers.c-3431-{\nkernel/bpf/helpers.c:3432:\tstruct bpf_throw_ctx ctx = {};\nkernel/bpf/helpers.c-3433-\n--\nkernel/bpf/helpers.c-3441-\t * Prevent KASAN false positives for CONFIG_KASAN_STACK by unpoisoning\nkernel/bpf/helpers.c:3442:\t * deeper stack depths than ctx.sp as we do not return from bpf_throw,\nkernel/bpf/helpers.c-3443-\t * which skips compiler generated instrumentation to do the same. Some\n--\nkernel/bpf/helpers.c=5119=BTF_ID_FLAGS(func, bpf_task_from_vpid, KF_ACQUIRE | KF_RET_NULL)\nkernel/bpf/helpers.c:5120:BTF_ID_FLAGS(func, bpf_throw)\nkernel/bpf/helpers.c-5121-#ifdef CONFIG_BPF_EVENTS\n"
} |
| 47/2 | 2026/10/21 07:50 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 36661 output: 192 thoughts: 236 Thoughts: **Final BPF Patch Assessment** Okay, so this patch is going to be compiled unconditionally, assuming `CONFIG_BPF_SYSCALL` is set, which is good. Time to run through the checklist one last time to make sure we've got everything covered before we move forward. First, `WorthFuzzing`: Yep, that's a solid "true." It's touching the BPF verifier logic in `check_unwind_insns` and also deals with unwinding logic inside `bpf_prog_can_unwind`. The impact is the BPF program verification and JIT code generation on x86_64, which is definitely accessible through the BPF syscall. We have a solid chance of finding interesting things here. Next, `FocusSymbols`: Alright, we have a clear set of functions we want to keep an eye on: `check_unwind_insns`, `bpf_jit_subprogs`, `bpf_unwind_target`, `bpf_mark_subprog_exc_cb`, and, importantly, `bpf_throw`. That list looks good. Then, we have `EnableConfigs`: Looks like we need `BPF_SYSCALL` (obviously, since the patch is tied to it) and `BPF_JIT`. That's reasonable, makes sense. Finally, the `Reasoning` provides a concise explanation of how this code is reachable, what's being changed, and why fuzzing it is worthwhile, and the explanation makes sense, confirming my assessment. Alright, everything checks out. Let's call `set-results` and move on. |
| 48/2 | 2026/10/21 07:50 | tool | set-results |
0mArgs:{
"EnableConfigs": [
"BPF_SYSCALL",
"BPF_JIT"
],
"FocusSymbols": [
"check_unwind_insns",
"bpf_jit_subprogs",
"bpf_unwind_target",
"bpf_mark_subprog_exc_cb",
"bpf_throw"
],
"Reasoning": "The patch modifies BPF verifier unwinding validation logic in check_unwind_insns() to disallow unwind instructions in offloaded programs, and updates bpf_prog_can_unwind() to prevent exception callbacks from unwinding. These paths are directly reachable from userspace via the bpf() system call when verifying and JIT-compiling BPF programs with subprograms, exception callbacks, and unwinding on x86_64.",
"WorthFuzzing": true
}Results: {
"EnableConfigs": [
"BPF_SYSCALL",
"BPF_JIT"
],
"FocusSymbols": [
"check_unwind_insns",
"bpf_jit_subprogs",
"bpf_unwind_target",
"bpf_mark_subprog_exc_cb",
"bpf_throw"
],
"Reasoning": "The patch modifies BPF verifier unwinding validation logic in check_unwind_insns() to disallow unwind instructions in offloaded programs, and updates bpf_prog_can_unwind() to prevent exception callbacks from unwinding. These paths are directly reachable from userspace via the bpf() system call when verifying and JIT-compiling BPF programs with subprograms, exception callbacks, and unwinding on x86_64.",
"WorthFuzzing": true
} |
| 49/1 | 2026/10/21 07:50 | action | If |
0mArgs:{
"WorthFuzzing": true
}Results: null |
| 50/2 | 2026/10/21 07:50 | agent | kmsan-evaluator |
0mModel:core Args: null Results: {
"KMSANReasoning": "The patch adjusts BPF verifier and JIT compilation logic for BPF stack unwinding: it ensures exception callbacks cannot unwind (`bpf_prog_can_unwind()` returns false if `prog-\u003eaux-\u003eexception_cb` is set), rejects unwind instructions for offloaded BPF programs in `check_unwind_insns()`, and updates selftests.\n\nKMSAN vs. KASAN applicability:\n- The changes only modify verifier validation rules, JIT instruction selection, and comments, along with userspace selftests.\n- No new memory allocations or structures are introduced, and no kernel data is copied or leaked to user space (no copy_to_user, put_user, netlink, or ioctl output).\n- The inspected struct fields (`prog-\u003eaux-\u003eexception_cb` and `prog-\u003eaux-\u003eoffload`) reside within `struct bpf_prog_aux`, which is zero-allocated via kzalloc upon program allocation.\n- The patch does not introduce or expose any uninitialized stack or heap memory, nor does it create branching on uninitialized data. Any execution or JIT framing issues would pertain to control flow or out-of-bounds access (detectable by KASAN), not uninitialized memory reads detectable only by KMSAN.\n\nTherefore, a dedicated KMSAN fuzzing session is not needed.",
"NeedsKMSAN": false
}Instruction: You are an expert Linux kernel security engineer specializing in kernel memory
error detectors (KASAN and KMSAN). Your job is to review the provided patch series and
determine if the code changes justify spawning a dedicated KMSAN (KernelMemorySanitizer)
fuzzing session in addition to standard KASAN fuzzing.
CRITICAL DISTINCTION BETWEEN KASAN AND KMSAN:
- Standard KASAN kernel builds (upstream-apparmor-kasan.config) already enable
a comprehensive suite of debugging tools and sanitizers, including KASAN
(out-of-bounds accesses, use-after-free, double free, invalid free), LOCKDEP
(locking bugs and deadlocks), UB-sanitizers, and memory corruption checks.
- KMSAN (KernelMemorySanitizer) detects reads of UNINITIALIZED memory (stack, heap,
or page allocations) and kernel-to-user memory info-leaks.
Rule: THERE IS NO SENSE IN RUNNING A KMSAN SESSION IF A BUG CAN BE CAUGHT BY KASAN,
LOCKDEP, OR OTHER STANDARD BUG DETECTORS.
A dedicated KMSAN fuzzing session incurs significant resource costs. You must ONLY
set NeedsKMSAN=true if the code changes introduce or expose UNINITIALIZED MEMORY risks
that are detected ONLY by KMSAN.
Look holistically at the patch series and surrounding code. Even if no direct
uninitialized field accesses or new buffer allocations are added in the diff itself,
a patch may alter control flow, bounds checking, or data length calculations in ways
that change how the rest of the code operates on existing buffers (e.g. allowing
uninitialized stack/heap memory to be read, copied to user space, or used in control
flow). Do not hesitate to use your code access tools to inspect the surrounding code,
called functions, and callers.
Set NeedsKMSAN=true ONLY IF the patch introduces or modifies:
1. Kernel structures sent to user space (via copy_to_user, put_user, netlink skb
attributes, ioctl output arguments, socket options, or BPF buffers) where fields
or structure padding might not be fully initialized/zeroed.
2. Conditional logic or branching that depends on potentially uninitialized variables
or struct fields.
3. Allocation or initialization of complex data structures where uninitialized fields
could be read later in reachable code paths.
4. Bounds checks, lengths, or logic in a way that allows surrounding code to access
uninitialized bytes of existing buffers.
Set NeedsKMSAN=false IF:
- The code changes primarily risk out-of-bounds access, array overflows, NULL pointer
dereferences, locking deadlocks, or use-after-free bugs (these are already caught
by KASAN, LOCKDEP, or standard bug detectors).
- All stack/heap structures touched or introduced by the patch are fully zeroed
or initialized (e.g. using = {0}, memset, kzalloc) before being read or copied.
- The patch does not introduce any risk of uninitialized memory usage or info-leaks.
Use your code access tools to inspect the surrounding code if necessary, then provide
detailed KMSANReasoning contrasting KASAN vs KMSAN applicability for this patch.
Prefer calling several tools at the same time to save round-trips.
Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.
Prompt: Target architecture: amd64
For your convenience, here is the diff of the changes:
commit a9dcc1468c3fbec1d9063fdb94dc3d5063641908
Author: syz-cluster <triage@syzkaller.com>
Date: Wed Oct 21 07:47:27 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 b3efe0668e868..326e9e1dea0a7 100644
--- a/arch/arm64/net/bpf_jit_comp.c
+++ b/arch/arm64/net/bpf_jit_comp.c
@@ -1273,7 +1273,7 @@ static long bpf_unwind_fixup(u64 lr)
e = search_bpf_extables(ptrauth_strip_kernel_insn_pac(lr) - 1);
/*
* The verifier made sure that unwind_goto follows a call in a prog. When
- * the kernel called an async or an exception callback, it's exit.
+ * the kernel called an async callback, it's exit.
*/
return e ? e->fixup : 0;
}
diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
index d3ab36281144d..6a2fe3d0039d3 100644
--- a/arch/x86/net/bpf_jit_comp.c
+++ b/arch/x86/net/bpf_jit_comp.c
@@ -2552,7 +2552,7 @@ static u64 bpf_unwind_target(u64 ret_addr)
/*
* The verifier made sure that unwind_goto follows a call in a prog. When
- * the kernel called an async or an exception callback, it's exit.
+ * the kernel called an async callback, it's exit.
*/
return e ? ret_addr + e->fixup : ret_addr;
}
diff --git a/include/linux/filter.h b/include/linux/filter.h
index fccd8db336470..e0218e677a1dc 100644
--- a/include/linux/filter.h
+++ b/include/linux/filter.h
@@ -267,9 +267,13 @@ static inline bool bpf_is_unwind_exit(const struct bpf_insn *insn)
/*
* The caller of the main prog doesn't tell unwind_exit from exit. An extension
* is different: its caller is the caller of the subprog that it replaced.
+ * An exception callback returns from the frame of the main prog. After freplace
+ * or a tail call it returns to a prog that wasn't verified with the callback.
*/
static inline bool bpf_prog_can_unwind(const struct bpf_prog *prog)
{
+ if (prog->aux->exception_cb)
+ return false;
return bpf_is_subprog(prog) || prog->type == BPF_PROG_TYPE_EXT;
}
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index 7d7193b087f67..5601d20562186 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -3462,7 +3462,7 @@ static int check_unwind_insns(struct bpf_verifier_env *env)
}
if (!seen)
return 0;
- if (!bpf_jit_supports_unwind()) {
+ if (!bpf_jit_supports_unwind() || bpf_prog_is_offloaded(env->prog->aux)) {
verbose(env, "JIT does not support unwinding\n");
return -ENOTSUPP;
}
diff --git a/tools/testing/selftests/bpf/prog_tests/unwind_attach.c b/tools/testing/selftests/bpf/prog_tests/unwind_attach.c
index ada8b3273ccb1..37e03b3e0ee80 100644
--- a/tools/testing/selftests/bpf/prog_tests/unwind_attach.c
+++ b/tools/testing/selftests/bpf/prog_tests/unwind_attach.c
@@ -67,7 +67,7 @@ void test_unwind_attach(void)
{
struct verifier_unwind *tgt;
struct bpf_program *prog;
- int tgt_fd, plain_fd, err;
+ int tgt_fd, plain_fd, shared_fd, tail_fd, throws_fd, err, key = 0;
if (!is_jit_enabled()) {
printf("%s:SKIP:JIT is disabled\n", __func__);
@@ -79,7 +79,10 @@ void test_unwind_attach(void)
return;
bpf_object__for_each_program(prog, tgt->obj)
bpf_program__set_autoload(prog, prog == tgt->progs.calls_global_unwinds ||
- prog == tgt->progs.calls_global_never_unwinds);
+ prog == tgt->progs.calls_global_never_unwinds ||
+ prog == tgt->progs.shared_pad ||
+ prog == tgt->progs.tail_call_in_subprog ||
+ prog == tgt->progs.exception_callback_unwinds);
err = verifier_unwind__load(tgt);
if (err == -ENOTSUPP) {
printf("%s:SKIP:JIT does not support unwinding\n", __func__);
@@ -107,6 +110,21 @@ void test_unwind_attach(void)
attach(plain_fd, "global_never_unwinds", "freplace_unwinds",
"Extension program can unwind, while original does not", 0);
ASSERT_EQ(run(tgt_fd), 15, "retval");
+
+ /*
+ * An exception callback returns from the frame of the main prog. Here
+ * that's a return to a call that unwind_goto follows. unwind_exit of
+ * the callback has to be exit: the pad wasn't verified with it.
+ */
+ shared_fd = bpf_program__fd(tgt->progs.shared_pad);
+ attach(shared_fd, "global_never_unwinds", "freplace_throws", NULL, 3);
+
+ tail_fd = bpf_program__fd(tgt->progs.tail_call_in_subprog);
+ throws_fd = bpf_program__fd(tgt->progs.exception_callback_unwinds);
+ err = bpf_map__update_elem(tgt->maps.prog_array, &key, sizeof(key),
+ &throws_fd, sizeof(throws_fd), 0);
+ if (ASSERT_OK(err, "prog_array"))
+ ASSERT_EQ(run(tail_fd), 7, "retval");
out:
verifier_unwind__destroy(tgt);
}
diff --git a/tools/testing/selftests/bpf/progs/unwind_attach.c b/tools/testing/selftests/bpf/progs/unwind_attach.c
index df73c26c1ff46..9aff7c6bda238 100644
--- a/tools/testing/selftests/bpf/progs/unwind_attach.c
+++ b/tools/testing/selftests/bpf/progs/unwind_attach.c
@@ -7,6 +7,13 @@
/* The targets are global_unwinds() and global_never_unwinds() in verifier_unwind.c */
+#define unwind_exit ".8byte %[insn_unwind_exit];"
+#define __imm_unwind_exit \
+ __imm_insn(insn_unwind_exit, \
+ BPF_RAW_INSN(BPF_JMP | BPF_EXIT, 0, BPF_UNWIND_EXIT, 0, 0))
+
+extern void bpf_throw(__u64 cookie) __ksym;
+
int fentry_cnt;
SEC("?fentry/global_unwinds")
@@ -33,11 +40,27 @@ __naked unsigned long freplace_unwinds(void)
{
asm volatile (
"r0 = 3;"
- ".8byte %[unwind_exit];"
+ unwind_exit
:
- : __imm_insn(unwind_exit,
- BPF_RAW_INSN(BPF_JMP | BPF_EXIT, 0, BPF_UNWIND_EXIT, 0, 0))
+ : __imm_unwind_exit
);
}
+/* Not naked: the argument has to have a name in BTF */
+__noinline int throws_cb(__u64 cookie)
+{
+ if (cookie)
+ asm volatile ("r0 = 3;" unwind_exit :: __imm_unwind_exit : "r0");
+ return 0;
+}
+
+/* It has no unwind_exit, so it can replace a subprog that cannot unwind */
+SEC("?freplace/global_never_unwinds")
+__attribute__((btf_decl_tag("exception_callback:throws_cb")))
+unsigned long freplace_throws(void)
+{
+ bpf_throw(1);
+ return 0;
+}
+
char _license[] SEC("license") = "GPL";
diff --git a/tools/testing/selftests/bpf/progs/verifier_unwind.c b/tools/testing/selftests/bpf/progs/verifier_unwind.c
index 0a75cb8af67ff..5a21345c34d45 100644
--- a/tools/testing/selftests/bpf/progs/verifier_unwind.c
+++ b/tools/testing/selftests/bpf/progs/verifier_unwind.c
@@ -611,6 +611,35 @@ __naked int calls_global_never_unwinds(void)
);
}
+/*
+ * The verifier gets to the pad from the first call only, with r6 = 1. The second
+ * unwind_goto stays, since the pad is not dead code.
+ */
+SEC("tc")
+__description("unwind: a pad shared with a call of a subprog that cannot unwind")
+__arch_x86_64
+__arch_arm64
+__load_if_JITed()
+__success __retval(7)
+__naked int shared_pad(void)
+{
+ asm volatile (
+ "r6 = 1;"
+ "call global_returns;"
+ unwind_goto(4)
+ "r6 = 2;"
+ "call global_never_unwinds;"
+ unwind_goto(1)
+ "exit;"
+ "r0 = r6;"
+ "exit;"
+ :
+ : __imm_unwind_goto(4),
+ __imm_unwind_goto(1)
+ : __clobber_all
+ );
+}
+
SEC("tc")
__description("unwind: no unwind_goto after a call of a global subprog")
__arch_x86_64
|
| 51/3 | 2026/10/21 07:50 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 4940 output: 23 thoughts: 404 Thoughts: **Analyzing This Patch for KMSAN Fuzzing Needs** Okay, let's break this down. My initial assessment is we need to determine if KMSAN fuzzing is warranted here. I'm seeing a series of changes related to BPF, and my expert intuition is pinging that could have memory safety implications, especially with the added complexity of exception callbacks and unwinding. First, the simple stuff: the comment updates in `arch/arm64/net/bpf_jit_comp.c` and `arch/x86/net/bpf_jit_comp.c` are minor tweaks, likely clarifying the behavior of exit conditions after async callbacks. Nothing inherently concerning there on its own. Now the core of the matter: the `include/linux/filter.h` change introduces a critical check within `bpf_prog_can_unwind`. The addition `if (prog->aux->exception_cb) return false;` is a red flag. The comments explain that if an exception callback is present, the program *cannot* unwind. That suggests potential for execution paths that were previously not handled in the unwind analysis. The note about freplace and tail calls immediately makes me think of control flow complexity. Deeper concern is the modification in `kernel/bpf/verifier.c`. The conditional change in `check_unwind_insns` now considers offloaded BPF programs in relation to unwinding support. The combination of this change with the previous one strongly implies that we're dealing with a new, potentially less-well-tested interaction between the JIT, offloaded BPF programs, and exception callbacks. That's a classic scenario for memory safety bugs. Finally, the inclusion of selftests in `tools/testing/selftests/bpf/...` for BPF unwinding with freplace, exception callbacks, and tail calls is a good sign—at least the developers are thinking about it—but it's not a guarantee of thoroughness. My instinct says we need to dig deeper. I want to see how `bpf_prog_can_unwind` is used, and what consequences the new check could have. Grepping or reading the code where that function is used is the next step to confirm my suspicions and decide if KMSAN is necessary here. |
| 52/3 | 2026/10/21 07:50 | tool | grepper |
0mArgs:{
"Expression": "bpf_prog_can_unwind"
}Results: {
"Output": "arch/arm64/net/bpf_jit_comp.c=1432=static int build_insn(const struct bpf_verifier_env *env, const struct bpf_insn *insn,\n--\narch/arm64/net/bpf_jit_comp.c-1892-\tcase BPF_JMP | BPF_EXIT:\narch/arm64/net/bpf_jit_comp.c:1893:\t\tif (bpf_is_unwind_exit(insn) \u0026\u0026 bpf_prog_can_unwind(ctx-\u003eprog)) {\narch/arm64/net/bpf_jit_comp.c-1894-\t\t\temit_unwind_exit(ctx);\n--\narch/x86/net/bpf_jit_comp.c=2577=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-3867-\t\tcase BPF_JMP | BPF_EXIT:\narch/x86/net/bpf_jit_comp.c:3868:\t\t\tif (src_reg == BPF_UNWIND_EXIT \u0026\u0026 bpf_prog_can_unwind(bpf_prog) \u0026\u0026\narch/x86/net/bpf_jit_comp.c-3869-\t\t\t emit_unwind_ret_addr(\u0026prog, ip))\n--\ninclude/linux/filter.h=262=static inline bool bpf_is_unwind_exit(const struct bpf_insn *insn)\n--\ninclude/linux/filter.h-272- */\ninclude/linux/filter.h:273:static inline bool bpf_prog_can_unwind(const struct bpf_prog *prog)\ninclude/linux/filter.h-274-{\n"
} |
| 53/3 | 2026/10/21 07:50 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 6337 output: 35 thoughts: 178 Thoughts: Here's my understanding of the situation, tailored for an expert like yourself:
**Analyzing BPF Unwinding Capabilities in the JIT Compiler**
Okay, so I'm digging into `bpf_jit_comp.c` to understand the use of `bpf_prog_can_unwind`. The x86 JIT code uses it in this crucial spot: `if (src_reg == BPF_UNWIND_EXIT && bpf_prog_can_unwind(bpf_prog) && emit_unwind_ret_addr(&prog, ip))`. My initial thought is that it looks like this is related to returning from a BPF program with the instruction code `BPF_UNWIND_EXIT`. It checks whether we can unwind and then emits the return address. Seems pretty standard.
Immediately following, I see a check that looks important to note: `if (prog->aux->exception_cb) return false;`. This looks like if there's an exception callback, we don't allow unwinding. That makes sense; if there's a specialized exception handler, unwinding probably interferes with it.
Then, there's `check_unwind_insns`. This seems to be where we decide whether unwinding is even supported in the first place, or if something is offloaded. `if (!bpf_jit_supports_unwind() || bpf_prog_is_offloaded(env->prog->aux)) { verbose(...); return -ENOTSUPP; }`. This makes it clear: If the JIT doesn't support it or the program is offloaded, unwinding isn't allowed, and an error is returned. That's a good sanity check.
Now, I think I should check the kernel's `filter.h` file, as I think it holds relevant info. I'm going to scan the code around lines 265-285. I'll need to figure out what's going on there.
|
| 54/3 | 2026/10/21 07:50 | tool | read-file |
0mArgs:{
"File": "include/linux/filter.h",
"FirstLine": 260,
"LineCount": 30
}Results: {
"Contents": " 260:\t}\n 261:\t\n 262:\tstatic inline bool bpf_is_unwind_exit(const struct bpf_insn *insn)\n 263:\t{\n 264:\t\treturn insn-\u003ecode == (BPF_JMP | BPF_EXIT) \u0026\u0026 insn-\u003esrc_reg == BPF_UNWIND_EXIT;\n 265:\t}\n 266:\t\n 267:\t/*\n 268:\t * The caller of the main prog doesn't tell unwind_exit from exit. An extension\n 269:\t * is different: its caller is the caller of the subprog that it replaced.\n 270:\t * An exception callback returns from the frame of the main prog. After freplace\n 271:\t * or a tail call it returns to a prog that wasn't verified with the callback.\n 272:\t */\n 273:\tstatic inline bool bpf_prog_can_unwind(const struct bpf_prog *prog)\n 274:\t{\n 275:\t\tif (prog-\u003eaux-\u003eexception_cb)\n 276:\t\t\treturn false;\n 277:\t\treturn bpf_is_subprog(prog) || prog-\u003etype == BPF_PROG_TYPE_EXT;\n 278:\t}\n 279:\t\n 280:\tstatic inline bool insn_is_zext(const struct bpf_insn *insn)\n 281:\t{\n 282:\t\treturn insn-\u003ecode == (BPF_ALU | BPF_MOV | BPF_X) \u0026\u0026 insn-\u003eimm == 1;\n 283:\t}\n 284:\t\n 285:\t/* addr_space_cast from as(0) to as(1) is for converting bpf arena pointers\n 286:\t * to pointers in user vma.\n 287:\t */\n 288:\tstatic inline bool insn_is_cast_user(const struct bpf_insn *insn)\n 289:\t{\n"
} |
| 55/3 | 2026/10/21 07:50 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 7511 output: 37 thoughts: 22 Thoughts: Okay, let's dive into this. Here's how I'd approach that snippet of code, assuming I'm an expert in this field: **Diving into the BPF Verifier** Alright, I need to investigate the BPF verifier. The task is to examine `kernel/bpf/verifier.c`, specifically around line 3462. I'm already mentally parsing that file path – the kernel's BPF implementation, specifically the verifier component. Line 3462... that's deep within, likely dealing with a specific aspect of instruction validation, register management, or perhaps a complex control flow analysis. I’m guessing it's not a trivial check, given its depth within the file. I anticipate it could be handling an edge case, a potential vulnerability, or maybe a performance optimization related to how BPF programs are checked for safety and correctness. I'll need to remember the surrounding context to understand what that line is doing. Let's get to it. |
| 56/3 | 2026/10/21 07:50 | tool | read-file |
0mArgs:{
"File": "kernel/bpf/verifier.c",
"FirstLine": 3450,
"LineCount": 35
}Results: {
"Contents": "3450:\t\t\tif (!bpf_is_unwind_goto(insn))\n3451:\t\t\t\tcontinue;\n3452:\t\t\tseen = true;\n3453:\t\t\tif (!i || !(bpf_pseudo_call(insn - 1) || bpf_is_callx(insn - 1))) {\n3454:\t\t\t\tverbose(env, \"unwind_goto at insn %d doesn't follow a call of a subprog\\n\",\n3455:\t\t\t\t\ti);\n3456:\t\t\t\treturn -EINVAL;\n3457:\t\t\t}\n3458:\t\t\tif (bpf_is_jump_target(env, i)) {\n3459:\t\t\t\tverbose(env, \"jump to unwind_goto at insn %d\\n\", i);\n3460:\t\t\t\treturn -EINVAL;\n3461:\t\t\t}\n3462:\t\t}\n3463:\t\tif (!seen)\n3464:\t\t\treturn 0;\n3465:\t\tif (!bpf_jit_supports_unwind() || bpf_prog_is_offloaded(env-\u003eprog-\u003eaux)) {\n3466:\t\t\tverbose(env, \"JIT does not support unwinding\\n\");\n3467:\t\t\treturn -ENOTSUPP;\n3468:\t\t}\n3469:\t\tenv-\u003eprog-\u003ejit_required = 1;\n3470:\t\tenv-\u003eprog-\u003eaux-\u003ecan_unwind = env-\u003esubprog_info[0].can_unwind;\n3471:\t\treturn 0;\n3472:\t}\n3473:\t\n3474:\t/*\n3475:\t * Sort subprogs in topological order so that leaf subprogs come first and\n3476:\t * their callers come later. This is a DFS post-order traversal of the call\n3477:\t * graph. Scan only reachable instructions (those in the computed postorder) of\n3478:\t * the current subprog to discover callees (direct subprogs and sync\n3479:\t * callbacks).\n3480:\t *\n3481:\t * The callees of callx are not known before the main verification pass.\n3482:\t * When callx is used the sort is repeated after it with the recorded callx\n3483:\t * edges added to the call graph to reject recursion through indirect calls.\n3484:\t */\n"
} |
| 57/3 | 2026/10/21 07:50 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 8396 output: 45 thoughts: 27 Thoughts: Okay, let's dive into this. I'm taking a look at `bpf_unwind_fixup` and `bpf_unwind_target`. My understanding is that these are crucial components in BPF-based unwinding, particularly when dealing with potential issues or ambiguities during the unwinding process. They likely address edge cases, handle platform-specific quirks, or resolve conflicting information that the BPF program encounters when trying to reconstruct a call stack. I need to understand their exact roles and how they fit into the larger unwinding architecture. Are they used for error correction, alternative path selection, or perhaps for handling indirect calls in a reliable manner? The naming suggests they're involved in correcting or guiding the unwinding process towards a valid "target" frame. This warrants a closer look at the surrounding code to determine how they're used in practice. |
| 58/3 | 2026/10/21 07:50 | tool | read-file |
0mArgs:{
"File": "arch/x86/net/bpf_jit_comp.c",
"FirstLine": 2540,
"LineCount": 30
}Results: {
"Contents": "2540:\t\t}\n2541:\t\t/* switch ex to rw buffer for writes */\n2542:\t\tex = (void *)rw_image + ((void *)ex - (void *)image);\n2543:\t\tex-\u003einsn = delta;\n2544:\t\tex-\u003efixup = target - ret_addr;\n2545:\t\tex-\u003edata = EX_TYPE_BPF;\n2546:\t\treturn 0;\n2547:\t}\n2548:\t\n2549:\tstatic u64 bpf_unwind_target(u64 ret_addr)\n2550:\t{\n2551:\t\tconst struct exception_table_entry *e = search_bpf_extables(ret_addr - 1);\n2552:\t\n2553:\t\t/*\n2554:\t\t * The verifier made sure that unwind_goto follows a call in a prog. When\n2555:\t\t * the kernel called an async callback, it's exit.\n2556:\t\t */\n2557:\t\treturn e ? ret_addr + e-\u003efixup : ret_addr;\n2558:\t}\n2559:\t\n2560:\t/* unwind_exit: fix the return address of this frame. r0 and r2 are returned. */\n2561:\tstatic int emit_unwind_ret_addr(u8 **pprog, u8 *ip)\n2562:\t{\n2563:\t\tu8 *prog = *pprog, *start = prog;\n2564:\t\n2565:\t\tEMIT2(0x50, 0x56);\t\t\t/* push rax; push rsi */\n2566:\t\tEMIT4(0x48, 0x8B, 0x7D, 0x08);\t\t/* mov rdi, [rbp + 8] */\n2567:\t\tip += prog - start;\n2568:\t\tip += x86_call_depth_emit_accounting(\u0026prog, bpf_unwind_target, ip);\n2569:\t\tif (emit_call(\u0026prog, bpf_unwind_target, ip))\n"
} |
| 59/3 | 2026/10/21 07:50 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 9203 output: 309 thoughts: 1097 Thoughts: **KMSAN Analysis: BPF Unwinding Patch** Okay, let's break this down. First, the patch itself: it's focused on refining how BPF unwinding (`BPF_UNWIND_EXIT`) works, specifically in the context of exception callbacks and offloaded BPF programs. The changes involve modifying `bpf_prog_can_unwind()` to prevent unwinding from exception callbacks, rejecting unwind instructions for offloaded programs in the verifier, and adding associated selftests. No big surprises there, just careful adjustments to existing functionality. Now, the crucial question: does this patch necessitate a KMSAN check? Let's walk through the KMSAN criteria. Does it involve any data copied to user space? Nope. Does it introduce or read any uninitialized memory? The changes operate strictly within the BPF verifier and JIT compilation flow, modifying existing checks and constraints on unwinding. The `exception_cb` and `offload` flags are already part of the `bpf_prog_aux` struct, which is *kzalloc'd* at program creation, ensuring initialization. The patch doesn't introduce any new structures or data paths that might be susceptible to uninitialized memory issues. We're not reading any potentially uninitialized memory or branching based on uninitialized data. These modifications are purely control flow, and existing checks ensure these control flows do not trigger memory corruption. The selftests are in user space, so they don't directly introduce kernel-side uninitialized memory issues either. Considering KMSAN's focus on detecting uninitialized memory reads, information leaks to user space, and similar problems, this patch doesn't trigger any of those concerns. The risks here relate to potential bugs in BPF JIT code generation or execution frames, but those would manifest as control flow, instruction decoding, or stack/frame layout bugs, that would be checked by standard memory error detectors like KASAN. Therefore, the analysis is conclusive. **NeedsKMSAN = false.** This patch is well-contained and doesn't introduce any uninitialized memory risks or information leaks that would trigger KMSAN. |
| 60/3 | 2026/10/21 07:51 | tool | set-results |
0mArgs:{
"KMSANReasoning": "The patch adjusts BPF verifier and JIT compilation logic for BPF stack unwinding: it ensures exception callbacks cannot unwind (`bpf_prog_can_unwind()` returns false if `prog-\u003eaux-\u003eexception_cb` is set), rejects unwind instructions for offloaded BPF programs in `check_unwind_insns()`, and updates selftests.\n\nKMSAN vs. KASAN applicability:\n- The changes only modify verifier validation rules, JIT instruction selection, and comments, along with userspace selftests.\n- No new memory allocations or structures are introduced, and no kernel data is copied or leaked to user space (no copy_to_user, put_user, netlink, or ioctl output).\n- The inspected struct fields (`prog-\u003eaux-\u003eexception_cb` and `prog-\u003eaux-\u003eoffload`) reside within `struct bpf_prog_aux`, which is zero-allocated via kzalloc upon program allocation.\n- The patch does not introduce or expose any uninitialized stack or heap memory, nor does it create branching on uninitialized data. Any execution or JIT framing issues would pertain to control flow or out-of-bounds access (detectable by KASAN), not uninitialized memory reads detectable only by KMSAN.\n\nTherefore, a dedicated KMSAN fuzzing session is not needed.",
"NeedsKMSAN": false
}Results: {
"KMSANReasoning": "The patch adjusts BPF verifier and JIT compilation logic for BPF stack unwinding: it ensures exception callbacks cannot unwind (`bpf_prog_can_unwind()` returns false if `prog-\u003eaux-\u003eexception_cb` is set), rejects unwind instructions for offloaded BPF programs in `check_unwind_insns()`, and updates selftests.\n\nKMSAN vs. KASAN applicability:\n- The changes only modify verifier validation rules, JIT instruction selection, and comments, along with userspace selftests.\n- No new memory allocations or structures are introduced, and no kernel data is copied or leaked to user space (no copy_to_user, put_user, netlink, or ioctl output).\n- The inspected struct fields (`prog-\u003eaux-\u003eexception_cb` and `prog-\u003eaux-\u003eoffload`) reside within `struct bpf_prog_aux`, which is zero-allocated via kzalloc upon program allocation.\n- The patch does not introduce or expose any uninitialized stack or heap memory, nor does it create branching on uninitialized data. Any execution or JIT framing issues would pertain to control flow or out-of-bounds access (detectable by KASAN), not uninitialized memory reads detectable only by KMSAN.\n\nTherefore, a dedicated KMSAN fuzzing session is not needed.",
"NeedsKMSAN": false
} |
| Total Calls | Total Tokens | Avg Tokens | Total Duration (Seconds) | Avg Duration (Seconds) |
|---|
| Total Calls | Total Duration (Seconds) | Avg Duration (Seconds) |
|---|