BPF List
 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 v6 1/6] bpf: Track verifier instruction stats for each subprogram
Date: Wed, 05 Aug 2026 01:26:15 +0000	[thread overview]
Message-ID: <20260805012615.8F99C1F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260805011517.1717238-2-memxor@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] A NULL pointer dereference occurs in `account_current_path()` when handling an allocation failure during `pop_stack()`.
--

--- Patch [1]: [PATCH bpf-next v6 1/6] bpf: Track verifier instruction stats for each subprogram ---
commit 026daf56a558e1775b6ccd02d21953d3b59b6a28
Author: Kumar Kartikeya Dwivedi <memxor@gmail.com>

bpf: Track verifier instruction stats for each subprogram
    
This patch tracks verifier instruction counts for each subprogram
independently. It records both own and inclusive instruction counts,
updating the subtotals during function returns and when a path terminates
or is pruned.

> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> index 7439afdc851a7..88e7ea6fbe73a 100644
> --- a/kernel/bpf/verifier.c
> +++ b/kernel/bpf/verifier.c

[ ... ]

> @@ -9807,6 +9809,37 @@ static int set_task_work_schedule_callback_state(struct bpf_verifier_env *env,
>  
>  static bool is_rbtree_lock_required_kfunc(u32 btf_id);
>  
> +static void account_processed_insn(struct bpf_verifier_env *env)
> +{
> +	struct bpf_func_state *frame = cur_func(env);
> +
> +	env->insn_processed++;
> +	frame->insns_subtotal++;
> +	env->subprog_info[frame->subprogno].insns_own++;
> +}
> +
> +static void account_processed_insns(struct bpf_verifier_env *env,
> +				    struct bpf_func_state *callee,
> +				    struct bpf_func_state *caller)
> +{
> +	u32 insns = callee->insns_subtotal;
                    ^^^^^^^^^^^^^^^^^^^^^^

[Severity: High]
Could `callee` be NULL here on error paths?

If a memory allocation failure happens during `pop_stack()` (for example, if
`kzalloc_obj()` fails while allocating a new frame during the verifier state
copy), the state can be partially copied, leaving `state->frame[i]` as NULL
for some `i <= state->curframe`.

When `do_check_common()` handles this error, it unconditionally calls
`account_current_path()`. The loop in `account_current_path()` iterates up to
`state->curframe` and passes `state->frame[frame]` to
`account_processed_insns()`, which would then unconditionally dereference the
NULL pointer.

Should we check `if (!callee)` before attempting to read its subtotal?

> +
> +	env->subprog_info[callee->subprogno].insns_total += insns;
> +	if (caller)
> +		caller->insns_subtotal += insns;
> +	callee->insns_subtotal = 0;
> +}
> +
> +static void account_current_path(struct bpf_verifier_env *env)
> +{
> +	struct bpf_verifier_state *state = env->cur_state;
> +	int frame;
> +
> +	for (frame = state->curframe; frame >= 0; frame--)
> +		account_processed_insns(env, state->frame[frame],
> +					frame ? state->frame[frame - 1] : NULL);
> +}

[ ... ]

> @@ -18680,6 +18717,7 @@ static int do_check_common(struct bpf_verifier_env *env, int subprog)
>  
>  	ret = do_check(env);
>  out:
> +	account_current_path(env);
>  	if (!ret && pop_log)
>  		bpf_vlog_reset(&env->log, 0);
>  	free_states(env);

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

  reply	other threads:[~2026-08-05  1:26 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-05  1:15 [PATCH bpf-next v6 0/6] Improve stack depth verification stats output Kumar Kartikeya Dwivedi
2026-08-05  1:15 ` [PATCH bpf-next v6 1/6] bpf: Track verifier instruction stats for each subprogram Kumar Kartikeya Dwivedi
2026-08-05  1:26   ` sashiko-bot [this message]
2026-08-05  1:15 ` [PATCH bpf-next v6 2/6] bpf: Propagate async callback instructions to scheduling subprograms Kumar Kartikeya Dwivedi
2026-08-05  1:40   ` sashiko-bot
2026-08-05 18:18   ` Eduard Zingerman
2026-08-05  1:15 ` [PATCH bpf-next v6 3/6] bpf: Show more useful info in stack depth stats Kumar Kartikeya Dwivedi
2026-08-05  1:28   ` sashiko-bot
2026-08-05  1:15 ` [PATCH bpf-next v6 4/6] selftests/bpf: Adjust veristat stack depth parsing Kumar Kartikeya Dwivedi
2026-08-05  1:15 ` [PATCH bpf-next v6 5/6] selftests/bpf: Test stack depth stats without BTF subprog names Kumar Kartikeya Dwivedi
2026-08-05  1:15 ` [PATCH bpf-next v6 6/6] selftests/bpf: Test subprogram instruction statistics Kumar Kartikeya Dwivedi
2026-08-05  1:23   ` sashiko-bot

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=20260805012615.8F99C1F00A3A@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