@@ -225,25 +225,36 @@ ext4_xattr_check_entries(struct ext4_xattr_entry *entry, void *end,
225
225
}
226
226
227
227
static inline int
228
- ext4_xattr_check_block (struct inode * inode , struct buffer_head * bh )
228
+ __ext4_xattr_check_block (struct inode * inode , struct buffer_head * bh ,
229
+ const char * function , unsigned int line )
229
230
{
230
- int error ;
231
+ int error = - EFSCORRUPTED ;
231
232
232
233
if (buffer_verified (bh ))
233
234
return 0 ;
234
235
235
236
if (BHDR (bh )-> h_magic != cpu_to_le32 (EXT4_XATTR_MAGIC ) ||
236
237
BHDR (bh )-> h_blocks != cpu_to_le32 (1 ))
237
- return - EFSCORRUPTED ;
238
+ goto errout ;
239
+ error = - EFSBADCRC ;
238
240
if (!ext4_xattr_block_csum_verify (inode , bh ))
239
- return - EFSBADCRC ;
241
+ goto errout ;
240
242
error = ext4_xattr_check_entries (BFIRST (bh ), bh -> b_data + bh -> b_size ,
241
243
bh -> b_data );
242
- if (!error )
244
+ errout :
245
+ if (error )
246
+ __ext4_error_inode (inode , function , line , 0 ,
247
+ "corrupted xattr block %llu" ,
248
+ (unsigned long long ) bh -> b_blocknr );
249
+ else
243
250
set_buffer_verified (bh );
244
251
return error ;
245
252
}
246
253
254
+ #define ext4_xattr_check_block (inode , bh ) \
255
+ __ext4_xattr_check_block((inode), (bh), __func__, __LINE__)
256
+
257
+
247
258
static int
248
259
__xattr_check_inode (struct inode * inode , struct ext4_xattr_ibody_header * header ,
249
260
void * end , const char * function , unsigned int line )
@@ -514,12 +525,9 @@ ext4_xattr_block_get(struct inode *inode, int name_index, const char *name,
514
525
goto cleanup ;
515
526
ea_bdebug (bh , "b_count=%d, refcount=%d" ,
516
527
atomic_read (& (bh -> b_count )), le32_to_cpu (BHDR (bh )-> h_refcount ));
517
- if (ext4_xattr_check_block (inode , bh )) {
518
- EXT4_ERROR_INODE (inode , "bad block %llu" ,
519
- EXT4_I (inode )-> i_file_acl );
520
- error = - EFSCORRUPTED ;
528
+ error = ext4_xattr_check_block (inode , bh );
529
+ if (error )
521
530
goto cleanup ;
522
- }
523
531
ext4_xattr_block_cache_insert (ea_block_cache , bh );
524
532
entry = BFIRST (bh );
525
533
error = ext4_xattr_find_entry (& entry , name_index , name , 1 );
@@ -679,12 +687,9 @@ ext4_xattr_block_list(struct dentry *dentry, char *buffer, size_t buffer_size)
679
687
goto cleanup ;
680
688
ea_bdebug (bh , "b_count=%d, refcount=%d" ,
681
689
atomic_read (& (bh -> b_count )), le32_to_cpu (BHDR (bh )-> h_refcount ));
682
- if (ext4_xattr_check_block (inode , bh )) {
683
- EXT4_ERROR_INODE (inode , "bad block %llu" ,
684
- EXT4_I (inode )-> i_file_acl );
685
- error = - EFSCORRUPTED ;
690
+ error = ext4_xattr_check_block (inode , bh );
691
+ if (error )
686
692
goto cleanup ;
687
- }
688
693
ext4_xattr_block_cache_insert (EA_BLOCK_CACHE (inode ), bh );
689
694
error = ext4_xattr_list_entries (dentry , BFIRST (bh ), buffer , buffer_size );
690
695
@@ -811,10 +816,9 @@ int ext4_get_inode_usage(struct inode *inode, qsize_t *usage)
811
816
goto out ;
812
817
}
813
818
814
- if ( ext4_xattr_check_block (inode , bh )) {
815
- ret = - EFSCORRUPTED ;
819
+ ret = ext4_xattr_check_block (inode , bh );
820
+ if ( ret )
816
821
goto out ;
817
- }
818
822
819
823
for (entry = BFIRST (bh ); !IS_LAST_ENTRY (entry );
820
824
entry = EXT4_XATTR_NEXT (entry ))
@@ -1796,12 +1800,9 @@ ext4_xattr_block_find(struct inode *inode, struct ext4_xattr_info *i,
1796
1800
ea_bdebug (bs -> bh , "b_count=%d, refcount=%d" ,
1797
1801
atomic_read (& (bs -> bh -> b_count )),
1798
1802
le32_to_cpu (BHDR (bs -> bh )-> h_refcount ));
1799
- if (ext4_xattr_check_block (inode , bs -> bh )) {
1800
- EXT4_ERROR_INODE (inode , "bad block %llu" ,
1801
- EXT4_I (inode )-> i_file_acl );
1802
- error = - EFSCORRUPTED ;
1803
+ error = ext4_xattr_check_block (inode , bs -> bh );
1804
+ if (error )
1803
1805
goto cleanup ;
1804
- }
1805
1806
/* Find the named attribute. */
1806
1807
bs -> s .base = BHDR (bs -> bh );
1807
1808
bs -> s .first = BFIRST (bs -> bh );
@@ -2724,13 +2725,9 @@ int ext4_expand_extra_isize_ea(struct inode *inode, int new_extra_isize,
2724
2725
error = - EIO ;
2725
2726
if (!bh )
2726
2727
goto cleanup ;
2727
- if (ext4_xattr_check_block (inode , bh )) {
2728
- EXT4_ERROR_INODE (inode , "bad block %llu" ,
2729
- EXT4_I (inode )-> i_file_acl );
2730
- error = - EFSCORRUPTED ;
2731
- brelse (bh );
2728
+ error = ext4_xattr_check_block (inode , bh );
2729
+ if (error )
2732
2730
goto cleanup ;
2733
- }
2734
2731
base = BHDR (bh );
2735
2732
end = bh -> b_data + bh -> b_size ;
2736
2733
min_offs = end - base ;
@@ -2887,11 +2884,8 @@ int ext4_xattr_delete_inode(handle_t *handle, struct inode *inode,
2887
2884
goto cleanup ;
2888
2885
}
2889
2886
error = ext4_xattr_check_block (inode , bh );
2890
- if (error ) {
2891
- EXT4_ERROR_INODE (inode , "bad block %llu (error %d)" ,
2892
- EXT4_I (inode )-> i_file_acl , error );
2887
+ if (error )
2893
2888
goto cleanup ;
2894
- }
2895
2889
2896
2890
if (ext4_has_feature_ea_inode (inode -> i_sb )) {
2897
2891
for (entry = BFIRST (bh ); !IS_LAST_ENTRY (entry );
0 commit comments