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 - 12:31:30 EST




On Wed, Nov 25, 2026, at 10:18 PM, Alexei Starovoitov wrote:
> On Wed, Nov 25, 2026 at 09:38 PM Andy Lutomirski <luto@xxxxxxxxxx> wrote:
>
> Pls wrap your emails to ~80 char per line as the whole kernel community does.
>
>> 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.
>
> let me google it for you without bpf :)
>
> echo 'f tcp_retransmit_skb f=sk->sk_socket->file' >> dynamic_events
> echo 'p vfs_read v=@ADDR' >> kprobe_events

Fair enough.

>
> It does the same walk by BTF with one copy_from_kernel_nofault() per step.
> No locks, no NULL check.
> The second line reads any kernel address.
>
>> 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.
>
> sigh...
> the kernel has that API since 2009. bpf is not the first user of it
> and not the last:
>
> API since the address is
> ---------------------------- ----- -----------------------------
> probe event: @ADDR, +8(%di) 2009 any number, from a string
> bpf_probe_read[_kernel]() 2015 any scalar in the prog
> PROBE_MEM: a->b->c 2019 a pointer field, by BTF
> PROBE_MEM: bpf_rdonly_cast() 2022 any scalar, explicit cast
> probe event: a->b->c 2023 a pointer field, by BTF
> probe event: (STRUCT)x->b 2026 any value, explicit cast
>
> Every row returns the bytes at the address, or no data on a fault.

Okay. So maybe there should be a nice patch set to *fix* it.

>
> That would be good to have. Every row of the table needs it, so
> maccess.c is the place for it. What are the two ways?

All the ways involve identifying mappings that are safe for no-fault reads. And then one needs a clean way to access them, which could include:

1. Walking a little list or table to validate the address (which may require some sort of synchronization and obviously needs to be NMI-safe -- for systems that use TLB-flush IPIs, blocking interrupts could probably do most of the hard work, and otherwise a little flag set while a read is in progress that can block the change of an address from safe to unsafe would do it.

2. Allocate a PKS key for the purpose and use it. (Only works on systems that have PKS.)

3. Use an entire mm for the purpose and treat it as a user access. This is probably the cleanest solution but it will be slooooooooow.


Note that there is no strict requirement for #1 that every address in the list be mapped. For example, the entire portion of the direct map covering ordinary RAM (and sparse-mapped areas, etc) could be allowed even if they happen to be unmapped.

--Andy