All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Kumar Kartikeya Dwivedi" <memxor@gmail.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next v4 02/16] bpf: Add source and instruction diagnostic context
Date: Thu, 13 Aug 2026 00:15:47 +0000	[thread overview]
Message-ID: <20260813001547.C11DB1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260812233326.3575958-3-memxor@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] bpf_disasm_kfunc_name() will trigger a NULL pointer dereference or mutate verifier state if diagnostic formatting is invoked before the add_kfuncs() pass completes.
--

--- Patch [2]: [PATCH bpf-next v4 02/16] bpf: Add source and instruction diagnostic context ---
commit ef91626322111071ba03bd2ef6640700c748dd5f
Author: Kumar Kartikeya Dwivedi <memxor@gmail.com>

bpf: Add source and instruction diagnostic context

Teach verifier diagnostics to annotate an instruction with BTF source
line information and nearby BPF instructions. 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
> --- a/kernel/bpf/diagnostics.c
> +++ b/kernel/bpf/diagnostics.c

[ ... ]

> @@ -35,6 +245,182 @@ static void diag_write(struct bpf_verifier_env *env, const char *fmt, ...)

[ ... ]

> +static const char *disasm_kfunc_name(void *private_data, const struct bpf_insn *insn)
> +{
> +	struct disasm_ctx *ctx = private_data;
> +
> +	return bpf_disasm_kfunc_name(ctx->env, insn);
> +}
> +
> +static void format_disasm_line(struct bpf_verifier_env *env, int insn_idx,
> +			       struct disasm_line *line)
> +{
> +	struct disasm_ctx ctx = { .env = env };
> +	struct bpf_insn *insn;
> +	const struct bpf_insn_cbs cbs = {
> +		.cb_call = disasm_kfunc_name,
> +		.cb_print = disasm_print,
> +		.private_data = &ctx,
> +	};

[Severity: High]
Can this sequence trigger a NULL pointer dereference or unsafe state
mutation?

If bpf_diag_source() handles an error during early structural validation
(before add_kfuncs() runs), it calls format_disasm_line() to print nearby
context instructions. 

If any instruction in this window is a module kfunc call, it invokes the
bpf_disasm_kfunc_name() callback shown above, which eventually cascades into
__find_kfunc_desc_btf() in kernel/bpf/verifier.c.

__find_kfunc_desc_btf() then executes:

tab = env->prog->aux->kfunc_btf_tab;
b = bsearch(&kf_btf, tab->descs, tab->nr_descs, ...);

If the kfunc BTF table hasn't been allocated yet, wouldn't dereferencing
tab cause a panic? 

Additionally, if the table is only partially initialized, wouldn't
__find_kfunc_desc_btf() mutate the table by appending and sorting new
entries during what is expected to be a read-only logging operation?

> +
> +	line->idx = insn_idx;
> +	line->valid = false;
> +	seq_buf_init(&ctx.seq, line->text, sizeof(line->text));

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260812233326.3575958-1-memxor@gmail.com?part=2

  reply	other threads:[~2026-08-13  0:15 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-12 23:33 [PATCH bpf-next v4 00/16] Redesign Verification Errors Kumar Kartikeya Dwivedi
2026-08-12 23:33 ` [PATCH bpf-next v4 01/16] bpf: Add verifier diagnostics report helpers Kumar Kartikeya Dwivedi
2026-08-12 23:41   ` sashiko-bot
2026-08-12 23:33 ` [PATCH bpf-next v4 02/16] bpf: Add source and instruction diagnostic context Kumar Kartikeya Dwivedi
2026-08-13  0:15   ` sashiko-bot [this message]
2026-08-12 23:33 ` [PATCH bpf-next v4 03/16] bpf: Add verifier diagnostic event log Kumar Kartikeya Dwivedi
2026-08-12 23:33 ` [PATCH bpf-next v4 04/16] bpf: Prune verifier diagnostics when switching paths Kumar Kartikeya Dwivedi
2026-08-12 23:33 ` [PATCH bpf-next v4 05/16] bpf: Track verifier register diagnostic events Kumar Kartikeya Dwivedi
2026-08-12 23:53   ` sashiko-bot
2026-08-12 23:33 ` [PATCH bpf-next v4 06/16] bpf: Track verifier reference " Kumar Kartikeya Dwivedi
2026-08-12 23:33 ` [PATCH bpf-next v4 07/16] bpf: Track verifier context " Kumar Kartikeya Dwivedi
2026-08-12 23:33 ` [PATCH bpf-next v4 08/16] bpf: Report Register Type Safety errors Kumar Kartikeya Dwivedi
2026-08-12 23:33 ` [PATCH bpf-next v4 09/16] bpf: Report Memory Safety bounds errors Kumar Kartikeya Dwivedi
2026-08-12 23:33 ` [PATCH bpf-next v4 10/16] bpf: Report Resource Lifetime reference leaks Kumar Kartikeya Dwivedi
2026-08-12 23:33 ` [PATCH bpf-next v4 11/16] bpf: Report Call Type Safety argument errors Kumar Kartikeya Dwivedi
2026-08-12 23:58   ` sashiko-bot
2026-08-12 23:33 ` [PATCH bpf-next v4 12/16] bpf: Report Execution Context Safety errors Kumar Kartikeya Dwivedi
2026-08-12 23:33 ` [PATCH bpf-next v4 13/16] bpf: Report Program Structure CFG errors Kumar Kartikeya Dwivedi
2026-08-12 23:33 ` [PATCH bpf-next v4 14/16] bpf: Report Policy helper and kfunc errors Kumar Kartikeya Dwivedi
2026-08-12 23:33 ` [PATCH bpf-next v4 15/16] bpf: Report Verifier Limit errors Kumar Kartikeya Dwivedi
2026-08-12 23:33 ` [PATCH bpf-next v4 16/16] bpf: Gate verifier diagnostics on log level Kumar Kartikeya Dwivedi
2026-08-13  1:38 ` [PATCH bpf-next v4 00/16] Redesign Verification Errors Eduard Zingerman

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=20260813001547.C11DB1F000E9@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.