]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
f2fs: fix to relocate check condition in f2fs_fallocate()
authorChao Yu <chao@kernel.org>
Wed, 3 Apr 2024 14:24:19 +0000 (22:24 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 16 Jun 2024 11:39:36 +0000 (13:39 +0200)
[ Upstream commit 278a6253a673611dbc8ab72a3b34b151a8e75822 ]

compress and pinfile flag should be checked after inode lock held to
avoid race condition, fix it.

Fixes: 4c8ff7095bef ("f2fs: support data compression")
Fixes: 5fed0be8583f ("f2fs: do not allow partial truncation on pinned file")
Signed-off-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/f2fs/file.c

index ffec3c5374f89f8875d4b566dc622f9f0bd3be91..39002f3c3f8a7c8b4a02a3ec483dd3b1ecd266ba 100644 (file)
@@ -1760,15 +1760,6 @@ static long f2fs_fallocate(struct file *file, int mode,
                (mode & (FALLOC_FL_COLLAPSE_RANGE | FALLOC_FL_INSERT_RANGE)))
                return -EOPNOTSUPP;
 
-       /*
-        * Pinned file should not support partial truncation since the block
-        * can be used by applications.
-        */
-       if ((f2fs_compressed_file(inode) || f2fs_is_pinned_file(inode)) &&
-               (mode & (FALLOC_FL_PUNCH_HOLE | FALLOC_FL_COLLAPSE_RANGE |
-                       FALLOC_FL_ZERO_RANGE | FALLOC_FL_INSERT_RANGE)))
-               return -EOPNOTSUPP;
-
        if (mode & ~(FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE |
                        FALLOC_FL_COLLAPSE_RANGE | FALLOC_FL_ZERO_RANGE |
                        FALLOC_FL_INSERT_RANGE))
@@ -1776,6 +1767,17 @@ static long f2fs_fallocate(struct file *file, int mode,
 
        inode_lock(inode);
 
+       /*
+        * Pinned file should not support partial truncation since the block
+        * can be used by applications.
+        */
+       if ((f2fs_compressed_file(inode) || f2fs_is_pinned_file(inode)) &&
+               (mode & (FALLOC_FL_PUNCH_HOLE | FALLOC_FL_COLLAPSE_RANGE |
+                       FALLOC_FL_ZERO_RANGE | FALLOC_FL_INSERT_RANGE))) {
+               ret = -EOPNOTSUPP;
+               goto out;
+       }
+
        ret = file_modified(file);
        if (ret)
                goto out;