mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-09-22 10:31:08 +00:00
ext4: move 'ix' sanity check to corrent position
[ Upstream commitaf90a8f4a0
] Check 'ix' before it is used. Fixes:80e675f906
("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> Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
parent
242ba2e20b
commit
4f13eab0e8
1 changed files with 5 additions and 5 deletions
|
@ -1010,6 +1010,11 @@ static int ext4_ext_insert_index(handle_t *handle, struct inode *inode,
|
||||||
ix = curp->p_idx;
|
ix = curp->p_idx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (unlikely(ix > EXT_MAX_INDEX(curp->p_hdr))) {
|
||||||
|
EXT4_ERROR_INODE(inode, "ix > EXT_MAX_INDEX!");
|
||||||
|
return -EFSCORRUPTED;
|
||||||
|
}
|
||||||
|
|
||||||
len = EXT_LAST_INDEX(curp->p_hdr) - ix + 1;
|
len = EXT_LAST_INDEX(curp->p_hdr) - ix + 1;
|
||||||
BUG_ON(len < 0);
|
BUG_ON(len < 0);
|
||||||
if (len > 0) {
|
if (len > 0) {
|
||||||
|
@ -1019,11 +1024,6 @@ static int ext4_ext_insert_index(handle_t *handle, struct inode *inode,
|
||||||
memmove(ix + 1, ix, len * sizeof(struct ext4_extent_idx));
|
memmove(ix + 1, ix, len * sizeof(struct ext4_extent_idx));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (unlikely(ix > EXT_MAX_INDEX(curp->p_hdr))) {
|
|
||||||
EXT4_ERROR_INODE(inode, "ix > EXT_MAX_INDEX!");
|
|
||||||
return -EFSCORRUPTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
ix->ei_block = cpu_to_le32(logical);
|
ix->ei_block = cpu_to_le32(logical);
|
||||||
ext4_idx_store_pblock(ix, ptr);
|
ext4_idx_store_pblock(ix, ptr);
|
||||||
le16_add_cpu(&curp->p_hdr->eh_entries, 1);
|
le16_add_cpu(&curp->p_hdr->eh_entries, 1);
|
||||||
|
|
Loading…
Reference in a new issue