From: Dominique Martinet <asmadeus@codewreck.org>
To: sashiko-reviews@lists.linux.dev
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH 5.10-6.18] libbpf: fix cross-endian build with newer libbpf
Date: Mon, 16 Nov 2026 05:41:00 +0900 [thread overview]
Message-ID: <avoY3KOmyKGifeau@codewreck.org> (raw)
In-Reply-To: <sashiko-outbox-215783@kernel.org>
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
prev parent reply other threads:[~2026-11-15 20:41 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-15 20:23 ` sashiko-bot
2026-11-15 20:41 ` 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=avoY3KOmyKGifeau@codewreck.org \
--to=asmadeus@codewreck.org \
--cc=bpf@vger.kernel.org \
--cc=sashiko-reviews@lists.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