Message ID | 20230303182602.1088032-1-roberto.sassu@huaweicloud.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp562420wrd; Fri, 3 Mar 2023 10:28:48 -0800 (PST) X-Google-Smtp-Source: AK7set9Q9rPOfZZAUkQ/K1KTKGukdtlt3DBSgsSqrOnTOGrzjQ5j7DBfksv/EGHTK6aTVmmN4piQ X-Received: by 2002:a05:6a20:3947:b0:c7:1bae:876e with SMTP id r7-20020a056a20394700b000c71bae876emr3444674pzg.36.1677868127739; Fri, 03 Mar 2023 10:28:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677868127; cv=none; d=google.com; s=arc-20160816; b=r+4m1pf/d3clNFmA8OhqJMo3XvaSMvhopxvwrMhktQIjVLaVHiZgXl7E5qFIhn0OKx lYF8zJEg3FL+62mnnYiAFXO7dmtAMmyChoHmufwvYzbPEaiDaT2/6dTxU1eBNBp1/9Fg POQ/I9Ii3laRPffoeVqaMp8Dri0c8zsq8IzBp+94FrjiN0gitRjtpjN+auXFnySiwQGr d4gJMnFzYQWoR4etf0B8Kf+3rCrcxYmWytI1jXADa764KbO+b7vOnhi/sDiahTkpgMtn A2Mcsi8L0FV3cmEKfFXfEA/dhPraufMFlgfem3MIpXUJsuipZbldoUHmzBiCA0zCI398 Td2Q== 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=rzL2Y/AczM6NS5BTDePoIRj7uk2qGlzJicuDGEB37SA=; b=Prg4ATyjzrHPfJvmlAJ4/wWvVTC23jEqZQ4WfyiaKP5M8RJxVH6FLQ8K5PyhtclyGF qZVFhZa+a7xNGgctuGwwM+uzZly/Tcpcd617fEcwn88Wv/jN2+COvCZMiOqJzxaB2PDW 0SQAh75583aeWAwIL57nMFFGqU/8h13aIpdivSDVtvjz/FxJibgSUFNWJATEiq7Tt430 dDOjKsiGN8FCFnw8Z9npvY7GKq5hcADuHRltTUAx6bWlAluS7HTj+k82Kv09HcKX56Hu 8ygmirpZRJSaxYoNl38Ah6w7gf8P2X5TW7pJQ6/wuJMRkKVFpHCRaXLS7vTLm9zxeLBI QoVA== ARC-Authentication-Results: i=1; mx.google.com; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 123-20020a620581000000b005dd190cfc54si2507592pff.349.2023.03.03.10.28.33; Fri, 03 Mar 2023 10:28:47 -0800 (PST) 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; 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 S231694AbjCCS2L (ORCPT <rfc822;davidbtadokoro@gmail.com> + 99 others); Fri, 3 Mar 2023 13:28:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51128 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231684AbjCCS2J (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 3 Mar 2023 13:28:09 -0500 Received: from frasgout12.his.huawei.com (frasgout12.his.huawei.com [14.137.139.154]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C48A1124; Fri, 3 Mar 2023 10:28:02 -0800 (PST) Received: from mail02.huawei.com (unknown [172.18.147.227]) by frasgout12.his.huawei.com (SkyGuard) with ESMTP id 4PSx7H2YjJz9v7Yb; Sat, 4 Mar 2023 02:18:51 +0800 (CST) Received: from huaweicloud.com (unknown [10.204.63.22]) by APP1 (Coremail) with SMTP id LxC2BwCHCAQOPAJkKY9rAQ--.12963S2; Fri, 03 Mar 2023 19:27:38 +0100 (CET) From: Roberto Sassu <roberto.sassu@huaweicloud.com> To: viro@zeniv.linux.org.uk, chuck.lever@oracle.com, jlayton@kernel.org, zohar@linux.ibm.com, dmitry.kasatkin@gmail.com, paul@paul-moore.com, jmorris@namei.org, serge@hallyn.com, dhowells@redhat.com, jarkko@kernel.org, stephen.smalley.work@gmail.com, eparis@parisplace.org, casey@schaufler-ca.com, brauner@kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org, keyrings@vger.kernel.org, selinux@vger.kernel.org, linux-kernel@vger.kernel.org, stefanb@linux.ibm.com, Roberto Sassu <roberto.sassu@huawei.com> Subject: [PATCH 23/28] security: Introduce LSM_ORDER_LAST Date: Fri, 3 Mar 2023 19:25:57 +0100 Message-Id: <20230303182602.1088032-1-roberto.sassu@huaweicloud.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230303181842.1087717-1-roberto.sassu@huaweicloud.com> References: <20230303181842.1087717-1-roberto.sassu@huaweicloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: LxC2BwCHCAQOPAJkKY9rAQ--.12963S2 X-Coremail-Antispam: 1UD129KBjvJXoW7KFyUXr4xKr1DCry3Cr15Arb_yoW8ZFy8pa yDtFWfGr40yFyrWw1DAanxK3W8J395Ca4UGFWDWw1UXa9aqry0yr43Cr1S9ryDXF9rAFyI 9FW2vw4Skw1DZaDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUvab4IE77IF4wAFF20E14v26ryj6rWUM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4 vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Xr0_Ar1l84ACjcxK6xIIjxv20xvEc7Cj xVAFwI0_Cr1j6rxdM28EF7xvwVC2z280aVAFwI0_Cr0_Gr1UM28EF7xvwVC2z280aVCY1x 0267AKxVW0oVCq3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG 6I80ewAv7VC0I7IYx2IY67AKxVWUGVWUXwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFV Cjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JM4IIrI8v6xkF7I0E8cxan2IY04v7MxkF7I0E n4kS14v26r4a6rW5MxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I 0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVW8 ZVWrXwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26ryj6F1UMIIF0xvE2Ix0cI8IcV CY1x0267AKxVWxJr0_GcWlIxAIcVCF04k26cxKx2IYs7xG6Fyj6rWUJwCI42IY6I8E87Iv 67AKxVWxJVW8Jr1lIxAIcVC2z280aVCY1x0267AKxVW0oVCq3bIYCTnIWIevJa73UjIFyT uYvjxUxo7KDUUUU X-CM-SenderInfo: purev21wro2thvvxqx5xdzvxpfor3voofrz/1tbiAgAFBF1jj4YvgAAAsb X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_NONE 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759372249517809061?= X-GMAIL-MSGID: =?utf-8?q?1759372249517809061?= |
Series |
security: Move IMA and EVM to the LSM infrastructure
|
|
Commit Message
Roberto Sassu
March 3, 2023, 6:25 p.m. UTC
From: Roberto Sassu <roberto.sassu@huawei.com> Introduce LSM_ORDER_LAST, to satisfy the requirement of LSMs willing to be the last, e.g. the 'integrity' LSM, without changing the kernel command line or configuration. As for LSM_ORDER_FIRST, LSMs with LSM_ORDER_LAST are always enabled and put at the end of the LSM list in no particular order. Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com> --- include/linux/lsm_hooks.h | 1 + security/security.c | 12 +++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-)
Comments
On 3/3/23 13:25, Roberto Sassu wrote: > From: Roberto Sassu <roberto.sassu@huawei.com> > > Introduce LSM_ORDER_LAST, to satisfy the requirement of LSMs willing to be > the last, e.g. the 'integrity' LSM, without changing the kernel command > line or configuration. > > As for LSM_ORDER_FIRST, LSMs with LSM_ORDER_LAST are always enabled and put > at the end of the LSM list in no particular order. > I think you should describe the reason for the change for LSM_ORDER_MUTABLE as well. > Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com> > --- > include/linux/lsm_hooks.h | 1 + > security/security.c | 12 +++++++++--- > 2 files changed, 10 insertions(+), 3 deletions(-) > > diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h > index 21a8ce23108..05c4b831d99 100644 > --- a/include/linux/lsm_hooks.h > +++ b/include/linux/lsm_hooks.h > @@ -93,6 +93,7 @@ extern void security_add_hooks(struct security_hook_list *hooks, int count, > enum lsm_order { > LSM_ORDER_FIRST = -1, /* This is only for capabilities. */ > LSM_ORDER_MUTABLE = 0, > + LSM_ORDER_LAST = 1, > }; > > struct lsm_info { > diff --git a/security/security.c b/security/security.c > index 322090a50cd..24f52ba3218 100644 > --- a/security/security.c > +++ b/security/security.c > @@ -284,9 +284,9 @@ static void __init ordered_lsm_parse(const char *order, const char *origin) > bool found = false; > > for (lsm = __start_lsm_info; lsm < __end_lsm_info; lsm++) { > - if (lsm->order == LSM_ORDER_MUTABLE && > - strcmp(lsm->name, name) == 0) { > - append_ordered_lsm(lsm, origin); > + if (strcmp(lsm->name, name) == 0) { > + if (lsm->order == LSM_ORDER_MUTABLE) > + append_ordered_lsm(lsm, origin); > found = true; > } > } > @@ -306,6 +306,12 @@ static void __init ordered_lsm_parse(const char *order, const char *origin) > } > } > > + /* LSM_ORDER_LAST is always last. */ > + for (lsm = __start_lsm_info; lsm < __end_lsm_info; lsm++) { > + if (lsm->order == LSM_ORDER_LAST) > + append_ordered_lsm(lsm, " last"); > + } > + > /* Disable all LSMs not in the ordered list. */ > for (lsm = __start_lsm_info; lsm < __end_lsm_info; lsm++) { > if (exists_ordered_lsm(lsm))
On Tue, 2023-03-07 at 13:04 -0500, Stefan Berger wrote: > > On 3/3/23 13:25, Roberto Sassu wrote: > > From: Roberto Sassu <roberto.sassu@huawei.com> > > > > Introduce LSM_ORDER_LAST, to satisfy the requirement of LSMs willing to be > > the last, e.g. the 'integrity' LSM, without changing the kernel command > > line or configuration. > > > > As for LSM_ORDER_FIRST, LSMs with LSM_ORDER_LAST are always enabled and put > > at the end of the LSM list in no particular order. > > > > I think you should describe the reason for the change for LSM_ORDER_MUTABLE as well. Right. Thanks Roberto > > Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com> > > --- > > include/linux/lsm_hooks.h | 1 + > > security/security.c | 12 +++++++++--- > > 2 files changed, 10 insertions(+), 3 deletions(-) > > > > diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h > > index 21a8ce23108..05c4b831d99 100644 > > --- a/include/linux/lsm_hooks.h > > +++ b/include/linux/lsm_hooks.h > > @@ -93,6 +93,7 @@ extern void security_add_hooks(struct security_hook_list *hooks, int count, > > enum lsm_order { > > LSM_ORDER_FIRST = -1, /* This is only for capabilities. */ > > LSM_ORDER_MUTABLE = 0, > > + LSM_ORDER_LAST = 1, > > }; > > > > struct lsm_info { > > diff --git a/security/security.c b/security/security.c > > index 322090a50cd..24f52ba3218 100644 > > --- a/security/security.c > > +++ b/security/security.c > > @@ -284,9 +284,9 @@ static void __init ordered_lsm_parse(const char *order, const char *origin) > > bool found = false; > > > > for (lsm = __start_lsm_info; lsm < __end_lsm_info; lsm++) { > > - if (lsm->order == LSM_ORDER_MUTABLE && > > - strcmp(lsm->name, name) == 0) { > > - append_ordered_lsm(lsm, origin); > > + if (strcmp(lsm->name, name) == 0) { > > + if (lsm->order == LSM_ORDER_MUTABLE) > > + append_ordered_lsm(lsm, origin); > > found = true; > > } > > } > > @@ -306,6 +306,12 @@ static void __init ordered_lsm_parse(const char *order, const char *origin) > > } > > } > > > > + /* LSM_ORDER_LAST is always last. */ > > + for (lsm = __start_lsm_info; lsm < __end_lsm_info; lsm++) { > > + if (lsm->order == LSM_ORDER_LAST) > > + append_ordered_lsm(lsm, " last"); > > + } > > + > > /* Disable all LSMs not in the ordered list. */ > > for (lsm = __start_lsm_info; lsm < __end_lsm_info; lsm++) { > > if (exists_ordered_lsm(lsm))
Hi Roberto, On Fri, 2023-03-03 at 19:25 +0100, Roberto Sassu wrote: > From: Roberto Sassu <roberto.sassu@huawei.com> > > Introduce LSM_ORDER_LAST, to satisfy the requirement of LSMs willing to be > the last, e.g. the 'integrity' LSM, without changing the kernel command > line or configuration. Please reframe this as a bug fix for 79f7865d844c ("LSM: Introduce "lsm=" for boottime LSM selection") and upstream it first, with 'integrity' as the last LSM. The original bug fix commit 92063f3ca73a ("integrity: double check iint_cache was initialized") could then be removed. > > As for LSM_ORDER_FIRST, LSMs with LSM_ORDER_LAST are always enabled and put > at the end of the LSM list in no particular order. ^Similar to LSM_ORDER_FIRST ... And remove "in no particular order". > > Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com> > --- > include/linux/lsm_hooks.h | 1 + > security/security.c | 12 +++++++++--- > 2 files changed, 10 insertions(+), 3 deletions(-) > > diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h > index 21a8ce23108..05c4b831d99 100644 > --- a/include/linux/lsm_hooks.h > +++ b/include/linux/lsm_hooks.h > @@ -93,6 +93,7 @@ extern void security_add_hooks(struct security_hook_list *hooks, int count, > enum lsm_order { > LSM_ORDER_FIRST = -1, /* This is only for capabilities. */ > LSM_ORDER_MUTABLE = 0, > + LSM_ORDER_LAST = 1, > }; > > struct lsm_info { > diff --git a/security/security.c b/security/security.c > index 322090a50cd..24f52ba3218 100644 > --- a/security/security.c > +++ b/security/security.c > @@ -284,9 +284,9 @@ static void __init ordered_lsm_parse(const char *order, const char *origin) > bool found = false; > > for (lsm = __start_lsm_info; lsm < __end_lsm_info; lsm++) { > - if (lsm->order == LSM_ORDER_MUTABLE && > - strcmp(lsm->name, name) == 0) { > - append_ordered_lsm(lsm, origin); > + if (strcmp(lsm->name, name) == 0) { > + if (lsm->order == LSM_ORDER_MUTABLE) > + append_ordered_lsm(lsm, origin); > found = true; > } > } > @@ -306,6 +306,12 @@ static void __init ordered_lsm_parse(const char *order, const char *origin) > } > } > > + /* LSM_ORDER_LAST is always last. */ > + for (lsm = __start_lsm_info; lsm < __end_lsm_info; lsm++) { > + if (lsm->order == LSM_ORDER_LAST) > + append_ordered_lsm(lsm, " last"); > + } > + > /* Disable all LSMs not in the ordered list. */ > for (lsm = __start_lsm_info; lsm < __end_lsm_info; lsm++) { > if (exists_ordered_lsm(lsm))
On Wed, 2023-03-08 at 08:13 -0500, Mimi Zohar wrote: > Hi Roberto, > > On Fri, 2023-03-03 at 19:25 +0100, Roberto Sassu wrote: > > From: Roberto Sassu <roberto.sassu@huawei.com> > > > > Introduce LSM_ORDER_LAST, to satisfy the requirement of LSMs willing to be > > the last, e.g. the 'integrity' LSM, without changing the kernel command > > line or configuration. > > Please reframe this as a bug fix for 79f7865d844c ("LSM: Introduce > "lsm=" for boottime LSM selection") and upstream it first, with > 'integrity' as the last LSM. The original bug fix commit 92063f3ca73a > ("integrity: double check iint_cache was initialized") could then be > removed. Ok, I should complete the patch by checking the cache initialization in iint.c. > > As for LSM_ORDER_FIRST, LSMs with LSM_ORDER_LAST are always enabled and put > > at the end of the LSM list in no particular order. > > ^Similar to LSM_ORDER_FIRST ... > > And remove "in no particular order". The reason for this is that I originally thought that the relative order of LSMs specified in the kernel configuration or the command line was respected (if more than one LSM specifies LSM_ORDER_LAST). In fact not. To do this, we would have to parse the LSM string again, as it is done for LSM_ORDER_MUTABLE LSMs. Thanks Roberto > > Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com> > > --- > > include/linux/lsm_hooks.h | 1 + > > security/security.c | 12 +++++++++--- > > 2 files changed, 10 insertions(+), 3 deletions(-) > > > > diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h > > index 21a8ce23108..05c4b831d99 100644 > > --- a/include/linux/lsm_hooks.h > > +++ b/include/linux/lsm_hooks.h > > @@ -93,6 +93,7 @@ extern void security_add_hooks(struct security_hook_list *hooks, int count, > > enum lsm_order { > > LSM_ORDER_FIRST = -1, /* This is only for capabilities. */ > > LSM_ORDER_MUTABLE = 0, > > + LSM_ORDER_LAST = 1, > > }; > > > > struct lsm_info { > > diff --git a/security/security.c b/security/security.c > > index 322090a50cd..24f52ba3218 100644 > > --- a/security/security.c > > +++ b/security/security.c > > @@ -284,9 +284,9 @@ static void __init ordered_lsm_parse(const char *order, const char *origin) > > bool found = false; > > > > for (lsm = __start_lsm_info; lsm < __end_lsm_info; lsm++) { > > - if (lsm->order == LSM_ORDER_MUTABLE && > > - strcmp(lsm->name, name) == 0) { > > - append_ordered_lsm(lsm, origin); > > + if (strcmp(lsm->name, name) == 0) { > > + if (lsm->order == LSM_ORDER_MUTABLE) > > + append_ordered_lsm(lsm, origin); > > found = true; > > } > > } > > @@ -306,6 +306,12 @@ static void __init ordered_lsm_parse(const char *order, const char *origin) > > } > > } > > > > + /* LSM_ORDER_LAST is always last. */ > > + for (lsm = __start_lsm_info; lsm < __end_lsm_info; lsm++) { > > + if (lsm->order == LSM_ORDER_LAST) > > + append_ordered_lsm(lsm, " last"); > > + } > > + > > /* Disable all LSMs not in the ordered list. */ > > for (lsm = __start_lsm_info; lsm < __end_lsm_info; lsm++) { > > if (exists_ordered_lsm(lsm))
On Wed, 2023-03-08 at 14:26 +0100, Roberto Sassu wrote: > On Wed, 2023-03-08 at 08:13 -0500, Mimi Zohar wrote: > > Hi Roberto, > > > > On Fri, 2023-03-03 at 19:25 +0100, Roberto Sassu wrote: > > > From: Roberto Sassu <roberto.sassu@huawei.com> > > > > > > Introduce LSM_ORDER_LAST, to satisfy the requirement of LSMs willing to be > > > the last, e.g. the 'integrity' LSM, without changing the kernel command > > > line or configuration. > > > > Please reframe this as a bug fix for 79f7865d844c ("LSM: Introduce > > "lsm=" for boottime LSM selection") and upstream it first, with > > 'integrity' as the last LSM. The original bug fix commit 92063f3ca73a > > ("integrity: double check iint_cache was initialized") could then be > > removed. > > Ok, I should complete the patch by checking the cache initialization in > iint.c. > > > > As for LSM_ORDER_FIRST, LSMs with LSM_ORDER_LAST are always enabled and put > > > at the end of the LSM list in no particular order. > > > > ^Similar to LSM_ORDER_FIRST ... > > > > And remove "in no particular order". > > The reason for this is that I originally thought that the relative > order of LSMs specified in the kernel configuration or the command line > was respected (if more than one LSM specifies LSM_ORDER_LAST). In fact > not. To do this, we would have to parse the LSM string again, as it is > done for LSM_ORDER_MUTABLE LSMs. IMA and EVM are only configurable if 'integrity' is enabled. Similar to how LSM_ORDER_FIRST is reserved for capabilities, LSM_ORDER_LAST should be reserved for integrity (LSMs), if it is configured, for the reason as described in the "[PATCH 24/28] ima: Move to LSM infrastructure" patch description. > > Thanks > > Roberto > > > > Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com> > > > --- > > > include/linux/lsm_hooks.h | 1 + > > > security/security.c | 12 +++++++++--- > > > 2 files changed, 10 insertions(+), 3 deletions(-) > > > > > > diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h > > > index 21a8ce23108..05c4b831d99 100644 > > > --- a/include/linux/lsm_hooks.h > > > +++ b/include/linux/lsm_hooks.h > > > @@ -93,6 +93,7 @@ extern void security_add_hooks(struct security_hook_list *hooks, int count, > > > enum lsm_order { > > > LSM_ORDER_FIRST = -1, /* This is only for capabilities. */ > > > LSM_ORDER_MUTABLE = 0, > > > + LSM_ORDER_LAST = 1, > > > }; > > > > > > struct lsm_info { > > > diff --git a/security/security.c b/security/security.c > > > index 322090a50cd..24f52ba3218 100644 > > > --- a/security/security.c > > > +++ b/security/security.c > > > @@ -284,9 +284,9 @@ static void __init ordered_lsm_parse(const char *order, const char *origin) > > > bool found = false; > > > > > > for (lsm = __start_lsm_info; lsm < __end_lsm_info; lsm++) { > > > - if (lsm->order == LSM_ORDER_MUTABLE && > > > - strcmp(lsm->name, name) == 0) { > > > - append_ordered_lsm(lsm, origin); > > > + if (strcmp(lsm->name, name) == 0) { > > > + if (lsm->order == LSM_ORDER_MUTABLE) > > > + append_ordered_lsm(lsm, origin); > > > found = true; > > > } > > > } > > > @@ -306,6 +306,12 @@ static void __init ordered_lsm_parse(const char *order, const char *origin) > > > } > > > } > > > > > > + /* LSM_ORDER_LAST is always last. */ > > > + for (lsm = __start_lsm_info; lsm < __end_lsm_info; lsm++) { > > > + if (lsm->order == LSM_ORDER_LAST) > > > + append_ordered_lsm(lsm, " last"); > > > + } > > > + > > > /* Disable all LSMs not in the ordered list. */ > > > for (lsm = __start_lsm_info; lsm < __end_lsm_info; lsm++) { > > > if (exists_ordered_lsm(lsm)) >
On Wed, 2023-03-08 at 09:00 -0500, Mimi Zohar wrote: > On Wed, 2023-03-08 at 14:26 +0100, Roberto Sassu wrote: > > On Wed, 2023-03-08 at 08:13 -0500, Mimi Zohar wrote: > > > Hi Roberto, > > > > > > On Fri, 2023-03-03 at 19:25 +0100, Roberto Sassu wrote: > > > > From: Roberto Sassu <roberto.sassu@huawei.com> > > > > > > > > Introduce LSM_ORDER_LAST, to satisfy the requirement of LSMs willing to be > > > > the last, e.g. the 'integrity' LSM, without changing the kernel command > > > > line or configuration. > > > > > > Please reframe this as a bug fix for 79f7865d844c ("LSM: Introduce > > > "lsm=" for boottime LSM selection") and upstream it first, with > > > 'integrity' as the last LSM. The original bug fix commit 92063f3ca73a > > > ("integrity: double check iint_cache was initialized") could then be > > > removed. > > > > Ok, I should complete the patch by checking the cache initialization in > > iint.c. > > > > > > As for LSM_ORDER_FIRST, LSMs with LSM_ORDER_LAST are always enabled and put > > > > at the end of the LSM list in no particular order. > > > > > > ^Similar to LSM_ORDER_FIRST ... > > > > > > And remove "in no particular order". > > > > The reason for this is that I originally thought that the relative > > order of LSMs specified in the kernel configuration or the command line > > was respected (if more than one LSM specifies LSM_ORDER_LAST). In fact > > not. To do this, we would have to parse the LSM string again, as it is > > done for LSM_ORDER_MUTABLE LSMs. > > IMA and EVM are only configurable if 'integrity' is enabled. Similar > to how LSM_ORDER_FIRST is reserved for capabilities, LSM_ORDER_LAST > should be reserved for integrity (LSMs), if it is configured, for the > reason as described in the "[PATCH 24/28] ima: Move to LSM > infrastructure" patch description. Yes, it is just that nothing prevents to have multiple LSMs with order LSM_ORDER_LAST. I guess we will enforce that it is only one by reviewing the code. Thanks Roberto > > Thanks > > > > Roberto > > > > > > Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com> > > > > --- > > > > include/linux/lsm_hooks.h | 1 + > > > > security/security.c | 12 +++++++++--- > > > > 2 files changed, 10 insertions(+), 3 deletions(-) > > > > > > > > diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h > > > > index 21a8ce23108..05c4b831d99 100644 > > > > --- a/include/linux/lsm_hooks.h > > > > +++ b/include/linux/lsm_hooks.h > > > > @@ -93,6 +93,7 @@ extern void security_add_hooks(struct security_hook_list *hooks, int count, > > > > enum lsm_order { > > > > LSM_ORDER_FIRST = -1, /* This is only for capabilities. */ > > > > LSM_ORDER_MUTABLE = 0, > > > > + LSM_ORDER_LAST = 1, > > > > }; > > > > > > > > struct lsm_info { > > > > diff --git a/security/security.c b/security/security.c > > > > index 322090a50cd..24f52ba3218 100644 > > > > --- a/security/security.c > > > > +++ b/security/security.c > > > > @@ -284,9 +284,9 @@ static void __init ordered_lsm_parse(const char *order, const char *origin) > > > > bool found = false; > > > > > > > > for (lsm = __start_lsm_info; lsm < __end_lsm_info; lsm++) { > > > > - if (lsm->order == LSM_ORDER_MUTABLE && > > > > - strcmp(lsm->name, name) == 0) { > > > > - append_ordered_lsm(lsm, origin); > > > > + if (strcmp(lsm->name, name) == 0) { > > > > + if (lsm->order == LSM_ORDER_MUTABLE) > > > > + append_ordered_lsm(lsm, origin); > > > > found = true; > > > > } > > > > } > > > > @@ -306,6 +306,12 @@ static void __init ordered_lsm_parse(const char *order, const char *origin) > > > > } > > > > } > > > > > > > > + /* LSM_ORDER_LAST is always last. */ > > > > + for (lsm = __start_lsm_info; lsm < __end_lsm_info; lsm++) { > > > > + if (lsm->order == LSM_ORDER_LAST) > > > > + append_ordered_lsm(lsm, " last"); > > > > + } > > > > + > > > > /* Disable all LSMs not in the ordered list. */ > > > > for (lsm = __start_lsm_info; lsm < __end_lsm_info; lsm++) { > > > > if (exists_ordered_lsm(lsm))
On Wed, 2023-03-08 at 15:35 +0100, Roberto Sassu wrote: > On Wed, 2023-03-08 at 09:00 -0500, Mimi Zohar wrote: > > On Wed, 2023-03-08 at 14:26 +0100, Roberto Sassu wrote: > > > On Wed, 2023-03-08 at 08:13 -0500, Mimi Zohar wrote: > > > > Hi Roberto, > > > > > > > > On Fri, 2023-03-03 at 19:25 +0100, Roberto Sassu wrote: > > > > > From: Roberto Sassu <roberto.sassu@huawei.com> > > > > > > > > > > Introduce LSM_ORDER_LAST, to satisfy the requirement of LSMs willing to be > > > > > the last, e.g. the 'integrity' LSM, without changing the kernel command > > > > > line or configuration. > > > > > > > > Please reframe this as a bug fix for 79f7865d844c ("LSM: Introduce > > > > "lsm=" for boottime LSM selection") and upstream it first, with > > > > 'integrity' as the last LSM. The original bug fix commit 92063f3ca73a > > > > ("integrity: double check iint_cache was initialized") could then be > > > > removed. > > > > > > Ok, I should complete the patch by checking the cache initialization in > > > iint.c. > > > > > > > > As for LSM_ORDER_FIRST, LSMs with LSM_ORDER_LAST are always enabled and put > > > > > at the end of the LSM list in no particular order. > > > > > > > > ^Similar to LSM_ORDER_FIRST ... > > > > > > > > And remove "in no particular order". > > > > > > The reason for this is that I originally thought that the relative > > > order of LSMs specified in the kernel configuration or the command line > > > was respected (if more than one LSM specifies LSM_ORDER_LAST). In fact > > > not. To do this, we would have to parse the LSM string again, as it is > > > done for LSM_ORDER_MUTABLE LSMs. > > > > IMA and EVM are only configurable if 'integrity' is enabled. Similar > > to how LSM_ORDER_FIRST is reserved for capabilities, LSM_ORDER_LAST > > should be reserved for integrity (LSMs), if it is configured, for the > > reason as described in the "[PATCH 24/28] ima: Move to LSM > > infrastructure" patch description. > > Yes, it is just that nothing prevents to have multiple LSMs with order > LSM_ORDER_LAST. I guess we will enforce that it is only one by > reviewing the code. At least add a comment, like the existing one for LSM_ORDER_FIRST. > > > > enum lsm_order { > > > > > LSM_ORDER_FIRST = -1, /* This is only for capabilities. */ > > > > > LSM_ORDER_MUTABLE = 0, > > > > > + LSM_ORDER_LAST = 1, > > > > > };
diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h index 21a8ce23108..05c4b831d99 100644 --- a/include/linux/lsm_hooks.h +++ b/include/linux/lsm_hooks.h @@ -93,6 +93,7 @@ extern void security_add_hooks(struct security_hook_list *hooks, int count, enum lsm_order { LSM_ORDER_FIRST = -1, /* This is only for capabilities. */ LSM_ORDER_MUTABLE = 0, + LSM_ORDER_LAST = 1, }; struct lsm_info { diff --git a/security/security.c b/security/security.c index 322090a50cd..24f52ba3218 100644 --- a/security/security.c +++ b/security/security.c @@ -284,9 +284,9 @@ static void __init ordered_lsm_parse(const char *order, const char *origin) bool found = false; for (lsm = __start_lsm_info; lsm < __end_lsm_info; lsm++) { - if (lsm->order == LSM_ORDER_MUTABLE && - strcmp(lsm->name, name) == 0) { - append_ordered_lsm(lsm, origin); + if (strcmp(lsm->name, name) == 0) { + if (lsm->order == LSM_ORDER_MUTABLE) + append_ordered_lsm(lsm, origin); found = true; } } @@ -306,6 +306,12 @@ static void __init ordered_lsm_parse(const char *order, const char *origin) } } + /* LSM_ORDER_LAST is always last. */ + for (lsm = __start_lsm_info; lsm < __end_lsm_info; lsm++) { + if (lsm->order == LSM_ORDER_LAST) + append_ordered_lsm(lsm, " last"); + } + /* Disable all LSMs not in the ordered list. */ for (lsm = __start_lsm_info; lsm < __end_lsm_info; lsm++) { if (exists_ordered_lsm(lsm))