Whamcloud - gitweb
LU-13197 e2fsck: fix e2fsck_allocate_memory() overflow 23/37423/7
authorAndreas Dilger <adilger@whamcloud.com>
Tue, 4 Feb 2020 05:32:12 +0000 (22:32 -0700)
committerAndreas Dilger <adilger@whamcloud.com>
Fri, 22 May 2020 06:18:23 +0000 (06:18 +0000)
commit007512516f96292f29cf8c3ea1534880a7802081
tree026e54c8bd5a257654a166ba677ebf3961088c1b
parent815b2a77c913198181284dba2130e1802c881182
LU-13197 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.

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 so
that it can do single memory allocations larger than 4GB.  Change
variables that hold inode numbers to be ext2_ino_t, and print them as
unsigned values instead of signed.

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.

Signed-off-by: Andreas Dilger <adilger@whamcloud.com>
Change-Id: If6624feb391be2ebf2ddfa46f62a0d2b3f3ebbe5
Reviewed-on: https://review.whamcloud.com/37423
Reviewed-by: Wang Shilong <wshilong@ddn.com>
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
e2fsck/dirinfo.c
e2fsck/dx_dirinfo.c
e2fsck/e2fsck.h
e2fsck/logfile.c
e2fsck/pass2.c
e2fsck/util.c