Whamcloud - gitweb
e2fsck: fix e2fsck_allocate_memory() overflow
authorAndreas Dilger <adilger@whamcloud.com>
Fri, 7 Feb 2020 01:09:38 +0000 (18:09 -0700)
committerTheodore Ts'o <tytso@mit.edu>
Sat, 29 Feb 2020 23:24:42 +0000 (18:24 -0500)
commit74fbba1ff1074333eedaa3ed46597294641bf6b8
tree1ea3ea59fc16e87a0e897dfeda7978963e3a1621
parent336c440ccea8f94b0728f881cddee84f730e7cc7
e2fsck: fix e2fsck_allocate_memory() overflow

e2fsck_allocate_memory() takes an "unsigned int size" argument, which
will overflow for allocations above 4GB.  This happens for dir_info
and dx_dir_info arrays when there are more than 350M directories in a
filesystem, and for the dblist array above 180M directories.

There is also a risk of overflow during the binary search in both
e2fsck_get_dir_info() and e2fsck_get_dx_dir_info() when the midpoint
of the array is calculated, if there would be more than 2B directories
in the filesystem and working above the half way point.

Also, in some places inode numbers are "int" instead of "ext2_ino_t",
which can also cause problems with the array size calculations, and
makes it hard to identify where inode numbers are used.

Fix e2fsck_allocate_memory() to take an "unsigned long" argument to
match ext2fs_get_mem(), so that it can do single memory allocations
over 4GB.

Fix e2fsck_get_dir_info() and e2fsck_get_dx_dir_info() to temporarily
use an unsigned long long value to calculate the midpoint (which will
always fit into an ext2_ino_t again afterward).

Change variables that hold inode numbers to be ext2_ino_t, and print
them as unsigned values instead of printing negative inode numbers.

Signed-off-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Shilong Wang <wshilong@ddn.com>
Lustre-bug-id: https://jira.whamcloud.com/browse/LU-13197
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
e2fsck/dirinfo.c
e2fsck/dx_dirinfo.c
e2fsck/e2fsck.h
e2fsck/logfile.c
e2fsck/pass2.c
e2fsck/util.c