diff options
author | Vegard Nossum <vegard.nossum@oracle.com> | 2016-06-30 11:53:46 -0400 |
---|---|---|
committer | Willy Tarreau <w@1wt.eu> | 2016-08-21 23:22:49 +0200 |
commit | 6dc68acbb65e2336d6f8b35c2f0c9a4219d3adf2 (patch) | |
tree | 14b4fd64ba9ef0b0b5e6336cf1eec22103f4c063 | |
parent | ea8f8498b39a4e9ef9c55f5b3eb25efea85a6ffb (diff) | |
download | lwn-6dc68acbb65e2336d6f8b35c2f0c9a4219d3adf2.tar.gz lwn-6dc68acbb65e2336d6f8b35c2f0c9a4219d3adf2.zip |
ext4: check for extents that wrap around
commit f70749ca42943faa4d4dcce46dfdcaadb1d0c4b6 upstream.
An extent with lblock = 4294967295 and len = 1 will pass the
ext4_valid_extent() test:
ext4_lblk_t last = lblock + len - 1;
if (len == 0 || lblock > last)
return 0;
since last = 4294967295 + 1 - 1 = 4294967295. This would later trigger
the BUG_ON(es->es_lblk + es->es_len < es->es_lblk) in ext4_es_end().
We can simplify it by removing the - 1 altogether and changing the test
to use lblock + len <= lblock, since now if len = 0, then lblock + 0 ==
lblock and it fails, and if len > 0 then lblock + len > lblock in order
to pass (i.e. it doesn't overflow).
Fixes: 5946d0893 ("ext4: check for overlapping extents in ext4_valid_extent_entries()")
Fixes: 2f974865f ("ext4: check for zero length extent explicitly")
Cc: Eryu Guan <guaneryu@gmail.com>
Cc: stable@vger.kernel.org
Signed-off-by: Phil Turnbull <phil.turnbull@oracle.com>
Signed-off-by: Vegard Nossum <vegard.nossum@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Signed-off-by: Willy Tarreau <w@1wt.eu>
-rw-r--r-- | fs/ext4/extents.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index f9fe3593d926..7eea76168d33 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c @@ -361,9 +361,13 @@ static int ext4_valid_extent(struct inode *inode, struct ext4_extent *ext) ext4_fsblk_t block = ext4_ext_pblock(ext); int len = ext4_ext_get_actual_len(ext); ext4_lblk_t lblock = le32_to_cpu(ext->ee_block); - ext4_lblk_t last = lblock + len - 1; - if (len == 0 || lblock > last) + /* + * We allow neither: + * - zero length + * - overflow/wrap-around + */ + if (lblock + len <= lblock) return 0; return ext4_data_block_valid(EXT4_SB(inode->i_sb), block, len); } |