From: sashiko-bot@kernel.org
To: "Pu Lehui" <pulehui@huaweicloud.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next v2 6/7] riscv, bpf: Adjust bpf_func to account for CFI offset in bpf_jit_free
Date: Sat, 25 Jul 2026 10:27:52 +0000 [thread overview]
Message-ID: <20260725102752.DC3BD1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260725102020.2287770-7-pulehui@huaweicloud.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [Critical] bpf_jit_free() ignores the return value of bpf_jit_binary_pack_finalize(), leading to a double free and use-after-free of the ro_header if finalization fails.
--
--- Patch [6]: [PATCH bpf-next v2 6/7] riscv, bpf: Adjust bpf_func to account for CFI offset in bpf_jit_free ---
commit 3086c59fad7254d5809adea2a09ea130ccb95d10
Author: Pu Lehui <pulehui@huawei.com>
riscv, bpf: Adjust bpf_func to account for CFI offset in bpf_jit_free
This commit subtracts cfi_get_offset() from prog->bpf_func to correctly
restore the original JITed allocation address before freeing it. This prevents
potential invalid memory frees when CFI is enabled.
> diff --git a/arch/riscv/net/bpf_jit_core.c b/arch/riscv/net/bpf_jit_core.c
> index cbfcd287ea166..059db1adeaf8d 100644
> --- a/arch/riscv/net/bpf_jit_core.c
> +++ b/arch/riscv/net/bpf_jit_core.c
> @@ -237,6 +237,7 @@ void bpf_jit_free(struct bpf_prog *prog)
> kvfree(jit_data->ctx.offset);
> kfree(jit_data);
> }
> + prog->bpf_func = (void *)prog->bpf_func - cfi_get_offset();
> hdr = bpf_jit_binary_pack_hdr(prog);
> bpf_jit_binary_pack_free(hdr, NULL);
[Severity: Critical]
This is a pre-existing issue, but does ignoring the return value of
bpf_jit_binary_pack_finalize() called just above this block lead to a double
free?
If bpf_jit_binary_pack_finalize() fails during text patching, it frees the
ro_header internally and returns an error.
Since that error is ignored in bpf_jit_free(), the execution unconditionally
continues down to:
hdr = bpf_jit_binary_pack_hdr(prog);
bpf_jit_binary_pack_free(hdr, NULL);
Can this lead to a use-after-free when bpf_jit_binary_pack_free() tries to
read the header size, followed by a double free of the memory chunk?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260725102020.2287770-1-pulehui@huaweicloud.com?part=6
next prev parent reply other threads:[~2026-07-25 10:27 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-25 10:20 [PATCH bpf-next v2 0/7] Fixes for bpf_jit_free Pu Lehui
2026-07-25 10:20 ` [PATCH bpf-next v2 1/7] bpf, arm64: Fix memory leak in bpf_jit_free Pu Lehui
2026-07-25 10:31 ` sashiko-bot
2026-07-25 10:20 ` [PATCH bpf-next v2 2/7] s390/bpf: " Pu Lehui
2026-07-25 10:27 ` sashiko-bot
2026-07-25 10:20 ` [PATCH bpf-next v2 3/7] parisc: " Pu Lehui
2026-07-25 10:28 ` sashiko-bot
2026-07-25 10:20 ` [PATCH bpf-next v2 4/7] bpf, sparc64: " Pu Lehui
2026-07-25 10:29 ` sashiko-bot
2026-07-25 10:20 ` [PATCH bpf-next v2 5/7] ARC, bpf: " Pu Lehui
2026-07-25 10:29 ` sashiko-bot
2026-07-25 10:20 ` [PATCH bpf-next v2 6/7] riscv, bpf: Adjust bpf_func to account for CFI offset " Pu Lehui
2026-07-25 10:27 ` sashiko-bot [this message]
2026-07-25 10:20 ` [PATCH bpf-next v2 7/7] 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=20260725102752.DC3BD1F000E9@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox