From: Luis Gerhorst <luis.gerhorst@fau.de>
To: Alexei Starovoitov <ast@kernel.org>, bpf@vger.kernel.org
Cc: Luis Gerhorst <luis.gerhorst@fau.de>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
Eduard Zingerman <eddyz87@gmail.com>,
Kumar Kartikeya Dwivedi <memxor@gmail.com>,
Martin KaFai Lau <martin.lau@linux.dev>,
Song Liu <song@kernel.org>,
Yonghong Song <yonghong.song@linux.dev>,
Jiri Olsa <jolsa@kernel.org>,
Emil Tsalapatis <emil@etsalapatis.com>,
Ihor Solodrai <ihor.solodrai@linux.dev>,
John Fastabend <john.fastabend@gmail.com>,
Shuah Khan <shuah@kernel.org>,
Henriette Herzog <henriette.herzog@rub.de>,
linux-kselftest@vger.kernel.org
Subject: [PATCH bpf 0/4] bpf: Emit nospec after every insn that stores to the stack
Date: Wed, 25 Nov 2026 18:12:48 +0100 [thread overview]
Message-ID: <cover.1795625597.git.luis.gerhorst@fau.de> (raw)
In-Reply-To: <20261125-nospec-result-reply-d60fdc6da8ef@fau.de>
This is an alternative to patches 4 and 5 of [1]. It applies on top of
patches 1-3 of that series.
check_stack_write_fixed_off() sets nospec_result for every insn that
stores to the stack and must not be bypassed speculatively: a BPF_MEM
store, a BPF_ATOMIC insn, or a call of a helper or kfunc that
initializes a dynptr, an iterator or the flags of bpf_local_irq_save()
there. bpf_convert_ctx_accesses() emits the nospec only after BPF_MEM
stores.
[1] handles the other two cases per insn: patch 4 also emits the nospec
after BPF_ATOMIC insns, patch 5 makes do_check() continue a speculative
path behind a call because no nospec follows it. This series emits the
nospec after every insn with nospec_result instead, whatever the insn
is. do_check() is not changed: it can end a speculative path at each of
these insns, and the store of a call is covered for Spectre v4 like
every other store to the stack.
The nospec behind a call has to be inserted without taking the aux data
from the call, because the passes that follow still rewrite the call.
bpf_patch_insn_data() can not do that: it moves the aux data to the last
insn of the patch.
patch content
----- ------------------------------------------------------------------
1 bpf_insert_insns(), which inserts insns in front of or behind an
insn that keeps its aux data, and its use where a patch only
inserts. No functional change.
2 tests for the converted callers that no test reached
3 the fix: a pass that emits the nospec in front of an insn with
nospec, and behind an insn with nospec_result
4 tests for the nospec behind calls and atomics
The main downside is that bpf_insert_insns() needs a buffer of its own
to build the patch, because the callers pass env->insn_buf. This adds
insert_buf with INSN_BUF_SIZE insns (256 bytes) to bpf_verifier_env.
[1] https://lore.kernel.org/bpf/20261125040820.947816-1-alexei.starovoitov@gmail.com/
Luis Gerhorst (4):
bpf: Add bpf_insert_insns() to insert insns next to an insn
selftests/bpf: Test the insns that bpf_insert_insns() inserts
bpf: Emit nospec after every insn with nospec_result
selftests/bpf: Test nospec after stack writes of calls and atomics
include/linux/bpf_verifier.h | 2 +
kernel/bpf/fixups.c | 351 +++++++++---------
kernel/bpf/verifier.c | 3 +
.../bpf/progs/verifier_percpu_addr.c | 31 ++
.../selftests/bpf/progs/verifier_unpriv.c | 201 ++++++++++
.../selftests/bpf/progs/verifier_zext.c | 57 +++
6 files changed, 477 insertions(+), 168 deletions(-)
base-commit: 81c6c8c608b6075846d3bd5b6f57958300a56eda
prerequisite-patch-id: 6079fc600b6711222dba245601eab9d1b76f0ecc
prerequisite-patch-id: 1f8ba1a2f5b8b7bf73dea4349ccd7b2679f4ffaf
prerequisite-patch-id: 2a97f28aef89f4281e7205a16f2210d3a95581b2
--
2.56.1
next prev parent reply other threads:[~2026-11-25 17:16 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 4:08 [PATCH bpf 0/5] bpf: Fixes for speculation barriers and constant reads Alexei Starovoitov
2026-11-25 4:08 ` [PATCH bpf 1/5] bpf: Undo insn aux changes of a failed speculative path Alexei Starovoitov
2026-11-25 4:08 ` [PATCH bpf 2/5] bpf: Treat NOT_INIT as a pointer in __is_pointer_value() Alexei Starovoitov
2026-11-25 4:08 ` [PATCH bpf 3/5] bpf: Use get_unaligned() in bpf_map_direct_read() Alexei Starovoitov
2026-11-25 4:08 ` [PATCH bpf 4/5] bpf: Emit nospec after BPF_ATOMIC stores to the stack Alexei Starovoitov
2026-11-25 17:12 ` Luis Gerhorst
2026-11-25 17:12 ` Luis Gerhorst [this message]
2026-11-25 17:12 ` [PATCH bpf 1/4] bpf: Add bpf_insert_insns() to insert insns next to an insn Luis Gerhorst
2026-11-25 17:51 ` sashiko-bot
2026-11-25 18:17 ` bot+bpf-ci
2026-11-25 17:12 ` [PATCH bpf 2/4] selftests/bpf: Test the insns that bpf_insert_insns() inserts Luis Gerhorst
2026-11-25 17:39 ` sashiko-bot
2026-11-25 17:12 ` [PATCH bpf 3/4] bpf: Emit nospec after every insn with nospec_result Luis Gerhorst
2026-11-25 18:17 ` bot+bpf-ci
2026-11-25 17:12 ` [PATCH bpf 4/4] selftests/bpf: Test nospec after stack writes of calls and atomics Luis Gerhorst
2026-11-25 17:45 ` sashiko-bot
2026-11-26 3:40 ` [PATCH bpf 4/5] bpf: Emit nospec after BPF_ATOMIC stores to the stack Alexei Starovoitov
2026-11-25 4:08 ` [PATCH bpf 5/5] bpf: Do not end a speculative path at a call Alexei Starovoitov
2026-11-25 5:00 ` 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=cover.1795625597.git.luis.gerhorst@fau.de \
--to=luis.gerhorst@fau.de \
--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=henriette.herzog@rub.de \
--cc=ihor.solodrai@linux.dev \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=memxor@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 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.