BPF List
 help / color / mirror / Atom feed
From: Martin KaFai Lau <martin.lau@linux.dev>
To: Lorenz Bauer <oss@lmb.io>
Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>, Song Liu <song@kernel.org>,
	Yonghong Song <yhs@fb.com>,
	John Fastabend <john.fastabend@gmail.com>,
	KP Singh <kpsingh@kernel.org>,
	Stanislav Fomichev <sdf@google.com>, Hao Luo <haoluo@google.com>,
	Jiri Olsa <jolsa@kernel.org>
Subject: Re: [PATCH bpf] bpf: btf: fix truncated last_member_type_id in btf_struct_resolve
Date: Fri, 9 Sep 2022 11:17:52 -0700	[thread overview]
Message-ID: <d2fd289d-a5b5-f0af-3125-417ba9d242f0@linux.dev> (raw)
In-Reply-To: <20220909092107.3035-1-oss@lmb.io>

On 9/9/22 2:21 AM, Lorenz Bauer wrote:
> When trying to finish resolving a struct member, btf_struct_resolve
> saves the member type id in a u16 temporary variable. This truncates
> the 32 bit type id value if it exceeds UINT16_MAX.
> 
> As a result, structs that have members with type ids > UINT16_MAX and
> which need resolution will fail with a message like this:
> 
>      [67414] STRUCT ff_device size=120 vlen=12
>          effect_owners type_id=67434 bits_offset=960 Member exceeds struct_size
> 
> Fix this by changing the type of last_member_type_id to u32.
> 
> Fixes: eb3f595dab40 ("bpf: btf: Validate type reference")

The fix tag should be

Fixes: a0791f0df7d2 ("bpf: fix BTF limits")

> Signed-off-by: Lorenz Bauer <oss@lmb.io>
> ---
>   kernel/bpf/btf.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
> index 7e64447659f3..36fd4b509294 100644
> --- a/kernel/bpf/btf.c
> +++ b/kernel/bpf/btf.c
> @@ -3128,7 +3128,7 @@ static int btf_struct_resolve(struct btf_verifier_env *env,
>   	if (v->next_member) {
>   		const struct btf_type *last_member_type;
>   		const struct btf_member *last_member;
> -		u16 last_member_type_id;
> +		u32 last_member_type_id;

The change makes sense.

The kernel's vmlinux and module btf parsing doesn't go through this 
resolve check though.  Are you trying to __sys_bpf(BPF_BTF_LOAD) the btf 
from the vmlinux file into the kernel ?


  parent reply	other threads:[~2022-09-09 18:18 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-09  9:21 [PATCH bpf] bpf: btf: fix truncated last_member_type_id in btf_struct_resolve Lorenz Bauer
2022-09-09 17:19 ` sdf
2022-09-09 18:17 ` Martin KaFai Lau [this message]
2022-09-10 11:02   ` Lorenz Bauer

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=d2fd289d-a5b5-f0af-3125-417ba9d242f0@linux.dev \
    --to=martin.lau@linux.dev \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=haoluo@google.com \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kpsingh@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=oss@lmb.io \
    --cc=sdf@google.com \
    --cc=song@kernel.org \
    --cc=yhs@fb.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