From patchwork Fri Apr 15 21:17:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Casey Schaufler X-Patchwork-Id: 12815334 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 05745C433F5 for ; Fri, 15 Apr 2022 21:22:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353900AbiDOVYb (ORCPT ); Fri, 15 Apr 2022 17:24:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36834 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354390AbiDOVWe (ORCPT ); Fri, 15 Apr 2022 17:22:34 -0400 Received: from sonic317-39.consmr.mail.ne1.yahoo.com (sonic317-39.consmr.mail.ne1.yahoo.com [66.163.184.50]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0057D45AC5 for ; Fri, 15 Apr 2022 14:19:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1650057596; bh=3RLBS8CrIdzx+91VdCCgk3y7gT/slr8sqP+FVnzX5L4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=EFRU9mxjoxy4QDQcmvzwEfSyGTzxiV1r/eDtytyPMIuvKMHFivmo03KM4yU+AHHWkJv3HfubHqGcZGjfrSX74WIcTYAPr22dJdsmZFyOHpLksg+71nHT89JbCHnkVOO/QwHTe0/1/tdno6GfeZXHgI6spXNcbCN2ECnkGo9BmxCW7bFiVauvCiV1Wih4vpybXk4F5MiWr8xbCjvwnqUV/r4ih4jIg9sV6W/bm+m746tweFforPJX7wUaQTI027NzMSBeKjhXy/5LRiun2dXHWvT1TQFUvh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ss_3VlSpSV2z_9 ST3cYKAwjiRoj8uTLx3oIBleBiOeW0kCGiF82ZK8muxVaPfWvGn1W3LXBxakCVcGv4Uy1eLd9DL5 TWPFUSy.nWkQZV4gAJKk6ZUhcOuvsQgHAGSVrmNgqyhfvSLHFuR36uC_n8xEVyHlZYh7jMHWYRmV fLaw7xJVFyBhK.8dJI1YRlSKA1Md17Zix2bmc24XzuC6NMCIz7zpbLdaXxGoC9rvlV1RpgQ5NGCC HAgnVFGsyztEZFOWvwv9k.WLMdCzlRRWeQ7.jzjPvRF4_6x2YdtjVoNZ8K7IHNwn3Yu.oghmsR1F RCyYO.m8L88aiStPZFT5iD6W0f3N8y4SMQC8Fxrv.uxULRkEEKE.LD1jRk3wz8slQuXijiDKdoA_ LvhqPyVWltYsw9v9t2U7mf0TqK4R62TitcGGrq1Fmr8KMf4atNub2wQUMFQCwQqBgQs9dhCXTM9I ucdoCzNSp.Rn3.WE8iWei5PnvtZ0kncDiNb18RHDfqs6Kb2jDAoq2rWmBJGfsV.Ih4EaCE12NlQG MiQMVJvmKEcdaWQl8pbM_Cg3LliAFfsy8.CKkx76eVsP62vEwzCUicZ_OqchWcLw8mr88uOc_phb zzh04grUDxI5l6pdG3159oSJhr_DHAuoHP_Xw1LhCSuqC6htEWdxJDNXyN47AEFQc1AKKvv4pgeE Qnj5QUWAj5eYtTkxzW_WpzGVfsAVq5eNUCJMZw5xYgCKN2SK_SORA6EKqnQbWitu3mdS. X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic317.consmr.mail.ne1.yahoo.com with HTTP; Fri, 15 Apr 2022 21:19:56 +0000 Received: by hermes--canary-production-bf1-5f49dbcd6-hf9hx (VZM Hermes SMTP Server) with ESMTPA ID e160565289e8323acb3cde95677cb354; Fri, 15 Apr 2022 21:19:50 +0000 (UTC) From: Casey Schaufler To: casey.schaufler@intel.com, jmorris@namei.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org Cc: casey@schaufler-ca.com, linux-audit@redhat.com, keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, paul@paul-moore.com, stephen.smalley.work@gmail.com, linux-kernel@vger.kernel.org Subject: [PATCH v34 04/29] LSM: provide lsm name and id slot mappings Date: Fri, 15 Apr 2022 14:17:36 -0700 Message-Id: <20220415211801.12667-5-casey@schaufler-ca.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220415211801.12667-1-casey@schaufler-ca.com> References: <20220415211801.12667-1-casey@schaufler-ca.com> MIME-Version: 1.0 Precedence: bulk List-ID: Provide interfaces to map LSM slot numbers and LSM names. Update the LSM registration code to save this information. Acked-by: Paul Moore Reviewed-by: Kees Cook Signed-off-by: Casey Schaufler --- include/linux/security.h | 4 ++++ security/security.c | 45 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/include/linux/security.h b/include/linux/security.h index e5f3eb9618e6..5400f68134e5 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -195,6 +195,10 @@ static inline bool lsmblob_equal(const struct lsmblob *bloba, return !memcmp(bloba, blobb, sizeof(*bloba)); } +/* Map lsm names to blob slot numbers */ +extern int lsm_name_to_slot(char *name); +extern const char *lsm_slot_to_name(int slot); + /* These functions are in security/commoncap.c */ extern int cap_capable(const struct cred *cred, struct user_namespace *ns, int cap, unsigned int opts); diff --git a/security/security.c b/security/security.c index 49fa61028da2..d1ddbb857af1 100644 --- a/security/security.c +++ b/security/security.c @@ -477,6 +477,50 @@ static int lsm_append(const char *new, char **result) * Current index to use while initializing the lsmblob secid list. */ static int lsm_slot __lsm_ro_after_init; +static struct lsm_id *lsm_slotlist[LSMBLOB_ENTRIES] __lsm_ro_after_init; + +/** + * lsm_name_to_slot - Report the slot number for a security module + * @name: name of the security module + * + * Look up the slot number for the named security module. + * Returns the slot number or LSMBLOB_INVALID if @name is not + * a registered security module name. + */ +int lsm_name_to_slot(char *name) +{ + int i; + + for (i = 0; i < lsm_slot; i++) + if (strcmp(lsm_slotlist[i]->lsm, name) == 0) + return i; + + return LSMBLOB_INVALID; +} + +/** + * lsm_slot_to_name - Get the name of the security module in a slot + * @slot: index into the interface LSM slot list. + * + * Provide the name of the security module associated with + * a interface LSM slot. + * + * If @slot is LSMBLOB_INVALID return the value + * for slot 0 if it has been set, otherwise NULL. + * + * Returns a pointer to the name string or NULL. + */ +const char *lsm_slot_to_name(int slot) +{ + if (slot == LSMBLOB_INVALID) + slot = 0; + else if (slot >= LSMBLOB_ENTRIES || slot < 0) + return NULL; + + if (lsm_slotlist[slot] == NULL) + return NULL; + return lsm_slotlist[slot]->lsm; +} /** * security_add_hooks - Add a modules hooks to the hook lists. @@ -498,6 +542,7 @@ void __init security_add_hooks(struct security_hook_list *hooks, int count, if (lsmid->slot == LSMBLOB_NEEDED) { if (lsm_slot >= LSMBLOB_ENTRIES) panic("%s Too many LSMs registered.\n", __func__); + lsm_slotlist[lsm_slot] = lsmid; lsmid->slot = lsm_slot++; init_debug("%s assigned lsmblob slot %d\n", lsmid->lsm, lsmid->slot);