]>
git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blob - fs/verity/measure.c
1 // SPDX-License-Identifier: GPL-2.0
3 * fs/verity/measure.c: ioctl to get a verity file's measurement
5 * Copyright 2019 Google LLC
8 #include "fsverity_private.h"
10 #include <linux/uaccess.h>
13 * fsverity_ioctl_measure() - get a verity file's measurement
14 * @filp: file to get measurement of
15 * @_uarg: user pointer to fsverity_digest
17 * Retrieve the file measurement that the kernel is enforcing for reads from a
18 * verity file. See the "FS_IOC_MEASURE_VERITY" section of
19 * Documentation/filesystems/fsverity.rst for the documentation.
21 * Return: 0 on success, -errno on failure
23 int fsverity_ioctl_measure(struct file
*filp
, void __user
*_uarg
)
25 const struct inode
*inode
= file_inode(filp
);
26 struct fsverity_digest __user
*uarg
= _uarg
;
27 const struct fsverity_info
*vi
;
28 const struct fsverity_hash_alg
*hash_alg
;
29 struct fsverity_digest arg
;
31 vi
= fsverity_get_info(inode
);
33 return -ENODATA
; /* not a verity file */
34 hash_alg
= vi
->tree_params
.hash_alg
;
37 * The user specifies the digest_size their buffer has space for; we can
38 * return the digest if it fits in the available space. We write back
39 * the actual size, which may be shorter than the user-specified size.
42 if (get_user(arg
.digest_size
, &uarg
->digest_size
))
44 if (arg
.digest_size
< hash_alg
->digest_size
)
47 memset(&arg
, 0, sizeof(arg
));
48 arg
.digest_algorithm
= hash_alg
- fsverity_hash_algs
;
49 arg
.digest_size
= hash_alg
->digest_size
;
51 if (copy_to_user(uarg
, &arg
, sizeof(arg
)))
54 if (copy_to_user(uarg
->digest
, vi
->measurement
, hash_alg
->digest_size
))
59 EXPORT_SYMBOL_GPL(fsverity_ioctl_measure
);