From: John Fastabend <john.fastabend@gmail.com>
To: Tony Ambardar <tony.ambardar@gmail.com>,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>
Cc: Tony Ambardar <Tony.Ambardar@gmail.com>,
netdev@vger.kernel.org, bpf@vger.kernel.org,
linux-arch@vger.kernel.org, Arnd Bergmann <arnd@arndb.de>
Subject: RE: [PATCH bpf v1 3/3] libbpf: fix native endian assumption when parsing BTF
Date: Mon, 21 Sep 2020 08:46:53 -0700 [thread overview]
Message-ID: <5f68caed36dab_17370208e9@john-XPS-13-9370.notmuch> (raw)
In-Reply-To: <90f81508ecc57bc0da318e0fe0f45cfe49b17ea7.1600417359.git.Tony.Ambardar@gmail.com>
Tony Ambardar wrote:
> Code in btf__parse_raw() fails to detect raw BTF of non-native endianness
> and assumes it must be ELF data, which then fails to parse as ELF and
> yields a misleading error message:
>
> root:/# bpftool btf dump file /sys/kernel/btf/vmlinux
> libbpf: failed to get EHDR from /sys/kernel/btf/vmlinux
>
> For example, this could occur after cross-compiling a BTF-enabled kernel
> for a target with non-native endianness, which is currently unsupported.
>
> Check for correct endianness and emit a clearer error message:
>
> root:/# bpftool btf dump file /sys/kernel/btf/vmlinux
> libbpf: non-native BTF endianness is not supported
>
> Fixes: 94a1fedd63ed ("libbpf: Add btf__parse_raw() and generic btf__parse() APIs")
>
> Signed-off-by: Tony Ambardar <Tony.Ambardar@gmail.com>
> ---
> tools/lib/bpf/btf.c | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c
> index 7dfca7016aaa..6bdbc389b493 100644
> --- a/tools/lib/bpf/btf.c
> +++ b/tools/lib/bpf/btf.c
> @@ -659,6 +659,12 @@ struct btf *btf__parse_raw(const char *path)
> err = -EIO;
> goto err_out;
> }
> + if (magic == __bswap_16(BTF_MAGIC)) {
> + /* non-native endian raw BTF */
> + pr_warn("non-native BTF endianness is not supported\n");
> + err = -LIBBPF_ERRNO__ENDIAN;
> + goto err_out;
> + }
> if (magic != BTF_MAGIC) {
> /* definitely not a raw BTF */
> err = -EPROTO;
> --
> 2.25.1
>
Acked-by: John Fastabend <john.fastabend@gmail.com>
next prev parent reply other threads:[~2020-09-21 15:47 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-20 5:01 [PATCH bpf v1 0/3] fix BTF usage on embedded systems Tony Ambardar
2020-09-20 5:01 ` [PATCH bpf v1 1/3] bpf: fix sysfs export of empty BTF section Tony Ambardar
2020-09-21 15:44 ` John Fastabend
2020-09-21 19:21 ` Andrii Nakryiko
2020-09-20 5:01 ` [PATCH bpf v1 2/3] bpf: prevent .BTF section elimination Tony Ambardar
2020-09-21 15:45 ` John Fastabend
2020-09-20 5:01 ` [PATCH bpf v1 3/3] libbpf: fix native endian assumption when parsing BTF Tony Ambardar
2020-09-21 15:46 ` John Fastabend [this message]
2020-09-21 19:24 ` [PATCH bpf v1 0/3] fix BTF usage on embedded systems Andrii Nakryiko
2020-09-21 20:52 ` Daniel Borkmann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5f68caed36dab_17370208e9@john-XPS-13-9370.notmuch \
--to=john.fastabend@gmail.com \
--cc=arnd@arndb.de \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=linux-arch@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=tony.ambardar@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox