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]
Date:   Thu, 3 Feb 2022 11:08:55 -0500
From:   Mauricio Vásquez Bernal <mauricio@...volk.io>
To:     Quentin Monnet <quentin@...valent.com>
Cc:     Networking <netdev@...r.kernel.org>, bpf <bpf@...r.kernel.org>,
        Alexei Starovoitov <ast@...nel.org>,
        Daniel Borkmann <daniel@...earbox.net>,
        Andrii Nakryiko <andrii@...nel.org>,
        Rafael David Tinoco <rafaeldtinoco@...il.com>,
        Lorenzo Fontana <lorenzo.fontana@...stic.co>,
        Leonardo Di Donato <leonardo.didonato@...stic.co>
Subject: Re: [PATCH bpf-next v5 1/9] libbpf: Implement changes needed for
 BTFGen in bpftool

On Tue, Feb 1, 2022 at 3:57 PM Quentin Monnet <quentin@...valent.com> wrote:
>
> 2022-01-28 17:33 UTC-0500 ~ Mauricio Vásquez <mauricio@...volk.io>
> > This commit extends libbpf with the features that are needed to
> > implement BTFGen:
> >
> > - Implement bpf_core_create_cand_cache() and bpf_core_free_cand_cache()
> > to handle candidates cache.
> > - Expose bpf_core_add_cands() and bpf_core_free_cands to handle
> > candidates list.
> > - Expose bpf_core_calc_relo_insn() to bpftool.
> >
> > Signed-off-by: Mauricio Vásquez <mauricio@...volk.io>
> > Signed-off-by: Rafael David Tinoco <rafael.tinoco@...asec.com>
> > Signed-off-by: Lorenzo Fontana <lorenzo.fontana@...stic.co>
> > Signed-off-by: Leonardo Di Donato <leonardo.didonato@...stic.co>
>
> Hi, note that the patchset (or at least, this patch) does not apply
> cleanly. Can you please double-check that it is based on bpf-next?

I missed one commit on this submission...

> > ---
> >  tools/lib/bpf/libbpf.c          | 44 ++++++++++++++++++++++-----------
> >  tools/lib/bpf/libbpf_internal.h | 12 +++++++++
> >  2 files changed, 41 insertions(+), 15 deletions(-)
> >
> > diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> > index 12771f71a6e7..61384d219e28 100644
> > --- a/tools/lib/bpf/libbpf.c
> > +++ b/tools/lib/bpf/libbpf.c
> > @@ -5195,18 +5195,18 @@ size_t bpf_core_essential_name_len(const char *name)
> >       return n;
> >  }
> >
> > -static void bpf_core_free_cands(struct bpf_core_cand_list *cands)
> > +void bpf_core_free_cands(struct bpf_core_cand_list *cands)
> >  {
> >       free(cands->cands);
> >       free(cands);
> >  }
> >
> > -static int bpf_core_add_cands(struct bpf_core_cand *local_cand,
> > -                           size_t local_essent_len,
> > -                           const struct btf *targ_btf,
> > -                           const char *targ_btf_name,
> > -                           int targ_start_id,
> > -                           struct bpf_core_cand_list *cands)
> > +int bpf_core_add_cands(struct bpf_core_cand *local_cand,
> > +                    size_t local_essent_len,
> > +                    const struct btf *targ_btf,
> > +                    const char *targ_btf_name,
> > +                    int targ_start_id,
> > +                    struct bpf_core_cand_list *cands)
> >  {
> >       struct bpf_core_cand *new_cands, *cand;
> >       const struct btf_type *t, *local_t;
> > @@ -5577,6 +5577,25 @@ static int bpf_core_resolve_relo(struct bpf_program *prog,
> >                                      targ_res);
> >  }
> >
> > +struct hashmap *bpf_core_create_cand_cache(void)
> > +{
> > +     return hashmap__new(bpf_core_hash_fn, bpf_core_equal_fn, NULL);
> > +}
> > +
> > +void bpf_core_free_cand_cache(struct hashmap *cand_cache)
> > +{
> > +     struct hashmap_entry *entry;
> > +     int i;
> > +
> > +     if (IS_ERR_OR_NULL(cand_cache))
> > +             return;
> > +
> > +     hashmap__for_each_entry(cand_cache, entry, i) {
> > +             bpf_core_free_cands(entry->value);
> > +     }
> > +     hashmap__free(cand_cache);
> > +}
> > +
> >  static int
> >  bpf_object__relocate_core(struct bpf_object *obj, const char *targ_btf_path)
> >  {
> > @@ -5584,7 +5603,6 @@ bpf_object__relocate_core(struct bpf_object *obj, const char *targ_btf_path)
> >       struct bpf_core_relo_res targ_res;
> >       const struct bpf_core_relo *rec;
> >       const struct btf_ext_info *seg;
> > -     struct hashmap_entry *entry;
> >       struct hashmap *cand_cache = NULL;
> >       struct bpf_program *prog;
> >       struct bpf_insn *insn;
> > @@ -5603,7 +5621,7 @@ bpf_object__relocate_core(struct bpf_object *obj, const char *targ_btf_path)
> >               }
> >       }
> >
> > -     cand_cache = hashmap__new(bpf_core_hash_fn, bpf_core_equal_fn, NULL);
> > +     cand_cache = bpf_core_create_cand_cache();
> >       if (IS_ERR(cand_cache)) {
> >               err = PTR_ERR(cand_cache);
> >               goto out;
> > @@ -5694,12 +5712,8 @@ bpf_object__relocate_core(struct bpf_object *obj, const char *targ_btf_path)
> >       btf__free(obj->btf_vmlinux_override);
> >       obj->btf_vmlinux_override = NULL;
> >
> > -     if (!IS_ERR_OR_NULL(cand_cache)) {
> > -             hashmap__for_each_entry(cand_cache, entry, i) {
> > -                     bpf_core_free_cands(entry->value);
> > -             }
> > -             hashmap__free(cand_cache);
> > -     }
> > +     bpf_core_free_cand_cache(cand_cache);
> > +
> >       return err;
> >  }
> >
> > diff --git a/tools/lib/bpf/libbpf_internal.h b/tools/lib/bpf/libbpf_internal.h
> > index bc86b82e90d1..686a5654262b 100644
> > --- a/tools/lib/bpf/libbpf_internal.h
> > +++ b/tools/lib/bpf/libbpf_internal.h
> > @@ -529,4 +529,16 @@ static inline int ensure_good_fd(int fd)
> >       return fd;
> >  }
> >
> > +struct hashmap;
> > +
> > +struct hashmap *bpf_core_create_cand_cache(void);
> > +void bpf_core_free_cand_cache(struct hashmap *cand_cache);
> > +int bpf_core_add_cands(struct bpf_core_cand *local_cand,
> > +                    size_t local_essent_len,
> > +                    const struct btf *targ_btf,
> > +                    const char *targ_btf_name,
> > +                    int targ_start_id,
> > +                    struct bpf_core_cand_list *cands);
> > +void bpf_core_free_cands(struct bpf_core_cand_list *cands);
>
> I wonder if these might deserve a comment to mention that they are
> exposed for bpftool? I fear someone might attempt to clean it up and
> remove the unused exports otherwise.

I added a comment there.

Powered by blists - more mailing lists