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 23 2026 - 12:28:34 EST


On Mon, 23 Nov 2026 at 07:58, Alexei Starovoitov
<alexei.starovoitov@xxxxxxxxx> wrote:
>
> On Sun, Nov 22, 2026 at 07:56 PM Kumar Kartikeya Dwivedi <memxor@xxxxxxxxx> wrote:
> > On Mon, 23 Nov 2026 at 03:55, Borislav Petkov <bp@xxxxxxxxx> wrote:
>
> >> "the only line of defense is for is_bpf_text_address() to really DTRT."
>
> Boris,
> SMAP stays on. The SMAP branch in do_user_addr_fault() runs only with
> AC clear, after the CPU refused the load.
> A wrong answer from is_bpf_text_address() can hide an oops,
> but it cannot expose user memory, so your concerns are unsound.
>
> > In fact, for kernel address faults, we already invoke it for exception
> > handling. This change would simply extend that to user address faults,
> > optionally for BPF code; otherwise, we panic as usual.
>
> Not quite. See:
>
> fixup_exception(regs)
> search_exception_tables(regs->ip)
> search_bpf_extables(ip)
> bpf_prog_ksym_find(ip) progs only, no trampolines
> search_extable(ip) exact match of the insn
>
> Here is the alternative
>
> diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
> index aa88370..9fe8705 100644
> --- a/arch/x86/mm/fault.c
> +++ b/arch/x86/mm/fault.c
> @@ -1263,7 +1263,16 @@ void do_user_addr_fault(struct pt_regs *regs,
> !(error_code & X86_PF_USER) &&
> !(regs->flags & X86_EFLAGS_AC))) {
> /*
> - * No extable entry here. This was a kernel access to an
> + * The CPU refused the access. If the BPF JIT marked this load
> + * as one that may fault, skip it and zero the destination.
> + */
> + if (!user_mode(regs) && !(error_code & X86_PF_WRITE) &&
> + ex_get_fixup_type(regs->ip) == EX_TYPE_BPF &&
> + fixup_exception(regs, X86_TRAP_PF, error_code, address))
> + return;
> +
> + /*
> + * No other fixups here. This was a kernel access to an

I guess this is better in some ways than the is_bpf_text_address()
predicate, since the condition is tighter, and since we rely on the
exception table entry type itself. I am fine with reworking in this
direction if others feel it is better.