Received: by 2002:a05:6520:3645:b029:c0:f950:43e0 with SMTP id l5csp460894lki; Mon, 22 Feb 2021 10:32:50 -0800 (PST) X-Google-Smtp-Source: ABdhPJwlEu1tfjthIY8Oc6HyVsvZco3RroVWmOhBPuN0CoU0CyxXPeHIkt7CsdFYWZ6ivLYFo+CJ X-Received: by 2002:aa7:c80e:: with SMTP id a14mr10674226edt.295.1614018770407; Mon, 22 Feb 2021 10:32:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614018770; cv=none; d=google.com; s=arc-20160816; b=bJKXBrlN/SD0g1PIGivd4eIrwde8mxpUUJB+mjfiLnjb7eKl9rpPTvBdrJPU8wDzgU CBCyCfapaQ1S0EGl2pPL9d0IXBRSfv7d1RVSn33sXkKGaKLOazeDiGnNel3sx6N+V91X X4EDIJwTFwBwNjss+NwJdGn6VVE28kDwsb9ccQnvx19OEii3PlcxS+VrxmxOagqJtITi L9SoYW7+vDuR/DP7syXmzMrfe+TuxLXHhCXzN8Q4z0977H6wN9RITupn1qv7xJYSq9MB S+FJ3ZeVllGfpCtUGSkcB//HCNd1DaeberBXS4AiSAJtqZ5Sj/pXO03aK6qx4/ckDBbx l1cw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=+7BKYPH1EE/RIbSShTrlfkibD5oQ+oa+dKP+IpxaDKI=; b=DfFG21lGiCbydG/qUMtuwfKLO730t+s9oTWo6xEr+OJXodYqroQMF0LiQEJ7//YZqd JqcG/aYb3viHJOx6YZtNSGQGoO3ivwYEbcKgmhfHBIJXLtIH5YCzi5VEgPcHhCNM28ij Pk7sRnnbGquqVz5qB8XeHFf4E5gB83cBQgHxrxusj8jPO9Dd12dKB2i9UvNCR2WKV7AH ynpU1R18XCgGkS31Ioek8YF4VCYLhzJwlD0OCLbiiSJYpw45TXcWkApMR+N1lzs1khfC WugGh9KI3b68aD2e41jW4Ot5E+3cM6r/Ix1iDwKYbxYcMjdGGRAPJOAKXYF9BjjKyzMg bhaA== 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 q19si12458391edv.67.2021.02.22.10.32.26; Mon, 22 Feb 2021 10:32:50 -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 S231848AbhBVSbt (ORCPT + 99 others); Mon, 22 Feb 2021 13:31:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54792 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232756AbhBVSbg (ORCPT ); Mon, 22 Feb 2021 13:31:36 -0500 Received: from smtp-42af.mail.infomaniak.ch (smtp-42af.mail.infomaniak.ch [IPv6:2001:1600:3:17::42af]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 98E3FC06174A for ; Mon, 22 Feb 2021 10:30:44 -0800 (PST) Received: from smtp-2-0000.mail.infomaniak.ch (unknown [10.5.36.107]) by smtp-2-3000.mail.infomaniak.ch (Postfix) with ESMTPS id 4DkrN30fH2zMqDYj; Mon, 22 Feb 2021 19:30:43 +0100 (CET) Received: from ns3096276.ip-94-23-54.eu (unknown [23.97.221.149]) by smtp-2-0000.mail.infomaniak.ch (Postfix) with ESMTPA id 4DkrN14dNkzlppyp; Mon, 22 Feb 2021 19:30:41 +0100 (CET) Subject: Re: [PATCH v3 1/1] security: Add CONFIG_LSM_AUTO to handle default LSM stack ordering To: Casey Schaufler , James Morris , "Serge E . Hallyn" Cc: Kees Cook , linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org, =?UTF-8?Q?Micka=c3=abl_Sala=c3=bcn?= References: <20210222150608.808146-1-mic@digikod.net> <20210222150608.808146-2-mic@digikod.net> <51725b44-bc40-0205-8583-285d3b35b5ca@schaufler-ca.com> From: =?UTF-8?Q?Micka=c3=abl_Sala=c3=bcn?= Message-ID: Date: Mon, 22 Feb 2021 19:31:58 +0100 User-Agent: MIME-Version: 1.0 In-Reply-To: <51725b44-bc40-0205-8583-285d3b35b5ca@schaufler-ca.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 22/02/2021 17:51, Casey Schaufler wrote: > On 2/22/2021 7:06 AM, Mickaël Salaün wrote: >> 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. > > TL;DR - NAK > > Do you think that we might have considered this when stacking was > introduced? I didn't dig the detailed history of LSM stacking, but you are in Cc because I know that you know. I may have though that the main goal of the current LSM stacking implementation was to enable to stack existing LSMs, which works well with this CONFIG_LSM list, but doesn't work as well for new LSMs. > Did you even consider the implications before sending > the patch? Yes, and it doesn't change much the current behavior without user interaction. However, it gives the choice to users to choose how they want their configuration to evolve. > This only makes any sense if you want to compile in > AppArmor and/or Smack but always use SELinux. The existing Kconfig > model handles that perfectly well. This patch series doesn't change this behavior if the user doesn't want it to change. > Also, this will break when the > next phase of module stacking comes in, and all of a sudden > systems will automatically get AppArmor in addition to SELinux > or Smack. What is the next phase of module stacking? What would be the consequences? Systems will only get new LSMs if their configuration said so, either from Kconfig or from boot arguments. I think we should make easier to have a working, consistent and secure kernel configuration by default. If users want to have a non-default configuration, that's fine, fully supported, and they can do it. > > I know that the CONFIG_LSM/lsm= mechanism is clumsy. But we spent > about a year discussing, proposing and implementing alternatives, > and if there's a better mechanism, we couldn't find it. Of course > we considered "just use the kernel order". This is indeed the intent of this patch, but this configuration is optional. > It doesn't work for generic kernels. Why? Generic kernels can be configured with CONFIG_LSM or with CONFIG_LSM_AUTO. I agree that generic distros may want to not enable major LSMs such as SELinux, AppArmor, Smack and Tomoyo by default but support them in their generic kernel anyway to let users pick and configure an LSM thanks to the boot arguments, and that's totally fine. Moreover, distro maintainers will surely browse most of new options to identify if it is the best choice for their distro. The *default* choice (for LSMs enabled at boot) is in the hand of users configuring their kernel, and they are in the best position to choose if they want to follow new kernel options and their consequences (e.g. distro kernel maintainers, whose job is to follow kernel development), or to have an easier way to maintain an up-to-date kernel (e.g. sysadmins or hobbyists, who may not have so much time dedicated to follow kernel developments). > I understand that adding a new LSM that you want > to be included by default is a tough problem. I also suggest > that silently adding an LSM to an existing configuration is likely > to violate the principle of least astonishment. Nothing is silently added to the user configuration with this patch. It is an optional (default) configuration, which I think makes more sense for users not expert in every kernel toggles. > >> >> 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; >