From: Jiri Olsa <olsajiri@gmail.com>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
bpf@vger.kernel.org, Martin KaFai Lau <kafai@fb.com>,
Song Liu <songliubraving@fb.com>, Yonghong Song <yhs@fb.com>,
John Fastabend <john.fastabend@gmail.com>,
KP Singh <kpsingh@chromium.org>,
Stanislav Fomichev <sdf@google.com>, Hao Luo <haoluo@google.com>
Subject: Re: [PATCH bpf] bpf: Force kprobe multi expected_attach_type for kprobe_multi link
Date: Sat, 17 Jun 2023 21:16:55 +0200 [thread overview]
Message-ID: <ZI4Gp1dI0JtDM9Kx@krava> (raw)
In-Reply-To: <CAEf4BzaoecaejztBK9O+hbh1d-g_iTSXgpDrJAZmcaWYiWBn3Q@mail.gmail.com>
On Fri, Jun 16, 2023 at 09:53:00AM -0700, Andrii Nakryiko wrote:
> On Tue, Jun 13, 2023 at 4:31 AM Jiri Olsa <jolsa@kernel.org> wrote:
> >
> > We currently allow to create perf link for program with
> > expected_attach_type == BPF_TRACE_KPROBE_MULTI.
> >
> > This will cause crash when we call helpers like get_attach_cookie or
> > get_func_ip in such program, because it will call the kprobe_multi's
> > version (current->bpf_ctx context setup) of those helpers while it
> > expects perf_link's current->bpf_ctx context setup.
> >
> > Making sure that we use BPF_TRACE_KPROBE_MULTI expected_attach_type
> > only for programs attaching through kprobe_multi link.
> >
> > Fixes: ca74823c6e16 ("bpf: Add cookie support to programs attached with kprobe multi link")
> > Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> > ---
> > kernel/bpf/syscall.c | 5 +++++
> > 1 file changed, 5 insertions(+)
> >
> > diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
> > index 0c21d0d8efe4..e8fe04a5db93 100644
> > --- a/kernel/bpf/syscall.c
> > +++ b/kernel/bpf/syscall.c
> > @@ -4675,6 +4675,11 @@ static int link_create(union bpf_attr *attr, bpfptr_t uattr)
> > ret = bpf_perf_link_attach(attr, prog);
> > break;
> > case BPF_PROG_TYPE_KPROBE:
> > + if (prog->expected_attach_type == BPF_TRACE_KPROBE_MULTI &&
> > + attr->link_create.attach_type != BPF_TRACE_KPROBE_MULTI) {
> > + ret = -EINVAL;
> > + goto out;
> > + }
>
> there is a separate expected attach type validation switch above this,
> shouldn't this go there? We also have
> bpf_prog_attach_check_attach_type() call above as well, and tbh by now
> I'm not sure why we have like three places to check conditions like
> this... But I'd put this check in either
> bpf_prog_attach_check_attach_type() or in the dedicated switch for
> attach_type checks.
>
bpf_prog_attach_check_attach_type looks good, will move it there
thanks,
jirka
prev parent reply other threads:[~2023-06-17 19:17 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-13 11:31 [PATCH bpf] bpf: Force kprobe multi expected_attach_type for kprobe_multi link Jiri Olsa
2023-06-13 14:35 ` Yonghong Song
2023-06-16 16:53 ` Andrii Nakryiko
2023-06-17 19:16 ` Jiri Olsa [this message]
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=ZI4Gp1dI0JtDM9Kx@krava \
--to=olsajiri@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=haoluo@google.com \
--cc=john.fastabend@gmail.com \
--cc=kafai@fb.com \
--cc=kpsingh@chromium.org \
--cc=sdf@google.com \
--cc=songliubraving@fb.com \
--cc=yhs@fb.com \
/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