aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorChao Yu <yuchao0@huawei.com>2019-04-15 15:28:34 +0800
committerPaul Gortmaker <paul.gortmaker@windriver.com>2019-09-16 12:20:44 -0400
commitfb108b652316df22f88a310c293a8bf369a50bdd (patch)
tree351f016098023733fc89a39a7b513ac3bd230de7 /fs
parentf7d1b1648726facaca3f9f9eaef62cdad7e45ec3 (diff)
downloadlinux-yocto-fb108b652316df22f88a310c293a8bf369a50bdd.tar.gz
linux-yocto-fb108b652316df22f88a310c293a8bf369a50bdd.tar.bz2
linux-yocto-fb108b652316df22f88a310c293a8bf369a50bdd.zip
f2fs: fix to avoid panic in f2fs_remove_inode_page()
commit 8b6810f8acfe429fde7c7dad4714692cc5f75651 upstream. As Jungyeon reported in bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=203219 - Overview When mounting the attached crafted image and running program, I got this error. Additionally, it hangs on sync after running the program. The image is intentionally fuzzed from a normal f2fs image for testing and I enabled option CONFIG_F2FS_CHECK_FS on. - Reproduces cc poc_06.c mkdir test mount -t f2fs tmp.img test cp a.out test cd test sudo ./a.out sync - Messages kernel BUG at fs/f2fs/node.c:1183! RIP: 0010:f2fs_remove_inode_page+0x294/0x2d0 Call Trace: f2fs_evict_inode+0x2a3/0x3a0 evict+0xba/0x180 __dentry_kill+0xbe/0x160 dentry_kill+0x46/0x180 dput+0xbb/0x100 do_renameat2+0x3c9/0x550 __x64_sys_rename+0x17/0x20 do_syscall_64+0x43/0xf0 entry_SYSCALL_64_after_hwframe+0x44/0xa9 The reason is f2fs_remove_inode_page() will trigger kernel panic due to inconsistent i_blocks value of inode. To avoid panic, let's just print debug message and set SBI_NEED_FSCK to give a hint to fsck for latter repairing of potential image corruption. Signed-off-by: Chao Yu <yuchao0@huawei.com> [Jaegeuk Kim: fix build warning and add unlikely] Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org> Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Diffstat (limited to 'fs')
-rw-r--r--fs/f2fs/node.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c
index ec22e7c5b37e..1417782bab00 100644
--- a/fs/f2fs/node.c
+++ b/fs/f2fs/node.c
@@ -1055,8 +1055,14 @@ int f2fs_remove_inode_page(struct inode *inode)
f2fs_truncate_data_blocks_range(&dn, 1);
/* 0 is possible, after f2fs_new_inode() has failed */
- f2fs_bug_on(F2FS_I_SB(inode),
- inode->i_blocks != 0 && inode->i_blocks != 8);
+
+ if (unlikely(inode->i_blocks != 0 && inode->i_blocks != 8)) {
+ f2fs_msg(F2FS_I_SB(inode)->sb, KERN_WARNING,
+ "Inconsistent i_blocks, ino:%lu, iblocks:%llu",
+ inode->i_ino,
+ (unsigned long long)inode->i_blocks);
+ set_sbi_flag(F2FS_I_SB(inode), SBI_NEED_FSCK);
+ }
/* will put inode & node pages */
truncate_node(&dn);