From: Eduard Zingerman <eddyz87@gmail.com>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: Andrii Nakryiko <andrii@kernel.org>,
bpf@vger.kernel.org, ast@kernel.org, daniel@iogearbox.net,
martin.lau@kernel.org, kernel-team@meta.com
Subject: Re: [PATCH v2 bpf-next 2/7] libbpf: fix __arg_ctx type enforcement for perf_event programs
Date: Fri, 26 Jan 2024 23:32:30 +0200 [thread overview]
Message-ID: <63c28870a70aceed3385b2c018880399f32357df.camel@gmail.com> (raw)
In-Reply-To: <CAEf4BzY8XoPmHCTzp=THQr+kYpXGo5G9hLwzJWGSquFt-DZHnw@mail.gmail.com>
On Fri, 2024-01-26 at 11:06 -0800, Andrii Nakryiko wrote:
> On Fri, Jan 26, 2024 at 5:24 AM Eduard Zingerman <eddyz87@gmail.com> wrote:
> >
> > On Thu, 2024-01-25 at 12:55 -0800, Andrii Nakryiko wrote:
> > [...]
> >
> > > @@ -6379,11 +6388,21 @@ static bool need_func_arg_type_fixup(const struct btf *btf, const struct bpf_pro
> > > /* special cases */
> > > switch (prog->type) {
> > > case BPF_PROG_TYPE_KPROBE:
> > > - case BPF_PROG_TYPE_PERF_EVENT:
> > > /* `struct pt_regs *` is expected, but we need to fix up */
> > > if (btf_is_struct(t) && strcmp(tname, "pt_regs") == 0)
> > > return true;
> > > break;
> >
> > Sorry, this was probably discussed, but I got lost a bit.
> > Kernel side does not change pt_regs for BPF_PROG_TYPE_KPROBE
> > (in ./kernel/bpf/btf.c:btf_validate_prog_ctx_type)
> > but here we do, why do it differently?
> >
>
> Hm... We do the same. After this patch w end up with this logic on
> libbpf side (which matches kernel-side one, I believe):
>
> for KPROBE => allow pt_regs (unconditionally)
> for PERF_EVENT => allow user_regs_struct|user_pt_regs|pt_regs,
> depending on bpf_user_pt_regs_t definition on host platform
>
> That should match what the kernel is doing.
Oh..., I see:
After (and before) this patch on libbpf side for KPROBE/pt_regs
need_func_arg_type_fixup() would return true,
thus bpf_program_fixup_func_info() would apply type transformation
(convert it to bpf_user_pt_regs_t).
And kernel before the arg:ctx series expected bpf_user_pt_regs_t
for global subprograms called from KPROBE programs,
hence old kernel would accept program with KPROBE/pt_regs
thanks to libbpf manipulations.
I was put off by need_func_arg_type_fixup() returning true,
thus requiring change, and btf_validate_prog_ctx_type()
just accepting pt_regs => not doing anything.
Thank you for explaining.
next prev parent reply other threads:[~2024-01-26 21:32 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-25 20:55 [PATCH v2 bpf-next 0/7] Trusted PTR_TO_BTF_ID arg support in global subprogs Andrii Nakryiko
2024-01-25 20:55 ` [PATCH v2 bpf-next 1/7] libbpf: integrate __arg_ctx feature detector into kernel_supports() Andrii Nakryiko
2024-01-25 20:55 ` [PATCH v2 bpf-next 2/7] libbpf: fix __arg_ctx type enforcement for perf_event programs Andrii Nakryiko
2024-01-26 13:24 ` Eduard Zingerman
2024-01-26 19:06 ` Andrii Nakryiko
2024-01-26 21:32 ` Eduard Zingerman [this message]
2024-01-26 22:21 ` Andrii Nakryiko
2024-01-25 20:55 ` [PATCH v2 bpf-next 3/7] bpf: move arg:ctx type enforcement check inside the main logic loop Andrii Nakryiko
2024-01-25 20:55 ` [PATCH v2 bpf-next 4/7] bpf: add __arg_trusted global func arg tag Andrii Nakryiko
2024-01-25 20:55 ` [PATCH v2 bpf-next 5/7] bpf: add arg:maybe_null tag to be combined with trusted pointers Andrii Nakryiko
2024-01-25 20:55 ` [PATCH v2 bpf-next 6/7] libbpf: add __arg_trusted and __arg_maybe_null tag macros Andrii Nakryiko
2024-01-25 20:55 ` [PATCH v2 bpf-next 7/7] selftests/bpf: add trusted global subprog arg tests Andrii Nakryiko
2024-01-29 17:29 ` [PATCH v2 bpf-next 0/7] Trusted PTR_TO_BTF_ID arg support in global subprogs Eduard Zingerman
2024-01-29 20:50 ` patchwork-bot+netdevbpf
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=63c28870a70aceed3385b2c018880399f32357df.camel@gmail.com \
--to=eddyz87@gmail.com \
--cc=andrii.nakryiko@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=kernel-team@meta.com \
--cc=martin.lau@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;
as well as URLs for NNTP newsgroup(s).