Skip to content

Commit 7f9ee5f

Browse files
shardulsb08Martin KaFai Lau
authored andcommitted
bpf: test_run: Fix ctx leak in bpf_prog_test_run_xdp error path
Fix a memory leak in bpf_prog_test_run_xdp() where the context buffer allocated by bpf_ctx_init() is not freed when the function returns early due to a data size check. On the failing path: ctx = bpf_ctx_init(...); if (kattr->test.data_size_in - meta_sz < ETH_HLEN) return -EINVAL; The early return bypasses the cleanup label that kfree()s ctx, leading to a leak detectable by kmemleak under fuzzing. Change the return to jump to the existing free_ctx label. Fixes: fe9544e ("bpf: Support specifying linear xdp packet data size for BPF_PROG_TEST_RUN") 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: Jiri Olsa <jolsa@kernel.org> Acked-by: Daniel Borkmann <daniel@iogearbox.net> Link: https://patch.msgid.link/20251014120037.1981316-1-shardulsb08@gmail.com
1 parent 3a86608 commit 7f9ee5f

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

net/bpf/test_run.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1269,7 +1269,7 @@ int bpf_prog_test_run_xdp(struct bpf_prog *prog, const union bpf_attr *kattr,
12691269
goto free_ctx;
12701270

12711271
if (kattr->test.data_size_in - meta_sz < ETH_HLEN)
1272-
return -EINVAL;
1272+
goto free_ctx;
12731273

12741274
data = bpf_test_init(kattr, linear_sz, max_linear_sz, headroom, tailroom);
12751275
if (IS_ERR(data)) {

0 commit comments

Comments
 (0)