Re: [PATCH bpf-next v1 1/3] x86/mm: Resolve BPF exception fixups for user address faults under SMAP
From: Kumar Kartikeya Dwivedi
Date: Mon Nov 30 2026 - 21:07:17 EST
On Tue, 1 Dec 2026 at 02:49, Andy Lutomirski <luto@xxxxxxxxxx> wrote:
>
>
>
> On Fri, Nov 27, 2026, at 5:55 PM, Alexei Starovoitov wrote:
> > On Sat Nov 28, 2026 at 1:48 AM UTC, Kumar Kartikeya Dwivedi wrote:
> >> On Fri Nov 27, 2026 at 1:18 AM CET, Alexei Starovoitov wrote:
> >>> On Thu, Nov 26, 2026 at 09:30 AM Andy Lutomirski <luto@xxxxxxxxxx> wrote:
> >>>> Okay. So maybe there should be a nice patch set to *fix* it.
> >>>
> >>> [[...]
> >>>
> >>> The main point that it's orgonal to this patchset.
> >>>
> >>
> >> I was wondering whether one concrete improvement could be to emit BTF type tags
> >> for __iomem annotations in the kernel, then reject accesses on BTF pointers
> >> formed using such walks in the verifier, so such programs would fail to load.
> >>
> >> I think in practice, at least for BPF users, this will close the issue.
> >
> > That's a great idea. Much better than Andy's 1-3 options.
>
> Alexei, I've genuinely tried to engage with this patchset in good faith.
>
> 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.
However, it seems like a bigger change that will require more discussion.
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.
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.
Does this seem reasonable to you?
>
> --Andy