From: sashiko-bot@kernel.org
To: adubey@linux.ibm.com
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH v7 7/7] powerpc/bpf: fix buffer overflow in JIT for large BPF programs
Date: Thu, 11 Jun 2026 12:01:27 +0000 [thread overview]
Message-ID: <20260611120128.1C0471F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260611153826.31187-8-adubey@linux.ibm.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
New issues:
- [Critical] The patch introduces a guaranteed buffer overflow for BPF programs larger than 32MB by failing to clear `cgctx.alt_exit_addr` before the second size-calculation pass (pass 0).
Pre-existing issues:
- [Critical] This problem wasn't introduced by this patch, but the patch exposes it fatally: missing update of `addrs[fp->len]` during JIT passes causes `BPF_EXIT` to branch to uninitialized memory, crashing the kernel.
--
commit 7f31e323d670ec5c6b2df079f524622af737b8e6
Author: Abhishek Dubey <adubey@linux.ibm.com>
powerpc/bpf: fix buffer overflow in JIT for large BPF programs
During pass 0 (size calculation), exit_addr is 0 since addrs[fp->len]
is not yet populated. bpf_jit_emit_exit_insn() treats a zero exit_addr
as in-range and skips bpf_jit_build_epilogue(), so the alternate inline
epilogue instructions are not counted in alloclen.
Closes: https://lore.kernel.org/bpf/20260529015855.364704-2-adubey@linux.ibm.com/T/#mfcb23909d977b949727cca4f59ee56a13fd69b92
> diff --git a/arch/powerpc/net/bpf_jit_comp.c b/arch/powerpc/net/bpf_jit_comp.c
> index 2e2993bc646e5..032918f192b1f 100644
> --- a/arch/powerpc/net/bpf_jit_comp.c
> +++ b/arch/powerpc/net/bpf_jit_comp.c
> @@ -128,11 +128,10 @@ void bpf_jit_build_fentry_stubs(u32 *image, u32 *fimage, struct codegen_context
> int bpf_jit_emit_exit_insn(u32 *image, u32 *fimage, struct codegen_context *ctx,
> int tmp_reg, long exit_addr)
> {
> - if (!exit_addr || is_offset_in_branch_range(exit_addr - (ctx->idx * 4))) {
> + if (exit_addr && is_offset_in_branch_range(exit_addr - (long)(ctx->idx * 4))) {
> PPC_JMP(exit_addr);
> - } else if (ctx->alt_exit_addr) {
> - if (WARN_ON(!is_offset_in_branch_range((long)ctx->alt_exit_addr - (ctx->idx * 4))))
> - return -1;
> + } else if (ctx->alt_exit_addr &&
> + is_offset_in_branch_range(ctx->alt_exit_addr - (long)(ctx->idx * 4))) {
[Severity: Critical]
For programs larger than 32MB, bpf_int_jit_compile() runs a second size
calculation pass (pass 0). Since cgctx.alt_exit_addr isn't cleared before
this second pass, could this condition evaluate to true using the stale
offset from the first pass?
If this happens, pass 0 would skip the inline epilogue and emit a single
jump instead, undercalculating the buffer size. Would passes 1 and 2 then
write past the end of the allocated buffer, corrupting kernel memory?
[Severity: Critical]
This is a pre-existing issue, but this patch appears to expose it fatally.
In bpf_int_jit_compile(), addrs[fp->len] is set after pass 0:
addrs[fp->len] = cgctx.idx * 4;
However, it is never updated inside the subsequent loop for passes 1 and 2.
Because pass 0 now generates a significantly larger body (building a full
inline epilogue for the first BPF_EXIT), passes 1 and 2 will shrink. Since
addrs[fp->len] isn't updated for the new shrunken body sizes, BPF_EXIT
instructions in pass 2 will branch to the old pass 0 offset.
This offset points past the actual generated epilogue into the breakpoint
padding. Could this cause a kernel panic when the BPF program executes?
> PPC_JMP(ctx->alt_exit_addr);
> } else {
> ctx->alt_exit_addr = ctx->idx * 4;
> bpf_jit_build_epilogue(image, fimage, ctx);
> }
>
> return 0;
> }
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260611153826.31187-1-adubey@linux.ibm.com?part=7
prev parent reply other threads:[~2026-06-11 12:01 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-11 15:38 [PATCH v7 0/7] powerpc/bpf: Add support for verifier selftest adubey
2026-06-11 15:38 ` [PATCH v7 1/7] powerpc/bpf: fix alignment of long branch trampoline address adubey
2026-06-11 15:38 ` [PATCH v7 2/7] powerpc/bpf: Move out dummy_tramp_addr after Long branch stub adubey
2026-06-11 11:52 ` sashiko-bot
2026-06-11 12:18 ` bot+bpf-ci
2026-06-11 15:38 ` [PATCH v7 3/7] selftest/bpf: Fixing powerpc JIT disassembly failure adubey
2026-06-11 11:47 ` sashiko-bot
2026-06-11 15:38 ` [PATCH v7 4/7] selftest/bpf: Enable verifier selftest for powerpc64 adubey
2026-06-11 15:38 ` [PATCH v7 5/7] powerpc64/bpf: fix compare instruction emitted for tailcall adubey
2026-06-11 15:38 ` [PATCH v7 6/7] selftest/bpf: Add tailcall verifier selftest for powerpc64 adubey
2026-06-11 15:38 ` [PATCH v7 7/7] powerpc/bpf: fix buffer overflow in JIT for large BPF programs adubey
2026-06-11 12:01 ` sashiko-bot [this message]
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=20260611120128.1C0471F00893@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=adubey@linux.ibm.com \
--cc=bpf@vger.kernel.org \
--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