Received: by 2002:ab2:69cc:0:b0:1f4:be93:e15a with SMTP id n12csp1545171lqp; Mon, 15 Apr 2024 09:22:13 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUEZEwpt6ha1jbkPByHk3MOHzjN5Sj8WkO41dqUJRvTRXf+gWy1K7t2MJUsvteRLzWvWo/uy0z8S0IkJ7GgbyapKGsFjsIeDNxnk3o5Kg== X-Google-Smtp-Source: AGHT+IFlgnUU/kU+bW+emtj1nKF0BSa+lGVpt7lD8KeA/wd3kmkl+VT2qXwr2huUuN8Qy+lVl0oj X-Received: by 2002:a05:6a20:a11d:b0:1a7:7bc4:e214 with SMTP id q29-20020a056a20a11d00b001a77bc4e214mr11335359pzk.7.1713198133016; Mon, 15 Apr 2024 09:22:13 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713198133; cv=pass; d=google.com; s=arc-20160816; b=GzRQmkSDDrqyDR/HhhXKELiGCnvplQqjfiRj2+zsmDSpwX/m4twBm2++wIxHnbzRjK k0KN88Mxt0Q+aCvb+8cEmDBJsoggyC4+9XTcfrWf7VVHJ0F3dxDqfg9hgKGXXP8my1Er kML/RPTa59gpwiaEdYPr02zu4hn/8mvT/jtSnavO4A2XRcHWtEzZ8TUQ+Hm/1vHiOLwa TawOjUGxisyJgWRq/23kpo8YYwDXj4jjpX+mPo5jeEV79to7Td/BDtt/WrCAPQVrbK+g YlTN/AaT1/UrIX3Hd5c+2we+iyryMM+YrqmZkTmbHC8nllWpeKxYMdPuNGtVnTLA/Sgg YOpw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=1sYHn5iMGd4znEEID12QYnA8kyJgEOhFYsXpQZrTeTQ=; fh=F8wSLrSynnSgKRChnHx8yDJNkDxnE8NrN57nkyJpkWA=; b=ROyOrwYl49mjMWO9Tt6u3aQeybBVzvJOwOBIycvk5U8pdv39vVaczt85P9JejBdLch cUf2FsGNMCbzVM7ySO9Z5GKaXXMsPSdB+VpSwpwixa4ws17HxlUr/mauTOKXG33iKZ6q efiL7Vljs7Tw2stMdEanP7RgZ4RhDuXIr48Su7VAlIvnpQFaHKvjq1Wd8yEOxwrSXDNX 6JsNbrB3Pt8kStVsLDrR3U5q7r1hK0dYl5nXeN5KS1U+eq85AQVW9U1f7mhFtNHEOK1T +WyOxcgxrCbfBsbqJKDJH93V2XjVvOHFnQlLshA+DmALaHMcwCOxVpA9XfuXR2PeSwEg 0hsQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-kernel+bounces-145524-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-145524-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 20-20020a630114000000b005cee9117ef6si8176380pgb.810.2024.04.15.09.22.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Apr 2024 09:22:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-145524-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-kernel+bounces-145524-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-145524-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 372A5286837 for ; Mon, 15 Apr 2024 16:15:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2054E8527D; Mon, 15 Apr 2024 16:13:15 +0000 (UTC) Received: from frasgout11.his.huawei.com (frasgout11.his.huawei.com [14.137.139.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9FDB984D0F; Mon, 15 Apr 2024 16:13:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=14.137.139.23 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713197594; cv=none; b=PMmjLiA5VKM7yhLwGmL6/ci5jpEVIDsLMQ+GA5682rQ2mSq/EB41NhBQ6RmITGxR16iLt6eMuWKAonYeJ0Htr+5/kx7SZ2msdVQRvasghoun61eORxkFUo1KyBE1n32pcj8/m/szLeV1aNSt7OgIO/bU/D/peMAEsDU1zWcbIas= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713197594; c=relaxed/simple; bh=PoVu1zT5xkQsZ4kp0hfNGuar5mykAljYwYgLbKEw6OE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=li3+otRapvQGQBo2cz4kJLS4rucPglYr6BbbGV8s8fx1qaWP3qmgGQr2l7PVZisma3MYylJlugrVUgWdgx9XtlPifNDM2YJgFS1MMdf4aDczK2XsZcGq46OZ5Y30NU12FiyHQOw62Yr+5a/pbY6YD9vbwD51zKFtfOPScHI+RTo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=14.137.139.23 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.18.186.51]) by frasgout11.his.huawei.com (SkyGuard) with ESMTP id 4VJBcS4DNQz9xGhS; Mon, 15 Apr 2024 23:56:40 +0800 (CST) Received: from mail02.huawei.com (unknown [7.182.16.27]) by mail.maildlp.com (Postfix) with ESMTP id A7F63140159; Tue, 16 Apr 2024 00:13:09 +0800 (CST) Received: from huaweicloud.com (unknown [10.204.63.22]) by APP2 (Coremail) with SMTP id GxC2BwDn0iaZUR1m4n9HBg--.16529S10; Mon, 15 Apr 2024 17:13:09 +0100 (CET) From: Roberto Sassu To: corbet@lwn.net, zohar@linux.ibm.com, dmitry.kasatkin@gmail.com, eric.snowberg@oracle.com, paul@paul-moore.com, jmorris@namei.org, serge@hallyn.com Cc: linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org, wufan@linux.microsoft.com, pbrobinson@gmail.com, zbyszek@in.waw.pl, hch@lst.de, mjg59@srcf.ucam.org, pmatilai@redhat.com, jannh@google.com, dhowells@redhat.com, jikos@kernel.org, mkoutny@suse.com, ppavlu@suse.com, petr.vorel@gmail.com, mzerqung@0pointer.de, kgold@linux.ibm.com, Roberto Sassu Subject: [RFC][PATCH v2 8/9] ima: Use digest caches for appraisal Date: Mon, 15 Apr 2024 18:10:43 +0200 Message-Id: <20240415161044.2572438-9-roberto.sassu@huaweicloud.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240415161044.2572438-1-roberto.sassu@huaweicloud.com> References: <20240415161044.2572438-1-roberto.sassu@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID:GxC2BwDn0iaZUR1m4n9HBg--.16529S10 X-Coremail-Antispam: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BIdaVFxhVjvjDU0xZFpf9x 07j7GYLUUUUU= X-CM-SenderInfo: purev21wro2thvvxqx5xdzvxpfor3voofrz/1tbiAQAOBF1jj5x3GgAAsL From: Roberto Sassu Similarly to measurement, enable the new appraisal style too using digest caches. Instead of verifying individual file signatures, verify the signature of lists of digests and search calculated file digests in those lists. The benefits are that signed lists of digests already exist (e.g. RPM package headers), although their format needs to be supported by the digest_cache LSM, and appraisal with digest lists is computationally much less expensive than with individual file signatures (see the performance evaluation of the digest_cache LSM). Take the allowed usage after the call to ima_digest_cache_update_allowed_usage(), and pass it to ima_appraise_measurement(). If EVM is disabled or the file does not have any protected xattr (evm_verifyxattr() returns INTEGRITY_UNKNOWN or INTEGRITY_NOXATTRS) and the allowed usage has the IMA_DIGEST_CACHE_APPRAISE_DATA flag set, mark the file as successfully appraised (i.e. set the integrity status to INTEGRITY_PASS and return zero). The digest cache method is tried first, for performance reasons, in the event there are for example IMA signatures in the system (which are computationally more expensive to verify). The usage of the digest_cache LSM has anyway to be authorized in the IMA policy. Signed-off-by: Roberto Sassu --- security/integrity/ima/ima.h | 6 ++++-- security/integrity/ima/ima_appraise.c | 30 ++++++++++++++++++++------- security/integrity/ima/ima_main.c | 3 ++- 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h index 865137dfcf22..1f0810be9f8a 100644 --- a/security/integrity/ima/ima.h +++ b/security/integrity/ima/ima.h @@ -432,7 +432,8 @@ int ima_check_blacklist(struct ima_iint_cache *iint, int ima_appraise_measurement(enum ima_hooks func, struct ima_iint_cache *iint, struct file *file, const unsigned char *filename, struct evm_ima_xattr_data *xattr_value, - int xattr_len, const struct modsig *modsig); + int xattr_len, const struct modsig *modsig, + u64 allowed_usage); int ima_must_appraise(struct mnt_idmap *idmap, struct inode *inode, int mask, enum ima_hooks func); void ima_update_xattr(struct ima_iint_cache *iint, struct file *file); @@ -457,7 +458,8 @@ static inline int ima_appraise_measurement(enum ima_hooks func, const unsigned char *filename, struct evm_ima_xattr_data *xattr_value, int xattr_len, - const struct modsig *modsig) + const struct modsig *modsig, + u64 allowed_usage) { return INTEGRITY_UNKNOWN; } diff --git a/security/integrity/ima/ima_appraise.c b/security/integrity/ima/ima_appraise.c index 27ccc9a2c09f..3b4d6491e69e 100644 --- a/security/integrity/ima/ima_appraise.c +++ b/security/integrity/ima/ima_appraise.c @@ -478,7 +478,8 @@ int ima_check_blacklist(struct ima_iint_cache *iint, int ima_appraise_measurement(enum ima_hooks func, struct ima_iint_cache *iint, struct file *file, const unsigned char *filename, struct evm_ima_xattr_data *xattr_value, - int xattr_len, const struct modsig *modsig) + int xattr_len, const struct modsig *modsig, + u64 allowed_usage) { static const char op[] = "appraise_data"; const char *cause = "unknown"; @@ -488,12 +489,18 @@ int ima_appraise_measurement(enum ima_hooks func, struct ima_iint_cache *iint, int rc = xattr_len; bool try_modsig = iint->flags & IMA_MODSIG_ALLOWED && modsig; - /* If not appraising a modsig, we need an xattr. */ - if (!(inode->i_opflags & IOP_XATTR) && !try_modsig) + /* + * If not appraising a modsig/there is no digest cache match, we need + * an xattr. + */ + if (!(inode->i_opflags & IOP_XATTR) && !try_modsig && !allowed_usage) return INTEGRITY_UNKNOWN; - /* If reading the xattr failed and there's no modsig, error out. */ - if (rc <= 0 && !try_modsig) { + /* + * If reading the xattr failed and there's no modsig/digest cache match, + * error out. + */ + if (rc <= 0 && !try_modsig && !allowed_usage) { if (rc && rc != -ENODATA) goto out; @@ -524,8 +531,11 @@ int ima_appraise_measurement(enum ima_hooks func, struct ima_iint_cache *iint, case INTEGRITY_UNKNOWN: break; case INTEGRITY_NOXATTRS: /* No EVM protected xattrs. */ - /* It's fine not to have xattrs when using a modsig. */ - if (try_modsig) + /* + * It's fine not to have xattrs when using a modsig or the + * digest cache. + */ + if (try_modsig || allowed_usage) break; fallthrough; case INTEGRITY_NOLABEL: /* No security.evm xattr. */ @@ -542,6 +552,12 @@ int ima_appraise_measurement(enum ima_hooks func, struct ima_iint_cache *iint, WARN_ONCE(true, "Unexpected integrity status %d\n", status); } + if (allowed_usage & IMA_DIGEST_CACHE_APPRAISE_DATA) { + status = INTEGRITY_PASS; + rc = 0; + goto out; + } + if (xattr_value) rc = xattr_verify(func, iint, xattr_value, xattr_len, &status, &cause); diff --git a/security/integrity/ima/ima_main.c b/security/integrity/ima/ima_main.c index 0ff5de9bef70..7ae2bd888d41 100644 --- a/security/integrity/ima/ima_main.c +++ b/security/integrity/ima/ima_main.c @@ -384,7 +384,8 @@ static int process_measurement(struct file *file, const struct cred *cred, inode_lock(inode); rc = ima_appraise_measurement(func, iint, file, pathname, xattr_value, - xattr_len, modsig); + xattr_len, modsig, + digest_cache_usage); inode_unlock(inode); } if (!rc) -- 2.34.1