]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
e2fsck: on read error, don't rewrite blocks past the end of the fs
authorDarrick J. Wong <darrick.wong@oracle.com>
Tue, 27 Jan 2015 17:32:25 +0000 (12:32 -0500)
committerTheodore Ts'o <tytso@mit.edu>
Tue, 27 Jan 2015 18:12:37 +0000 (13:12 -0500)
If e2fsck encounters a read error on a block past the end of the
filesystem, don't bother trying to "rewrite" the block.  We might
still want to re-try the read to capture FS data marooned past the end
of the filesystem, but in that case e2fsck ought to move the block
back inside the filesystem.

This enables e2fuzz to detect writes past the end of the FS due to
software bugs.

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

index 6dddf9c17dc90f8e29b5b50c5cd338550186103d..71ca301ca5fe8777d51ce1e2bbcc58484e05bdbd 100644 (file)
@@ -58,6 +58,11 @@ static errcode_t e2fsck_handle_read_error(io_channel channel,
                printf(_("Error reading block %lu (%s).  "), block,
                       error_message(error));
        preenhalt(ctx);
+
+       /* Don't rewrite a block past the end of the FS. */
+       if (block >= ext2fs_blocks_count(fs->super))
+               return 0;
+
        if (ask(ctx, _("Ignore error"), 1)) {
                if (ask(ctx, _("Force rewrite"), 1))
                        io_channel_write_blk64(channel, block, count, data);
index 4cb7b61f534fafc67df2bc068c0b5acdbe62d462..d8d9a82a8dd590df233e2d3c09cf3e1635def7b0 100755 (executable)
@@ -219,6 +219,7 @@ seq 1 "${PASSES}" | while read pass; do
        fi
        if [ "${RUN_FSCK}" -gt 0 ]; then
                cp "${PASS_IMG}" "${FSCK_IMG}"
+               pass_img_sz="$(stat -c '%s' "${PASS_IMG}")"
 
                seq 1 "${MAX_FSCK}" | while read fsck_pass; do
                        echo "++ fsck pass ${fsck_pass}: $(which e2fsck) -fy ${FSCK_IMG} ${EXTENDED_FSCK_OPTS}"
@@ -250,6 +251,12 @@ seq 1 "${PASSES}" | while read pass; do
                                        exit 2
                                fi
                        fi
+
+                       fsck_img_sz="$(stat -c '%s' "${FSCK_IMG}")"
+                       if [ "${fsck_img_sz}" -ne "${pass_img_sz}" ]; then
+                               echo "++ fsck image size changed"
+                               exit 3
+                       fi
                done
                fsck_loop_ret=$?
                if [ "${fsck_loop_ret}" -gt 0 ]; then