From: sashiko-bot@kernel.org
To: "Ihor Solodrai" <ihor.solodrai@linux.dev>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next v1 2/4] libbpf: Render decl_tags in btf_dump
Date: Thu, 17 Sep 2026 01:30:48 +0000 [thread overview]
Message-ID: <20260917013049.2263A1F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260917012037.1396254-3-ihor.solodrai@linux.dev>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] libbpf: btf_dump_cmp_decl_tags violates strict weak ordering in qsort
- [Medium] libbpf: duplicate tags and memory leak on btf_dump_resize error paths
--
commit 869ac84b9144d9ee48198dbc0d57c9510a6f9d98
Author: Ihor Solodrai <ihor.solodrai@linux.dev>
Subject: libbpf: Render decl_tags in btf_dump
This commit adds support for rendering BTF_KIND_DECL_TAG in btf_dump.
It builds an array of decl tags sorted by target ID and tag ID, which
are then emitted at every declaration.
> diff --git a/tools/lib/bpf/btf_dump.c b/tools/lib/bpf/btf_dump.c
> --- a/tools/lib/bpf/btf_dump.c
> +++ b/tools/lib/bpf/btf_dump.c
> @@ -202,9 +202,15 @@ struct btf_dump *btf_dump__new(const struct btf *btf,
> +static int btf_dump_cmp_decl_tags(const void *a, const void *b)
> +{
> + const struct decl_tag_desc *x = a, *y = b;
> +
> + if (x->target_id != y->target_id)
> + return x->target_id < y->target_id ? -1 : 1;
> + return x->tag_id < y->tag_id ? -1 : 1;
[Severity: Medium]
Does this comparator satisfy the strict weak ordering requirement for qsort?
If two elements have the same tag_id, this returns 1 instead of 0. Depending
on the libc implementation, returning 1 when comparing an element to itself
or to a duplicate could break antisymmetry and potentially lead to out of
bounds accesses or infinite loops.
> +}
[ ... ]
> @@ -258,8 +258,18 @@ static int btf_dump_resize(struct btf_dump *d)
> err = btf_dump_mark_referenced(d, t);
> if (err)
> return err;
[Severity: Medium]
Do we need to roll back d->decl_tags_cnt or free resources here?
If this loop encounters an error and returns early, it leaves the previously
pushed decl_tags in the array, but d->last_id isn't updated.
If a user handles the error and resumes using the btf_dump object, won't it
re-push those same tags on the next call, causing duplicates and memory leaks?
> +
> + if (btf_is_decl_tag(t)) {
> + err = btf_dump_push_decl_tag(d, i, t);
> + if (err)
> + return err;
[Severity: Medium]
Similarly, does returning early here lead to the same duplicate tag entries
on retry, since d->decl_tags_cnt is not rolled back on error?
> + }
> }
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260917012037.1396254-1-ihor.solodrai@linux.dev?part=2
next prev parent reply other threads:[~2026-09-17 1:30 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-17 1:20 [PATCH bpf-next v1 0/4] libbpf: Render decl_tags in btf_dump Ihor Solodrai
2026-09-17 1:20 ` [PATCH bpf-next v1 1/4] libbpf: Walk types in btf_dump_resize(), not in mark_referenced() Ihor Solodrai
2026-09-17 22:32 ` Eduard Zingerman
2026-09-17 1:20 ` [PATCH bpf-next v1 2/4] libbpf: Render decl_tags in btf_dump Ihor Solodrai
2026-09-17 1:30 ` sashiko-bot [this message]
2026-09-17 2:12 ` Alexei Starovoitov
2026-09-17 3:25 ` Ihor Solodrai
2026-09-17 22:46 ` Eduard Zingerman
2026-09-17 23:59 ` Andrii Nakryiko
2026-09-22 16:59 ` Ihor Solodrai
2026-09-22 19:43 ` Andrii Nakryiko
2026-09-17 1:20 ` [PATCH bpf-next v1 3/4] selftests/bpf: Test btf_dump rendering of decl_tags Ihor Solodrai
2026-09-17 10:30 ` Alan Maguire
2026-09-17 17:38 ` Ihor Solodrai
2026-09-17 23:18 ` Eduard Zingerman
2026-09-17 1:20 ` [PATCH bpf-next v1 4/4] selftests/bpf: Show the tag kflag in the raw BTF dump helper Ihor Solodrai
2026-09-17 1:27 ` sashiko-bot
2026-09-17 23:21 ` Eduard Zingerman
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=20260917013049.2263A1F000FF@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=ihor.solodrai@linux.dev \
--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