BPF List
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Saket Kumar Bhaskar" <skb99@linux.ibm.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH v13 5/8] powerpc/bpf: Move out dummy_tramp_addr after Long branch stub
Date: Mon, 31 Aug 2026 07:35:36 +0000	[thread overview]
Message-ID: <20260831073536.85CEA1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <647e37d4e0049cc9c9a6977ac112a445f6ced6c8.1788154635.git.skb99@linux.ibm.com>

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

Pre-existing issues:
- [High] Preexisting boundary asymmetry in branch range validation causes silent failure and NOP patching when trampoline targets are exactly 32MB away.
--

commit 5b58234b51abd3de6209e164ca3ba6723fb0f569
Author: Abhishek Dubey <adubey@linux.ibm.com>
powerpc/bpf: Move out dummy_tramp_addr after Long branch stub

This patch moves the long branch address field to the bottom of the long
branch stub to prevent disassembly failure. It updates the dummy_tramp_addr
field offset calculation from the end of the program to reflect its new
location.

> diff --git a/arch/powerpc/net/bpf_jit_comp.c b/arch/powerpc/net/bpf_jit_comp.c
> index 8ca36a933c7ae..c2717f0d9cdd4 100644
> --- a/arch/powerpc/net/bpf_jit_comp.c
> +++ b/arch/powerpc/net/bpf_jit_comp.c
[ ... ]
> @@ -1425,10 +1427,12 @@ int bpf_arch_text_poke(void *ip, enum bpf_text_poke_type old_t,
>  	 * 1. Update the address in the long branch stub:
>  	 * If new_addr is out of range, we will have to use the long branch stub, so patch new_addr
>  	 * here. Otherwise, revert to dummy_tramp, but only if we had patched old_addr here.
> +	 *
> +	 * dummy_tramp_addr moved to bottom of long branch stub.
>  	 */
>  	if ((new_addr && !is_offset_in_branch_range(new_addr - ip)) ||
>  	    (old_addr && !is_offset_in_branch_range(old_addr - ip)))
> -		ret = patch_ulong((void *)(bpf_func_end - bpf_jit_long_branch_stub - SZL),
> +		ret = patch_ulong((void *)(bpf_func_end - SZL), /* SZL: dummy_tramp_addr offset */
>  				  (new_addr && !is_offset_in_branch_range(new_addr - ip)) ?
>  				  (unsigned long)new_addr : (unsigned long)dummy_tramp);
>  	if (ret)

[Severity: High]
This is a pre-existing issue, but looking at bpf_arch_text_poke(), there
appears to be a boundary asymmetry in the branch range validation just above
this hunk.

Earlier in the function, the offset is calculated as ip - old_addr and
ip - new_addr:

	if (old_addr) {
		if (is_offset_in_branch_range(ip - old_addr))
			create_branch(&old_inst, ip, (unsigned long)old_addr, branch_flags);
		else
...
	if (new_addr) {
		if (is_offset_in_branch_range(ip - new_addr))
			create_branch(&new_inst, ip, (unsigned long)new_addr, branch_flags);
		else

While in the hunk above it correctly calculates new_addr - ip and
old_addr - ip.

Does this cause silent failures when trampoline targets are exactly 32MB away?

If new_addr is exactly 0x2000000 bytes ahead of ip, the true offset (0x2000000)
is out of range. However, ip - new_addr evaluates to -0x2000000, which
is_offset_in_branch_range() incorrectly sees as IN range.

If this happens, the code enters the block and calls create_branch(), which
correctly calculates the true offset, fails its internal bounds check, and
returns an error.

Because bpf_arch_text_poke() ignores the return value of create_branch() in
this path, does this leave new_inst as a NOP?

If so, bpf_modify_inst() would silently patch a NOP into the execution path
instead of a branch to the long branch stub, dropping the BPF call entirely.

Similarly, if the target is 0x2000000 bytes behind ip, the true offset
-0x2000000 is valid, but ip - old_addr evaluates to 0x2000000, incorrectly
triggering the else path.

Could this mismatch cause bpf_modify_inst() to fail (as the instruction
currently in memory is a direct branch, not a stub branch), leaving the system
unable to detach the BPF program?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1788154635.git.skb99@linux.ibm.com?part=5

  reply	other threads:[~2026-08-31  7:35 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-31  7:15 [PATCH v13 0/8] powerpc/bpf: address missing verifier selftest coverage Saket Kumar Bhaskar
2026-08-31  7:15 ` [PATCH v13 1/8] powerpc64/bpf: fix compare instruction emitted for tailcall Saket Kumar Bhaskar
2026-08-31  7:15 ` [PATCH v13 2/8] powerpc64/bpf: fix percpu private stack leak on JIT failure Saket Kumar Bhaskar
2026-08-31  7:32   ` sashiko-bot
2026-08-31  7:16 ` [PATCH v13 3/8] powerpc/bpf: fix buffer overflow in JIT for large BPF programs Saket Kumar Bhaskar
2026-08-31  8:24   ` bot+bpf-ci
2026-08-31  7:16 ` [PATCH v13 4/8] powerpc/bpf: fix alignment of long branch trampoline address Saket Kumar Bhaskar
2026-08-31  8:12   ` bot+bpf-ci
2026-08-31  7:16 ` [PATCH v13 5/8] powerpc/bpf: Move out dummy_tramp_addr after Long branch stub Saket Kumar Bhaskar
2026-08-31  7:35   ` sashiko-bot [this message]
2026-08-31  7:16 ` [PATCH v13 6/8] selftests/bpf: Fix powerpc JIT disassembly failure Saket Kumar Bhaskar
2026-08-31  8:12   ` bot+bpf-ci
2026-08-31  7:16 ` [PATCH v13 7/8] selftests/bpf: Enable verifier selftest for powerpc64 Saket Kumar Bhaskar
2026-08-31  7:16 ` [PATCH v13 8/8] selftests/bpf: Add tailcall " Saket Kumar Bhaskar
2026-08-31  8:12   ` bot+bpf-ci

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=20260831073536.85CEA1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=skb99@linux.ibm.com \
    /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