All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Kumar Kartikeya Dwivedi" <memxor@gmail.com>, bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next v2 1/3] x86/mm: Resolve BPF exception fixups for user address faults under SMAP
Date: Sat, 28 Nov 2026 01:46:59 +0000	[thread overview]
Message-ID: <sashiko-outbox-238412@kernel.org> (raw)
In-Reply-To: <0a30eeab6bea7ddfc0202d1970ab1b7f3a4d580c.1795829324.git.memxor@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] x86/mm: SMAP does not fault on supervisor mappings below
  TASK_SIZE_MAX
--

commit 9b387754d627ac256ae9705ce7d6a4e7a2935051
Author: Kumar Kartikeya Dwivedi <memxor@gmail.com>

x86/mm: Resolve BPF exception fixups for user address faults under SMAP

This commit resolves EX_TYPE_BPF exception table entries on kernel-mode read
faults in do_user_addr_fault() under SMAP, allowing the x86 BPF JIT to omit
its software range check before PROBE_MEM loads.

> diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
> index aa88370ce7394..9fe8705eff043 100644
> --- a/arch/x86/mm/fault.c
> +++ b/arch/x86/mm/fault.c
> @@ -1263,7 +1263,16 @@ void do_user_addr_fault(struct pt_regs *regs,
>  		     !(error_code & X86_PF_USER) &&
>  		     !(regs->flags & X86_EFLAGS_AC))) {
>  		/*
> -		 * No extable entry here.  This was a kernel access to an
> +		 * The CPU refused the access. If the BPF JIT marked this load
> +		 * as one that may fault, skip it and zero the destination.
> +		 */
> +		if (!user_mode(regs) && !(error_code & X86_PF_WRITE) &&
> +		    ex_get_fixup_type(regs->ip) == EX_TYPE_BPF &&
> +		    fixup_exception(regs, X86_TRAP_PF, error_code, address))
> +			return;

[Severity: Medium]
Can relying on SMAP to refuse PROBE_MEM loads below TASK_SIZE_MAX allow reads
from supervisor mappings in the low address range when a temporary mm such as
efi_mm is active in CR3?

SMAP only faults when the page-table entries mapping the linear address have
_PAGE_USER set.  efi_setup_page_tables() permanently maps 0x0..0xfff 1:1 in
efi_mm.pgd without _PAGE_USER, and efi_map_region() likewise creates 1:1
supervisor mappings below TASK_SIZE_MAX for EFI runtime and MMIO regions:

arch/x86/platform/efi/efi_64.c:efi_setup_page_tables() {
    ...
	pf = _PAGE_NX | _PAGE_RW;
	if (sev_es_active())
		pf |= _PAGE_ENC;

	if (kernel_map_pages_in_pgd(pgd, 0x0, 0x0, 1, pf)) {
    ...
}

While arch_efi_call_virt_setup() has efi_mm loaded in CR3 (with LASS disabled
and interrupts and NMIs enabled), a BPF tracing program executing a PROBE_MEM
load through a NULL pointer or into a 1:1 EFI region will not fault into
do_user_addr_fault() and will instead read physical page 0 or trigger an
unintended firmware/MMIO read rather than zeroing the destination register.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1795829324.git.memxor@gmail.com?part=1

  reply	other threads:[~2026-11-28  1:47 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-28  1:28 [PATCH bpf-next v2 0/3] bpf, x86: Drop the PROBE_MEM address range check under SMAP Kumar Kartikeya Dwivedi
2026-11-28  1:28 ` [PATCH bpf-next v2 1/3] x86/mm: Resolve BPF exception fixups for user address faults " Kumar Kartikeya Dwivedi
2026-11-28  1:46   ` sashiko-bot [this message]
2026-11-28  2:16     ` Kumar Kartikeya Dwivedi
2026-11-28  1:28 ` [PATCH bpf-next v2 2/3] bpf, x86: Skip the PROBE_MEM address range check " Kumar Kartikeya Dwivedi
2026-11-28  1:41   ` sashiko-bot
2026-11-28  2:16     ` Kumar Kartikeya Dwivedi
2026-11-28  1:28 ` [PATCH bpf-next v2 3/3] selftests/bpf: Test PROBE_MEM loads from invalid addresses Kumar Kartikeya Dwivedi

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-238412@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=memxor@gmail.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.