Re: [PATCH bpf-next v1 1/3] x86/mm: Resolve BPF exception fixups for user address faults under SMAP
From: Andy Lutomirski
Date: Thu Nov 26 2026 - 00:38:41 EST
On Tue, Nov 24, 2026, at 10:45 PM, Alexei Starovoitov wrote:
>
> 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().
With copy_from_kernel_nofault(), I can grep the kernel sources and attempt to determine whether it's being used in problematic ways. With eBPF, this is not really possible.
>
> 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.
Okay. I randomly sampled a few use cases. I found some that are only run on paths where we're already crashing and lots that would require an entire separate major screwup to point to MMIO. (The most common pattern appears to be reading regs->ip in a path where *usually* regs->ip points to kernel text and, if we have gotten so corrupt that it doesn't, then at least we want to crash cleanly instead of recursively.)
x86 does not have a special syscall to do copy_from_user_nofault(). If we did, it would be a pretty obviously terrible idea. But eBPF has an actual API here. I think it should make sense.
Off the top of my head, I see two possibly severe problems:
1. MMIO and, more generally, addresses where reads may have side effects.
2. Really nasty information leaks.
Let me elaborate on #2. I'm informed by reliable sources (a chatbot) that a common use of PROBE_MEM is to read from pointers where the verifier can't verify the lifetime. I bet it's not terribly uncommon to find progrrams in the while where it is genuinely possible for the program to follow a pointer in a data structure that has been freed.
This gives something to the effect of:
u64 value = read_nofault(foo->p);
where foo points to freed memory and value is either the actual bytes at whatever address is currently in foo->p or zero (or a MMIO screwup that will take down the whole system in creative ways).
And the author of the program thinks "well, *usually* it's the right value and I'm just collecting statistics".
These days it's easier than ever for a malicious user to write a cute little tool to put a value they control into foo->p. And they can point it at *someone else's* memory. And they can get that memory leaked into the statistics. And probably find a clever way to extract the value.
*If* it were somehow deemed that #1 was the *only* major problem with PROBE_MEM and the feature otherwise made sense and it could have well-defined semantics, I think that x86 could offer a reasonably performant way to do a read that's guaranteed to be side-effect-free. I can think of at least two ways to do it, both nontrivial. But there are a lot of ifs here.
--Andy