|
|
f239de |
From 742255d914bf06fa8e8a3f048aae2c738657af52 Mon Sep 17 00:00:00 2001
|
|
|
f239de |
From: Theodore Ts'o <tytso@mit.edu>
|
|
|
f239de |
Date: Fri, 2 Oct 2020 14:47:25 -0400
|
|
|
f239de |
Subject: [PATCH 11/46] resize2fs: prevent block group descriptors from
|
|
|
f239de |
overflowing the first bg
|
|
|
f239de |
Content-Type: text/plain
|
|
|
f239de |
|
|
|
f239de |
For 1k block file systems, resizing a file system larger than
|
|
|
f239de |
1073610752 blocks will result in the size of the block group
|
|
|
f239de |
descriptors to be so large that it will overlap with the backup
|
|
|
f239de |
superblock in block group #1. This problem can be reproduced via:
|
|
|
f239de |
|
|
|
f239de |
mke2fs -t ext4 /tmp/foo.img 200M
|
|
|
f239de |
resize2fs /tmp/foo.img 1T
|
|
|
f239de |
e2fsck -f /tmp/foo.img
|
|
|
f239de |
|
|
|
f239de |
https://github.com/tytso/e2fsprogs/issues/50
|
|
|
f239de |
|
|
|
f239de |
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
|
|
|
f239de |
Signed-off-by: Lukas Czerner <lczerner@redhat.com>
|
|
|
f239de |
---
|
|
|
f239de |
resize/main.c | 14 ++++++++++++++
|
|
|
f239de |
1 file changed, 14 insertions(+)
|
|
|
f239de |
|
|
|
f239de |
diff --git a/resize/main.c b/resize/main.c
|
|
|
f239de |
index a0c31c06..5e771d2a 100644
|
|
|
f239de |
--- a/resize/main.c
|
|
|
f239de |
+++ b/resize/main.c
|
|
|
f239de |
@@ -269,6 +269,8 @@ int main (int argc, char ** argv)
|
|
|
f239de |
long sysval;
|
|
|
f239de |
int len, mount_flags;
|
|
|
f239de |
char *mtpt, *undo_file = NULL;
|
|
|
f239de |
+ dgrp_t new_group_desc_count;
|
|
|
f239de |
+ unsigned long new_desc_blocks;
|
|
|
f239de |
|
|
|
f239de |
#ifdef ENABLE_NLS
|
|
|
f239de |
setlocale(LC_MESSAGES, "");
|
|
|
f239de |
@@ -528,6 +530,18 @@ int main (int argc, char ** argv)
|
|
|
f239de |
exit(1);
|
|
|
f239de |
}
|
|
|
f239de |
}
|
|
|
f239de |
+ new_group_desc_count = ext2fs_div64_ceil(new_size -
|
|
|
f239de |
+ fs->super->s_first_data_block,
|
|
|
f239de |
+ EXT2_BLOCKS_PER_GROUP(fs->super));
|
|
|
f239de |
+ new_desc_blocks = ext2fs_div_ceil(new_group_desc_count,
|
|
|
f239de |
+ EXT2_DESC_PER_BLOCK(fs->super));
|
|
|
f239de |
+ if ((new_desc_blocks + fs->super->s_first_data_block) >
|
|
|
f239de |
+ EXT2_BLOCKS_PER_GROUP(fs->super)) {
|
|
|
f239de |
+ com_err(program_name, 0,
|
|
|
f239de |
+ _("New size results in too many block group "
|
|
|
f239de |
+ "descriptors.\n"));
|
|
|
f239de |
+ exit(1);
|
|
|
f239de |
+ }
|
|
|
f239de |
|
|
|
f239de |
if (!force && new_size < min_size) {
|
|
|
f239de |
com_err(program_name, 0,
|
|
|
f239de |
--
|
|
|
f239de |
2.35.1
|
|
|
f239de |
|