linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ext4: Do not zeroout extents beyond i_disksize
@ 2020-03-31 10:50 Jan Kara
  2020-03-31 13:34 ` Lukas Czerner
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Jan Kara @ 2020-03-31 10:50 UTC (permalink / raw)
  To: Ted Tso; +Cc: linux-ext4, Dmitry Monakhov, Jan Kara, stable

We do not want to create initialized extents beyond end of file because
for e2fsck it is impossible to distinguish them from a case of corrupted
file size / extent tree and so it complains like:

Inode 12, i_size is 147456, should be 163840.  Fix? no

Code in ext4_ext_convert_to_initialized() and
ext4_split_convert_extents() try to make sure it does not create
initialized extents beyond inode size however they check against
inode->i_size which is wrong. They should instead check against
EXT4_I(inode)->i_disksize which is the current inode size on disk.
That's what e2fsck is going to see in case of crash before all dirty
data is written. This bug manifests as generic/456 test failure (with
recent enough fstests where fsx got fixed to properly pass
FALLOC_KEEP_SIZE_FL flags to the kernel) when run with dioread_lock
mount option.

CC: stable@vger.kernel.org
Fixes: 21ca087a3891 ("ext4: Do not zero out uninitialized extents beyond i_size")
Signed-off-by: Jan Kara <jack@suse.cz>
---
 fs/ext4/extents.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
index 954013d6076b..c5e190fd4589 100644
--- a/fs/ext4/extents.c
+++ b/fs/ext4/extents.c
@@ -3532,8 +3532,8 @@ static int ext4_ext_convert_to_initialized(handle_t *handle,
 		(unsigned long long)map->m_lblk, map_len);
 
 	sbi = EXT4_SB(inode->i_sb);
-	eof_block = (inode->i_size + inode->i_sb->s_blocksize - 1) >>
-		inode->i_sb->s_blocksize_bits;
+	eof_block = (EXT4_I(inode)->i_disksize + inode->i_sb->s_blocksize - 1)
+			>> inode->i_sb->s_blocksize_bits;
 	if (eof_block < map->m_lblk + map_len)
 		eof_block = map->m_lblk + map_len;
 
@@ -3785,8 +3785,8 @@ static int ext4_split_convert_extents(handle_t *handle,
 		  __func__, inode->i_ino,
 		  (unsigned long long)map->m_lblk, map->m_len);
 
-	eof_block = (inode->i_size + inode->i_sb->s_blocksize - 1) >>
-		inode->i_sb->s_blocksize_bits;
+	eof_block = (EXT4_I(inode)->i_disksize + inode->i_sb->s_blocksize - 1)
+			>> inode->i_sb->s_blocksize_bits;
 	if (eof_block < map->m_lblk + map->m_len)
 		eof_block = map->m_lblk + map->m_len;
 	/*
-- 
2.16.4


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

* Re: [PATCH] ext4: Do not zeroout extents beyond i_disksize
  2020-03-31 10:50 [PATCH] ext4: Do not zeroout extents beyond i_disksize Jan Kara
@ 2020-03-31 13:34 ` Lukas Czerner
  2020-04-10 15:12 ` Jan Kara
  2020-04-14  1:30 ` Theodore Y. Ts'o
  2 siblings, 0 replies; 4+ messages in thread
From: Lukas Czerner @ 2020-03-31 13:34 UTC (permalink / raw)
  To: Jan Kara; +Cc: Ted Tso, linux-ext4, Dmitry Monakhov, stable

On Tue, Mar 31, 2020 at 12:50:16PM +0200, Jan Kara wrote:
> We do not want to create initialized extents beyond end of file because
> for e2fsck it is impossible to distinguish them from a case of corrupted
> file size / extent tree and so it complains like:
> 
> Inode 12, i_size is 147456, should be 163840.  Fix? no
> 
> Code in ext4_ext_convert_to_initialized() and
> ext4_split_convert_extents() try to make sure it does not create
> initialized extents beyond inode size however they check against
> inode->i_size which is wrong. They should instead check against
> EXT4_I(inode)->i_disksize which is the current inode size on disk.
> That's what e2fsck is going to see in case of crash before all dirty
> data is written. This bug manifests as generic/456 test failure (with
> recent enough fstests where fsx got fixed to properly pass
> FALLOC_KEEP_SIZE_FL flags to the kernel) when run with dioread_lock
> mount option.

Makes sense, thanks.

Reviewed-by: Lukas Czerner <lczerner@redhat.com>

-Lukas

> 
> CC: stable@vger.kernel.org
> Fixes: 21ca087a3891 ("ext4: Do not zero out uninitialized extents beyond i_size")
> Signed-off-by: Jan Kara <jack@suse.cz>
> ---
>  fs/ext4/extents.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
> index 954013d6076b..c5e190fd4589 100644
> --- a/fs/ext4/extents.c
> +++ b/fs/ext4/extents.c
> @@ -3532,8 +3532,8 @@ static int ext4_ext_convert_to_initialized(handle_t *handle,
>  		(unsigned long long)map->m_lblk, map_len);
>  
>  	sbi = EXT4_SB(inode->i_sb);
> -	eof_block = (inode->i_size + inode->i_sb->s_blocksize - 1) >>
> -		inode->i_sb->s_blocksize_bits;
> +	eof_block = (EXT4_I(inode)->i_disksize + inode->i_sb->s_blocksize - 1)
> +			>> inode->i_sb->s_blocksize_bits;
>  	if (eof_block < map->m_lblk + map_len)
>  		eof_block = map->m_lblk + map_len;
>  
> @@ -3785,8 +3785,8 @@ static int ext4_split_convert_extents(handle_t *handle,
>  		  __func__, inode->i_ino,
>  		  (unsigned long long)map->m_lblk, map->m_len);
>  
> -	eof_block = (inode->i_size + inode->i_sb->s_blocksize - 1) >>
> -		inode->i_sb->s_blocksize_bits;
> +	eof_block = (EXT4_I(inode)->i_disksize + inode->i_sb->s_blocksize - 1)
> +			>> inode->i_sb->s_blocksize_bits;
>  	if (eof_block < map->m_lblk + map->m_len)
>  		eof_block = map->m_lblk + map->m_len;
>  	/*
> -- 
> 2.16.4
> 


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

* Re: [PATCH] ext4: Do not zeroout extents beyond i_disksize
  2020-03-31 10:50 [PATCH] ext4: Do not zeroout extents beyond i_disksize Jan Kara
  2020-03-31 13:34 ` Lukas Czerner
@ 2020-04-10 15:12 ` Jan Kara
  2020-04-14  1:30 ` Theodore Y. Ts'o
  2 siblings, 0 replies; 4+ messages in thread
From: Jan Kara @ 2020-04-10 15:12 UTC (permalink / raw)
  To: Ted Tso; +Cc: linux-ext4, Dmitry Monakhov, Jan Kara, stable

On Tue 31-03-20 12:50:16, Jan Kara wrote:
> We do not want to create initialized extents beyond end of file because
> for e2fsck it is impossible to distinguish them from a case of corrupted
> file size / extent tree and so it complains like:
> 
> Inode 12, i_size is 147456, should be 163840.  Fix? no
> 
> Code in ext4_ext_convert_to_initialized() and
> ext4_split_convert_extents() try to make sure it does not create
> initialized extents beyond inode size however they check against
> inode->i_size which is wrong. They should instead check against
> EXT4_I(inode)->i_disksize which is the current inode size on disk.
> That's what e2fsck is going to see in case of crash before all dirty
> data is written. This bug manifests as generic/456 test failure (with
> recent enough fstests where fsx got fixed to properly pass
> FALLOC_KEEP_SIZE_FL flags to the kernel) when run with dioread_lock
> mount option.
> 
> CC: stable@vger.kernel.org
> Fixes: 21ca087a3891 ("ext4: Do not zero out uninitialized extents beyond i_size")
> Signed-off-by: Jan Kara <jack@suse.cz>

Ping Ted? Did this patch get lost?

								Honza

> ---
>  fs/ext4/extents.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
> index 954013d6076b..c5e190fd4589 100644
> --- a/fs/ext4/extents.c
> +++ b/fs/ext4/extents.c
> @@ -3532,8 +3532,8 @@ static int ext4_ext_convert_to_initialized(handle_t *handle,
>  		(unsigned long long)map->m_lblk, map_len);
>  
>  	sbi = EXT4_SB(inode->i_sb);
> -	eof_block = (inode->i_size + inode->i_sb->s_blocksize - 1) >>
> -		inode->i_sb->s_blocksize_bits;
> +	eof_block = (EXT4_I(inode)->i_disksize + inode->i_sb->s_blocksize - 1)
> +			>> inode->i_sb->s_blocksize_bits;
>  	if (eof_block < map->m_lblk + map_len)
>  		eof_block = map->m_lblk + map_len;
>  
> @@ -3785,8 +3785,8 @@ static int ext4_split_convert_extents(handle_t *handle,
>  		  __func__, inode->i_ino,
>  		  (unsigned long long)map->m_lblk, map->m_len);
>  
> -	eof_block = (inode->i_size + inode->i_sb->s_blocksize - 1) >>
> -		inode->i_sb->s_blocksize_bits;
> +	eof_block = (EXT4_I(inode)->i_disksize + inode->i_sb->s_blocksize - 1)
> +			>> inode->i_sb->s_blocksize_bits;
>  	if (eof_block < map->m_lblk + map->m_len)
>  		eof_block = map->m_lblk + map->m_len;
>  	/*
> -- 
> 2.16.4
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

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

* Re: [PATCH] ext4: Do not zeroout extents beyond i_disksize
  2020-03-31 10:50 [PATCH] ext4: Do not zeroout extents beyond i_disksize Jan Kara
  2020-03-31 13:34 ` Lukas Czerner
  2020-04-10 15:12 ` Jan Kara
@ 2020-04-14  1:30 ` Theodore Y. Ts'o
  2 siblings, 0 replies; 4+ messages in thread
From: Theodore Y. Ts'o @ 2020-04-14  1:30 UTC (permalink / raw)
  To: Jan Kara; +Cc: linux-ext4, Dmitry Monakhov, stable

On Tue, Mar 31, 2020 at 12:50:16PM +0200, Jan Kara wrote:
> We do not want to create initialized extents beyond end of file because
> for e2fsck it is impossible to distinguish them from a case of corrupted
> file size / extent tree and so it complains like:
> 
> Inode 12, i_size is 147456, should be 163840.  Fix? no
> 
> Code in ext4_ext_convert_to_initialized() and
> ext4_split_convert_extents() try to make sure it does not create
> initialized extents beyond inode size however they check against
> inode->i_size which is wrong. They should instead check against
> EXT4_I(inode)->i_disksize which is the current inode size on disk.
> That's what e2fsck is going to see in case of crash before all dirty
> data is written. This bug manifests as generic/456 test failure (with
> recent enough fstests where fsx got fixed to properly pass
> FALLOC_KEEP_SIZE_FL flags to the kernel) when run with dioread_lock
> mount option.
> 
> CC: stable@vger.kernel.org
> Fixes: 21ca087a3891 ("ext4: Do not zero out uninitialized extents beyond i_size")
> Signed-off-by: Jan Kara <jack@suse.cz>

Applied, thanks.

					- Ted

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

end of thread, other threads:[~2020-04-14  1:30 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-31 10:50 [PATCH] ext4: Do not zeroout extents beyond i_disksize Jan Kara
2020-03-31 13:34 ` Lukas Czerner
2020-04-10 15:12 ` Jan Kara
2020-04-14  1:30 ` 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).