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 2/6] bpf: Propagate async callback instructions to scheduling subprograms
Date: Wed, 05 Aug 2026 01:40:37 +0000	[thread overview]
Message-ID: <20260805014038.475151F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260805011517.1717238-3-memxor@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Critical] Unbounded `async_stats_subprog_cnt` causes OOB write in `push_async_cb` and OOB read/write in `account_current_path`.
--

--- Patch [2]: [PATCH bpf-next v6 2/6] bpf: Propagate async callback instructions to scheduling subprograms ---
commit e22fc6d02fda1f775515a1bbc9834113d0ba7767
Author: Kumar Kartikeya Dwivedi <memxor@gmail.com>

bpf: Propagate async callback instructions to scheduling subprograms

This commit propagates the instruction budget from asynchronous callback
executions back to the subprograms that originally scheduled them. It tracks
active subprogram IDs when a callback is queued and adds the inclusive
subtotal of the async frame-zero path to the saved scheduling subprograms.

> diff --git a/include/linux/bpf_verifier.h b/include/linux/bpf_verifier.h
> --- a/include/linux/bpf_verifier.h
> +++ b/include/linux/bpf_verifier.h
> @@ -447,6 +447,8 @@ static_assert(MAX_BPF_STACK / 8 <= (1 << 6));
>  struct bpf_verifier_state {
>  	/* call stack tracking */
>  	struct bpf_func_state *frame[MAX_CALL_FRAMES];
> +	u32 async_stats_subprog_ids[MAX_CALL_FRAMES];
> +	u32 async_stats_subprog_cnt;

[Severity: Critical]
Is it possible for the accumulated call chains of all ancestral scheduling
events to exceed MAX_CALL_FRAMES? If a BPF program chains async callbacks
(like a timer callback scheduling another timer callback), the count might
grow indefinitely.

>  	struct bpf_verifier_state *parent;
>  	/* Acquired reference states */
>  	struct bpf_reference_state *refs;

[ ... ]

> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> --- a/kernel/bpf/verifier.c
> +++ b/kernel/bpf/verifier.c

[ ... ]

> @@ -2293,6 +2298,12 @@ static struct bpf_verifier_state *push_async_cb(struct bpf_verifier_env *env,
>  			0 /* frameno within this callchain */,
>  			subprog /* subprog number within this prog */);
>  	elem->st.frame[0] = frame;
> +	cnt = env->cur_state->async_stats_subprog_cnt;
> +	memcpy(elem->st.async_stats_subprog_ids, env->cur_state->async_stats_subprog_ids,
> +	       cnt * sizeof(elem->st.async_stats_subprog_ids[0]));
> +	for (i = 0; i <= env->cur_state->curframe; i++)
> +		elem->st.async_stats_subprog_ids[cnt++] = env->cur_state->frame[i]->subprogno;
> +	elem->st.async_stats_subprog_cnt = cnt;

[Severity: Critical]
Can this loop overflow the async_stats_subprog_ids array? Since cnt is
incremented without checking against MAX_CALL_FRAMES, it appears this could
write past the end of the array, corrupting adjacent fields in struct
bpf_verifier_state like the parent pointer.

>  	return &elem->st;
>  }

[ ... ]

> @@ -9828,16 +9839,24 @@ static void account_processed_insns(struct bpf_verifier_env *env,
>  	if (caller)
>  		caller->insns_subtotal += insns;
>  	callee->insns_subtotal = 0;
> +	return insns;
>  }
>  
>  static void account_current_path(struct bpf_verifier_env *env)
>  {
>  	struct bpf_verifier_state *state = env->cur_state;
> -	int frame;
> +	u32 insns;
> +	int frame, i;
>  
>  	for (frame = state->curframe; frame >= 0; frame--)
> -		account_processed_insns(env, state->frame[frame],
> -					frame ? state->frame[frame - 1] : NULL);
> +		insns = account_processed_insns(env, state->frame[frame],
> +						frame ? state->frame[frame - 1] : NULL);
> +
> +	if (!state->async_stats_subprog_cnt)
> +		return;
> +
> +	for (i = 0; i < state->async_stats_subprog_cnt; i++)
> +		env->subprog_info[state->async_stats_subprog_ids[i]].insns_total += insns;

[Severity: Critical]
If async_stats_subprog_cnt was corrupted and grew beyond MAX_CALL_FRAMES, does
this result in an out-of-bounds read from async_stats_subprog_ids? This could
read from the corrupted parent pointer and cause an arbitrary kernel memory
write into env->subprog_info.

>  }

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

  reply	other threads:[~2026-08-05  1:40 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
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 [this message]
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=20260805014038.475151F000E9@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