* [PATCH 5.10-6.18 v2] libbpf: fix cross-endian build with newer libbpf
@ 2026-11-16 23:33 Dominique Martinet
2026-11-17 8:19 ` Greg KH
2026-11-18 0:19 ` Sasha Levin
0 siblings, 2 replies; 4+ messages in thread
From: Dominique Martinet @ 2026-11-16 23:33 UTC (permalink / raw)
To: stable, Alan Maguire, andrii, eddyz87
Cc: ast, ihor.solodrai, daniel, memxor, martin.lau, song,
yonghong.song, jolsa, emil, dwarves, bpf, Dominique Martinet,
Alan Maguire
commit 087f3964f4b3 ("libbpf: Support layout section handling in BTF")
added extra data to the BTF header.
This extra data is ignored in the native case, but when building with
different endianness the bswap code in old libbpf would check for strict
size equality, leading to build failures such as this when BTF data is
generated with a newer version of libbpf (through pahole)
BTFIDS vmlinux.unstripped
libbpf: Can't load BTF with non-native endianness due to unsupported header length 32
FAILED: load BTF from vmlinux.unstripped: Operation not supported
make[2]: *** [../scripts/Makefile.vmlinux:72: vmlinux.unstripped] Error 255
Newer libbpf versions also properly ignore trailing data in the bswap
case, but the patch is too intrusive to backport, so take the header
length comparison fix from it instead.
Link: https://github.com/NixOS/nixpkgs/pull/570639
Fixes: 3289959b97ca ("libbpf: Support BTF loading and raw data output in both endianness")
Acked-by: Alan Maguire <almagui@kernel.org>
Signed-off-by: Dominique Martinet <asmadeus@codewreck.org>
---
v1 -> v2:
- link to v1: https://lore.kernel.org/r/20261115200505.1494710-2-asmadeus@codewreck.org
- use offsetofend() instead of sizeof() to match the support layout
section handling patch as suggested by Alan
I checked this builds on 5.10 (non-cross-endian build) and 6.18 (ppc64
cross build)
- add Fixes tag as suggested by sashiko
tools/lib/bpf/btf.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c
index 9f141395c074..0ab11be8ebc5 100644
--- a/tools/lib/bpf/btf.c
+++ b/tools/lib/bpf/btf.c
@@ -229,14 +229,14 @@ static int btf_parse_hdr(struct btf *btf)
struct btf_header *hdr = btf->hdr;
__u32 meta_left;
- if (btf->raw_size < sizeof(struct btf_header)) {
+ if (btf->raw_size < offsetofend(struct btf_header, str_len)) {
pr_debug("BTF header not found\n");
return -EINVAL;
}
if (hdr->magic == bswap_16(BTF_MAGIC)) {
btf->swapped_endian = true;
- if (bswap_32(hdr->hdr_len) != sizeof(struct btf_header)) {
+ if (bswap_32(hdr->hdr_len) < offsetofend(struct btf_header, str_len)) {
pr_warn("Can't load BTF with non-native endianness due to unsupported header length %u\n",
bswap_32(hdr->hdr_len));
return -ENOTSUP;
--
2.56.1
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH 5.10-6.18 v2] libbpf: fix cross-endian build with newer libbpf
2026-11-16 23:33 [PATCH 5.10-6.18 v2] libbpf: fix cross-endian build with newer libbpf Dominique Martinet
@ 2026-11-17 8:19 ` Greg KH
2026-11-18 0:19 ` Sasha Levin
1 sibling, 0 replies; 4+ messages in thread
From: Greg KH @ 2026-11-17 8:19 UTC (permalink / raw)
To: Dominique Martinet
Cc: stable, Alan Maguire, andrii, eddyz87, ast, ihor.solodrai, daniel,
memxor, martin.lau, song, yonghong.song, jolsa, emil, dwarves,
bpf, Alan Maguire
On Tue, Nov 17, 2026 at 08:33:01AM +0900, Dominique Martinet wrote:
> commit 087f3964f4b3 ("libbpf: Support layout section handling in BTF")
> added extra data to the BTF header.
>
> This extra data is ignored in the native case, but when building with
> different endianness the bswap code in old libbpf would check for strict
> size equality, leading to build failures such as this when BTF data is
> generated with a newer version of libbpf (through pahole)
> BTFIDS vmlinux.unstripped
> libbpf: Can't load BTF with non-native endianness due to unsupported header length 32
> FAILED: load BTF from vmlinux.unstripped: Operation not supported
> make[2]: *** [../scripts/Makefile.vmlinux:72: vmlinux.unstripped] Error 255
>
> Newer libbpf versions also properly ignore trailing data in the bswap
> case, but the patch is too intrusive to backport, so take the header
> length comparison fix from it instead.
>
> Link: https://github.com/NixOS/nixpkgs/pull/570639
> Fixes: 3289959b97ca ("libbpf: Support BTF loading and raw data output in both endianness")
> Acked-by: Alan Maguire <almagui@kernel.org>
> Signed-off-by: Dominique Martinet <asmadeus@codewreck.org>
> ---
> v1 -> v2:
> - link to v1: https://lore.kernel.org/r/20261115200505.1494710-2-asmadeus@codewreck.org
> - use offsetofend() instead of sizeof() to match the support layout
> section handling patch as suggested by Alan
> I checked this builds on 5.10 (non-cross-endian build) and 6.18 (ppc64
> cross build)
> - add Fixes tag as suggested by sashiko
>
> tools/lib/bpf/btf.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c
> index 9f141395c074..0ab11be8ebc5 100644
> --- a/tools/lib/bpf/btf.c
> +++ b/tools/lib/bpf/btf.c
> @@ -229,14 +229,14 @@ static int btf_parse_hdr(struct btf *btf)
> struct btf_header *hdr = btf->hdr;
> __u32 meta_left;
>
> - if (btf->raw_size < sizeof(struct btf_header)) {
> + if (btf->raw_size < offsetofend(struct btf_header, str_len)) {
> pr_debug("BTF header not found\n");
> return -EINVAL;
> }
>
> if (hdr->magic == bswap_16(BTF_MAGIC)) {
> btf->swapped_endian = true;
> - if (bswap_32(hdr->hdr_len) != sizeof(struct btf_header)) {
> + if (bswap_32(hdr->hdr_len) < offsetofend(struct btf_header, str_len)) {
> pr_warn("Can't load BTF with non-native endianness due to unsupported header length %u\n",
> bswap_32(hdr->hdr_len));
> return -ENOTSUP;
> --
> 2.56.1
>
<formletter>
This is not the correct way to submit patches for inclusion in the
stable kernel tree. Please read:
https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html
for how to do this properly.
</formletter>
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH 5.10-6.18 v2] libbpf: fix cross-endian build with newer libbpf
2026-11-16 23:33 [PATCH 5.10-6.18 v2] libbpf: fix cross-endian build with newer libbpf Dominique Martinet
2026-11-17 8:19 ` Greg KH
@ 2026-11-18 0:19 ` Sasha Levin
2026-11-18 0:22 ` Sasha Levin
1 sibling, 1 reply; 4+ messages in thread
From: Sasha Levin @ 2026-11-18 0:19 UTC (permalink / raw)
To: stable, Alan Maguire, andrii, eddyz87
Cc: Sasha Levin, ast, ihor.solodrai, daniel, memxor, martin.lau, song,
yonghong.song, jolsa, emil, dwarves, bpf, Dominique Martinet,
Alan Maguire
> Newer libbpf versions also properly ignore trailing data in the bswap
> case, but the patch is too intrusive to backport, so take the header
> length comparison fix from it instead.
Queued for 6.18, 6.12, 6.6, 6.1, 5.15 and 5.10, thanks.
--
Thanks,
Sasha
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 5.10-6.18 v2] libbpf: fix cross-endian build with newer libbpf
2026-11-18 0:19 ` Sasha Levin
@ 2026-11-18 0:22 ` Sasha Levin
0 siblings, 0 replies; 4+ messages in thread
From: Sasha Levin @ 2026-11-18 0:22 UTC (permalink / raw)
To: stable, Alan Maguire, andrii, eddyz87
Cc: ast, ihor.solodrai, daniel, memxor, martin.lau, song,
yonghong.song, jolsa, emil, dwarves, bpf, Dominique Martinet,
Alan Maguire
> Newer libbpf versions also properly ignore trailing data in the bswap
> case, but the patch is too intrusive to backport, so take the header
> length comparison fix from it instead.
Queued for 6.18, 6.12, 6.6, 6.1, 5.15 and 5.10, thanks.
--
Thanks,
Sasha
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-18 0:22 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-16 23:33 [PATCH 5.10-6.18 v2] libbpf: fix cross-endian build with newer libbpf Dominique Martinet
2026-11-17 8:19 ` Greg KH
2026-11-18 0:19 ` Sasha Levin
2026-11-18 0:22 ` Sasha Levin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox