From patchwork Fri Jun 11 00:04:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Casey Schaufler X-Patchwork-Id: 12314335 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=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham 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 76245C48BDF for ; Fri, 11 Jun 2021 00:08:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5B992613CF for ; Fri, 11 Jun 2021 00:08:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230417AbhFKAKC (ORCPT ); Thu, 10 Jun 2021 20:10:02 -0400 Received: from sonic311-31.consmr.mail.ne1.yahoo.com ([66.163.188.212]:45506 "EHLO sonic311-31.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230307AbhFKAKB (ORCPT ); Thu, 10 Jun 2021 20:10:01 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1623370084; bh=vc75HBdHrsxBmtLktLZ2z+T6Shh8g9//phefY7W7K1w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=SMdyFVvIwgjRmeyxotY+isB69LBx156QOEqD6kf/y+sz9iQaPc3jwK7r54ht7/RVg5Mp7SUWrh10w5s/7sgEu1UHPcgQEpPniw1Zjs8p7aQkA6W+8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XPz2_wlsrqVXNVpv8IcSjZbLv9xw1aYsNl 30ouS28b1OxfdLOyvFCdxL37BiuLcJiztwg.l3_m06VGj9fSQovf_b2s7DZwQmWHGldSPe_7Lifa nSLaFOd62PMtkiXY2.2KvfO5RkMClIIy0XYqG_FpjgdACVm1NAVCJrO63YrHNDX4JzP052oP3nHh yf54Wc1AppAq_o._pQPjdvqBU86s8aPlZCdyyoQmXN5kn88d90YjkA3uB_h3hx2e23d4EH5GfnPP TsChLH0AbQCO.iQ7uSWNmEH7EAST9ZPVK1QUW6gHoBQydswcgEbgj2mxzkZ2zmMIQKPz16233Xi5 gSgEX4wJfEzFm2W17L_vR1VvXWjeboXyDbuQ8kYUdPjRKY45Wjf7LTwvur3LanER2sdfTE2n8Ap5 enBBwa9WsZ8wLJqZwRc.VEtagMH8jpwJpHrIiRxXywJ.9oOle3gKNMKQpOHYoMel2rEamUGRAfjz HFfSKbNAn40XkF6NmBu8aWUrGqFxe0UDG81ZrRaf96sNdDlehCc4FIQ1iZXZPHvfUWTUEU9M6rVr akDd0JqbYj5IDP2HSU8HSZOajsPMOT_PNYFSHBtFn5Dl_O2IwApE94C_TUF4ufbsCzK.cfacZJ97 PTCVsj8PJnmxwpcWyhjO9jdk4IUa0nvQB0SmgFoKW8vMCrg-- X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic311.consmr.mail.ne1.yahoo.com with HTTP; Fri, 11 Jun 2021 00:08:04 +0000 Received: by kubenode502.mail-prod1.omega.bf1.yahoo.com (VZM Hermes SMTP Server) with ESMTPA ID d27c7752e1fb9a4c4f97207b6af5182f; Fri, 11 Jun 2021 00:08:03 +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, sds@tycho.nsa.gov, linux-kernel@vger.kernel.org Subject: [PATCH v27 03/25] LSM: provide lsm name and id slot mappings Date: Thu, 10 Jun 2021 17:04:13 -0700 Message-Id: <20210611000435.36398-4-casey@schaufler-ca.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210611000435.36398-1-casey@schaufler-ca.com> References: <20210611000435.36398-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. 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 62588bc522ba..ca9485105f00 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -192,6 +192,10 @@ static inline bool lsmblob_equal(struct lsmblob *bloba, struct lsmblob *blobb) 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 473b49971aab..6387107e4014 100644 --- a/security/security.c +++ b/security/security.c @@ -476,6 +476,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. @@ -497,6 +541,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);