diff options
| author | Kumar Kartikeya Dwivedi <memxor@gmail.com> | 2026-08-15 08:46:08 +0200 |
|---|---|---|
| committer | Eduard Zingerman <eddyz87@gmail.com> | 2026-08-15 11:15:17 -0700 |
| commit | a8f4278353947d019c990a77d574dfd4d1dc9b46 (patch) | |
| tree | b3413812112a53ee2cee814536111618a8a31312 /kernel/bpf/diagnostics.c | |
| parent | 99a6a288a82bf00ba0b01e72bf85164e848d1d18 (diff) | |
| download | linux-a8f4278353947d019c990a77d574dfd4d1dc9b46.tar.gz linux-a8f4278353947d019c990a77d574dfd4d1dc9b46.zip | |
bpf: Report Program Structure CFG errors
Augment selected whole-program and subprogram CFG validation failures with
Program Structure reports. These errors are structural rather than
path-dependent, so the reports focus on source and instruction context
instead of causal history.
Cover direct and indirect jumps outside the program or current subprogram,
unprivileged backedges, missing and out-of-range jump tables, targets in the
second half of an ldimm64, unreachable instructions, subprogram fallthrough,
and recursive bpf2bpf call graph edges.
Format long jump-range reasons directly in diagnostics.c, and keep the
fallthrough suggestion aligned with the verifier check by suggesting exit or
explicit jumps.
Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Acked-by: Eduard Zingerman <eddyz87@gmail.com>
Link: https://patch.msgid.link/20260815064612.378577-14-memxor@gmail.com
Signed-off-by: Eduard Zingerman <eddyz87@gmail.com>
Diffstat (limited to 'kernel/bpf/diagnostics.c')
| -rw-r--r-- | kernel/bpf/diagnostics.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/kernel/bpf/diagnostics.c b/kernel/bpf/diagnostics.c index c69160f656e9..9fc1f8cf7312 100644 --- a/kernel/bpf/diagnostics.c +++ b/kernel/bpf/diagnostics.c @@ -21,6 +21,7 @@ #define RESOURCE_LIFETIME_SAFETY "Resource Lifetime Safety" #define CALL_TYPE_SAFETY "Call Type Safety" #define EXECUTION_CONTEXT_SAFETY "Execution Context Safety" +#define PROGRAM_STRUCTURE "Program Structure" #define BPF_DIAG_TEXT_WIDTH 100 #define BPF_DIAG_TEXT_INDENT " " @@ -1192,6 +1193,24 @@ void bpf_diag_ctx_underflow(struct bpf_verifier_env *env, u32 insn_idx, diag_suggestion(env, "%s", suggestion); } +void bpf_diag_program_structure(struct bpf_verifier_env *env, u32 insn_idx, + const char *problem, const char *suggestion, + const char *reason_fmt, ...) +{ + va_list args; + + bpf_diag_header(env, PROGRAM_STRUCTURE, problem); + diag_section(env, "Reason"); + + va_start(args, reason_fmt); + diag_vprint_indented(env, reason_fmt, args); + va_end(args); + + diag_section(env, "At"); + bpf_diag_source(env, insn_idx, "error", "%s", problem); + + diag_suggestion(env, "%s", suggestion); +} void bpf_diag_invalid_deref(struct bpf_verifier_env *env, u32 insn_idx, int regno, const char *reg_name, const struct bpf_reg_state *reg, enum bpf_diag_invalid_deref_kind kind, s64 offset) |
