add patch check-for-extents-that-wrap-around
[ext4-patch-queue.git] / check-for-extents-that-wrap-around
blobeeef93fb5da79225b17178fed52964b56f38722e
1 ext4: check for extents that wrap around
3 From: Vegard Nossum <vegard.nossum@oracle.com>
5 An extent with lblock = 4294967295 and len = 1 will pass the
6 ext4_valid_extent() test:
8         ext4_lblk_t last = lblock + len - 1;
10         if (len == 0 || lblock > last)
11                 return 0;
13 since last = 4294967295 + 1 - 1 = 4294967295. This would later trigger
14 the BUG_ON(es->es_lblk + es->es_len < es->es_lblk) in ext4_es_end().
16 We can simplify it by removing the - 1 altogether and changing the test
17 to use lblock + len <= lblock, since now if len = 0, then lblock + 0 ==
18 lblock and it fails, and if len > 0 then lblock + len > lblock in order
19 to pass (i.e. it doesn't overflow).
21 Fixes: 5946d0893 ("ext4: check for overlapping extents in ext4_valid_extent_entries()")
22 Fixes: 2f974865f ("ext4: check for zero length extent explicitly")
23 Cc: Eryu Guan <guaneryu@gmail.com>
24 Cc: stable@vger.kernel.org
25 Signed-off-by: Phil Turnbull <phil.turnbull@oracle.com>
26 Signed-off-by: Vegard Nossum <vegard.nossum@oracle.com>
27 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
28 ---
29  fs/ext4/extents.c | 8 ++++++--
30  1 file changed, 6 insertions(+), 2 deletions(-)
32 diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
33 index 2a2eef9..2f258c6 100644
34 --- a/fs/ext4/extents.c
35 +++ b/fs/ext4/extents.c
36 @@ -381,9 +381,13 @@ static int ext4_valid_extent(struct inode *inode, struct ext4_extent *ext)
37         ext4_fsblk_t block = ext4_ext_pblock(ext);
38         int len = ext4_ext_get_actual_len(ext);
39         ext4_lblk_t lblock = le32_to_cpu(ext->ee_block);
40 -       ext4_lblk_t last = lblock + len - 1;
42 -       if (len == 0 || lblock > last)
43 +       /*
44 +        * We allow neither:
45 +        *  - zero length
46 +        *  - overflow/wrap-around
47 +        */
48 +       if (lblock + len <= lblock)
49                 return 0;
50         return ext4_data_block_valid(EXT4_SB(inode->i_sb), block, len);
51  }
52 -- 
53 1.9.1