From: sashiko-bot@kernel.org
To: "Kumar Kartikeya Dwivedi" <memxor@gmail.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next v1 03/17] bpf: Add source and instruction diagnostic context
Date: Fri, 05 Jun 2026 08:48:14 +0000 [thread overview]
Message-ID: <20260605084814.729271F00899@smtp.kernel.org> (raw)
In-Reply-To: <20260605063412.974640-4-memxor@gmail.com>
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] Missing array bounds check in `bpf_diag_func_name()` when resolving hidden subprograms.
- [Medium] Tight loop coupling silently drops BPF instructions when the diagnostic is triggered near the top of a file.
- [Low] Potential loss of the visual alignment caret (`^-- `) due to `scnprintf` truncation if the source code is heavily indented.
--
commit e84e87b559a751018ace3ee43b2b61b8014f1c4e
Author: Kumar Kartikeya Dwivedi <memxor@gmail.com>
bpf: Add source and instruction diagnostic context
This patch adds source line and nearby instruction annotations to the BPF
verifier diagnostics. The renderer keeps source text in a fixed-width lane
and prints instructions in a stable right-hand gutter.
> diff --git a/kernel/bpf/diagnostics.c b/kernel/bpf/diagnostics.c
> index d9a103cf3a16e..652d4627c2b0f 100644
> --- a/kernel/bpf/diagnostics.c
> +++ b/kernel/bpf/diagnostics.c
[ ... ]
> +static const char *bpf_diag_func_name(struct bpf_verifier_env *env, u32 insn_idx)
> +{
> + const struct bpf_subprog_info *subprog;
> + const struct bpf_func_info *info;
> + const struct btf_type *type;
> + int subprogno;
> +
> + if (!env->prog->aux->func_info || !env->prog->aux->btf)
> + return NULL;
> +
> + subprog = bpf_find_containing_subprog(env, insn_idx);
> + if (!subprog)
> + return NULL;
> +
> + subprogno = subprog - env->subprog_info;
> + info = &env->prog->aux->func_info[subprogno];
[Severity: High]
If the verifier dynamically adds a hidden subprogram like the exception
callback, env->subprog_cnt increments but env->prog->aux->func_info_cnt
remains the same since it represents user-supplied BTF data. Can this code
cause an out-of-bounds read on the func_info array if a diagnostic is
triggered inside a hidden subprogram? Should this verify that subprogno is
less than env->prog->aux->func_info_cnt before accessing the array?
> + type = btf_type_by_id(env->prog->aux->btf, info->type_id);
> + if (!type)
> + return NULL;
[ ... ]
> +static void bpf_diag_print_source_annotation(struct bpf_verifier_env *env,
> + int line_width, int indent,
> + const char *label,
> + const char *msg)
> +{
> + char first_prefix[128], next_prefix[128], text[BPF_DIAG_MSG_LEN];
> +
> + scnprintf(first_prefix, sizeof(first_prefix), " %*s | %*s^-- ",
> + line_width + 4, "", indent, "");
[Severity: Low]
Since the indent comes from user-supplied BTF line info, what happens if the
source code has heavy indentation (for example, over 110 spaces)? Will
first_prefix truncate here and silently drop the "^-- " visual caret used
for alignment?
> + scnprintf(next_prefix, sizeof(next_prefix), " %*s | %*s ",
> + line_width + 4, "", indent, "");
> + scnprintf(text, sizeof(text), "%s: %s", label, msg);
[ ... ]
> +void bpf_diag_report_source(struct bpf_verifier_env *env, u32 insn_idx,
> + char marker, const char *fmt, ...)
> +{
[ ... ]
> + for (line_num = start_line; line_num <= end_line; line_num++) {
> + const char *line;
> + int row = line_num - src.line_num;
> +
> + line = line_num == src.line_num ?
> + src.line :
> + bpf_diag_find_source_line(env, src.file_name_off, line_num);
> +
> + bpf_diag_print_source_insn_line(env,
> + line_num == src.line_num ?
> + ">>> " : " ",
> + width, line_num, line,
> + &diag_insn[row + BPF_DIAG_INSN_CONTEXT],
[Severity: Medium]
When a diagnostic is triggered near the top of a file, start_line is clamped
to 1. Because the instruction layout is coupled to the source line loop
using the line_num difference, doesn't this skip iterating over the earlier
BPF instructions that were already correctly populated in the diag_insn
buffer? Could this drop valid instructions from the verifier log output,
making diagnostics harder to read?
> + insn_idx, insn_width);
> + if (line_num == src.line_num)
> + bpf_diag_print_source_annotation(env, width, indent,
> + label, msg);
> + }
> +}
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260605063412.974640-1-memxor@gmail.com?part=3
next prev parent reply other threads:[~2026-06-05 8:48 UTC|newest]
Thread overview: 52+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-05 6:33 [PATCH bpf-next v1 00/17] Redesign Verification Errors Kumar Kartikeya Dwivedi
2026-06-05 6:33 ` [PATCH bpf-next v1 01/17] bpf: Add verifier diagnostics report helpers Kumar Kartikeya Dwivedi
2026-06-05 6:42 ` sashiko-bot
2026-06-05 7:40 ` bot+bpf-ci
2026-06-05 18:58 ` Eduard Zingerman
2026-06-05 6:33 ` [PATCH bpf-next v1 02/17] bpf: Define verifier diagnostic categories Kumar Kartikeya Dwivedi
2026-06-05 19:10 ` Eduard Zingerman
2026-06-05 6:33 ` [PATCH bpf-next v1 03/17] bpf: Add source and instruction diagnostic context Kumar Kartikeya Dwivedi
2026-06-05 8:48 ` sashiko-bot [this message]
2026-06-05 20:22 ` Eduard Zingerman
2026-06-05 20:55 ` Kumar Kartikeya Dwivedi
2026-06-05 21:07 ` Eduard Zingerman
2026-06-05 6:33 ` [PATCH bpf-next v1 04/17] bpf: Track verifier branch diagnostic history Kumar Kartikeya Dwivedi
2026-06-05 6:50 ` sashiko-bot
2026-06-05 7:57 ` bot+bpf-ci
2026-06-05 21:41 ` Eduard Zingerman
2026-06-05 21:37 ` Eduard Zingerman
2026-06-05 6:33 ` [PATCH bpf-next v1 05/17] bpf: Track verifier register " Kumar Kartikeya Dwivedi
2026-06-05 6:53 ` sashiko-bot
2026-06-05 7:40 ` bot+bpf-ci
2026-06-05 22:31 ` Eduard Zingerman
2026-06-05 6:33 ` [PATCH bpf-next v1 06/17] bpf: Track verifier reference " Kumar Kartikeya Dwivedi
2026-06-05 6:33 ` [PATCH bpf-next v1 07/17] bpf: Track verifier context " Kumar Kartikeya Dwivedi
2026-06-05 6:46 ` sashiko-bot
2026-06-05 7:22 ` bot+bpf-ci
2026-06-05 6:33 ` [PATCH bpf-next v1 08/17] bpf: Report Register Type Safety errors Kumar Kartikeya Dwivedi
2026-06-05 6:57 ` sashiko-bot
2026-06-05 7:23 ` bot+bpf-ci
2026-06-05 6:33 ` [PATCH bpf-next v1 09/17] bpf: Report Memory Safety bounds errors Kumar Kartikeya Dwivedi
2026-06-05 6:45 ` sashiko-bot
2026-06-05 7:57 ` bot+bpf-ci
2026-06-05 6:34 ` [PATCH bpf-next v1 10/17] bpf: Report Resource Lifetime reference leaks Kumar Kartikeya Dwivedi
2026-06-05 6:45 ` sashiko-bot
2026-06-05 7:22 ` bot+bpf-ci
2026-06-05 6:34 ` [PATCH bpf-next v1 11/17] bpf: Report Call Type Safety argument errors Kumar Kartikeya Dwivedi
2026-06-05 6:47 ` sashiko-bot
2026-06-05 7:23 ` bot+bpf-ci
2026-06-05 6:34 ` [PATCH bpf-next v1 12/17] bpf: Report Execution Context Safety errors Kumar Kartikeya Dwivedi
2026-06-05 6:46 ` sashiko-bot
2026-06-05 7:23 ` bot+bpf-ci
2026-06-05 6:34 ` [PATCH bpf-next v1 13/17] bpf: Report Program Structure CFG errors Kumar Kartikeya Dwivedi
2026-06-05 6:51 ` sashiko-bot
2026-06-05 7:22 ` bot+bpf-ci
2026-06-05 6:34 ` [PATCH bpf-next v1 14/17] bpf: Report Policy helper and kfunc errors Kumar Kartikeya Dwivedi
2026-06-05 7:02 ` sashiko-bot
2026-06-05 6:34 ` [PATCH bpf-next v1 15/17] bpf: Report Verifier Limit errors Kumar Kartikeya Dwivedi
2026-06-05 6:53 ` sashiko-bot
2026-06-05 7:40 ` bot+bpf-ci
2026-06-05 6:34 ` [PATCH bpf-next v1 16/17] bpf: Report Verifier Internal errors Kumar Kartikeya Dwivedi
2026-06-05 6:34 ` [PATCH bpf-next v1 17/17] bpf: Gate verifier diagnostics on log level Kumar Kartikeya Dwivedi
2026-06-05 6:58 ` sashiko-bot
2026-06-05 7:40 ` bot+bpf-ci
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260605084814.729271F00899@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=memxor@gmail.com \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox