12
12
13
13
static struct workqueue_struct * fsverity_read_workqueue ;
14
14
15
- static inline int cmp_hashes (const struct fsverity_info * vi ,
16
- const u8 * want_hash , const u8 * real_hash ,
17
- u64 data_pos , int level )
18
- {
19
- const unsigned int hsize = vi -> tree_params .digest_size ;
20
-
21
- if (memcmp (want_hash , real_hash , hsize ) == 0 )
22
- return 0 ;
23
-
24
- fsverity_err (vi -> inode ,
25
- "FILE CORRUPTED! pos=%llu, level=%d, want_hash=%s:%*phN, real_hash=%s:%*phN" ,
26
- data_pos , level ,
27
- vi -> tree_params .hash_alg -> name , hsize , want_hash ,
28
- vi -> tree_params .hash_alg -> name , hsize , real_hash );
29
- return - EBADMSG ;
30
- }
31
-
32
15
/*
33
16
* Returns true if the hash block with index @hblock_idx in the tree, located in
34
17
* @hpage, has already been verified.
@@ -131,7 +114,6 @@ verify_data_block(struct inode *inode, struct fsverity_info *vi,
131
114
* index of that block's hash within the current level.
132
115
*/
133
116
u64 hidx = data_pos >> params -> log_blocksize ;
134
- int err ;
135
117
136
118
/* Up to 1 + FS_VERITY_MAX_LEVELS pages may be mapped at once */
137
119
BUILD_BUG_ON (1 + FS_VERITY_MAX_LEVELS > KM_MAX_IDX );
@@ -191,11 +173,10 @@ verify_data_block(struct inode *inode, struct fsverity_info *vi,
191
173
hpage_idx , level == 0 ? min (max_ra_pages ,
192
174
params -> tree_pages - hpage_idx ) : 0 );
193
175
if (IS_ERR (hpage )) {
194
- err = PTR_ERR (hpage );
195
176
fsverity_err (inode ,
196
- "Error %d reading Merkle tree page %lu" ,
197
- err , hpage_idx );
198
- goto out ;
177
+ "Error %ld reading Merkle tree page %lu" ,
178
+ PTR_ERR ( hpage ) , hpage_idx );
179
+ goto error ;
199
180
}
200
181
haddr = kmap_local_page (hpage ) + hblock_offset_in_page ;
201
182
if (is_hash_block_verified (vi , hpage , hblock_idx )) {
@@ -221,12 +202,10 @@ verify_data_block(struct inode *inode, struct fsverity_info *vi,
221
202
unsigned long hblock_idx = hblocks [level - 1 ].index ;
222
203
unsigned int hoffset = hblocks [level - 1 ].hoffset ;
223
204
224
- err = fsverity_hash_block (params , inode , haddr , real_hash );
225
- if (err )
226
- goto out ;
227
- err = cmp_hashes (vi , want_hash , real_hash , data_pos , level - 1 );
228
- if (err )
229
- goto out ;
205
+ if (fsverity_hash_block (params , inode , haddr , real_hash ) != 0 )
206
+ goto error ;
207
+ if (memcmp (want_hash , real_hash , hsize ) != 0 )
208
+ goto corrupted ;
230
209
/*
231
210
* Mark the hash block as verified. This must be atomic and
232
211
* idempotent, as the same hash block might be verified by
@@ -243,16 +222,24 @@ verify_data_block(struct inode *inode, struct fsverity_info *vi,
243
222
}
244
223
245
224
/* Finally, verify the data block. */
246
- err = fsverity_hash_block (params , inode , data , real_hash );
247
- if (err )
248
- goto out ;
249
- err = cmp_hashes (vi , want_hash , real_hash , data_pos , -1 );
250
- out :
225
+ if (fsverity_hash_block (params , inode , data , real_hash ) != 0 )
226
+ goto error ;
227
+ if (memcmp (want_hash , real_hash , hsize ) != 0 )
228
+ goto corrupted ;
229
+ return true;
230
+
231
+ corrupted :
232
+ fsverity_err (inode ,
233
+ "FILE CORRUPTED! pos=%llu, level=%d, want_hash=%s:%*phN, real_hash=%s:%*phN" ,
234
+ data_pos , level - 1 ,
235
+ params -> hash_alg -> name , hsize , want_hash ,
236
+ params -> hash_alg -> name , hsize , real_hash );
237
+ error :
251
238
for (; level > 0 ; level -- ) {
252
239
kunmap_local (hblocks [level - 1 ].addr );
253
240
put_page (hblocks [level - 1 ].page );
254
241
}
255
- return err == 0 ;
242
+ return false ;
256
243
}
257
244
258
245
static bool
0 commit comments