Received: by 2002:a05:6a10:83d0:0:0:0:0 with SMTP id o16csp93655pxh; Thu, 7 Apr 2022 15:05:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzoEEJxNcQrNI+DkqKGnFSHmePc/OtOnQNisg9tUrth20r+lKwh041YMdy4OX9SE0FfoXBU X-Received: by 2002:a17:902:8a8d:b0:157:ab0:a07 with SMTP id p13-20020a1709028a8d00b001570ab00a07mr4606505plo.77.1649369110362; Thu, 07 Apr 2022 15:05:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649369110; cv=none; d=google.com; s=arc-20160816; b=PbzalUMsdiM+hl1x3WKRpb1XSscSl1Lc7AmbwtKvuPz8EKNMXUpA/REDKNMt7kc7sF oUT9COfTQA8V/G/Uza51h3lhFsoB7ZdUyAT8080LFX+09V6XV63kcj4+PLFJEoka65i+ wy2pInMEDnj45UGJgfsUVghMy4/7dmNdIJms4pcMPcG9D5lCJMVsxkBY0YMtm4fAOnim XlQRQDQamZYPmROFH4Lfm6v4LwS1C/z55Kkb0S3RZ9MkDcLzhX1k8spb385FlxvhDHqh ltASnekbR83nar2NN5xW65xC+fWinlg7MCbd5CFlnGfR/o4uA0nqelLuGQe7dL456xyo zxdg== 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=rIRoSp2oTfmJjY2R9v3o5OGftJPEjwsqE8Ln7s8ivkk8WBAINgK6fck9fxpHlzJrb5 8VuL852dKHEvBuSqtgB5TK31ym+cGAwaisKlMKlrjOFw0yZckCvRBhL0JGi4BXulhuL0 RHy0sHYrUDBrGrCNDEf1rTSd/4HmdADOtCQUc9pDHQMvnWQmikxzfwB4I2kFVLLIXF3R MT/3nlq9EIAJ93W+QMJw22RXCMV4wNswjBMMd44DDcSx1Kwolvy/y5dUl29OEVJWv+p5 tua6qRTHE7uCoKvtwQwOMPVfBBG2lwf4LtKUMFn2bmLuy0PwXUSuVgzTw3wc/gviCMWo 6uoA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@yahoo.com header.s=s2048 header.b=oxWhiKnj; 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 j3-20020a170903028300b00156a87b3106si898279plr.565.2022.04.07.15.05.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Apr 2022 15:05: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=oxWhiKnj; 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 9F6F9195D9C; Thu, 7 Apr 2022 14:24:31 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231317AbiDGV01 (ORCPT + 99 others); Thu, 7 Apr 2022 17:26:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59080 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231180AbiDGV0Z (ORCPT ); Thu, 7 Apr 2022 17:26:25 -0400 Received: from sonic311-30.consmr.mail.ne1.yahoo.com (sonic311-30.consmr.mail.ne1.yahoo.com [66.163.188.211]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 23CB3195306 for ; Thu, 7 Apr 2022 14:24:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1649366663; bh=3RLBS8CrIdzx+91VdCCgk3y7gT/slr8sqP+FVnzX5L4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=oxWhiKnjxPopCIRcY1RkneJHoKwIgdDcFb+Oe8mEmagzoQRHAmFo6Wug3jq1nt9B7LSD/ulgvqRufkb9PdxMZiWTEH+HGiiH4JFCqPT/wElJ66gQ9dAzPtXdggVHDJPOLTeA82/w6mQVbKiPtv1sZS+iANIwdyNR6XbLMYz5ihFuChKqnVmPZLxr7/j8g9iDpJfs2gCPahdV5H5nYS7nl0iJ9bnbIB1RQIbHjSFsN52nx3FyKMOqa2JQQlI3GfC1zEXibyaktS1zUyx9THpsiiH2duwt4Fl4W0Dukn3GIPlFVj9bcfZ+UpWwAhUFynX0p4e6PO2Mxk8qXKzqB5D2vw== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1649366663; bh=YlPjpIpl6mUa/bOVouZXvx1+EIqITZb1LkD9pmJeMH0=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=Cz2FxCSkhx7NhKAU1NKf62+yTVocwEHSAJx6v9GQDVen1PmXNa12XlvHoEtbvknMGT0j5m2viBrNxyk3U2I3EL/6E1DhDVbEpc3PDGL0HLBw86XNafwtVNPbmmuKjSl77PA/uTG5I0X8aCJd6B9nlJ1opwwXg3ezauSNoDLPOFffN7d5RvPLhdPPkNDTn0JYYikA+hAZBF1kEgt69mgNWfsiRCprcSLhvmwBooZ7SzNfwWsgYEQFr6W+qzZ2mKYBpyfbJSd33tNalg2YrPyxzn4dWT7gCFnGwV3F2DMu1BMFaYVjWv2U0TEwz9A+4V77a4qMZO5pE6EHlJAKd4Malg== X-YMail-OSG: tdzIIacVM1ko8kHIsxjRxT33xlzsNysqNJ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KxQt5GtHlHxHMKIu70xVVZ.BcuB8Q0mebT69kzthTPSv B_fml1mgZ0TEk.DVHfSbC1O0MqGGM0y04MECjY22xO8PpS4xg9uxg X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic311.consmr.mail.ne1.yahoo.com with HTTP; Thu, 7 Apr 2022 21:24:23 +0000 Received: by hermes--canary-production-bf1-665cdb9985-6hz22 (VZM Hermes SMTP Server) with ESMTPA ID 7b3eda77d72d772e8386b3c1f765a2b9; Thu, 07 Apr 2022 21:24:21 +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: Thu, 7 Apr 2022 14:22:05 -0700 Message-Id: <20220407212230.12893-5-casey@schaufler-ca.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220407212230.12893-1-casey@schaufler-ca.com> References: <20220407212230.12893-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