From: Alan Maguire <alan.maguire@oracle.com>
To: bot+bpf-ci@kernel.org, andrii@kernel.org, ast@kernel.org
Cc: daniel@iogearbox.net, martin.lau@linux.dev, eddyz87@gmail.com,
song@kernel.org, yonghong.song@linux.dev,
john.fastabend@gmail.com, kpsingh@kernel.org, sdf@fomichev.me,
haoluo@google.com, jolsa@kernel.org, qmo@kernel.org,
ihor.solodrai@linux.dev, mykyta.yatsenko5@gmail.com,
dwarves@vger.kernel.org, bpf@vger.kernel.org,
martin.lau@kernel.org, clm@meta.com
Subject: Re: [PATCH v9 bpf-next 06/10] btf: support kernel parsing of BTF with layout info
Date: Thu, 26 Feb 2026 16:25:54 +0000 [thread overview]
Message-ID: <de9dbe59-7adc-4e00-a0eb-7f5b3cb88ae9@oracle.com> (raw)
In-Reply-To: <dc1d9fb29ac2eba86b21fb85ad1bac9d096f0e9680ef87b42a86200120b5e7a1@mail.kernel.org>
On 26/02/2026 10:05, bot+bpf-ci@kernel.org wrote:
>> diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
>> --- a/kernel/bpf/btf.c
>> +++ b/kernel/bpf/btf.c
>
> [ ... ]
>
>> @@ -5327,23 +5328,36 @@ static s32 btf_check_meta(struct btf_verifier_env *env,
>> return -EINVAL;
>> }
>>
>> + if (!btf_name_offset_valid(env->btf, t->name_off)) {
>> + btf_verifier_log(env, "[%u] Invalid name_offset:%u",
>> + env->log_type_id, t->name_off);
>> + return -EINVAL;
>> + }
>> +
>> + if (BTF_INFO_KIND(t->info) == BTF_KIND_UNKN) {
>> btf_verifier_log(env, "[%u] Invalid kind:%u",
>> env->log_type_id, BTF_INFO_KIND(t->info));
>> return -EINVAL;
>> }
>>
>> + if (BTF_INFO_KIND(t->info) > BTF_KIND_MAX && env->btf->layout &&
>> + ((BTF_INFO_KIND(t->info) + 1) * sizeof(struct btf_layout)) <
>> + env->btf->hdr.layout_len) {
> ^
>
> Should this be <= instead of < ? If the layout section has exactly
> N entries, layout_len is N * sizeof(struct btf_layout). For the
> last covered kind (K = N - 1), this computes:
>
> (K + 1) * sizeof(struct btf_layout) == layout_len
>
> With < that evaluates to false, so the last kind covered by the
> layout section falls through to the else branch and gets logged as
> "Invalid kind" instead of "unknown but required kind".
>
> The libbpf equivalent in btf_type_size_unknown() uses:
>
> __u32 layout_kinds = btf->hdr.layout_len / sizeof(struct btf_layout);
> if (!l || kind >= layout_kinds) {
>
> which accepts the last entry. Using <= here would match that
> behavior.
>
looking at this again, is it worth making the distinction between a kind
that's in the BTF layout but unknown to the kernel versus one that is
not in the BTF layout and unknown to the kernel? In both cases we reject
the BTF, and given that the kernel cannot be in the business of trusting
the layout provided with that BTF it seems like it's a distinction without
a practical difference.
>> + btf_verifier_log(env, "[%u] unknown but required kind %u",
>> + env->log_type_id,
>> + BTF_INFO_KIND(t->info));
>> return -EINVAL;
>> + } else {
>> + if (BTF_INFO_KIND(t->info) > BTF_KIND_MAX) {
>> + btf_verifier_log(env, "[%u] Invalid kind:%u",
>> + env->log_type_id, BTF_INFO_KIND(t->info));
>> + return -EINVAL;
>> + }
>> + var_meta_size = btf_type_ops(t)->check_meta(env, t, meta_left);
>> + if (var_meta_size < 0)
>> + return var_meta_size;
>> }
>
>
> ---
> AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
> See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
>
> CI run summary: https://github.com/kernel-patches/bpf/actions/runs/22436234361
>
> AI-authorship-score: low
> AI-authorship-explanation: Multi-year revision history with detailed reviewer interactions, idiomatic kernel C, and an off-by-one error typical of manual arithmetic translation are inconsistent with AI-generated code.
> issues-found: 1
> issue-severity-score: low
> issue-severity-explanation: Off-by-one in layout bounds check produces wrong verifier log message but does not change functional behavior since both paths return -EINVAL.
next prev parent reply other threads:[~2026-02-26 16:26 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-26 8:56 [PATCH v9 bpf-next 00/10] Add BTF layout to BTF Alan Maguire
2026-02-26 8:56 ` [PATCH v9 bpf-next 01/10] btf: add BTF kind layout encoding to UAPI Alan Maguire
2026-02-26 10:06 ` bot+bpf-ci
2026-02-26 8:56 ` [PATCH v9 bpf-next 02/10] libbpf: Support layout section handling in BTF Alan Maguire
2026-02-26 10:05 ` bot+bpf-ci
2026-02-26 15:55 ` Alan Maguire
2026-02-26 8:56 ` [PATCH v9 bpf-next 03/10] libbpf: use layout to compute an unknown kind size Alan Maguire
2026-02-26 10:05 ` bot+bpf-ci
2026-02-26 8:56 ` [PATCH v9 bpf-next 04/10] libbpf: Add layout encoding support Alan Maguire
2026-02-26 10:05 ` bot+bpf-ci
2026-02-26 14:46 ` Alan Maguire
2026-02-26 8:56 ` [PATCH v9 bpf-next 05/10] libbpf: BTF validation can use layout for unknown kinds Alan Maguire
2026-02-26 8:56 ` [PATCH v9 bpf-next 06/10] btf: support kernel parsing of BTF with layout info Alan Maguire
2026-02-26 10:05 ` bot+bpf-ci
2026-02-26 16:25 ` Alan Maguire [this message]
2026-02-26 16:34 ` Alexei Starovoitov
2026-02-26 16:39 ` Alan Maguire
2026-02-26 8:56 ` [PATCH v9 bpf-next 07/10] selftests/bpf: test kind encoding/decoding Alan Maguire
2026-02-26 8:56 ` [PATCH v9 bpf-next 08/10] bpftool: add BTF dump "format meta" to dump header/metadata Alan Maguire
2026-02-26 10:05 ` bot+bpf-ci
2026-02-26 8:56 ` [PATCH v9 bpf-next 09/10] bpftool: Update doc to describe bpftool btf dump .. format metadata Alan Maguire
2026-02-26 10:05 ` bot+bpf-ci
2026-02-26 8:56 ` [PATCH v9 bpf-next 10/10] kbuild, bpf: Specify "layout" optional feature Alan Maguire
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=de9dbe59-7adc-4e00-a0eb-7f5b3cb88ae9@oracle.com \
--to=alan.maguire@oracle.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bot+bpf-ci@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=clm@meta.com \
--cc=daniel@iogearbox.net \
--cc=dwarves@vger.kernel.org \
--cc=eddyz87@gmail.com \
--cc=haoluo@google.com \
--cc=ihor.solodrai@linux.dev \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=martin.lau@kernel.org \
--cc=martin.lau@linux.dev \
--cc=mykyta.yatsenko5@gmail.com \
--cc=qmo@kernel.org \
--cc=sdf@fomichev.me \
--cc=song@kernel.org \
--cc=yonghong.song@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