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: <CAEf4BzbP4Urmg3m-ynSv8XAVhhm-4Rk3+F7zguZ7E7-oGBuWOQ@mail.gmail.com>
Date:   Mon, 17 Jun 2019 11:35:29 -0700
From:   Andrii Nakryiko <andrii.nakryiko@...il.com>
To:     Song Liu <songliubraving@...com>
Cc:     Song Liu <liu.song.a23@...il.com>,
        Andrii Nakryiko <andriin@...com>, bpf <bpf@...r.kernel.org>,
        Networking <netdev@...r.kernel.org>,
        Alexei Starovoitov <ast@...com>,
        Daniel Borkmann <daniel@...earbox.net>,
        Kernel Team <Kernel-team@...com>
Subject: Re: [PATCH bpf-next 2/8] libbpf: extract BTF loading and simplify ELF
 parsing logic

On Mon, Jun 17, 2019 at 11:07 AM Song Liu <songliubraving@...com> wrote:
>
>
>
> > On Jun 17, 2019, at 10:24 AM, Andrii Nakryiko <andrii.nakryiko@...il.com> wrote:
> >
> > On Sat, Jun 15, 2019 at 1:26 PM Song Liu <liu.song.a23@...il.com> wrote:
> >>
> >> On Mon, Jun 10, 2019 at 9:49 PM Andrii Nakryiko <andriin@...com> wrote:
> >>>
> >>> As a preparation for adding BTF-based BPF map loading, extract .BTF and
> >>> .BTF.ext loading logic. Also simplify error handling in
> >>> bpf_object__elf_collect() by returning early, as there is no common
> >>> clean up to be done.
> >>>
> >>> Signed-off-by: Andrii Nakryiko <andriin@...com>
> >>> ---
> >>> tools/lib/bpf/libbpf.c | 137 ++++++++++++++++++++++-------------------
> >>> 1 file changed, 75 insertions(+), 62 deletions(-)
> >>>
> >>> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> >>> index ba89d9727137..9e39a0a33aeb 100644
> >>> --- a/tools/lib/bpf/libbpf.c
> >>> +++ b/tools/lib/bpf/libbpf.c
> >>> @@ -1078,6 +1078,58 @@ static void bpf_object__sanitize_btf_ext(struct bpf_object *obj)
> >>>        }
> >>> }
> >>>
> >>> +static int bpf_object__load_btf(struct bpf_object *obj,
> >>> +                               Elf_Data *btf_data,
> >>> +                               Elf_Data *btf_ext_data)
> >>> +{
> >>> +       int err = 0;
> >>> +
> >>> +       if (btf_data) {
> >>> +               obj->btf = btf__new(btf_data->d_buf, btf_data->d_size);
> >>> +               if (IS_ERR(obj->btf)) {
> >>> +                       pr_warning("Error loading ELF section %s: %d.\n",
> >>> +                                  BTF_ELF_SEC, err);
> >>> +                       goto out;
> >>
> >> If we goto out here, we will return 0.
> >
> >
> > Yes, it's intentional. BTF is treated as optional, so if we fail to
> > load it, libbpf will emit warning, but will proceed as nothing
> > happened and no BTF was supposed to be loaded.
> >
> >>
> >>> +               }
> >>> +               err = btf__finalize_data(obj, obj->btf);
> >>> +               if (err) {
> >>> +                       pr_warning("Error finalizing %s: %d.\n",
> >>> +                                  BTF_ELF_SEC, err);
> >>> +                       goto out;
> >>> +               }
> >>> +               bpf_object__sanitize_btf(obj);
> >>> +               err = btf__load(obj->btf);
> >>> +               if (err) {
> >>> +                       pr_warning("Error loading %s into kernel: %d.\n",
> >>> +                                  BTF_ELF_SEC, err);
> >>> +                       goto out;
> >>> +               }
> >>> +       }
> >>> +       if (btf_ext_data) {
> >>> +               if (!obj->btf) {
> >>> +                       pr_debug("Ignore ELF section %s because its depending ELF section %s is not found.\n",
> >>> +                                BTF_EXT_ELF_SEC, BTF_ELF_SEC);
> >>> +                       goto out;
> >>
> >> We will also return 0 when goto out here.
> >
> >
> > See above, it's original behavior of libbpf.
> >
> >>
> >>> +               }
> >>> +               obj->btf_ext = btf_ext__new(btf_ext_data->d_buf,
> >>> +                                           btf_ext_data->d_size);
> >>> +               if (IS_ERR(obj->btf_ext)) {
> >>> +                       pr_warning("Error loading ELF section %s: %ld. Ignored and continue.\n",
> >>> +                                  BTF_EXT_ELF_SEC, PTR_ERR(obj->btf_ext));
> >>> +                       obj->btf_ext = NULL;
> >>> +                       goto out;
> >> And, here. And we will not free obj->btf.
> >
> > This is situation in which we successfully loaded .BTF, but failed to
> > load .BTF.ext. In that case we'll warn about .BTF.ext, but will drop
> > it and continue with .BTF only.
> >
>
> Yeah, that makes sense.
>
> Shall we let bpf_object__load_btf() return void? Since it always
> returns 0?

This is split into bpf_object__init_btf and
bpf_object__sanitize_and_load_btf in patch #6, both of which can
return errors. So probably not worth changing just for one patch.

>
> Thanks,
> Song
>
> <snip>
>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ