The patch below does not apply to the 4.14-stable tree. If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <stable@xxxxxxxxxxxxxxx>. To reproduce the conflict and resubmit, you may use the following commands: git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-4.14.y git checkout FETCH_HEAD git cherry-pick -x fa83c34e3e56b3c672af38059e066242655271b1 # <resolve conflicts, build, test, etc.> git commit -s git send-email --to '<stable@xxxxxxxxxxxxxxx>' --in-reply-to '2023051521-buckshot-elliptic-0f14@gregkh' --subject-prefix 'PATCH 4.14.y' HEAD^.. Possible dependencies: fa83c34e3e56 ("ext4: check iomap type only if ext4_iomap_begin() does not fail") 8cd115bdda17 ("ext4: Optimize ext4 DIO overwrites") aa9714d0e397 ("ext4: Start with shared i_rwsem in case of DIO instead of exclusive") 378f32bab371 ("ext4: introduce direct I/O write using iomap infrastructure") 0b9f230b94dd ("ext4: move inode extension check out from ext4_iomap_alloc()") 569342dc2485 ("ext4: move inode extension/truncate code out from ->iomap_end() callback") b1b4705d54ab ("ext4: introduce direct I/O read using iomap infrastructure") 09edf4d38195 ("ext4: introduce new callback for IOMAP_REPORT") f063db5ee989 ("ext4: split IOMAP_WRITE branch in ext4_iomap_begin() into helper") c8fdfe294187 ("ext4: move set iomap routines into a separate helper ext4_set_iomap()") 2e9b51d78229 ("ext4: iomap that extends beyond EOF should be marked dirty") 548feebec7e9 ("ext4: update direct I/O read lock pattern for IOCB_NOWAIT") 53e5cca56795 ("ext4: reorder map.m_flags checks within ext4_iomap_begin()") c8cc88163f40 ("ext4: Add support for blocksize < pagesize in dioread_nolock") 2943fdbc688e ("ext4: Refactor mpage_map_and_submit_buffers function") a00713ea982b ("ext4: Add API to bring in support for unwritten io_end_vec conversion") 821ff38d192a ("ext4: keep uniform naming convention for io & io_end variables") 70cb0d02b581 ("Merge tag 'ext4_for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4") thanks, greg k-h ------------------ original commit in Linus's tree ------------------ >From fa83c34e3e56b3c672af38059e066242655271b1 Mon Sep 17 00:00:00 2001 From: Baokun Li <libaokun1@xxxxxxxxxx> Date: Fri, 5 May 2023 21:24:29 +0800 Subject: [PATCH] ext4: check iomap type only if ext4_iomap_begin() does not fail 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@xxxxxxxxxx Reported-by: syzbot+08106c4b7d60702dbc14@xxxxxxxxxxxxxxxxxxxxxxxxx Link: https://lore.kernel.org/all/00000000000015760b05f9b4eee9@xxxxxxxxxx Signed-off-by: Baokun Li <libaokun1@xxxxxxxxxx> Reviewed-by: Jan Kara <jack@xxxxxxx> Link: https://lore.kernel.org/r/20230505132429.714648-1-libaokun1@xxxxxxxxxx Signed-off-by: Theodore Ts'o <tytso@xxxxxxx> diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 3cb774d9e3f1..ce5f21b6c2b3 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -3377,7 +3377,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; }