Skip to contentSkip to conversation

f2fs: fix wrong total_sections check

PATCH Superseded Xiaojun Wang 2 participants 5 messages Sep 16, 2020 – Sep 17, 2020 F2FS file system

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 f2fs: fix wrong total_sections check

Meta area is not included in section_count computation. The code in mkfs/f2fs_format.c is:

	total_zones = get_sb(segment_count) / (c.segs_per_zone) -
					total_meta_zones;
	set_sb(section_count, total_zones * c.secs_per_zone);

So the minimum total_sections is 1.

---
 fs/f2fs/super.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
fs/f2fs/super.c +1 -2
index dfa072fa8081..a450c8589841 100644
@@ -2799,8 +2799,7 @@ static int sanity_check_raw_super(struct f2fs_sb_info *sbi,
 		return -EFSCORRUPTED;
 	}
 
-	if (total_sections > segment_count ||
-			total_sections < F2FS_MIN_SEGMENTS ||
+	if (total_sections > segment_count || total_sections < 1 ||
 			segs_per_sec > segment_count || !segs_per_sec) {
 		f2fs_info(sbi, "Invalid segment/section count (%u, %u x %u)",
 			  segment_count, total_sections, segs_per_sec);
Signature · 8 lines
2.25.1



_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
#1 lore raw
Quoted 18 lines · Xiaojun Wang

Meta area is not included in section_count computation. The code in mkfs/f2fs_format.c is:

	total_zones = get_sb(segment_count) / (c.segs_per_zone) -
					total_meta_zones;
	set_sb(section_count, total_zones * c.secs_per_zone);

So the minimum total_sections is 1.

---
  fs/f2fs/super.c | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)
fs/f2fs/super.c +0 -0
index dfa072fa8081..a450c8589841 100644

fs/f2fs/super.c static int sanity_check_raw_super(struct f2fs_sb_info *sbi, · line 2803

Quoted 7 lines
fs/f2fs/super.c +1 -2
@@ -2799,8 +2799,7 @@ static int sanity_check_raw_super(struct f2fs_sb_info *sbi,
  		return -EFSCORRUPTED;
  	}
 
-	if (total_sections > segment_count ||
-			total_sections < F2FS_MIN_SEGMENTS ||
+	if (total_sections > segment_count || total_sections < 1 ||
  			segs_per_sec > segment_count || !segs_per_sec) {

Here, we try to check sanity on segs_per_sec config directly and indirectly:
- directly: check raw_super->segs_per_sec field
- indirectly: check whether segment_count / total_sections is less than 1

So I guess that first condition is wrong as well, should change it like?

if (total_sections > segment_count - 'total_meta_segment_count' ||

Thoughts?

Thanks,

fs/f2fs/super.c static int sanity_check_raw_super(struct f2fs_sb_info *sbi, · line 2805

Quoted 3 lines
fs/f2fs/super.c +0 -0
  		f2fs_info(sbi, "Invalid segment/section count (%u, %u x %u)",
  			  segment_count, total_sections, segs_per_sec);

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

#2 lore raw
Quoted 30 lines · Yuchao (T)
Quoted 18 lines · Xiaojun Wang

Meta area is not included in section_count computation. The code in mkfs/f2fs_format.c is:

	total_zones = get_sb(segment_count) / (c.segs_per_zone) -
					total_meta_zones;
	set_sb(section_count, total_zones * c.secs_per_zone);

So the minimum total_sections is 1.

---
  fs/f2fs/super.c | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)
fs/f2fs/super.c +0 -0
index dfa072fa8081..a450c8589841 100644

fs/f2fs/super.c static int sanity_check_raw_super(struct f2fs_sb_info *sbi, · line 2803

Quoted 7 lines
fs/f2fs/super.c +1 -2
@@ -2799,8 +2799,7 @@ static int sanity_check_raw_super(struct f2fs_sb_info *sbi,
  		return -EFSCORRUPTED;
  	}
 
-	if (total_sections > segment_count ||
-			total_sections < F2FS_MIN_SEGMENTS ||
+	if (total_sections > segment_count || total_sections < 1 ||
  			segs_per_sec > segment_count || !segs_per_sec) {

Here, we try to check sanity on segs_per_sec config directly and indirectly:
- directly: check raw_super->segs_per_sec field
- indirectly: check whether segment_count / total_sections is less than 1

Quoted 7 lines

So I guess that first condition is wrong as well, should change it like?

if (total_sections > segment_count - 'total_meta_segment_count' ||

Thoughts?

Thanks,

Hi Chao, aggree with you.

'total_meta_segment_count' = le32_to_cpu(raw_super->segment_count_ckpt) +

			le32_to_cpu(raw_super->segment_count_sit) +
			le32_to_cpu(raw_super->segment_count_nat) +
			le32_to_cpu(raw_super->segment_count_ssa)

But the above values will be checked in sanity_check_area_boundary() which will be called later. So can we move the total_sections checking to sanity_check_area_boundary
ensure the 'total_meta_segment_count' is correct ?

Quoted 4 lines

fs/f2fs/super.c static int sanity_check_raw_super(struct f2fs_sb_info *sbi, · line 2805

Quoted 4 lines
fs/f2fs/super.c +0 -0
  		f2fs_info(sbi, "Invalid segment/section count (%u, %u x %u)",
  			  segment_count, total_sections, segs_per_sec);

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

#3 lore raw
Quoted 39 lines · wangxiaojun (N)
Quoted 30 lines · Yuchao (T)
Quoted 18 lines · Xiaojun Wang

Meta area is not included in section_count computation. The code in mkfs/f2fs_format.c is:

	total_zones = get_sb(segment_count) / (c.segs_per_zone) -
					total_meta_zones;
	set_sb(section_count, total_zones * c.secs_per_zone);

So the minimum total_sections is 1.

---
   fs/f2fs/super.c | 3 +--
   1 file changed, 1 insertion(+), 2 deletions(-)
fs/f2fs/super.c +0 -0
index dfa072fa8081..a450c8589841 100644

fs/f2fs/super.c static int sanity_check_raw_super(struct f2fs_sb_info *sbi, · line 2803

Quoted 7 lines
fs/f2fs/super.c +1 -2
@@ -2799,8 +2799,7 @@ static int sanity_check_raw_super(struct f2fs_sb_info *sbi,
   		return -EFSCORRUPTED;
   	}
 
-	if (total_sections > segment_count ||
-			total_sections < F2FS_MIN_SEGMENTS ||
+	if (total_sections > segment_count || total_sections < 1 ||
   			segs_per_sec > segment_count || !segs_per_sec) {

Here, we try to check sanity on segs_per_sec config directly and indirectly:
- directly: check raw_super->segs_per_sec field
- indirectly: check whether segment_count / total_sections is less than 1

Quoted 7 lines

So I guess that first condition is wrong as well, should change it like?

if (total_sections > segment_count - 'total_meta_segment_count' ||

Thoughts?

Thanks,

Quoted 8 lines

Hi Chao, aggree with you.

'total_meta_segment_count' = le32_to_cpu(raw_super->segment_count_ckpt) +

			le32_to_cpu(raw_super->segment_count_sit) +
			le32_to_cpu(raw_super->segment_count_nat) +
			le32_to_cpu(raw_super->segment_count_ssa)

But the above values will be checked in sanity_check_area_boundary() which will be called later. So can we move the total_sections checking to sanity_check_area_boundary

I think we'd better keep segs_per_sec check in sanity_check_raw_super(), as it's a field of superblock.

Quoted 1 line

ensure the 'total_meta_segment_count' is correct ?

It looks the condition below is wrong as well for the same reason you mentioned in commit message?

if (unlikely(fsmeta < F2FS_MIN_SEGMENTS ||

Thanks,

Quoted 9 lines
Quoted 5 lines

fs/f2fs/super.c static int sanity_check_raw_super(struct f2fs_sb_info *sbi, · line 2805

Quoted 5 lines
fs/f2fs/super.c +0 -0
   		f2fs_info(sbi, "Invalid segment/section count (%u, %u x %u)",
   			  segment_count, total_sections, segs_per_sec);

.

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

#4 lore raw
Quoted 41 lines · Yuchao (T)
Quoted 40 lines · wangxiaojun (N)
Quoted 30 lines · Yuchao (T)
Quoted 18 lines · Xiaojun Wang

Meta area is not included in section_count computation. The code in mkfs/f2fs_format.c is:

	total_zones = get_sb(segment_count) / (c.segs_per_zone) -
					total_meta_zones;
	set_sb(section_count, total_zones * c.secs_per_zone);

So the minimum total_sections is 1.

---
   fs/f2fs/super.c | 3 +--
   1 file changed, 1 insertion(+), 2 deletions(-)
fs/f2fs/super.c +0 -0
index dfa072fa8081..a450c8589841 100644

fs/f2fs/super.c static int sanity_check_raw_super(struct f2fs_sb_info *sbi, · line 2803

Quoted 7 lines
fs/f2fs/super.c +1 -2
@@ -2799,8 +2799,7 @@ static int sanity_check_raw_super(struct f2fs_sb_info *sbi,
   		return -EFSCORRUPTED;
   	}
 
-	if (total_sections > segment_count ||
-			total_sections < F2FS_MIN_SEGMENTS ||
+	if (total_sections > segment_count || total_sections < 1 ||
   			segs_per_sec > segment_count || !segs_per_sec) {

Here, we try to check sanity on segs_per_sec config directly and indirectly:
- directly: check raw_super->segs_per_sec field
- indirectly: check whether segment_count / total_sections is less than 1

Quoted 7 lines

So I guess that first condition is wrong as well, should change it like?

if (total_sections > segment_count - 'total_meta_segment_count' ||

Thoughts?

Thanks,

Hi Chao, aggree with you.

Quoted 8 lines
Quoted 6 lines

'total_meta_segment_count' = le32_to_cpu(raw_super->segment_count_ckpt) +

			le32_to_cpu(raw_super->segment_count_sit) +
			le32_to_cpu(raw_super->segment_count_nat) +
			le32_to_cpu(raw_super->segment_count_ssa)

But the above values will be checked in sanity_check_area_boundary() which will be called later. So can we move the total_sections checking to sanity_check_area_boundary

I think we'd better keep segs_per_sec check in sanity_check_raw_super(), as it's a field of superblock.

OK

Quoted 7 lines
Quoted 1 line

ensure the 'total_meta_segment_count' is correct ?

It looks the condition below is wrong as well for the same reason you mentioned in commit message?

if (unlikely(fsmeta < F2FS_MIN_SEGMENTS ||

Thanks,

Will updated in V2

Thanks,

Quoted 6 lines
Quoted 6 lines
Quoted 3 lines

fs/f2fs/super.c static int sanity_check_raw_super(struct f2fs_sb_info *sbi, · line 2805

Quoted 3 lines
fs/f2fs/super.c +0 -0
   		f2fs_info(sbi, "Invalid segment/section count (%u, %u x %u)",
   			  segment_count, total_sections, segs_per_sec);

.

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel