aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTheodore Ts'o <tytso@mit.edu>2022-09-13 07:59:52 -0400
committerTheodore Ts'o <tytso@mit.edu>2022-09-13 07:59:52 -0400
commit281dcbfb1d59d0db95d4f81b8b9c275d87515ceb (patch)
tree43aad23d5d8b36b5772827b989e719b4b8308575
parenta721b865d97cef58d7bca3bd03c8190342da79e8 (diff)
downloade2fsprogs-281dcbfb1d59d0db95d4f81b8b9c275d87515ceb.tar.gz
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 <tytso@mit.edu>
-rw-r--r--lib/ext2fs/openfs.c6
-rw-r--r--tests/f_first_meta_bg_too_big/expect.14
2 files changed, 10 insertions, 0 deletions
diff --git a/lib/ext2fs/openfs.c b/lib/ext2fs/openfs.c
index 39229d7ca..fea352f5b 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 85786bda5..3148513ca 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