All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ext4: check iomap type only if ext4_iomap_begin() does not fail
@ 2023-05-05 13:24 Baokun Li
  2023-05-05 16:50 ` Jan Kara
  2023-05-13  4:59 ` Theodore Ts'o
  0 siblings, 2 replies; 3+ messages in thread
From: Baokun Li @ 2023-05-05 13:24 UTC (permalink / raw)
  To: linux-ext4
  Cc: tytso, adilger.kernel, jack, ritesh.list, linux-kernel, yi.zhang,
	yangerkun, yukuai3, libaokun1, syzbot+08106c4b7d60702dbc14

When ext4_iomap_overwrite_begin() calls ext4_iomap_begin() map blocks may
fail for some reason (e.g. memory allocation failure, bare disk write), and
later because "iomap->type ! = IOMAP_MAPPED" triggers WARN_ON(). When ext4
iomap_begin() returns an error, it is normal that the type of iomap->type
may not match the expectation. Therefore, we only determine if iomap->type
is as expected when ext4_iomap_begin() is executed successfully.

Reported-by: syzbot+08106c4b7d60702dbc14@syzkaller.appspotmail.com
Link: https://lore.kernel.org/all/00000000000015760b05f9b4eee9@google.com
Signed-off-by: Baokun Li <libaokun1@huawei.com>
---
 fs/ext4/inode.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index 0d5ba922e411..19c884abe52b 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -3375,7 +3375,7 @@ static int ext4_iomap_overwrite_begin(struct inode *inode, loff_t offset,
 	 */
 	flags &= ~IOMAP_WRITE;
 	ret = ext4_iomap_begin(inode, offset, length, flags, iomap, srcmap);
-	WARN_ON_ONCE(iomap->type != IOMAP_MAPPED);
+	WARN_ON_ONCE(!ret && iomap->type != IOMAP_MAPPED);
 	return ret;
 }
 
-- 
2.31.1


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

* Re: [PATCH] ext4: check iomap type only if ext4_iomap_begin() does not fail
  2023-05-05 13:24 [PATCH] ext4: check iomap type only if ext4_iomap_begin() does not fail Baokun Li
@ 2023-05-05 16:50 ` Jan Kara
  2023-05-13  4:59 ` Theodore Ts'o
  1 sibling, 0 replies; 3+ messages in thread
From: Jan Kara @ 2023-05-05 16:50 UTC (permalink / raw)
  To: Baokun Li
  Cc: linux-ext4, tytso, adilger.kernel, jack, ritesh.list,
	linux-kernel, yi.zhang, yangerkun, yukuai3,
	syzbot+08106c4b7d60702dbc14

On Fri 05-05-23 21:24:29, Baokun Li wrote:
> When ext4_iomap_overwrite_begin() calls ext4_iomap_begin() map blocks may
> fail for some reason (e.g. memory allocation failure, bare disk write), and
> later because "iomap->type ! = IOMAP_MAPPED" triggers WARN_ON(). When ext4
> iomap_begin() returns an error, it is normal that the type of iomap->type
> may not match the expectation. Therefore, we only determine if iomap->type
> is as expected when ext4_iomap_begin() is executed successfully.
> 
> Reported-by: syzbot+08106c4b7d60702dbc14@syzkaller.appspotmail.com
> Link: https://lore.kernel.org/all/00000000000015760b05f9b4eee9@google.com
> Signed-off-by: Baokun Li <libaokun1@huawei.com>

Makes sense. Feel free to add:

Reviewed-by: Jan Kara <jack@suse.cz>

								Honza

> diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
> index 0d5ba922e411..19c884abe52b 100644
> --- a/fs/ext4/inode.c
> +++ b/fs/ext4/inode.c
> @@ -3375,7 +3375,7 @@ static int ext4_iomap_overwrite_begin(struct inode *inode, loff_t offset,
>  	 */
>  	flags &= ~IOMAP_WRITE;
>  	ret = ext4_iomap_begin(inode, offset, length, flags, iomap, srcmap);
> -	WARN_ON_ONCE(iomap->type != IOMAP_MAPPED);
> +	WARN_ON_ONCE(!ret && iomap->type != IOMAP_MAPPED);
>  	return ret;
>  }
>  
> -- 
> 2.31.1
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

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

* Re: [PATCH] ext4: check iomap type only if ext4_iomap_begin() does not fail
  2023-05-05 13:24 [PATCH] ext4: check iomap type only if ext4_iomap_begin() does not fail Baokun Li
  2023-05-05 16:50 ` Jan Kara
@ 2023-05-13  4:59 ` Theodore Ts'o
  1 sibling, 0 replies; 3+ messages in thread
From: Theodore Ts'o @ 2023-05-13  4:59 UTC (permalink / raw)
  To: linux-ext4, Baokun Li
  Cc: Theodore Ts'o, adilger.kernel, jack, ritesh.list,
	linux-kernel, yi.zhang, yangerkun, yukuai3,
	syzbot+08106c4b7d60702dbc14


On Fri, 05 May 2023 21:24:29 +0800, Baokun Li wrote:
> When ext4_iomap_overwrite_begin() calls ext4_iomap_begin() map blocks may
> fail for some reason (e.g. memory allocation failure, bare disk write), and
> later because "iomap->type ! = IOMAP_MAPPED" triggers WARN_ON(). When ext4
> iomap_begin() returns an error, it is normal that the type of iomap->type
> may not match the expectation. Therefore, we only determine if iomap->type
> is as expected when ext4_iomap_begin() is executed successfully.
> 
> [...]

Applied, thanks!

[1/1] ext4: check iomap type only if ext4_iomap_begin() does not fail
      commit: 705c514635a4b6fd0ee321bcf1a9bd75c3629b71

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

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

end of thread, other threads:[~2023-05-13  5:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-05 13:24 [PATCH] ext4: check iomap type only if ext4_iomap_begin() does not fail Baokun Li
2023-05-05 16:50 ` Jan Kara
2023-05-13  4:59 ` Theodore Ts'o

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.