Skip to content

Commit 8dd27fe

Browse files
zhangyi089tytso
authored andcommitted
ext4: check for out-of-order index extents in ext4_valid_extent_entries()
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 <[email protected]> Reviewed-by: Theodore Ts'o <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Theodore Ts'o <[email protected]>
1 parent 31d21d2 commit 8dd27fe

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

fs/ext4/extents.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,9 @@ static int ext4_valid_extent_entries(struct inode *inode,
357357
ext4_fsblk_t *pblk, int depth)
358358
{
359359
unsigned short entries;
360+
ext4_lblk_t lblock = 0;
361+
ext4_lblk_t prev = 0;
362+
360363
if (eh->eh_entries == 0)
361364
return 1;
362365

@@ -365,31 +368,35 @@ static int ext4_valid_extent_entries(struct inode *inode,
365368
if (depth == 0) {
366369
/* leaf entries */
367370
struct ext4_extent *ext = EXT_FIRST_EXTENT(eh);
368-
ext4_lblk_t lblock = 0;
369-
ext4_lblk_t prev = 0;
370-
int len = 0;
371371
while (entries) {
372372
if (!ext4_valid_extent(inode, ext))
373373
return 0;
374374

375375
/* Check for overlapping extents */
376376
lblock = le32_to_cpu(ext->ee_block);
377-
len = ext4_ext_get_actual_len(ext);
378377
if ((lblock <= prev) && prev) {
379378
*pblk = ext4_ext_pblock(ext);
380379
return 0;
381380
}
381+
prev = lblock + ext4_ext_get_actual_len(ext) - 1;
382382
ext++;
383383
entries--;
384-
prev = lblock + len - 1;
385384
}
386385
} else {
387386
struct ext4_extent_idx *ext_idx = EXT_FIRST_INDEX(eh);
388387
while (entries) {
389388
if (!ext4_valid_extent_idx(inode, ext_idx))
390389
return 0;
390+
391+
/* Check for overlapping index extents */
392+
lblock = le32_to_cpu(ext_idx->ei_block);
393+
if ((lblock <= prev) && prev) {
394+
*pblk = ext4_idx_pblock(ext_idx);
395+
return 0;
396+
}
391397
ext_idx++;
392398
entries--;
399+
prev = lblock;
393400
}
394401
}
395402
return 1;

0 commit comments

Comments
 (0)