linux-f2fs-devel.lists.sourceforge.net archive mirror
 help / color / mirror / Atom feed
From: Eric Biggers <ebiggers@kernel.org>
To: linux-f2fs-devel@lists.sourceforge.net
Subject: [f2fs-dev] [PATCH] mkfs.f2fs: catch total_zones=0 instead of crashing
Date: Mon, 15 Aug 2022 21:48:32 -0700	[thread overview]
Message-ID: <20220816044832.129302-1-ebiggers@kernel.org> (raw)

From: Eric Biggers <ebiggers@google.com>

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().

Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 mkfs/f2fs_format.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/mkfs/f2fs_format.c b/mkfs/f2fs_format.c
index 7cd5815..40ac589 100644
--- a/mkfs/f2fs_format.c
+++ b/mkfs/f2fs_format.c
@@ -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
-- 
2.37.1



_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

                 reply	other threads:[~2022-08-16  4:49 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220816044832.129302-1-ebiggers@kernel.org \
    --to=ebiggers@kernel.org \
    --cc=linux-f2fs-devel@lists.sourceforge.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).