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

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