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] [day] [month] [year] [list]
Date:   Mon, 8 Aug 2022 15:34:58 -0700
From:   Andrii Nakryiko <andrii.nakryiko@...il.com>
To:     Quentin Monnet <quentin@...valent.com>
Cc:     Hangbin Liu <liuhangbin@...il.com>, netdev@...r.kernel.org,
        Andrii Nakryiko <andrii@...nel.org>,
        Alexei Starovoitov <ast@...nel.org>,
        Daniel Borkmann <daniel@...earbox.net>,
        Martin KaFai Lau <martin.lau@...ux.dev>,
        Song Liu <song@...nel.org>, Yonghong Song <yhs@...com>,
        John Fastabend <john.fastabend@...il.com>,
        KP Singh <kpsingh@...nel.org>,
        Stanislav Fomichev <sdf@...gle.com>,
        Hao Luo <haoluo@...gle.com>, Jiri Olsa <jolsa@...nel.org>,
        bpf@...r.kernel.org
Subject: Re: [PATCH bpf-next] libbpf: try to add a name for bpftool
 self-created maps

On Mon, Aug 8, 2022 at 6:45 AM Quentin Monnet <quentin@...valent.com> wrote:
>
> On 08/08/2022 10:33, Hangbin Liu wrote:
> > As discussed before[1], the bpftool self-created maps can appear in final
> > map show output due to deferred removal in kernel. These maps don't have
> > a name, which would make users confused about where it comes from.
> >
> > Adding names for these maps could make users know what these maps used for.
> > It also could make some tests (like test_offload.py, which skip base maps
> > without names as a workaround) filter them out.
> >
> > As Quentin suggested, add a small wrapper to fall back with no name
> > if kernel is not supported.
> >
> > [1] https://lore.kernel.org/bpf/CAEf4BzY66WPKQbDe74AKZ6nFtZjq5e+G3Ji2egcVytB9R6_sGQ@mail.gmail.com/
> >
> > Suggested-by: Quentin Monnet <quentin@...valent.com>
> > Signed-off-by: Hangbin Liu <liuhangbin@...il.com>
> > ---
> >  tools/lib/bpf/libbpf.c | 22 +++++++++++++++++++---
> >  1 file changed, 19 insertions(+), 3 deletions(-)
> >
> > diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> > index 77e3797cf75a..db4f1a02b9e0 100644
> > --- a/tools/lib/bpf/libbpf.c
> > +++ b/tools/lib/bpf/libbpf.c
> > @@ -4423,6 +4423,22 @@ static int probe_kern_prog_name(void)
> >       return probe_fd(ret);
> >  }
> >
> > +static int probe_kern_map_name(enum bpf_map_type map_type,
> > +                            const char *map_name, __u32 key_size,
> > +                            __u32 value_size, __u32 max_entries,
> > +                            const struct bpf_map_create_opts *opts)
> > +{
> > +     int map;
> > +
> > +     map = bpf_map_create(map_type, map_name, key_size, value_size, max_entries, opts);
> > +     if (map < 0 && errno == EINVAL) {
> > +             /* Retry without name */
> > +             map = bpf_map_create(map_type, NULL, key_size, value_size, max_entries, opts);
> > +     }
> > +
> > +     return map;
> > +}
> > +
> >  static int probe_kern_global_data(void)
> >  {
> >       char *cp, errmsg[STRERR_BUFSIZE];
> > @@ -4434,7 +4450,7 @@ static int probe_kern_global_data(void)
> >       };
> >       int ret, map, insn_cnt = ARRAY_SIZE(insns);
> >
> > -     map = bpf_map_create(BPF_MAP_TYPE_ARRAY, NULL, sizeof(int), 32, 1, NULL);
> > +     map = probe_kern_map_name(BPF_MAP_TYPE_ARRAY, "global_data", sizeof(int), 32, 1, NULL);
>
> Thanks! Some comments on the naming: It reads strange here to "probe"
> for the maps, given that we still need to compare the return value
> below. Maybe use something else instead of "probe_kern_map_name()"?
> Maybe "map_create_adjust_name()" or "map_create_compat()" (or something
> else)?
>
> Regarding "global_data": If the intent is to filter out these maps from
> the output of bpftool for example, should we use a common prefix for the
> three of them? "libbpf_" or "probe_"? Or even something shorter? I know
> we're limited to 15 characters.

Yeah, "libbpf_" sounds like the best name to let users know it's some
libbpf-specific internal thing. It leaves only 8 characters for the
"feature name", but we can be creative about those 8 symbols, right?
:)

>
> Quentin

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ