Whamcloud - gitweb
libext2fs: fix crash in ext2fs_open2() on Big Endian systems
authorTheodore Ts'o <tytso@mit.edu>
Fri, 27 Dec 2019 04:19:54 +0000 (23:19 -0500)
committerTheodore Ts'o <tytso@mit.edu>
Fri, 27 Dec 2019 04:19:54 +0000 (23:19 -0500)
commitc9a8c53b17ccc4543509d55ff3b343ddbfe805e5
tree7c39a6ec7a2a81ecb358f5648a315d429f1d0736
parent523219f20a09b8e5b396e5b64bd4ef2962861cb5
libext2fs: fix crash in ext2fs_open2() on Big Endian systems

Commit e6069a05: ("Teach ext2fs_open2() to honor the
EXT2_FLAG_SUPER_ONLY flag") changed how the function
ext2fs_group_desc() handled a request for a gdp pointer for a group
larger than the number of groups in the file system; it now returns
NULL, instead of returning a pointer beyond the end of the array.

Previously, the ext2fs_open2() function would swap all of the block
group descriptors in a block, even if they are beyond the end of the
file system.  This was OK, since we were not overrunning the allocated
memory, since it was rounded to a block boundary.  But now that
ext2fs_group_desc() would return NULL for those gdp, it would cause
ext2fs_open2(), when it was byte swapping the block group descriptors
on Big Endian systems, to dereference a null pointer and crash.

This commit adds a NULL pointer check to avoid byte swapping those
block group descriptors in a bg descriptor block, but which are beyond
the end of the file system, to address this crash.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Reported-by: Anatoly Pugachev <matorola@gmail.com>
lib/ext2fs/openfs.c