Blame SOURCES/e2fsprogs-1.45.6-resize2fs-prevent-block-group-descriptors-from-overf.patch

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