Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp595898imu; Mon, 26 Nov 2018 15:32:31 -0800 (PST) X-Google-Smtp-Source: AFSGD/UTUsbTwcYXBX8oXpKuEO6IPj262Fc4JnPwCY8APkogw0aXw0H6HrZof+4HJ4hpCcFpUwC2 X-Received: by 2002:a17:902:a710:: with SMTP id w16mr29448905plq.95.1543275151408; Mon, 26 Nov 2018 15:32:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543275151; cv=none; d=google.com; s=arc-20160816; b=PqzUC0biBWwZ3DkKBuflPlYK2W1EIfkh3NCvC5ebdCOQZhea68OoQPYZo75gRwIRwQ 2IaCe+PIXEnI7jiLEJKHE+9R5zo651ECwhvn8oRatJ2bwqGNYP5KNQrKDy0ZW1DrWTms oIJwyS49w+mrGqUSKxS0wd2gFAvQTSFNxL4KCp06mVNJMRWrs1fK3NyzXIdXdkEcdJVg /2OHvoSnsgbxpjd5YQX1CLymih58DMPRHsNWQwJb049yMcAgDScR127pIGkddjtEjJKS GgWL2OaPdZ9LXIUcmU4kSwceCIPsR8faYk6IupBCAq9D/Xwg13kxFnZKL6evxnlqwwsN nv2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=fMPrSb+dmaLWXhRA4kL8eUvonseX5wD/nHNn/Azz/o8=; b=B/51R7h20SL6S/lzG/pwUTGccZxpqbA/455ECLEYHAdQg4nmVAU8iszFh4pginX2oC UPlVBNEiGdM6UwYbbGuOXh0xielTKQHJqrc/nNOtvnVlrVL2wGGHnWFmSJoK8rZuAufs E+FKCqvj2YEFo4GHXeSPflmTibhntEefc/rwLjPWTQdHK5+eudBLZABrbOSV8zrFcTJv VmDRBYnJDAMbjhW5ae3++tTgfr6r8rTPrqbkuy+m/pVfN4J9ny71EbzOn7CXJubdy9A+ UuSGsclPpUuFKqCrJw3i3NH86PuJXUvbBMk5Z6rdsyMpXa0ISy6QpzVQCuIYBaw+HOBK lKJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@yahoo.com header.s=s2048 header.b=i4KRo80P; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p8si1661655pls.83.2018.11.26.15.32.16; Mon, 26 Nov 2018 15:32:31 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@yahoo.com header.s=s2048 header.b=i4KRo80P; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727740AbeK0K0Q (ORCPT + 99 others); Tue, 27 Nov 2018 05:26:16 -0500 Received: from sonic302-28.consmr.mail.ne1.yahoo.com ([66.163.186.154]:42185 "EHLO sonic302-28.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727649AbeK0K0Q (ORCPT ); Tue, 27 Nov 2018 05:26:16 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1543275029; bh=fMPrSb+dmaLWXhRA4kL8eUvonseX5wD/nHNn/Azz/o8=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From:Subject; b=i4KRo80PEW+S0nkB0oAcXA96KqkgwJmwcRN2Q36g2taRGDNW969JMkm0qIQ76VT1PqrcZhvZ7j/ExxEovZDP9YzFaK3anc5hUviwaYGNBK+vPVx3oZjZUOQ4HsT71kAiQx5eOLbaB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lU8h3kwaekTkNBb2D562Wwgh1Aij_x3D2_hQa 5H6piJtCfajphb0YgiD7DACoJcyJAoxOTRv3..nmIpnfW0P37BOwDMgekJYNBFhkzOxjeEcGIfs. MJrhrSb9l.OPaEhzdbMks3x.59MWaTjzmSSItFkhtzdkcGPyNEigvZ_Y5RWej5xvgOxwtIhOKj6W i5XVFkD7ihWoa4HLJjEKRHXHwhrFPmaLOnLA_B6Bw.KmxSSj73ueT8DvsmEEzneOYHgp2Mopd9NH d7a9_KKC9oudn_H2EI9y6pbm_E8Wz Received: from sonic.gate.mail.ne1.yahoo.com by sonic302.consmr.mail.ne1.yahoo.com with HTTP; Mon, 26 Nov 2018 23:30:29 +0000 Received: from c-67-169-65-224.hsd1.ca.comcast.net (EHLO [192.168.0.105]) ([67.169.65.224]) by smtp418.mail.ne1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 8b6410a7d9dc669a9c778bff1b9412de; Mon, 26 Nov 2018 23:30:26 +0000 (UTC) Subject: [PATCH v5 05/38] LSM: Build ordered list of LSMs to initialize To: James Morris , LSM , LKLM , SE Linux Cc: John Johansen , Kees Cook , Tetsuo Handa , Paul Moore , "linux-fsdevel@vger.kernel.org" , Stephen Smalley , Alexey Dobriyan , =?UTF-8?Q?Micka=c3=abl_Sala=c3=bcn?= , Salvatore Mesoraca References: <50db058a-7dde-441b-a7f9-f6837fe8b69f@schaufler-ca.com> From: Casey Schaufler Message-ID: Date: Mon, 26 Nov 2018 15:30:24 -0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <50db058a-7dde-441b-a7f9-f6837fe8b69f@schaufler-ca.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This constructs an ordered list of LSMs to initialize, using a hard-coded list of only "integrity": minor LSMs continue to have direct hook calls, and major LSMs continue to initialize separately. Signed-off-by: Kees Cook Reviewed-by: Casey Schaufler --- security/security.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 53 insertions(+), 5 deletions(-) diff --git a/security/security.c b/security/security.c index 7562da854b62..4c193aba4531 100644 --- a/security/security.c +++ b/security/security.c @@ -37,6 +37,9 @@ /* Maximum number of letters for an LSM name string */ #define SECURITY_NAME_MAX 10 +/* How many LSMs were built into the kernel? */ +#define LSM_COUNT (__end_lsm_info - __start_lsm_info) + struct security_hook_heads security_hook_heads __lsm_ro_after_init; static ATOMIC_NOTIFIER_HEAD(lsm_notifier_chain); @@ -45,6 +48,9 @@ char *lsm_names; static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] = CONFIG_DEFAULT_SECURITY; +/* Ordered list of LSMs to initialize. */ +static __initdata struct lsm_info **ordered_lsms; + static __initdata bool debug; #define init_debug(...) \ do { \ @@ -85,6 +91,34 @@ static void __init set_enabled(struct lsm_info *lsm, bool enabled) } } +/* Is an LSM already listed in the ordered LSMs list? */ +static bool __init exists_ordered_lsm(struct lsm_info *lsm) +{ + struct lsm_info **check; + + for (check = ordered_lsms; *check; check++) + if (*check == lsm) + return true; + + return false; +} + +/* Append an LSM to the list of ordered LSMs to initialize. */ +static int last_lsm __initdata; +static void __init append_ordered_lsm(struct lsm_info *lsm, const char *from) +{ + /* Ignore duplicate selections. */ + if (exists_ordered_lsm(lsm)) + return; + + if (WARN(last_lsm == LSM_COUNT, "%s: out of LSM slots!?\n", from)) + return; + + ordered_lsms[last_lsm++] = lsm; + init_debug("%s ordering: %s (%sabled)\n", from, lsm->name, + is_enabled(lsm) ? "en" : "dis"); +} + /* Is an LSM allowed to be initialized? */ static bool __init lsm_allowed(struct lsm_info *lsm) { @@ -121,18 +155,32 @@ static void __init maybe_initialize_lsm(struct lsm_info *lsm) } } -static void __init ordered_lsm_init(void) +/* Populate ordered LSMs list from single LSM name. */ +static void __init ordered_lsm_parse(const char *order, const char *origin) { struct lsm_info *lsm; for (lsm = __start_lsm_info; lsm < __end_lsm_info; lsm++) { - if ((lsm->flags & LSM_FLAG_LEGACY_MAJOR) != 0) - continue; - - maybe_initialize_lsm(lsm); + if (strcmp(lsm->name, order) == 0) + append_ordered_lsm(lsm, origin); } } +static void __init ordered_lsm_init(void) +{ + struct lsm_info **lsm; + + ordered_lsms = kcalloc(LSM_COUNT + 1, sizeof(*ordered_lsms), + GFP_KERNEL); + + ordered_lsm_parse("integrity", "builtin"); + + for (lsm = ordered_lsms; *lsm; lsm++) + maybe_initialize_lsm(*lsm); + + kfree(ordered_lsms); +} + static void __init major_lsm_init(void) { struct lsm_info *lsm; -- 2.14.5