Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp7930106rwp; Wed, 19 Jul 2023 02:32:29 -0700 (PDT) X-Google-Smtp-Source: APBJJlEWFN0VTYJmtrIq87xHLeRFKGz/Gm+6MbUrYHuU7mB2wYmbMdYONo2LwrqYB+iIkVeQeydv X-Received: by 2002:a05:6358:2904:b0:134:f28f:aa47 with SMTP id y4-20020a056358290400b00134f28faa47mr6516150rwb.23.1689759149152; Wed, 19 Jul 2023 02:32:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689759149; cv=none; d=google.com; s=arc-20160816; b=gk8hMklb3HBot8kVlZ6HcemUSjfmv/2+T0iUMZzKXDkjX3JqzbSwzbA1ioM20LUtAz pMmAjUXyfJgCUHVwjmI1w/vxdYD966D2XaLcB/0FuR6TIc/vis90/16Jq6DRf2Zxn+Hd W9FpwdY4aULFLWYSnUj2E7aRnP2tbNfO0ECTvZPdK7YlRrjBJN9wJD+/o+ZtNOStgOay Tcf9sAd4qBhq7NbTvNdVJkjqTxJrIf25pdKTZiAoJlw4F59dpDzyuCIUXR2T2xedQyXc JEA0fqQkopv3THjy71/P1mn78VgOeXHnna69FIqtB4ge0yin3z5nhzF5M5fh3NXBNXEK E2cA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=7yIrbZZR4lCf9GkhcpzxSxXCXtiiG2twcc9m1HrepQM=; fh=2sg2q7H8sim4Fm1AbvHvV4k3HSKIwWA7VUbqHVkgvXY=; b=cZBigAJ+g1fiGQLAy4cGEhVcm542oEPDh1E/nGOSHWK43ee6DpnSvcFljR6LdeYxk1 T/hU7FfUHVFpG2tSIN6G+tgi/RmxXwz1qAZyHJwRRcewGHMJ3x6lF9DTebVSmFTlCfjS UT8gQDNsgqLZ4zCHrXkcoQNKGm1U+XwJjt8dbPYyeMy4jM9n1kmZ5mHrmj4MC6xfULrh hdfeGNGI1Ey54/Ny/ehX+nSPuOI6aW82SQ0XdP/gnbamwtZnEAeMMHB9nVxQpFAx8jl0 UFFps/vixN/EUvapb9XlrAT9K1dZM8QQD5xJRwFeAZfB20tM0zmzzVX3qbQOYMkDPJcM E7Xw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@isovalent.com header.s=google header.b=YEixGh5H; 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=isovalent.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r7-20020a63e507000000b00563379020f4si2846320pgh.71.2023.07.19.02.32.17; Wed, 19 Jul 2023 02:32:29 -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=@isovalent.com header.s=google header.b=YEixGh5H; 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=isovalent.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229801AbjGSJ2q (ORCPT + 99 others); Wed, 19 Jul 2023 05:28:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39846 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229689AbjGSJ2n (ORCPT ); Wed, 19 Jul 2023 05:28:43 -0400 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C2C511BFC for ; Wed, 19 Jul 2023 02:28:42 -0700 (PDT) Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-3110ab7110aso6864775f8f.3 for ; Wed, 19 Jul 2023 02:28:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=isovalent.com; s=google; t=1689758921; x=1692350921; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=7yIrbZZR4lCf9GkhcpzxSxXCXtiiG2twcc9m1HrepQM=; b=YEixGh5HQBFgZR9iRMGxVQCaew6ZN4cNCvdwaCgkfJ4NWRHyaXymSonkXqsxYBpeHw eFC+YxzSSrCN7HiNvb14OxUMDE8BJyipOGvbCz2c4iFNE1kVuNRKPGkbtOojEi5nU9O1 10SWJi8kIW2w4bJ9Zm88mldz64l1zZLyPWdqqAtXxawhrlOGm4TgPy9mGIs0JMn/vVqZ 0XaPgHMVc8OlKMG/t1sPKUe0I4eLQbEwCfsL9bBWJziaxlG+QoRVZn2oHrw6UBqHkzYB vqLIcP+F3xKVCbHQd0NfLVf32dNlWI91inCPekKmzovxRwFbW7Y6IVI9/P+MkBPN7cTF VVCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689758921; x=1692350921; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7yIrbZZR4lCf9GkhcpzxSxXCXtiiG2twcc9m1HrepQM=; b=NcSywi+HWU+zgLHWWr3JkcJaMuFdtNbcAWnN0zAMD4usF3Pswo4K1qxCXhH3Ty0CAY IzySY8uYnEOJHElV5Fv+duUXEfMXnqU3F3oCreK0oWZw2x3g9hh4LNr2jHXxeFGIDzRK e79uBGoLMLckvS38G2dObEEPz7hVvvEnB5KtSW7kWcvPUlYqtxUaPJPH3eDXheqeNOXa ycxy3TXo9hYrUAAn371AVa/+F0CsUnBhVPhZ2mIMwr3qRS+eob93IMdpBiWP9eul9OTA MCPJSt56ztiNijJ/SER0MhNFel1REPckk4vFxG+LtqV5s57/aY4n3z8V+AO7MzCAti7v TMtw== X-Gm-Message-State: ABy/qLYC0QfcLEriVG3bBxcKTUJmLuFK7KUiuANRubnSieFam4uyhleT 2RjmDDjmNbRQidbg2UL3zu6mOw== X-Received: by 2002:a5d:4292:0:b0:314:f88:4fea with SMTP id k18-20020a5d4292000000b003140f884feamr15008563wrq.8.1689758921130; Wed, 19 Jul 2023 02:28:41 -0700 (PDT) Received: from zh-lab-node-5.home ([2a02:168:f656:0:1ac0:4dff:fe0f:3782]) by smtp.gmail.com with ESMTPSA id r18-20020adff112000000b0031435c2600esm4857213wro.79.2023.07.19.02.28.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Jul 2023 02:28:40 -0700 (PDT) From: Anton Protopopov To: Martin KaFai Lau , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Mykola Lysenko , Shuah Khan , Hou Tao , Joe Stringer , Anton Protopopov , bpf@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH v2 bpf-next 1/4] bpf: consider types listed in reg2btf_ids as trusted Date: Wed, 19 Jul 2023 09:29:49 +0000 Message-Id: <20230719092952.41202-2-aspsk@isovalent.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230719092952.41202-1-aspsk@isovalent.com> References: <20230719092952.41202-1-aspsk@isovalent.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=unavailable 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 The reg2btf_ids array contains a list of types for which we can (and need) to find a corresponding static BTF id. All the types in the list can be considered as trusted for purposes of kfuncs. Signed-off-by: Anton Protopopov --- kernel/bpf/verifier.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 0b9da95331d7..05123feab378 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -5413,12 +5413,24 @@ static bool is_flow_key_reg(struct bpf_verifier_env *env, int regno) return reg->type == PTR_TO_FLOW_KEYS; } +static u32 *reg2btf_ids[__BPF_REG_TYPE_MAX] = { +#ifdef CONFIG_NET + [PTR_TO_SOCKET] = &btf_sock_ids[BTF_SOCK_TYPE_SOCK], + [PTR_TO_SOCK_COMMON] = &btf_sock_ids[BTF_SOCK_TYPE_SOCK_COMMON], + [PTR_TO_TCP_SOCK] = &btf_sock_ids[BTF_SOCK_TYPE_TCP], +#endif +}; + static bool is_trusted_reg(const struct bpf_reg_state *reg) { /* A referenced register is always trusted. */ if (reg->ref_obj_id) return true; + /* Types listed in the reg2btf_ids are always trusted */ + if (reg2btf_ids[base_type(reg->type)]) + return true; + /* If a register is not referenced, it is trusted if it has the * MEM_ALLOC or PTR_TRUSTED type modifiers, and no others. Some of the * other type modifiers may be safe, but we elect to take an opt-in @@ -10052,15 +10064,6 @@ static bool __btf_type_is_scalar_struct(struct bpf_verifier_env *env, return true; } - -static u32 *reg2btf_ids[__BPF_REG_TYPE_MAX] = { -#ifdef CONFIG_NET - [PTR_TO_SOCKET] = &btf_sock_ids[BTF_SOCK_TYPE_SOCK], - [PTR_TO_SOCK_COMMON] = &btf_sock_ids[BTF_SOCK_TYPE_SOCK_COMMON], - [PTR_TO_TCP_SOCK] = &btf_sock_ids[BTF_SOCK_TYPE_TCP], -#endif -}; - enum kfunc_ptr_arg_type { KF_ARG_PTR_TO_CTX, KF_ARG_PTR_TO_ALLOC_BTF_ID, /* Allocated object */ -- 2.34.1