f2fs: fix to abort atomic write only during do_exist()
authorChao Yu <chao@kernel.org>
Mon, 9 Jan 2023 03:44:51 +0000 (11:44 +0800)
committerJaegeuk Kim <jaegeuk@kernel.org>
Tue, 31 Jan 2023 18:48:13 +0000 (10:48 -0800)
Commit 7a10f0177e11 ("f2fs: don't give partially written atomic data
from process crash") attempted to drop atomic write data after process
crash, however, f2fs_abort_atomic_write() may be called from noncrash
case, fix it by adding missed PF_EXITING check condition
f2fs_file_flush().

- application crashs
 - do_exit
  - exit_signals -- sets PF_EXITING
  - exit_files
   - put_files_struct
    - close_files
     - filp_close
      - flush (f2fs_file_flush)
       - check atomic_write_task && PF_EXITING
       - f2fs_abort_atomic_write

Fixes: 7a10f0177e11 ("f2fs: don't give partially written atomic data from process crash")
Signed-off-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fs/f2fs/file.c

index 391da47761e3259983137cb93cff502d69c675aa..eaae2ad3957b0f5f90b493f225ef1b1d39e5d2ca 100644 (file)
@@ -1876,7 +1876,8 @@ static int f2fs_file_flush(struct file *file, fl_owner_t id)
         * until all the writers close its file. Since this should be done
         * before dropping file lock, it needs to do in ->flush.
         */
-       if (F2FS_I(inode)->atomic_write_task == current)
+       if (F2FS_I(inode)->atomic_write_task == current &&
+                               (current->flags & PF_EXITING))
                f2fs_abort_atomic_write(inode, true);
        return 0;
 }