Skip to content

Commit ed854f1

Browse files
chaseyugregkh
authored andcommitted
f2fs: fix to do sanity check on destination blkaddr during recovery
commit 0ef4ca0 upstream. As Wenqing Liu reported in bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=216456 loop5: detected capacity change from 0 to 131072 F2FS-fs (loop5): recover_inode: ino = 6, name = hln, inline = 1 F2FS-fs (loop5): recover_data: ino = 6 (i_size: recover) err = 0 F2FS-fs (loop5): recover_inode: ino = 6, name = hln, inline = 1 F2FS-fs (loop5): recover_data: ino = 6 (i_size: recover) err = 0 F2FS-fs (loop5): recover_inode: ino = 6, name = hln, inline = 1 F2FS-fs (loop5): recover_data: ino = 6 (i_size: recover) err = 0 F2FS-fs (loop5): Bitmap was wrongly set, blk:5634 ------------[ cut here ]------------ WARNING: CPU: 3 PID: 1013 at fs/f2fs/segment.c:2198 RIP: 0010:update_sit_entry+0xa55/0x10b0 [f2fs] Call Trace: <TASK> f2fs_do_replace_block+0xa98/0x1890 [f2fs] f2fs_replace_block+0xeb/0x180 [f2fs] recover_data+0x1a69/0x6ae0 [f2fs] f2fs_recover_fsync_data+0x120d/0x1fc0 [f2fs] f2fs_fill_super+0x4665/0x61e0 [f2fs] mount_bdev+0x2cf/0x3b0 legacy_get_tree+0xed/0x1d0 vfs_get_tree+0x81/0x2b0 path_mount+0x47e/0x19d0 do_mount+0xce/0xf0 __x64_sys_mount+0x12c/0x1a0 do_syscall_64+0x38/0x90 entry_SYSCALL_64_after_hwframe+0x63/0xcd If we enable CONFIG_F2FS_CHECK_FS config, it will trigger a kernel panic instead of warning. The root cause is: in fuzzed image, SIT table is inconsistent with inode mapping table, result in triggering such warning during SIT table update. This patch introduces a new flag DATA_GENERIC_ENHANCE_UPDATE, w/ this flag, data block recovery flow can check destination blkaddr's validation in SIT table, and skip f2fs_replace_block() to avoid inconsistent status. Cc: [email protected] Reported-by: Wenqing Liu <[email protected]> Signed-off-by: Chao Yu <[email protected]> Signed-off-by: Jaegeuk Kim <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 7f10357 commit ed854f1

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

fs/f2fs/checkpoint.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,14 +139,21 @@ static bool __is_bitmap_valid(struct f2fs_sb_info *sbi, block_t blkaddr,
139139
unsigned int segno, offset;
140140
bool exist;
141141

142-
if (type != DATA_GENERIC_ENHANCE && type != DATA_GENERIC_ENHANCE_READ)
142+
if (type == DATA_GENERIC)
143143
return true;
144144

145145
segno = GET_SEGNO(sbi, blkaddr);
146146
offset = GET_BLKOFF_FROM_SEG0(sbi, blkaddr);
147147
se = get_seg_entry(sbi, segno);
148148

149149
exist = f2fs_test_bit(offset, se->cur_valid_map);
150+
if (exist && type == DATA_GENERIC_ENHANCE_UPDATE) {
151+
f2fs_err(sbi, "Inconsistent error blkaddr:%u, sit bitmap:%d",
152+
blkaddr, exist);
153+
set_sbi_flag(sbi, SBI_NEED_FSCK);
154+
return exist;
155+
}
156+
150157
if (!exist && type == DATA_GENERIC_ENHANCE) {
151158
f2fs_err(sbi, "Inconsistent error blkaddr:%u, sit bitmap:%d",
152159
blkaddr, exist);
@@ -184,6 +191,7 @@ bool f2fs_is_valid_blkaddr(struct f2fs_sb_info *sbi,
184191
case DATA_GENERIC:
185192
case DATA_GENERIC_ENHANCE:
186193
case DATA_GENERIC_ENHANCE_READ:
194+
case DATA_GENERIC_ENHANCE_UPDATE:
187195
if (unlikely(blkaddr >= MAX_BLKADDR(sbi) ||
188196
blkaddr < MAIN_BLKADDR(sbi))) {
189197
f2fs_warn(sbi, "access invalid blkaddr:%u",

fs/f2fs/f2fs.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,10 @@ enum {
249249
* condition of read on truncated area
250250
* by extent_cache
251251
*/
252+
DATA_GENERIC_ENHANCE_UPDATE, /*
253+
* strong check on range and segment
254+
* bitmap for update case
255+
*/
252256
META_GENERIC,
253257
};
254258

fs/f2fs/recovery.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,14 @@ static int do_recover_data(struct f2fs_sb_info *sbi, struct inode *inode,
677677
goto err;
678678
}
679679

680+
if (f2fs_is_valid_blkaddr(sbi, dest,
681+
DATA_GENERIC_ENHANCE_UPDATE)) {
682+
f2fs_err(sbi, "Inconsistent dest blkaddr:%u, ino:%lu, ofs:%u",
683+
dest, inode->i_ino, dn.ofs_in_node);
684+
err = -EFSCORRUPTED;
685+
goto err;
686+
}
687+
680688
/* write dummy data page */
681689
f2fs_replace_block(sbi, &dn, src, dest,
682690
ni.version, false, false);

0 commit comments

Comments
 (0)