Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp2324594rwn; Fri, 9 Sep 2022 11:48:59 -0700 (PDT) X-Google-Smtp-Source: AA6agR6KfPohV5glgYxWKGNlDnXBrjbI0GQhSPuGxH5a/wufr9cpGjZWUmTLow275YI0YT9dVjfb X-Received: by 2002:a05:6402:28ca:b0:43b:5235:f325 with SMTP id ef10-20020a05640228ca00b0043b5235f325mr12510420edb.320.1662749338912; Fri, 09 Sep 2022 11:48:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662749338; cv=none; d=google.com; s=arc-20160816; b=UugW3nl1wtEo2VsPurFSUzwGY9NIr7S1BmMOqwVTBjs/AhNs60QwjKff1KZRYoF6hI Zb0dBQedGznwYmgzDRFi4s06Wtz24jl2Bky5C9PYXJ3LQk1ujFftpYdY+vg+xKSp5OIr inCWjg+3Gr+VIPc2yi1TXInGu/kwMTfWwgLB3AEdYOj6Tx/j2TW/S4DFVMt3wG2/xnmd hctENpOhEFCR8rNPQ9jgSQFYWlYy8p2ZLDfUJfyHwSHY3XGjVHaubVRF1ZM8n6oDvpSW uVkyRxbyHjHVDmsdTm7isITf85jlwHGRSHhiWq58cyuqjsMFw36f+G82CrU1xMBTr44j FcMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:mime-version:date :dkim-signature:message-id; bh=hxQnEaoROX92cThvzg5SE/OCMATF1xv047X1ewBjYn8=; b=W721pOpoTgfzWUtrVuzdRI7Nle4HBQOZaCayMGH+lvcSv5lX2tYBaW9PFCXliWwGF5 XPAS+qc7XXKUzw1bH/QtR4qSt1i/VaE0R8MrOpHxoOgoTbgrPa0UX7iL6Qt6vlRrQpxA f2Yo/0vT8xGF6Mv9NGmNCBno7PMj2EZj0bIS3XcqGRFGk+wFX+/PZvIVT4M2mit3/mwz /ZqfST+AhO4f5LAS0X6KJRIowhbHDh+dLqftEHjuPTDNIlEusCmRsUdXOWa32dDe27NW WKpoQGUjAAdjDQo1Sifub58WrV1c/jnADLDyMhOzZHHa7jAOHJv2bXF6hlqhJ96824vq 8EcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=m8SodHb5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u2-20020a1709067d0200b00732fcbcfedesi994442ejo.623.2022.09.09.11.48.31; Fri, 09 Sep 2022 11:48:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=m8SodHb5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230220AbiIISSK (ORCPT + 99 others); Fri, 9 Sep 2022 14:18:10 -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 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 ?