BPF List
 help / color / mirror / Atom feed
From: Eduard Zingerman <eddyz87@gmail.com>
To: Kumar Kartikeya Dwivedi <memxor@gmail.com>,
	Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: Matt Bobrowski <mattbobrowski@google.com>,
	bpf <bpf@vger.kernel.org>,  Alexei Starovoitov	 <ast@kernel.org>,
	Andrii Nakryiko <andrii@kernel.org>,
	Daniel Borkmann	 <daniel@iogearbox.net>,
	Martin KaFai Lau <martin.lau@linux.dev>,
	Kernel Team	 <kernel-team@fb.com>,
	Yonghong Song <yonghong.song@linux.dev>
Subject: Re: [PATCH bpf-next v1 4/8] bpf: attribute __arg_untrusted for global function parameters
Date: Fri, 04 Jul 2025 13:34:02 -0700	[thread overview]
Message-ID: <f61674e3d16bee41b35acaac70285f673259d023.camel@gmail.com> (raw)
In-Reply-To: <CAP01T76tXJVMk_Yy1USRNity5rA=DXe9BgS7OOa0G960UsVPcg@mail.gmail.com>

On Fri, 2025-07-04 at 22:20 +0200, Kumar Kartikeya Dwivedi wrote:
> On Fri, 4 Jul 2025 at 22:06, Alexei Starovoitov
> <alexei.starovoitov@gmail.com> wrote:
> > 
> > On Fri, Jul 4, 2025 at 12:23 PM Eduard Zingerman <eddyz87@gmail.com> wrote:
> > > 
> > > On Fri, 2025-07-04 at 21:15 +0200, Kumar Kartikeya Dwivedi wrote:
> > > 
> > > [...]
> > > 
> > > > Yeah, so if the user specifies a type and has co-re enabled, they're
> > > > accessing a kernel struct.
> > > > If they're doing it without co-re, it's broken today already, or they
> > > > know the struct is fixed in layout somehow so it's ok.
> > > > If not, they want to access things at fixed offsets. So we can just
> > > > use the type they're using to model untrusted derefs.
> > > > 
> > > > So always using prog BTF makes sense to me.
> > > 
> > > Ok, I'm switching to always using prog BTF.
> > 
> > Hold on. The concept of ptr_to_btf_id|untrusted that points to
> > prog type doesn't exist today. We should be careful when introducing
> > such things.
> > I prefer to keep btf_get_ptr_to_btf_id() in this patch
> > and think through untrusted|ptr_to prog type later,
> > since the use case of untrusted local type doesn't quite resonate with me.
> 
> Yeah, we can add it separately from this set, but otherwise I don't
> see the problem with the idea.
> There is no reason to restrict ourselves to kernel types.
> All accesses will be untrusted, it's like probe_read so it should be
> well-formed for any type.
> It's the same reason why pointers to non-struct makes sense. Ideally
> any type should be allowed.
> 
> Otherwise to reconstruct a walk of untrusted pointer chains the user
> will do it by hand.
> Showing the structure types to the verifier allows it to be inserted
> automatically.

I agree with Kumar, it's an expansion of the idea behind
bpf_rdonly_cast(...,0). Having some untrusted pointer source
(e.g. value from a program stack trace) one can already write:

  struct foo {
    struct bar *bar;
  };

  struct foo *foo = bpf_rdonly_cast(magic_value, 0);
  struct bar *bar = bpf_rdonly_cast(foo->bar, 0);

We can make it more convenient by introducing an additional kfunc:

  struct foo {
    struct bar *bar;
  };

  struct foo *foo = bpf_rdonly_cast_local(magic_value, bpf_core_type_id_local(struct foo));
  ... just use foo->bar ...

As for global function parameters. Discussed this with Kumar off-list
a bit. There are types with generic names in vmlinux.h, like "region",
"regex", "hash", "key". So, imo, the above bpf_rdonly_cast_local()
should be accompanied by its own tag: __arg_untrusted_local.

  reply	other threads:[~2025-07-04 20:34 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-02 22:42 [PATCH bpf-next v1 0/8] bpf: additional use-cases for untrusted PTR_TO_MEM Eduard Zingerman
2025-07-02 22:42 ` [PATCH bpf-next v1 1/8] bpf: make makr_btf_ld_reg return error for unexpected reg types Eduard Zingerman
2025-07-04 17:20   ` Kumar Kartikeya Dwivedi
2025-07-02 22:42 ` [PATCH bpf-next v1 2/8] bpf: rdonly_untrusted_mem for btf id walk pointer leafs Eduard Zingerman
2025-07-04 17:27   ` Kumar Kartikeya Dwivedi
2025-07-02 22:42 ` [PATCH bpf-next v1 3/8] selftests/bpf: ptr_to_btf_id struct walk ending with primitive pointer Eduard Zingerman
2025-07-04 17:34   ` Kumar Kartikeya Dwivedi
2025-07-02 22:42 ` [PATCH bpf-next v1 4/8] bpf: attribute __arg_untrusted for global function parameters Eduard Zingerman
2025-07-03  3:18   ` Alexei Starovoitov
2025-07-03 21:25     ` Eduard Zingerman
2025-07-04 18:17       ` Alexei Starovoitov
2025-07-04 18:03   ` Kumar Kartikeya Dwivedi
2025-07-04 18:28     ` Eduard Zingerman
2025-07-04 18:33       ` Eduard Zingerman
2025-07-04 18:50         ` Kumar Kartikeya Dwivedi
2025-07-04 19:07           ` Eduard Zingerman
2025-07-04 19:15             ` Kumar Kartikeya Dwivedi
2025-07-04 19:23               ` Eduard Zingerman
2025-07-04 20:05                 ` Alexei Starovoitov
2025-07-04 20:20                   ` Kumar Kartikeya Dwivedi
2025-07-04 20:34                     ` Eduard Zingerman [this message]
2025-07-04 20:47                       ` Alexei Starovoitov
2025-07-02 22:42 ` [PATCH bpf-next v1 5/8] libbpf: __arg_untrusted in bpf_helpers.h Eduard Zingerman
2025-07-04 18:04   ` Kumar Kartikeya Dwivedi
2025-07-02 22:42 ` [PATCH bpf-next v1 6/8] selftests/bpf: test cases for __arg_untrusted Eduard Zingerman
2025-07-04 18:05   ` Kumar Kartikeya Dwivedi
2025-07-02 22:42 ` [PATCH bpf-next v1 7/8] bpf: support for void/primitive __arg_untrusted global func params Eduard Zingerman
2025-07-03  3:20   ` Alexei Starovoitov
2025-07-03 21:49     ` Eduard Zingerman
2025-07-04 18:11       ` Alexei Starovoitov
2025-07-04 18:09   ` Kumar Kartikeya Dwivedi
2025-07-02 22:42 ` [PATCH bpf-next v1 8/8] selftests/bpf: tests for __arg_untrusted void * " Eduard Zingerman
2025-07-04 18:12   ` Kumar Kartikeya Dwivedi
2025-07-04 18:35     ` Eduard Zingerman

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=f61674e3d16bee41b35acaac70285f673259d023.camel@gmail.com \
    --to=eddyz87@gmail.com \
    --cc=alexei.starovoitov@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=kernel-team@fb.com \
    --cc=martin.lau@linux.dev \
    --cc=mattbobrowski@google.com \
    --cc=memxor@gmail.com \
    --cc=yonghong.song@linux.dev \
    /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