From patchwork Fri Mar 3 18:25:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roberto Sassu X-Patchwork-Id: 64034 Return-Path: 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 + 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 ); 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 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 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 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: 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?= From: Roberto Sassu 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 --- 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))