bpf: correctly free bpf_scc_info objects referenced in env->scc_info
Eduard Zingerman
maintainerPATCH 1/1 bpf: correctly free bpf_scc_info objects referenced in env->scc_info
env->scc_info array contains references to bpf_scc_info objects allocated lazily in verifier.c:scc_visit_alloc(). env->scc_cnt was supposed to track env->scc_info array size in order to free referenced objects in verifier.c:free_states(). Initialization of env->scc_cnt was omitted in verifier.c:compute_scc(), which is fixed by this commit.
To reproduce the bug:
- build with CONFIG_DEBUG_KMEMLEAK
- boot and load bpf program with loops, e.g.:
./veristat -q pyperf180.bpf.o
- initiate memleak scan and check results:
echo scan > /sys/kernel/debug/kmemleak
cat /sys/kernel/debug/kmemleak
--- kernel/bpf/verifier.c | 3 +++ 1 file changed, 3 insertions(+)
kernel/bpf/verifier.c +3 -0
@@ -23114,6 +23114,8 @@ static void free_states(struct bpf_verifier_env *env)for (i =0 ; i < env->scc_cnt; ++i) { info = env->scc_info[i]; +if (!info) +continue ;for (j =0 ; j < info->num_visits; j++)free_backedges (&info->visits[j]);kvfree (info);
@@ -24554,6 +24556,7 @@ static int compute_scc(struct bpf_verifier_env *env) err = -ENOMEM ; goto exit; } + env->scc_cnt = next_scc_id; exit:kvfree (stack);kvfree (pre);
Signature · 1 line
2.50.1
Alexei Starovoitov
AppliedQuoted 7 lines · Eduard Zingerman
env->scc_infoarray contains references tobpf_scc_infoobjects allocated lazily in verifier.c:scc_visit_alloc().env->scc_cntwas supposed to trackenv->scc_infoarray size in order to free referenced objects in verifier.c:free_states(). Initialization ofenv->scc_cntwas omitted in verifier.c:compute_scc(), which is fixed by this commit.
Applied to bpf tree and slightly reworded above commit log and subject to use imperative language.
This patch was applied to bpf/bpf.git (master) by Alexei Starovoitov <[email protected]>:
Hello:
This patch was applied to bpf/bpf.git (master)
by Alexei Starovoitov <[email protected]>:
Quoted 8 lines · On Fri, 1 Aug 2025 16:23:30 -0700 you wrote:
env->scc_infoarray contains references tobpf_scc_infoobjects allocated lazily in verifier.c:scc_visit_alloc().env->scc_cntwas supposed to trackenv->scc_infoarray size in order to free referenced objects in verifier.c:free_states(). Initialization ofenv->scc_cntwas omitted in verifier.c:compute_scc(), which is fixed by this commit.[...]
Here is the summary with links:
- [bpf,v1] bpf: correctly free bpf_scc_info objects referenced in env->scc_info
https://git.kernel.org/bpf/bpf/c/989705e34ad3
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html
Quoted 7 lines · Eduard Zingerman
env->scc_infoarray contains references tobpf_scc_infoobjects allocated lazily in verifier.c:scc_visit_alloc().env->scc_cntwas supposed to trackenv->scc_infoarray size in order to free referenced objects in verifier.c:free_states(). Initialization ofenv->scc_cntwas omitted in verifier.c:compute_scc(), which is fixed by this commit.
Quoted 7 lines
To reproduce the bug:
- build withCONFIG_DEBUG_KMEMLEAK
- boot and load bpf program with loops, e.g.:
./veristat -q pyperf180.bpf.o
- initiate memleak scan and check results:
echo scan >/sys/kernel/debug/kmemleak
cat/sys/kernel/debug/kmemleak
Thanks for fixing this. Even though it's already applied, I did test it:
Signature · 1 line
Jens Axboe