diff options
| author | Kumar Kartikeya Dwivedi <memxor@gmail.com> | 2026-08-15 08:46:00 +0200 |
|---|---|---|
| committer | Eduard Zingerman <eddyz87@gmail.com> | 2026-08-15 11:11:16 -0700 |
| commit | af4ea6e20fff383cdc2f01b9a372b4c7a0abf5ff (patch) | |
| tree | dbd42c395865d53790a8abffaf2f0f5aa48a4a9f /kernel/bpf/diagnostics.h | |
| parent | a6debd5f25c9c79f534074e9cb460cf6495d6daf (diff) | |
| download | linux-af4ea6e20fff383cdc2f01b9a372b4c7a0abf5ff.tar.gz linux-af4ea6e20fff383cdc2f01b9a372b4c7a0abf5ff.zip | |
bpf: Track verifier register diagnostic events
Record material register and outgoing stack argument changes so diagnostics can
explain how a value reached its current type, bounds, or unreadable state.
Store old and new register types, scalar ranges, tnum value and mask, map and
BTF type identity, and basic operand metadata in the environment-owned
diagnostic event stream.
Record invalidations when packet data moves, references are released, or
borrowed references leave their protected region. Register-scoped history
starts at the latest matching modification and then shows later branch
outcomes.
Also record fixed stack spills and overwrites, and tag register fills from
stack so register-scoped history can follow value flow through spilled stack
slots.
The type_is_map_ptr() helper previously lived as a static function in
kernel/bpf/log.c since commit 0c95c9fdb696 ("bpf: emit map name in register
state if applicable and available"). Move it verbatim to
include/linux/bpf_verifier.h as a static inline, next to the other type
classifiers, so diagnostics.c can reuse it without duplicating the case list.
Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Link: https://patch.msgid.link/20260815064612.378577-6-memxor@gmail.com
Signed-off-by: Eduard Zingerman <eddyz87@gmail.com>
Diffstat (limited to 'kernel/bpf/diagnostics.h')
| -rw-r--r-- | kernel/bpf/diagnostics.h | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/kernel/bpf/diagnostics.h b/kernel/bpf/diagnostics.h index 6eda2fd65ee1..c4e44b86e89d 100644 --- a/kernel/bpf/diagnostics.h +++ b/kernel/bpf/diagnostics.h @@ -8,17 +8,40 @@ #include <linux/stdarg.h> #include <linux/types.h> +struct bpf_func_state; +struct bpf_reg_state; struct bpf_verifier_env; +struct btf; + +enum bpf_diag_mod_reason { + BPF_DIAG_MOD_WRITE, + BPF_DIAG_MOD_SPILL, + BPF_DIAG_MOD_VAR_WRITE, + BPF_DIAG_MOD_REF_RELEASE, + BPF_DIAG_MOD_PKT_DATA_CHANGE, + BPF_DIAG_MOD_NON_OWN_REF, + BPF_DIAG_MOD_CALLER_SAVED, +}; bool bpf_diag_enabled(const struct bpf_verifier_env *env); int bpf_diag_init(struct bpf_verifier_env *env); +void bpf_diag_init_frame(struct bpf_verifier_env *env, struct bpf_func_state *state); char *bpf_diag_fmt_buf(struct bpf_verifier_env *env, size_t size); const char *bpf_diag_vfmt(struct bpf_verifier_env *env, const char *fmt, va_list args) __printf(2, 0); const char *bpf_diag_fmt(struct bpf_verifier_env *env, const char *fmt, ...) __printf(2, 3); +const char *bpf_diag_fmt_btf_type(struct bpf_verifier_env *env, const struct btf *btf, u32 type_id); u64 bpf_diag_event_log_save(struct bpf_verifier_env *env); void bpf_diag_event_log_restore(struct bpf_verifier_env *env, u64 log_pos); void bpf_diag_free(struct bpf_verifier_env *env); void bpf_diag_record_branch(struct bpf_verifier_env *env, u32 insn_idx, bool cond_true); +void bpf_diag_mod_begin(struct bpf_verifier_env *env, const struct bpf_reg_state *reg, + const struct bpf_reg_state *origin, enum bpf_diag_mod_reason reason); +void bpf_diag_mod_end(struct bpf_verifier_env *env); +void bpf_diag_record_scrub(struct bpf_verifier_env *env, const struct bpf_reg_state *reg, + enum bpf_diag_mod_reason reason); +void bpf_diag_record_scrub_stack(struct bpf_verifier_env *env, + const struct bpf_func_state *state, s16 min_off, s16 max_off, + enum bpf_diag_mod_reason reason); #endif /* __BPF_DIAGNOSTICS_H */ |
