summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShardul Bankar <shardulsb08@gmail.com>2025-10-14 17:30:37 +0530
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2026-01-17 16:39:34 +0100
commit805e88b15d6f85d2b9a653b6a87a11b579e2668c (patch)
tree363c079ea41ddf885252c42e46c8a2dc445b2105
parent98115f8dc31e68b0c6d1de2b88c7b6a51e773f35 (diff)
bpf: test_run: Fix ctx leak in bpf_prog_test_run_xdp error path
commit 7f9ee5fc97e14682e36fe22ae2654c07e4998b82 upstream. 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: fe9544ed1a2e ("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 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--net/bpf/test_run.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/net/bpf/test_run.c b/net/bpf/test_run.c
index 59edba6994c3..ab8d21372b7d 100644
--- a/net/bpf/test_run.c
+++ b/net/bpf/test_run.c
@@ -1344,7 +1344,7 @@ int bpf_prog_test_run_xdp(struct bpf_prog *prog, const union bpf_attr *kattr,
goto free_ctx;
if (kattr->test.data_size_in - meta_sz < ETH_HLEN)
- return -EINVAL;
+ goto free_ctx;
data = bpf_test_init(kattr, linear_sz, max_linear_sz, headroom, tailroom);
if (IS_ERR(data)) {