From f7dd5f0807d822615a8ddbceb711c343ac8eaab2 Mon Sep 17 00:00:00 2001 From: Jiri Slaby Date: May 17 2023 19:16:07 +0000 Subject: ext4: check iomap type only if ext4_iomap_begin() does not fail (bsc#1012628). --- diff --git a/patches.kernel.org/6.3.3-230-ext4-check-iomap-type-only-if-ext4_iomap_begin-.patch b/patches.kernel.org/6.3.3-230-ext4-check-iomap-type-only-if-ext4_iomap_begin-.patch new file mode 100644 index 0000000..7e16fcb --- /dev/null +++ b/patches.kernel.org/6.3.3-230-ext4-check-iomap-type-only-if-ext4_iomap_begin-.patch @@ -0,0 +1,46 @@ +From: Baokun Li +Date: Fri, 5 May 2023 21:24:29 +0800 +Subject: [PATCH] ext4: check iomap type only if ext4_iomap_begin() does not + fail +References: bsc#1012628 +Patch-mainline: 6.3.3 +Git-commit: fa83c34e3e56b3c672af38059e066242655271b1 + +commit fa83c34e3e56b3c672af38059e066242655271b1 upstream. + +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. + +Cc: stable@kernel.org +Reported-by: syzbot+08106c4b7d60702dbc14@syzkaller.appspotmail.com +Link: https://lore.kernel.org/all/00000000000015760b05f9b4eee9@google.com +Signed-off-by: Baokun Li +Reviewed-by: Jan Kara +Link: https://lore.kernel.org/r/20230505132429.714648-1-libaokun1@huawei.com +Signed-off-by: Theodore Ts'o +Signed-off-by: Greg Kroah-Hartman +Signed-off-by: Jiri Slaby +--- + 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 87d01f1c..145ea24d 100644 +--- a/fs/ext4/inode.c ++++ b/fs/ext4/inode.c +@@ -3576,7 +3576,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.35.3 + diff --git a/series.conf b/series.conf index 97f5994..76f54c8 100644 --- a/series.conf +++ b/series.conf @@ -963,6 +963,7 @@ patches.kernel.org/6.3.3-227-ext4-avoid-a-potential-slab-out-of-bounds-in-ex.patch patches.kernel.org/6.3.3-228-ext4-fix-data-races-when-using-cached-status-ex.patch patches.kernel.org/6.3.3-229-ext4-avoid-deadlock-in-fs-reclaim-with-page-wri.patch + patches.kernel.org/6.3.3-230-ext4-check-iomap-type-only-if-ext4_iomap_begin-.patch ######################################################## # Build fixes that apply to the vanilla kernel too.