public inbox for dwarves@vger.kernel.org
 help / color / mirror / Atom feed
From: Eduard Zingerman <eddyz87@gmail.com>
To: Alan Maguire <alan.maguire@oracle.com>,
	andrii@kernel.org, ast@kernel.org
Cc: daniel@iogearbox.net, martin.lau@linux.dev, 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,
	dwarves@vger.kernel.org, bpf@vger.kernel.org,  ttreyer@meta.com,
	mykyta.yatsenko5@gmail.com
Subject: Re: [PATCH v8 bpf-next 06/10] btf: support kernel parsing of BTF with kind layout
Date: Mon, 15 Dec 2025 22:51:14 -0800	[thread overview]
Message-ID: <1351a3a944fab86e7fe1babf8b31cde4e722077e.camel@gmail.com> (raw)
In-Reply-To: <20251215091730.1188790-7-alan.maguire@oracle.com>

On Mon, 2025-12-15 at 09:17 +0000, Alan Maguire wrote:

If strict kind layout checks are the goal, would it make sense to
check sizes declared in kind_layout for known types?

[...]

> @@ -5215,23 +5216,36 @@ static s32 btf_check_meta(struct btf_verifier_env *env,
>  		return -EINVAL;
>  	}
>  
> -	if (BTF_INFO_KIND(t->info) > BTF_KIND_MAX ||
> -	    BTF_INFO_KIND(t->info) == BTF_KIND_UNKN) {
> +	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_name_offset_valid(env->btf, t->name_off)) {
> -		btf_verifier_log(env, "[%u] Invalid name_offset:%u",
> -				 env->log_type_id, t->name_off);
> +	if (BTF_INFO_KIND(t->info) > BTF_KIND_MAX && env->btf->kind_layout &&
> +	    ((BTF_INFO_KIND(t->info) + 1) * sizeof(struct btf_kind_layout)) <
> +	     env->btf->hdr.kind_layout_len) {
> +		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;
>  	}
>  
> -	var_meta_size = btf_type_ops(t)->check_meta(env, t, meta_left);
> -	if (var_meta_size < 0)
> -		return var_meta_size;
> -
>  	meta_left -= var_meta_size;

It appears that a smaller change here would achieve same results:

    -        if (BTF_INFO_KIND(t->info) > BTF_KIND_MAX ||
    +        u32 layout_kind_max = env->btf->hdr.kind_layout_len / sizeof(struct btf_kind_layout);
    +        if (BTF_INFO_KIND(t->info) > layout_kind_max ||
                 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) {
    +                btf_verifier_log(env, "[%u] unknown but required kind %u",
    +                                 env->log_type_id,
    +                                 BTF_INFO_KIND(t->info));
    +        }
    +
             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);

wdyt?

But tbh, the "unknown but required kind" message seems unnecessary,

>  
>  	return saved_meta_left - meta_left;
> @@ -5405,7 +5419,8 @@ static int btf_parse_str_sec(struct btf_verifier_env *env)
>  	start = btf->nohdr_data + hdr->str_off;
>  	end = start + hdr->str_len;
>  
> -	if (end != btf->data + btf->data_size) {
> +	if (hdr->hdr_len < sizeof(struct btf_header) &&
> +	    end != btf->data + btf->data_size) {

Given that btf_check_sec_info() checks for overlap and total size,
is this check needed at all?

>  		btf_verifier_log(env, "String section is not at the end");
>  		return -EINVAL;
>  	}

[...]

  reply	other threads:[~2025-12-16  6:51 UTC|newest]

Thread overview: 65+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-15  9:17 [PATCH v8 bpf-next 00/10] Add kind layout to BTF Alan Maguire
2025-12-15  9:17 ` [PATCH v8 bpf-next 01/10] btf: add kind layout encoding to UAPI Alan Maguire
2025-12-15  9:38   ` bot+bpf-ci
2025-12-16 19:23   ` Andrii Nakryiko
2025-12-19 13:15     ` Alan Maguire
2025-12-19 17:53       ` Andrii Nakryiko
2025-12-19 18:13         ` Alan Maguire
2025-12-19 18:19           ` Andrii Nakryiko
2025-12-19 18:22             ` Alan Maguire
2025-12-20  0:05             ` Alexei Starovoitov
2025-12-22  8:58               ` Alan Maguire
2025-12-22 19:03                 ` Alexei Starovoitov
2025-12-23 11:09                   ` Alan Maguire
2026-01-06  0:11                     ` Andrii Nakryiko
2026-01-06  0:51                       ` Alexei Starovoitov
2026-01-06  1:19                         ` Andrii Nakryiko
2026-01-08 18:55                           ` Alan Maguire
2026-01-09  1:24                             ` Andrii Nakryiko
2026-01-09  1:40                               ` Alexei Starovoitov
2026-01-09 13:20                                 ` Alan Maguire
2026-01-09 18:34                                   ` Alexei Starovoitov
2026-01-12 17:47                                     ` Alan Maguire
2025-12-15  9:17 ` [PATCH v8 bpf-next 02/10] libbpf: Support kind layout section handling in BTF Alan Maguire
2025-12-15  9:38   ` bot+bpf-ci
2025-12-15 16:03     ` Alan Maguire
2025-12-16  0:08   ` Eduard Zingerman
2025-12-16  6:01   ` Eduard Zingerman
2025-12-16 14:58     ` Alan Maguire
2025-12-16 19:34   ` Andrii Nakryiko
2025-12-19 13:34     ` Alan Maguire
2025-12-19 17:58       ` Andrii Nakryiko
2025-12-19 18:18         ` Alan Maguire
2025-12-19 18:21           ` Andrii Nakryiko
2025-12-19 18:36             ` Eduard Zingerman
2025-12-19 18:41               ` Andrii Nakryiko
2025-12-19 18:44                 ` Eduard Zingerman
2025-12-15  9:17 ` [PATCH v8 bpf-next 03/10] libbpf: use kind layout to compute an unknown kind size Alan Maguire
2025-12-16  6:07   ` Eduard Zingerman
2025-12-16 15:00     ` Alan Maguire
2025-12-16 19:42       ` Andrii Nakryiko
2025-12-16 19:58         ` Eduard Zingerman
2025-12-16 21:11           ` Andrii Nakryiko
2025-12-16 21:21             ` Eduard Zingerman
2025-12-16 22:23               ` Andrii Nakryiko
2025-12-16 22:35                 ` Eduard Zingerman
2025-12-16 23:00                   ` Andrii Nakryiko
2025-12-16 23:36                     ` Eduard Zingerman
2025-12-17  0:30                       ` Andrii Nakryiko
2025-12-17  0:38                         ` Eduard Zingerman
2025-12-16 19:37   ` Andrii Nakryiko
2025-12-15  9:17 ` [PATCH v8 bpf-next 04/10] libbpf: Add kind layout encoding support Alan Maguire
2025-12-16  5:58   ` Eduard Zingerman
2025-12-16 21:04   ` Andrii Nakryiko
2025-12-15  9:17 ` [PATCH v8 bpf-next 05/10] libbpf: BTF validation can use kind layout for unknown kinds Alan Maguire
2025-12-15  9:17 ` [PATCH v8 bpf-next 06/10] btf: support kernel parsing of BTF with kind layout Alan Maguire
2025-12-16  6:51   ` Eduard Zingerman [this message]
2025-12-16 21:21     ` Andrii Nakryiko
2025-12-16 21:25       ` Eduard Zingerman
2025-12-16 22:09         ` Andrii Nakryiko
2025-12-16 22:12           ` Eduard Zingerman
2025-12-15  9:17 ` [PATCH v8 bpf-next 07/10] selftests/bpf: test kind encoding/decoding Alan Maguire
2025-12-15  9:17 ` [PATCH v8 bpf-next 08/10] bpftool: add BTF dump "format meta" to dump header/metadata Alan Maguire
2025-12-15  9:52   ` bot+bpf-ci
2025-12-15  9:17 ` [PATCH v8 bpf-next 09/10] bpftool: Update doc to describe bpftool btf dump .. format metadata Alan Maguire
2025-12-15  9:17 ` [PATCH v8 bpf-next 10/10] kbuild, bpf: Specify "kind_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=1351a3a944fab86e7fe1babf8b31cde4e722077e.camel@gmail.com \
    --to=eddyz87@gmail.com \
    --cc=alan.maguire@oracle.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=dwarves@vger.kernel.org \
    --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@linux.dev \
    --cc=mykyta.yatsenko5@gmail.com \
    --cc=qmo@kernel.org \
    --cc=sdf@fomichev.me \
    --cc=song@kernel.org \
    --cc=ttreyer@meta.com \
    --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