add patch check-for-zero-length-extent-explicitly
[ext4-patch-queue.git] / check-for-zero-length-extent-explicitly
blob75536bd96a2fcb708d6f32caabdb892c059ddea3
1 ext4: check for zero length extent explicitly
3 From: Eryu Guan <guaneryu@gmail.com>
5 The following commit introduced a bug when checking for zero length extent
7 5946d08 ext4: check for overlapping extents in ext4_valid_extent_entries()
9 Zero length extent could pass the check if lblock is zero.
11 Adding the explicit check for zero length back.
13 Signed-off-by: Eryu Guan <guaneryu@gmail.com>
14 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
15 Cc: stable@vger.kernel.org
16 ---
18 This is uncovered by recent updates for encryption, catting a file with zero
19 length extent results in infinite loop ext4_mpage_readpages(), and process
20 cannot be killed either.
22 Tested with corrupted ext4 image in e2fsprogs sources, cat returned EIO
23 correctly
25 tests/f_ext_zero_len/image.gz
27  fs/ext4/extents.c | 2 +-
28  1 file changed, 1 insertion(+), 1 deletion(-)
30 diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
31 index d74e0802..451b92a 100644
32 --- a/fs/ext4/extents.c
33 +++ b/fs/ext4/extents.c
34 @@ -377,7 +377,7 @@ static int ext4_valid_extent(struct inode *inode, struct ext4_extent *ext)
35         ext4_lblk_t lblock = le32_to_cpu(ext->ee_block);
36         ext4_lblk_t last = lblock + len - 1;
38 -       if (lblock > last)
39 +       if (len == 0 || lblock > last)
40                 return 0;
41         return ext4_data_block_valid(EXT4_SB(inode->i_sb), block, len);
42  }
43 -- 
44 1.8.3.1