[PATCH bpf-next v2 5/7] ARC, bpf: Fix memory leak in bpf_jit_free
From: Pu Lehui
Date: Sat Jul 25 2026 - 06:19:14 EST
From: Pu Lehui <pulehui@xxxxxxxxxx>
If a subprogram fails to JIT in jit_subprogs(), previously JITed
subprograms are freed. However, the generic bpf_jit_free() fails to
free their leftover jit_data, causing a memory leak.
Implement a custom bpf_jit_free() to free this data.
Fixes: f122668ddcce ("ARC: Add eBPF JIT support")
Reported-by: Sashiko <sashiko-bot@xxxxxxxxxx>
Signed-off-by: Pu Lehui <pulehui@xxxxxxxxxx>
---
arch/arc/net/bpf_jit_core.c | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/arch/arc/net/bpf_jit_core.c b/arch/arc/net/bpf_jit_core.c
index 639a2736f029..45a700f42cd4 100644
--- a/arch/arc/net/bpf_jit_core.c
+++ b/arch/arc/net/bpf_jit_core.c
@@ -1412,3 +1412,22 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_verifier_env *env, struct bpf_pr
return prog;
}
+
+void bpf_jit_free(struct bpf_prog *fp)
+{
+ if (fp->jited) {
+ struct bpf_jit_data *jit_data = fp->aux->jit_data;
+ struct bpf_binary_header *hdr = bpf_jit_binary_hdr(fp);
+
+ /* Cleanup for earlier subprogs if jit_subprogs() aborts */
+ if (jit_data) {
+ kfree(jit_data->bpf2insn)
+ kfree(jit_data);
+ }
+
+ bpf_jit_binary_free(hdr);
+ WARN_ON_ONCE(!bpf_prog_kallsyms_verify_off(fp));
+ }
+
+ bpf_prog_unlock_free(fp);
+}
--
2.34.1