All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Mingpei CAO" <caomingpei@gmail.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf v2 1/2] libbpf: Fix array comparison in BTF dedup
Date: Tue, 08 Sep 2026 17:01:33 +0000	[thread overview]
Message-ID: <20260908170133.923D41F00A3D@smtp.kernel.org> (raw)
In-Reply-To: <20260908164920.108074-2-caomingpei@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] btf_dedup_identical_types() can enter an infinite loop when resolving cyclic modifiers due to a missing depth decrement.
--

commit 724de86c8298443100e097d1d516c73679a67fcc
Author: Mingpei CAO <caomingpei@gmail.com>

libbpf: Fix array comparison in BTF dedup

btf_dedup_identical_types() reads both array descriptors from t1,
skipping comparisons of their referenced types. This can incorrectly
merge distinct structs and corrupt CO-RE relocation metadata.

Closes: https://lore.kernel.org/bpf/CABzjXVz3iBuump-pXFkefZ5v+2uu4fG61zqRyWD4xmz3PuBycw@mail.gmail.com/

> diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c
> index 8417de92d0282..41cc3140925fb 100644
> --- a/tools/lib/bpf/btf.c
> +++ b/tools/lib/bpf/btf.c
> @@ -4827,7 +4827,7 @@ static bool btf_dedup_identical_types(struct btf_dedup *d, __u32 id1, __u32 id2,
>  			return false;
>  

[Severity: High]
This is a pre-existing issue, but looking slightly above this hunk in
btf_dedup_identical_types(), can this code enter an infinite loop when
resolving cyclic modifiers?

    case BTF_KIND_TYPE_TAG:
        if (t1->info != t2->info || t1->name_off != t2->name_off)
            return false;
        id1 = t1->type;
        id2 = t2->type;
        goto recur;

The depth parameter is tracked to prevent infinite recursion on cyclic types.
However, this path uses goto recur to iteratively traverse the modifiers
without decrementing depth.

If a malformed BTF contains a cycle of modifier types (such as a TYPEDEF
that references itself), it appears depth would never decrease. Could this
lead to an infinite loop and exhaust the CPU during BTF deduplication?

>  		a1 = btf_array(t1);
> -		a2 = btf_array(t1);
> +		a2 = btf_array(t2);
>  
>  		if (a1->index_type != a2->index_type &&
>  		    !btf_dedup_identical_types(d, a1->index_type, a2->index_type, depth - 1))

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260908164920.108074-1-caomingpei@gmail.com?part=1

  reply	other threads:[~2026-09-08 17:01 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-08 16:49 [PATCH bpf v2 0/2] libbpf: Fix array comparison in BTF dedup Mingpei CAO
2026-09-08 16:49 ` [PATCH bpf v2 1/2] " Mingpei CAO
2026-09-08 17:01   ` sashiko-bot [this message]
2026-09-08 16:49 ` [PATCH bpf v2 2/2] selftests/bpf: Test array element " Mingpei CAO
2026-09-08 23:40 ` [PATCH bpf v2 0/2] libbpf: Fix array " patchwork-bot+netdevbpf

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=20260908170133.923D41F00A3D@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=caomingpei@gmail.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.