All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Kumar Kartikeya Dwivedi" <memxor@gmail.com>, bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next v1 06/29] bpf: Keep last insn's aux data in add_hidden_subprog()
Date: Wed, 11 Nov 2026 14:38:11 +0000	[thread overview]
Message-ID: <sashiko-outbox-209175@kernel.org> (raw)
In-Reply-To: <4e0c5d6d96b2e917ff52effe483ec90daf0e2ac0.1794399387.git.memxor@gmail.com>

Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [Critical] bpf: misplaced nospec flag in adjust_insn_aux_data() [1]
--

commit f29fbac112320caad2087aefcfcc0181b977759d
Author: Kumar Kartikeya Dwivedi <memxor@gmail.com>

bpf: Keep last insn's aux data in add_hidden_subprog()

This commit swaps the aux data of the original last instruction and the end
of the patch in add_hidden_subprog() so that the original instruction keeps
its aux data (while leaving indirect_target on the first instruction).

> diff --git a/kernel/bpf/fixups.c b/kernel/bpf/fixups.c
> index eb5a5bca5c8d5..8597b443d5619 100644
> --- a/kernel/bpf/fixups.c
> +++ b/kernel/bpf/fixups.c
> @@ -2280,8 +2280,10 @@ static int add_hidden_subprog(struct bpf_verifier_env *env, struct bpf_insn *pat
>  {
>  	struct bpf_subprog_info *info = env->subprog_info;
>  	int err, cnt = env->subprog_cnt;
> +	struct bpf_insn_aux_data *aux;
>  	struct bpf_insn *last;
>  	struct bpf_prog *prog;
> +	bool indirect;
>  
>  	/* We only reserve one slot for hidden subprogs in subprog_info. */
>  	if (env->hidden_subprog_cnt) {
> @@ -2299,6 +2301,17 @@ static int add_hidden_subprog(struct bpf_verifier_env *env, struct bpf_insn *pat
>  	if (err)
>  		return err;
>  	prog = env->prog;
> +	/*
> +	 * The patch starts with the original last insn, but the commit moved that
> +	 * insn's aux data to the end of the patch: give it back to the insn. All
> +	 * but indirect_target, which the commit left with the insn, since an
> +	 * indirect jump to it lands there still, see patch_list_adj_aux().
> +	 */
> +	aux = &env->insn_aux_data[prog->len - len];
> +	indirect = aux->indirect_target;
> +	swap(aux[0], aux[len - 1]);
> +	aux[0].indirect_target = indirect;
> +	aux[len - 1].indirect_target = false;
>  	info[cnt + 1].start = info[cnt].start;
>  	info[cnt].start = prog->len - len + 1;
>  	/* The patch ends with the exit. */

[Severity: Critical]
This problem wasn't introduced by this patch, but can patch_list_adj_aux()
misplace the nospec flag [1] when expanding a single instruction into a
multi-instruction sequence?

kernel/bpf/fixups.c:patch_list_adj_aux() {
	...
	*last = *old;
	/* Recompute zext_dst: the last insn of the patch need not be the patched one. */
	last->zext_dst = bpf_insn_def32(prog, &patch[p->len - 1]) >= 0;
	memset(slot, 0, sizeof(*slot) * (p->len - 1));
	...
	/* indirect jumps to the replaced insn land on p->target */
	if (last->indirect_target && p->target != p->len - 1) {
		slot[p->target].indirect_target = 1;
		last->indirect_target = 0;
	}
}

During verification with Spectre v1 mitigation active, a bpf_loop() call can
be eligible for inlining on an architectural path while a speculative path to
the same instruction fails in check_func_args() with -EACCES, causing
do_check() to set insn_aux->nospec on the call instruction and stop verifying
that speculative path.

When bpf_optimize_bpf_loop() -> inline_bpf_loop() later replaces the call
with a 19-instruction sequence, patch_list_adj_aux() moves old aux data to
last and zeroes the preceding entries while only restoring indirect_target to
slot[p->target].  As a result, bpf_convert_ctx_accesses() emits BPF_ST_NOSPEC()
before the last instruction of the inlined loop instead of at its entry,
allowing speculative execution to enter the loop body and invoke the callback
with unverified state.

[1] https://sashiko.dev/#/bug/linux-9fe39327-eb21-4b95-9330-3ea552a3b9fc

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1794399387.git.memxor@gmail.com?part=6

  reply	other threads:[~2026-11-11 14:38 UTC|newest]

Thread overview: 58+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-11 12:56 [PATCH bpf-next v1 00/29] Exceptions - Resource Cleanup - Redux Kumar Kartikeya Dwivedi
2026-11-11 12:56 ` [PATCH bpf-next v1 01/29] bpf: Record where JITs save callee-saved registers Kumar Kartikeya Dwivedi
2026-11-11 12:57 ` [PATCH bpf-next v1 02/29] bpf: Add bpf_throw_unwind() and an arch entry hook Kumar Kartikeya Dwivedi
2026-11-11 14:45   ` sashiko-bot
2026-11-11 12:57 ` [PATCH bpf-next v1 03/29] bpf, x86: Capture registers in a native bpf_throw() entry Kumar Kartikeya Dwivedi
2026-11-11 12:57 ` [PATCH bpf-next v1 04/29] bpf, arm64: " Kumar Kartikeya Dwivedi
2026-11-11 12:57 ` [PATCH bpf-next v1 05/29] bpf: Restore callee-saved registers from unwound frames Kumar Kartikeya Dwivedi
2026-11-11 14:41   ` sashiko-bot
2026-11-11 12:57 ` [PATCH bpf-next v1 06/29] bpf: Keep last insn's aux data in add_hidden_subprog() Kumar Kartikeya Dwivedi
2026-11-11 14:38   ` sashiko-bot [this message]
2026-11-11 12:57 ` [PATCH bpf-next v1 07/29] bpf: Add one allocator for hidden stack slots Kumar Kartikeya Dwivedi
2026-11-11 14:04   ` bot+bpf-ci
2026-11-11 15:15   ` sashiko-bot
2026-11-11 12:57 ` [PATCH bpf-next v1 08/29] bpf: Add flags and release kfuncs to the dtor registry Kumar Kartikeya Dwivedi
2026-11-11 13:33   ` bot+bpf-ci
2026-11-11 15:36   ` sashiko-bot
2026-11-11 12:57 ` [PATCH bpf-next v1 09/29] bpf: Register cleanup destructors for more types Kumar Kartikeya Dwivedi
2026-11-11 14:04   ` bot+bpf-ci
2026-11-11 15:00   ` sashiko-bot
2026-11-11 12:57 ` [PATCH bpf-next v1 10/29] bpf: Record where JITed frames keep the BPF stack Kumar Kartikeya Dwivedi
2026-11-11 12:57 ` [PATCH bpf-next v1 11/29] bpf: Give every reference an owner frame Kumar Kartikeya Dwivedi
2026-11-11 13:33   ` bot+bpf-ci
2026-11-11 12:57 ` [PATCH bpf-next v1 12/29] bpf: Release resources in hidden slots on bpf_throw() Kumar Kartikeya Dwivedi
2026-11-11 14:04   ` bot+bpf-ci
2026-11-11 15:30   ` sashiko-bot
2026-11-11 12:57 ` [PATCH bpf-next v1 13/29] bpf: Track held resources in hidden stack slots Kumar Kartikeya Dwivedi
2026-11-11 14:04   ` bot+bpf-ci
2026-11-11 16:12   ` sashiko-bot
2026-11-11 12:57 ` [PATCH bpf-next v1 14/29] bpf: Describe held resources at throw sites Kumar Kartikeya Dwivedi
2026-11-11 14:04   ` bot+bpf-ci
2026-11-11 12:57 ` [PATCH bpf-next v1 15/29] bpf: Describe handles in registers " Kumar Kartikeya Dwivedi
2026-11-11 14:04   ` bot+bpf-ci
2026-11-11 16:11   ` sashiko-bot
2026-11-11 12:57 ` [PATCH bpf-next v1 16/29] bpf: Describe locks " Kumar Kartikeya Dwivedi
2026-11-11 14:04   ` bot+bpf-ci
2026-11-11 16:04   ` sashiko-bot
2026-11-11 12:57 ` [PATCH bpf-next v1 17/29] bpf: Apply hidden slot limits only when a slot is needed Kumar Kartikeya Dwivedi
2026-11-11 16:31   ` sashiko-bot
2026-11-11 12:57 ` [PATCH bpf-next v1 18/29] bpf: Allow a callee to leave resources with its caller Kumar Kartikeya Dwivedi
2026-11-11 14:04   ` bot+bpf-ci
2026-11-11 16:41   ` sashiko-bot
2026-11-11 12:57 ` [PATCH bpf-next v1 19/29] bpf: Allow a callee to release its caller's resources Kumar Kartikeya Dwivedi
2026-11-11 17:02   ` sashiko-bot
2026-11-11 12:57 ` [PATCH bpf-next v1 20/29] bpf: Transfer a reference to the callee that releases it Kumar Kartikeya Dwivedi
2026-11-11 14:04   ` bot+bpf-ci
2026-11-11 16:57   ` sashiko-bot
2026-11-11 12:57 ` [PATCH bpf-next v1 21/29] bpf: Support callx when a callee releases resources Kumar Kartikeya Dwivedi
2026-11-11 14:04   ` bot+bpf-ci
2026-11-11 17:13   ` sashiko-bot
2026-11-11 12:57 ` [PATCH bpf-next v1 22/29] selftests/bpf: Test rejected throws that hold resources Kumar Kartikeya Dwivedi
2026-11-11 12:57 ` [PATCH bpf-next v1 23/29] selftests/bpf: Test resource cleanup on bpf_throw() Kumar Kartikeya Dwivedi
2026-11-11 12:57 ` [PATCH bpf-next v1 24/29] selftests/bpf: Test cleanup of handles on the stack Kumar Kartikeya Dwivedi
2026-11-11 12:57 ` [PATCH bpf-next v1 25/29] selftests/bpf: Test cleanup of handles in registers Kumar Kartikeya Dwivedi
2026-11-11 12:57 ` [PATCH bpf-next v1 26/29] selftests/bpf: Test callees releasing caller resources Kumar Kartikeya Dwivedi
2026-11-11 12:57 ` [PATCH bpf-next v1 27/29] selftests/bpf: Test resources a callee leaves with its caller Kumar Kartikeya Dwivedi
2026-11-11 12:57 ` [PATCH bpf-next v1 28/29] selftests/bpf: Test cleanup of locks described at sites Kumar Kartikeya Dwivedi
2026-11-11 12:57 ` [PATCH bpf-next v1 29/29] selftests/bpf: Test callee releases through callx Kumar Kartikeya Dwivedi
2026-11-11 20:33 ` [PATCH bpf-next v1 00/29] Exceptions - Resource Cleanup - Redux Alexei Starovoitov

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-209175@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=memxor@gmail.com \
    --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.