]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blame - releases/4.19.51/f2fs-fix-to-avoid-panic-in-f2fs_remove_inode_page.patch
Linux 4.19.51
[thirdparty/kernel/stable-queue.git] / releases / 4.19.51 / f2fs-fix-to-avoid-panic-in-f2fs_remove_inode_page.patch
CommitLineData
37554d48
SL
1From ffcd55ace4fbcadc6781160828c066432ead4156 Mon Sep 17 00:00:00 2001
2From: Chao Yu <yuchao0@huawei.com>
3Date: Mon, 15 Apr 2019 15:28:34 +0800
4Subject: f2fs: fix to avoid panic in f2fs_remove_inode_page()
5
6[ Upstream commit 8b6810f8acfe429fde7c7dad4714692cc5f75651 ]
7
8As Jungyeon reported in bugzilla:
9
10https://bugzilla.kernel.org/show_bug.cgi?id=203219
11
12- Overview
13When mounting the attached crafted image and running program, I got this error.
14Additionally, it hangs on sync after running the program.
15
16The image is intentionally fuzzed from a normal f2fs image for testing and I enabled option CONFIG_F2FS_CHECK_FS on.
17
18- Reproduces
19cc poc_06.c
20mkdir test
21mount -t f2fs tmp.img test
22cp a.out test
23cd test
24sudo ./a.out
25sync
26
27- Messages
28 kernel BUG at fs/f2fs/node.c:1183!
29 RIP: 0010:f2fs_remove_inode_page+0x294/0x2d0
30 Call Trace:
31 f2fs_evict_inode+0x2a3/0x3a0
32 evict+0xba/0x180
33 __dentry_kill+0xbe/0x160
34 dentry_kill+0x46/0x180
35 dput+0xbb/0x100
36 do_renameat2+0x3c9/0x550
37 __x64_sys_rename+0x17/0x20
38 do_syscall_64+0x43/0xf0
39 entry_SYSCALL_64_after_hwframe+0x44/0xa9
40
41The reason is f2fs_remove_inode_page() will trigger kernel panic due to
42inconsistent i_blocks value of inode.
43
44To avoid panic, let's just print debug message and set SBI_NEED_FSCK to
45give a hint to fsck for latter repairing of potential image corruption.
46
47Signed-off-by: Chao Yu <yuchao0@huawei.com>
48[Jaegeuk Kim: fix build warning and add unlikely]
49Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
50Signed-off-by: Sasha Levin <sashal@kernel.org>
51---
52 fs/f2fs/node.c | 10 ++++++++--
53 1 file changed, 8 insertions(+), 2 deletions(-)
54
55diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c
56index 19a0d83aae65..807a77518a49 100644
57--- a/fs/f2fs/node.c
58+++ b/fs/f2fs/node.c
59@@ -1180,8 +1180,14 @@ int f2fs_remove_inode_page(struct inode *inode)
60 f2fs_put_dnode(&dn);
61 return -EIO;
62 }
63- f2fs_bug_on(F2FS_I_SB(inode),
64- inode->i_blocks != 0 && inode->i_blocks != 8);
65+
66+ if (unlikely(inode->i_blocks != 0 && inode->i_blocks != 8)) {
67+ f2fs_msg(F2FS_I_SB(inode)->sb, KERN_WARNING,
68+ "Inconsistent i_blocks, ino:%lu, iblocks:%llu",
69+ inode->i_ino,
70+ (unsigned long long)inode->i_blocks);
71+ set_sbi_flag(F2FS_I_SB(inode), SBI_NEED_FSCK);
72+ }
73
74 /* will put inode & node pages */
75 err = truncate_node(&dn);
76--
772.20.1
78