Received: by 2002:a05:6358:700f:b0:131:369:b2a3 with SMTP id 15csp1319654rwo; Wed, 2 Aug 2023 12:03:39 -0700 (PDT) X-Google-Smtp-Source: APBJJlElqhOJvGYaFYHXa3KhJT8+xABYAW8IphRlbKemH6m43ockdpYhie0w4io2RcCxsfY/+97T X-Received: by 2002:a05:6a20:12c2:b0:13e:fec5:ac12 with SMTP id v2-20020a056a2012c200b0013efec5ac12mr2500379pzg.34.1691003019080; Wed, 02 Aug 2023 12:03:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691003019; cv=none; d=google.com; s=arc-20160816; b=Ma3wk47uixb/KXgqZlFhzDCFjIiRmzga/+iF+W+HSf2k4V9L3dyZMMCEnY7/OGbuyk I3vZ0qDeJFUxTGm6jyLc1GZKBPJOGmwme7UG4lOT4QpasvucdWr4UKqvbHX6nsIaUnGU 1iymk2Q3z/XRIDr4oKpvniz7uVv/w7I9CNdr+/YFROGDLwKWsuuaFXpcZuTe54S0CIkC rVhMSnvLU2LKOlL2MdgP3n9xGewfNcFsIMNtDXWEDvKQJ+OznqHTlIbqfRZ5U9Xh38RN pb78ZnagwQpEZjWC1+hLo4kvzNMYp7pkzZsAHwtD7ScASDGuKGAqY5YPMqyD7lE6E49i rELQ== 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=ToC+SC5FgpVH1bMwFJ4SomOW39/rLrbS89hxS3BAGhk=; fh=arL9UBRJHFsofiiQd44aZRxxzO7fu/grwMh4D2tbp88=; b=KzsvKN4lQCWBi4SkykfeiYVKhqgWld7GLqfAzzh10b5XD5Ix1mCsJtncz2tIFiUT7M SO3spBdoJRuVESScAYWfCcjHBFUfZ6jcZto26qKJjIIkyCx+rdLPxpBFUJayqXm2SFyc xk+yUlCkErZjFR9KeTmh+eCUqjTVP5OOoFgXPf+WYh5tLXwhJa0lKqVXjfQ5wvymOZn7 GbTDNH/OG/vuEKXIo7CyHMIkjhGpUNQfw6nE1Grc1/V4SylPMsnHEOqboPKx6u59f0QC DacUbsQQ0O07qKhkgtczXQnP3wGhaPEP+asAWvyBDjMoOMBLPh1+HfeZWCRDaEalbhOR VjCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@yahoo.com header.s=s2048 header.b=j10ToaCh; 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 s3-20020a63d043000000b005636f6c7f56si1422943pgi.25.2023.08.02.12.03.27; Wed, 02 Aug 2023 12:03:39 -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=j10ToaCh; 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 S233829AbjHBRpD (ORCPT + 99 others); Wed, 2 Aug 2023 13:45:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36314 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233782AbjHBRos (ORCPT ); Wed, 2 Aug 2023 13:44:48 -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 0908C173A for ; Wed, 2 Aug 2023 10:44:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1690998286; bh=ToC+SC5FgpVH1bMwFJ4SomOW39/rLrbS89hxS3BAGhk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=j10ToaCh3Xkb2u+AZwrCYZKaSGdHKnLwxuroIVAEEDtk+e+5G6SIzZN25Xjfj58pp5mFs5OPUY8lVvD8XIQyCl59ZHnOxpXirMYwRDQBFW7Fi870uSSeYeuaHKL04tRGCp+xsxWEaea9fbtySf5s/x1+nFJo5rNyx8avmXGI76Ko3iFqlXb8vZQR8AXE2kEviifMufYkMRKQ9jKUl2YiddxB0BiP/+apOTPVAnqT7jiVl5+BS+nMAOwIkmJN6gasZ6PDkeZjPFBSAfLC3nuKQ9CAp32ei9UQExUFug+/3BqzUsygYzNrAnad0ExNCpKwMYNCeD0myBOFY55DsCM92w== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1690998286; bh=ZHTlAUptwH2igMnYQ3BV9OGV3cb7oAoxuRmMOPRs4j/=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=aKJACkIO84YJ9CYuxV/YQpvICTwt5DI9NADpR+qcOzvSXPsFoeeC12rAiaHmWMAZHG7egryBjxuSrlpCor/UiVItSAhEvbIysSSpJdnMpaTETMqPmumroJRR50KYVGMlfn7wXjSfMm2eKwRsOZKA54ipU4Bec+38lMe/kg2K57Y6LNt2+5VyO5xxNHkvjV65YEvqAUJvZ3aKNTSGIqyF2UbU9lnzHHsflWxqj/Ul4ZE653O4pGSjemoB0oiimEzgnbiS6RwSQCDzA3fatutBDmXmIGLBYC0VBRGaT9XrtJBK0emXICVHAJZ9qz3occcCyBmTkD6kvThcj7qeH9j4GA== X-YMail-OSG: TKkGTagVM1mvN9I3wCAqCytbgC_iQUrEN9ir8FtHCwQCdGd7iVlTd6h62jryj.9 Bk8ofJjZ9yXIO2nQM3gQXpCnzfK_FAhVIe5UR5dadNn9edqiZdXBpBvLM80QnHEMto_yWDQkoiac toRCt6SaRc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x9_9WWMziYiARUVQKR8EUq4RRbnDcsmie2y3iyQ4CzVuDvcTp9hxLTy8GSe npkBBpsJkuJsjRfv2 X-Sonic-MF: X-Sonic-ID: 427dd040-a3fe-46a8-a4cf-987a71033c9c Received: from sonic.gate.mail.ne1.yahoo.com by sonic311.consmr.mail.ne1.yahoo.com with HTTP; Wed, 2 Aug 2023 17:44:46 +0000 Received: by hermes--production-gq1-7d844d8954-psjqr (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 839fbc661e28c041ce8f4c5628604c14; Wed, 02 Aug 2023 17:44:43 +0000 (UTC) From: Casey Schaufler To: casey@schaufler-ca.com, paul@paul-moore.com, linux-security-module@vger.kernel.org Cc: jmorris@namei.org, serge@hallyn.com, keescook@chromium.org, john.johansen@canonical.com, penguin-kernel@i-love.sakura.ne.jp, stephen.smalley.work@gmail.com, linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, mic@digikod.net Subject: [PATCH v13 02/11] LSM: Maintain a table of LSM attribute data Date: Wed, 2 Aug 2023 10:44:25 -0700 Message-ID: <20230802174435.11928-3-casey@schaufler-ca.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230802174435.11928-1-casey@schaufler-ca.com> References: <20230802174435.11928-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_BLOCKED,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE 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 As LSMs are registered add their lsm_id pointers to a table. This will be used later for attribute reporting. Determine the number of possible security modules based on their respective CONFIG options. This allows the number to be known at build time. This allows data structures and tables to use the constant. Signed-off-by: Casey Schaufler Reviewed-by: Kees Cook Reviewed-by: Serge Hallyn --- include/linux/security.h | 2 ++ security/security.c | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/include/linux/security.h b/include/linux/security.h index 32828502f09e..a20a4ceda6d9 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -138,6 +138,8 @@ enum lockdown_reason { }; extern const char *const lockdown_reasons[LOCKDOWN_CONFIDENTIALITY_MAX+1]; +extern u32 lsm_active_cnt; +extern const struct lsm_id *lsm_idlist[]; /* These functions are in security/commoncap.c */ extern int cap_capable(const struct cred *cred, struct user_namespace *ns, diff --git a/security/security.c b/security/security.c index feaae09581dc..87b70a55a028 100644 --- a/security/security.c +++ b/security/security.c @@ -36,6 +36,25 @@ /* How many LSMs were built into the kernel? */ #define LSM_COUNT (__end_lsm_info - __start_lsm_info) +/* + * How many LSMs are built into the kernel as determined at + * build time. Used to determine fixed array sizes. + * The capability module is accounted for by CONFIG_SECURITY + */ +#define LSM_CONFIG_COUNT ( \ + (IS_ENABLED(CONFIG_SECURITY) ? 1 : 0) + \ + (IS_ENABLED(CONFIG_SECURITY_SELINUX) ? 1 : 0) + \ + (IS_ENABLED(CONFIG_SECURITY_SMACK) ? 1 : 0) + \ + (IS_ENABLED(CONFIG_SECURITY_TOMOYO) ? 1 : 0) + \ + (IS_ENABLED(CONFIG_IMA) ? 1 : 0) + \ + (IS_ENABLED(CONFIG_SECURITY_APPARMOR) ? 1 : 0) + \ + (IS_ENABLED(CONFIG_SECURITY_YAMA) ? 1 : 0) + \ + (IS_ENABLED(CONFIG_SECURITY_LOADPIN) ? 1 : 0) + \ + (IS_ENABLED(CONFIG_SECURITY_SAFESETID) ? 1 : 0) + \ + (IS_ENABLED(CONFIG_SECURITY_LOCKDOWN_LSM) ? 1 : 0) + \ + (IS_ENABLED(CONFIG_BPF_LSM) ? 1 : 0) + \ + (IS_ENABLED(CONFIG_SECURITY_LANDLOCK) ? 1 : 0)) + /* * These are descriptions of the reasons that can be passed to the * security_locked_down() LSM hook. Placing this array here allows @@ -245,6 +264,12 @@ static void __init initialize_lsm(struct lsm_info *lsm) } } +/* + * Current index to use while initializing the lsm id list. + */ +u32 lsm_active_cnt __ro_after_init; +const struct lsm_id *lsm_idlist[LSM_CONFIG_COUNT] __ro_after_init; + /* Populate ordered LSMs list from comma-separated LSM name list. */ static void __init ordered_lsm_parse(const char *order, const char *origin) { @@ -521,6 +546,18 @@ void __init security_add_hooks(struct security_hook_list *hooks, int count, { int i; + /* + * A security module may call security_add_hooks() more + * than once during initialization, and LSM initialization + * is serialized. Landlock is one such case. + * Look at the previous entry, if there is one, for duplication. + */ + if (lsm_active_cnt == 0 || lsm_idlist[lsm_active_cnt - 1] != lsmid) { + if (lsm_active_cnt >= LSM_CONFIG_COUNT) + panic("%s Too many LSMs registered.\n", __func__); + lsm_idlist[lsm_active_cnt++] = lsmid; + } + for (i = 0; i < count; i++) { hooks[i].lsmid = lsmid; hlist_add_tail_rcu(&hooks[i].list, hooks[i].head); -- 2.41.0