All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Pu Lehui" <pulehui@huaweicloud.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next v3 3/9] parisc: Fix memory leak in bpf_jit_free
Date: Sat, 25 Jul 2026 15:54:18 +0000	[thread overview]
Message-ID: <20260725155419.4B7DC1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260725154915.2488611-4-pulehui@huaweicloud.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] Pre-existing memory leak of the allocated JIT image (`jit_data->header`) in `bpf_int_jit_compile()` if `build_body()` fails during an iteration after the image is allocated.
--

--- Patch [3]: [PATCH bpf-next v3 3/9] parisc: Fix memory leak in bpf_jit_free ---
commit 91fdce2769b7bfc645bd4e9356cd152dd1568159
Author: Pu Lehui <pulehui@huawei.com>

parisc: Fix memory leak in bpf_jit_free

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.

> diff --git a/arch/parisc/net/bpf_jit_core.c b/arch/parisc/net/bpf_jit_core.c
> index 172770132440d..ef63c38bdf151 100644
> --- a/arch/parisc/net/bpf_jit_core.c
> +++ b/arch/parisc/net/bpf_jit_core.c
> @@ -178,6 +178,25 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_verifier_env *env, struct bpf_pr
>  	goto out_offset;
>  }

[Severity: High]
This is a pre-existing issue, but does bpf_int_jit_compile() leak
jit_data->header on some error paths?

Looking at bpf_int_jit_compile(), if build_body() fails during an iteration
after the image is allocated:

	for (i = 0; i < NR_JIT_ITERATIONS; i++) {
		...
		if (build_body(ctx, extra_pass, ctx->offset))
			goto out_err;
		...
		if (ctx->ninsns == prev_ninsns) {
			if (jit_data->header)
				break;
			...
			jit_data->header = bpf_jit_binary_alloc(...);

The code jumps to out_err, which falls through to out_offset (seen above):

out_err:
	if (extra_pass) {
		...
	}
	goto out_offset;

However, the out_offset cleanup block only frees ctx->offset and jit_data,
and skips freeing the already allocated jit_data->header:

out_offset:
		kfree(ctx->offset);
		kfree(jit_data);
		prog->aux->jit_data = NULL;

Could this lead to a memory leak of the JIT image buffer?

[ ... ]

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260725154915.2488611-1-pulehui@huaweicloud.com?part=3

  reply	other threads:[~2026-07-25 15:54 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-25 15:49 [PATCH bpf-next v3 0/9] Fixes for bpf_jit_free Pu Lehui
2026-07-25 15:49 ` [PATCH bpf-next v3 1/9] bpf: Extract the bpf_jit_binary_hdr helper Pu Lehui
2026-07-25 15:49 ` [PATCH bpf-next v3 2/9] s390/bpf: Fix memory leak in bpf_jit_free Pu Lehui
2026-07-25 15:49 ` [PATCH bpf-next v3 3/9] parisc: " Pu Lehui
2026-07-25 15:54   ` sashiko-bot [this message]
2026-07-25 15:49 ` [PATCH bpf-next v3 4/9] bpf, sparc64: " Pu Lehui
2026-07-25 15:49 ` [PATCH bpf-next v3 5/9] ARC, bpf: " Pu Lehui
2026-07-25 15:49 ` [PATCH bpf-next v3 6/9] bpf, arm64: " Pu Lehui
2026-07-25 16:01   ` sashiko-bot
2026-07-25 15:49 ` [PATCH bpf-next v3 7/9] bpf, arm64: Fix private stack leak when JIT failed Pu Lehui
2026-07-25 15:55   ` sashiko-bot
2026-07-25 15:49 ` [PATCH bpf-next v3 8/9] riscv, bpf: Adjust bpf_func to account for CFI offset in bpf_jit_free Pu Lehui
2026-07-25 15:57   ` sashiko-bot
2026-07-25 15:49 ` [PATCH bpf-next v3 9/9] bpf: Fix double-free RO header " Pu Lehui

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260725155419.4B7DC1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=pulehui@huaweicloud.com \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.