Re: [PATCH v1 1/5] fs-verity: define a function to return the integrity protected file digest

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Dec 02, 2021 at 04:55:03PM -0500, Mimi Zohar wrote:
> +
> +/**
> + * fsverity_collect_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_collect_digest(struct inode *inode,
> +			    u8 digest[FS_VERITY_MAX_DIGEST_SIZE],
> +			    enum hash_algo *alg)

I'd still prefer that this be named fsverity_get_digest(), but this is fine too.

> +{
> +	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);
> +	*alg = HASH_ALGO__LAST;
> +
> +	/* convert hash algorithm to hash_algo_name */
> +	for (i = 0; i < HASH_ALGO__LAST; i++) {
> +		pr_debug("name %s hash_algo_name[%d] %s\n",
> +			  hash_alg->name, i, hash_algo_name[i]);
> +
> +		if (!strcmp(hash_alg->name, hash_algo_name[i])) {
> +			*alg = i;
> +			break;
> +		}
> +	}

How about using match_string() here?

> +	pr_debug("file digest:%s %*phN\n", hash_algo_name[*alg],
> +		  hash_digest_size[*alg], digest);

Other log messages in fs/verity/ use the format alg:hash.  How about using
"file_digest %s:%*phN\n" as the format string here?

- Eric



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux Kernel]     [Linux Kernel Hardening]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux SCSI]

  Powered by Linux