Skip to content
Permalink
Browse files
fsverity: Introduce fsverity_get_file_digest()
Since the fsverity_info structure is defined internally in fsverity, expose
the fsverity file digest through the new function
fsverity_get_file_digest().

Given that an fsverity file is guaranteed to be immutable, also the
retrieved file digest is stable and won't change.

Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com>
  • Loading branch information
robertosassu authored and intel-lab-lkp committed Nov 12, 2021
1 parent b828014 commit b954223b18edd435d0bc93893ee4fa0fe47261d2
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
@@ -218,6 +218,30 @@ void fsverity_free_info(struct fsverity_info *vi)
kmem_cache_free(fsverity_info_cachep, vi);
}

/*
* Copy the file digest and associated algorithm taken from the passed
* fsverity_info structure to the locations supplied by the caller.
*
* Return: the digest size on success, a negative value on error
*/
ssize_t fsverity_get_file_digest(struct fsverity_info *info, u8 *buf,
size_t bufsize, enum hash_algo *algo)
{
enum hash_algo a;

a = match_string(hash_algo_name, HASH_ALGO__LAST,
info->tree_params.hash_alg->name);
if (a < 0)
return a;

if (bufsize < hash_digest_size[a])
return -ERANGE;

*algo = a;
memcpy(buf, info->file_digest, hash_digest_size[*algo]);
return hash_digest_size[*algo];
}

static bool validate_fsverity_descriptor(struct inode *inode,
const struct fsverity_descriptor *desc,
size_t desc_size)
@@ -13,6 +13,7 @@

#include <linux/fs.h>
#include <uapi/linux/fsverity.h>
#include <crypto/hash_info.h>

/* Verity operations for filesystems */
struct fsverity_operations {
@@ -137,6 +138,8 @@ int fsverity_ioctl_measure(struct file *filp, void __user *arg);
int fsverity_file_open(struct inode *inode, struct file *filp);
int fsverity_prepare_setattr(struct dentry *dentry, struct iattr *attr);
void fsverity_cleanup_inode(struct inode *inode);
ssize_t fsverity_get_file_digest(struct fsverity_info *info, u8 *buf,
size_t bufsize, enum hash_algo *algo);

/* read_metadata.c */

@@ -187,6 +190,13 @@ static inline void fsverity_cleanup_inode(struct inode *inode)
{
}

static inline ssize_t fsverity_get_file_digest(struct fsverity_info *info,
u8 *buf, size_t bufsize,
enum hash_algo *algo)
{
return -EOPNOTSUPP;
}

/* read_metadata.c */

static inline int fsverity_ioctl_read_metadata(struct file *filp,

0 comments on commit b954223

Please sign in to comment.