Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1460468ybt; Thu, 18 Jun 2020 09:10:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzJX/IvAl2sdEMxA1Wvfj4dyNUYe0bQSWM6sAC1oPYMUfq855AXsCRwuSt+hHJPUDBUSRXv X-Received: by 2002:aa7:c758:: with SMTP id c24mr4677426eds.290.1592496614786; Thu, 18 Jun 2020 09:10:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592496614; cv=none; d=google.com; s=arc-20160816; b=igF6rQ3Zyk8OtwDqLvRZTSdauQppmfO83KJPUXIrK1vnafvAFj+RxRyHAXFGWXwq7P 67lrrQTbAJ7ACs4S7c+YQqnjZTNPTVpmhR0yjfHSTa5HhCA3Z4kf2hD6RTBnlaJPNt+7 jKgKksF2cjcF1XjcZH9y8/AOknk6r4v9NiO27CyZvdbLjXDO5v+oG8AZZN7C4RWznwmF TzwvuaEapQyIAm9TbuWMmkzwCutMLdSYEIeS4Sgy24HvfMkLm0Bst4ktuHh7iJ5jEUzT Mc6+lpYsGzI6v3zLkepJxj+r10hedlbRC+pvZibbZ3e+M5feGD8vNoQuWIO0g/40UBkh Fqww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=rqiGS49F8MMELNIATWFAebapJQp7BsvOQ5Hhp286poo=; b=bIGSxTmDCs2aW3n0Oi9mkS7ww0yiKxLkk7RsYQ2diWY2pLSm2jqRQTpy3kxinADS2K kIP6WVO7eQuARiQ0H+Kb5uIPrHFIIhGauMs6rOU57uPO9CllGM64BBrNjCt6dF+Kj75z u/euILxNMPP2lAifnueHc1TFlV/2R5AlL/R2ReY6CpE4/GbWvy43Zh4OYu28iVr8gzPW 7b0xnIGRaR9vsIJ/xsJipgMJsE5AfQwnLQpf/3+80KpqvcU4R9UyzSXFEA1Cil0+25bj llIKcrdrxPCmXaKE4hR96gXl26RXFASFuHKhFgyLKW4GKgAE/OFbl2+B31zjbHqtxHKX I97A== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v22si2237716edy.558.2020.06.18.09.09.51; Thu, 18 Jun 2020 09:10:14 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731858AbgFRQHy (ORCPT + 99 others); Thu, 18 Jun 2020 12:07:54 -0400 Received: from lhrrgout.huawei.com ([185.176.76.210]:2338 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728008AbgFRQHm (ORCPT ); Thu, 18 Jun 2020 12:07:42 -0400 Received: from lhreml720-chm.china.huawei.com (unknown [172.18.7.106]) by Forcepoint Email with ESMTP id 24093DC22CC506F26122; Thu, 18 Jun 2020 17:07:40 +0100 (IST) Received: from fraeml714-chm.china.huawei.com (10.206.15.33) by lhreml720-chm.china.huawei.com (10.201.108.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1913.5; Thu, 18 Jun 2020 17:07:39 +0100 Received: from roberto-HP-EliteDesk-800-G2-DM-65W.huawei.com (10.204.65.160) by fraeml714-chm.china.huawei.com (10.206.15.33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.1913.5; Thu, 18 Jun 2020 18:07:38 +0200 From: Roberto Sassu To: , CC: , , , , Roberto Sassu Subject: [PATCH 08/11] ima: Allow imasig requirement to be satisfied by EVM portable signatures Date: Thu, 18 Jun 2020 18:04:55 +0200 Message-ID: <20200618160458.1579-8-roberto.sassu@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200618160329.1263-2-roberto.sassu@huawei.com> References: <20200618160329.1263-2-roberto.sassu@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.204.65.160] X-ClientProxiedBy: lhreml704-chm.china.huawei.com (10.201.108.53) To fraeml714-chm.china.huawei.com (10.206.15.33) X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org 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, only IMA signatures satisfy this requirement. IMA 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 at least the same guarantees of IMA signatures. 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 --- security/integrity/ima/ima_appraise.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/security/integrity/ima/ima_appraise.c b/security/integrity/ima/ima_appraise.c index 21bda264fc30..9505bb390d90 100644 --- a/security/integrity/ima/ima_appraise.c +++ b/security/integrity/ima/ima_appraise.c @@ -219,12 +219,16 @@ static int xattr_verify(enum ima_hooks func, struct integrity_iint_cache *iint, hash_start = 1; /* fall through */ 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) /* @@ -394,6 +398,8 @@ 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"; goto out; @@ -437,9 +443,9 @@ int ima_appraise_measurement(enum ima_hooks func, status = INTEGRITY_PASS; } - /* Permit new files with file signatures, but without data. */ + /* Permit new files marked as immutable, 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; } -- 2.17.1