Whamcloud - gitweb
mke2fs: Avoid crashes / infinite loops for absurdly large devices
authorJan Kara <jack@suse.cz>
Tue, 25 Oct 2016 18:08:59 +0000 (14:08 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Tue, 25 Oct 2016 18:08:59 +0000 (14:08 -0400)
When a device reports absurdly high size, some arithmetics in mke2fs can
overflow (e.g. number of block descriptors) and we end in an infinite
loop. Fix that by checking and refusing insanely large devices.

Signed-off-by: Jan Kara <jack@suse.cz>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
misc/mke2fs.c

index d98e71e..6a83bd9 100644 (file)
@@ -2089,6 +2089,18 @@ profile_error:
                        EXT2_BLOCK_SIZE(&fs_param));
                exit(1);
        }
+       /*
+        * Guard against group descriptor count overflowing... Mostly to avoid
+        * strange results for absurdly large devices.
+        */
+       if (fs_blocks_count > ((1ULL << (fs_param.s_log_block_size + 3 + 32)) - 1)) {
+               fprintf(stderr, _("%s: Size of device (0x%llx blocks) %s "
+                                 "too big to create\n\t"
+                                 "a filesystem using a blocksize of %d.\n"),
+                       program_name, fs_blocks_count, device_name,
+                       EXT2_BLOCK_SIZE(&fs_param));
+               exit(1);
+       }
 
        ext2fs_blocks_count_set(&fs_param, fs_blocks_count);