0001
0002
0003
0004
0005
0006
0007
0008 #ifndef _FSVERITY_PRIVATE_H
0009 #define _FSVERITY_PRIVATE_H
0010
0011 #ifdef CONFIG_FS_VERITY_DEBUG
0012 #define DEBUG
0013 #endif
0014
0015 #define pr_fmt(fmt) "fs-verity: " fmt
0016
0017 #include <linux/fsverity.h>
0018 #include <linux/mempool.h>
0019
0020 struct ahash_request;
0021
0022
0023
0024
0025
0026 #define FS_VERITY_MAX_LEVELS 8
0027
0028
0029 struct fsverity_hash_alg {
0030 struct crypto_ahash *tfm;
0031 const char *name;
0032 unsigned int digest_size;
0033 unsigned int block_size;
0034 mempool_t req_pool;
0035 };
0036
0037
0038 struct merkle_tree_params {
0039 struct fsverity_hash_alg *hash_alg;
0040 const u8 *hashstate;
0041 unsigned int digest_size;
0042 unsigned int block_size;
0043 unsigned int hashes_per_block;
0044 unsigned int log_blocksize;
0045 unsigned int log_arity;
0046 unsigned int num_levels;
0047 u64 tree_size;
0048 unsigned long level0_blocks;
0049
0050
0051
0052
0053
0054 u64 level_start[FS_VERITY_MAX_LEVELS];
0055 };
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066 struct fsverity_info {
0067 struct merkle_tree_params tree_params;
0068 u8 root_hash[FS_VERITY_MAX_DIGEST_SIZE];
0069 u8 file_digest[FS_VERITY_MAX_DIGEST_SIZE];
0070 const struct inode *inode;
0071 };
0072
0073
0074 #define FS_VERITY_MAX_DESCRIPTOR_SIZE 16384
0075
0076 #define FS_VERITY_MAX_SIGNATURE_SIZE (FS_VERITY_MAX_DESCRIPTOR_SIZE - \
0077 sizeof(struct fsverity_descriptor))
0078
0079
0080
0081 extern struct fsverity_hash_alg fsverity_hash_algs[];
0082
0083 struct fsverity_hash_alg *fsverity_get_hash_alg(const struct inode *inode,
0084 unsigned int num);
0085 struct ahash_request *fsverity_alloc_hash_request(struct fsverity_hash_alg *alg,
0086 gfp_t gfp_flags);
0087 void fsverity_free_hash_request(struct fsverity_hash_alg *alg,
0088 struct ahash_request *req);
0089 const u8 *fsverity_prepare_hash_state(struct fsverity_hash_alg *alg,
0090 const u8 *salt, size_t salt_size);
0091 int fsverity_hash_page(const struct merkle_tree_params *params,
0092 const struct inode *inode,
0093 struct ahash_request *req, struct page *page, u8 *out);
0094 int fsverity_hash_buffer(struct fsverity_hash_alg *alg,
0095 const void *data, size_t size, u8 *out);
0096 void __init fsverity_check_hash_algs(void);
0097
0098
0099
0100 void __printf(3, 4) __cold
0101 fsverity_msg(const struct inode *inode, const char *level,
0102 const char *fmt, ...);
0103
0104 #define fsverity_warn(inode, fmt, ...) \
0105 fsverity_msg((inode), KERN_WARNING, fmt, ##__VA_ARGS__)
0106 #define fsverity_err(inode, fmt, ...) \
0107 fsverity_msg((inode), KERN_ERR, fmt, ##__VA_ARGS__)
0108
0109
0110
0111 int fsverity_init_merkle_tree_params(struct merkle_tree_params *params,
0112 const struct inode *inode,
0113 unsigned int hash_algorithm,
0114 unsigned int log_blocksize,
0115 const u8 *salt, size_t salt_size);
0116
0117 struct fsverity_info *fsverity_create_info(const struct inode *inode,
0118 struct fsverity_descriptor *desc);
0119
0120 void fsverity_set_info(struct inode *inode, struct fsverity_info *vi);
0121
0122 void fsverity_free_info(struct fsverity_info *vi);
0123
0124 int fsverity_get_descriptor(struct inode *inode,
0125 struct fsverity_descriptor **desc_ret);
0126
0127 int __init fsverity_init_info_cache(void);
0128 void __init fsverity_exit_info_cache(void);
0129
0130
0131
0132 #ifdef CONFIG_FS_VERITY_BUILTIN_SIGNATURES
0133 int fsverity_verify_signature(const struct fsverity_info *vi,
0134 const u8 *signature, size_t sig_size);
0135
0136 int __init fsverity_init_signature(void);
0137 #else
0138 static inline int
0139 fsverity_verify_signature(const struct fsverity_info *vi,
0140 const u8 *signature, size_t sig_size)
0141 {
0142 return 0;
0143 }
0144
0145 static inline int fsverity_init_signature(void)
0146 {
0147 return 0;
0148 }
0149 #endif
0150
0151
0152
0153 int __init fsverity_init_workqueue(void);
0154 void __init fsverity_exit_workqueue(void);
0155
0156 #endif