BPF List
 help / color / mirror / Atom feed
From: "Alexei Starovoitov" <alexei.starovoitov@gmail.com>
To: "Andy Lutomirski" <luto@kernel.org>,
	"Kumar Kartikeya Dwivedi" <memxor@gmail.com>,
	<bpf@vger.kernel.org>
Cc: "Puranjay Mohan" <puranjay@kernel.org>,
	"Andrii Nakryiko" <andrii@kernel.org>,
	"Daniel Borkmann" <daniel@iogearbox.net>,
	"Eduard Zingerman" <eddyz87@gmail.com>,
	"Emil Tsalapatis" <emil@etsalapatis.com>,
	"Ihor Solodrai" <ihor.solodrai@linux.dev>,
	"Dave Hansen" <dave.hansen@linux.intel.com>,
	"Peter Zijlstra (Intel)" <peterz@infradead.org>,
	"Thomas Gleixner" <tglx@kernel.org>,
	"Ingo Molnar" <mingo@redhat.com>,
	"Borislav Petkov" <bp@alien8.de>, <kkd@meta.com>,
	<kernel-team@meta.com>,
	"the arch/x86 maintainers" <x86@kernel.org>,
	"Linux Kernel Mailing List" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH bpf-next v1 1/3] x86/mm: Resolve BPF exception fixups for user address faults under SMAP
Date: Wed, 25 Nov 2026 06:45:00 +0000	[thread overview]
Message-ID: <DN437OYZ5FGP.20VLV7ZEXQ5YY@gmail.com> (raw)
In-Reply-To: <df69ab5d-bc97-4651-8668-a2b3e4bb272a@app.fastmail.com>

On Tue, Nov 24, 2026 at 08:22 PM Andy Lutomirski <luto@kernel.org> wrote:
> Didn't we hash this out a decade ago or so?

Twice. Feb 2019 for probe_kernel_read() and Jan 2021 for PROBE_MEM:
https://lore.kernel.org/all/300C4516-A093-43AE-8707-1C42486807A4@amacapital.net/
https://lore.kernel.org/bpf/CALCETrVZRiG+qQFrf_7NaCZ9o9f2-aUTgLNJgCzBfsswpG7kTA@mail.gmail.com/

The problem in 2021 was a CPU without SMAP. There the fault handler
can't tell a PROBE_MEM load of a user address from a valid uaccess.
That part stays. Without SMAP the JIT emits the range check.
With SMAP and AC clear a fault on a user address is never a valid uaccess.

In the 2019 thread Linus proposed the same for __probe_kernel_read():
no uaccess_begin(), SMAP refuses a user address, extable returns -EFAULT.
https://lore.kernel.org/all/CAHk-=whNf_n1WXWW+ugAVeL5ZK0GcEP3cTYocju1nS85VtMjjQ@mail.gmail.com/

> Can you at least explain how a non-range-checked pointer read of a non-verifiable pointer doesn't have a problem with, say, MMIO?

The range check doesn't know about MMIO. It refuses user addresses, the
guard page, and VSYSCALL_ADDR and above.
ioremap() space is in the vmalloc range, so it passes the check today.
It passes copy_from_kernel_nofault_allowed() too.
"compare" and "CPU" refuse the address, "load" reads it:

                              user address,  kernel address
                              RAM or a BAR   RAM     ioremap()
  --------------------------  -------------  ------  ---------
  copy_from_kernel_nofault()  compare        load    load
  PROBE_MEM today             compare        load    load
  PROBE_MEM, patch 2, SMAP    CPU            load    load

A BAR that is mapped into user space is a user address.
The device sees no read in all three rows.

> Does anyone have a compelling argument as to why the vsyscall page is any different from a PCIe (virtual or otherwise) BAR other than the fact that the x86 arch code will OOPS you when you accidentally read the vsyscall page but you will just possibly deadlock or otherwise screw up more subtlely when hitting a different inappropriate page?

It's not different. The oops is the only reason for that check.
syzbot hit the oops through bpf_probe_read_kernel(). Then 32019c659ecf
added the vsyscall page to copy_from_kernel_nofault_allowed() and
b599d7d26d6a added it to the JIT.

> If not, then I think this series primarily serves to make x86 complicit in papering over a problem with eBPF: right now eBPF has a heuristic that is wrong, but with the patch set applied, eBPF can make the heuristic even more wrong and x86 will paper over the cases that it happens to be able to detect.

The range check is not a heuristic for "safe to read". It's the user
address part of get_kernel_nofault(), inlined. You asked for that in 2021.
Its job is to keep user addresses away from the load. SMAP does the same
job. With patch 2 PROBE_MEM reads the same addresses as
copy_from_kernel_nofault().

In both threads you wanted probe_kernel_read() / get_kernel_nofault() to
tell MMIO from RAM. arch/x86/mm/maccess.c has no such check.
bpf_probe_read_kernel(), kprobe event args and kdb pass any address to it.
So MMIO is a problem of every nofault reader, not of bpf and not of this
series.

  reply	other threads:[~2026-11-25  6:45 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-09  2:49 [PATCH bpf-next v1 0/3] bpf, x86: Drop the PROBE_MEM address range check under SMAP Kumar Kartikeya Dwivedi
2026-10-09  2:49 ` [PATCH bpf-next v1 1/3] x86/mm: Resolve BPF exception fixups for user address faults " Kumar Kartikeya Dwivedi
2026-10-09  3:03   ` sashiko-bot
2026-10-09  4:13   ` Borislav Petkov
2026-10-09 15:23     ` Kumar Kartikeya Dwivedi
2026-11-22 20:08       ` Borislav Petkov
2026-11-22 21:59         ` Kumar Kartikeya Dwivedi
2026-11-23  0:30           ` Borislav Petkov
2026-11-23  0:59             ` Kumar Kartikeya Dwivedi
2026-11-23  2:55               ` Borislav Petkov
2026-11-23  3:56                 ` Kumar Kartikeya Dwivedi
2026-11-23  4:34                   ` Borislav Petkov
2026-11-23  6:58                   ` Alexei Starovoitov
2026-11-23 17:27                     ` Kumar Kartikeya Dwivedi
2026-11-23 18:51                     ` Borislav Petkov
2026-11-24  6:25                       ` Alexei Starovoitov
2026-11-25  2:17                         ` Borislav Petkov
2026-11-25  3:27                           ` Alexei Starovoitov
2026-11-23 15:36       ` Dave Hansen
2026-11-23 17:23         ` Kumar Kartikeya Dwivedi
2026-11-24 15:25           ` Dave Hansen
2026-11-24 20:17             ` Alexei Starovoitov
2026-11-25  4:22   ` Andy Lutomirski
2026-11-25  6:45     ` Alexei Starovoitov [this message]
2026-10-09  2:49 ` [PATCH bpf-next v1 2/3] bpf, x86: Skip the PROBE_MEM address range check " Kumar Kartikeya Dwivedi
2026-10-09  3:42   ` bot+bpf-ci
2026-10-09  2:49 ` [PATCH bpf-next v1 3/3] selftests/bpf: Test PROBE_MEM loads from invalid addresses Kumar Kartikeya Dwivedi
2026-10-09  2:56   ` sashiko-bot

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=DN437OYZ5FGP.20VLV7ZEXQ5YY@gmail.com \
    --to=alexei.starovoitov@gmail.com \
    --cc=andrii@kernel.org \
    --cc=bp@alien8.de \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=dave.hansen@linux.intel.com \
    --cc=eddyz87@gmail.com \
    --cc=emil@etsalapatis.com \
    --cc=ihor.solodrai@linux.dev \
    --cc=kernel-team@meta.com \
    --cc=kkd@meta.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=memxor@gmail.com \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=puranjay@kernel.org \
    --cc=tglx@kernel.org \
    --cc=x86@kernel.org \
    /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