Received: by 2002:a05:6358:51dd:b0:131:369:b2a3 with SMTP id 29csp1291407rwl; Thu, 10 Aug 2023 09:03:42 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHIoeMhLzT35J717T3a5BMZJa40ytnP1BZhJFEJH+fJ47LtquO27/mD1k9UbaXoqOqWd+d+ X-Received: by 2002:aa7:88c3:0:b0:667:d0ff:6a0f with SMTP id k3-20020aa788c3000000b00667d0ff6a0fmr3362278pff.5.1691683421726; Thu, 10 Aug 2023 09:03:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691683421; cv=none; d=google.com; s=arc-20160816; b=MC2JMBMFmaSRkcsPSxbYMXJ4M4yagUPpQGXhwGgFV9ApoDf8RzTrgaJZGnFzwLP3Fl 2tjNNdg85dQhDIQ3nwH6mvjZNmAGbBAIWAG75xwlyyiUDNFI+nesJaZKbAWzZu+PwD9j sXl0h+2PvJkTfdpIC6dMEijd3JRyP7PbKHIE99bKZ2y6XyJZcFYynkHmlkCpGvu4i1cW OIWO0vjLkup8tqxQPIhL+NwJIORqT4vlARRG93IpVVYfrKYHvsR368q/8c3G05yE4voJ C0ppycd9grJfuK16cM3EhobBDl+2Yq+/1wDW2rHVW2We8bs/iQa+1zd8RMhdERGwA2/x H/rQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :organization:from:references:cc:to:content-language:subject :user-agent:mime-version:date:message-id:dkim-signature; bh=X3c2GGn/eSUQZahV8jMYvTZLbSX/dn6AUwnI9IP7Nws=; fh=H2bQjOQaozSh++KJznqJDYqt+EgZjr0JtjYjnFnraSM=; b=sj1a3PjF56/fFMc0hmb06oelUAy3SbTf8LSSekDbB3ny39L0i609dI8YsbQ7UxwC0s EBKFSoHgS1P06QFvlDEn3f4X0O5GFWEFc0mo8y7SqnHlZeQofOTrPsWGY6OLtjpo+8Se bANhIi+YbeW69k9zJdCRNrYYCFVnoIOhBsfKHTPC1rby8Dc8vGBlZXKy347QKdcI5des JxrYPT4hNM8xZYw/WZTosygxjhO+fWxDaluOa/aJpsx5cl00e+ub70q8DlGR7nWZuduU OCrv2hnqab2UBP3XmWvpbrPPDZPvmc9o/L2aTbyayQBwdOz3wzJ0eUjSsoJp2uWJTn1g xwcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@canonical.com header.s=20210705 header.b=Bi1OMg8t; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s9-20020a637709000000b0056531bfc660si1833273pgc.143.2023.08.10.09.03.13; Thu, 10 Aug 2023 09:03:41 -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=@canonical.com header.s=20210705 header.b=Bi1OMg8t; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236268AbjHJPyn (ORCPT + 99 others); Thu, 10 Aug 2023 11:54:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42604 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236281AbjHJPyi (ORCPT ); Thu, 10 Aug 2023 11:54:38 -0400 Received: from smtp-relay-canonical-1.canonical.com (smtp-relay-canonical-1.canonical.com [185.125.188.121]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E422D2D65; Thu, 10 Aug 2023 08:54:35 -0700 (PDT) Received: from [192.168.192.83] (unknown [50.47.134.245]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by smtp-relay-canonical-1.canonical.com (Postfix) with ESMTPSA id DE1123F5DF; Thu, 10 Aug 2023 15:54:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1691682874; bh=X3c2GGn/eSUQZahV8jMYvTZLbSX/dn6AUwnI9IP7Nws=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=Bi1OMg8tQRhRtRzOmp8DcH3gMlpCFAsdSHE4YQ8a+v7VMEs3lfVOVLsWyEVCrsDjv XC9mHBCD8iQl5KlOGNMDF3zylymzSsFyynIoqyTY9VVw37sOIKupayHCtYwcgOLBE5 nvhd3E3S13vhkcE4vL4UQ/NRVWXO+HEjuILa2vnrjx4BjrVVy+1NqmFuowdu9jHTZl KkbKQxHbKGir7hYirONpqa+ba247k6nFja8ni+uiqj7+jpgfFJF4IZ9gHa/i3Zaf+k yND6sub7m32od2jUUKTG1xt0hoPaBZ0jIcezYCvHkdKGMXMzgh0Acg7LN3NSzqtUA4 V+g2DDgFSgoig== Message-ID: Date: Thu, 10 Aug 2023 08:54:30 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Subject: Re: [PATCH v13 02/11] LSM: Maintain a table of LSM attribute data Content-Language: en-US To: Casey Schaufler , paul@paul-moore.com, linux-security-module@vger.kernel.org Cc: jmorris@namei.org, serge@hallyn.com, keescook@chromium.org, 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 References: <20230802174435.11928-1-casey@schaufler-ca.com> <20230802174435.11928-3-casey@schaufler-ca.com> From: John Johansen Organization: Canonical In-Reply-To: <20230802174435.11928-3-casey@schaufler-ca.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham 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 On 8/2/23 10:44, Casey Schaufler wrote: > 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 Reviewed-by: John Johansen > --- > 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);