Whamcloud - gitweb
resize2fs: prevent block bitmap warnings when doing extreme fs expansions
authorTheodore Ts'o <tytso@mit.edu>
Fri, 26 Feb 2021 02:40:27 +0000 (21:40 -0500)
committerTheodore Ts'o <tytso@mit.edu>
Fri, 26 Feb 2021 02:40:27 +0000 (21:40 -0500)
This commit fixes a bug where if a small file system is resized to
ridiculous sizes, such that the size of the resized block group
descriptor blocks exceed the original file system, and this would
result in resize2fs triggering a large number of scary warning
messages:

   Illegal block number passed to ext2fs_test_block_bitmap #12440
   for block bitmap for broken.img

This can be replicated via:

   ./misc/mke2fs broken.img -b 1024 -T default
   truncate -s +1500G broken.img
   ./resize/resize2fs broken.img

Fortunately, aside from triggering these warning messages, the bug had
no other bad effects.

https://github.com/tytso/e2fsprogs/issues/60

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
resize/resize2fs.c

index 5d2a856..a0d08e5 100644 (file)
@@ -1243,7 +1243,8 @@ static void mark_fs_metablock(ext2_resize_t rfs,
                 * nothing other than standard metadata in use.
                 */
                return;
-       } else if (ext2fs_test_block_bitmap2(rfs->old_fs->block_map, blk) &&
+       } else if (blk < ext2fs_blocks_count(rfs->old_fs->super) &&
+                  ext2fs_test_block_bitmap2(rfs->old_fs->block_map, blk) &&
                   !ext2fs_test_block_bitmap2(meta_bmap, blk)) {
                ext2fs_mark_block_bitmap2(rfs->move_blocks, blk);
                rfs->needed_blocks++;
@@ -1510,7 +1511,8 @@ static errcode_t blocks_to_move(ext2_resize_t rfs)
                if (ext2fs_block_bitmap_loc(old_fs, i) !=
                    (blk = ext2fs_block_bitmap_loc(fs, i))) {
                        ext2fs_block_alloc_stats2(fs, blk, +1);
-                       if (ext2fs_test_block_bitmap2(old_fs->block_map, blk) &&
+                       if (blk < ext2fs_blocks_count(old_fs->super) &&
+                           ext2fs_test_block_bitmap2(old_fs->block_map, blk) &&
                            !ext2fs_test_block_bitmap2(meta_bmap, blk))
                                ext2fs_mark_block_bitmap2(rfs->move_blocks,
                                                         blk);
@@ -1518,7 +1520,8 @@ static errcode_t blocks_to_move(ext2_resize_t rfs)
                if (ext2fs_inode_bitmap_loc(old_fs, i) !=
                    (blk = ext2fs_inode_bitmap_loc(fs, i))) {
                        ext2fs_block_alloc_stats2(fs, blk, +1);
-                       if (ext2fs_test_block_bitmap2(old_fs->block_map, blk) &&
+                       if (blk < ext2fs_blocks_count(old_fs->super) &&
+                           ext2fs_test_block_bitmap2(old_fs->block_map, blk) &&
                            !ext2fs_test_block_bitmap2(meta_bmap, blk))
                                ext2fs_mark_block_bitmap2(rfs->move_blocks,
                                                         blk);
@@ -1544,7 +1547,8 @@ static errcode_t blocks_to_move(ext2_resize_t rfs)
                for (blk = ext2fs_inode_table_loc(fs, i), j=0;
                     j < fs->inode_blocks_per_group ; j++, blk++) {
                        ext2fs_block_alloc_stats2(fs, blk, +1);
-                       if (ext2fs_test_block_bitmap2(old_fs->block_map, blk) &&
+                       if (blk < ext2fs_blocks_count(old_fs->super) &&
+                           ext2fs_test_block_bitmap2(old_fs->block_map, blk) &&
                            !ext2fs_test_block_bitmap2(meta_bmap, blk))
                                ext2fs_mark_block_bitmap2(rfs->move_blocks,
                                                         blk);