From: Chao Yu <chao@xxxxxxxxxx> commit 96cfeb0389530ae32ade8a48ae3ae1ac3b6c009d upstream. It should wait all existing dio write IOs before block removal, otherwise, previous direct write IO may overwrite data in the block which may be reused by other inode. Cc: stable@xxxxxxxxxxxxxxx Signed-off-by: Chao Yu <chao@xxxxxxxxxx> Signed-off-by: Jaegeuk Kim <jaegeuk@xxxxxxxxxx> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- fs/f2fs/file.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -1054,6 +1054,13 @@ int f2fs_setattr(struct mnt_idmap *idmap return err; } + /* + * wait for inflight dio, blocks should be removed after + * IO completion. + */ + if (attr->ia_size < old_size) + inode_dio_wait(inode); + f2fs_down_write(&fi->i_gc_rwsem[WRITE]); filemap_invalidate_lock(inode->i_mapping); @@ -1890,6 +1897,12 @@ static long f2fs_fallocate(struct file * if (ret) goto out; + /* + * wait for inflight dio, blocks should be removed after IO + * completion. + */ + inode_dio_wait(inode); + if (mode & FALLOC_FL_PUNCH_HOLE) { if (offset >= inode->i_size) goto out; Patches currently in stable-queue which might be from chao@xxxxxxxxxx are queue-6.11/f2fs-fix-to-don-t-set-sb_rdonly-in-f2fs_handle_criti.patch queue-6.11/f2fs-fix-several-potential-integer-overflows-in-file-offsets.patch queue-6.11/f2fs-fix-to-wait-page-writeback-before-setting-gcing.patch queue-6.11/f2fs-prevent-possible-int-overflow-in-dir_block_index.patch queue-6.11/f2fs-fix-to-avoid-use-after-free-in-f2fs_stop_gc_thr.patch queue-6.11/f2fs-avoid-potential-int-overflow-in-sanity_check_area_boundary.patch queue-6.11/f2fs-fix-to-check-atomic_file-in-f2fs-ioctl-interfaces.patch queue-6.11/f2fs-create-cow-inode-from-parent-dentry-for-atomic-.patch queue-6.11/f2fs-atomic-fix-to-avoid-racing-w-gc.patch queue-6.11/f2fs-fix-to-avoid-racing-in-between-read-and-opu-dio.patch queue-6.11/f2fs-reduce-expensive-checkpoint-trigger-frequency.patch queue-6.11/f2fs-require-fmode_write-for-atomic-write-ioctls.patch queue-6.11/revert-f2fs-use-flush-command-instead-of-fua-for-zoned-device.patch queue-6.11/f2fs-fix-to-wait-dio-completion.patch queue-6.11/f2fs-get-rid-of-online-repaire-on-corrupted-director.patch queue-6.11/f2fs-compress-don-t-redirty-sparse-cluster-during-de.patch queue-6.11/f2fs-atomic-fix-to-truncate-pagecache-before-on-disk.patch queue-6.11/erofs-fix-error-handling-in-z_erofs_init_decompresso.patch queue-6.11/f2fs-check-discard-support-for-conventional-zones.patch