Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp1471757rwb; Tue, 27 Sep 2022 13:41:17 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5tOhfp7MZdcDNk8Zk15EVjGe3TRtaUMhHBxo4UICVGEgeFTxyKfNrxzztDIo+LJ5UtLxl9 X-Received: by 2002:a17:902:ec8f:b0:177:ff40:19bf with SMTP id x15-20020a170902ec8f00b00177ff4019bfmr28148276plg.141.1664311277512; Tue, 27 Sep 2022 13:41:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664311277; cv=none; d=google.com; s=arc-20160816; b=rDgyaADmUMaJLNldQ1MPOgIdFi5cUELeh+aMpxU+UHo921c8/+rAjrZn+XUWwFNMw8 QYk9yas+Sd+wmXmb6yzxFoNcjuua4MPIy3+zdW53lr2nVHL22qSTDza3SmD1Ey1wfN7o Mke5wH0QEeacZqyk3jOUz8qsy03Jc/m9SKuOcgXt/3cQNtqEKBPI8+dgrqan15AA2qrU lMZ3yhkEHVWCqK2CK+9mJeRiFt+FDqKU/qyGqHGq7t/4sHq/wuw4OqzUrZV21/FDvnSu GP5ECM0vWQF8n0BnfYyD9OWNkwtgtr15muV2u7NAIjv+aISi0cFyAd/eZjweSK8TL6rD eqQA== 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=VPzKlwpLKZOBzTB//B7tagQk/2MUAL21dCJ/O4/krZc=; b=MK0EZkMLZzGITAC00KDjjkxT4i2wI2C9hLThvH/Rfmm1R1Z0aPU/0i5vB9in5AMsVr BqHSCoC3p5bjInLKO8o/jU1q2hRCB3bSumuN++zNfledAOmesvAmI76MT2DUvmL/zdFX rlNsJfgwj4aSY9W+qt3/a2i5abBbemEsdcJo55XgdNuIyahIRfFfOZsY8zKlVpW1rQjR OsLBPwzzf8e5SX1HD0njzAPS2maqMmUB/fo5DQyuVxvaDlYM0UB2dZ0/0fhz4knLtKyl d4paKfSEyZ1Rj0n8YLLcPvz7ioGueqZjiw1PbCmxn9Feg18MEOsyX5ctqfrHeyjVj6ZL hy/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@yahoo.com header.s=s2048 header.b=V3+ShlJ+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x26-20020a634a1a000000b00439f66e23cfsi2957546pga.9.2022.09.27.13.41.06; Tue, 27 Sep 2022 13:41:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@yahoo.com header.s=s2048 header.b=V3+ShlJ+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232493AbiI0UA1 (ORCPT + 99 others); Tue, 27 Sep 2022 16:00:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52124 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232479AbiI0T7c (ORCPT ); Tue, 27 Sep 2022 15:59:32 -0400 Received: from sonic308-15.consmr.mail.ne1.yahoo.com (sonic308-15.consmr.mail.ne1.yahoo.com [66.163.187.38]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 822FB1CE614 for ; Tue, 27 Sep 2022 12:59:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1664308768; bh=VPzKlwpLKZOBzTB//B7tagQk/2MUAL21dCJ/O4/krZc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=V3+ShlJ+vqQ786/oViQKmFJZ7U9de1rePF5gK+toHJjN5yBHGOwF6SHdALX56YKWYQvPGLrB8QV4eWHCmRuluDchJl0v93MV1s7MRZYbff/0FH+0d+KX+t4p0RXv9VOXUK6uyIsw5eZDIhDcT6cTW6TGsUxJfJVfshS4WgiTidbQOeM19Y3iLeuEoqjcBKQAKJgMSXPdP/0UCzdl7UNBJC6KvgEzNZFHB4Zm86CwAjFO4jnGCzI/jxdNcnGkRK/dYJuBjqbFgdpx+YfCTW4nP7Ol5adFoNJ5ld6LF44Ys8MXZr7pIuYhElsQST9647FOcXXGBK7ZG81XY/N0iu6/7Q== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1664308768; bh=q2wDraLE9wUf/JVZLUYk2ol1DZI+RDn+ZNZ7japat9o=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=GPpsIXZ/gQHRk25pt4HzNAhavXnyNoYvo4cq5Drs60U84TPTSRoTyWyfblUlg/kHWQnfMBcpbu/it2UCqwl3ql9U6oMeEoaFXlB9xMiKyhsWXsbG0ntIgnHn8AgnlcGtf0CDmAgQhJ7LvGGwXHe7c7P6Cqw8raiN+7QPsOfJVVktMGkj1q+Fm1r2zwhFrUx4ijBGNNDFsUMLdNmIgygOF/UffE2XU0XueWMWyPgpCOR4Ca20gSqpNmLJsaPLmPzBWIr9xtq72590MEU36G/VRyh8gm9ePCSh97+cVOd6q8PDQlBCXQmGKbavzEPNKt/48ZlCwNxelV4xNa5GsYkSTg== X-YMail-OSG: quY2aZYVM1lvozECIdOvLWEfgx5w29WOXAgHMS.NuV3ppO.ouymQPJb69pCaLdj gd8aufOQ0siP1.EDg0IKX1flZbMPQe09iA9Np6RnBX_cviLp3U2vyWzW1ejp.BFL15zauQy8aC.q 8xUn98v0tysoAj4JhUglRQu5Mnv8uB8.R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hOPJ2qkEnTfwnEes- X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic308.consmr.mail.ne1.yahoo.com with HTTP; Tue, 27 Sep 2022 19:59:28 +0000 Received: by hermes--production-gq1-7dfd88c84d-mgq76 (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID a8608bb7fdb0322afb9a5fe3db2c5570; Tue, 27 Sep 2022 19:59:24 +0000 (UTC) From: Casey Schaufler To: casey.schaufler@intel.com, paul@paul-moore.com, linux-security-module@vger.kernel.org Cc: casey@schaufler-ca.com, linux-audit@redhat.com, jmorris@namei.org, selinux@vger.kernel.org, keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, stephen.smalley.work@gmail.com, linux-kernel@vger.kernel.org Subject: [PATCH v38 10/39] LSM: provide lsm name and id slot mappings Date: Tue, 27 Sep 2022 12:53:52 -0700 Message-Id: <20220927195421.14713-11-casey@schaufler-ca.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220927195421.14713-1-casey@schaufler-ca.com> References: <20220927195421.14713-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,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE autolearn=unavailable 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 c1f8b33e7c27..0f0fb2077f41 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -214,6 +214,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 b837500cb3dc..2c197c25746c 100644 --- a/security/security.c +++ b/security/security.c @@ -486,6 +486,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. @@ -517,6 +561,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.37.3