Skip to content

Commit fbfdf00

Browse files
eddyz87Kernel Patches Daemon
authored andcommitted
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 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]> Signed-off-by: Eduard Zingerman <[email protected]>
1 parent 837ec5d commit fbfdf00

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
@@ -23114,6 +23114,8 @@ static void free_states(struct bpf_verifier_env *env)
2311423114

2311523115
for (i = 0; i < env->scc_cnt; ++i) {
2311623116
info = env->scc_info[i];
23117+
if (!info)
23118+
continue;
2311723119
for (j = 0; j < info->num_visits; j++)
2311823120
free_backedges(&info->visits[j]);
2311923121
kvfree(info);
@@ -24554,6 +24556,7 @@ static int compute_scc(struct bpf_verifier_env *env)
2455424556
err = -ENOMEM;
2455524557
goto exit;
2455624558
}
24559+
env->scc_cnt = next_scc_id;
2455724560
exit:
2455824561
kvfree(stack);
2455924562
kvfree(pre);

0 commit comments

Comments
 (0)