From: Theodore Ts'o Date: Tue, 13 Sep 2022 11:59:52 +0000 (-0400) Subject: libext2fs: in ext2fs_open[2](), return an error if s_first_meta_bg is too big X-Git-Tag: v1.46.6-wc1~97 X-Git-Url: https://git.whamcloud.com/tools/e2fsprogs.git/?a=commitdiff_plain;h=281dcbfb1d59d0db95d4f81b8b9c275d87515ceb;p=tools%2Fe2fsprogs.git libext2fs: in ext2fs_open[2](), return an error if s_first_meta_bg is too big These checks will be skipped for e2fsck when it uses the flag EXT2_FLAG_IGNORE_SB_ERRORS. Signed-off-by: Theodore Ts'o --- diff --git a/lib/ext2fs/openfs.c b/lib/ext2fs/openfs.c index 39229d7..fea352f 100644 --- a/lib/ext2fs/openfs.c +++ b/lib/ext2fs/openfs.c @@ -409,6 +409,12 @@ retry: } fs->desc_blocks = ext2fs_div_ceil(fs->group_desc_count, EXT2_DESC_PER_BLOCK(fs->super)); + if (ext2fs_has_feature_meta_bg(fs->super) && + (fs->super->s_first_meta_bg > fs->desc_blocks) && + !(flags & EXT2_FLAG_IGNORE_SB_ERRORS)) { + retval = EXT2_ET_CORRUPT_SUPERBLOCK; + goto cleanup; + } if (flags & EXT2_FLAG_SUPER_ONLY) goto skip_read_bg; retval = ext2fs_get_array(fs->desc_blocks, fs->blocksize, diff --git a/tests/f_first_meta_bg_too_big/expect.1 b/tests/f_first_meta_bg_too_big/expect.1 index 85786bd..3148513 100644 --- a/tests/f_first_meta_bg_too_big/expect.1 +++ b/tests/f_first_meta_bg_too_big/expect.1 @@ -1,3 +1,7 @@ +ext2fs_open2: The ext2 superblock is corrupt +../e2fsck/e2fsck: Superblock invalid, trying backup blocks... +../e2fsck/e2fsck: The ext2 superblock is corrupt while trying to open test.img +../e2fsck/e2fsck: Trying to load superblock despite errors... First_meta_bg is too big. (2, max value 1). Clear? yes Pass 1: Checking inodes, blocks, and sizes