All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Alexei Starovoitov" <alexei.starovoitov@gmail.com>
To: "Andy Lutomirski" <luto@kernel.org>,
	"Kumar Kartikeya Dwivedi" <memxor@gmail.com>,
	<bpf@vger.kernel.org>
Cc: "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>,
	"Peter Zijlstra (Intel)" <peterz@infradead.org>,
	"Thomas Gleixner" <tglx@kernel.org>,
	"Ingo Molnar" <mingo@redhat.com>,
	"Borislav Petkov" <bp@alien8.de>, <kkd@meta.com>,
	<kernel-team@meta.com>,
	"the arch/x86 maintainers" <x86@kernel.org>,
	"Linux Kernel Mailing List" <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: Thu, 26 Nov 2026 06:18:01 +0000	[thread overview]
Message-ID: <DN4X9KVYMONH.VHKD1QED1BUQ@gmail.com> (raw)
In-Reply-To: <5f46d1c1-fdce-4f3b-9d56-675a822b2d65@app.fastmail.com>

On Wed, Nov 25, 2026 at 09:38 PM Andy Lutomirski <luto@kernel.org> 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

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.
Every row is read only and needs root or CAP_PERFMON.

PROBE_MEM has the semantics of bpf_probe_read(). It came to replace
chains of bpf_probe_read() calls. The risk of MMIO was one of the reasons:
https://lore.kernel.org/bpf/20191016032505.2089704-1-ast@kernel.org/
bpf_probe_read() takes any integer. In a->b->c the verifier checks every
step against BTF and rejects a load through an integer field.

> 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).

Yes, that's possible. It's possible in every row of the table.
The first echo line above has the same window.
foo->p is a kernel address here. The range check passes it, and so does
copy_from_kernel_nofault_allowed(). The series doesn't change that load.

> 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.

The value goes into a map, a ring buffer or the trace file.
An unprivileged user has no access to them.
Their reader has root or CAP_PERFMON and can read all kernel memory anyway.
A tool that walks a freed object and hands the value to unprivileged
users has a bug. It's the same bug with a probe event.

> *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.

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?

It's a separate topic from this series. 1 and 2 are about loads from
kernel addresses. The series is about user addresses. Today a compare
refuses them. With patch 2 and SMAP the CPU refuses them.


  reply	other threads:[~2026-11-26  6:18 UTC|newest]

Thread overview: 41+ 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 under SMAP 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  3:03   ` sashiko-bot
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
2026-11-25  3:27                           ` Alexei Starovoitov
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-11-25  4:22   ` Andy Lutomirski
2026-11-25  6:45     ` Alexei Starovoitov
2026-11-26  5:38       ` Andy Lutomirski
2026-11-26  6:18         ` Alexei Starovoitov [this message]
2026-11-26 17:30           ` Andy Lutomirski
2026-11-27  0:18             ` Alexei Starovoitov
2026-11-27 17:51               ` Andy Lutomirski
2026-11-28  1:48               ` Kumar Kartikeya Dwivedi
2026-11-28  1:55                 ` Alexei Starovoitov
2026-12-01  1:49                   ` Andy Lutomirski
2026-12-01  2:06                     ` Kumar Kartikeya Dwivedi
2026-12-01  2:38                       ` Andy Lutomirski
2026-12-01  3:24                         ` Kumar Kartikeya Dwivedi
2026-12-01 19:16                           ` Andy Lutomirski
2026-12-01 20:16                             ` Kumar Kartikeya Dwivedi
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
2026-10-09  2:56   ` sashiko-bot

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=DN4X9KVYMONH.VHKD1QED1BUQ@gmail.com \
    --to=alexei.starovoitov@gmail.com \
    --cc=andrii@kernel.org \
    --cc=bp@alien8.de \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.