Skip to content

Commit 372235d

Browse files
bpf: Fix memory leak of bpf_scc_info objects
JIRA: https://issues.redhat.com/browse/RHEL-78204 commit 1b30d44 Author: Eduard Zingerman <[email protected]> Date: Fri Aug 1 16:23:30 2025 -0700 bpf: Fix memory leak of bpf_scc_info objects 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(). Fix initialization of env->scc_cnt that was omitted in verifier.c:compute_scc(). 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 Fixes: c9e3190 ("bpf: propagate read/precision marks over state graph backedges") Reported-by: Jens Axboe <[email protected]> Closes: https://lore.kernel.org/bpf/CAADnVQKXUWg9uRCPD5ebRXwN4dmBCRUFFM7kN=GxymYz3zU25A@mail.gmail.com/T/ Suggested-by: Alexei Starovoitov <[email protected]> Tested-by: Jens Axboe <[email protected]> Signed-off-by: Eduard Zingerman <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]> Signed-off-by: Jerome Marchand <[email protected]>
1 parent 495d0ad commit 372235d

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

kernel/bpf/verifier.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23118,6 +23118,8 @@ static void free_states(struct bpf_verifier_env *env)
2311823118

2311923119
for (i = 0; i < env->scc_cnt; ++i) {
2312023120
info = env->scc_info[i];
23121+
if (!info)
23122+
continue;
2312123123
for (j = 0; j < info->num_visits; j++)
2312223124
free_backedges(&info->visits[j]);
2312323125
kvfree(info);
@@ -24558,6 +24560,7 @@ static int compute_scc(struct bpf_verifier_env *env)
2455824560
err = -ENOMEM;
2455924561
goto exit;
2456024562
}
24563+
env->scc_cnt = next_scc_id;
2456124564
exit:
2456224565
kvfree(stack);
2456324566
kvfree(pre);

0 commit comments

Comments
 (0)