lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAEf4BzZ_H7_HVL0uDkxP2hvW7FC=9r_V4X2VzgB+uZMZcxP7aQ@mail.gmail.com>
Date:   Tue, 18 Feb 2020 13:24:34 -0800
From:   Andrii Nakryiko <andrii.nakryiko@...il.com>
To:     Jakub Sitnicki <jakub@...udflare.com>
Cc:     Eelco Chaudron <echaudro@...hat.com>, bpf <bpf@...r.kernel.org>,
        "David S. Miller" <davem@...emloft.net>,
        Networking <netdev@...r.kernel.org>,
        Alexei Starovoitov <ast@...nel.org>,
        Daniel Borkmann <daniel@...earbox.net>,
        Martin Lau <kafai@...com>, Song Liu <songliubraving@...com>,
        Yonghong Song <yhs@...com>, Andrii Nakryiko <andriin@...com>,
        Toke Høiland-Jørgensen <toke@...hat.com>
Subject: Re: [PATCH bpf-next v4 2/3] libbpf: Add support for dynamic program
 attach target

On Tue, Feb 18, 2020 at 8:34 AM Jakub Sitnicki <jakub@...udflare.com> wrote:
>
> Hey Eelco,
>
> On Mon, Feb 17, 2020 at 12:43 PM GMT, Eelco Chaudron wrote:
> > Currently when you want to attach a trace program to a bpf program
> > the section name needs to match the tracepoint/function semantics.
> >
> > However the addition of the bpf_program__set_attach_target() API
> > allows you to specify the tracepoint/function dynamically.
> >
> > The call flow would look something like this:
> >
> >   xdp_fd = bpf_prog_get_fd_by_id(id);
> >   trace_obj = bpf_object__open_file("func.o", NULL);
> >   prog = bpf_object__find_program_by_title(trace_obj,
> >                                            "fentry/myfunc");
> >   bpf_program__set_expected_attach_type(prog, BPF_TRACE_FENTRY);
> >   bpf_program__set_attach_target(prog, xdp_fd,
> >                                  "xdpfilt_blk_all");
> >   bpf_object__load(trace_obj)
> >
> > Acked-by: Toke Høiland-Jørgensen <toke@...hat.com>
> > Signed-off-by: Eelco Chaudron <echaudro@...hat.com>
> > ---
> >  tools/lib/bpf/libbpf.c   |   34 ++++++++++++++++++++++++++++++----
> >  tools/lib/bpf/libbpf.h   |    4 ++++
> >  tools/lib/bpf/libbpf.map |    2 ++
> >  3 files changed, 36 insertions(+), 4 deletions(-)
> >
> > diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> > index 514b1a524abb..0c25d78fb5d8 100644
> > --- a/tools/lib/bpf/libbpf.c
> > +++ b/tools/lib/bpf/libbpf.c
>
> [...]
>
> > @@ -8132,6 +8133,31 @@ void bpf_program__bpil_offs_to_addr(struct bpf_prog_info_linear *info_linear)
> >       }
> >  }
> >
> > +int bpf_program__set_attach_target(struct bpf_program *prog,
> > +                                int attach_prog_fd,
> > +                                const char *attach_func_name)
> > +{
> > +     int btf_id;
> > +
> > +     if (!prog || attach_prog_fd < 0 || !attach_func_name)
> > +             return -EINVAL;
> > +
> > +     if (attach_prog_fd)
> > +             btf_id = libbpf_find_prog_btf_id(attach_func_name,
> > +                                              attach_prog_fd);
> > +     else
> > +             btf_id = __find_vmlinux_btf_id(prog->obj->btf_vmlinux,
> > +                                            attach_func_name,
> > +                                            prog->expected_attach_type);
> > +
> > +     if (btf_id <= 0)
> > +             return btf_id;
>
> Looks like we can get 0 as return value on both error and success
> (below)?  Is that intentional?

Neither libbpf_find_prog_btf_id nor __find_vmlinux_btf_id are going to
return 0 on failure. But I do agree that if (btf_id < 0) check would
be better here.

With that minor nit:

Acked-by: Andrii Nakryiko <andriin@...com>

>
> > +
> > +     prog->attach_btf_id = btf_id;
> > +     prog->attach_prog_fd = attach_prog_fd;
> > +     return 0;
> > +}
> > +
> >  int parse_cpu_mask_str(const char *s, bool **mask, int *mask_sz)
> >  {
> >       int err = 0, n, len, start, end = -1;
>
> [...]

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ