libbpf: Fix BTF data layout checks and allow empty BTF
authorAndrii Nakryiko <andrii@kernel.org>
Thu, 5 Nov 2020 04:33:57 +0000 (20:33 -0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 18 Nov 2021 13:04:10 +0000 (14:04 +0100)
commit4d4d6aa2ef803044badb1529a1bfb45680f4071e
treeb5810aa23ed7fbc5c56c70b74efd72fc3421bf89
parent0b95aaa493c6b3294a76eebe3930557512fbebfc
libbpf: Fix BTF data layout checks and allow empty BTF

[ Upstream commit d8123624506cd62730c9cd9c7672c698e462703d ]

Make data section layout checks stricter, disallowing overlap of types and
strings data.

Additionally, allow BTFs with no type data. There is nothing inherently wrong
with having BTF with no types (put potentially with some strings). This could
be a situation with kernel module BTFs, if module doesn't introduce any new
type information.

Also fix invalid offset alignment check for btf->hdr->type_off.

Fixes: 8a138aed4a80 ("bpf: btf: Add BTF support to libbpf")
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20201105043402.2530976-8-andrii@kernel.org
Signed-off-by: Sasha Levin <sashal@kernel.org>
tools/lib/bpf/btf.c