Whamcloud - gitweb
e2fsck: don't try backup superblocks beyond the size of the device
authorTheodore Ts'o <tytso@mit.edu>
Wed, 17 Apr 2024 20:52:00 +0000 (16:52 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Wed, 17 Apr 2024 20:58:26 +0000 (16:58 -0400)
commitb53ce7848c2ed2cf4acf2ba9384e96129bc89d25
treec02f0263a0f1eb1e630ae50955893b319ca30b9b
parent55bc5ce40648e4df91c019b05fbfcc9c5b803c10
e2fsck: don't try backup superblocks beyond the size of the device

Commit f7ef5f3e356d ("e2fsck: check all sparse_super backups") tries
to limit the number of block groups to search for backup superblocks
based on ctx->num_blocks.  Unfortunately, get_backup_sb() gets called
before ctx->num_blocks is set, so we try all block groups up to 2**32
- 1.  Not only does this waste time trying to read from blocks that
don't exist, it triggers the UBSAN checker when multiplying a very
large number by the block size.

Fix this by using ext2fs_get_Device_size(), and if that isn't
available, arbitrarily cap things so that we search block groups up to
128.

Fixes: f7ef5f3e356d ("e2fsck: check all sparse_super backups")
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
e2fsck/util.c