Blame SOURCES/e2fsprogs-1.45.6-libext2fs-fix-crash-in-ext2fs_image_super_write-on-B.patch

f239de
From 20a8dbefbc0510430aa7744692221b843b657f62 Mon Sep 17 00:00:00 2001
f239de
From: Theodore Ts'o <tytso@mit.edu>
f239de
Date: Tue, 14 Jan 2020 10:58:10 -0500
f239de
Subject: [PATCH 02/46] libext2fs: fix crash in ext2fs_image_super_write() on
f239de
 Big Endian systems
f239de
Content-Type: text/plain
f239de
f239de
This is a similar fix as c9a8c53b17cc ("libext2fs: fix crash in
f239de
ext2fs_open2() on Big Endian systems").
f239de
f239de
Commit e6069a05: ("Teach ext2fs_open2() to honor the
f239de
EXT2_FLAG_SUPER_ONLY flag") changed how the function
f239de
ext2fs_group_desc() handled a request for a gdp pointer for a group
f239de
larger than the number of groups in the file system; it now returns
f239de
NULL, instead of returning a pointer beyond the end of the array.
f239de
f239de
Previously, the ext2fs_imager_super_write() function would swap all of
f239de
the block group descriptors in a block, even if they are beyond the
f239de
end of the file system.  This was OK, since we were not overrunning
f239de
the allocated memory, since it was rounded to a block boundary.  But
f239de
now that ext2fs_group_desc() would return NULL for those gdp, it would
f239de
cause ext2fs_open2(), when it was byte swapping the block group
f239de
descriptors on Big Endian systems, to dereference a null pointer and
f239de
crash.
f239de
f239de
This commit adds a NULL pointer check to avoid byte swapping those
f239de
block group descriptors in a bg descriptor block, but which are beyond
f239de
the end of the file system, to address this crash.
f239de
f239de
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
f239de
Reported-by: Anatoly Pugachev <matorola@gmail.com>
f239de
Signed-off-by: Lukas Czerner <lczerner@redhat.com>
f239de
---
f239de
 lib/ext2fs/imager.c | 8 ++++----
f239de
 1 file changed, 4 insertions(+), 4 deletions(-)
f239de
f239de
diff --git a/lib/ext2fs/imager.c b/lib/ext2fs/imager.c
f239de
index b3ede9a8..f8d67d86 100644
f239de
--- a/lib/ext2fs/imager.c
f239de
+++ b/lib/ext2fs/imager.c
f239de
@@ -249,10 +249,10 @@ errcode_t ext2fs_image_super_write(ext2_filsys fs, int fd,
f239de
 	 * if needed
f239de
 	 */
f239de
 	groups_per_block = EXT2_DESC_PER_BLOCK(fs->super);
f239de
-	gdp = (struct ext2_group_desc *) cp;
f239de
 	for (j=0; j < groups_per_block*fs->desc_blocks; j++) {
f239de
 		gdp = ext2fs_group_desc(fs, fs->group_desc, j);
f239de
-		ext2fs_swap_group_desc2(fs, gdp);
f239de
+		if (gdp)
f239de
+			ext2fs_swap_group_desc2(fs, gdp);
f239de
 	}
f239de
 #endif
f239de
 
f239de
@@ -261,10 +261,10 @@ errcode_t ext2fs_image_super_write(ext2_filsys fs, int fd,
f239de
 
f239de
 #ifdef WORDS_BIGENDIAN
f239de
 	groups_per_block = EXT2_DESC_PER_BLOCK(fs->super);
f239de
-	gdp = (struct ext2_group_desc *) cp;
f239de
 	for (j=0; j < groups_per_block*fs->desc_blocks; j++) {
f239de
 		gdp = ext2fs_group_desc(fs, fs->group_desc, j);
f239de
-		ext2fs_swap_group_desc2(fs, gdp);
f239de
+		if (gdp)
f239de
+			ext2fs_swap_group_desc2(fs, gdp);
f239de
 	}
f239de
 #endif
f239de
 
f239de
-- 
f239de
2.35.1
f239de