BPF List
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Lukas Stockner" <lukas@lukasstockner.de>, bpf@vger.kernel.org
Subject: Re: [PATCH v2 7/7] powerpc32/bpf: don't fold MOV into jump targets
Date: Tue, 01 Dec 2026 17:24:54 +0000	[thread overview]
Message-ID: <sashiko-outbox-243834@kernel.org> (raw)
In-Reply-To: <20261201165313.413960-8-lukas@lukasstockner.de>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] bpf: jump_target lost across verifier patching in
  bpf_insn_is_jump_target()
- [High] powerpc32/bpf: bpf_insn_is_jump_target() returns false when env
  is NULL
--

commit fa51b274b4205b85901c47e5fab0c0ea5cb7a081
Author: Lukas Stockner <lukas@lukasstockner.de>

powerpc32/bpf: don't fold MOV into jump targets

This commit adds bpf_insn_is_jump_target() and uses it in the 32-bit PowerPC
BPF JIT to avoid folding a preceding BPF_MOV into an ALU instruction when the
ALU instruction is a jump target.

> diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
> index facb0d6d2e8d8..466c20a7aa5ad 100644
> --- a/kernel/bpf/core.c
> +++ b/kernel/bpf/core.c
> @@ -1984,6 +1984,15 @@ bool bpf_insn_is_indirect_target(const struct bpf_verifier_env *env, const struc
>  	return env->insn_aux_data[insn_idx].indirect_target;
>  }
>  
> +bool bpf_insn_is_jump_target(const struct bpf_verifier_env *env, const struct bpf_prog *prog,
> +				 int insn_idx)
> +{
> +	if (!env)
> +		return false;

[Severity: High]
Should bpf_insn_is_jump_target() return true when env is NULL?

Classic BPF programs migrated via bpf_migrate_filter() call
bpf_prog_select_runtime() with env == NULL.  Returning false allows
bpf_jit_build_body() to still fold a preceding BPF_MOV64_REG(BPF_REG_A, ...)
(such as from BPF_MISC | BPF_TXA) into a jump-target ALU instruction on
BPF_REG_A, corrupting the accumulator when a branch jumps to that ALU
instruction.

> +	insn_idx += prog->aux->subprog_start;
> +	return env->insn_aux_data[insn_idx].jump_target;
> +}

[Severity: High]
Can env->insn_aux_data[insn_idx].jump_target be cleared or stale by the time
the JIT runs?

jump_target is populated during bpf_check_cfg(), before verifier instruction
patching.  When a jump-target instruction is expanded into a multi-instruction
patch, jumps are redirected to slot[p->target], but patch_list_adj_aux()
copies the old aux entry to slot[p->self] and only moves indirect_target and
nospec to slot[p->target]:

kernel/bpf/fixups.c:patch_list_adj_aux() {
    ...
	/* jumps to the replaced insn land on p->target, so the barrier goes before it */
	if (p->target != p->self) {
		slot[p->target].indirect_target = last->indirect_target;
		slot[p->target].nospec = last->nospec;
		last->indirect_target = last->nospec = 0;
	}
}

Because bpf_jit_needs_zext() is true on PowerPC,
bpf_opt_subreg_zext_lo32_rnd_hi32() expands any zero-extended 32-bit ALU
instruction into the ALU instruction at slot[0] (p->target) followed by
BPF_ZEXT_REG at slot[1] (p->self).  That leaves jump_target cleared on the
actual jump target at slot[0], so bpf_insn_is_jump_target() returns false and
bpf_jit_build_body() still folds a preceding BPF_MOV into it.

Similarly, when a jump-target instruction is deleted (p->len == 0, such as in
bpf_opt_remove_nops()), patch_list_remap_aux() drops its jump_target flag
instead of propagating it to the next surviving instruction.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261201165313.413960-1-lukas@lukasstockner.de?part=7

      reply	other threads:[~2026-12-01 17:24 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01 16:53 [PATCH v2 0/7] powerpc32/bpf: fix BPF-to-BPF calls and instruction folding Lukas Stockner
2026-12-01 16:53 ` [PATCH v2 1/7] powerpc32/bpf: fix argument passing for subprograms Lukas Stockner
2026-12-01 16:53 ` [PATCH v2 2/7] powerpc32/bpf: fetch fifth argument in BPF subprograms Lukas Stockner
2026-12-01 16:53 ` [PATCH v2 3/7] powerpc32/bpf: mark all argument registers seen in function calls Lukas Stockner
2026-12-01 16:53 ` [PATCH v2 4/7] powerpc32/bpf: don't fold MOVSX into following instruction Lukas Stockner
2026-12-01 16:53 ` [PATCH v2 5/7] powerpc32/bpf: fix MOV folding with in-place operations Lukas Stockner
2026-12-01 17:18   ` sashiko-bot
2026-12-01 16:53 ` [PATCH v2 6/7] powerpc32/bpf: use src2_reg for all ALU operations Lukas Stockner
2026-12-01 17:13   ` sashiko-bot
2026-12-01 16:53 ` [PATCH v2 7/7] powerpc32/bpf: don't fold MOV into jump targets Lukas Stockner
2026-12-01 17:24   ` 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=sashiko-outbox-243834@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=lukas@lukasstockner.de \
    --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