aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTheodore Ts'o <tytso@mit.edu>2013-07-28 21:49:38 -0400
committerTheodore Ts'o <tytso@mit.edu>2013-07-28 22:03:01 -0400
commitc8ec2bad18fdaa842f786f3b37c9320a3411aea3 (patch)
tree4c13783b8bfb32e94da5a419361e07a3d4f76997
parentdd50ef87432284d93b9f39178c4fab242d76654e (diff)
downloade2fsprogs-c8ec2bad18fdaa842f786f3b37c9320a3411aea3.tar.gz
e2fsprogs-c8ec2bad18fdaa842f786f3b37c9320a3411aea3.tar.xz
e2fsprogs-c8ec2bad18fdaa842f786f3b37c9320a3411aea3.zip
e2fsck: correctly deallocate invalid extent-mapped symlinks
The function deallocate_inode() in e2fsck/pass2.c was buggy in that it would clear out the inode's mode and flags fields before trying to deallocate any blocks which might belong to the inode. The good news is that deallocate_inode() is mostly used to free inodes which do not have blocks: device inodes, FIFO's, Unix-domain sockets. The bad news is that if deallocate_inode() tried to free an invalid extent-mapped inode, it would try to interpret the root of the extent node as block numbers, and would therefore mark various file system metadata blocks (the superblock, block group descriptors, the root directory, etc.) as free and available for allocation. This was unfortunate. (Try running an older e2fsck against the test file system image in the new test f_invalid_extent_symlink, and then run e2fsck a second time on the fs image, and weep.) Fortunately, this kind of file system image corruption appears to be fairly rare in actual practice, since it would require a very unlucky set of bits to be flipped, or a buggy file system implementation. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
-rw-r--r--e2fsck/pass2.c7
-rw-r--r--tests/f_invalid_extent_symlink/expect.112
-rw-r--r--tests/f_invalid_extent_symlink/expect.27
-rw-r--r--tests/f_invalid_extent_symlink/image.gzbin0 -> 1115 bytes
-rw-r--r--tests/f_invalid_extent_symlink/name1
5 files changed, 25 insertions, 2 deletions
diff --git a/e2fsck/pass2.c b/e2fsck/pass2.c
index 749d264b..bceadfe6 100644
--- a/e2fsck/pass2.c
+++ b/e2fsck/pass2.c
@@ -1189,7 +1189,6 @@ static void deallocate_inode(e2fsck_t ctx, ext2_ino_t ino, char* block_buf)
struct del_block del_block;
e2fsck_read_inode(ctx, ino, &inode, "deallocate_inode");
- e2fsck_clear_inode(ctx, ino, &inode, 0, "deallocate_inode");
clear_problem_context(&pctx);
pctx.ino = ino;
@@ -1224,7 +1223,7 @@ static void deallocate_inode(e2fsck_t ctx, ext2_ino_t ino, char* block_buf)
}
if (!ext2fs_inode_has_valid_blocks2(fs, &inode))
- return;
+ goto clear_inode;
if (LINUX_S_ISREG(inode.i_mode) && EXT2_I_SIZE(&inode) >= 0x80000000UL)
ctx->large_files--;
@@ -1239,6 +1238,10 @@ static void deallocate_inode(e2fsck_t ctx, ext2_ino_t ino, char* block_buf)
ctx->flags |= E2F_FLAG_ABORT;
return;
}
+clear_inode:
+ /* Inode may have changed by block_iterate, so reread it */
+ e2fsck_read_inode(ctx, ino, &inode, "deallocate_inode");
+ e2fsck_clear_inode(ctx, ino, &inode, 0, "deallocate_inode");
}
/*
diff --git a/tests/f_invalid_extent_symlink/expect.1 b/tests/f_invalid_extent_symlink/expect.1
new file mode 100644
index 00000000..7bda0b73
--- /dev/null
+++ b/tests/f_invalid_extent_symlink/expect.1
@@ -0,0 +1,12 @@
+Pass 1: Checking inodes, blocks, and sizes
+Pass 2: Checking directory structure
+Symlink /a (inode #12) is invalid.
+Clear? yes
+
+Pass 3: Checking directory connectivity
+Pass 4: Checking reference counts
+Pass 5: Checking group summary information
+
+test_filesys: ***** FILE SYSTEM WAS MODIFIED *****
+test_filesys: 11/16 files (9.1% non-contiguous), 21/100 blocks
+Exit status is 1
diff --git a/tests/f_invalid_extent_symlink/expect.2 b/tests/f_invalid_extent_symlink/expect.2
new file mode 100644
index 00000000..41ceefb4
--- /dev/null
+++ b/tests/f_invalid_extent_symlink/expect.2
@@ -0,0 +1,7 @@
+Pass 1: Checking inodes, blocks, and sizes
+Pass 2: Checking directory structure
+Pass 3: Checking directory connectivity
+Pass 4: Checking reference counts
+Pass 5: Checking group summary information
+test_filesys: 11/16 files (0.0% non-contiguous), 21/100 blocks
+Exit status is 0
diff --git a/tests/f_invalid_extent_symlink/image.gz b/tests/f_invalid_extent_symlink/image.gz
new file mode 100644
index 00000000..d4a6eef7
--- /dev/null
+++ b/tests/f_invalid_extent_symlink/image.gz
Binary files differ
diff --git a/tests/f_invalid_extent_symlink/name b/tests/f_invalid_extent_symlink/name
new file mode 100644
index 00000000..3792aac7
--- /dev/null
+++ b/tests/f_invalid_extent_symlink/name
@@ -0,0 +1 @@
+extent-mapped symlink with two blocks