Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp874648pxf; Wed, 7 Apr 2021 13:53:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxnGm4etdW8MYxQioG8rcZQ7E5xRhql1yrv7g3x5dNKMhTgoJaQSFs6t8fq/iHelzJGik03 X-Received: by 2002:a02:294e:: with SMTP id p75mr5380384jap.34.1617828791338; Wed, 07 Apr 2021 13:53:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617828791; cv=none; d=google.com; s=arc-20160816; b=j9LRUMfEPLCJv5TmqE9l5LEOZkd9a3NKcsaRbuJer7geKwMbrKKdIyzWnewRb1KKZb 8gUvchdWRnVOAeb8eVDr+bA66WKCYopL76fP+7lSHD9WqM9GzPckDeAFbbc8wsZsXDSi zQuD+VceBHId13pMRc0mt8tmorMV1QHy0cwyO4R8usbSJo567QEd9OdWoZt+KZJ1Pvus +EMUZTYf5EQY6jvtW68tlSciOyG5SegKfkSKlor3M0dTYxr45K4V17B4thzGJC1Jxc4g yliNNw1QaGYkqji71P2OLSgFtuRu02DmZQKXo2xLbQBLVYBv6frYb3YuF6os6vHhbsle dqQg== 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=iO5u3IwMz5KOsU2F57kIYq4EMcYSq/ollUoA2Ht7dnk=; b=FtiPj7ZY4lDhXwPsnBBdXOz0Ok4oEcR9c8bWHjAU5PFy4t8TW34FTlQ1QLJIXrw+gb 21RKB2ntXSyXb5ZDfl9EyXv85AkrO3WWUzmvRIqE5tJbs4jwI7r7KkmFteG3SYLyCJa8 RtUBYBlM29J1pOEI9R2R3U9kuD+NLT8H6PuAREC67+eJkYncQs3p9g4IJUSyqHF9aT61 kJEpKz1EZl9bzxuV8QX2b/a+YAS6FwcDa2Kfjls3qPyKvBkkIdMMBQovpc0quv8ThI9r RjXrIHbvyc+qT6/ccf+452Bn90741C9QqIDcXCeuFYQ6qjQATxQNENB4pPm6e0OaWzX2 0FGw== 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 y11si20336998ill.115.2021.04.07.13.52.59; Wed, 07 Apr 2021 13:53:11 -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 S245239AbhDGKzs (ORCPT + 99 others); Wed, 7 Apr 2021 06:55:48 -0400 Received: from frasgout.his.huawei.com ([185.176.79.56]:2794 "EHLO frasgout.his.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232637AbhDGKzp (ORCPT ); Wed, 7 Apr 2021 06:55:45 -0400 Received: from fraeml714-chm.china.huawei.com (unknown [172.18.147.226]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4FFgzc5l80z684vf; Wed, 7 Apr 2021 18:46:04 +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; Wed, 7 Apr 2021 12:55:34 +0200 From: Roberto Sassu To: , CC: , , , , Roberto Sassu Subject: [PATCH v5 10/12] ima: Allow imasig requirement to be satisfied by EVM portable signatures Date: Wed, 7 Apr 2021 12:52:50 +0200 Message-ID: <20210407105252.30721-11-roberto.sassu@huawei.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210407105252.30721-1-roberto.sassu@huawei.com> References: <20210407105252.30721-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: lhreml753-chm.china.huawei.com (10.201.108.203) 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 System administrators can require that all accessed files have a signature by specifying appraise_type=imasig in a policy rule. Currently, IMA signatures satisfy this requirement. Appended signatures may also satisfy this requirement, but are not applicable as IMA signatures. IMA/appended signatures ensure data source authentication for file content and prevent any change. EVM signatures instead ensure data source authentication for file metadata. Given that the digest or signature of the file content must be included in the metadata, EVM signatures provide the same file data guarantees of IMA signatures, as well as providing file metadata guarantees. This patch lets systems protected with EVM signatures pass appraisal verification if the appraise_type=imasig requirement is specified in the policy. This facilitates deployment in the scenarios where only EVM signatures are available. The patch makes the following changes: file xattr types: security.ima: IMA_XATTR_DIGEST/IMA_XATTR_DIGEST_NG security.evm: EVM_XATTR_PORTABLE_DIGSIG execve(), mmap(), open() behavior (with appraise_type=imasig): before: denied (file without IMA signature, imasig requirement not met) after: allowed (file with EVM portable signature, imasig requirement met) open(O_WRONLY) behavior (without appraise_type=imasig): before: allowed (file without IMA signature, not immutable) after: denied (file with EVM portable signature, immutable) In addition, similarly to IMA signatures, this patch temporarily allows new files without or with incomplete metadata to be opened so that content can be written. Signed-off-by: Roberto Sassu Reviewed-by: Mimi Zohar --- security/integrity/ima/ima_appraise.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/security/integrity/ima/ima_appraise.c b/security/integrity/ima/ima_appraise.c index 24d59893aab0..538ccbf972c8 100644 --- a/security/integrity/ima/ima_appraise.c +++ b/security/integrity/ima/ima_appraise.c @@ -242,12 +242,16 @@ static int xattr_verify(enum ima_hooks func, struct integrity_iint_cache *iint, hash_start = 1; fallthrough; case IMA_XATTR_DIGEST: - if (iint->flags & IMA_DIGSIG_REQUIRED) { - *cause = "IMA-signature-required"; - *status = INTEGRITY_FAIL; - break; + if (*status != INTEGRITY_PASS_IMMUTABLE) { + if (iint->flags & IMA_DIGSIG_REQUIRED) { + *cause = "IMA-signature-required"; + *status = INTEGRITY_FAIL; + break; + } + clear_bit(IMA_DIGSIG, &iint->atomic_flags); + } else { + set_bit(IMA_DIGSIG, &iint->atomic_flags); } - clear_bit(IMA_DIGSIG, &iint->atomic_flags); if (xattr_len - sizeof(xattr_value->type) - hash_start >= iint->ima_hash->length) /* @@ -417,6 +421,7 @@ int ima_appraise_measurement(enum ima_hooks func, cause = "missing-HMAC"; goto out; case INTEGRITY_FAIL_IMMUTABLE: + set_bit(IMA_DIGSIG, &iint->atomic_flags); fallthrough; case INTEGRITY_FAIL: /* Invalid HMAC/signature. */ cause = "invalid-HMAC"; @@ -461,9 +466,12 @@ int ima_appraise_measurement(enum ima_hooks func, status = INTEGRITY_PASS; } - /* Permit new files with file signatures, but without data. */ + /* + * Permit new files with file/EVM portable signatures, but + * without data. + */ if (inode->i_size == 0 && iint->flags & IMA_NEW_FILE && - xattr_value && xattr_value->type == EVM_IMA_XATTR_DIGSIG) { + test_bit(IMA_DIGSIG, &iint->atomic_flags)) { status = INTEGRITY_PASS; } @@ -595,6 +603,8 @@ void ima_inode_post_setxattr(struct dentry *dentry, const char *xattr_name, xattr_value_len); if (result == 1) digsig = (xvalue->type == EVM_IMA_XATTR_DIGSIG); + if (!strcmp(xattr_name, XATTR_NAME_EVM) && xattr_value_len > 0) + digsig = (xvalue->type == EVM_XATTR_PORTABLE_DIGSIG); if (result == 1 || evm_status_revalidate(xattr_name)) ima_reset_appraise_flags(d_backing_inode(dentry), digsig); } -- 2.26.2