Skip to content

Commit dff15a2

Browse files
chaseyugregkh
authored andcommitted
f2fs: fix to do sanity check on valid block count of segment
[ Upstream commit e95bcdb ] As Jungyeon reported in bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=203233 - Overview When mounting the attached crafted image and running program, following errors are reported. Additionally, it hangs on sync after running program. The image is intentionally fuzzed from a normal f2fs image for testing. Compile options for F2FS are as follows. CONFIG_F2FS_FS=y CONFIG_F2FS_STAT_FS=y CONFIG_F2FS_FS_XATTR=y CONFIG_F2FS_FS_POSIX_ACL=y CONFIG_F2FS_CHECK_FS=y - Reproduces cc poc_13.c mkdir test mount -t f2fs tmp.img test cp a.out test cd test sudo ./a.out sync - Kernel messages F2FS-fs (sdb): Bitmap was wrongly set, blk:4608 kernel BUG at fs/f2fs/segment.c:2102! RIP: 0010:update_sit_entry+0x394/0x410 Call Trace: f2fs_allocate_data_block+0x16f/0x660 do_write_page+0x62/0x170 f2fs_do_write_node_page+0x33/0xa0 __write_node_page+0x270/0x4e0 f2fs_sync_node_pages+0x5df/0x670 f2fs_write_checkpoint+0x372/0x1400 f2fs_sync_fs+0xa3/0x130 f2fs_do_sync_file+0x1a6/0x810 do_fsync+0x33/0x60 __x64_sys_fsync+0xb/0x10 do_syscall_64+0x43/0xf0 entry_SYSCALL_64_after_hwframe+0x44/0xa9 sit.vblocks and sum valid block count in sit.valid_map may be inconsistent, segment w/ zero vblocks will be treated as free segment, while allocating in free segment, we may allocate a free block, if its bitmap is valid previously, it can cause kernel crash due to bitmap verification failure. Anyway, to avoid further serious metadata inconsistence and corruption, it is necessary and worth to detect SIT inconsistence. So let's enable check_block_count() to verify vblocks and valid_map all the time rather than do it only CONFIG_F2FS_CHECK_FS is enabled. Signed-off-by: Chao Yu <[email protected]> Signed-off-by: Jaegeuk Kim <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent 2b65316 commit dff15a2

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

fs/f2fs/segment.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,6 @@ static inline void verify_block_addr(struct f2fs_io_info *fio, block_t blk_addr)
613613
static inline int check_block_count(struct f2fs_sb_info *sbi,
614614
int segno, struct f2fs_sit_entry *raw_sit)
615615
{
616-
#ifdef CONFIG_F2FS_CHECK_FS
617616
bool is_valid = test_bit_le(0, raw_sit->valid_map) ? true : false;
618617
int valid_blocks = 0;
619618
int cur_pos = 0, next_pos;
@@ -640,7 +639,7 @@ static inline int check_block_count(struct f2fs_sb_info *sbi,
640639
set_sbi_flag(sbi, SBI_NEED_FSCK);
641640
return -EINVAL;
642641
}
643-
#endif
642+
644643
/* check segment usage, and check boundary of a given segment number */
645644
if (unlikely(GET_SIT_VBLOCKS(raw_sit) > sbi->blocks_per_seg
646645
|| segno > TOTAL_SEGS(sbi) - 1)) {

0 commit comments

Comments
 (0)