Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1635962pxb; Mon, 22 Feb 2021 07:10:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJxAz3HHjcNjQBCnnRkS0sBuBEdtmHGfAx6Z80qkmsRnVG5DJ86nn/4C2BeY5HTf/ctqQVZF X-Received: by 2002:a17:906:be9:: with SMTP id z9mr1500636ejg.35.1614006602038; Mon, 22 Feb 2021 07:10:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614006602; cv=none; d=google.com; s=arc-20160816; b=McLwLr+Y9g6xMrtPFcEma6F/doQTzyqmHULX7nTkapttQgMcbgofs7CkYkwY2MB4OT FVtPMy8xvDIyg6EdhvN29WXPcaIZFWwNP3LGzeYj9mhQgoz7PlX6AT0mGStFAERgNo/R PZrKKQtbN6xfHg26aoU4636MTgXHylM8j5NxmQyZSYTDlWmCL8zzIupMelPLqDgLY40k ohfYAbGOPh6blE/mBviHfZQy9i/R51aggkcedcduKMo8Ry8ES3X3Thus+fkrdAGvUCIS F4KcmDRk+XekVvuPIMWnxu80Sx7zQ1u0nhrNkgIHuDGRAwsxL4L/Z3cwmpbWzN4nJ6h6 7NCg== 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; bh=Vppa3O7BqyYSNZ0K651HZDNbQJj6G4eoXOz8Ck/p1LQ=; b=N+8x7HZzffhBNIhxeaAtWs+prnXXBPTFXrsGF9ARI8IlvIFQvUVEY8jCICgQNmNql1 IsFfuoLCsYTQkA/SDW6Z1PbjJi6o5dNrYZMbWO6hyDitvfCh+DZ999BvHCEgBRvLfhjd wIcUTX9QXaWCI2TtdDhqE5F9FP5zt6uE85nOpTjHCiCM9c9ooS+KtQOrc5BKbVqKjnNv +7PFaWj6No9wPHTSIyjCZ+UCSU7KfBHm5cbk/ShXYN52NKrtyv4NUVnBxBQaJG2zicVu 8rhbGr+SukV2sx/AJI5tYRpCzO6K64PMWb2aG94ziV7x/v5Fu+dTpzcIbUBgqvHJMxr2 WFhw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id du4si11996345ejc.53.2021.02.22.07.09.38; Mon, 22 Feb 2021 07:10:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230447AbhBVPGC (ORCPT + 99 others); Mon, 22 Feb 2021 10:06:02 -0500 Received: from smtp-42a9.mail.infomaniak.ch ([84.16.66.169]:53121 "EHLO smtp-42a9.mail.infomaniak.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230441AbhBVPFp (ORCPT ); Mon, 22 Feb 2021 10:05:45 -0500 Received: from smtp-2-0001.mail.infomaniak.ch (unknown [10.5.36.108]) by smtp-2-3000.mail.infomaniak.ch (Postfix) with ESMTPS id 4Dklpb3pLxzMppP0; Mon, 22 Feb 2021 16:04:55 +0100 (CET) Received: from localhost (unknown [23.97.221.149]) by smtp-2-0001.mail.infomaniak.ch (Postfix) with ESMTPA id 4Dklpb0tVvzlh8TH; Mon, 22 Feb 2021 16:04:55 +0100 (CET) From: =?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?= To: James Morris , "Serge E . Hallyn" Cc: =?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?= , Casey Schaufler , Kees Cook , linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org, =?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?= Subject: [PATCH v3 1/1] security: Add CONFIG_LSM_AUTO to handle default LSM stack ordering Date: Mon, 22 Feb 2021 16:06:08 +0100 Message-Id: <20210222150608.808146-2-mic@digikod.net> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210222150608.808146-1-mic@digikod.net> References: <20210222150608.808146-1-mic@digikod.net> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Mickaël Salaün Add a new option CONFIG_LSM_AUTO to enable users to delegate default LSM stacking order to kernel developers. This enable to keep a consistent order of enabled LSM when changing the LSM selection, especially when a new LSM is added to the kernel. CONFIG_LSM depends on !CONFIG_LSM_AUTO, which is backward compatible and gives the opportunity to users to select CONFIG_LSM_AUTO with a make oldconfig. CONFIG_LSM and CONFIG_LSM_AUTO depend on CONFIG_SECURITY, which makes sense because an LSM depends on the security framework. Cc: Casey Schaufler Cc: James Morris Cc: Kees Cook Cc: Serge E. Hallyn Signed-off-by: Mickaël Salaün Link: https://lore.kernel.org/r/20210222150608.808146-2-mic@digikod.net --- Changes since v2: * Revamp without virtual dependencies but a new option to automatically enable all selected LSMs. Changes since v1: * Add CONFIG_SECURITY as a dependency of CONFIG_LSM. This prevent an error when building without any LSMs. --- security/Kconfig | 19 +++++++++++++++++++ security/security.c | 26 +++++++++++++++++++++++++- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/security/Kconfig b/security/Kconfig index 7561f6f99f1d..fae083e9867d 100644 --- a/security/Kconfig +++ b/security/Kconfig @@ -243,6 +243,7 @@ source "security/integrity/Kconfig" choice prompt "First legacy 'major LSM' to be initialized" + depends on SECURITY default DEFAULT_SECURITY_SELINUX if SECURITY_SELINUX default DEFAULT_SECURITY_SMACK if SECURITY_SMACK default DEFAULT_SECURITY_TOMOYO if SECURITY_TOMOYO @@ -275,8 +276,26 @@ choice endchoice +config LSM_AUTO + bool "Automatically enable all selected LSMs at boot" + depends on SECURITY + default y + help + This automatically configure the build-time selected LSMs to be + enabled at boot unless the "lsm=" parameter is provided. + + If this option is not selected, it will be required to configure and + maintained a static list of enabled LSMs that may become inconsistent + with future user configuration. Indeed, this list will not be + automatically upgraded when selecting a new (future) LSM, e.g. with + make oldconfig. + + If you are unsure how to answer this question, answer Y. + +# This lists should be synchronized with LSM_ORDER defined in security/security.c . config LSM string "Ordered list of enabled LSMs" + depends on SECURITY && !LSM_AUTO default "lockdown,yama,loadpin,safesetid,integrity,smack,selinux,tomoyo,apparmor,bpf" if DEFAULT_SECURITY_SMACK default "lockdown,yama,loadpin,safesetid,integrity,apparmor,selinux,smack,tomoyo,bpf" if DEFAULT_SECURITY_APPARMOR default "lockdown,yama,loadpin,safesetid,integrity,tomoyo,bpf" if DEFAULT_SECURITY_TOMOYO diff --git a/security/security.c b/security/security.c index 401663b5b70e..defa1d2c40a3 100644 --- a/security/security.c +++ b/security/security.c @@ -82,7 +82,31 @@ static struct lsm_blob_sizes blob_sizes __lsm_ro_after_init; static __initdata const char *chosen_lsm_order; static __initdata const char *chosen_major_lsm; -static __initconst const char * const builtin_lsm_order = CONFIG_LSM; +#ifdef CONFIG_LSM +#define LSM_ORDER CONFIG_LSM +#else + +/* + * This lists should be synchronized with the default values of CONFIG_LSM + * defined in security/Kconfig . + */ +#define LSM_ORDER_PRE "lockdown,yama,loadpin,safesetid,integrity," + +#if defined(CONFIG_DEFAULT_SECURITY_SMACK) +#define LSM_ORDER LSM_ORDER_PRE "smack,selinux,tomoyo,apparmor,bpf" +#elif defined(CONFIG_DEFAULT_SECURITY_APPARMOR) +#define LSM_ORDER LSM_ORDER_PRE "apparmor,selinux,smack,tomoyo,bpf" +#elif defined(CONFIG_DEFAULT_SECURITY_TOMOYO) +#define LSM_ORDER LSM_ORDER_PRE "tomoyo,bpf" +#elif defined(CONFIG_DEFAULT_SECURITY_DAC) +#define LSM_ORDER LSM_ORDER_PRE "bpf" +#else +#define LSM_ORDER LSM_ORDER_PRE "selinux,smack,tomoyo,apparmor,bpf" +#endif + +#endif /* CONFIG_LSM */ + +static __initconst const char * const builtin_lsm_order = LSM_ORDER; /* Ordered list of LSMs to initialize. */ static __initdata struct lsm_info **ordered_lsms; -- 2.30.0