Re: [PATCH bpf-next 2/4] LoongArch: BPF: Fix memory leak in bpf_jit_free

Tiezhu Yang <[email protected]> Fri, 24 Jul 2026 16:04:50 +0800
Newsgroups dev.linux.lists.loongarch,org.kernel.vger.bpf,org.kernel.vger.linux-kernel
Message-ID <[email protected]>
Cc: Huacai Chen <[email protected]> [email protected]

On 2026/7/22 下午7:27, Pu Lehui wrote:
> From: Pu Lehui <[email protected]>
> 
> When bpf_int_jit_compile() is called for subprograms, it returns early
> during the first pass (!prog->is_func || extra_pass is false), keeping
> ctx->offset alive for the subsequent extra pass.
> 
> If JIT compilation fails for a later subprogram, the BPF core aborts and
> calls bpf_jit_free() to clean up the first subprogram. However,
> bpf_jit_free() fails to free jit_data->ctx.offset, which causes a memory
> leak of the JIT context offsets array.
> 
> Fix this by adding the missing kvfree(jit_data->ctx.offset) in
> bpf_jit_free().
> 
> Fixes: 4ab17e762b34 ("LoongArch: BPF: Use BPF prog pack allocator")
> Reported-by: Sashiko <[email protected]>
> Signed-off-by: Pu Lehui <[email protected]>
> ---
>   arch/loongarch/net/bpf_jit.c | 1 +
>   1 file changed, 1 insertion(+)
> 
> diff --git a/arch/loongarch/net/bpf_jit.c b/arch/loongarch/net/bpf_jit.c
> index 2738b4db1165..3d3ed1677d01 100644
> --- a/arch/loongarch/net/bpf_jit.c
> +++ b/arch/loongarch/net/bpf_jit.c
> @@ -2361,6 +2361,7 @@ void bpf_jit_free(struct bpf_prog *prog)
>   		 */
>   		if (jit_data) {
>   			bpf_jit_binary_pack_finalize(jit_data->ro_header, jit_data->header);
> +			kvfree(jit_data->ctx.offset);
>   			kfree(jit_data);
>   		}
>   		hdr = bpf_jit_binary_pack_hdr(prog);
> 

Here is the link:
https://lore.kernel.org/bpf/[email protected]/

Acked-by: Tiezhu Yang <[email protected]>

Thanks,
Tiezhu