From: Dominique Martinet <asmadeus@codewreck.org>
To: Alan Maguire <almagui@kernel.org>
Cc: stable@vger.kernel.org, Alan Maguire <alan.maguire@oracle.com>,
andrii@kernel.org, eddyz87@gmail.com, ast@kernel.org,
ihor.solodrai@linux.dev, daniel@iogearbox.net, memxor@gmail.com,
martin.lau@linux.dev, song@kernel.org, yonghong.song@linux.dev,
jolsa@kernel.org, emil@etsalapatis.com, dwarves@vger.kernel.org,
bpf@vger.kernel.org
Subject: Re: [PATCH 5.10-6.18] libbpf: fix cross-endian build with newer libbpf
Date: Mon, 16 Nov 2026 21:09:23 +0900 [thread overview]
Message-ID: <avryc0j9LwdUUGl7@codewreck.org> (raw)
In-Reply-To: <7a931778-2a99-4b33-8d1e-97f9b061fb02@kernel.org>
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
prev parent reply other threads:[~2026-11-16 12:09 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-15 20:05 [PATCH 5.10-6.18] libbpf: fix cross-endian build with newer libbpf Dominique Martinet
2026-11-16 8:51 ` Alan Maguire
2026-11-16 12:09 ` Dominique Martinet [this message]
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=avryc0j9LwdUUGl7@codewreck.org \
--to=asmadeus@codewreck.org \
--cc=alan.maguire@oracle.com \
--cc=almagui@kernel.org \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=dwarves@vger.kernel.org \
--cc=eddyz87@gmail.com \
--cc=emil@etsalapatis.com \
--cc=ihor.solodrai@linux.dev \
--cc=jolsa@kernel.org \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=song@kernel.org \
--cc=stable@vger.kernel.org \
--cc=yonghong.song@linux.dev \
/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