From: sashiko-bot@kernel.org
To: "Pawan Gupta" <pawan.kumar.gupta@linux.intel.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH 6.18.y 1/6] bpf: Support for hardening against JIT spraying
Date: Tue, 14 Jul 2026 01:23:08 +0000 [thread overview]
Message-ID: <20260714012308.94CAF1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260713-cbpf-jit-spray-hardening-6-18-y-v1-1-755f60c55705@linux.intel.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] BPF programs larger than BPF_PROG_PACK_SIZE bypass the new predictor flush during allocation, leaving large privileged programs vulnerable to Spectre v2 JIT spraying.
--
--- Patch [1]: [PATCH 6.18.y 1/6] bpf: Support for hardening against JIT spraying ---
commit cb1a8f614dfc8fdb1bb7a2e56154f4f8e2cb7a53
Author: Pawan Gupta <pawan.kumar.gupta@linux.intel.com>
bpf: Support for hardening against JIT spraying
This commit introduces a mechanism to flush indirect branch predictors before
reusing JIT memory. The goal is to ensure indirect jumps in a newly written
program don't reuse branch predictions left behind by an old program that
previously occupied the same space.
> --- a/kernel/bpf/core.c
> +++ b/kernel/bpf/core.c
[ ... ]
> @@ -923,6 +933,14 @@ void *bpf_prog_pack_alloc(u32 size, bpf_jit_fill_hole_t bpf_fill_ill_insns)
>
> mutex_lock(&pack_mutex);
> if (size > BPF_PROG_PACK_SIZE) {
> + /*
> + * Allocations larger than a pack get their own pages, and
> + * predictors are not flushed for such allocation. This is only
> + * safe because cBPF programs (the unprivileged attack surface)
> + * are bounded well below a pack size.
> + */
> + if (static_branch_unlikely(&bpf_pred_flush_enabled))
> + pr_warn_once("BPF: Predictors not flushed for allocations greater than BPF_PROG_PACK_SIZE\n");
> size = round_up(size, PAGE_SIZE);
> ptr = bpf_jit_alloc_exec(size);
[Severity: High]
This isn't a bug introduced by this patch, but does this logic leave large
privileged eBPF programs vulnerable to Spectre v2 attacks?
The comment here justifies skipping the flush by stating that cBPF programs
(the unprivileged attack surface) are bounded well below a pack size. However,
in a Spectre v2 attack, the newly allocated program is actually the victim,
not the attacker.
If an unprivileged attacker loads and frees a small cBPF program to mistrain
the CPU branch predictors, and a privileged user subsequently loads a large
eBPF program (> BPF_PROG_PACK_SIZE), bpf_prog_pack_alloc() allocates it via
bpf_jit_alloc_exec().
If it reuses the same virtual memory, it explicitly bypasses the new
bpf_arch_pred_flush() call, forcing the privileged eBPF program to execute
using the attacker's leftover mistrained branch predictions.
Could large allocations also receive a predictor flush to ensure privileged
programs are protected?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260713-cbpf-jit-spray-hardening-6-18-y-v1-0-755f60c55705@linux.intel.com?part=1
next prev parent reply other threads:[~2026-07-14 1:23 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-14 1:11 [PATCH 6.18.y 0/6] cBPF JIT spray hardening Pawan Gupta
2026-07-14 1:11 ` [PATCH 6.18.y 1/6] bpf: Support for hardening against JIT spraying Pawan Gupta
2026-07-14 1:23 ` sashiko-bot [this message]
2026-07-14 1:11 ` [PATCH 6.18.y 2/6] x86/bugs: Enable IBPB flush on BPF JIT allocation Pawan Gupta
2026-07-14 1:24 ` sashiko-bot
2026-07-14 1:12 ` [PATCH 6.18.y 3/6] bpf: Restrict JIT predictor flush to cBPF Pawan Gupta
2026-07-14 1:24 ` sashiko-bot
2026-07-14 1:12 ` [PATCH 6.18.y 4/6] bpf: Skip redundant IBPB in pack allocator Pawan Gupta
2026-07-14 1:12 ` [PATCH 6.18.y 5/6] bpf: Prefer packs that won't trigger an IBPB flush on allocation Pawan Gupta
2026-07-14 1:12 ` [PATCH 6.18.y 6/6] bpf: Prefer dirty packs for eBPF allocations 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=20260714012308.94CAF1F000E9@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox