Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp639005pxb; Thu, 15 Apr 2021 03:06:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwVge1158Sy4QIJdEFmbh2xqQA7o37YcRFv/5yJbk7X4o4vm44b56nhODpjONRG0M39nALc X-Received: by 2002:a17:902:bf07:b029:e7:137c:2e25 with SMTP id bi7-20020a170902bf07b02900e7137c2e25mr2969793plb.67.1618481185060; Thu, 15 Apr 2021 03:06:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618481185; cv=none; d=google.com; s=arc-20160816; b=1CkIiTcMZKbZOhBsZn703MTccoXgZaeTM+45jnzRFeOzg2dcnBVZUi/gIctD5s/c3A hAP5upHSlv/4ZOjAvi+psmaj/tya+B6+ZwO2Oh1YBBKSz/JjrX3osHjAarfw8ykupiB2 OwVK1oRieQ7AfjblPpSakZW4T53mEsQtWcj3So0ZWYa8hm3wlvN9Y6LHDGzkRD4toyk9 mfWIEoUfa1fD7H8qwlvtZ4rHbtChWclEemafrywff5kWUxrFJbbCGJLLs3yG/FqvkxGT RP4w65VDJLqqLh/SNtCLi6cIiWC48nVPRfrA8t0RzZYqAONJ6JPq4HMil9yzXEXfD/oe Da7Q== 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=Ccn9EClMNltwuJEpieMagGltzlNQJmEOZ8MaT4xAULY=; b=oe6kX5zOlMmVk5DCyBTFKafSNTkXkzd6N/ElIuMFGf9sRx0zbIuqSQPI4JZ2tb4LLD BClTo2a6TPRPh6Zy7aZgSLDBWpaZyd9S/TNyOPIWkpLtHsK+WIxj5zdIbLU1HgwQej3G KvWPSFCorFf5S0REaUzU/eKvJsVp0hhBzVC5gAX5JbBMRPuT2jBtAO5+G9K8L+EoJoXT cfQOvsmM1Wn44+cnlsGCQ16j2z6w7nxacCQWt5gFcXHmEzCn0NwhvCy9apcHEdwobCFg h+q9kL1UojlSdv7yFldt0POWWagApKfZDJ92CoV6qGOPhw0c4y3OlCHdIyuTdMvyeIqj Hpnw== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w2si3099870plg.55.2021.04.15.03.06.12; Thu, 15 Apr 2021 03:06:25 -0700 (PDT) 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232306AbhDOKFc (ORCPT + 99 others); Thu, 15 Apr 2021 06:05:32 -0400 Received: from frasgout.his.huawei.com ([185.176.79.56]:2864 "EHLO frasgout.his.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231919AbhDOKFQ (ORCPT ); Thu, 15 Apr 2021 06:05:16 -0400 Received: from fraeml714-chm.china.huawei.com (unknown [172.18.147.226]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4FLZZF44m0z68BH0; Thu, 15 Apr 2021 17:59:33 +0800 (CST) Received: from fraphisprd00473.huawei.com (7.182.8.141) by fraeml714-chm.china.huawei.com (10.206.15.33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2106.2; Thu, 15 Apr 2021 12:04:51 +0200 From: Roberto Sassu To: , , , CC: , , , , , Roberto Sassu Subject: [PATCH 4/5] evm: Align evm_inode_init_security() definition with LSM infrastructure Date: Thu, 15 Apr 2021 12:04:34 +0200 Message-ID: <20210415100435.18619-5-roberto.sassu@huawei.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210415100435.18619-1-roberto.sassu@huawei.com> References: <20210415100435.18619-1-roberto.sassu@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [7.182.8.141] X-ClientProxiedBy: lhreml752-chm.china.huawei.com (10.201.108.202) To fraeml714-chm.china.huawei.com (10.206.15.33) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch changes the evm_inode_init_security() definition to align with the LSM infrastructure, in preparation for moving IMA and EVM to that infrastructure. Signed-off-by: Roberto Sassu --- include/linux/evm.h | 21 ++++++++++++++------- security/integrity/evm/evm_main.c | 24 +++++++++++++++--------- security/security.c | 7 +++++-- 3 files changed, 34 insertions(+), 18 deletions(-) diff --git a/include/linux/evm.h b/include/linux/evm.h index 8cad46bcec9d..5d8b29d80296 100644 --- a/include/linux/evm.h +++ b/include/linux/evm.h @@ -34,9 +34,11 @@ 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, + const char **name, + void **value, size_t *len, + struct xattr *lsm_xattrs); extern bool evm_status_revalidate(const char *xattr_name); #ifdef CONFIG_FS_POSIX_ACL extern int posix_xattr_acl(const char *xattrname); @@ -102,11 +104,16 @@ 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, + const char **name, + void **value, size_t *len, + struct xattr *lsm_xattrs) { - return 0; + if (!name || !value || !len || !lsm_xattrs) + return 0; + + return -EOPNOTSUPP; } static inline bool evm_status_revalidate(const char *xattr_name) diff --git a/security/integrity/evm/evm_main.c b/security/integrity/evm/evm_main.c index 84a9b7a69b1f..a5069d69a893 100644 --- a/security/integrity/evm/evm_main.c +++ b/security/integrity/evm/evm_main.c @@ -706,29 +706,35 @@ 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, + const char **name, + void **value, size_t *len, + struct xattr *lsm_xattrs) { struct evm_xattr *xattr_data; int rc; - if (!(evm_initialized & EVM_INIT_HMAC) || - !evm_protected_xattr(lsm_xattr->name)) + if (!name || !value || !len || !lsm_xattrs) return 0; + if (!(evm_initialized & EVM_INIT_HMAC) || + !evm_protected_xattr(lsm_xattrs->name)) + return -EOPNOTSUPP; + 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, lsm_xattrs, xattr_data->digest); if (rc < 0) goto out; - evm_xattr->value = xattr_data; - evm_xattr->value_len = hash_digest_size[evm_hash_algo] + 1; - evm_xattr->name = XATTR_EVM_SUFFIX; + *name = XATTR_EVM_SUFFIX; + *value = xattr_data; + *len = hash_digest_size[evm_hash_algo] + 1; + return 0; out: kfree(xattr_data); diff --git a/security/security.c b/security/security.c index 8aabbc0f0dfc..e16ce150b111 100644 --- a/security/security.c +++ b/security/security.c @@ -1080,8 +1080,11 @@ int security_inode_init_security(struct inode *inode, struct inode *dir, goto out; } - ret = evm_inode_init_security(inode, new_xattrs, lsm_xattr); - if (ret) + ret = evm_inode_init_security(inode, dir, qstr, + &lsm_xattr->name, + &lsm_xattr->value, + &lsm_xattr->value_len, new_xattrs); + if (ret && ret != -EOPNOTSUPP) goto out; ret = initxattrs(inode, new_xattrs, fs_data); out: -- 2.26.2