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/4] bpf: handle bpf_user_pt_regs_t typedef explicitly for PTR_TO_CTX global arg
Date: Tue, 13 Feb 2024 19:08:53 +0200 [thread overview]
Message-ID: <4950b053549136fbf852160aa64676e2003c4255.camel@gmail.com> (raw)
In-Reply-To: <CAEf4Bza5yWU0Tu18ZfPB_XJeAKx_iKyR=FCkSvWXE17vPa73DA@mail.gmail.com>
On Tue, 2024-02-13 at 09:02 -0800, Andrii Nakryiko wrote:
[...]
> > t = btf_type_by_id(btf, t->type);
> > - while (btf_type_is_modifier(t))
> > - t = btf_type_by_id(btf, t->type);
> > - if (!btf_type_is_struct(t)) {
> > +
> > + /* Skip modifiers, but stop if skipping of typedef would
> > + * lead an anonymous type, e.g. like for s390:
> > + *
> > + * typedef struct { ... } user_pt_regs;
> > + * typedef user_pt_regs bpf_user_pt_regs_t;
> > + */
> > + t = __btf_type_skip_qualifiers(btf, t);
> > + while (btf_type_is_typedef(t)) {
> > + const struct btf_type *t1;
> > +
> > + t1 = btf_type_by_id(btf, t->type);
> > + t1 = __btf_type_skip_qualifiers(btf, t1);
> > + tname = btf_name_by_offset(btf, t1->name_off);
> > + if (!tname || tname[0] == '\0')
> > + break;
> > + t = t1;
> > + }
> > + if (!btf_type_is_struct(t) && !btf_type_is_typedef(t)) {
>
> and now we potentially are intermixing structs and typedefs and don't
> really distinguish them later (but struct abc is not the same thing as
> typedef abc), which is probably not what we want.
Yes, need a condition in the end to check that 'ctx_type' and 't' have
same kind.
> Also, we resolve typedef to its underlying type *or* typedef, right?
> So if I have typedef A -> typedef B -> struct C, we won't get to
> struct C, even if struct C is the expected correct context type for a
> given program type (and it should work).
For code above we would get to 'struct C'.
> So in general, yes, I think this code could be changed to not ignore
> typedefs and do the right thing, but we'd need to be very careful to
> not allow unexpected things for all program types. Given only kprobes
> define context as typedef, it's simpler and more reliable to special
> case kprobe, IMO.
Maybe, I do not insist.
next prev parent reply other threads:[~2024-02-13 17:08 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-12 23:32 [PATCH v2 bpf-next 0/4] Fix global subprog PTR_TO_CTX arg handling Andrii Nakryiko
2024-02-12 23:32 ` [PATCH v2 bpf-next 1/4] bpf: simplify btf_get_prog_ctx_type() into btf_is_prog_ctx_type() Andrii Nakryiko
2024-02-12 23:32 ` [PATCH v2 bpf-next 2/4] bpf: handle bpf_user_pt_regs_t typedef explicitly for PTR_TO_CTX global arg Andrii Nakryiko
2024-02-13 16:40 ` Eduard Zingerman
2024-02-13 17:02 ` Andrii Nakryiko
2024-02-13 17:08 ` Eduard Zingerman [this message]
2024-02-13 18:12 ` Andrii Nakryiko
2024-02-13 18:48 ` Eduard Zingerman
2024-02-13 18:59 ` Andrii Nakryiko
2024-02-12 23:32 ` [PATCH v2 bpf-next 3/4] bpf: don't infer PTR_TO_CTX for programs with unnamed context type Andrii Nakryiko
2024-02-12 23:32 ` [PATCH v2 bpf-next 4/4] selftests/bpf: add anonymous user struct as global subprog arg test Andrii Nakryiko
2024-02-13 12:51 ` [PATCH v2 bpf-next 0/4] Fix global subprog PTR_TO_CTX arg handling Jiri Olsa
2024-02-13 16:39 ` Eduard Zingerman
2024-02-14 2: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=4950b053549136fbf852160aa64676e2003c4255.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