1
2
3
4
5
6
7
8
9
10
11#ifndef DM_VERITY_H
12#define DM_VERITY_H
13
14#include <linux/dm-bufio.h>
15#include <linux/device-mapper.h>
16#include <crypto/hash.h>
17
18#define DM_VERITY_MAX_LEVELS 63
19
20enum verity_mode {
21 DM_VERITY_MODE_EIO,
22 DM_VERITY_MODE_LOGGING,
23 DM_VERITY_MODE_RESTART
24};
25
26enum verity_block_type {
27 DM_VERITY_BLOCK_TYPE_DATA,
28 DM_VERITY_BLOCK_TYPE_METADATA
29};
30
31struct dm_verity_fec;
32
33struct dm_verity {
34 struct dm_dev *data_dev;
35 struct dm_dev *hash_dev;
36 struct dm_target *ti;
37 struct dm_bufio_client *bufio;
38 char *alg_name;
39 struct crypto_ahash *tfm;
40 u8 *root_digest;
41 u8 *salt;
42 u8 *zero_digest;
43 unsigned salt_size;
44 sector_t data_start;
45 sector_t hash_start;
46 sector_t data_blocks;
47 sector_t hash_blocks;
48 unsigned char data_dev_block_bits;
49 unsigned char hash_dev_block_bits;
50 unsigned char hash_per_block_bits;
51 unsigned char levels;
52 unsigned char version;
53 unsigned digest_size;
54 unsigned int ahash_reqsize;
55 int hash_failed;
56 enum verity_mode mode;
57 unsigned corrupted_errs;
58
59 struct workqueue_struct *verify_wq;
60
61
62 sector_t hash_level_block[DM_VERITY_MAX_LEVELS];
63
64 struct dm_verity_fec *fec;
65 unsigned long *validated_blocks;
66
67 char *signature_key_desc;
68};
69
70struct dm_verity_io {
71 struct dm_verity *v;
72
73
74 bio_end_io_t *orig_bi_end_io;
75
76 sector_t block;
77 unsigned n_blocks;
78
79 struct bvec_iter iter;
80
81 struct work_struct work;
82
83
84
85
86
87
88
89
90
91
92
93};
94
95static inline struct ahash_request *verity_io_hash_req(struct dm_verity *v,
96 struct dm_verity_io *io)
97{
98 return (struct ahash_request *)(io + 1);
99}
100
101static inline u8 *verity_io_real_digest(struct dm_verity *v,
102 struct dm_verity_io *io)
103{
104 return (u8 *)(io + 1) + v->ahash_reqsize;
105}
106
107static inline u8 *verity_io_want_digest(struct dm_verity *v,
108 struct dm_verity_io *io)
109{
110 return (u8 *)(io + 1) + v->ahash_reqsize + v->digest_size;
111}
112
113static inline u8 *verity_io_digest_end(struct dm_verity *v,
114 struct dm_verity_io *io)
115{
116 return verity_io_want_digest(v, io) + v->digest_size;
117}
118
119extern int verity_for_bv_block(struct dm_verity *v, struct dm_verity_io *io,
120 struct bvec_iter *iter,
121 int (*process)(struct dm_verity *v,
122 struct dm_verity_io *io,
123 u8 *data, size_t len));
124
125extern int verity_hash(struct dm_verity *v, struct ahash_request *req,
126 const u8 *data, size_t len, u8 *digest);
127
128extern int verity_hash_for_block(struct dm_verity *v, struct dm_verity_io *io,
129 sector_t block, u8 *digest, bool *is_zero);
130
131#endif
132