Received: by 2002:a19:f614:0:0:0:0:0 with SMTP id x20csp58238lfe; Fri, 15 Apr 2022 19:23:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwzHUW9MQdGr+iC4teWLs5NLHj6no1oyMBHC3MM+g3qBSNg1bTAo7hccSxLJkHYQIk5L1Hl X-Received: by 2002:a63:d915:0:b0:39d:3f7d:1850 with SMTP id r21-20020a63d915000000b0039d3f7d1850mr1411007pgg.10.1650075790520; Fri, 15 Apr 2022 19:23:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650075790; cv=none; d=google.com; s=arc-20160816; b=HNE/zet7S02YhQE2OA8M/UWlRFYmJw4nlgCuUlfjtGzHYEwTdz8KQG+aL1CcpFShFd CUo9ojLsf5ndO81Ds1rMzaaPKgT9zNdRCfelomd3hLfg1i34Cq7St9HZHPQvGDTxgo6L HnI/mycky/YYpTpx0pW4zgx8EGH6QLsey5ctEqvo5U/iDcfaKyadi5gymXBFESlPRonB 2/1mnY/uMLlV/qhGOno0hJtkBvm0lrcC3fyGo7cTUPe2BFQyZCXU/chW+60eXSpDcymw UyndiVJ/UsXZYxQFEphjNI1OabGjO7KJGKCRdW1ika+9E0l7g0SmMa4Bc3TuMmck4UVr d4ZQ== 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:cc:to:from :dkim-signature; bh=3RLBS8CrIdzx+91VdCCgk3y7gT/slr8sqP+FVnzX5L4=; b=f8vJH2VXdqrzloJZzDyH/EwCsrv98cinZAhPzmJy6F0BmIKimo+GEOZgJ6IX9BxCXU Z8kLgpsoxld0SMDncIwTvucOJE9hfMK3rHtHum7eOPgMn02bnHU+HmYHt6SyhtlZmRJ4 iBINnVjBm9HmJ8O/IQo8ocsrmxl9YL3ya51sNDMlm5UBQzB/yh3rkYNTik98OCp4KjtG LdKQChwKqW6v00vZ73YfgI5srGQPiXcr5lFEyTLfdTYIoFuaiPC4KMCaqgZeQT9u1WW2 MpKHMG32GxkBL2k5BaY8BoHiBrH31N0krVfJp5kadoUphbJziMeTLF9MdV3L/NDSQtqo VvXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@yahoo.com header.s=s2048 header.b=EFRU9mxj; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id m20-20020a634c54000000b0038211f06f37si2918987pgl.867.2022.04.15.19.23.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Apr 2022 19:23:10 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@yahoo.com header.s=s2048 header.b=EFRU9mxj; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A06D0160155; Fri, 15 Apr 2022 18:37:21 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345357AbiDOVYh (ORCPT + 99 others); Fri, 15 Apr 2022 17:24:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38828 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354306AbiDOVWe (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 004AA44776 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/5LRiun2dXHWvT1TQFUvhINUgq//StsGOB3mPYbwXMdBpWEZEcVyMDpcqWb874idXge+Iz5z/AbSg== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1650057596; bh=0NbuN59THT+1YSTMA+4qih5PHoetooK0yycoTT37ffO=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=fnXdSuUzKnLt5ePyVWh5UjVpbNt4DgdSB3ZZ6xpr1vVs/NdFC10jh3rDJe6BnRY8sk1cBKNU2wfxC+C5peovtniSPv6BFzJ3hlebxBxOFM/ckjCsImZKMhKqkIIKRzuudOL+nfC2Pp0HMCGI+PF3O0X4qz+AXTBUh1j57q5SBMREJWnjd9df9SpGIrgkQXYJ1WSLqBmUyZeHYhZ0+9D3Rr9dhtsBn2VzKtjfaBnsJdKTZa/LMKoKfr8BKDN9mAqqSQ/BbBXkzS+aBANJNQaofgs7oCuPR3i9CC51SM5lVaqSSMeT0d0m9XRZ7IRmGzXJ51qbwJfKjKIJkIOOCb2Yrg== X-YMail-OSG: hqw_9PUVM1nRfELlkp9h0qfBKXKBz9ZHLn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.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 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 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); -- 2.35.1