From: sashiko-bot@kernel.org
To: "Pawan Gupta" <pawan.kumar.gupta@linux.intel.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH 6.16.y 3/6] bpf: Restrict JIT predictor flush to cBPF
Date: Tue, 14 Jul 2026 19:28:58 +0000 [thread overview]
Message-ID: <20260714192859.39F031F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260714-cbpf-jit-spray-hardening-6-16-y-v1-3-2fc3e16263ac@linux.intel.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Restricting the JIT predictor flush exclusively to cBPF programs bypasses the Spectre v2/BHB mitigation for eBPF programs, exposing privileged eBPF code, trampolines, and dispatchers to Branch Target Injection.
--
--- Patch [3]: [PATCH 6.16.y 3/6] bpf: Restrict JIT predictor flush to cBPF ---
commit 8b8cdfd6b31b7472477f24189e670075eceab23b
Author: Pawan Gupta <pawan.kumar.gupta@linux.intel.com>
bpf: Restrict JIT predictor flush to cBPF
This commit restricts the JIT predictor flush to only cBPF programs when
reusing memory in the BPF pack allocator. It skips the flush for eBPF
programs, trampolines, and dispatchers to improve performance.
> diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
> index 48208c3f58143..63569d23cfa09 100644
> --- a/kernel/bpf/core.c
> +++ b/kernel/bpf/core.c
[ ... ]
> @@ -999,7 +999,9 @@ void *bpf_prog_pack_alloc(u32 size, bpf_jit_fill_hole_t bpf_fill_ill_insns)
> pos = 0;
>
> found_free_area:
> - static_call_cond(bpf_arch_pred_flush)();
> + /* Flush only for cBPF as it may contain a crafted gadget */
> + if (static_branch_unlikely(&bpf_pred_flush_enabled) && was_classic)
> + static_call_cond(bpf_arch_pred_flush)();
[Severity: High]
Does restricting the predictor flush to only cBPF allocations bypass the
Spectre v2/BHB mitigation when memory is reused?
The JIT predictor flush clears branch history left by the previous occupant of
the memory. By gating the flush on was_classic in bpf_prog_pack_alloc(), the
mitigation is skipped if the new allocation is an eBPF program, dispatcher, or
trampoline.
If a local unprivileged user loads a cBPF program, trains the branch predictor
to jump to a specific offset, and frees the program, the kernel might reuse
this memory chunk for a privileged eBPF program. Because the new allocation is
eBPF, was_classic is false and the flush is skipped, potentially allowing the
attacker to trigger a misprediction and speculatively execute accidental
gadgets in the new privileged code.
Additionally, if unprivileged eBPF is enabled, an attacker can load an
unprivileged eBPF program, train the predictor, free it, and load another
unprivileged eBPF program with crafted gadgets. Since bpf_prog_was_classic()
returns false for native eBPF programs, the flush is also skipped for the new
allocation, leaving the crafted gadgets vulnerable to speculative execution.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260714-cbpf-jit-spray-hardening-6-16-y-v1-0-2fc3e16263ac@linux.intel.com?part=3
next prev parent reply other threads:[~2026-07-14 19:28 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-14 18:58 [PATCH 6.16.y 0/6] cBPF JIT spray hardening Pawan Gupta
2026-07-14 18:58 ` Pawan Gupta
2026-07-14 18:58 ` [PATCH 6.16.y 1/6] bpf: Support for hardening against JIT spraying Pawan Gupta
2026-07-14 18:58 ` Pawan Gupta
2026-07-14 19:17 ` sashiko-bot
2026-07-14 18:58 ` [PATCH 6.16.y 2/6] x86/bugs: Enable IBPB flush on BPF JIT allocation Pawan Gupta
2026-07-14 18:58 ` Pawan Gupta
2026-07-14 19:36 ` sashiko-bot
2026-07-14 18:59 ` [PATCH 6.16.y 3/6] bpf: Restrict JIT predictor flush to cBPF Pawan Gupta
2026-07-14 18:59 ` Pawan Gupta
2026-07-14 19:28 ` sashiko-bot [this message]
2026-07-14 18:59 ` [PATCH 6.16.y 4/6] bpf: Skip redundant IBPB in pack allocator Pawan Gupta
2026-07-14 18:59 ` Pawan Gupta
2026-07-14 18:59 ` [PATCH 6.16.y 5/6] bpf: Prefer packs that won't trigger an IBPB flush on allocation Pawan Gupta
2026-07-14 18:59 ` Pawan Gupta
2026-07-14 18:59 ` [PATCH 6.16.y 6/6] bpf: Prefer dirty packs for eBPF allocations Pawan Gupta
2026-07-14 18:59 ` Pawan Gupta
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=20260714192859.39F031F00A3A@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=pawan.kumar.gupta@linux.intel.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.