Received: by 2002:a05:6a10:a852:0:0:0:0 with SMTP id d18csp376854pxy; Wed, 5 May 2021 04:34:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzhSEwCdJAfVCKBvLOPSb8pdqPYQLixD6S6lGcmCXAIZEZw7VXqnTH3Z8R0K6OfE5QD9zzz X-Received: by 2002:aa7:8ad8:0:b029:290:2365:3ede with SMTP id b24-20020aa78ad80000b029029023653edemr2256445pfd.12.1620214480104; Wed, 05 May 2021 04:34:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620214480; cv=none; d=google.com; s=arc-20160816; b=DBaEnONdOWnup1qdgFfz0uRa1ZETYjrE0iTz19czeBUw8cGwP24EL6pZ6i7VQa7V4K hVGj7h8ZO7W5i7N8NYMjJkpIZdS1bwY6jQSrBLRevGKDzYfRMFk+ZaxlFrU1JU2zo89S DOEKNc7CVbsbXUbdqwR2V72NJYCayd/V9xb+QtjMI3t8Ke7OTMhK9DdijCpe7L91v3I2 TlHa4CwiINrtfCMS6kbbzFzFoa1zByGRMEFNV9NkJXLcOnh9wHnwCtr2HF9cnJ05E1Lz YjQdCvPMQ9gQlgC5/aWZu1bmoTLzRsVmP4Nz/HKEYrb7IzKNqEfz85XrT5px6I+gk50c RdGw== 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=fmwP1Q+PZ6jQJurtdLJG46KfsLyW5LNgVnRUHAw2vVc=; b=I0nUFTr7WDcRZYa817tv7bEuYJnnPKMNkIIDaQVbe73lhbbXFhM11zExeTKrY18exw HGyvApfDbknOxam9m4BxvyThiWTLBRDkiDIDZxlUckEAuanfU9IQccHoTqBz13eAI3Sg PQNgjK6/KlLg8+cTNTv/SbLFKa7lIZ0LoSKiFs0c9po4q88kVTcNOe9FbB9yLlGKJeVg XPlq8k21n2PZN574aggGGfucEx+xv8PCtwIRh1Ddv2JCt1xTdU3xud0DoKfU7Okd3fqy W8ygoboV5u4EyjHqv73O2ib9fQGWlvfsskgFMJEOcvLusERqoSC6lBVBKOm3hGWiokwI MJsA== 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 g8si20822508pja.25.2021.05.05.04.34.28; Wed, 05 May 2021 04:34:40 -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 S233042AbhEELex (ORCPT + 99 others); Wed, 5 May 2021 07:34:53 -0400 Received: from frasgout.his.huawei.com ([185.176.79.56]:3009 "EHLO frasgout.his.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232907AbhEELev (ORCPT ); Wed, 5 May 2021 07:34:51 -0400 Received: from fraeml714-chm.china.huawei.com (unknown [172.18.147.226]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4FZvXb2D6jz6rlTr; Wed, 5 May 2021 19:25:51 +0800 (CST) Received: from roberto-ThinkStation-P620.huawei.com (10.204.62.217) 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.2176.2; Wed, 5 May 2021 13:33:52 +0200 From: Roberto Sassu To: , CC: , , , Roberto Sassu Subject: [PATCH v6 06/11] evm: Allow xattr/attr operations for portable signatures Date: Wed, 5 May 2021 13:33:24 +0200 Message-ID: <20210505113329.1410943-2-roberto.sassu@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210505112935.1410679-1-roberto.sassu@huawei.com> References: <20210505112935.1410679-1-roberto.sassu@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.204.62.217] 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 If files with portable signatures are copied from one location to another or are extracted from an archive, verification can temporarily fail until all xattrs/attrs are set in the destination. Only portable signatures may be moved or copied from one file to another, as they don't depend on system-specific information such as the inode generation. Instead portable signatures must include security.ima. Unlike other security.evm types, EVM portable signatures are also immutable. Thus, it wouldn't be a problem to allow xattr/attr operations when verification fails, as portable signatures will never be replaced with the HMAC on possibly corrupted xattrs/attrs. This patch first introduces a new integrity status called INTEGRITY_FAIL_IMMUTABLE, that allows callers of evm_verify_current_integrity() to detect that a portable signature didn't pass verification and then adds an exception in evm_protect_xattr() and evm_inode_setattr() for this status and returns 0 instead of -EPERM. Signed-off-by: Roberto Sassu Reviewed-by: Mimi Zohar --- include/linux/integrity.h | 1 + security/integrity/evm/evm_main.c | 33 ++++++++++++++++++++++----- security/integrity/ima/ima_appraise.c | 2 ++ 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/include/linux/integrity.h b/include/linux/integrity.h index 2271939c5c31..2ea0f2f65ab6 100644 --- a/include/linux/integrity.h +++ b/include/linux/integrity.h @@ -13,6 +13,7 @@ enum integrity_status { INTEGRITY_PASS = 0, INTEGRITY_PASS_IMMUTABLE, INTEGRITY_FAIL, + INTEGRITY_FAIL_IMMUTABLE, INTEGRITY_NOLABEL, INTEGRITY_NOXATTRS, INTEGRITY_UNKNOWN, diff --git a/security/integrity/evm/evm_main.c b/security/integrity/evm/evm_main.c index f625196eee8e..9faebff029e6 100644 --- a/security/integrity/evm/evm_main.c +++ b/security/integrity/evm/evm_main.c @@ -27,7 +27,8 @@ int evm_initialized; static const char * const integrity_status_msg[] = { - "pass", "pass_immutable", "fail", "no_label", "no_xattrs", "unknown" + "pass", "pass_immutable", "fail", "fail_immutable", "no_label", + "no_xattrs", "unknown" }; int evm_hmac_attrs; @@ -155,7 +156,7 @@ static enum integrity_status evm_verify_hmac(struct dentry *dentry, enum integrity_status evm_status = INTEGRITY_PASS; struct evm_digest digest; struct inode *inode; - int rc, xattr_len; + int rc, xattr_len, evm_immutable = 0; if (iint && (iint->evm_status == INTEGRITY_PASS || iint->evm_status == INTEGRITY_PASS_IMMUTABLE)) @@ -200,8 +201,10 @@ static enum integrity_status evm_verify_hmac(struct dentry *dentry, if (rc) rc = -EINVAL; break; - case EVM_IMA_XATTR_DIGSIG: case EVM_XATTR_PORTABLE_DIGSIG: + evm_immutable = 1; + fallthrough; + case EVM_IMA_XATTR_DIGSIG: /* accept xattr with non-empty signature field */ if (xattr_len <= sizeof(struct signature_v2_hdr)) { evm_status = INTEGRITY_FAIL; @@ -238,9 +241,14 @@ static enum integrity_status evm_verify_hmac(struct dentry *dentry, break; } - if (rc) - evm_status = (rc == -ENODATA) ? - INTEGRITY_NOXATTRS : INTEGRITY_FAIL; + if (rc) { + if (rc == -ENODATA) + evm_status = INTEGRITY_NOXATTRS; + else if (evm_immutable) + evm_status = INTEGRITY_FAIL_IMMUTABLE; + else + evm_status = INTEGRITY_FAIL; + } out: if (iint) iint->evm_status = evm_status; @@ -379,6 +387,14 @@ static int evm_protect_xattr(struct dentry *dentry, const char *xattr_name, /* Exception if the HMAC is not going to be calculated. */ if (evm_hmac_disabled() && evm_status == INTEGRITY_NOLABEL) return 0; + + /* + * Writing other xattrs is safe for portable signatures, as portable + * signatures are immutable and can never be updated. + */ + if (evm_status == INTEGRITY_FAIL_IMMUTABLE) + return 0; + if (evm_status != INTEGRITY_PASS) integrity_audit_msg(AUDIT_INTEGRITY_METADATA, d_backing_inode(dentry), dentry->d_name.name, "appraise_metadata", @@ -539,8 +555,13 @@ int evm_inode_setattr(struct dentry *dentry, struct iattr *attr) if (!(ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID))) return 0; evm_status = evm_verify_current_integrity(dentry); + /* + * Writing attrs is safe for portable signatures, as portable signatures + * are immutable and can never be updated. + */ if ((evm_status == INTEGRITY_PASS) || (evm_status == INTEGRITY_NOXATTRS) || + (evm_status == INTEGRITY_FAIL_IMMUTABLE) || (evm_hmac_disabled() && evm_status == INTEGRITY_NOLABEL)) return 0; integrity_audit_msg(AUDIT_INTEGRITY_METADATA, d_backing_inode(dentry), diff --git a/security/integrity/ima/ima_appraise.c b/security/integrity/ima/ima_appraise.c index ddac9e727d3a..6d0983a97711 100644 --- a/security/integrity/ima/ima_appraise.c +++ b/security/integrity/ima/ima_appraise.c @@ -416,6 +416,8 @@ int ima_appraise_measurement(enum ima_hooks func, case INTEGRITY_NOLABEL: /* No security.evm xattr. */ cause = "missing-HMAC"; goto out; + case INTEGRITY_FAIL_IMMUTABLE: + fallthrough; case INTEGRITY_FAIL: /* Invalid HMAC/signature. */ cause = "invalid-HMAC"; goto out; -- 2.25.1