Skip to contentSkip to conversation

mkfs.f2fs: catch total_zones=0 instead of crashing

PATCH New Eric Biggers 1 participant 1 message Aug 16, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mkfs.f2fs: catch total_zones=0 instead of crashing

From: Eric Biggers <[email protected]>

Cleanly report an error instead of dividing by 0 (causing a floating point exception) in the following case:

	truncate -s 16M img && mkfs.f2fs img

Note that this is a minimal fix; it appears that overly-small images still cause various integer overflows in f2fs_prepare_super_block().

---
 mkfs/f2fs_format.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
mkfs/f2fs_format.c +7 -3
index 7cd5815..40ac589 100644
@@ -467,7 +467,8 @@ static int f2fs_prepare_super_block(void)
 
 	total_zones = get_sb(segment_count) / (c.segs_per_zone) -
 							total_meta_zones;
-
+	if (total_zones == 0)
+		goto too_small;
 	set_sb(section_count, total_zones * c.secs_per_zone);
 
 	set_sb(segment_count_main, get_sb(section_count) * c.segs_per_sec);
@@ -497,8 +498,7 @@ static int f2fs_prepare_super_block(void)
 			c.sector_size < zone_align_start_offset) ||
 		(get_sb(segment_count_main) - NR_CURSEG_TYPE) <
 						c.reserved_segments) {
-		MSG(0, "\tError: Device size is not sufficient for F2FS volume\n");
-		return -1;
+		goto too_small;
 	}
 
 	if (c.vol_uuid) {
@@ -612,6 +612,10 @@ static int f2fs_prepare_super_block(void)
 	}
 
 	return 0;
+
+too_small:
+	MSG(0, "\tError: Device size is not sufficient for F2FS volume\n");
+	return -1;
 }
 
 static int f2fs_init_sit_area(void)

base-commit: 6148db344eb25b23a7cbde36d026011cd15b6143

Signature · 8 lines
2.37.1



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