BPF List
 help / color / mirror / Atom feed
* [PATCH 5.10-6.18] libbpf: fix cross-endian build with newer libbpf
@ 2026-11-15 20:05 Dominique Martinet
  2026-11-15 20:23 ` sashiko-bot
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Dominique Martinet @ 2026-11-15 20:05 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

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, just fix the header
length comparison.

Link: https://github.com/NixOS/nixpkgs/pull/570639
Signed-off-by: Dominique Martinet <asmadeus@codewreck.org>
---
Hey,

we've got a cross build failure report for ppc64 in nixpkgs (link in
commit message), that turned out as described above.
(build broke for all kernels before 7.1)

In this case I believe it's easier to just fix the check than backport
the full layout section handling support, is that ok?
I've confirmed the build succeeds with this, I assume the reporter will
eventually also boot check but from my understanding of the code this
should be fine.

Feel free to throw this away if there's a better way, just let me know
if I can help.

Thanks

 tools/lib/bpf/btf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c
index 9f141395c074..ae344cf58e85 100644
--- a/tools/lib/bpf/btf.c
+++ b/tools/lib/bpf/btf.c
@@ -236,7 +236,7 @@ static int btf_parse_hdr(struct btf *btf)
 
 	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) < sizeof(struct btf_header)) {
 			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] 8+ messages in thread

* Re: [PATCH 5.10-6.18] libbpf: fix cross-endian build with newer libbpf
  2026-11-15 20:05 [PATCH 5.10-6.18] libbpf: fix cross-endian build with newer libbpf Dominique Martinet
@ 2026-11-15 20:23 ` sashiko-bot
  2026-11-15 20:41   ` Dominique Martinet
  2026-11-16  8:51 ` Alan Maguire
  2026-11-16 16:06 ` Sasha Levin
  2 siblings, 1 reply; 8+ messages in thread
From: sashiko-bot @ 2026-11-15 20:23 UTC (permalink / raw)
  To: Dominique Martinet; +Cc: bpf

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Low] libbpf: missing Fixes trailer for btf_parse_hdr() endianness
  check
- [Low] libbpf: out-of-bounds access in btf_parse_hdr() when hdr_len >
  sizeof(*hdr)
--

commit c3e5e38661056ceb32071ab50ba595824eefbdbf
Author: Dominique Martinet <asmadeus@codewreck.org>

> libbpf: fix cross-endian build with newer libbpf
>
> 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, just fix the header
> length comparison.
>
> Link: https://github.com/NixOS/nixpkgs/pull/570639
> Signed-off-by: Dominique Martinet <asmadeus@codewreck.org>

[Severity: Low]
Should this include a Fixes tag for the commit that introduced the strict
swapped-endian header size check:

  Fixes: 3289959b97ca ("libbpf: Support BTF loading and raw data output in both endianness")

> diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c
> index 231b07203e3d2..8f3f942eda704 100644
> --- a/tools/lib/bpf/btf.c
> +++ b/tools/lib/bpf/btf.c
> @@ -198,7 +198,7 @@ static int btf_parse_hdr(struct btf *btf)
>  
>  	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) < sizeof(struct btf_header)) {
>  			pr_warn("Can't load BTF with non-native endianness due to unsupported header length %u\n",
>  				bswap_32(hdr->hdr_len));
>  			return -ENOTSUP;

[Severity: Low]
Can relaxing this check cause out-of-bounds reads and writes on
btf->raw_data when parsing a malformed cross-endian BTF buffer with
hdr->hdr_len > sizeof(*hdr)?

Previously, requiring hdr->hdr_len == sizeof(struct btf_header) together
with btf->raw_size >= sizeof(struct btf_header) guaranteed hdr->hdr_len
fit within btf->raw_size.  btf_parse_hdr() still computes meta_left from
sizeof(*hdr) instead of hdr->hdr_len:

tools/lib/bpf/btf.c:btf_parse_hdr() {
	...
	meta_left = btf->raw_size - sizeof(*hdr);
	...
}

However, btf__new() offsets the section pointers by btf->hdr->hdr_len:

tools/lib/bpf/btf.c:btf__new() {
	...
	btf->strs_data = btf->raw_data + btf->hdr->hdr_len + btf->hdr->str_off;
	btf->types_data = btf->raw_data + btf->hdr->hdr_len + btf->hdr->type_off;
	...
}

If hdr->hdr_len exceeds sizeof(*hdr) (or exceeds btf->raw_size),
btf->strs_data and btf->types_data can point past btf->raw_data +
btf->raw_size, causing btf_parse_str_sec() to read out of bounds and
btf_parse_type_sec() to byte-swap memory in place past the end of the heap
buffer.  Checking that btf->raw_size >= hdr->hdr_len and subtracting
hdr->hdr_len when computing meta_left would avoid this.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261115200505.1494710-2-asmadeus@codewreck.org?part=1

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 5.10-6.18] libbpf: fix cross-endian build with newer libbpf
  2026-11-15 20:23 ` sashiko-bot
@ 2026-11-15 20:41   ` Dominique Martinet
  0 siblings, 0 replies; 8+ messages in thread
From: Dominique Martinet @ 2026-11-15 20:41 UTC (permalink / raw)
  To: sashiko-reviews; +Cc: bpf

sashiko-bot@kernel.org wrote on Sun, Nov 15, 2026 at 08:23:16PM +0000:
> > Link: https://github.com/NixOS/nixpkgs/pull/570639
> > Signed-off-by: Dominique Martinet <asmadeus@codewreck.org>
> 
> [Severity: Low]
> Should this include a Fixes tag for the commit that introduced the strict
> swapped-endian header size check:
> 
>   Fixes: 3289959b97ca ("libbpf: Support BTF loading and raw data output in both endianness")

Err, yeah, I guess that bug couldn't happen before support for
endianness was added, but it didn't work before either so meh :)
Feel free to add when applying if you think it helps.

> > diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c
> > index 231b07203e3d2..8f3f942eda704 100644
> > --- a/tools/lib/bpf/btf.c
> > +++ b/tools/lib/bpf/btf.c
> > @@ -198,7 +198,7 @@ static int btf_parse_hdr(struct btf *btf)
> >  
> >  	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) < sizeof(struct btf_header)) {
> >  			pr_warn("Can't load BTF with non-native endianness due to unsupported header length %u\n",
> >  				bswap_32(hdr->hdr_len));
> >  			return -ENOTSUP;
> 
> [Severity: Low]
> Can relaxing this check cause out-of-bounds reads and writes on
> btf->raw_data when parsing a malformed cross-endian BTF buffer with
> hdr->hdr_len > sizeof(*hdr)?
> 
> Previously, requiring hdr->hdr_len == sizeof(struct btf_header) together
> with btf->raw_size >= sizeof(struct btf_header) guaranteed hdr->hdr_len
> fit within btf->raw_size.  btf_parse_hdr() still computes meta_left from
> sizeof(*hdr) instead of hdr->hdr_len:
> 
> tools/lib/bpf/btf.c:btf_parse_hdr() {
> 	...
> 	meta_left = btf->raw_size - sizeof(*hdr);
> Sashiko AI review · https://sashiko.dev/#/patchset/20261115200505.1494710-2-asmadeus@codewreck.org?part=1

sashiko apparently picked the v5.10 tag, but this bad sizeof was fixed
in commit c825f5fee19c ("libbpf: Fix BTF header parsing checks") and
isn't a problem as far as I can tell (that commit was backported to all
stable kernels, and header is properly used, after endianness swap)

Thanks,
-- 
Dominique Martinet | Asmadeus

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 5.10-6.18] libbpf: fix cross-endian build with newer libbpf
  2026-11-15 20:05 [PATCH 5.10-6.18] libbpf: fix cross-endian build with newer libbpf Dominique Martinet
  2026-11-15 20:23 ` sashiko-bot
@ 2026-11-16  8:51 ` Alan Maguire
  2026-11-16 12:09   ` Dominique Martinet
  2026-11-16 16:06 ` Sasha Levin
  2 siblings, 1 reply; 8+ messages in thread
From: Alan Maguire @ 2026-11-16  8:51 UTC (permalink / raw)
  To: Dominique Martinet, stable, Alan Maguire, andrii, eddyz87
  Cc: ast, ihor.solodrai, daniel, memxor, martin.lau, song,
	yonghong.song, jolsa, emil, dwarves, bpf

On 11/15/26 8:05 PM, 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, just fix the header
> length comparison.
> 
> Link: https://github.com/NixOS/nixpkgs/pull/570639
> Signed-off-by: Dominique Martinet <asmadeus@codewreck.org>
> ---
> Hey,
> 
> we've got a cross build failure report for ppc64 in nixpkgs (link in
> commit message), that turned out as described above.
> (build broke for all kernels before 7.1)
> 
> In this case I believe it's easier to just fix the check than backport
> the full layout section handling support, is that ok?
> I've confirmed the build succeeds with this, I assume the reporter will
> eventually also boot check but from my understanding of the code this
> should be fine.
> 
> Feel free to throw this away if there's a better way, just let me know
> if I can help.
> 
> Thanks
> 
>  tools/lib/bpf/btf.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c
> index 9f141395c074..ae344cf58e85 100644
> --- a/tools/lib/bpf/btf.c
> +++ b/tools/lib/bpf/btf.c
> @@ -236,7 +236,7 @@ static int btf_parse_hdr(struct btf *btf)
>  
>  	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) < sizeof(struct btf_header)) {

Thanks for the fix! A small suggestion; what about matching the upstream test instead; i.e.

		if (bswap_32(hdr->hdr_len) < offsetofend(struct btf_header, str_len)) {

That approach is a bit more portable as the str_len field was the last field in the
original BTF header, and it will work regardless of the size of struct btf_header.

>  			pr_warn("Can't load BTF with non-native endianness due to unsupported header length %u\n",
>  				bswap_32(hdr->hdr_len));
>  			return -ENOTSUP;


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 5.10-6.18] libbpf: fix cross-endian build with newer libbpf
  2026-11-16  8:51 ` Alan Maguire
@ 2026-11-16 12:09   ` Dominique Martinet
  2026-11-16 12:26     ` sashiko-bot
  2026-11-16 16:12     ` Alan Maguire
  0 siblings, 2 replies; 8+ messages in thread
From: Dominique Martinet @ 2026-11-16 12:09 UTC (permalink / raw)
  To: Alan Maguire
  Cc: stable, Alan Maguire, andrii, eddyz87, ast, ihor.solodrai, daniel,
	memxor, martin.lau, song, yonghong.song, jolsa, emil, dwarves,
	bpf

Alan Maguire wrote on Mon, Nov 16, 2026 at 08:51:24AM +0000:
> >  	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) < sizeof(struct btf_header)) {
> 
> Thanks for the fix! A small suggestion; what about matching the upstream test instead; i.e.
> 
> 		if (bswap_32(hdr->hdr_len) < offsetofend(struct btf_header, str_len)) {
> 
> That approach is a bit more portable as the str_len field was the last field in the
> original BTF header, and it will work regardless of the size of struct btf_header.

Thanks for the look!

I wouldn't expect the struct to change in stable trees and favored a
minimal patch; my opinion being that if someone does take the time to
backport layout section handling or another btf_header extension in old
trees then they can also fix the check properly...

I actually prepared a v2 with this, but then noticed the raw_size check
also ought to be updated if you want to handle struct btf_header changes:
---
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;
---
and at this point this isn't just a cross-endian fix anymore but
something that looks more like future-proofing, and with my other
downstream stable kernel maintainer hat (yay embedded systems full of
vendor patches...), I'm not too fond of these and would rather keep this
minimal as it's not like it would reduce further merge conflicts either.

But if you think it's better I can send a v2 with either the above or
just the bswap_32 check updated, I've checked it builds on 5.10 and
6.18 so have no fundamental problem with either version.

Cheers,
-- 
Dominique Martinet | Asmadeus

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH 5.10-6.18] libbpf: fix cross-endian build with newer libbpf
  2026-11-16 12:09   ` Dominique Martinet
@ 2026-11-16 12:26     ` sashiko-bot
  2026-11-16 16:12     ` Alan Maguire
  1 sibling, 0 replies; 8+ messages in thread
From: sashiko-bot @ 2026-11-16 12:26 UTC (permalink / raw)
  To: Dominique Martinet; +Cc: bpf

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] libbpf: missing Signed-off-by trailer and raw email reply as
  commit log
- [Low] libbpf: missing Fixes trailer for btf_parse_hdr() endianness
  check
--

commit bf42d3c49f2ac6667938fafec9c2e11053665406
Author: Dominique Martinet <asmadeus@codewreck.org>

> libbpf: fix cross-endian build with newer libbpf
>
> Alan Maguire wrote on Mon, Nov 16, 2026 at 08:51:24AM +0000:
> > >     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) < sizeof(struct btf_header)) {
> >
> > Thanks for the fix! A small suggestion; what about matching the upstream test instead; i.e.
> >
> >               if (bswap_32(hdr->hdr_len) < offsetofend(struct btf_header, str_len)) {
> >
> > That approach is a bit more portable as the str_len field was the last field in the
> > original BTF header, and it will work regardless of the size of struct btf_header.
>
> Thanks for the look!
>
> I wouldn't expect the struct to change in stable trees and favored a
> minimal patch; my opinion being that if someone does take the time to
> backport layout section handling or another btf_header extension in old
> trees then they can also fix the check properly...
>
> I actually prepared a v2 with this, but then noticed the raw_size check
> also ought to be updated if you want to handle struct btf_header changes:

[Severity: High]
The commit message is an unedited mailing-list reply that ends
mid-sentence rather than a standalone changelog description, and it is
missing a Signed-off-by trailer.

> diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c
> index 231b07203e3d2..2dddee4870343 100644
> --- a/tools/lib/bpf/btf.c
> +++ b/tools/lib/bpf/btf.c
> @@ -191,14 +191,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)) {

[Severity: Low]
This fixes the strict cross-endian header length check in btf_parse_hdr().
Should the commit message include:

  Fixes: 3289959b97ca ("libbpf: Support BTF loading and raw data output in both endianness")

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/avryc0j9LwdUUGl7@codewreck.org?part=1

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 5.10-6.18] libbpf: fix cross-endian build with newer libbpf
  2026-11-15 20:05 [PATCH 5.10-6.18] libbpf: fix cross-endian build with newer libbpf Dominique Martinet
  2026-11-15 20:23 ` sashiko-bot
  2026-11-16  8:51 ` Alan Maguire
@ 2026-11-16 16:06 ` Sasha Levin
  2 siblings, 0 replies; 8+ messages in thread
From: Sasha Levin @ 2026-11-16 16:06 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

> Newer libbpf versions also properly ignore trailing data in the bswap
> case, but the patch is too intrusive to backport, just fix the header
> length comparison.

I'm holding this until there is either an ack from Alan on v1, or a v2.

-- 
Thanks,
Sasha

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 5.10-6.18] libbpf: fix cross-endian build with newer libbpf
  2026-11-16 12:09   ` Dominique Martinet
  2026-11-16 12:26     ` sashiko-bot
@ 2026-11-16 16:12     ` Alan Maguire
  1 sibling, 0 replies; 8+ messages in thread
From: Alan Maguire @ 2026-11-16 16:12 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

On 11/16/26 12:09 PM, Dominique Martinet wrote:
> Alan Maguire wrote on Mon, Nov 16, 2026 at 08:51:24AM +0000:
>>>  	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) < sizeof(struct btf_header)) {
>>
>> Thanks for the fix! A small suggestion; what about matching the upstream test instead; i.e.
>>
>> 		if (bswap_32(hdr->hdr_len) < offsetofend(struct btf_header, str_len)) {
>>
>> That approach is a bit more portable as the str_len field was the last field in the
>> original BTF header, and it will work regardless of the size of struct btf_header.
> 
> Thanks for the look!
> 
> I wouldn't expect the struct to change in stable trees and favored a
> minimal patch; my opinion being that if someone does take the time to
> backport layout section handling or another btf_header extension in old
> trees then they can also fix the check properly...
> 
> I actually prepared a v2 with this, but then noticed the raw_size check
> also ought to be updated if you want to handle struct btf_header changes:
> ---
> 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;
> ---
> and at this point this isn't just a cross-endian fix anymore but
> something that looks more like future-proofing, and with my other
> downstream stable kernel maintainer hat (yay embedded systems full of
> vendor patches...), I'm not too fond of these and would rather keep this
> minimal as it's not like it would reduce further merge conflicts either.
> 
> But if you think it's better I can send a v2 with either the above or
> just the bswap_32 check updated, I've checked it builds on 5.10 and
> 6.18 so have no fundamental problem with either version.
> 

The only risk with relying on struct btf_header size is if the libbpf
is compiled against system headers which for some reason have a newer 
"struct btf"; that shouldn't happen, and these days the standalone libbpf 
mirror carries its own uAPI headers, but just in case someone somewhere
is doing something unusual in building libbpf it might be best
to use the v2 approach. So for v2

Acked-by: Alan Maguire <almagui@kernel.org>

Thanks again! 
> Cheers,


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2026-11-16 16:12 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-15 20:05 [PATCH 5.10-6.18] libbpf: fix cross-endian build with newer libbpf Dominique Martinet
2026-11-15 20:23 ` sashiko-bot
2026-11-15 20:41   ` Dominique Martinet
2026-11-16  8:51 ` Alan Maguire
2026-11-16 12:09   ` Dominique Martinet
2026-11-16 12:26     ` sashiko-bot
2026-11-16 16:12     ` Alan Maguire
2026-11-16 16:06 ` Sasha Levin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox