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 X-Spam-Level: X-Spam-Status: No, score=-9.9 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 569C3C33CAF for ; Thu, 23 Jan 2020 15:25:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2AB5822522 for ; Thu, 23 Jan 2020 15:25:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="Jp69RmQk" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729133AbgAWPZL (ORCPT ); Thu, 23 Jan 2020 10:25:11 -0500 Received: from mail-pg1-f193.google.com ([209.85.215.193]:45462 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729107AbgAWPZK (ORCPT ); Thu, 23 Jan 2020 10:25:10 -0500 Received: by mail-pg1-f193.google.com with SMTP id b9so1525721pgk.12 for ; Thu, 23 Jan 2020 07:25:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Q4x5KAd27m8l4DDargFurbUE9qKxXrSpODZZ6bpQ4NY=; b=Jp69RmQkL6xEcGqyr24OfJqADG68GZDN7XOwN3C6RbgKxk3YJckrojP9H/yfiLVGpD qxWHjOfZEMp2p7tz7HOgM5FsSgnfRGBg54bIj9ZW2VfOMvC9cDf9MxtKy4m9AdBGYb8b c/1qg6nFPcx20v7/fvgeAGxLiHhwmCvUw+Ja4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Q4x5KAd27m8l4DDargFurbUE9qKxXrSpODZZ6bpQ4NY=; b=X23f7r/3D3pFYqRRh3JSvowbbWbgOB77ez7ql1rAyyjqnUw4lq7+h2e2nkDpTl/68Z Tp9ePF40lled6D2kaT8Kxb8mTVqR8z5jOJvNyn0z2snGo7vbOL6EMswB39nS6Vn34y44 j8hIXLn8nIdt71839GCkLU1jB8SvJFPaq2eB74bQc4QpwRhuGqRMLPHzsEA403VkWoXJ NsCfcExx3l2hLQUoopZDESc8xLd/kE3OkVBaiV4XFfUQeUASOKOg2Y15mBqTOA2duOkz 9F5w7u3UFr1d4v9oBD866ZagbH7pPt4vtPu66xOYXsVAQ1P7K8G1hSv/Z0DmHHF9Uuwq OSgg== X-Gm-Message-State: APjAAAWSxIM1f73N1yre/j9Pb3w42eKG9LRcJCMPoqRGIt5kjOA6qjv8 XtI2/T5YXgTINql1aw22YnvdsSVvQ5xU6A== X-Google-Smtp-Source: APXvYqy69wILp8KzY5eBLZS9Y6shozDIu5m42vqavj1O7DKkYvFz5hDVbewtJW2V8AcxgFhtzKJSDA== X-Received: by 2002:a63:2ac2:: with SMTP id q185mr4570434pgq.417.1579793109702; Thu, 23 Jan 2020 07:25:09 -0800 (PST) Received: from kpsingh-kernel.localdomain ([2a00:79e1:abc:122:bd8d:3f7b:87f7:16d1]) by smtp.gmail.com with ESMTPSA id v5sm3108118pfn.122.2020.01.23.07.25.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Jan 2020 07:25:09 -0800 (PST) From: KP Singh To: linux-kernel@vger.kernel.org, bpf@vger.kernel.org, linux-security-module@vger.kernel.org Cc: Brendan Jackman , Florent Revest , Thomas Garnier , Alexei Starovoitov , Daniel Borkmann , James Morris , Kees Cook , Thomas Garnier , Michael Halcrow , Paul Turner , Brendan Gregg , Jann Horn , Matthew Garrett , Christian Brauner , =?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?= , Florent Revest , Brendan Jackman , Martin KaFai Lau , Song Liu , Yonghong Song , "Serge E. Hallyn" , Mauro Carvalho Chehab , "David S. Miller" , Greg Kroah-Hartman , Nicolas Ferre , Stanislav Fomichev , Quentin Monnet , Andrey Ignatov , Joe Stringer Subject: [PATCH bpf-next v3 01/10] bpf: btf: Add btf_type_by_name_kind Date: Thu, 23 Jan 2020 07:24:31 -0800 Message-Id: <20200123152440.28956-2-kpsingh@chromium.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200123152440.28956-1-kpsingh@chromium.org> References: <20200123152440.28956-1-kpsingh@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: KP Singh - The LSM code does the combination of btf_find_by_name_kind and btf_type_by_id a couple of times to figure out the BTF type for security_hook_heads and security_list_options. - Add an extern for btf_vmlinux in btf.h Signed-off-by: KP Singh Reviewed-by: Brendan Jackman Reviewed-by: Florent Revest Reviewed-by: Thomas Garnier --- include/linux/btf.h | 3 +++ kernel/bpf/btf.c | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/include/linux/btf.h b/include/linux/btf.h index 5c1ea99b480f..d4e859f90a39 100644 --- a/include/linux/btf.h +++ b/include/linux/btf.h @@ -15,6 +15,7 @@ struct btf_type; union bpf_attr; extern const struct file_operations btf_fops; +extern struct btf *btf_vmlinux; void btf_put(struct btf *btf); int btf_new_fd(const union bpf_attr *attr); @@ -66,6 +67,8 @@ const struct btf_type * btf_resolve_size(const struct btf *btf, const struct btf_type *type, u32 *type_size, const struct btf_type **elem_type, u32 *total_nelems); +const struct btf_type *btf_type_by_name_kind( + struct btf *btf, const char *name, u8 kind); #define for_each_member(i, struct_type, member) \ for (i = 0, member = btf_type_member(struct_type); \ diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c index 32963b6d5a9c..ea53c16802cb 100644 --- a/kernel/bpf/btf.c +++ b/kernel/bpf/btf.c @@ -441,6 +441,18 @@ const struct btf_type *btf_type_resolve_func_ptr(const struct btf *btf, return NULL; } +const struct btf_type *btf_type_by_name_kind( + struct btf *btf, const char *name, u8 kind) +{ + s32 type_id; + + type_id = btf_find_by_name_kind(btf, name, kind); + if (type_id < 0) + return ERR_PTR(type_id); + + return btf_type_by_id(btf, type_id); +} + /* Types that act only as a source, not sink or intermediate * type when resolving. */ -- 2.20.1