Skip to content

Commit 6290d3f

Browse files
chaseyugregkh
authored andcommitted
f2fs: fix to do sanity check on blocks for inline_data inode
[ Upstream commit c240c87 ] inode can be fuzzed, so it can has F2FS_INLINE_DATA flag and valid i_blocks/i_nid value, this patch supports to do extra sanity check to detect such corrupted state. Signed-off-by: Chao Yu <[email protected]> Signed-off-by: Jaegeuk Kim <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent 862b19f commit 6290d3f

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

fs/f2fs/f2fs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4148,7 +4148,7 @@ extern struct kmem_cache *f2fs_inode_entry_slab;
41484148
* inline.c
41494149
*/
41504150
bool f2fs_may_inline_data(struct inode *inode);
4151-
bool f2fs_sanity_check_inline_data(struct inode *inode);
4151+
bool f2fs_sanity_check_inline_data(struct inode *inode, struct page *ipage);
41524152
bool f2fs_may_inline_dentry(struct inode *inode);
41534153
void f2fs_do_read_inline_data(struct page *page, struct page *ipage);
41544154
void f2fs_truncate_inline_inode(struct inode *inode,

fs/f2fs/inline.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,29 @@ bool f2fs_may_inline_data(struct inode *inode)
3333
return !f2fs_post_read_required(inode);
3434
}
3535

36-
bool f2fs_sanity_check_inline_data(struct inode *inode)
36+
static bool inode_has_blocks(struct inode *inode, struct page *ipage)
37+
{
38+
struct f2fs_inode *ri = F2FS_INODE(ipage);
39+
int i;
40+
41+
if (F2FS_HAS_BLOCKS(inode))
42+
return true;
43+
44+
for (i = 0; i < DEF_NIDS_PER_INODE; i++) {
45+
if (ri->i_nid[i])
46+
return true;
47+
}
48+
return false;
49+
}
50+
51+
bool f2fs_sanity_check_inline_data(struct inode *inode, struct page *ipage)
3752
{
3853
if (!f2fs_has_inline_data(inode))
3954
return false;
4055

56+
if (inode_has_blocks(inode, ipage))
57+
return false;
58+
4159
if (!support_inline_data(inode))
4260
return true;
4361

fs/f2fs/inode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ static bool sanity_check_inode(struct inode *inode, struct page *node_page)
346346
}
347347
}
348348

349-
if (f2fs_sanity_check_inline_data(inode)) {
349+
if (f2fs_sanity_check_inline_data(inode, node_page)) {
350350
f2fs_warn(sbi, "%s: inode (ino=%lx, mode=%u) should not have inline_data, run fsck to fix",
351351
__func__, inode->i_ino, inode->i_mode);
352352
return false;

0 commit comments

Comments
 (0)