All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: adubey@linux.ibm.com
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH v4 1/5] powerpc/bpf: fix alignment of long branch trampoline address
Date: Sun, 17 May 2026 18:02:01 +0000	[thread overview]
Message-ID: <20260517180201.87B8AC2BCB0@smtp.kernel.org> (raw)
In-Reply-To: <20260517214043.12975-2-adubey@linux.ibm.com>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [Critical] JIT Buffer Overflow due to undersized pass 0 allocation.
- [High] Flawed alignment arithmetic actively misaligns the trampoline address.
- [Medium] Inline epilogues silently bypass the alignment logic.
--

commit ce3a7a39e286dcf5c4eaad0616ec652506a106fa
Author: Abhishek Dubey <adubey@linux.ibm.com>
Subject: powerpc/bpf: fix alignment of long branch trampoline address

This commit attempts to align the dummy trampoline address field between
the OOL stub and the long branch stub to 8 bytes for memory compatibility.
It does this by emitting an optional NOP depending on the alignment of the
instruction pointer.

> diff --git a/arch/powerpc/net/bpf_jit_comp.c b/arch/powerpc/net/bpf_jit_comp.c
> --- a/arch/powerpc/net/bpf_jit_comp.c
> +++ b/arch/powerpc/net/bpf_jit_comp.c
> @@ -49,11 +49,34 @@ asm (
>  "	.popsection				;"
>  );
>  
> -void bpf_jit_build_fentry_stubs(u32 *image, struct codegen_context *ctx)
> +void bpf_jit_build_fentry_stubs(u32 *image, u32 *fimage, struct codegen_context *ctx)
>  {
>  	int ool_stub_idx, long_branch_stub_idx;
>  
>  	/*
> +	 * In the final pass, align the mis-aligned dummy_tramp_addr field
> +	 * in the fimage. The alignment NOP must appear before OOL stub,
> +	 * to make ool_stub_idx & long_branch_stub_idx constant from end.
> +	 */
> +#ifdef CONFIG_PPC64
> +	if (fimage && image) {

Since this condition evaluates to false during pass 0 (where fimage and
image are NULL), the alignment NOP is skipped and the required buffer size
in proglen is calculated without it.

During the final passes (1 and 2), if the NOP is emitted, could this increase
the instruction count beyond proglen and overflow into the subsequent
exception table or fixups? A later patch in the series may alter this area,
but does this patch introduce a self-contained memory corruption regression?

> +		/*
> +		 * pc points to first instruction of OOL stub,
> +		 * dummy_tramp_addr is past 4/3 instructions depending on
> +		 * CONFIG_PPC_FTRACE_OUT_OF_LINE is enabled/not respectively.
> +		 *
> +		 * The decision to emit alignment NOP must depend on the alignment
> +		 * of dummy_tramp_addr field.
> +		 */
> +		unsigned long pc = (unsigned long)fimage + CTX_NIA(ctx);
> +		pc += IS_ENABLED(CONFIG_PPC_FTRACE_OUT_OF_LINE) ? 4 : 3;

Because pc is an unsigned long byte address, adding 4 or 3 adds bytes
instead of the intended 16 or 12 bytes (since PowerPC instructions are 4
bytes long).

Adding 4 bytes to an 8-byte aligned address makes it unaligned. Does this
flawed arithmetic force the code to emit a NOP when the target address is
already aligned, thereby misaligning it?

> +		if (!IS_ALIGNED(pc, 8))
> +			EMIT(PPC_RAW_NOP());
> +	}
> +#endif

[ ... ]

> @@ -107,7 +131,7 @@ int bpf_jit_emit_exit_insn(u32 *image, struct codegen_context *ctx, int tmp_reg,
>  		PPC_JMP(ctx->alt_exit_addr);
>  	} else {
>  		ctx->alt_exit_addr = ctx->idx * 4;
> -		bpf_jit_build_epilogue(image, ctx);
> +		bpf_jit_build_epilogue(image, NULL, ctx);
>  	}

Because fimage is strictly passed as NULL here, the if (fimage && image)
check in bpf_jit_build_fentry_stubs() will always evaluate to false.

Will this cause the alignment NOP to be unconditionally skipped for all inline
epilogues, leaving their dummy_tramp_addr fields unaligned?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260517214043.12975-1-adubey@linux.ibm.com?part=1

  reply	other threads:[~2026-05-17 18:02 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-17 21:40 [PATCH v4 0/5] powerpc/bpf: Add support for verifier selftest adubey
2026-05-17 21:40 ` [PATCH v4 1/5] powerpc/bpf: fix alignment of long branch trampoline address adubey
2026-05-17 18:02   ` sashiko-bot [this message]
2026-05-17 18:30   ` bot+bpf-ci
2026-05-18  7:18   ` Hari Bathini
2026-05-17 21:40 ` [PATCH v4 2/5] powerpc/bpf: Move out dummy_tramp_addr after Long branch stub adubey
2026-05-17 18:23   ` sashiko-bot
2026-05-17 18:30   ` bot+bpf-ci
2026-05-18  7:25   ` Hari Bathini
2026-05-18  7:53     ` Hari Bathini
2026-05-17 21:40 ` [PATCH v4 3/5] selftest/bpf: Fixing powerpc JIT disassembly failure adubey
2026-05-17 18:18   ` bot+bpf-ci
2026-05-17 18:38   ` sashiko-bot
2026-05-17 21:40 ` [PATCH v4 4/5] selftest/bpf: Enable verifier selftest for powerpc64 adubey
2026-05-17 18:18   ` bot+bpf-ci
2026-05-17 21:40 ` [PATCH v4 5/5] selftest/bpf: Add tailcall " adubey
2026-05-17 19:14   ` sashiko-bot
2026-05-18 11:44 ` [PATCH v4 0/5] powerpc/bpf: Add support for verifier selftest Christophe Leroy (CS GROUP)

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=20260517180201.87B8AC2BCB0@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 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.