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  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:   Thu, 13 Aug 2020 13:46:23 -0700
From:   Andrii Nakryiko <andrii.nakryiko@...il.com>
To:     Andrii Nakryiko <andriin@...com>
Cc:     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 v2 bpf 4/9] libbpf: handle BTF pointer sizes more carefully

On Thu, Aug 13, 2020 at 1:39 PM Andrii Nakryiko <andriin@...com> wrote:
>
> With libbpf and BTF it is pretty common to have libbpf built for one
> architecture, while BTF information was generated for a different architecture
> (typically, but not always, BPF). In such case, the size of a pointer might
> differ betweem architectures. libbpf previously was always making an
> assumption that pointer size for BTF is the same as native architecture
> pointer size, but that breaks for cases where libbpf is built as 32-bit
> library, while BTF is for 64-bit architecture.
>
> To solve this, add heuristic to determine pointer size by searching for `long`
> or `unsigned long` integer type and using its size as a pointer size. Also,
> allow to override the pointer size with a new API btf__set_pointer_size(), for
> cases where application knows which pointer size should be used. User
> application can check what libbpf "guessed" by looking at the result of
> btf__pointer_size(). If it's not 0, then libbpf successfully determined a
> pointer size, otherwise native arch pointer size will be used.
>
> For cases where BTF is parsed from ELF file, use ELF's class (32-bit or
> 64-bit) to determine pointer size.
>
> Fixes: 8a138aed4a80 ("bpf: btf: Add BTF support to libbpf")
> Fixes: 351131b51c7a ("libbpf: add btf_dump API for BTF-to-C conversion")
> Signed-off-by: Andrii Nakryiko <andriin@...com>
> ---
>  tools/lib/bpf/btf.c      | 83 ++++++++++++++++++++++++++++++++++++++--
>  tools/lib/bpf/btf.h      |  2 +
>  tools/lib/bpf/btf_dump.c |  4 +-
>  tools/lib/bpf/libbpf.map |  2 +
>  4 files changed, 87 insertions(+), 4 deletions(-)
>

[...]

>
> +       switch (gelf_getclass(elf)) {
> +       case ELFCLASS32:
> +               btf__set_pointer_size(btf, 4);
> +               break;
> +       case ELFCLASS64:
> +               btf__set_pointer_size(btf, 8);
> +               break;
> +       default:
> +               pr_warn("failed to get ELF class (bitness) for %s\n", path);
> +               goto done;

This is not right, it should have been a break, not sure what
happened. I'll send v3, maybe the cover letter also won't go missing
this time.

> +       }
> +
>         if (btf_ext && btf_ext_data) {
>                 *btf_ext = btf_ext__new(btf_ext_data->d_buf,
>                                         btf_ext_data->d_size);

[...]

Powered by blists - more mailing lists