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: <CAEf4Bzao-mCaQ4BnvoFZ_-wMSuoJ3JMJw1SAuy9bNRwy0E7qdg@mail.gmail.com>
Date:   Fri, 9 Oct 2020 11:23:23 -0700
From:   Andrii Nakryiko <andrii.nakryiko@...il.com>
To:     "Daniel T. Lee" <danieltimlee@...il.com>
Cc:     Daniel Borkmann <daniel@...earbox.net>,
        Alexei Starovoitov <ast@...nel.org>,
        Jesper Dangaard Brouer <brouer@...hat.com>,
        Lorenzo Bianconi <lorenzo@...nel.org>,
        bpf <bpf@...r.kernel.org>, Networking <netdev@...r.kernel.org>,
        Xdp <xdp-newbies@...r.kernel.org>
Subject: Re: [PATCH bpf-next 2/3] samples: bpf: Replace attach_tracepoint() to
 attach() in xdp_redirect_cpu

On Fri, Oct 9, 2020 at 9:04 AM Daniel T. Lee <danieltimlee@...il.com> wrote:
>
> From commit d7a18ea7e8b6 ("libbpf: Add generic bpf_program__attach()"),
> for some BPF programs, it is now possible to attach BPF programs
> with __attach() instead of explicitly calling __attach_<type>().
>
> This commit refactors the __attach_tracepoint() with libbpf's generic
> __attach() method. In addition, this refactors the logic of setting
> the map FD to simplify the code. Also, the missing removal of
> bpf_load.o in Makefile has been fixed.
>
> Signed-off-by: Daniel T. Lee <danieltimlee@...il.com>
> ---
>  samples/bpf/Makefile                |   2 +-
>  samples/bpf/xdp_redirect_cpu_user.c | 138 +++++++++++++---------------
>  2 files changed, 67 insertions(+), 73 deletions(-)
>

[...]

>  #define NUM_TP 5
> +#define NUM_MAP 9
>  struct bpf_link *tp_links[NUM_TP] = { 0 };

= {}

> +static int map_fds[NUM_MAP];
>  static int tp_cnt = 0;
>
>  /* Exit return codes */

[...]

> -static struct bpf_link * attach_tp(struct bpf_object *obj,
> -                                  const char *tp_category,
> -                                  const char* tp_name)
> +static int init_tracepoints(struct bpf_object *obj)
>  {
> +       char *tp_section = "tracepoint/";
>         struct bpf_program *prog;
> -       struct bpf_link *link;
> -       char sec_name[PATH_MAX];
> -       int len;
> +       const char *section;
>
> -       len = snprintf(sec_name, PATH_MAX, "tracepoint/%s/%s",
> -                      tp_category, tp_name);
> -       if (len < 0)
> -               exit(EXIT_FAIL);
> +       bpf_object__for_each_program(prog, obj) {
> +               section = bpf_program__section_name(prog);
> +               if (strncmp(section, tp_section, strlen(tp_section)) != 0)
> +                       continue;

that's a convoluted and error-prone way (you can also use "tp/bla/bla"
for tracepoint programs, for example). Use
bpf_program__is_tracepoint() check.

>
> -       prog = bpf_object__find_program_by_title(obj, sec_name);
> -       if (!prog) {
> -               fprintf(stderr, "ERR: finding progsec: %s\n", sec_name);
> -               exit(EXIT_FAIL_BPF);
> +               tp_links[tp_cnt] = bpf_program__attach(prog);
> +               if (libbpf_get_error(tp_links[tp_cnt])) {
> +                       tp_links[tp_cnt] = NULL;
> +                       return -EINVAL;
> +               }
> +               tp_cnt++;
>         }
>

[...]

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ