]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
e2fsck: clear i_block[] when there are too many bad mappings on a special inode
authorDarrick J. Wong <darrick.wong@oracle.com>
Tue, 27 Jan 2015 18:12:12 +0000 (13:12 -0500)
committerTheodore Ts'o <tytso@mit.edu>
Tue, 27 Jan 2015 18:12:31 +0000 (13:12 -0500)
If we decide to clear a special inode because of bad mappings, we need
to zero the i_block array.  The clearing routine depends on setting
i_links_count to zero to keep us from re-checking the block maps,
but that field isn't checked for special inodes.  Therefore, if we
haven't erased the mappings, check_blocks will restart fsck and fsck
will try to check the blocks again, leading to an infinite loop.

(This seems easy to trigger if the bootloader inode extent map is
corrupted.)

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
e2fsck/pass1.c

index 14877d7585db1ee03435e35b1d97656eea3d82ca..faafa7c9f4a1fd42f19989a4054f9aa6ddcc37af 100644 (file)
@@ -2285,6 +2285,16 @@ void e2fsck_clear_inode(e2fsck_t ctx, ext2_ino_t ino,
        ext2fs_icount_store(ctx->inode_link_info, ino, 0);
        inode->i_dtime = ctx->now;
 
+       /*
+        * If a special inode has such rotten block mappings that we
+        * want to clear the whole inode, be sure to actually zap
+        * the block maps because i_links_count isn't checked for
+        * special inodes, and we'll end up right back here the next
+        * time we run fsck.
+        */
+       if (ino < EXT2_FIRST_INODE(ctx->fs->super))
+               memset(inode->i_block, 0, sizeof(inode->i_block));
+
        ext2fs_unmark_inode_bitmap2(ctx->inode_dir_map, ino);
        ext2fs_unmark_inode_bitmap2(ctx->inode_used_map, ino);
        if (ctx->inode_reg_map)