Skip to content

Commit f6fddc6

Browse files
shardulsb08Martin KaFai Lau
authored andcommitted
bpf: Fix memory leak in __lookup_instance error path
When __lookup_instance() allocates a func_instance structure but fails to allocate the must_write_set array, it returns an error without freeing the previously allocated func_instance. This causes a memory leak of 192 bytes (sizeof(struct func_instance)) each time this error path is triggered. Fix by freeing 'result' on must_write_set allocation failure. Fixes: b3698c3 ("bpf: callchain sensitive stack liveness tracking using CFG") Reported-by: BPF Runtime Fuzzer (BRF) Signed-off-by: Shardul Bankar <shardulsb08@gmail.com> Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org> Acked-by: Eduard Zingerman <eddyz87@gmail.com> Link: https://patch.msgid.link/20251016063330.4107547-1-shardulsb08@gmail.com
1 parent 0c1999e commit f6fddc6

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

kernel/bpf/liveness.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,10 @@ static struct func_instance *__lookup_instance(struct bpf_verifier_env *env,
195195
return ERR_PTR(-ENOMEM);
196196
result->must_write_set = kvcalloc(subprog_sz, sizeof(*result->must_write_set),
197197
GFP_KERNEL_ACCOUNT);
198-
if (!result->must_write_set)
198+
if (!result->must_write_set) {
199+
kvfree(result);
199200
return ERR_PTR(-ENOMEM);
201+
}
200202
memcpy(&result->callchain, callchain, sizeof(*callchain));
201203
result->insn_cnt = subprog_sz;
202204
hash_add(liveness->func_instances, &result->hl_node, key);

0 commit comments

Comments
 (0)