sxgbe: Fix off by one in samsung driver strncpy size arg
[linux/fpc-iii.git] / fs / verity / measure.c
blob05049b68c74553fb6b865818c989b00e5c2da36e
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * fs/verity/measure.c: ioctl to get a verity file's measurement
5 * Copyright 2019 Google LLC
6 */
8 #include "fsverity_private.h"
10 #include <linux/uaccess.h>
12 /**
13 * fsverity_ioctl_measure() - get a verity file's measurement
15 * Retrieve the file measurement that the kernel is enforcing for reads from a
16 * verity file. See the "FS_IOC_MEASURE_VERITY" section of
17 * Documentation/filesystems/fsverity.rst for the documentation.
19 * Return: 0 on success, -errno on failure
21 int fsverity_ioctl_measure(struct file *filp, void __user *_uarg)
23 const struct inode *inode = file_inode(filp);
24 struct fsverity_digest __user *uarg = _uarg;
25 const struct fsverity_info *vi;
26 const struct fsverity_hash_alg *hash_alg;
27 struct fsverity_digest arg;
29 vi = fsverity_get_info(inode);
30 if (!vi)
31 return -ENODATA; /* not a verity file */
32 hash_alg = vi->tree_params.hash_alg;
35 * The user specifies the digest_size their buffer has space for; we can
36 * return the digest if it fits in the available space. We write back
37 * the actual size, which may be shorter than the user-specified size.
40 if (get_user(arg.digest_size, &uarg->digest_size))
41 return -EFAULT;
42 if (arg.digest_size < hash_alg->digest_size)
43 return -EOVERFLOW;
45 memset(&arg, 0, sizeof(arg));
46 arg.digest_algorithm = hash_alg - fsverity_hash_algs;
47 arg.digest_size = hash_alg->digest_size;
49 if (copy_to_user(uarg, &arg, sizeof(arg)))
50 return -EFAULT;
52 if (copy_to_user(uarg->digest, vi->measurement, hash_alg->digest_size))
53 return -EFAULT;
55 return 0;
57 EXPORT_SYMBOL_GPL(fsverity_ioctl_measure);