Add a central enum for the verifier diagnostic categories used by structured reports. Keeping category names in one renderer helper makes later call sites choose a classification explicitly instead of formatting category strings locally. This adds no verifier call sites and keeps existing verifier output unchanged. Signed-off-by: Kumar Kartikeya Dwivedi --- kernel/bpf/diagnostics.c | 32 +++++++++++++++++++++++++++++--- kernel/bpf/diagnostics.h | 15 ++++++++++++++- 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/kernel/bpf/diagnostics.c b/kernel/bpf/diagnostics.c index a6684adc0c31..d9a103cf3a16 100644 --- a/kernel/bpf/diagnostics.c +++ b/kernel/bpf/diagnostics.c @@ -68,8 +68,34 @@ static void bpf_diag_vprint_indented(struct bpf_verifier_env *env, bpf_diag_print_wrapped_text(env, buf); } +static const char *bpf_diag_category_name(enum bpf_diag_category category) +{ + switch (category) { + case BPF_DIAG_CATEGORY_MEMORY_SAFETY: + return "Memory Safety"; + case BPF_DIAG_CATEGORY_REGISTER_TYPE_SAFETY: + return "Register Type Safety"; + case BPF_DIAG_CATEGORY_CALL_TYPE_SAFETY: + return "Call Type Safety"; + case BPF_DIAG_CATEGORY_RESOURCE_LIFETIME_SAFETY: + return "Resource Lifetime Safety"; + case BPF_DIAG_CATEGORY_EXECUTION_CONTEXT_SAFETY: + return "Execution Context Safety"; + case BPF_DIAG_CATEGORY_PROGRAM_STRUCTURE: + return "Program Structure"; + case BPF_DIAG_CATEGORY_POLICY: + return "Policy"; + case BPF_DIAG_CATEGORY_VERIFIER_LIMIT: + return "Verifier Limit"; + case BPF_DIAG_CATEGORY_VERIFIER_INTERNAL_ERROR: + default: + return "Verifier Internal Error"; + } +} + void bpf_diag_report_header(struct bpf_verifier_env *env, - const char *category, const char *problem) + enum bpf_diag_category category, + const char *problem) { char problem_buf[BPF_DIAG_MSG_LEN]; @@ -77,8 +103,8 @@ void bpf_diag_report_header(struct bpf_verifier_env *env, if (problem_buf[0] >= 'a' && problem_buf[0] <= 'z') problem_buf[0] += 'A' - 'a'; - verbose(env, "\nVerification failed: %s: %s\n", category, - problem_buf); + verbose(env, "\nVerification failed: %s: %s\n", + bpf_diag_category_name(category), problem_buf); } void bpf_diag_report_reason(struct bpf_verifier_env *env, const char *fmt, ...) diff --git a/kernel/bpf/diagnostics.h b/kernel/bpf/diagnostics.h index f13a939722bf..8bfc7104eeec 100644 --- a/kernel/bpf/diagnostics.h +++ b/kernel/bpf/diagnostics.h @@ -6,10 +6,23 @@ #include +enum bpf_diag_category { + BPF_DIAG_CATEGORY_MEMORY_SAFETY, + BPF_DIAG_CATEGORY_REGISTER_TYPE_SAFETY, + BPF_DIAG_CATEGORY_CALL_TYPE_SAFETY, + BPF_DIAG_CATEGORY_RESOURCE_LIFETIME_SAFETY, + BPF_DIAG_CATEGORY_EXECUTION_CONTEXT_SAFETY, + BPF_DIAG_CATEGORY_PROGRAM_STRUCTURE, + BPF_DIAG_CATEGORY_POLICY, + BPF_DIAG_CATEGORY_VERIFIER_LIMIT, + BPF_DIAG_CATEGORY_VERIFIER_INTERNAL_ERROR, +}; + struct bpf_verifier_env; void bpf_diag_report_header(struct bpf_verifier_env *env, - const char *category, const char *problem); + enum bpf_diag_category category, + const char *problem); void bpf_diag_report_reason(struct bpf_verifier_env *env, const char *fmt, ...) __printf(2, 3); void bpf_diag_report_section(struct bpf_verifier_env *env, const char *title); -- 2.53.0