From: sashiko-bot@kernel.org
To: "Ihor Solodrai" <ihor.solodrai@linux.dev>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next v1 4/4] selftests/bpf: Show the tag kflag in the raw BTF dump helper
Date: Thu, 17 Sep 2026 01:27:51 +0000 [thread overview]
Message-ID: <20260917012752.6CBBF1F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260917012037.1396254-5-ihor.solodrai@linux.dev>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] bpf: NULL pointer dereference in test_btf_attrs on test failure
--
commit 551463268433576dd9cc5cc27a8ffb06a64ecabb
Author: Ihor Solodrai <ihor.solodrai@linux.dev>
selftests/bpf: Show the tag kflag in the raw BTF dump helper
This commit updates fprintf_btf_type_raw() to print the kflag for
BTF_KIND_DECL_TAG and BTF_KIND_TYPE_TAG types. It also adds a new subtest
test_btf_attrs to prog_tests/btf_write.c to verify this behavior.
> diff --git a/tools/testing/selftests/bpf/prog_tests/btf_write.c b/tools/testing/selftests/bpf/prog_tests/btf_write.c
> index 5c84723cf2540..7ddda9348e4fe 100644
> --- a/tools/testing/selftests/bpf/prog_tests/btf_write.c
> +++ b/tools/testing/selftests/bpf/prog_tests/btf_write.c
> @@ -606,6 +606,64 @@ static void test_btf_add_btf_split()
[ ... ]
> +static void test_btf_attrs(void)
> +{
> + const struct btf_type *t;
> + struct btf *btf;
> + int id;
> +
> + btf = btf__new_empty();
> + if (!ASSERT_OK_PTR(btf, "new_empty"))
> + return;
> +
> + id = btf__add_int(btf, "int", 4, BTF_INT_SIGNED);
> + ASSERT_EQ(id, 1, "int_id");
> +
> + id = btf__add_struct(btf, "s", 4);
> + ASSERT_EQ(id, 2, "struct_id");
> + ASSERT_OK(btf__add_field(btf, "f", 1, 0, 0), "field_ok");
> +
> + id = btf__add_decl_tag(btf, "tag", 2, -1);
> + ASSERT_EQ(id, 3, "decl_tag_id");
> + t = btf__type_by_id(btf, 3);
> + ASSERT_EQ(btf_kind(t), BTF_KIND_DECL_TAG, "decl_tag_kind");
[Severity: Medium]
In BPF selftests, ASSERT_EQ() logs a failure but does not abort the execution
of the test block. If btf__add_decl_tag() fails, the subsequent call to
btf__type_by_id() will return a NULL pointer.
Will this cause a NULL pointer dereference when t is passed to btf_kind(),
which unconditionally dereferences it?
> + ASSERT_EQ(btf_kflag(t), 0, "decl_tag_kflag");
> +
> + id = btf__add_decl_attr(btf, "tag", 2, -1);
> + ASSERT_EQ(id, 4, "decl_attr_id");
> + t = btf__type_by_id(btf, 4);
> + ASSERT_EQ(btf_kind(t), BTF_KIND_DECL_TAG, "decl_attr_kind");
> + ASSERT_EQ(btf_kflag(t), 1, "decl_attr_kflag");
> + ASSERT_EQ(t->type, 2, "decl_attr_type");
> + ASSERT_EQ(btf_decl_tag(t)->component_idx, -1, "decl_attr_component_idx");
> +
> + id = btf__add_decl_attr(btf, "member_attr", 2, 0);
> + ASSERT_EQ(id, 5, "member_attr_id");
> + ASSERT_EQ(btf_decl_tag(btf__type_by_id(btf, 5))->component_idx, 0,
> + "member_attr_component_idx");
[Severity: Medium]
Similarly, could chaining a potential NULL return from btf__type_by_id()
directly into btf_decl_tag() lead to an out-of-bounds dereference due to
pointer arithmetic on NULL?
> +
> + id = btf__add_type_tag(btf, "tag", 1);
> + ASSERT_EQ(id, 6, "type_tag_id");
> + ASSERT_EQ(btf_kflag(btf__type_by_id(btf, 6)), 0, "type_tag_kflag");
[Severity: Medium]
Is it possible that calling btf_kflag() on a potential NULL pointer from
btf__type_by_id() results in a segmentation fault if the type addition failed?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260917012037.1396254-1-ihor.solodrai@linux.dev?part=4
next prev parent reply other threads:[~2026-09-17 1:27 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
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 [this message]
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=20260917012752.6CBBF1F000FF@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 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.