From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 36FF8ECAAD3 for ; Fri, 9 Sep 2022 18:18:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229845AbiIISSJ (ORCPT ); Fri, 9 Sep 2022 14:18:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54788 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230047AbiIISSB (ORCPT ); Fri, 9 Sep 2022 14:18:01 -0400 Received: from out0.migadu.com (out0.migadu.com [IPv6:2001:41d0:2:267::]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC155B0289; Fri, 9 Sep 2022 11:17:57 -0700 (PDT) Message-ID: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1662747476; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hxQnEaoROX92cThvzg5SE/OCMATF1xv047X1ewBjYn8=; b=m8SodHb5jeDFvbUyYV1O1Y0W46rXSYhxvBG8BB6oEwoHAP8jqiq3J3cly6azMFcDa8y/H+ 9BJ0IlatuXdUVOgKcncGTdWVnfVVf5OvL5JkfzcTkoz1FFZr936j817sHQ9ziHDexX/YkH Y3Rz+oCABNYQi1VXHpGSZVemq5fGU3A= Date: Fri, 9 Sep 2022 11:17:52 -0700 MIME-Version: 1.0 Subject: Re: [PATCH bpf] bpf: btf: fix truncated last_member_type_id in btf_struct_resolve Content-Language: en-US To: Lorenz Bauer Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org, Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa References: <20220909092107.3035-1-oss@lmb.io> X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Martin KaFai Lau In-Reply-To: <20220909092107.3035-1-oss@lmb.io> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: linux.dev Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org 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 > --- > 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 ?