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:   Fri, 19 Nov 2021 09:25:11 -0800
From:   Andrii Nakryiko <andrii.nakryiko@...il.com>
To:     Mauricio Vásquez <mauricio@...volk.io>
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 v2 1/4] libbpf: Implement btf__save_raw()

On Tue, Nov 16, 2021 at 9:25 PM Andrii Nakryiko
<andrii.nakryiko@...il.com> wrote:
>
> On Tue, Nov 16, 2021 at 8:42 AM Mauricio Vásquez <mauricio@...volk.io> wrote:
> >
> > Implement helper function to save the contents of a BTF object to a
> > file.
> >
> > 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>
> > ---
> >  tools/lib/bpf/btf.c      | 30 ++++++++++++++++++++++++++++++
> >  tools/lib/bpf/btf.h      |  2 ++
> >  tools/lib/bpf/libbpf.map |  1 +
> >  3 files changed, 33 insertions(+)
> >
> > diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c
> > index fadf089ae8fe..96a242f91832 100644
> > --- a/tools/lib/bpf/btf.c
> > +++ b/tools/lib/bpf/btf.c
> > @@ -1121,6 +1121,36 @@ struct btf *btf__parse_split(const char *path, struct btf *base_btf)
> >         return libbpf_ptr(btf_parse(path, base_btf, NULL));
> >  }
> >
> > +int btf__save_raw(const struct btf *btf, const char *path)
> > +{
> > +       const void *data;
> > +       FILE *f = NULL;
> > +       __u32 data_sz;
> > +       int err = 0;
> > +
> > +       data = btf__raw_data(btf, &data_sz);
> > +       if (!data) {
> > +               err = -ENOMEM;
> > +               goto out;
> > +       }
> > +
> > +       f = fopen(path, "wb");
> > +       if (!f) {
> > +               err = -errno;
> > +               goto out;
> > +       }
> > +
> > +       if (fwrite(data, 1, data_sz, f) != data_sz) {
> > +               err = -errno;
> > +               goto out;
> > +       }
> > +
> > +out:
> > +       if (f)
> > +               fclose(f);
> > +       return libbpf_err(err);
> > +}
> > +
> >  static void *btf_get_raw_data(const struct btf *btf, __u32 *size, bool swap_endian);
> >
> >  int btf__load_into_kernel(struct btf *btf)
> > diff --git a/tools/lib/bpf/btf.h b/tools/lib/bpf/btf.h
> > index 5c73a5b0a044..4f8d3f303aa6 100644
> > --- a/tools/lib/bpf/btf.h
> > +++ b/tools/lib/bpf/btf.h
> > @@ -114,6 +114,8 @@ LIBBPF_API struct btf *btf__parse_elf_split(const char *path, struct btf *base_b
> >  LIBBPF_API struct btf *btf__parse_raw(const char *path);
> >  LIBBPF_API struct btf *btf__parse_raw_split(const char *path, struct btf *base_btf);
> >
> > +LIBBPF_API int btf__save_raw(const struct btf *btf, const char *path);

Thinking about this some more, I don't feel it's necessary to have
this kind of API in libbpf. Libbpf provides raw bytes and it's not
hard to write dumping byte array to file. We don't have
btf__save_elf() and we probably shouldn't, so I don't see the need for
btf__save_raw() either. It's neither complicated nor frequently used
code to write.


> > +
> >  LIBBPF_API struct btf *btf__load_vmlinux_btf(void);
> >  LIBBPF_API struct btf *btf__load_module_btf(const char *module_name, struct btf *vmlinux_btf);
> >  LIBBPF_API struct btf *libbpf_find_kernel_btf(void);
> > diff --git a/tools/lib/bpf/libbpf.map b/tools/lib/bpf/libbpf.map
> > index 6a59514a48cf..c9555f8655af 100644
> > --- a/tools/lib/bpf/libbpf.map
> > +++ b/tools/lib/bpf/libbpf.map
> > @@ -414,4 +414,5 @@ LIBBPF_0.6.0 {
> >                 perf_buffer__new_deprecated;
> >                 perf_buffer__new_raw;
> >                 perf_buffer__new_raw_deprecated;
> > +               btf__save_raw;
>
> this is a sorted list, please keep it so
>
> >  } LIBBPF_0.5.0;
> > --
> > 2.25.1
> >

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ