Message ID | 20221110094639.3086409-5-roberto.sassu@huaweicloud.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp48328wru; Thu, 10 Nov 2022 01:51:27 -0800 (PST) X-Google-Smtp-Source: AMsMyM7Y6mU0sL3p6fwXtkdzcjCOTm6wX4hMI6wHGsvazuPuSlwSAlF8crwdXDdgxvWypYu4ZuG3 X-Received: by 2002:a63:f07:0:b0:440:5c6e:5833 with SMTP id e7-20020a630f07000000b004405c6e5833mr55787708pgl.375.1668073887246; Thu, 10 Nov 2022 01:51:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668073887; cv=none; d=google.com; s=arc-20160816; b=VkOAZ6qt3MLk9UAPIW0oaS0ORx6M+TlazN8xTMVWljVVJm8epx/CJ7C934fSzvxTRW uZPhQ/gt8iy6C4dpqrBSUcZ4jznxAf8E9/PtjdqKI+CLsisqiDAajos6xXRENXqT+eom hJB8CM7s54eEQ1eKGDiysM2HnL9rgy0THqvwtHGN9fuAKaGXqT2akvM7iv+CnLVmMGJ0 PL3ThfurABaOFBgfLgC1/X+Ma/i/FZiDz/XZfiwj1Hsh4Wt2iemwccPN7wlAqF+zJePp 9F9MfOkFun8/Ae77lvjetrMQhzjmk2WW5XtKWKJRU4zzC8J4P/gBccxtBaGjEoxcWOxd +Brg== 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=musURjlObpxgPV+l6+4bQxNBdQ0t/5Dvuk6lBLCXKb4=; b=i75Q5KhaNzZI0y4Wl8BhZBDg86XA8YqlUalmcrRrDCG09RwxpKct+HzLjpp3x2UwxL Co9tct6OwhJPIQVHzknSNYS82+5w+zbtWFvFBq7Q9H2htKA8i9/5lVtxfdDTWeUhatea FUlU6rzidFX9nhpw21SfPx0OHb7GLtqYHBp9X4EaLQVR5OEXZcVq7Pua3qpK1ivtw70Y Yrwwmi8P2E/bEQjJaakZx7EYo7EVNapWShMNSBRAObcs7ACB9KyPZat9DPjDNSc6y3Qy xD+Ehkqlf5gE4X3gjttOiKbB62uuaqrt97s6NzYiTm2BfP9QrGHMt/LmjO0x8qPWEOl4 kXfw== 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 m76-20020a633f4f000000b0046edec119f6si19782318pga.227.2022.11.10.01.50.48; Thu, 10 Nov 2022 01:51:27 -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 S230008AbiKJJsT (ORCPT <rfc822;winker.wchi@gmail.com> + 99 others); Thu, 10 Nov 2022 04:48:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35250 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229561AbiKJJr7 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 10 Nov 2022 04:47:59 -0500 Received: from frasgout12.his.huawei.com (frasgout12.his.huawei.com [14.137.139.154]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AB7186A6B5; Thu, 10 Nov 2022 01:47:56 -0800 (PST) Received: from mail02.huawei.com (unknown [172.18.147.228]) by frasgout12.his.huawei.com (SkyGuard) with ESMTP id 4N7H12298jz9v7Nl; Thu, 10 Nov 2022 17:41:58 +0800 (CST) Received: from huaweicloud.com (unknown [10.204.63.22]) by APP1 (Coremail) with SMTP id LxC2BwCHc3CNyGxjO3hSAA--.1123S6; Thu, 10 Nov 2022 10:47:32 +0100 (CET) From: Roberto Sassu <roberto.sassu@huaweicloud.com> To: zohar@linux.ibm.com, dmitry.kasatkin@gmail.com, paul@paul-moore.com, jmorris@namei.org, serge@hallyn.com, stephen.smalley.work@gmail.com, eparis@parisplace.org, casey@schaufler-ca.com Cc: linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org, reiserfs-devel@vger.kernel.org, linux-kernel@vger.kernel.org, keescook@chromium.org, nicolas.bouchinet@clip-os.org, Roberto Sassu <roberto.sassu@huawei.com> Subject: [PATCH v4 4/5] evm: Align evm_inode_init_security() definition with LSM infrastructure Date: Thu, 10 Nov 2022 10:46:38 +0100 Message-Id: <20221110094639.3086409-5-roberto.sassu@huaweicloud.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221110094639.3086409-1-roberto.sassu@huaweicloud.com> References: <20221110094639.3086409-1-roberto.sassu@huaweicloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: LxC2BwCHc3CNyGxjO3hSAA--.1123S6 X-Coremail-Antispam: 1UD129KBjvJXoWxtFW7tw1DGF1UtrWxKF4xXrb_yoW7GFyxpF W3K3WUCr1rJFyUWry0yF4xu3WSgFWrGr4UK393G34jyF1Dtr1xtFyFyr15ury5XrW8GFnY qw42vr1rWwn0y3DanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUBIb4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUAV Cq3wA2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0 rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVWUJVWUCwA2z4x0Y4vE2Ix0cI8IcVCY1x0267 AKxVWxJVW8Jr1l84ACjcxK6I8E87Iv67AKxVW8JVWxJwA2z4x0Y4vEx4A2jsIEc7CjxVAF wI0_Gr0_Gr1UM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7 xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Y z7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lFIxGxcIEc7CjxVA2Y2ka0xkIwI1l42xK82IYc2 Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s02 6x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r4a6rW5MIIYrxkI7VAKI48JMIIF0x vE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E14v26F4j6r4UJwCI42IY 6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aV CY1x0267AKxVW8JVW8JrUvcSsGvfC2KfnxnUUI43ZEXa7IU13l1DUUUUU== X-CM-SenderInfo: purev21wro2thvvxqx5xdzvxpfor3voofrz/1tbiAQAMBF1jj4VHCgAAsw X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS 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?1749102244423573509?= X-GMAIL-MSGID: =?utf-8?q?1749102244423573509?= |
Series |
evm: Prepare for moving to the LSM infrastructure
|
|
Commit Message
Roberto Sassu
Nov. 10, 2022, 9:46 a.m. UTC
From: Roberto Sassu <roberto.sassu@huawei.com> Change the evm_inode_init_security() definition to align with the LSM infrastructure, in preparation for moving IMA and EVM to that infrastructure. This requires passing only the xattr array allocated by security_inode_init_security(), instead of the first LSM xattr and the place where the EVM xattr should be filled. It also requires positioning after the last filled xattr (by checking the xattr name), since the beginning of the xattr array is given. If EVM is moved to the LSM infrastructure, it will use the xattr reservation mechanism too, i.e. it positions itself in the xattr array with the offset given by the LSM infrastructure. Finally, make evm_inode_init_security() return value compatible with the inode_init_security hook conventions, i.e. return -EOPNOTSUPP if it is not setting an xattr. EVM is a bit tricky, because xattrs is both an input and an output. If it was just output, EVM should have returned zero if xattrs is NULL. But, since xattrs is also input, EVM is unable to do its calculations, so return -EOPNOTSUPP and handle this error in security_inode_init_security(). Don't change the return value in the inline function evm_inode_init_security() in include/linux/evm.h, as the function will be removed if EVM is moved to the LSM infrastructure. Last note, this patch does not fix a possible crash if the xattr array is empty (due to calling evm_protected_xattr() with a NULL argument). It will be fixed with 'evm: Support multiple LSMs providing an xattr', as it will first ensure that the xattr name is not NULL before calling evm_protected_xattr(). Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com> --- include/linux/evm.h | 12 ++++++------ security/integrity/evm/evm_main.c | 20 +++++++++++++------- security/security.c | 5 ++--- 3 files changed, 21 insertions(+), 16 deletions(-)
Comments
On Thu, 2022-11-10 at 10:46 +0100, Roberto Sassu wrote: > From: Roberto Sassu <roberto.sassu@huawei.com> > > Change the evm_inode_init_security() definition to align with the LSM > infrastructure, in preparation for moving IMA and EVM to that > infrastructure. > > This requires passing only the xattr array allocated by > security_inode_init_security(), instead of the first LSM xattr and the > place where the EVM xattr should be filled. > > It also requires positioning after the last filled xattr (by checking the > xattr name), since the beginning of the xattr array is given. Perhaps combine this sentence to the previous paragraph and start the sentence with "In lieu of passing the EVM xattr, ..." > If EVM is moved to the LSM infrastructure, it will use the xattr > reservation mechanism too, i.e. it positions itself in the xattr array with > the offset given by the LSM infrastructure. The LSM infrastructure will need to support EVM as the last LSM. Is there a reason for including this comment in this patch description. > Finally, make evm_inode_init_security() return value compatible with the > inode_init_security hook conventions, i.e. return -EOPNOTSUPP if it is not > setting an xattr. > EVM is a bit tricky, because xattrs is both an input and an output. If it > was just output, EVM should have returned zero if xattrs is NULL. But, > since xattrs is also input, EVM is unable to do its calculations, so return > -EOPNOTSUPP and handle this error in security_inode_init_security(). > > Don't change the return value in the inline function > evm_inode_init_security() in include/linux/evm.h, as the function will be > removed if EVM is moved to the LSM infrastructure. > > Last note, this patch does not fix a possible crash if the xattr array is > empty (due to calling evm_protected_xattr() with a NULL argument). It will > be fixed with 'evm: Support multiple LSMs providing an xattr', as it will > first ensure that the xattr name is not NULL before calling > evm_protected_xattr(). From my reading of the code, although there might be multiple LSM xattrs, this patch only includes the first LSM xattr in the security EVM calculation. So it only checks the first xattr's name. Support for including multiple LSM xattrs in the EVM hmac calculation is added in the subsequent patch. thanks, Mimi > > Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com>
On 11/17/2022 6:07 PM, Mimi Zohar wrote: > On Thu, 2022-11-10 at 10:46 +0100, Roberto Sassu wrote: >> From: Roberto Sassu <roberto.sassu@huawei.com> >> >> Change the evm_inode_init_security() definition to align with the LSM >> infrastructure, in preparation for moving IMA and EVM to that >> infrastructure. >> >> This requires passing only the xattr array allocated by >> security_inode_init_security(), instead of the first LSM xattr and the >> place where the EVM xattr should be filled. >> >> It also requires positioning after the last filled xattr (by checking the >> xattr name), since the beginning of the xattr array is given. > > Perhaps combine this sentence to the previous paragraph and start the > sentence with > "In lieu of passing the EVM xattr, ..." Ok. >> If EVM is moved to the LSM infrastructure, it will use the xattr >> reservation mechanism too, i.e. it positions itself in the xattr array with >> the offset given by the LSM infrastructure. > > The LSM infrastructure will need to support EVM as the last LSM. Is > there a reason for including this comment in this patch description. The idea is to first make EVM work like other LSMs, and then add limitations that are EVM-specific. As a regular LSM, EVM could be placed anywhere in the list of LSMs. This would mean that whenever EVM is called, it will process xattrs that are set by previous LSMs, not the subsequent ones. What we would need to do EVM-specific is that EVM is the last in the list of LSMs, to ensure that all xattrs are protected. >> Finally, make evm_inode_init_security() return value compatible with the >> inode_init_security hook conventions, i.e. return -EOPNOTSUPP if it is not >> setting an xattr. > >> EVM is a bit tricky, because xattrs is both an input and an output. If it >> was just output, EVM should have returned zero if xattrs is NULL. But, >> since xattrs is also input, EVM is unable to do its calculations, so return >> -EOPNOTSUPP and handle this error in security_inode_init_security(). >> >> Don't change the return value in the inline function >> evm_inode_init_security() in include/linux/evm.h, as the function will be >> removed if EVM is moved to the LSM infrastructure. >> >> Last note, this patch does not fix a possible crash if the xattr array is >> empty (due to calling evm_protected_xattr() with a NULL argument). It will >> be fixed with 'evm: Support multiple LSMs providing an xattr', as it will >> first ensure that the xattr name is not NULL before calling >> evm_protected_xattr(). > > From my reading of the code, although there might be multiple LSM > xattrs, this patch only includes the first LSM xattr in the security > EVM calculation. So it only checks the first xattr's name. Support > for including multiple LSM xattrs in the EVM hmac calculation is added > in the subsequent patch. I tried to include in this patch just the function definition change and keep the existing behavior. The problem is trying to access xattr->name at the beginning of evm_inode_init_security(). That would disappear in patch 5, where there is a loop checking xattr->value first. Patch 3 disallows combination of NULL name - !NULL value and !NULL name - NULL value. Not sure if the latter is correct (empty xattr?). Will check what callers do. Roberto > thanks, > > Mimi > >> >> Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com>
On Fri, 2022-11-18 at 10:30 +0100, Roberto Sassu wrote: > On 11/17/2022 6:07 PM, Mimi Zohar wrote: > > On Thu, 2022-11-10 at 10:46 +0100, Roberto Sassu wrote: > >> From: Roberto Sassu <roberto.sassu@huawei.com> > >> > >> Change the evm_inode_init_security() definition to align with the LSM > >> infrastructure, in preparation for moving IMA and EVM to that > >> infrastructure. > >> > >> This requires passing only the xattr array allocated by > >> security_inode_init_security(), instead of the first LSM xattr and the > >> place where the EVM xattr should be filled. > >> > >> It also requires positioning after the last filled xattr (by checking the > >> xattr name), since the beginning of the xattr array is given. > > > > Perhaps combine this sentence to the previous paragraph and start the > > sentence with > > "In lieu of passing the EVM xattr, ..." > > Ok. > > >> If EVM is moved to the LSM infrastructure, it will use the xattr > >> reservation mechanism too, i.e. it positions itself in the xattr array with > >> the offset given by the LSM infrastructure. > > > > The LSM infrastructure will need to support EVM as the last LSM. Is > > there a reason for including this comment in this patch description. > > The idea is to first make EVM work like other LSMs, and then add > limitations that are EVM-specific. > > As a regular LSM, EVM could be placed anywhere in the list of LSMs. This > would mean that whenever EVM is called, it will process xattrs that are > set by previous LSMs, not the subsequent ones. > > What we would need to do EVM-specific is that EVM is the last in the > list of LSMs, to ensure that all xattrs are protected. > > >> Finally, make evm_inode_init_security() return value compatible with the > >> inode_init_security hook conventions, i.e. return -EOPNOTSUPP if it is not > >> setting an xattr. > > > >> EVM is a bit tricky, because xattrs is both an input and an output. If it > >> was just output, EVM should have returned zero if xattrs is NULL. But, > >> since xattrs is also input, EVM is unable to do its calculations, so return > >> -EOPNOTSUPP and handle this error in security_inode_init_security(). > >> > >> Don't change the return value in the inline function > >> evm_inode_init_security() in include/linux/evm.h, as the function will be > >> removed if EVM is moved to the LSM infrastructure. > >> > >> Last note, this patch does not fix a possible crash if the xattr array is > >> empty (due to calling evm_protected_xattr() with a NULL argument). It will > >> be fixed with 'evm: Support multiple LSMs providing an xattr', as it will > >> first ensure that the xattr name is not NULL before calling > >> evm_protected_xattr(). > > > > From my reading of the code, although there might be multiple LSM > > xattrs, this patch only includes the first LSM xattr in the security > > EVM calculation. So it only checks the first xattr's name. Support > > for including multiple LSM xattrs in the EVM hmac calculation is added > > in the subsequent patch. > > I tried to include in this patch just the function definition change and > keep the existing behavior. That's fine. > > The problem is trying to access xattr->name at the beginning of > evm_inode_init_security(). > > That would disappear in patch 5, where there is a loop checking > xattr->value first. Patch 3 disallows combination of NULL name - !NULL > value and !NULL name - NULL value. Not sure if the latter is correct > (empty xattr?). Will check what callers do. My comments here and above were for improving the patch description: - Just say what this patch is doing, not what subsequent changes will do in the future. We'll come to that when the time comes. - Say something only the lines that this patch includes only one LSM security xattr in the EVM calculation, like previously. thanks, Mimi
On Fri, 2022-11-18 at 10:30 +0100, Roberto Sassu wrote: > On 11/17/2022 6:07 PM, Mimi Zohar wrote: > > On Thu, 2022-11-10 at 10:46 +0100, Roberto Sassu wrote: > >> From: Roberto Sassu <roberto.sassu@huawei.com> > >> > >> Change the evm_inode_init_security() definition to align with the LSM > >> infrastructure, in preparation for moving IMA and EVM to that > >> infrastructure. > >> > >> This requires passing only the xattr array allocated by > >> security_inode_init_security(), instead of the first LSM xattr and the > >> place where the EVM xattr should be filled. > >> > >> It also requires positioning after the last filled xattr (by checking the > >> xattr name), since the beginning of the xattr array is given. > > > > Perhaps combine this sentence to the previous paragraph and start the > > sentence with > > "In lieu of passing the EVM xattr, ..." > > Ok. > > >> If EVM is moved to the LSM infrastructure, it will use the xattr > >> reservation mechanism too, i.e. it positions itself in the xattr array with > >> the offset given by the LSM infrastructure. > > > > The LSM infrastructure will need to support EVM as the last LSM. Is > > there a reason for including this comment in this patch description. > > The idea is to first make EVM work like other LSMs, and then add > limitations that are EVM-specific. > > As a regular LSM, EVM could be placed anywhere in the list of LSMs. This > would mean that whenever EVM is called, it will process xattrs that are > set by previous LSMs, not the subsequent ones. > > What we would need to do EVM-specific is that EVM is the last in the > list of LSMs, to ensure that all xattrs are protected. > > >> Finally, make evm_inode_init_security() return value compatible with the > >> inode_init_security hook conventions, i.e. return -EOPNOTSUPP if it is not > >> setting an xattr. > > > >> EVM is a bit tricky, because xattrs is both an input and an output. If it > >> was just output, EVM should have returned zero if xattrs is NULL. But, > >> since xattrs is also input, EVM is unable to do its calculations, so return > >> -EOPNOTSUPP and handle this error in security_inode_init_security(). > >> > >> Don't change the return value in the inline function > >> evm_inode_init_security() in include/linux/evm.h, as the function will be > >> removed if EVM is moved to the LSM infrastructure. > >> > >> Last note, this patch does not fix a possible crash if the xattr array is > >> empty (due to calling evm_protected_xattr() with a NULL argument). It will > >> be fixed with 'evm: Support multiple LSMs providing an xattr', as it will > >> first ensure that the xattr name is not NULL before calling > >> evm_protected_xattr(). > > > > From my reading of the code, although there might be multiple LSM > > xattrs, this patch only includes the first LSM xattr in the security > > EVM calculation. So it only checks the first xattr's name. Support > > for including multiple LSM xattrs in the EVM hmac calculation is added > > in the subsequent patch. > > I tried to include in this patch just the function definition change and > keep the existing behavior. That's fine. > > The problem is trying to access xattr->name at the beginning of > evm_inode_init_security(). > > That would disappear in patch 5, where there is a loop checking > xattr->value first. Patch 3 disallows combination of NULL name - !NULL > value and !NULL name - NULL value. Not sure if the latter is correct > (empty xattr?). Will check what callers do. My comments here and above were for improving the patch description: - Just say what this patch is doing, not what subsequent changes will do in the future. We'll come to that when the time comes. - Say something only the lines that this patch includes only one LSM security xattr in the EVM calculation, like previously. thanks, Mimi
diff --git a/include/linux/evm.h b/include/linux/evm.h index aa63e0b3c0a2..3bb2ae9fe098 100644 --- a/include/linux/evm.h +++ b/include/linux/evm.h @@ -35,9 +35,9 @@ extern int evm_inode_removexattr(struct user_namespace *mnt_userns, struct dentry *dentry, const char *xattr_name); extern void evm_inode_post_removexattr(struct dentry *dentry, const char *xattr_name); -extern int evm_inode_init_security(struct inode *inode, - const struct xattr *xattr_array, - struct xattr *evm); +extern int evm_inode_init_security(struct inode *inode, struct inode *dir, + const struct qstr *qstr, + struct xattr *xattrs); extern bool evm_revalidate_status(const char *xattr_name); extern int evm_protected_xattr_if_enabled(const char *req_xattr_name); extern int evm_read_protected_xattrs(struct dentry *dentry, u8 *buffer, @@ -108,9 +108,9 @@ static inline void evm_inode_post_removexattr(struct dentry *dentry, return; } -static inline int evm_inode_init_security(struct inode *inode, - const struct xattr *xattr_array, - struct xattr *evm) +static inline int evm_inode_init_security(struct inode *inode, struct inode *dir, + const struct qstr *qstr, + struct xattr *xattrs) { return 0; } diff --git a/security/integrity/evm/evm_main.c b/security/integrity/evm/evm_main.c index 23d484e05e6f..0a312cafb7de 100644 --- a/security/integrity/evm/evm_main.c +++ b/security/integrity/evm/evm_main.c @@ -845,23 +845,29 @@ void evm_inode_post_setattr(struct dentry *dentry, int ia_valid) /* * evm_inode_init_security - initializes security.evm HMAC value */ -int evm_inode_init_security(struct inode *inode, - const struct xattr *lsm_xattr, - struct xattr *evm_xattr) +int evm_inode_init_security(struct inode *inode, struct inode *dir, + const struct qstr *qstr, + struct xattr *xattrs) { struct evm_xattr *xattr_data; + struct xattr *xattr, *evm_xattr; int rc; - if (!(evm_initialized & EVM_INIT_HMAC) || - !evm_protected_xattr(lsm_xattr->name)) - return 0; + if (!(evm_initialized & EVM_INIT_HMAC) || !xattrs || + !evm_protected_xattr(xattrs->name)) + return -EOPNOTSUPP; + + for (xattr = xattrs; xattr->value != NULL; xattr++) + ; + + evm_xattr = xattr; xattr_data = kzalloc(sizeof(*xattr_data), GFP_NOFS); if (!xattr_data) return -ENOMEM; xattr_data->data.type = EVM_XATTR_HMAC; - rc = evm_init_hmac(inode, lsm_xattr, xattr_data->digest); + rc = evm_init_hmac(inode, xattrs, xattr_data->digest); if (rc < 0) goto out; diff --git a/security/security.c b/security/security.c index b62f192de6da..999102101a75 100644 --- a/security/security.c +++ b/security/security.c @@ -1170,9 +1170,8 @@ int security_inode_init_security(struct inode *inode, struct inode *dir, } } - ret = evm_inode_init_security(inode, new_xattrs, - new_xattrs + cur_xattrs); - if (ret) + ret = evm_inode_init_security(inode, dir, qstr, new_xattrs); + if (ret && ret != -EOPNOTSUPP) goto out; ret = initxattrs(inode, new_xattrs, fs_data); out: