Whamcloud - gitweb
libext2fs: in ext2fs_open[2](), return an error if s_desc_size is too large
authorTheodore Ts'o <tytso@mit.edu>
Tue, 9 Aug 2022 00:17:40 +0000 (20:17 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Tue, 9 Aug 2022 00:17:40 +0000 (20:17 -0400)
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>
e2fsck/unix.c
lib/ext2fs/openfs.c
tests/f_desc_size_bad/expect.1

index f267bae..af57e6a 100644 (file)
@@ -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);
index bda8274..39229d7 100644 (file)
@@ -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;
                }
index 122a577..84b852a 100644 (file)
@@ -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