From: sashiko-bot@kernel.org
To: "Eduard Zingerman" <eddyz87@gmail.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH RFC bpf-next 2/6] bpf: compute loops hierarchy
Date: Tue, 26 May 2026 10:07:38 +0000 [thread overview]
Message-ID: <20260526100738.DD69D1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260526-better-1m-reporting-v1-2-51e4f2c59780@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] bpf_compute_loops() incorrectly uses kfree() to free memory allocated with kvcalloc().
--
commit ef2f37474f7b031f628d088384c6723a83200838
Author: Eduard Zingerman <eddyz87@gmail.com>
bpf: compute loops hierarchy
This commit adds an analysis phase to the BPF verifier to compute the
loops hierarchy using a non-recursive algorithm. It records the loop
header per instruction and tracks loop irreducibility to provide better
callchain profiling.
> diff --git a/kernel/bpf/loops.c b/kernel/bpf/loops.c
> new file mode 100644
> index 0000000000000..4bbcd923e960a
> --- /dev/null
> +++ b/kernel/bpf/loops.c
[ ... ]
> +int bpf_compute_loops(struct bpf_verifier_env *env)
> +{
> + struct bpf_insn_aux_data *aux = env->insn_aux_data;
> + int i, err = 0, len = env->prog->len;
> + struct loops_dfs dfs = {};
> +
> + dfs.dfs_pos = kvcalloc(len, sizeof(int), GFP_KERNEL_ACCOUNT);
> + dfs.state = kvcalloc(len, sizeof(struct dfs_state), GFP_KERNEL_ACCOUNT);
> + dfs.stack = kvcalloc(len, sizeof(int), GFP_KERNEL_ACCOUNT);
> + if (!dfs.dfs_pos || !dfs.state || !dfs.stack) {
> + err = -ENOMEM;
> + goto out;
> + }
[ ... ]
> +out:
> + kfree(dfs.dfs_pos);
> + kfree(dfs.stack);
> + kfree(dfs.state);
[Severity: High]
Should these be freed using kvfree() instead of kfree()?
Since these arrays are allocated using kvcalloc() and BPF programs can contain
up to 1 million instructions, the allocations can grow to several megabytes.
In such cases, kvcalloc() will fall back to vmalloc().
Calling kfree() on a vmalloc address will blindly call virt_to_page() for a
virtual address, which can lead to a kernel panic or slab corruption.
> + return err;
> +}
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260526-better-1m-reporting-v1-0-51e4f2c59780@gmail.com?part=2
next prev parent reply other threads:[~2026-05-26 10:07 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-26 9:30 [PATCH RFC bpf-next 0/6] bpf: better error reporting when verifier hits 1M instructions limit Eduard Zingerman
2026-05-26 9:30 ` [PATCH RFC bpf-next 1/6] bpf: move live registers and scc printout to a standalone function Eduard Zingerman
2026-05-26 9:30 ` [PATCH RFC bpf-next 2/6] bpf: compute loops hierarchy Eduard Zingerman
2026-05-26 10:05 ` bot+bpf-ci
2026-05-26 11:18 ` Eduard Zingerman
2026-05-26 10:07 ` sashiko-bot [this message]
2026-05-26 9:30 ` [PATCH RFC bpf-next 3/6] selftests/bpf: test cases for loop hierarchy computation Eduard Zingerman
2026-05-26 10:25 ` sashiko-bot
2026-05-26 11:22 ` Eduard Zingerman
2026-05-26 9:30 ` [PATCH RFC bpf-next 4/6] bpf: report hot simulated callchains when 1M instructions limit is met Eduard Zingerman
2026-05-26 10:05 ` bot+bpf-ci
2026-05-26 11:24 ` Eduard Zingerman
2026-05-26 10:45 ` sashiko-bot
2026-05-26 11:31 ` Eduard Zingerman
2026-05-26 9:30 ` [PATCH RFC bpf-next 5/6] bpf: report register diff summary for hot callchains Eduard Zingerman
2026-05-26 10:05 ` bot+bpf-ci
2026-05-26 11:11 ` sashiko-bot
2026-05-26 11:36 ` Eduard Zingerman
2026-05-26 9:30 ` [PATCH RFC bpf-next 6/6] selftests/bpf: test budget exhaustion profiling report 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=20260526100738.DD69D1F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=eddyz87@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