From: Tao Ma Date: Sat, 8 Oct 2011 21:18:27 +0000 (-0400) Subject: ext4: avoid stamping on other memories in ext4_ext_insert_index() X-Git-Tag: next-20111011~83^2~3 X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=4fd30c0330ba951d579ee3f0c24eaf1fa0580719;p=karo-tx-linux.git ext4: avoid stamping on other memories in ext4_ext_insert_index() In ext4_ext_insert_index, we initialize 'ix' before checking its validity, so we have a chance to stamp on memories out of the block. Move the check before we do the work. Signed-off-by: Tao Ma Signed-off-by: "Theodore Ts'o" --- diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index f473ddf0bd94..2dff31efa33e 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c @@ -779,15 +779,15 @@ static int ext4_ext_insert_index(handle_t *handle, struct inode *inode, ix = curp->p_idx; } - ix->ei_block = cpu_to_le32(logical); - ext4_idx_store_pblock(ix, ptr); - le16_add_cpu(&curp->p_hdr->eh_entries, 1); - if (unlikely(ix > EXT_LAST_INDEX(curp->p_hdr))) { EXT4_ERROR_INODE(inode, "ix > EXT_LAST_INDEX!"); return -EIO; } + ix->ei_block = cpu_to_le32(logical); + ext4_idx_store_pblock(ix, ptr); + le16_add_cpu(&curp->p_hdr->eh_entries, 1); + err = ext4_ext_dirty(handle, inode, curp); ext4_std_error(inode->i_sb, err);