Skip to content

Commit af90a8f

Browse files
gouhao2025tytso
authored andcommitted
ext4: move 'ix' sanity check to corrent position
Check 'ix' before it is used. Fixes: 80e675f ("ext4: optimize memmmove lengths in extent/index insertions") Signed-off-by: Gou Hao <gouhao@uniontech.com> Link: https://lore.kernel.org/r/20230906013341.7199-1-gouhao@uniontech.com Signed-off-by: Theodore Ts'o <tytso@mit.edu>
1 parent 8b6b562 commit af90a8f

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

fs/ext4/extents.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,6 +1010,11 @@ static int ext4_ext_insert_index(handle_t *handle, struct inode *inode,
10101010
ix = curp->p_idx;
10111011
}
10121012

1013+
if (unlikely(ix > EXT_MAX_INDEX(curp->p_hdr))) {
1014+
EXT4_ERROR_INODE(inode, "ix > EXT_MAX_INDEX!");
1015+
return -EFSCORRUPTED;
1016+
}
1017+
10131018
len = EXT_LAST_INDEX(curp->p_hdr) - ix + 1;
10141019
BUG_ON(len < 0);
10151020
if (len > 0) {
@@ -1019,11 +1024,6 @@ static int ext4_ext_insert_index(handle_t *handle, struct inode *inode,
10191024
memmove(ix + 1, ix, len * sizeof(struct ext4_extent_idx));
10201025
}
10211026

1022-
if (unlikely(ix > EXT_MAX_INDEX(curp->p_hdr))) {
1023-
EXT4_ERROR_INODE(inode, "ix > EXT_MAX_INDEX!");
1024-
return -EFSCORRUPTED;
1025-
}
1026-
10271027
ix->ei_block = cpu_to_le32(logical);
10281028
ext4_idx_store_pblock(ix, ptr);
10291029
le16_add_cpu(&curp->p_hdr->eh_entries, 1);

0 commit comments

Comments
 (0)