From: Abhinav Madake <abhinavmadake@gmail.com>
To: bpf@vger.kernel.org
Cc: Andrii Nakryiko <andrii@kernel.org>,
Eduard Zingerman <eddyz87@gmail.com>,
Ihor Solodrai <ihor.solodrai@linux.dev>,
Abhinav Madake <abhinavmadake@gmail.com>
Subject: [PATCH bpf-next v2] libbpf: Check for unknown type ID in btf__align_of()
Date: Sat, 19 Sep 2026 23:15:32 +0530 [thread overview]
Message-ID: <20260919174532.25407-1-abhinavmadake@gmail.com> (raw)
In-Reply-To: <20260919164229.95154-1-abhinavmadake@gmail.com>
btf__align_of() passes the result of btf__type_by_id() to btf_kind()
without a NULL check, so an unknown type ID crashes. Parsed BTF cannot
hit this since btf_sanity_check() rejects dangling references, but BTF
built with btf__add_*() can, as those only check the ID range.
Return 0 with errno set to EINVAL, like the unsupported-kind case.
Link: https://github.com/libbpf/libbpf/issues/983
Signed-off-by: Abhinav Madake <abhinavmadake@gmail.com>
---
v2: return 0 with errno instead of -EINVAL, callers test for 0.
tools/lib/bpf/btf.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c
index 908bd3442..6bfbc7a65 100644
--- a/tools/lib/bpf/btf.c
+++ b/tools/lib/bpf/btf.c
@@ -986,8 +986,12 @@ done:
int btf__align_of(const struct btf *btf, __u32 id)
{
const struct btf_type *t = btf__type_by_id(btf, id);
- __u16 kind = btf_kind(t);
+ __u16 kind;
+ if (!t)
+ return errno = EINVAL, 0;
+
+ kind = btf_kind(t);
switch (kind) {
case BTF_KIND_INT:
case BTF_KIND_ENUM:
--
2.47.0
next prev parent reply other threads:[~2026-09-19 17:45 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-19 16:42 [PATCH bpf-next] libbpf: Return -EINVAL from btf__align_of() for unknown type ID Abhinav Madake
2026-09-19 16:57 ` sashiko-bot
2026-09-19 17:45 ` Abhinav Madake [this message]
2026-09-19 18:44 ` [PATCH bpf-next v2] libbpf: Check for unknown type ID in btf__align_of() Alexei Starovoitov
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=20260919174532.25407-1-abhinavmadake@gmail.com \
--to=abhinavmadake@gmail.com \
--cc=andrii@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=eddyz87@gmail.com \
--cc=ihor.solodrai@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.