From: Borislav Petkov <bp@alien8.de>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: Kumar Kartikeya Dwivedi <memxor@gmail.com>,
bpf@vger.kernel.org, Puranjay Mohan <puranjay@kernel.org>,
Andrii Nakryiko <andrii@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Eduard Zingerman <eddyz87@gmail.com>,
Emil Tsalapatis <emil@etsalapatis.com>,
Ihor Solodrai <ihor.solodrai@linux.dev>,
Dave Hansen <dave.hansen@linux.intel.com>,
Andy Lutomirski <luto@kernel.org>,
Peter Zijlstra <peterz@infradead.org>,
Thomas Gleixner <tglx@kernel.org>, Ingo Molnar <mingo@redhat.com>,
kkd@meta.com, kernel-team@meta.com, x86@kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH bpf-next v1 1/3] x86/mm: Resolve BPF exception fixups for user address faults under SMAP
Date: Tue, 24 Nov 2026 18:17:33 -0800 [thread overview]
Message-ID: <20261125021733.GAawZFPYeXUtqNINJ2@fat_crate.local> (raw)
In-Reply-To: <DN386F271FUR.35EWQWGMEMX7K@gmail.com>
On Tue, Nov 24, 2026 at 06:25:45AM +0000, Alexei Starovoitov wrote:
> On Mon, Nov 23, 2026 at 10:51 AM Borislav Petkov <bp@alien8.de> 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.
That's very much appreciated - much better than telling me that I don't
understand BPF and I should not ask questions.
> 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 &&
Ok, I see the JIT is marking exception table entries with that in those
arenas.
So if someone would try to exploit this, then something must've jitted
a binary blob just right in order to bypass that complex conditional.
> SMAP stays enabled in that case too.
All I mean is, this is the first scenario where one can bypass it. The
exception fixup thing.
> 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.
Yes, I guess, even if it were a malicious blob, what ex_handler_bpf() is doing
to it is limited so I guess that's fine-ish. I mean, if the machine is already
loading bpf programs from userspace, the risk is already there.
> 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.
Yes, that's a bit better.
> A JITed bpf prog is not a user space program.
I meant, it is a user program which gets loaded and runs in the kernel at
CPL0. We're on the same page.
> 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.
The hurdles are more, which is better. I guess we can try it and see what
catches fire.
Next time, when you decide to touch core arch functionality like the #PF
handler, please include us in the design *early* too so that we can chime in
and check the sanity of such proposals.
Thanks!
--
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquette
next prev parent reply other threads:[~2026-11-25 2:18 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-09 2:49 [PATCH bpf-next v1 0/3] bpf, x86: Drop the PROBE_MEM address range check " Kumar Kartikeya Dwivedi
2026-10-09 2:49 ` [PATCH bpf-next v1 1/3] x86/mm: Resolve BPF exception fixups for user address faults " Kumar Kartikeya Dwivedi
2026-10-09 4:13 ` Borislav Petkov
2026-10-09 15:23 ` Kumar Kartikeya Dwivedi
2026-11-22 20:08 ` Borislav Petkov
2026-11-22 21:59 ` Kumar Kartikeya Dwivedi
2026-11-23 0:30 ` Borislav Petkov
2026-11-23 0:59 ` Kumar Kartikeya Dwivedi
2026-11-23 2:55 ` Borislav Petkov
2026-11-23 3:56 ` Kumar Kartikeya Dwivedi
2026-11-23 4:34 ` Borislav Petkov
2026-11-23 6:58 ` Alexei Starovoitov
2026-11-23 17:27 ` Kumar Kartikeya Dwivedi
2026-11-23 18:51 ` Borislav Petkov
2026-11-24 6:25 ` Alexei Starovoitov
2026-11-25 2:17 ` Borislav Petkov [this message]
2026-11-23 15:36 ` Dave Hansen
2026-11-23 17:23 ` Kumar Kartikeya Dwivedi
2026-11-24 15:25 ` Dave Hansen
2026-11-24 20:17 ` Alexei Starovoitov
2026-10-09 2:49 ` [PATCH bpf-next v1 2/3] bpf, x86: Skip the PROBE_MEM address range check " Kumar Kartikeya Dwivedi
2026-10-09 3:42 ` bot+bpf-ci
2026-10-09 2:49 ` [PATCH bpf-next v1 3/3] selftests/bpf: Test PROBE_MEM loads from invalid addresses Kumar Kartikeya Dwivedi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261125021733.GAawZFPYeXUtqNINJ2@fat_crate.local \
--to=bp@alien8.de \
--cc=alexei.starovoitov@gmail.com \
--cc=andrii@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=dave.hansen@linux.intel.com \
--cc=eddyz87@gmail.com \
--cc=emil@etsalapatis.com \
--cc=ihor.solodrai@linux.dev \
--cc=kernel-team@meta.com \
--cc=kkd@meta.com \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@kernel.org \
--cc=memxor@gmail.com \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=puranjay@kernel.org \
--cc=tglx@kernel.org \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®