]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
e2fsck: handle s_inodes_count corruption properly
authorJan Kara <jack@suse.cz>
Tue, 19 Jun 2018 15:23:37 +0000 (11:23 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Tue, 19 Jun 2018 15:27:45 +0000 (11:27 -0400)
When s_inodes_count would overflow given number of groups and inodes per
group, we cannot currently fix the breakage in e2fsck as that requires
trimming number of groups or inodes per group which both means data &
inode migration etc. Just trimming sb->s_inodes_count is not enough as
kernel's inode allocation code is not able to handle filesystems where
not all inodes in the last group are usable. So don't pretend we can fix
s_inodes_count overflow by just trimming the s_inodes_count value.

When s_inodes_count is just wrong but will not overflow, let's fix it.
Also move this check before we use s_inodes_count for checking
s_first_ino.

Signed-off-by: Jan Kara <jack@suse.cz>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
e2fsck/problem.c
e2fsck/problem.h
e2fsck/super.c

index edc9d51fcf31e12f52de0a7636ce078a5623cec5..efe98c920661e23a2e71ecf73e5082c79278d62e 100644 (file)
@@ -493,6 +493,11 @@ static struct e2fsck_problem problem_table[] = {
          N_("Invalid %U @q @i %i.  "),
          PROMPT_FIX, 0 },
 
+       /* Too many inodes in the filesystem */
+       { PR_0_INODE_COUNT_BIG,
+         N_("@S would have too many inodes (%N).\n"),
+         PROMPT_NONE, PR_AFTER_CODE, PR_0_SB_CORRUPT },
+
        /* Pass 1 errors */
 
        /* Pass 1: Checking inodes, blocks, and sizes */
index 482d111a0f2ceccf094e1541efe7d364bbed9f8e..b6bca668bb1b59039319fa7272221242b4b1fbb4 100644 (file)
@@ -282,6 +282,8 @@ struct problem_context {
 /* Invalid quota inode number */
 #define PR_0_INVALID_QUOTA_INO                 0x00004F
 
+/* Inode count in the superblock incorrect */
+#define PR_0_INODE_COUNT_BIG                   0x000050
 
 /*
  * Pass 1 errors
index 9c0e0e7b35b4a0aa5525964214e6352610dce3fd..60a19a7e27677ecd2fcb0fa3ee7051b24d67f66f 100644 (file)
@@ -646,6 +646,22 @@ void check_super_block(e2fsck_t ctx)
        check_super_value(ctx, "desc_size",
                          sb->s_desc_size, MAX_CHECK | LOG2_CHECK, 0,
                          EXT2_MAX_DESC_SIZE);
+
+       should_be = (__u64)sb->s_inodes_per_group * fs->group_desc_count;
+       if (should_be > ~0U) {
+               pctx.num = should_be;
+               fix_problem(ctx, PR_0_INODE_COUNT_BIG, &pctx);
+               ctx->flags |= E2F_FLAG_ABORT;
+               return;
+       }
+       if (sb->s_inodes_count != should_be) {
+               pctx.ino = sb->s_inodes_count;
+               pctx.ino2 = should_be;
+               if (fix_problem(ctx, PR_0_INODE_COUNT_WRONG, &pctx)) {
+                       sb->s_inodes_count = should_be;
+                       ext2fs_mark_super_dirty(fs);
+               }
+       }
        if (sb->s_rev_level > EXT2_GOOD_OLD_REV)
                check_super_value(ctx, "first_ino", sb->s_first_ino,
                                  MIN_CHECK | MAX_CHECK,
@@ -683,17 +699,6 @@ void check_super_block(e2fsck_t ctx)
                return;
        }
 
-       should_be = (blk64_t)sb->s_inodes_per_group * fs->group_desc_count;
-       if (should_be > UINT_MAX)
-               should_be = UINT_MAX;
-       if (sb->s_inodes_count != should_be) {
-               pctx.ino = sb->s_inodes_count;
-               pctx.ino2 = should_be;
-               if (fix_problem(ctx, PR_0_INODE_COUNT_WRONG, &pctx)) {
-                       sb->s_inodes_count = should_be;
-                       ext2fs_mark_super_dirty(fs);
-               }
-       }
        if (EXT2_INODE_SIZE(sb) > EXT2_GOOD_OLD_INODE_SIZE) {
                unsigned min =
                        sizeof(((struct ext2_inode_large *) 0)->i_extra_isize) +