BPF List
 help / color / mirror / Atom feed
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 1/6] bpf: Support for hardening against JIT spraying
Date: Tue, 14 Jul 2026 19:17:41 +0000	[thread overview]
Message-ID: <20260714191742.283AD1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260714-cbpf-jit-spray-hardening-6-16-y-v1-1-2fc3e16263ac@linux.intel.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] The branch predictor flush is bypassed for BPF allocations larger than BPF_PROG_PACK_SIZE, leaving privileged BPF programs vulnerable to Branch Target Injection (BTI) / Spectre v2 attacks. The author's rationale for skipping the flush assumes attackers cannot allocate large programs. However, an attacker can train the BTB using small programs and free them; a victim's subsequent large allocation can reuse the same virtual memory and will skip the flush, inheriting the poisoned BTB entries. Additionally, on configurations where PMD_SIZE is undefined, BPF_PROG_PACK_SIZE defaults to PAGE_SIZE (typically 4KB), which unprivileged cBPF programs (up to 32KB) can exceed, directly bypassing the flush.
--

--- Patch [1]: [PATCH 6.16.y 1/6] bpf: Support for hardening against JIT spraying ---
commit 86ef6d6286895019e1dbe8a1db211825e4c28b04
Author: Pawan Gupta <pawan.kumar.gupta@linux.intel.com>

bpf: Support for hardening against JIT spraying

This commit introduces a branch predictor flush before reusing BPF JIT memory.
It aims to prevent indirect jumps in a newly written program from reusing
predictions left behind by an old program that occupied the same space.

> diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
> index 17e5cf18da1ef..48208c3f58143 100644
> --- a/kernel/bpf/core.c
> +++ b/kernel/bpf/core.c

[ ... ]

> @@ -951,6 +961,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);
>  		if (ptr) {

[Severity: High]
Does skipping the flush for large allocations leave them vulnerable to BTB
poisoning if the virtual memory is reused?

If an attacker trains the BTB using small programs and frees them, and then a
victim loads a large program that reuses the same virtual memory, wouldn't the
large allocation skip the flush and inherit the poisoned BTB entries?

Additionally, on configurations where PMD_SIZE is undefined,
BPF_PROG_PACK_SIZE defaults to PAGE_SIZE (typically 4KB). Could unprivileged
cBPF programs (which can be up to 32KB) exceed this and bypass the flush
directly?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260714-cbpf-jit-spray-hardening-6-16-y-v1-0-2fc3e16263ac@linux.intel.com?part=1

  reply	other threads:[~2026-07-14 19:17 UTC|newest]

Thread overview: 10+ 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 ` [PATCH 6.16.y 1/6] bpf: Support for hardening against JIT spraying Pawan Gupta
2026-07-14 19:17   ` sashiko-bot [this message]
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 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 19:28   ` sashiko-bot
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 ` [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 ` [PATCH 6.16.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=20260714191742.283AD1F000E9@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