]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blame - releases/4.9.28/f2fs-sanity-check-segment-count.patch
5.1-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 4.9.28 / f2fs-sanity-check-segment-count.patch
CommitLineData
517ec11f
GKH
1From b9dd46188edc2f0d1f37328637860bb65a771124 Mon Sep 17 00:00:00 2001
2From: Jin Qian <jinqian@google.com>
3Date: Tue, 25 Apr 2017 16:28:48 -0700
4Subject: f2fs: sanity check segment count
5
6From: Jin Qian <jinqian@google.com>
7
8commit b9dd46188edc2f0d1f37328637860bb65a771124 upstream.
9
10F2FS uses 4 bytes to represent block address. As a result, supported
11size of disk is 16 TB and it equals to 16 * 1024 * 1024 / 2 segments.
12
13Signed-off-by: Jin Qian <jinqian@google.com>
14Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
15Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
16
17---
18 fs/f2fs/super.c | 7 +++++++
19 include/linux/f2fs_fs.h | 6 ++++++
20 2 files changed, 13 insertions(+)
21
22--- a/fs/f2fs/super.c
23+++ b/fs/f2fs/super.c
24@@ -1405,6 +1405,13 @@ static int sanity_check_raw_super(struct
25 return 1;
26 }
27
28+ if (le32_to_cpu(raw_super->segment_count) > F2FS_MAX_SEGMENT) {
29+ f2fs_msg(sb, KERN_INFO,
30+ "Invalid segment count (%u)",
31+ le32_to_cpu(raw_super->segment_count));
32+ return 1;
33+ }
34+
35 /* check CP/SIT/NAT/SSA/MAIN_AREA area boundary */
36 if (sanity_check_area_boundary(sbi, bh))
37 return 1;
38--- a/include/linux/f2fs_fs.h
39+++ b/include/linux/f2fs_fs.h
40@@ -286,6 +286,12 @@ struct f2fs_nat_block {
41 #define SIT_ENTRY_PER_BLOCK (PAGE_SIZE / sizeof(struct f2fs_sit_entry))
42
43 /*
44+ * F2FS uses 4 bytes to represent block address. As a result, supported size of
45+ * disk is 16 TB and it equals to 16 * 1024 * 1024 / 2 segments.
46+ */
47+#define F2FS_MAX_SEGMENT ((16 * 1024 * 1024) / 2)
48+
49+/*
50 * Note that f2fs_sit_entry->vblocks has the following bit-field information.
51 * [15:10] : allocation type such as CURSEG_XXXX_TYPE
52 * [9:0] : valid block count