]> git.baikalelectronics.ru Git - kernel.git/commit
ext4: fix crash when a directory's i_size is too small
authorChandan Rajendra <chandan@linux.vnet.ibm.com>
Mon, 11 Dec 2017 20:00:57 +0000 (15:00 -0500)
committerTheodore Ts'o <tytso@mit.edu>
Mon, 11 Dec 2017 20:00:57 +0000 (15:00 -0500)
commit3b4a7f513d3ea27e51a2c1db2bde6d21a0f3a7cd
treefa959ddb7e55d7e89fe173eb4b58bf6fd090daa6
parent3b8e0d867aaae064db5e333643d92e058b1e4af5
ext4: fix crash when a directory's i_size is too small

On a ppc64 machine, when mounting a fuzzed ext2 image (generated by
fsfuzzer) the following call trace is seen,

VFS: brelse: Trying to free free buffer
WARNING: CPU: 1 PID: 6913 at /root/repos/linux/fs/buffer.c:1165 .__brelse.part.6+0x24/0x40
.__brelse.part.6+0x20/0x40 (unreliable)
.ext4_find_entry+0x384/0x4f0
.ext4_lookup+0x84/0x250
.lookup_slow+0xdc/0x230
.walk_component+0x268/0x400
.path_lookupat+0xec/0x2d0
.filename_lookup+0x9c/0x1d0
.vfs_statx+0x98/0x140
.SyS_newfstatat+0x48/0x80
system_call+0x58/0x6c

This happens because the directory that ext4_find_entry() looks up has
inode->i_size that is less than the block size of the filesystem. This
causes 'nblocks' to have a value of zero. ext4_bread_batch() ends up not
reading any of the directory file's blocks. This renders the entries in
bh_use[] array to continue to have garbage data. buffer_uptodate() on
bh_use[0] can then return a zero value upon which brelse() function is
invoked.

This commit fixes the bug by returning -ENOENT when the directory file
has no associated blocks.

Reported-by: Abdul Haleem <abdhalee@linux.vnet.ibm.com>
Signed-off-by: Chandan Rajendra <chandan@linux.vnet.ibm.com>
Cc: stable@vger.kernel.org
fs/ext4/namei.c