Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2944965rwd; Fri, 16 Jun 2023 10:07:01 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ40LqFpegk7m66Gyu8oLQ6HashwvHM3OtKaOT9JRmYtbrmo01dGmOrV5RT6N9rUrSVDgwnF X-Received: by 2002:a17:902:ab54:b0:1ae:8e58:eb25 with SMTP id ij20-20020a170902ab5400b001ae8e58eb25mr2274226plb.28.1686935221245; Fri, 16 Jun 2023 10:07:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686935221; cv=none; d=google.com; s=arc-20160816; b=lyXrdmPFC7Wxbiv+qEZf9zO6FHxhLrhorCMogeWH9iH7BUn94kWVf2R3K7KC2ZJKiP f4wN2n/M5tUD4WQGqucLb2ldRUfH9xDgvwjuvGl+umnqRvKeEFBHiwF9xr5b2q0AWzsR 0WKmbJACD4x3gtq69x8vuB5C5Y4jtwJW+XfIT/1TUhfhs38fX71KDhsR+5urELLkqezk wnJkjay1ug2Sz6e2o+OJy3SIaJn59XUH/SH2LY+FoVEb/nLu6eV9p2yx5DCe12Pt7NrE rsjEhc3XR45k44np93jvozZhyos/gChfUzjwOJiQAWlTP6Uk6izh84V6NIl2lD4lgRNf ZOfg== 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=hommsA3BOKWH8JPrcSGmlsvcDXkkKM3xWdtpA/dVKf4=; b=rLl1yfRiLlHymxWi6aeeDGgMfWrioJwOu59qJ53e/2Lq4R0JJxAOlJVYN6bw8Jj93f lkIgc5zn33Y3GdXmMoSrFjKBtYotSu1PnZCKenxLIeAaOb/31XUaj+j2Nj+DIhoDW+f7 NHdYh/JOLIJ+CZnMfTn9RdvQUwjNHEF3bGyLMDGy6qJzmacZ0KZZg+pYLWAK94WcJ7+X iWLLpRXj5hMYP6Az6UZZFJvIGH2i657GrzoJK8zB4HxuSb6ioiz7b4P2DQ59j6PcllO1 gKTzOF1vSikySbsrfU2xrlDztBV1CpHrcM6Q2v2KUql3VuT677dG+JDkJ08GyGXXC8sQ FTpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@yahoo.com header.s=s2048 header.b="Pn/vnY0+"; 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 m11-20020a170902f20b00b001b52ca9f711si1798947plc.585.2023.06.16.10.06.49; Fri, 16 Jun 2023 10:07:01 -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="Pn/vnY0+"; 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 S1345565AbjFPQvZ (ORCPT + 99 others); Fri, 16 Jun 2023 12:51:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37264 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344993AbjFPQvN (ORCPT ); Fri, 16 Jun 2023 12:51:13 -0400 Received: from sonic313-14.consmr.mail.ne1.yahoo.com (sonic313-14.consmr.mail.ne1.yahoo.com [66.163.185.37]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B660F3593 for ; Fri, 16 Jun 2023 09:51:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1686934264; bh=hommsA3BOKWH8JPrcSGmlsvcDXkkKM3xWdtpA/dVKf4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=Pn/vnY0+uG5t9Ag4oOmqOIhBpc6yq4/6RmCcUqgLRFOCfipDcosS6dMp4sVX8t14v0B1hf3BnJHrVqrOovRE5svCuXI25qNRoUxW+egTaGcEdR2xO+aVOpkp/PAm6uUvTSFoAHMvF5nzVVgliVyuD4faDekkH0nYjxCSA7GMc3RQ+kb1NE355O7MlDkrszq0OqgCWMi0puEAgdFl49FT9m9+UKsvDchVTSXu7EGiQYiVoWpCL0ZlEAodsILeUVs7W+5I4Tatg5Nj14bwbuBGnoH7qMwqSKhMjduz7H0fMwEvyqF5FPA0jVFm6xERjgHn7ORu0y00VK/2aC22oG95Mw== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1686934264; bh=hhCwww0P+VUEB7CgtXYOeaqiKmrYtJmfDukbl2sYzhX=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=qK0itaXv8pUws/vHzImGZhUp3mg0cw2rV2TcVLnQICFFy79JYalAZi6vt3vW8/8BdCsXeaKPntzdwO+zKAfltGdXD6S7IVbprx+VdszGdvidojFbBUIXcAvmfW+vy1I+X8iTrgNYH38gAqF5ONvwvj2OprAmqCGHVbKWYqTBZu2tFQxeF7T6s95VdSJqKJJ5LMYQEf+lmmhWB8uLzkjPr3Mz894ybZxZAckdmdMlhH8JvP2qHKnPdP164hFxxJ7s4v2GCnngLRKeDDszrrUC8yNAXpZpKsZsuAsfLj6m0LJ4Kx6ZzSv8DkJLuLDwoxkrYSbQ5p0SN7u0fBPoLE+Fyg== X-YMail-OSG: aFLgZj8VM1lE.dZ6WhidqFrc84AZbm_cJZloUYl7MKO8cvfnq9qhXCHos8.VEoD fW8f39IxPeChYkuSsUrcmY695InR66xBHYsyeJ1pd5cdLKSnSzbAVHphfxxyARVxpQVnV5_Y3HQo bW8PV7czqMNhW4EKMvqeEcvcqDgSySx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dg46iXLEpoGI9kQQnWpJkpy3fJiq8lhMvK4HfQ NE066TeL7QuUBhio- X-Sonic-MF: X-Sonic-ID: 6763a677-41eb-4da2-9e44-5040b023e185 Received: from sonic.gate.mail.ne1.yahoo.com by sonic313.consmr.mail.ne1.yahoo.com with HTTP; Fri, 16 Jun 2023 16:51:04 +0000 Received: by hermes--production-ne1-574d4b7954-tvjss (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID b70d58d7ec5b436008cc3a1dab4c00b9; Fri, 16 Jun 2023 16:51:01 +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 v11 02/11] LSM: Maintain a table of LSM attribute data Date: Fri, 16 Jun 2023 09:50:46 -0700 Message-Id: <20230616165055.4705-3-casey@schaufler-ca.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230616165055.4705-1-casey@schaufler-ca.com> References: <20230616165055.4705-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,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE 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 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 | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/include/linux/security.h b/include/linux/security.h index e2734e9e44d5..569b1d8ab002 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 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 e56714ef045a..39c5225603cf 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; +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,17 @@ void __init security_add_hooks(struct security_hook_list *hooks, int count, { int i; + if (lsm_active_cnt >= LSM_CONFIG_COUNT) + panic("%s Too many LSMs registered.\n", __func__); + /* + * 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) + 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.40.1