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