public inbox for bpf@vger.kernel.org
 help / color / mirror / Atom feed
From: Eduard Zingerman <eddyz87@gmail.com>
To: Dudu Lu <phx0fer@gmail.com>, bpf@vger.kernel.org
Cc: martin.lau@linux.dev, ast@kernel.org, daniel@iogearbox.net,
	andrii@kernel.org
Subject: Re: [PATCH] bpf: btf: reject division by zero in btf_struct_walk for zero-size flex array elements
Date: Mon, 13 Apr 2026 14:43:25 -0700	[thread overview]
Message-ID: <5258cc4b95c2c835b699598f0ce24b3a318b5bc3.camel@gmail.com> (raw)
In-Reply-To: <20260413085033.71952-1-phx0fer@gmail.com>

On Mon, 2026-04-13 at 16:50 +0800, Dudu Lu wrote:
> btf_struct_walk() computes `off = (off - moff) % t->size` when handling
> access to a flexible array member. If the element type is a zero-size
> struct (e.g., `struct B {}`), t->size is 0 and this causes a division-
> by-zero exception. On x86 this triggers a #DE fault resulting in a
> kernel panic.
> 
> The BTF validator does not reject zero-size structs: btf_struct_check_meta()
> passes trivially for vlen=0 structs, and btf_array_resolve() skips the
> overflow check for flex arrays (nelems=0). This allows a user to load
> crafted BTF containing `struct B {}; struct A { int x; struct B flex[]; }`
> and then trigger the crash when the verifier calls btf_struct_walk()
> during program load.

Could you please add a selftest as well?

[...]

      parent reply	other threads:[~2026-04-13 21:43 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-13  8:50 [PATCH] bpf: btf: reject division by zero in btf_struct_walk for zero-size flex array elements Dudu Lu
2026-04-13  9:26 ` bot+bpf-ci
2026-04-13 10:23   ` Leon Hwang
2026-04-13 10:31     ` Leon Hwang
2026-04-13 21:43 ` Eduard Zingerman [this message]

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=5258cc4b95c2c835b699598f0ce24b3a318b5bc3.camel@gmail.com \
    --to=eddyz87@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=martin.lau@linux.dev \
    --cc=phx0fer@gmail.com \
    /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