public inbox for dwarves@vger.kernel.org
 help / color / mirror / Atom feed
From: Eduard Zingerman <eddyz87@gmail.com>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: Alan Maguire <alan.maguire@oracle.com>,
	andrii@kernel.org, ast@kernel.org, 	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 03/10] libbpf: use kind layout to compute an unknown kind size
Date: Tue, 16 Dec 2025 13:21:53 -0800	[thread overview]
Message-ID: <26e95f737d2de5133702c9b641946e70ec2d1dae.camel@gmail.com> (raw)
In-Reply-To: <CAEf4BzayA6if0xcTLux=eyASM1kpARmrOdDRmgG9F1SFa-fEcg@mail.gmail.com>

On Tue, 2025-12-16 at 13:11 -0800, Andrii Nakryiko wrote:
> On Tue, Dec 16, 2025 at 11:58 AM Eduard Zingerman <eddyz87@gmail.com> wrote:
> > 
> > On Tue, 2025-12-16 at 11:42 -0800, Andrii Nakryiko wrote:
> > > On Tue, Dec 16, 2025 at 7:00 AM Alan Maguire <alan.maguire@oracle.com> wrote:
> > > > 
> > > > On 16/12/2025 06:07, Eduard Zingerman wrote:
> > > > > On Mon, 2025-12-15 at 09:17 +0000, Alan Maguire wrote:
> > > > > 
> > > > > [...]
> > > > > 
> > > > > > @@ -395,8 +416,7 @@ static int btf_type_size(const struct btf_type *t)
> > > > > >      case BTF_KIND_DECL_TAG:
> > > > > >              return base_size + sizeof(struct btf_decl_tag);
> > > > > >      default:
> > > > > > -            pr_debug("Unsupported BTF_KIND:%u\n", btf_kind(t));
> > > > > > -            return -EINVAL;
> > > > > > +            return btf_type_size_unknown(btf, t);
> > > > > >      }
> > > > > >  }
> > > > > > 
> > > > > 
> > > > > That's a matter of personal preference, of-course, but it seems to me
> > > > > that using `kind_layouts` table from your next patch for size
> > > > > computation for all kinds would be a bit more elegant.
> > > > > 
> > > > > Also, a question, should BTF validation check sizes for known kinds
> > > > > and reject kind layout sections if those sizes differ from expected?
> > > > > 
> > > > 
> > > > yeah, I'd say we'd need your second suggestion for the first to be safe,
> > > > and it seems worthwhile doing both I think. Thanks!
> > > 
> > > ... but we will just blindly trust layout for unknown kinds, though?
> > > So it's a bit inconsistent. I'd say let's keep it simple and don't
> > > overdo the checking? btf_sanity_check() will validate that all known
> > > kinds are well-formed, isn't that sufficient to ensure that subsequent
> > > use of BTF data in libbpf won't crash? If some tool generated a subtly
> > > invalid layout section which otherwise preserves BTF data
> > > correctness... I don't know, this seems fine. The goal of sanity
> > > checking is just to prevent more checks in all different places that
> > > will subsequently rely on IDs being valid, and stuff like that. If
> > > layout info is wrong for known kinds, so be it, we are not using that
> > > information anyways.
> > 
> > Ignoring layout information for known kinds can lead to weird
> > scenarios: e.g. suppose type size is N, but kind layout specifies that
> > it is M > N, and the tool generating BTF uses M to actually layout the
> > binary data. We are being a bit inconsistent with such encoding.
> 
> Who are "we" here? The tool that emitted incorrect layout information
> -- yep, for sure. (But that shouldn't happen for correct BTF.)
> 
> We do btf_sanity_check() upfront to minimize various sanity checks
> spread out in libbpf code when using BTF data later on. But the goal
> there is not really to check "100% standards conformance" of whatever
> BTF we are working with. Kernel is way more concerned about validity
> and not letting anything unexpected get through, but libbpf is in user
> space and it's a bit different approach there.
> 
> As long as BTF looks structurally sound (btf_sanity_check), it should
> be fine for our needs. If BTF is corrupted or just uses invalid ID, or
> whatnot, it will eventually fail somewhere, most probably. But the
> goal is not to have NULL derefs and stuff like that.

Introducing layout info into format provides an alternative definition
for structural soundness. E.g. some types or vlen elements can have
padding in the end all of a sudden.

Using this info for some types but not the others is inconsistent.
Given that BTF rewrites would only be unsound in presence of unknown
types the whole feature looks questionable to me.

> Basically what I'm trying to say is that if some tool intentionally or
> unintentionally generates invalid layout information, but the rest of
> data is valid, and libbpf doesn't look at layout and otherwise makes
> fine use of BTF. Then that's fine with me, that BTF fulfills its duty
> as far as libbpf is concerned. Libbpf here is just a consumer that
> tries to be as permissive (unlike kernel) as possible, while not
> leading to a process crash.
> 
> With double checking that layout info matches our implicit knowledge
> of type layout we are starting to move into BTF verification a bit,
> IMO. And I think that's misleading and unnecessary.

  reply	other threads:[~2025-12-16 21:21 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 [this message]
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
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=26e95f737d2de5133702c9b641946e70ec2d1dae.camel@gmail.com \
    --to=eddyz87@gmail.com \
    --cc=alan.maguire@oracle.com \
    --cc=andrii.nakryiko@gmail.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