Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp808982pxj; Fri, 14 May 2021 17:05:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw63He8qH8XaZ+GfexceccB8o/WNp/grG5AyAZAsgFBGLAjWsGTaAyRLfi91Zk5iTr+F9UE X-Received: by 2002:a17:906:6b92:: with SMTP id l18mr1067627ejr.367.1621037132246; Fri, 14 May 2021 17:05:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621037132; cv=none; d=google.com; s=arc-20160816; b=aP/kUX8UHxiq+Xf+ZMwDzR3I2nD8aUDies2b2FPMgSv/TcBCQTM4e7yYMOR24tjea4 1JxhzzabF+4eHkC89ijo1r+0tyczbZQlW1KbRrPXmlkfcmD8iHJoSNR5zxzm1QkR+uor CpMmeSAKG/QR9swAxmjJ5rx5xLuzDNAc2PmKVBbrkAsV9S7gNOhtA9wThFyCD92huLLf lz1/7RPR9wpnnbUf5QL8cHdpLxkwDivhqYGFSuF5c65eBWQ3PNSsMn2515gMIwOMehiH VmQm8TxvaWchb09nJ4LC+rBmivG7rQXh5qWF83ji+hpqbSG2y2x5ckkwW9LG7Szsn/Jm wTDw== 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=Q2/wgVJqYNOqiIR3Ngqbi5BlDn9PERZaGmwTglkRXlg=; b=DMoP1xoMG2kGTxhi27d17iXKoVpjaj0ZU/WAwBDMx0BC/kto3vEMlu6cB2o84Jl2nP pxCCMH8qT1Ok0zLH6zEtyHBgWsAggtxO171Rh2l+lokj8Z36yzC/yoqse7/vMTNWLQxk PGIq0TyDWrpXdnGAJTRb34X0RKRpPmMDI4Lxt3SqwBRt9lZ1uK6OJhKIwQiXjb+oHdIf KTuLhAASYi6v5pgeIHfTCvqHIP8/I94hq77Thfvt+KVX+7ZwGmUaIOMm5H2jC2+1G7+b OpcnRCzGPXgFL9xcXIY9J3wNp6raNT8uKDZ6QzgOcfk4EoFBGfWt1gJKoob/i8sISZjJ 5zEQ== 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 a42si8817298edf.319.2021.05.14.17.05.09; Fri, 14 May 2021 17:05:32 -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 S234738AbhENPbs (ORCPT + 99 others); Fri, 14 May 2021 11:31:48 -0400 Received: from frasgout.his.huawei.com ([185.176.79.56]:3078 "EHLO frasgout.his.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231218AbhENPbs (ORCPT ); Fri, 14 May 2021 11:31:48 -0400 Received: from fraeml714-chm.china.huawei.com (unknown [172.18.147.207]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4FhXPs01jNz6cw7x; Fri, 14 May 2021 23:24:33 +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; Fri, 14 May 2021 17:30:34 +0200 From: Roberto Sassu To: , CC: , , , Roberto Sassu Subject: [PATCH v7 10/12] ima: Allow imasig requirement to be satisfied by EVM portable signatures Date: Fri, 14 May 2021 17:27:51 +0200 Message-ID: <20210514152753.982958-11-roberto.sassu@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210514152753.982958-1-roberto.sassu@huawei.com> References: <20210514152753.982958-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: 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 9bb351b933fb..d9a627de3930 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; } @@ -581,6 +589,8 @@ int ima_inode_setxattr(struct dentry *dentry, const char *xattr_name, if (!xattr_value_len || (xvalue->type >= IMA_XATTR_LAST)) return -EINVAL; digsig = (xvalue->type == EVM_IMA_XATTR_DIGSIG); + } else if (!strcmp(xattr_name, XATTR_NAME_EVM) && xattr_value_len > 0) { + digsig = (xvalue->type == EVM_XATTR_PORTABLE_DIGSIG); } if (result == 1 || evm_revalidate_status(xattr_name)) { ima_reset_appraise_flags(d_backing_inode(dentry), digsig); -- 2.25.1