Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp5133398pxb; Wed, 26 Jan 2022 05:38:22 -0800 (PST) X-Google-Smtp-Source: ABdhPJyPWv0qW+KpA3IEobRxy4MN5iwQ/+sxCeGnxuD9Ta6uqK8IVDxlu7pjzQr5MdWhhX6AEH6g X-Received: by 2002:a17:907:2d8d:: with SMTP id gt13mr19499769ejc.590.1643204302294; Wed, 26 Jan 2022 05:38:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643204302; cv=none; d=google.com; s=arc-20160816; b=Sl9htInz7EtZkmwgu1DBrMvdfaEGDWHLR2kqNuQkY8HHkyOy8HkV6Z5YtfsesjBMDm e1qAOoODBrH1ZrUMtJazMQGdSp2yytH10adDk0YFYR45LU9Flfezo+kZrAKDarnWtLIx Di9nCA+doQhPpDh09gzY/nbN18cXV4EQNqtEahOmnC5FaMQXB25GH5uh5BHrS7UOKth5 fV7bzK9itCKNDQq51kfczFCjz5FH/30oysbU03ByQ8Njb5Lx3s9yqJH/7siBDV3YRy+0 yeOwxe9MrSDFn4odMWMnKgX3EthohWywS8rb8nsrI8A0dvIBmh+9nL7kGBWXyg+oMCiS PQdA== 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 :dkim-signature; bh=9HkkflENhczYHDDccj59lqRxj+7tIOqWXMdoYuuTz2s=; b=px0NV2QbLr0nALixqenV76+aM6Ch4ObUH4wa0hy0qSdLB9HNO3niJ8ziUaIOmrZa0x Zy3oXjLVXoJlJ7PQebkXRby5+0X0+Q/CJ2FugLMUsykrAWwZfr2Ud7WDEKO/iZnE8JSy I/0ZGJGbHVbQHM0QJ0ciFXKsnJwgrqJntkn+jptpevcALs6HXjeq+wDcWZbGTf2WSAUX mTwmfIZjV1cDtBMZIilb8LmSKgZBDuMieCviXq6bEHDW8MWyDaCkJuKHQjyC/opwuWJ9 V408bxRAqgpOQFQV0eDisPPYRpEm9D6JA8kO1PjN1n9VWzjceTTu9JrdmiocJzxgM37h /k4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=K3le10E+; 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=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m18si4350877ejn.786.2022.01.26.05.37.55; Wed, 26 Jan 2022 05:38:22 -0800 (PST) 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; dkim=pass header.i=@ibm.com header.s=pp1 header.b=K3le10E+; 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=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235190AbiAZAH0 (ORCPT + 99 others); Tue, 25 Jan 2022 19:07:26 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:5034 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235131AbiAZAHT (ORCPT ); Tue, 25 Jan 2022 19:07:19 -0500 Received: from pps.filterd (m0098394.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 20PNeKbO031888; Wed, 26 Jan 2022 00:07:17 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=9HkkflENhczYHDDccj59lqRxj+7tIOqWXMdoYuuTz2s=; b=K3le10E+IU0fjrpp1NJBTWzVti1FDXES/Lk8YD/JuzUTIMN0VV12von1IdDL7OpWxige GBlFgUfikGruApqk5Ah2OSdBDnXGReJig6tmAj0mvjOBHNV0AUONjYmQItdoDg1hCrMg cobnXo9JfuHEdAoHMVIY5i921M2CoUAuJSD1JgejzNbLluUFqRjRNrUQ5+13m35RKu4T vy2TgjB8ZRI6kVrtx4M9Zu2t7mLeYVYwwu4f9m31zprarSOKO17kKtFhDEHptg7AWbqZ vKI2fFwAjpdMeAjS21LOcL4e34OeW+u9iS+LhBwIFckkA6kLduhdPW3PtJ0pQrH+wEwe 0w== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3dtsbehvqy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 26 Jan 2022 00:07:16 +0000 Received: from m0098394.ppops.net (m0098394.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 20PNf6At007817; Wed, 26 Jan 2022 00:07:16 GMT Received: from ppma06ams.nl.ibm.com (66.31.33a9.ip4.static.sl-reverse.com [169.51.49.102]) by mx0a-001b2d01.pphosted.com with ESMTP id 3dtsbehvq5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 26 Jan 2022 00:07:16 +0000 Received: from pps.filterd (ppma06ams.nl.ibm.com [127.0.0.1]) by ppma06ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 20Q02jWL019338; Wed, 26 Jan 2022 00:07:13 GMT Received: from b06cxnps4075.portsmouth.uk.ibm.com (d06relay12.portsmouth.uk.ibm.com [9.149.109.197]) by ppma06ams.nl.ibm.com with ESMTP id 3dr96jjb2p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 26 Jan 2022 00:07:13 +0000 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 20Q07AKP43450764 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 26 Jan 2022 00:07:10 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B63A04C050; Wed, 26 Jan 2022 00:07:10 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C993D4C040; Wed, 26 Jan 2022 00:07:09 +0000 (GMT) Received: from li-f45666cc-3089-11b2-a85c-c57d1a57929f.ibm.com.com (unknown [9.65.78.94]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP; Wed, 26 Jan 2022 00:07:09 +0000 (GMT) From: Mimi Zohar To: linux-integrity@vger.kernel.org Cc: Mimi Zohar , Eric Biggers , Stefan Berger , linux-fscrypt@vger.kernel.org, linux-kernel@vger.kernel.org, Eric Biggers Subject: [PATCH v3 3/8] fs-verity: define a function to return the integrity protected file digest Date: Tue, 25 Jan 2022 19:06:53 -0500 Message-Id: <20220126000658.138345-4-zohar@linux.ibm.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20220126000658.138345-1-zohar@linux.ibm.com> References: <20220126000658.138345-1-zohar@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: TzUIJP6ct108gSSPodi4Hi7knBEOy0c2 X-Proofpoint-GUID: ZPhYOY_nWCA8BgT76Mz1mo7nEwUDdDQr X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.816,Hydra:6.0.425,FMLib:17.11.62.513 definitions=2022-01-25_06,2022-01-25_02,2021-12-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 adultscore=0 bulkscore=0 lowpriorityscore=0 spamscore=0 phishscore=0 clxscore=1015 impostorscore=0 priorityscore=1501 mlxlogscore=999 suspectscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2201250145 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Define a function named fsverity_get_digest() to return the verity file digest and the associated hash algorithm (enum hash_algo). Acked-by: Eric Biggers Signed-off-by: Mimi Zohar --- fs/verity/Kconfig | 1 + fs/verity/fsverity_private.h | 7 ------- fs/verity/measure.c | 39 ++++++++++++++++++++++++++++++++++++ include/linux/fsverity.h | 18 +++++++++++++++++ 4 files changed, 58 insertions(+), 7 deletions(-) diff --git a/fs/verity/Kconfig b/fs/verity/Kconfig index 24d1b54de807..54598cd80145 100644 --- a/fs/verity/Kconfig +++ b/fs/verity/Kconfig @@ -3,6 +3,7 @@ config FS_VERITY bool "FS Verity (read-only file-based authenticity protection)" select CRYPTO + select CRYPTO_HASH_INFO # SHA-256 is implied as it's intended to be the default hash algorithm. # To avoid bloat, other wanted algorithms must be selected explicitly. # Note that CRYPTO_SHA256 denotes the generic C implementation, but diff --git a/fs/verity/fsverity_private.h b/fs/verity/fsverity_private.h index a7920434bae5..c6fb62e0ef1a 100644 --- a/fs/verity/fsverity_private.h +++ b/fs/verity/fsverity_private.h @@ -14,7 +14,6 @@ #define pr_fmt(fmt) "fs-verity: " fmt -#include #include #include @@ -26,12 +25,6 @@ struct ahash_request; */ #define FS_VERITY_MAX_LEVELS 8 -/* - * Largest digest size among all hash algorithms supported by fs-verity. - * Currently assumed to be <= size of fsverity_descriptor::root_hash. - */ -#define FS_VERITY_MAX_DIGEST_SIZE SHA512_DIGEST_SIZE - /* A hash algorithm supported by fs-verity */ struct fsverity_hash_alg { struct crypto_ahash *tfm; /* hash tfm, allocated on demand */ diff --git a/fs/verity/measure.c b/fs/verity/measure.c index f0d7b30c62db..2152f115071a 100644 --- a/fs/verity/measure.c +++ b/fs/verity/measure.c @@ -57,3 +57,42 @@ int fsverity_ioctl_measure(struct file *filp, void __user *_uarg) return 0; } EXPORT_SYMBOL_GPL(fsverity_ioctl_measure); + +/** + * fsverity_get_digest() - get a verity file's digest + * @inode: inode to get digest of + * @digest: (out) pointer to the digest + * @alg: (out) pointer to the hash algorithm enumeration + * + * Return the file hash algorithm and digest of an fsverity protected file. + * + * Return: 0 on success, -errno on failure + */ +int fsverity_get_digest(struct inode *inode, + u8 digest[FS_VERITY_MAX_DIGEST_SIZE], + enum hash_algo *alg) +{ + const struct fsverity_info *vi; + const struct fsverity_hash_alg *hash_alg; + int i; + + vi = fsverity_get_info(inode); + if (!vi) + return -ENODATA; /* not a verity file */ + + hash_alg = vi->tree_params.hash_alg; + memset(digest, 0, FS_VERITY_MAX_DIGEST_SIZE); + + /* convert hash algorithm to hash_algo_name */ + i = match_string(hash_algo_name, HASH_ALGO__LAST, hash_alg->name); + if (i < 0) + return -EINVAL; + *alg = i; + + memcpy(digest, vi->file_digest, hash_alg->digest_size); + + pr_debug("file digest %s:%*phN\n", hash_algo_name[*alg], + hash_digest_size[*alg], digest); + + return 0; +} diff --git a/include/linux/fsverity.h b/include/linux/fsverity.h index b568b3c7d095..9a1b70cc7318 100644 --- a/include/linux/fsverity.h +++ b/include/linux/fsverity.h @@ -12,8 +12,16 @@ #define _LINUX_FSVERITY_H #include +#include +#include #include +/* + * Largest digest size among all hash algorithms supported by fs-verity. + * Currently assumed to be <= size of fsverity_descriptor::root_hash. + */ +#define FS_VERITY_MAX_DIGEST_SIZE SHA512_DIGEST_SIZE + /* Verity operations for filesystems */ struct fsverity_operations { @@ -131,6 +139,9 @@ int fsverity_ioctl_enable(struct file *filp, const void __user *arg); /* measure.c */ int fsverity_ioctl_measure(struct file *filp, void __user *arg); +int fsverity_get_digest(struct inode *inode, + u8 digest[FS_VERITY_MAX_DIGEST_SIZE], + enum hash_algo *alg); /* open.c */ @@ -170,6 +181,13 @@ static inline int fsverity_ioctl_measure(struct file *filp, void __user *arg) return -EOPNOTSUPP; } +static inline int fsverity_get_digest(struct inode *inode, + u8 digest[FS_VERITY_MAX_DIGEST_SIZE], + enum hash_algo *alg) +{ + return -EOPNOTSUPP; +} + /* open.c */ static inline int fsverity_file_open(struct inode *inode, struct file *filp) -- 2.27.0