|
|
a77133 |
From 20a8dbefbc0510430aa7744692221b843b657f62 Mon Sep 17 00:00:00 2001
|
|
|
a77133 |
From: Theodore Ts'o <tytso@mit.edu>
|
|
|
a77133 |
Date: Tue, 14 Jan 2020 10:58:10 -0500
|
|
|
a77133 |
Subject: [PATCH 02/46] libext2fs: fix crash in ext2fs_image_super_write() on
|
|
|
a77133 |
Big Endian systems
|
|
|
a77133 |
Content-Type: text/plain
|
|
|
a77133 |
|
|
|
a77133 |
This is a similar fix as c9a8c53b17cc ("libext2fs: fix crash in
|
|
|
a77133 |
ext2fs_open2() on Big Endian systems").
|
|
|
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_imager_super_write() function would swap all of
|
|
|
a77133 |
the block group descriptors in a block, even if they are beyond the
|
|
|
a77133 |
end of the file system. This was OK, since we were not overrunning
|
|
|
a77133 |
the allocated memory, since it was rounded to a block boundary. But
|
|
|
a77133 |
now that ext2fs_group_desc() would return NULL for those gdp, it would
|
|
|
a77133 |
cause ext2fs_open2(), when it was byte swapping the block group
|
|
|
a77133 |
descriptors on Big Endian systems, to dereference a null pointer and
|
|
|
a77133 |
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/imager.c | 8 ++++----
|
|
|
a77133 |
1 file changed, 4 insertions(+), 4 deletions(-)
|
|
|
a77133 |
|
|
|
a77133 |
diff --git a/lib/ext2fs/imager.c b/lib/ext2fs/imager.c
|
|
|
a77133 |
index b3ede9a8..f8d67d86 100644
|
|
|
a77133 |
--- a/lib/ext2fs/imager.c
|
|
|
a77133 |
+++ b/lib/ext2fs/imager.c
|
|
|
a77133 |
@@ -249,10 +249,10 @@ errcode_t ext2fs_image_super_write(ext2_filsys fs, int fd,
|
|
|
a77133 |
* if needed
|
|
|
a77133 |
*/
|
|
|
a77133 |
groups_per_block = EXT2_DESC_PER_BLOCK(fs->super);
|
|
|
a77133 |
- gdp = (struct ext2_group_desc *) cp;
|
|
|
a77133 |
for (j=0; j < groups_per_block*fs->desc_blocks; 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 |
|
|
|
a77133 |
@@ -261,10 +261,10 @@ errcode_t ext2fs_image_super_write(ext2_filsys fs, int fd,
|
|
|
a77133 |
|
|
|
a77133 |
#ifdef WORDS_BIGENDIAN
|
|
|
a77133 |
groups_per_block = EXT2_DESC_PER_BLOCK(fs->super);
|
|
|
a77133 |
- gdp = (struct ext2_group_desc *) cp;
|
|
|
a77133 |
for (j=0; j < groups_per_block*fs->desc_blocks; 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 |
|
|
|
a77133 |
--
|
|
|
a77133 |
2.35.1
|
|
|
a77133 |
|