Blame SOURCES/e2fsprogs-1.45.6-libext2fs-fix-crash-in-ext2fs_open2-on-Big-Endian-sy.patch

a77133
From db2efc9e0a8cdb70afc8dd7c9621da9376da7afb Mon Sep 17 00:00:00 2001
a77133
From: Theodore Ts'o <tytso@mit.edu>
a77133
Date: Thu, 26 Dec 2019 23:19:54 -0500
a77133
Subject: [PATCH 01/46] libext2fs: fix crash in ext2fs_open2() on Big Endian
a77133
 systems
a77133
Content-Type: text/plain
a77133
a77133
Commit e6069a05: ("Teach ext2fs_open2() to honor the
a77133
EXT2_FLAG_SUPER_ONLY flag") changed how the function
a77133
ext2fs_group_desc() handled a request for a gdp pointer for a group
a77133
larger than the number of groups in the file system; it now returns
a77133
NULL, instead of returning a pointer beyond the end of the array.
a77133
a77133
Previously, the ext2fs_open2() function would swap all of the block
a77133
group descriptors in a block, even if they are beyond the end of the
a77133
file system.  This was OK, since we were not overrunning the allocated
a77133
memory, since it was rounded to a block boundary.  But now that
a77133
ext2fs_group_desc() would return NULL for those gdp, it would cause
a77133
ext2fs_open2(), when it was byte swapping the block group descriptors
a77133
on Big Endian systems, to dereference a null pointer and crash.
a77133
a77133
This commit adds a NULL pointer check to avoid byte swapping those
a77133
block group descriptors in a bg descriptor block, but which are beyond
a77133
the end of the file system, to address this crash.
a77133
a77133
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
a77133
Reported-by: Anatoly Pugachev <matorola@gmail.com>
a77133
Signed-off-by: Lukas Czerner <lczerner@redhat.com>
a77133
---
a77133
 lib/ext2fs/openfs.c | 6 ++++--
a77133
 1 file changed, 4 insertions(+), 2 deletions(-)
a77133
a77133
diff --git a/lib/ext2fs/openfs.c b/lib/ext2fs/openfs.c
a77133
index 51b54a44..e457ce1a 100644
a77133
--- a/lib/ext2fs/openfs.c
a77133
+++ b/lib/ext2fs/openfs.c
a77133
@@ -433,7 +433,8 @@ errcode_t ext2fs_open2(const char *name, const char *io_options,
a77133
 		gdp = (struct ext2_group_desc *) dest;
a77133
 		for (j=0; j < groups_per_block*first_meta_bg; j++) {
a77133
 			gdp = ext2fs_group_desc(fs, fs->group_desc, j);
a77133
-			ext2fs_swap_group_desc2(fs, gdp);
a77133
+			if (gdp)
a77133
+				ext2fs_swap_group_desc2(fs, gdp);
a77133
 		}
a77133
 #endif
a77133
 		dest += fs->blocksize*first_meta_bg;
a77133
@@ -453,7 +454,8 @@ errcode_t ext2fs_open2(const char *name, const char *io_options,
a77133
 		for (j=0; j < groups_per_block; j++) {
a77133
 			gdp = ext2fs_group_desc(fs, fs->group_desc,
a77133
 						i * groups_per_block + j);
a77133
-			ext2fs_swap_group_desc2(fs, gdp);
a77133
+			if (gdp)
a77133
+				ext2fs_swap_group_desc2(fs, gdp);
a77133
 		}
a77133
 #endif
a77133
 		dest += fs->blocksize;
a77133
-- 
a77133
2.35.1
a77133