Skip to content

Commit 4edbdf5

Browse files
Jin Qiangregkh
authored andcommitted
f2fs: sanity check segment count
commit b9dd46188edc2f0d1f37328637860bb65a771124 upstream. F2FS uses 4 bytes to represent block address. As a result, supported size of disk is 16 TB and it equals to 16 * 1024 * 1024 / 2 segments. Signed-off-by: Jin Qian <jinqian@google.com> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 9456239 commit 4edbdf5

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

fs/f2fs/super.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,6 +1059,13 @@ static int sanity_check_raw_super(struct super_block *sb,
10591059
return 1;
10601060
}
10611061

1062+
if (le32_to_cpu(raw_super->segment_count) > F2FS_MAX_SEGMENT) {
1063+
f2fs_msg(sb, KERN_INFO,
1064+
"Invalid segment count (%u)",
1065+
le32_to_cpu(raw_super->segment_count));
1066+
return 1;
1067+
}
1068+
10621069
/* check CP/SIT/NAT/SSA/MAIN_AREA area boundary */
10631070
if (sanity_check_area_boundary(sb, raw_super))
10641071
return 1;

include/linux/f2fs_fs.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,12 @@ struct f2fs_nat_block {
283283
#define SIT_VBLOCK_MAP_SIZE 64
284284
#define SIT_ENTRY_PER_BLOCK (PAGE_CACHE_SIZE / sizeof(struct f2fs_sit_entry))
285285

286+
/*
287+
* F2FS uses 4 bytes to represent block address. As a result, supported size of
288+
* disk is 16 TB and it equals to 16 * 1024 * 1024 / 2 segments.
289+
*/
290+
#define F2FS_MAX_SEGMENT ((16 * 1024 * 1024) / 2)
291+
286292
/*
287293
* Note that f2fs_sit_entry->vblocks has the following bit-field information.
288294
* [15:10] : allocation type such as CURSEG_XXXX_TYPE

0 commit comments

Comments
 (0)