diff options
author | Theodore Ts'o <tytso@mit.edu> | 2022-08-08 20:17:40 -0400 |
---|---|---|
committer | Theodore Ts'o <tytso@mit.edu> | 2022-08-08 20:17:40 -0400 |
commit | 42c11edd0863e093a2cb84c56720af0e9b8e8c68 (patch) | |
tree | 1395ab69b7947161b5018d90e7f859483882e84e | |
parent | 54445dc254dec30649dad8e1bb2c7a9990137a36 (diff) | |
download | e2fsprogs-42c11edd0863e093a2cb84c56720af0e9b8e8c68.tar.gz |
libext2fs: in ext2fs_open[2](), return an error if s_desc_size is too large
Previously, ext2fs_open() and ext2fs_open2() would return an error if
s_desc_size is too small. Add a check so it will return an error if
s_desc_size is too large, as well.
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-- | e2fsck/unix.c | 3 | ||||
-rw-r--r-- | lib/ext2fs/openfs.c | 9 | ||||
-rw-r--r-- | tests/f_desc_size_bad/expect.1 | 2 |
3 files changed, 11 insertions, 3 deletions
diff --git a/e2fsck/unix.c b/e2fsck/unix.c index f267bae2c..af57e6abc 100644 --- a/e2fsck/unix.c +++ b/e2fsck/unix.c @@ -1619,7 +1619,8 @@ failure: * so that we are able to recover from more errors * (e.g. some tool messing up some value in the sb). */ - if ((retval == EXT2_ET_CORRUPT_SUPERBLOCK) && + if (((retval == EXT2_ET_CORRUPT_SUPERBLOCK) || + (retval == EXT2_ET_BAD_DESC_SIZE)) && !(flags & EXT2_FLAG_IGNORE_SB_ERRORS)) { if (fs) ext2fs_close_free(&fs); diff --git a/lib/ext2fs/openfs.c b/lib/ext2fs/openfs.c index bda8274fb..39229d7ca 100644 --- a/lib/ext2fs/openfs.c +++ b/lib/ext2fs/openfs.c @@ -330,8 +330,13 @@ retry: } /* Enforce the block group descriptor size */ - if (ext2fs_has_feature_64bit(fs->super)) { - if (fs->super->s_desc_size < EXT2_MIN_DESC_SIZE_64BIT) { + if (!(flags & EXT2_FLAG_IGNORE_SB_ERRORS) && + ext2fs_has_feature_64bit(fs->super)) { + unsigned desc_size = fs->super->s_desc_size; + + if ((desc_size < EXT2_MIN_DESC_SIZE_64BIT) || + (desc_size > EXT2_MAX_DESC_SIZE) || + (desc_size & (desc_size - 1)) != 0) { retval = EXT2_ET_BAD_DESC_SIZE; goto cleanup; } diff --git a/tests/f_desc_size_bad/expect.1 b/tests/f_desc_size_bad/expect.1 index 122a5774d..84b852a40 100644 --- a/tests/f_desc_size_bad/expect.1 +++ b/tests/f_desc_size_bad/expect.1 @@ -1,3 +1,5 @@ +../e2fsck/e2fsck: Block group descriptor size incorrect while trying to open test.img +../e2fsck/e2fsck: Trying to load superblock despite errors... ext2fs_check_desc: Block group descriptor size incorrect ../e2fsck/e2fsck: Group descriptors look bad... trying backup blocks... Pass 1: Checking inodes, blocks, and sizes |