This is a note to let you know that I've just added the patch titled ext4: check for out-of-order index extents in ext4_valid_extent_entries() to the 5.15-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: ext4-check-for-out-of-order-index-extents-in-ext4_valid_extent_entries.patch and it can be found in the queue-5.15 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@xxxxxxxxxxxxxxx> know about it. >From 8dd27fecede55e8a4e67eef2878040ecad0f0d33 Mon Sep 17 00:00:00 2001 From: Zhang Yi <yi.zhang@xxxxxxxxxx> Date: Wed, 8 Sep 2021 20:08:48 +0800 Subject: ext4: check for out-of-order index extents in ext4_valid_extent_entries() From: Zhang Yi <yi.zhang@xxxxxxxxxx> commit 8dd27fecede55e8a4e67eef2878040ecad0f0d33 upstream. After commit 5946d089379a ("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@xxxxxxxxxx> Reviewed-by: Theodore Ts'o <tytso@xxxxxxx> Link: https://lore.kernel.org/r/20210908120850.4012324-2-yi.zhang@xxxxxxxxxx Signed-off-by: Theodore Ts'o <tytso@xxxxxxx> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- fs/ext4/extents.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c @@ -370,6 +370,9 @@ static int ext4_valid_extent_entries(str ext4_fsblk_t *pblk, int depth) { unsigned short entries; + ext4_lblk_t lblock = 0; + ext4_lblk_t prev = 0; + if (eh->eh_entries == 0) return 1; @@ -378,31 +381,35 @@ static int ext4_valid_extent_entries(str if (depth == 0) { /* leaf entries */ struct ext4_extent *ext = EXT_FIRST_EXTENT(eh); - ext4_lblk_t lblock = 0; - ext4_lblk_t prev = 0; - int len = 0; while (entries) { if (!ext4_valid_extent(inode, ext)) return 0; /* Check for overlapping extents */ lblock = le32_to_cpu(ext->ee_block); - len = ext4_ext_get_actual_len(ext); if ((lblock <= prev) && prev) { *pblk = ext4_ext_pblock(ext); return 0; } + prev = lblock + ext4_ext_get_actual_len(ext) - 1; ext++; entries--; - prev = lblock + len - 1; } } else { struct ext4_extent_idx *ext_idx = EXT_FIRST_INDEX(eh); while (entries) { if (!ext4_valid_extent_idx(inode, ext_idx)) return 0; + + /* Check for overlapping index extents */ + lblock = le32_to_cpu(ext_idx->ei_block); + if ((lblock <= prev) && prev) { + *pblk = ext4_idx_pblock(ext_idx); + return 0; + } ext_idx++; entries--; + prev = lblock; } } return 1; Patches currently in stable-queue which might be from yi.zhang@xxxxxxxxxx are queue-5.15/ext4-check-for-out-of-order-index-extents-in-ext4_valid_extent_entries.patch queue-5.15/ext4-check-for-inconsistent-extents-between-index-and-leaf-block.patch queue-5.15/ext4-prevent-partial-update-of-the-extent-blocks.patch