public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ext4: move 'ix' sanity check to corrent position
@ 2023-09-06  1:33 gouhao
  2023-10-06 18:06 ` Theodore Ts'o
  0 siblings, 1 reply; 2+ messages in thread
From: gouhao @ 2023-09-06  1:33 UTC (permalink / raw)
  To: tytso, adilger.kernel, linux-ext4; +Cc: egouriou, linux-kernel

From: Gou Hao <gouhao@uniontech.com>

'ix' check should be before using it.

Fixes: 80e675f906db ("ext4: optimize memmmove lengths in extent/index insertions")
Signed-off-by: Gou Hao <gouhao@uniontech.com>
---
 fs/ext4/extents.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
index 202c76996b62..4d8496d1a8ac 100644
--- a/fs/ext4/extents.c
+++ b/fs/ext4/extents.c
@@ -1010,6 +1010,11 @@ static int ext4_ext_insert_index(handle_t *handle, struct inode *inode,
 		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;
 	BUG_ON(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));
 	}
 
-	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);
 	ext4_idx_store_pblock(ix, ptr);
 	le16_add_cpu(&curp->p_hdr->eh_entries, 1);
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] ext4: move 'ix' sanity check to corrent position
  2023-09-06  1:33 [PATCH] ext4: move 'ix' sanity check to corrent position gouhao
@ 2023-10-06 18:06 ` Theodore Ts'o
  0 siblings, 0 replies; 2+ messages in thread
From: Theodore Ts'o @ 2023-10-06 18:06 UTC (permalink / raw)
  To: adilger.kernel, linux-ext4, gouhao
  Cc: Theodore Ts'o, egouriou, linux-kernel


On Wed, 06 Sep 2023 09:33:41 +0800, gouhao@uniontech.com wrote:
> 'ix' check should be before using it.
> 
> 

Applied, thanks!

[1/1] ext4: move 'ix' sanity check to corrent position
      commit: af90a8f4a09ec4a3de20142e37f37205d4687f28

Best regards,
-- 
Theodore Ts'o <tytso@mit.edu>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-10-06 18:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-06  1:33 [PATCH] ext4: move 'ix' sanity check to corrent position gouhao
2023-10-06 18:06 ` Theodore Ts'o

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox