Re: [PATCH bpf-next v1 1/3] x86/mm: Resolve BPF exception fixups for user address faults under SMAP

From: Alexei Starovoitov

Date: Tue Nov 24 2026 - 01:25:56 EST


On Mon, Nov 23, 2026 at 10:51 AM Borislav Petkov <bp@xxxxxxxxx> wrote:
> Look here, our mails crossed last night:
>
> https://lore.kernel.org/r/20261123043409.GFawPCQT2M-hz0mvZP@fat_crate.local

hmm. I thought my diff answered it already, but ok. Here the answers spelled out.

> 1. How reliable is is_bpf_text_address() and what happens if someone manages
> to pull off a hack which bypasses it? In that case, SMAP is basically
> disabled. And yes, "no one can hack this", "can't ROP-chain around it" and
> whatever else is not a good answer. This silly function becomes the last
> and only line of defense.

SMAP stays enabled in that case too.
The fixup doesn't touch CR4.SMAP or AC, and it doesn't retry the load.
ex_handler_bpf() writes 0 into the destination register and moves
regs->ip past the load. User memory is not read.
A jump straight to that load with a user address in the register
gets zero too.
The range check gives the same result today: zero and no oops.
My diff has no is_bpf_text_address(). It checks the type of the extable
entry of the faulting insn.

> 2. Is the rest of the arch code going to get "if is_bpf..." sprinkled around
> it because of some other performance argument?
>
> Because long time ago there was a pile of patches which did sprinkle "if
> (xen)" and they didn't go anywhere. The point being, special-casing
> something completely unrelated is not going to fly.

The diff has one check, and it's on the type of the extable entry.
error_context() does the same for #MC with ex_get_fixup_type().
fixup_exception() has EX_TYPE_BPF already.

> 3. What do I tell the next userspace program type set which wanna do "if
> is_Y_program" in the #PF handler? I take them too? Because I should not
> question their design either and who do I think I am to question that?

A JITed bpf prog is not a user space program.
It's kernel text in ring 0 with an extable, like a module.
The bar is the extable: kernel text, an entry for the faulting insn,
and a type that says "load from any address, skip it on a fault".
That's an inlined get_kernel_nofault(). It isn't specific to bpf.
If you prefer a generic type instead of EX_TYPE_BPF, that works for me.
Then get_kernel_nofault() can use it too, and
copy_from_kernel_nofault_allowed() can drop its user address checks
under SMAP.