Skip to content

Commit 76366c0

Browse files
zhangyi089gregkh
authored andcommitted
ext4: check for out-of-order index extents in ext4_valid_extent_entries()
commit 8dd27fe upstream. After commit 5946d08 ("ext4: check for overlapping extents in ext4_valid_extent_entries()"), we can check out the overlapping extent entry in leaf extent blocks. But the out-of-order extent entry in index extent blocks could also trigger bad things if the filesystem is inconsistent. So this patch add a check to figure out the out-of-order index extents and return error. Signed-off-by: Zhang Yi <yi.zhang@huawei.com> Reviewed-by: Theodore Ts'o <tytso@mit.edu> Link: https://lore.kernel.org/r/20210908120850.4012324-2-yi.zhang@huawei.com Signed-off-by: Theodore Ts'o <tytso@mit.edu> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 1d4b1c4 commit 76366c0

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

‎fs/ext4/extents.c‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,9 @@ static int ext4_valid_extent_entries(struct inode *inode,
369369
ext4_fsblk_t *pblk, int depth)
370370
{
371371
unsigned short entries;
372+
ext4_lblk_t lblock = 0;
373+
ext4_lblk_t prev = 0;
374+
372375
if (eh->eh_entries == 0)
373376
return 1;
374377

@@ -377,31 +380,35 @@ static int ext4_valid_extent_entries(struct inode *inode,
377380
if (depth == 0) {
378381
/* leaf entries */
379382
struct ext4_extent *ext = EXT_FIRST_EXTENT(eh);
380-
ext4_lblk_t lblock = 0;
381-
ext4_lblk_t prev = 0;
382-
int len = 0;
383383
while (entries) {
384384
if (!ext4_valid_extent(inode, ext))
385385
return 0;
386386

387387
/* Check for overlapping extents */
388388
lblock = le32_to_cpu(ext->ee_block);
389-
len = ext4_ext_get_actual_len(ext);
390389
if ((lblock <= prev) && prev) {
391390
*pblk = ext4_ext_pblock(ext);
392391
return 0;
393392
}
393+
prev = lblock + ext4_ext_get_actual_len(ext) - 1;
394394
ext++;
395395
entries--;
396-
prev = lblock + len - 1;
397396
}
398397
} else {
399398
struct ext4_extent_idx *ext_idx = EXT_FIRST_INDEX(eh);
400399
while (entries) {
401400
if (!ext4_valid_extent_idx(inode, ext_idx))
402401
return 0;
402+
403+
/* Check for overlapping index extents */
404+
lblock = le32_to_cpu(ext_idx->ei_block);
405+
if ((lblock <= prev) && prev) {
406+
*pblk = ext4_idx_pblock(ext_idx);
407+
return 0;
408+
}
403409
ext_idx++;
404410
entries--;
411+
prev = lblock;
405412
}
406413
}
407414
return 1;

0 commit comments

Comments
 (0)