summaryrefslogtreecommitdiffstats
path: root/fs/verity/measure.c
diff options
context:
space:
mode:
authorEric Biggers <ebiggers@google.com>2022-11-28 20:51:39 -0800
committerEric Biggers <ebiggers@google.com>2022-11-29 21:07:41 -0800
commita4bbf53d88c728da9ff6c316b1e4ded63a8f3940 (patch)
tree0462f2ab83d7d9e8fe49c98a6625baf62135bcf7 /fs/verity/measure.c
parent98dc08bae6780bb950b5c0cdefeb662b22482655 (diff)
downloadlinux-a4bbf53d88c728da9ff6c316b1e4ded63a8f3940.tar.gz
linux-a4bbf53d88c728da9ff6c316b1e4ded63a8f3940.tar.bz2
linux-a4bbf53d88c728da9ff6c316b1e4ded63a8f3940.zip
fsverity: simplify fsverity_get_digest()
Instead of looking up the algorithm by name in hash_algo_name[] to get its hash_algo ID, just store the hash_algo ID in the fsverity_hash_alg struct. Verify at boot time that every fsverity_hash_alg has a valid hash_algo ID with matching digest size. Remove an unnecessary memset() of the whole digest array to 0 before the digest is copied into it. Finally, remove the pr_debug statement. There is already a pr_debug for the fsverity digest when the file is opened. Signed-off-by: Eric Biggers <ebiggers@google.com> Reviewed-by: Mimi Zohar <zohar@linux.ibm.com> Link: https://lore.kernel.org/r/20221129045139.69803-1-ebiggers@kernel.org
Diffstat (limited to 'fs/verity/measure.c')
-rw-r--r--fs/verity/measure.c19
1 files changed, 2 insertions, 17 deletions
diff --git a/fs/verity/measure.c b/fs/verity/measure.c
index e99c00350c28..5c79ea1b2468 100644
--- a/fs/verity/measure.c
+++ b/fs/verity/measure.c
@@ -65,8 +65,7 @@ EXPORT_SYMBOL_GPL(fsverity_ioctl_measure);
* @alg: (out) pointer to the hash algorithm enumeration
*
* Return the file hash algorithm and digest of an fsverity protected file.
- * Assumption: before calling fsverity_get_digest(), the file must have been
- * opened.
+ * Assumption: before calling this, the file must have been opened.
*
* Return: 0 on success, -errno on failure
*/
@@ -76,27 +75,13 @@ int fsverity_get_digest(struct inode *inode,
{
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 the verity hash algorithm name to a hash_algo_name enum */
- i = match_string(hash_algo_name, HASH_ALGO__LAST, hash_alg->name);
- if (i < 0)
- return -EINVAL;
- *alg = i;
-
- if (WARN_ON_ONCE(hash_alg->digest_size != hash_digest_size[*alg]))
- return -EINVAL;
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);
-
+ *alg = hash_alg->algo_id;
return 0;
}