@@ -185,6 +185,21 @@ void f2fs_inode_chksum_set(struct f2fs_sb_info *sbi, struct page *page)
185
185
ri -> i_inode_checksum = cpu_to_le32 (f2fs_inode_chksum (sbi , page ));
186
186
}
187
187
188
+ static bool sanity_check_inode (struct inode * inode )
189
+ {
190
+ struct f2fs_sb_info * sbi = F2FS_I_SB (inode );
191
+
192
+ if (f2fs_sb_has_flexible_inline_xattr (sbi -> sb )
193
+ && !f2fs_has_extra_attr (inode )) {
194
+ set_sbi_flag (sbi , SBI_NEED_FSCK );
195
+ f2fs_msg (sbi -> sb , KERN_WARNING ,
196
+ "%s: corrupted inode ino=%lx, run fsck to fix." ,
197
+ __func__ , inode -> i_ino );
198
+ return false;
199
+ }
200
+ return true;
201
+ }
202
+
188
203
static int do_read_inode (struct inode * inode )
189
204
{
190
205
struct f2fs_sb_info * sbi = F2FS_I_SB (inode );
@@ -235,7 +250,6 @@ static int do_read_inode(struct inode *inode)
235
250
le16_to_cpu (ri -> i_extra_isize ) : 0 ;
236
251
237
252
if (f2fs_sb_has_flexible_inline_xattr (sbi -> sb )) {
238
- f2fs_bug_on (sbi , !f2fs_has_extra_attr (inode ));
239
253
fi -> i_inline_xattr_size = le16_to_cpu (ri -> i_inline_xattr_size );
240
254
} else if (f2fs_has_inline_xattr (inode ) ||
241
255
f2fs_has_inline_dentry (inode )) {
@@ -313,6 +327,10 @@ struct inode *f2fs_iget(struct super_block *sb, unsigned long ino)
313
327
ret = do_read_inode (inode );
314
328
if (ret )
315
329
goto bad_inode ;
330
+ if (!sanity_check_inode (inode )) {
331
+ ret = - EINVAL ;
332
+ goto bad_inode ;
333
+ }
316
334
make_now :
317
335
if (ino == F2FS_NODE_INO (sbi )) {
318
336
inode -> i_mapping -> a_ops = & f2fs_node_aops ;
0 commit comments