diff mbox series

[f2fs-dev,1/2] f2fs: fix to relocate check condition in f2fs_fallocate()

Message ID 20240403142420.2042498-1-chao@kernel.org (mailing list archive)
State Accepted
Commit 278a6253a673611dbc8ab72a3b34b151a8e75822
Headers show
Series [f2fs-dev,1/2] f2fs: fix to relocate check condition in f2fs_fallocate() | expand

Commit Message

Chao Yu April 3, 2024, 2:24 p.m. UTC
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>
---
 fs/f2fs/file.c | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

Comments

Zhiguo Niu April 7, 2024, 2:11 a.m. UTC | #1
On Wed, Apr 3, 2024 at 10:26 PM Chao Yu <chao@kernel.org> wrote:
>
> 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>
> ---
>  fs/f2fs/file.c | 20 +++++++++++---------
>  1 file changed, 11 insertions(+), 9 deletions(-)
>
> diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
> index 148bfe3effdf..83a807e25e31 100644
> --- a/fs/f2fs/file.c
> +++ b/fs/f2fs/file.c
> @@ -1820,15 +1820,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))
> @@ -1836,6 +1827,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;
> +       }
> +
Dear Chao,
I see  the judgment code "if(!f2fs_compressed_file(inode))" also is
before inode_lock in functions
f2fs_ioc_decompress_file/f2fs_ioc_compress_file/f2fs_reserve_compress_blocks/f2fs_release_compress_blocks.
should they are changed together?
thanks!
>         ret = file_modified(file);
>         if (ret)
>                 goto out;
> --
> 2.40.1
>
>
>
> _______________________________________________
> Linux-f2fs-devel mailing list
> Linux-f2fs-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Chao Yu April 7, 2024, 7:29 a.m. UTC | #2
On 2024/4/7 10:11, Zhiguo Niu wrote:
> On Wed, Apr 3, 2024 at 10:26 PM Chao Yu <chao@kernel.org> wrote:
>>
>> 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>
>> ---
>>   fs/f2fs/file.c | 20 +++++++++++---------
>>   1 file changed, 11 insertions(+), 9 deletions(-)
>>
>> diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
>> index 148bfe3effdf..83a807e25e31 100644
>> --- a/fs/f2fs/file.c
>> +++ b/fs/f2fs/file.c
>> @@ -1820,15 +1820,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))
>> @@ -1836,6 +1827,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;
>> +       }
>> +
> Dear Chao,
> I see  the judgment code "if(!f2fs_compressed_file(inode))" also is
> before inode_lock in functions
> f2fs_ioc_decompress_file/f2fs_ioc_compress_file/f2fs_reserve_compress_blocks/f2fs_release_compress_blocks.
> should they are changed together?

Zhiguo,

Thanks for noticing that, I've submitted separated patches for fixing
because those bugs were introduced by separated commits.

Thanks,

> thanks!
>>          ret = file_modified(file);
>>          if (ret)
>>                  goto out;
>> --
>> 2.40.1
>>
>>
>>
>> _______________________________________________
>> Linux-f2fs-devel mailing list
>> Linux-f2fs-devel@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Zhiguo Niu April 7, 2024, 8:29 a.m. UTC | #3
On Sun, Apr 7, 2024 at 3:29 PM Chao Yu <chao@kernel.org> wrote:
>
> On 2024/4/7 10:11, Zhiguo Niu wrote:
> > On Wed, Apr 3, 2024 at 10:26 PM Chao Yu <chao@kernel.org> wrote:
> >>
> >> 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>
> >> ---
> >>   fs/f2fs/file.c | 20 +++++++++++---------
> >>   1 file changed, 11 insertions(+), 9 deletions(-)
> >>
> >> diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
> >> index 148bfe3effdf..83a807e25e31 100644
> >> --- a/fs/f2fs/file.c
> >> +++ b/fs/f2fs/file.c
> >> @@ -1820,15 +1820,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))
> >> @@ -1836,6 +1827,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;
> >> +       }
> >> +
> > Dear Chao,
> > I see  the judgment code "if(!f2fs_compressed_file(inode))" also is
> > before inode_lock in functions
> > f2fs_ioc_decompress_file/f2fs_ioc_compress_file/f2fs_reserve_compress_blocks/f2fs_release_compress_blocks.
> > should they are changed together?
>
> Zhiguo,
>
> Thanks for noticing that, I've submitted separated patches for fixing
> because those bugs were introduced by separated commits.
>
> Thanks,
Dear Chao,
You're welcome^^

>
> > thanks!
> >>          ret = file_modified(file);
> >>          if (ret)
> >>                  goto out;
> >> --
> >> 2.40.1
> >>
> >>
> >>
> >> _______________________________________________
> >> Linux-f2fs-devel mailing list
> >> Linux-f2fs-devel@lists.sourceforge.net
> >> https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
patchwork-bot+f2fs@kernel.org April 14, 2024, 3:32 p.m. UTC | #4
Hello:

This series was applied to jaegeuk/f2fs.git (dev)
by Jaegeuk Kim <jaegeuk@kernel.org>:

On Wed,  3 Apr 2024 22:24:19 +0800 you wrote:
> 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>
> 
> [...]

Here is the summary with links:
  - [f2fs-dev,1/2] f2fs: fix to relocate check condition in f2fs_fallocate()
    https://git.kernel.org/jaegeuk/f2fs/c/278a6253a673
  - [f2fs-dev,2/2] f2fs: fix to check pinfile flag in f2fs_move_file_range()
    https://git.kernel.org/jaegeuk/f2fs/c/e07230da0500

You are awesome, thank you!
diff mbox series

Patch

diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index 148bfe3effdf..83a807e25e31 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -1820,15 +1820,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))
@@ -1836,6 +1827,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;