From: sashiko-bot@kernel.org
To: "Viktor Malik" <vmalik@redhat.com>, bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next 2/2] x86/bugs: Restrict BPF JIT IBPB flush to CPUs that ran BPF
Date: Fri, 04 Dec 2026 14:17:45 +0000 [thread overview]
Message-ID: <sashiko-outbox-249954@kernel.org> (raw)
In-Reply-To: <7ac95882a7218a0494304189d4f500fa589a651d.1796391323.git.vmalik@redhat.com>
Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [High] bpf: link failure on CONFIG_BPF_JIT=n from bpf_prog_mark_ran()
- [Medium] x86/bugs: bpf_arch_ibpb() skips CPUs that ran
bpf_run_async_cb()
- [Medium] x86/bugs: bpf_arch_ibpb() skips CPUs that ran BPF trampolines
- [Medium] x86/bugs: bpf_arch_ibpb() skips CPUs for reused non-BPF
execmem VAs
--
commit 781f81166f8975129aeee336798a4632f98a3a71
Author: Viktor Malik <vmalik@redhat.com>
x86/bugs: Restrict BPF JIT IBPB flush to CPUs that ran BPF
This commit changes bpf_arch_ibpb() to use on_each_cpu_cond() with the
per-CPU bpf_prog_ran flag so that only CPUs that have executed a BPF
program since the last flush receive an IPI and IBPB, clearing the flag
before issuing write_ibpb().
> diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c
> index 4ced10c6ba0db..08eac5cf2c32d 100644
> --- a/arch/x86/kernel/cpu/bugs.c
> +++ b/arch/x86/kernel/cpu/bugs.c
> @@ -2253,12 +2253,18 @@ static void __init spectre_v2_update_mitigation(void)
> #ifdef CONFIG_BPF_JIT
> static void __bpf_arch_ibpb(void *unused)
> {
> + WRITE_ONCE(*raw_cpu_ptr(&bpf_prog_ran), false);
> write_ibpb();
> }
[Severity: High]
Does commit "bpf: Track CPUs that have executed a BPF program" break
linking when CONFIG_BPF_JIT=n?
kernel/bpf/core.c defines bpf_pred_flush_enabled and bpf_prog_ran inside
#ifdef CONFIG_BPF_JIT, while include/linux/filter.h defines
bpf_prog_mark_ran() outside that guard and calls it unconditionally from
__bpf_prog_run().
Any build with CONFIG_BPF_JIT=n that compiles a caller such as
__seccomp_filter() in kernel/seccomp.c fails to link with undefined
references to both symbols. Guarding bpf_prog_mark_ran() with #ifdef
CONFIG_BPF_JIT and providing an empty stub otherwise would avoid this.
>
> +static bool bpf_ibpb_needed(int cpu, void *unused)
> +{
> + return READ_ONCE(per_cpu(bpf_prog_ran, cpu));
> +}
> +
> void bpf_arch_ibpb(void)
> {
> - on_each_cpu(__bpf_arch_ibpb, NULL, 1);
> + on_each_cpu_cond(bpf_ibpb_needed, __bpf_arch_ibpb, NULL, 1);
> }
[Severity: Medium]
Can bpf_arch_ibpb() skip a CPU that executed a JITed async BPF callback?
Async callbacks (such as bpf_timer_cb() and bpf_wq_work()) are JITed as
subprograms into bpf_prog_pack chunks and invoked directly through
bpf_run_async_cb() in kernel/bpf/helpers.c, bypassing __bpf_prog_run()
and the trampoline exit helpers.
Because bpf_run_async_cb() does not call bpf_prog_mark_ran(),
bpf_prog_ran remains false on that CPU. When a freed chunk is later
reused for an unprivileged cBPF program, bpf_arch_ibpb() skips flushing
that CPU and leaves stale branch predictions intact.
Calling bpf_prog_mark_ran() after callback_fn() returns in
bpf_run_async_cb() would close this gap.
[Severity: Medium]
Will bpf_arch_ibpb() also skip CPUs that executed a JITed BPF trampoline
image?
On x86_64, arch_alloc_bpf_trampoline() allocates trampoline images from
bpf_prog_pack, while bpf_prog_mark_ran() is only called in the
per-program __bpf_prog_exit*() helpers and not in __bpf_tramp_exit().
During __bpf_trampoline_unlink_prog(), bpf_trampoline_skip_prog() patches
the skip target past bpf_trampoline_exit(), so a CPU running the
trampoline before detach executes JITed trampoline branches (including
call *rbx under BPF_TRAMP_F_ORIG_STACK) with bpf_prog_ran left false.
A task running a BPF_TRAMP_F_CALL_ORIG trampoline without fexit can also
migrate or take a clearing IPI during orig_call before executing the
trampoline epilogue. When the trampoline chunk is later reused for cBPF,
bpf_arch_ibpb() skips flushing that CPU and leaves stale predictions.
[Severity: Medium]
Does restricting bpf_arch_ibpb() to CPUs with bpf_prog_ran set miss stale
predictions from non-BPF code when a new pack reuses virtual addresses?
On x86, execmem_arch_setup() places EXECMEM_BPF in the same virtual
address range and shared EXECMEM_ROX_CACHE pool as EXECMEM_MODULE_TEXT,
EXECMEM_KPROBES, and EXECMEM_FTRACE, and execmem_free() does not issue an
IBPB.
When alloc_new_pack() reuses addresses freed by an unloaded module or
module .init.text, the first cBPF allocation calls bpf_arch_ibpb() and
clears pack->dirty_map. CPUs that executed that unloaded code without
running BPF have bpf_prog_ran false and are skipped without being flushed.
--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1796391323.git.vmalik@redhat.com?part=2
next prev parent reply other threads:[~2026-12-04 14:17 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 13:44 [PATCH bpf-next 0/2] bpf, x86: Restrict BPF JIT IBPB flush to CPUs that ran BPF Viktor Malik
2026-12-04 13:44 ` [PATCH bpf-next 1/2] bpf: Track CPUs that have executed a BPF program Viktor Malik
2026-12-04 14:03 ` sashiko-bot
2026-12-04 15:22 ` Viktor Malik
2026-12-04 14:51 ` Valentin Schneider
2026-12-04 16:27 ` Dave Hansen
2026-12-04 16:45 ` Viktor Malik
2026-12-04 13:44 ` [PATCH bpf-next 2/2] x86/bugs: Restrict BPF JIT IBPB flush to CPUs that ran BPF Viktor Malik
2026-12-04 14:17 ` sashiko-bot [this message]
2026-12-04 15:33 ` Viktor Malik
2026-12-04 14:51 ` Valentin Schneider
2026-12-04 15:01 ` [PATCH bpf-next 0/2] bpf, x86: " Valentin Schneider
2026-12-04 16:37 ` Dave Hansen
2026-12-04 17:46 ` Valentin Schneider
2026-12-04 19:42 ` 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-249954@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=vmalik@redhat.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