linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ext4: fix invalid inode checksum
@ 2020-10-20  1:36 Luo Meng
  2020-10-20  3:59 ` Darrick J. Wong
  2020-10-28  3:38 ` Theodore Y. Ts'o
  0 siblings, 2 replies; 3+ messages in thread
From: Luo Meng @ 2020-10-20  1:36 UTC (permalink / raw)
  To: tytso, adilger.kernel, linux-ext4, jack, luomeng12

During the stability test, there are some errors:
  ext4_lookup:1590: inode #6967: comm fsstress: iget: checksum invalid.

If the inode->i_iblocks too big and doesn't set huge file flag, checksum
will not be recalculated when update the inode information to it's buffer.
If other inode marks the buffer dirty, then the inconsistent inode will
be flushed to disk.

Fix this problem by checking i_blocks in advance.

Signed-off-by: Luo Meng <luomeng12@huawei.com>
---
 fs/ext4/inode.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index bf596467c234..fe53774b8b6c 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -4971,6 +4971,12 @@ static int ext4_do_update_inode(handle_t *handle,
 	if (ext4_test_inode_state(inode, EXT4_STATE_NEW))
 		memset(raw_inode, 0, EXT4_SB(inode->i_sb)->s_inode_size);
 
+	err = ext4_inode_blocks_set(handle, raw_inode, ei);
+	if (err) {
+		spin_unlock(&ei->i_raw_lock);
+		goto out_brelse;
+	}
+
 	raw_inode->i_mode = cpu_to_le16(inode->i_mode);
 	i_uid = i_uid_read(inode);
 	i_gid = i_gid_read(inode);
@@ -5004,11 +5010,6 @@ static int ext4_do_update_inode(handle_t *handle,
 	EXT4_INODE_SET_XTIME(i_atime, inode, raw_inode);
 	EXT4_EINODE_SET_XTIME(i_crtime, ei, raw_inode);
 
-	err = ext4_inode_blocks_set(handle, raw_inode, ei);
-	if (err) {
-		spin_unlock(&ei->i_raw_lock);
-		goto out_brelse;
-	}
 	raw_inode->i_dtime = cpu_to_le32(ei->i_dtime);
 	raw_inode->i_flags = cpu_to_le32(ei->i_flags & 0xFFFFFFFF);
 	if (likely(!test_opt2(inode->i_sb, HURD_COMPAT)))
-- 
2.25.4


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

* Re: [PATCH] ext4: fix invalid inode checksum
  2020-10-20  1:36 [PATCH] ext4: fix invalid inode checksum Luo Meng
@ 2020-10-20  3:59 ` Darrick J. Wong
  2020-10-28  3:38 ` Theodore Y. Ts'o
  1 sibling, 0 replies; 3+ messages in thread
From: Darrick J. Wong @ 2020-10-20  3:59 UTC (permalink / raw)
  To: Luo Meng; +Cc: tytso, adilger.kernel, linux-ext4, jack

On Tue, Oct 20, 2020 at 09:36:31AM +0800, Luo Meng wrote:
> During the stability test, there are some errors:
>   ext4_lookup:1590: inode #6967: comm fsstress: iget: checksum invalid.
> 
> If the inode->i_iblocks too big and doesn't set huge file flag, checksum
> will not be recalculated when update the inode information to it's buffer.
> If other inode marks the buffer dirty, then the inconsistent inode will
> be flushed to disk.
> 
> Fix this problem by checking i_blocks in advance.
> 
> Signed-off-by: Luo Meng <luomeng12@huawei.com>

Fun!  Yikes!
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>

--D

> ---
>  fs/ext4/inode.c | 11 ++++++-----
>  1 file changed, 6 insertions(+), 5 deletions(-)
> 
> diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
> index bf596467c234..fe53774b8b6c 100644
> --- a/fs/ext4/inode.c
> +++ b/fs/ext4/inode.c
> @@ -4971,6 +4971,12 @@ static int ext4_do_update_inode(handle_t *handle,
>  	if (ext4_test_inode_state(inode, EXT4_STATE_NEW))
>  		memset(raw_inode, 0, EXT4_SB(inode->i_sb)->s_inode_size);
>  
> +	err = ext4_inode_blocks_set(handle, raw_inode, ei);
> +	if (err) {
> +		spin_unlock(&ei->i_raw_lock);
> +		goto out_brelse;
> +	}
> +
>  	raw_inode->i_mode = cpu_to_le16(inode->i_mode);
>  	i_uid = i_uid_read(inode);
>  	i_gid = i_gid_read(inode);
> @@ -5004,11 +5010,6 @@ static int ext4_do_update_inode(handle_t *handle,
>  	EXT4_INODE_SET_XTIME(i_atime, inode, raw_inode);
>  	EXT4_EINODE_SET_XTIME(i_crtime, ei, raw_inode);
>  
> -	err = ext4_inode_blocks_set(handle, raw_inode, ei);
> -	if (err) {
> -		spin_unlock(&ei->i_raw_lock);
> -		goto out_brelse;
> -	}
>  	raw_inode->i_dtime = cpu_to_le32(ei->i_dtime);
>  	raw_inode->i_flags = cpu_to_le32(ei->i_flags & 0xFFFFFFFF);
>  	if (likely(!test_opt2(inode->i_sb, HURD_COMPAT)))
> -- 
> 2.25.4
> 

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

* Re: [PATCH] ext4: fix invalid inode checksum
  2020-10-20  1:36 [PATCH] ext4: fix invalid inode checksum Luo Meng
  2020-10-20  3:59 ` Darrick J. Wong
@ 2020-10-28  3:38 ` Theodore Y. Ts'o
  1 sibling, 0 replies; 3+ messages in thread
From: Theodore Y. Ts'o @ 2020-10-28  3:38 UTC (permalink / raw)
  To: Luo Meng; +Cc: adilger.kernel, linux-ext4, jack

On Tue, Oct 20, 2020 at 09:36:31AM +0800, Luo Meng wrote:
> During the stability test, there are some errors:
>   ext4_lookup:1590: inode #6967: comm fsstress: iget: checksum invalid.
> 
> If the inode->i_iblocks too big and doesn't set huge file flag, checksum
> will not be recalculated when update the inode information to it's buffer.
> If other inode marks the buffer dirty, then the inconsistent inode will
> be flushed to disk.
> 
> Fix this problem by checking i_blocks in advance.
> 
> Signed-off-by: Luo Meng <luomeng12@huawei.com>

Thanks, this has been applied.

					- Ted

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

end of thread, other threads:[~2020-10-28 21:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-10-20  1:36 [PATCH] ext4: fix invalid inode checksum Luo Meng
2020-10-20  3:59 ` Darrick J. Wong
2020-10-28  3:38 ` Theodore Y. Ts'o

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).