public inbox for dwarves@vger.kernel.org
 help / color / mirror / Atom feed
From: Alan Maguire <alan.maguire@oracle.com>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: bot+bpf-ci@kernel.org, Andrii Nakryiko <andrii@kernel.org>,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Martin KaFai Lau <martin.lau@linux.dev>,
	Eduard <eddyz87@gmail.com>, Song Liu <song@kernel.org>,
	Yonghong Song <yonghong.song@linux.dev>,
	John Fastabend <john.fastabend@gmail.com>,
	KP Singh <kpsingh@kernel.org>,
	Stanislav Fomichev <sdf@fomichev.me>, Hao Luo <haoluo@google.com>,
	Jiri Olsa <jolsa@kernel.org>, Quentin Monnet <qmo@kernel.org>,
	Ihor Solodrai <ihor.solodrai@linux.dev>,
	Mykyta Yatsenko <mykyta.yatsenko5@gmail.com>,
	dwarves <dwarves@vger.kernel.org>, bpf <bpf@vger.kernel.org>,
	Martin KaFai Lau <martin.lau@kernel.org>,
	Chris Mason <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:39:06 +0000	[thread overview]
Message-ID: <b6f2967d-4d8e-4898-8aa6-e1fc5e59deb7@oracle.com> (raw)
In-Reply-To: <CAADnVQJOv7aayd1Awsfhwmiotkex_-ie+_H2agx55Ka954rbqA@mail.gmail.com>

On 26/02/2026 16:34, Alexei Starovoitov wrote:
> On Thu, Feb 26, 2026 at 8:26 AM Alan Maguire <alan.maguire@oracle.com> wrote:
>>
>> 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.
> 
> "unknown but required kind" means that the kernel doesn't understand
> the kind, but its layout is described in BTF?
> If so the sentence is odd, since presence in kind_layout doesn't mean
> it's actually used. Here the check is when the kind is parsed.
> So the kernel should reject it with existing "invalid kind" message and
> that's it. It doesn't matter whether the unknown kind was described
> in the layout.
>

yeah, looking at this again it's leftovers from the flags stuff which makes
it confusing. I'll revert to original error messaging since it's irrelevant
to the kernel if the kind is in the layout if the kernel doesn't know about
that kind - we can't blindly trust the layout data.

 
> But at the same time if the kind layout describes some unknown kinds
> it's not an error. I think it's fine to load such BTF since all used
> kinds are known.

Right; we'll allow layout to describe additional kinds not known to the
kernel, but won't trust that info for parsing BTF in-kernel.

  reply	other threads:[~2026-02-26 16:39 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
2026-02-26 16:34       ` Alexei Starovoitov
2026-02-26 16:39         ` Alan Maguire [this message]
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=b6f2967d-4d8e-4898-8aa6-e1fc5e59deb7@oracle.com \
    --to=alan.maguire@oracle.com \
    --cc=alexei.starovoitov@gmail.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