e2fsck: pass2 should not process directory blocks that are impossibly large

Currently, directories cannot be fallocated, which means that the only
way they get bigger is for the kernel to append blocks one by one.
Therefore, if we encounter a logical block offset that is too big, we
needn't bother adding it to the dblist for pass2 processing, because
it's unlikely to contain a valid directory block.  The code that
handles extent based directories also does not add toobig blocks to
the dblist.

Note that we can easily cause e2fsck to fail with ENOMEM if we start
feeding it really large logical block offsets, as the dblist
implementation will try to realloc() an array big enough to hold it.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
test-maint
Darrick J. Wong 2014-07-25 08:41:11 -04:00 committed by Theodore Ts'o
parent 0733835bf7
commit c28c2741ba
5 changed files with 29 additions and 0 deletions

View File

@ -2456,6 +2456,17 @@ static int process_block(ext2_filsys fs,
blk = *block_nr = 0;
ret_code = BLOCK_CHANGED;
p->inode_modified = 1;
/*
* If the directory block is too big and is beyond the
* end of the FS, don't bother trying to add it for
* processing -- the kernel would never have created a
* directory this large, and we risk an ENOMEM abort.
* In any case, the toobig handler for extent-based
* directories also doesn't feed toobig blocks to
* pass 2.
*/
if (problem == PR_1_TOOBIG_DIR)
return ret_code;
goto mark_dir;
} else
return 0;

View File

@ -0,0 +1,10 @@
Pass 1: Checking inodes, blocks, and sizes
Inode 12 is too big. Truncate? yes
Block #1074791435 (13) causes directory to be too big. CLEARED.
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
test_filesys: 12/128 files (8.3% non-contiguous), 22/512 blocks
Exit status is 0

View File

@ -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: 12/128 files (8.3% non-contiguous), 22/512 blocks
Exit status is 0

Binary file not shown.

View File

@ -0,0 +1 @@
crash e2fsck with a dir with an impossibly high logical blk offset