From: "Andy Lutomirski" <luto@kernel.org>
To: "Kumar Kartikeya Dwivedi" <memxor@gmail.com>
Cc: "Alexei Starovoitov" <alexei.starovoitov@gmail.com>,
bpf@vger.kernel.org, "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: Mon, 30 Nov 2026 18:38:19 -0800 [thread overview]
Message-ID: <bb61ebdf-624c-43c9-bca6-04872a66efe9@app.fastmail.com> (raw)
In-Reply-To: <CAP01T74XuUQ7+SNJYAQGxhekcXDxXjPguMzj3tn3dTCrRS=0mQ@mail.gmail.com>
On Mon, Nov 30, 2026, at 6:06 PM, Kumar Kartikeya Dwivedi wrote:
> On Tue, 1 Dec 2026 at 02:49, Andy Lutomirski <luto@kernel.org> wrote:
>>
>>
>>
>> If you believe that the BPF verifier can statically verify that a BPF program doing a PROBE_MEM access is referencing a valid (or maybe only mildly stale) kernel address, then I encourage you and Kumar to drop all of the x86 patches you keep sending, remove all the code that BPF emits to avoid tripping over SMAP, and be completely confident that the kernel will never OOPS or otherwise malfunction as a result.
>>
>> If you don't believe that, for example if you think a program might do x = a->b->c where the *a cannot be proven to still be alive and intact at the time that a->b is read, then I don't think that __iomem will save you, and maybe you should not believe anything in the previous paragraph, and maybe you should rethink this.
>
> Hi Andy,
>
> I think that part is clear to me, __iomem based rejections are useful
> but not sufficient to prevent the problem you mentioned. I should have
> been clearer in my earlier reply.
>
> That said, some of the options you outlined would be too expensive
> (like walking a table at each access) and would just make tracing
> programs prohibitively slow due to potential overhead. If you look at
> the cover letter, some programs consist largely of probe reads, and
> are often used in performance critical paths for observability and
> statistics collection.
>
> Taking a step back, we agree that ioremap() pages are also a problem
> for every user of copy_from_kernel_nofault(). My impression is that
> exploring a region based approach, so we can isolate ioremap() regions
> in a range and using a range check to cheaply work around those
> addresses would be the best fit. I haven't spent time exploring this
> option, but I'm happy to follow up separately.
>
As I understand the situation, there's a class of eBPF programs that contain memory accesses that cannot be statically verified to be correct, and eBPF is does not actually trust the programs enough to run them despite the lack of verification. And presumably the SMAP check (or the range check that avoids it) actually gets hit in practice, so eBPF can't get away with just ignoring the issue, because it will OOPS on occasion.
I'll assume for the sake of this discussion that it is actually reasonable for eBPF to have a primitive that means, approximately, "read this address and produce either a garbage result or zero in case the pointer is bogus". (And that it's okay that a malicious attacker might control the result, etc.)
Given this, eBPF needs an implementation of the primitive. Apparently the pointers really are wild enough that they hit user-half addresses with some frequency and they've even hit the vsyscall page. So I'll assume that they are genuinely completely wild.
And you want good performance.
And there is no plan that I'm aware of to improve the verifier and the tools available to eBPF programs to get actual static verification.
So I think this is a catch-22. x86 could make an arch change (the ignore-bpf-smap-violations thing) that will make most, but not all, wild pointer reads "safe" in the sense that they will return zero instead of oopsing. But it will do nothing to help the smaller fraction that hit side-effect-ful memory out of bounds. And it will encourage everyone to forget about the issue even while it's known buggy.
> At the same time, getting rid of the user space address check which is
> feasible when SMAP is enabled, and closing the case where __iomem
> tagged pointers are rejected from the verifier, both seem useful
> additions to me. They do not fix everything we discussed but are
> orthogonal improvements to the status quo, reducing overhead and
> preventing potential mistakes.
I think the __iomem change makes sense. Those programs are presumably just wrong.
But I'm not seeing why the SMAP change is actually a good idea, since it just papers over the issue by suppressing most of the OOPSes.
In any case, if eBPF needs a dynamic check for address safety, then it needs a dynamic check or address safety. x86 has PKS, which can do this (on some CPUs), coherently with the page tables. And it can be done as ordinary code. Using a temporary mm will be slow. I don't really see another option.
>
> Even if we have to keep instrumentation for the ioremap() range (since
> we don't have potential ways to cheaply activate hardware protection
> on such accesses), that will still be much cheaper (perhaps a single
> branch) than emitting a longer sequence for each load instruction, as
> we do today.
>
Can you explain what the sequence is? I'm not really seeing why SMAP is expensive but MMIO checks would be cheap.
next prev parent reply other threads:[~2026-12-01 2:38 UTC|newest]
Thread overview: 36+ 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 " 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 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
2026-11-26 5:38 ` Andy Lutomirski
2026-11-26 6:18 ` Alexei Starovoitov
2026-11-26 17:30 ` Andy Lutomirski
2026-11-27 0:18 ` Alexei Starovoitov
2026-11-27 17:51 ` Andy Lutomirski
2026-11-28 1:48 ` Kumar Kartikeya Dwivedi
2026-11-28 1:55 ` Alexei Starovoitov
2026-12-01 1:49 ` Andy Lutomirski
2026-12-01 2:06 ` Kumar Kartikeya Dwivedi
2026-12-01 2:38 ` Andy Lutomirski [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
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=bb61ebdf-624c-43c9-bca6-04872a66efe9@app.fastmail.com \
--to=luto@kernel.org \
--cc=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=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
all inboxes | Powered by JetHome®