mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: bot+bpf-ci@kernel.org
To: odys.yuan@gmail.com,ast@kernel.org,daniel@iogearbox.net,john.fastabend@gmail.com,andrii@kernel.org,eddyz87@gmail.com,memxor@gmail.com,martin.lau@linux.dev,song@kernel.org,yonghong.song@linux.dev,jolsa@kernel.org,emil@etsalapatis.com,ihor.solodrai@linux.dev,shuah@kernel.org
Cc: bpf@vger.kernel.org,linux-kernel@vger.kernel.org,linux-kselftest@vger.kernel.org,odys.yuan@gmail.com,ast@kernel.org,andrii@kernel.org,daniel@iogearbox.net,martin.lau@kernel.org,eddyz87@gmail.com,yonghong.song@linux.dev,mason@kernel.org,ihor.solodrai@linux.dev
Subject: Re: [PATCH bpf-next v2 02/22] bpf: Remap the verifier state through the patch list
Date: Fri, 30 Oct 2026 12:44:57 +0000 (UTC)	[thread overview]
Message-ID: <069cbe00bc6babf6b2e1585b0b945d21b001ebfe35a6367d53603d5ad8ddc981@mail.kernel.org> (raw)
In-Reply-To: <20261030-bpf-verifier-patch-batch-v2-2-55cd43439f7c@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 3432 bytes --]

> bpf: Remap the verifier state through the patch list

TL;DR: patch_list_adj_aux() may clear indirect_target for single-instruction
patches, so a gotox target could lose its ENDBR/BTI landing pad on IBT/BTI
kernels. Latent for now, as there are no callers yet; the comment and
changelog are also inaccurate.

> diff --git a/kernel/bpf/fixups.c b/kernel/bpf/fixups.c
> index f062ef7dd943..0697f66b1ffc 100644
> --- a/kernel/bpf/fixups.c
> +++ b/kernel/bpf/fixups.c
> @@ -380,6 +380,157 @@ struct bpf_prog *bpf_patch_insn_data(struct bpf_verifier_env *env, u32 off,

[ ... ]

> +/*
> + * Fill the aux data of the 'p->len' insns at 'slot' from the aux data 'old'
> + * of the insn they replace, the same way as adjust_insn_aux_data() does.
> + */
> +static void patch_list_adj_aux(struct bpf_prog *prog, struct bpf_insn_patch *p,
> +			       struct bpf_insn *patch,
> +			       const struct bpf_insn_aux_data *old,
> +			       struct bpf_insn_aux_data *slot)
> +{
> +	struct bpf_insn_aux_data *last = slot + p->len - 1;
> +	struct bpf_insn *orig = &p->orig;
> +	u32 i;
> +
> +	*last = *old;

[ ... ]

> +	/* indirect jumps to the replaced insn land on the first new one */
> +	if (last->indirect_target) {
> +		slot[0].indirect_target = 1;
> +		last->indirect_target = 0;
> +	}
> +}

For a single-instruction patch (p->len == 1), 'last' is 'slot + p->len - 1',
which is 'slot'.  Can this block clear the flag it just set?

    slot[0].indirect_target = 1;
    last->indirect_target = 0;     /* last == &slot[0] */

bpf_patch_list_add() only rejects !len, so len == 1 patches are accepted.
An instruction that is the target of an indirect jump (gotox) would lose
its indirect_target flag when it is replaced one-for-one.

adjust_insn_aux_data() does not behave this way.  For cnt == 1 it takes the
early return and leaves indirect_target alone.

bpf_insn_is_indirect_target() hands this flag to the JITs, and x86 do_jit()
emits ENDBR and arm64 build_insn() emits 'BTI J' only for flagged
instructions.  An indirect jump to an unflagged instruction would then hit
a missing landing pad on IBT/BTI-enabled kernels.

The len == 1 path also treats non_stack_access differently.  It keeps the
old marking, while adjust_insn_aux_data() recomputes it with
bpf_is_mem_insn(insn + off).

So the comment above patch_list_adj_aux() ("the same way as
adjust_insn_aux_data() does") and the commit message line "filling in the
aux data of patched instructions the way adjust_insn_aux_data() does" do
not hold for single-instruction patches.

This looks latent in this commit.  bpf_patch_list_add() and
bpf_patch_list_commit() have no callers here, and in the series the next
commit a3a12f55a1ad ("bpf: Apply single-instruction patches of the verifier
in place") applies len == 1 patches in place before any caller exists.  The
first callers arrive in a9b03b9b8596 ("bpf: Queue the rewrites of
bpf_do_misc_fixups()"), and 3c859182c47c ("bpf: Teach the patch list to
insert in front of an instruction") later adds a 'p->target != p->len - 1'
guard to this block.

Would it make sense to fold a3a12f55a1ad into this commit, so the helper is
correct on its own and its comment and the changelog are accurate?


---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

CI run summary: https://github.com/kernel-patches/bpf/actions/runs/41053659762

  reply	other threads:[~2026-10-30 12:44 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-30 11:51 [PATCH bpf-next v2 00/22] bpf: Replace bpf_patch_insn_data() with a list of deferred patches Qiliang Yuan
2026-10-30 11:51 ` [PATCH bpf-next v2 01/22] bpf: Add a list of deferred instruction patches Qiliang Yuan
2026-10-30 11:51 ` [PATCH bpf-next v2 02/22] bpf: Remap the verifier state through the patch list Qiliang Yuan
2026-10-30 12:44   ` bot+bpf-ci [this message]
2026-10-30 11:51 ` [PATCH bpf-next v2 03/22] bpf: Apply single-instruction patches of the verifier in place Qiliang Yuan
2026-10-30 11:51 ` [PATCH bpf-next v2 04/22] bpf: Queue the rewrites of bpf_do_misc_fixups() Qiliang Yuan
2026-10-30 11:51 ` [PATCH bpf-next v2 05/22] bpf: Expand a backward may_goto to gotol when patches push it out of range Qiliang Yuan
2026-10-30 12:59   ` bot+bpf-ci
2026-10-30 11:51 ` [PATCH bpf-next v2 06/22] bpf: Drop the constant delta from bpf_do_misc_fixups() Qiliang Yuan
2026-10-30 11:51 ` [PATCH bpf-next v2 07/22] bpf: Let the patch list remove instructions Qiliang Yuan
2026-10-31  5:29   ` Alexei Starovoitov
2026-10-30 11:51 ` [PATCH bpf-next v2 08/22] bpf: Remove dead code through the patch list Qiliang Yuan
2026-10-30 11:51 ` [PATCH bpf-next v2 09/22] bpf: Strip nops " Qiliang Yuan
2026-10-30 12:45   ` bot+bpf-ci
2026-10-30 11:51 ` [PATCH bpf-next v2 10/22] bpf: Batch the patches of bpf_opt_subreg_zext_lo32_rnd_hi32() Qiliang Yuan
2026-10-30 11:51 ` [PATCH bpf-next v2 11/22] bpf: Allow patching an instruction twice through the patch list Qiliang Yuan
2026-10-30 11:51 ` [PATCH bpf-next v2 12/22] bpf: Teach the patch list to insert in front of an instruction Qiliang Yuan
2026-10-30 12:44   ` bot+bpf-ci
2026-10-30 11:51 ` [PATCH bpf-next v2 13/22] bpf: Allow inserting in front of a queued patch Qiliang Yuan
2026-10-30 11:51 ` [PATCH bpf-next v2 14/22] bpf: Move bpf_convert_ctx_accesses() to the patch list Qiliang Yuan
2026-10-30 11:52 ` [PATCH bpf-next v2 15/22] bpf: Insert the may_goto counter setup through " Qiliang Yuan
2026-10-30 11:52 ` [PATCH bpf-next v2 16/22] bpf: Append the hidden subprog " Qiliang Yuan
2026-10-30 11:52 ` [PATCH bpf-next v2 17/22] bpf: Inline bpf_loop() calls " Qiliang Yuan
2026-10-30 11:52 ` [PATCH bpf-next v2 18/22] bpf: Apply the patch list without a verifier env Qiliang Yuan
2026-10-30 11:52 ` [PATCH bpf-next v2 19/22] bpf: Blind constants through the patch list Qiliang Yuan
2026-10-30 12:44   ` bot+bpf-ci
2026-10-30 11:52 ` [PATCH bpf-next v2 20/22] bpf: Remove the old instruction patching code Qiliang Yuan
2026-10-30 11:52 ` [PATCH bpf-next v2 21/22] selftests/bpf: Test jumps around patches of bpf_do_misc_fixups() Qiliang Yuan
2026-10-30 11:52 ` [PATCH bpf-next v2 22/22] selftests/bpf: Cover a backward may_goto pushed out of range by patches Qiliang Yuan

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=069cbe00bc6babf6b2e1585b0b945d21b001ebfe35a6367d53603d5ad8ddc981@mail.kernel.org \
    --to=bot+bpf-ci@kernel.org \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=emil@etsalapatis.com \
    --cc=ihor.solodrai@linux.dev \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=martin.lau@kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=mason@kernel.org \
    --cc=memxor@gmail.com \
    --cc=odys.yuan@gmail.com \
    --cc=shuah@kernel.org \
    --cc=song@kernel.org \
    --cc=yonghong.song@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

all inboxes | Powered by JetHome®