Blame SOURCES/e2fsprogs-1.42.9-14-mke2fs-Avoid-crashes-infinite-loops-for-absurdly-lar.patch

0ef434
From f7da56758e5d15416339d640f79d6eee875d22a9 Mon Sep 17 00:00:00 2001
0ef434
From: Jan Kara <jack@suse.cz>
0ef434
Date: Tue, 25 Oct 2016 14:08:59 -0400
0ef434
Subject: [PATCH 09/16] mke2fs: Avoid crashes / infinite loops for absurdly
0ef434
 large devices
0ef434
0ef434
commit 101ef2e93c253ae62320628e8958067d2d2a4e2a
0ef434
0ef434
When a device reports absurdly high size, some arithmetics in mke2fs can
0ef434
overflow (e.g. number of block descriptors) and we end in an infinite
0ef434
loop. Fix that by checking and refusing insanely large devices.
0ef434
0ef434
Signed-off-by: Jan Kara <jack@suse.cz>
0ef434
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
0ef434
---
0ef434
 misc/mke2fs.c | 12 ++++++++++++
0ef434
 1 file changed, 12 insertions(+)
0ef434
0ef434
diff --git a/misc/mke2fs.c b/misc/mke2fs.c
0ef434
index 2787a127..7cea0330 100644
0ef434
--- a/misc/mke2fs.c
0ef434
+++ b/misc/mke2fs.c
0ef434
@@ -1858,6 +1858,18 @@ profile_error:
0ef434
 			EXT2_BLOCK_SIZE(&fs_param));
0ef434
 		exit(1);
0ef434
 	}
0ef434
+	/*
0ef434
+	 * Guard against group descriptor count overflowing... Mostly to avoid
0ef434
+	 * strange results for absurdly large devices.
0ef434
+	 */
0ef434
+	if (fs_blocks_count > ((1ULL << (fs_param.s_log_block_size + 3 + 32)) - 1)) {
0ef434
+		fprintf(stderr, _("%s: Size of device (0x%llx blocks) %s "
0ef434
+				  "too big to create\n\t"
0ef434
+				  "a filesystem using a blocksize of %d.\n"),
0ef434
+			program_name, fs_blocks_count, device_name,
0ef434
+			EXT2_BLOCK_SIZE(&fs_param));
0ef434
+		exit(1);
0ef434
+	}
0ef434
 
0ef434
 	ext2fs_blocks_count_set(&fs_param, fs_blocks_count);
0ef434
 
0ef434
-- 
0ef434
2.20.1
0ef434