2022-01-23 15:12:03

by Harry Austen

[permalink] [raw]
Subject: [PATCH] f2fs: fix fileattr_set unsupported attribute handling

FS_IOC_SETFLAGS ioctl should return EOPNOTSUPP if the file attribute
(e.g. FS_NOCOW_FL) is not supported, rather than silently ignoring it
and returning success.

Fixes: 9b1bb01c8ae7 (f2fs: convert to fileattr)
Signed-off-by: Harry Austen <[email protected]>
---
fs/f2fs/file.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index 92ec2699bc85..061bf35c2582 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -3085,9 +3085,8 @@ int f2fs_fileattr_set(struct user_namespace *mnt_userns,
return -EIO;
if (!f2fs_is_checkpoint_ready(F2FS_I_SB(inode)))
return -ENOSPC;
- if (fsflags & ~F2FS_GETTABLE_FS_FL)
+ if (fsflags & ~F2FS_SETTABLE_FS_FL)
return -EOPNOTSUPP;
- fsflags &= F2FS_SETTABLE_FS_FL;
if (!fa->flags_valid)
mask &= FS_COMMON_FL;

--
2.34.1


2022-01-24 07:14:36

by Chao Yu

[permalink] [raw]
Subject: Re: [PATCH] f2fs: fix fileattr_set unsupported attribute handling

On 2022/1/22 20:59, Harry Austen wrote:
> FS_IOC_SETFLAGS ioctl should return EOPNOTSUPP if the file attribute
> (e.g. FS_NOCOW_FL) is not supported, rather than silently ignoring it
> and returning success.
>
> Fixes: 9b1bb01c8ae7 (f2fs: convert to fileattr)
> Signed-off-by: Harry Austen <[email protected]>

Reviewed-by: Chao Yu <[email protected]>

Thanks,

2022-01-24 20:29:55

by Eric Biggers

[permalink] [raw]
Subject: Re: [f2fs-dev] [PATCH] f2fs: fix fileattr_set unsupported attribute handling

On Sat, Jan 22, 2022 at 12:59:03PM +0000, Harry Austen wrote:
> FS_IOC_SETFLAGS ioctl should return EOPNOTSUPP if the file attribute
> (e.g. FS_NOCOW_FL) is not supported, rather than silently ignoring it
> and returning success.
>
> Fixes: 9b1bb01c8ae7 (f2fs: convert to fileattr)
> Signed-off-by: Harry Austen <[email protected]>
> ---
> fs/f2fs/file.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
> index 92ec2699bc85..061bf35c2582 100644
> --- a/fs/f2fs/file.c
> +++ b/fs/f2fs/file.c
> @@ -3085,9 +3085,8 @@ int f2fs_fileattr_set(struct user_namespace *mnt_userns,
> return -EIO;
> if (!f2fs_is_checkpoint_ready(F2FS_I_SB(inode)))
> return -ENOSPC;
> - if (fsflags & ~F2FS_GETTABLE_FS_FL)
> + if (fsflags & ~F2FS_SETTABLE_FS_FL)
> return -EOPNOTSUPP;
> - fsflags &= F2FS_SETTABLE_FS_FL;
> if (!fa->flags_valid)
> mask &= FS_COMMON_FL;

This is intentional, and matches what ext4 does; see the comment in the ext4
implementation of this:

/*
* chattr(1) grabs flags via GETFLAGS, modifies the result and
* passes that to SETFLAGS. So we cannot easily make SETFLAGS
* more restrictive than just silently masking off visible but
* not settable flags as we always did.
*/

Also, even if this patch was correct, the Fixes tag is wrong.

- Eric

2022-01-26 10:53:03

by Harry Austen

[permalink] [raw]
Subject: Re: [f2fs-dev] [PATCH] f2fs: fix fileattr_set unsupported attribute handling

On Monday, 24 January 2022 19:25:44 GMT Eric Biggers wrote:
> On Sat, Jan 22, 2022 at 12:59:03PM +0000, Harry Austen wrote:
> > FS_IOC_SETFLAGS ioctl should return EOPNOTSUPP if the file attribute
> > (e.g. FS_NOCOW_FL) is not supported, rather than silently ignoring it
> > and returning success.
> >
> > Fixes: 9b1bb01c8ae7 (f2fs: convert to fileattr)
> > Signed-off-by: Harry Austen <[email protected]>
> > ---
> >
> > fs/f2fs/file.c | 3 +--
> > 1 file changed, 1 insertion(+), 2 deletions(-)
> >
> > diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
> > index 92ec2699bc85..061bf35c2582 100644
> > --- a/fs/f2fs/file.c
> > +++ b/fs/f2fs/file.c
> > @@ -3085,9 +3085,8 @@ int f2fs_fileattr_set(struct user_namespace
> > *mnt_userns,>
> > return -EIO;
> >
> > if (!f2fs_is_checkpoint_ready(F2FS_I_SB(inode)))
> >
> > return -ENOSPC;
> >
> > - if (fsflags & ~F2FS_GETTABLE_FS_FL)
> > + if (fsflags & ~F2FS_SETTABLE_FS_FL)
> >
> > return -EOPNOTSUPP;
> >
> > - fsflags &= F2FS_SETTABLE_FS_FL;
> >
> > if (!fa->flags_valid)
> >
> > mask &= FS_COMMON_FL;
>
> This is intentional, and matches what ext4 does; see the comment in the ext4
> implementation of this:
>
> /*
> * chattr(1) grabs flags via GETFLAGS, modifies the result and
> * passes that to SETFLAGS. So we cannot easily make SETFLAGS
> * more restrictive than just silently masking off visible but
> * not settable flags as we always did.
> */

Ah, my apologies. I thought it looked a little too obvious. Clearly I
should have looked at the ext4 code. Please disregard this patch.

Is there anything else that could be done to improve unsettable
attribute handling? For example, is there a reason FS_NOCOW_FL is
gettable but not settable? Could it be added to the settable list?

>
> Also, even if this patch was correct, the Fixes tag is wrong.

Having looked at this a bit more, I assume you are saying this due to
the missing double quotes around the commit summary? (just so I know for
next time as this is my first attempt at sending a kernel patch)

>
> - Eric

Many thanks for your help Eric,
Harry


2022-01-26 10:55:00

by Eric Biggers

[permalink] [raw]
Subject: Re: [f2fs-dev] [PATCH] f2fs: fix fileattr_set unsupported attribute handling

On Tue, Jan 25, 2022 at 10:01:49PM +0000, Harry Austen wrote:
> On Monday, 24 January 2022 19:25:44 GMT Eric Biggers wrote:
> > On Sat, Jan 22, 2022 at 12:59:03PM +0000, Harry Austen wrote:
> > > FS_IOC_SETFLAGS ioctl should return EOPNOTSUPP if the file attribute
> > > (e.g. FS_NOCOW_FL) is not supported, rather than silently ignoring it
> > > and returning success.
> > >
> > > Fixes: 9b1bb01c8ae7 (f2fs: convert to fileattr)
> > > Signed-off-by: Harry Austen <[email protected]>
> > > ---
> > >
> > > fs/f2fs/file.c | 3 +--
> > > 1 file changed, 1 insertion(+), 2 deletions(-)
> > >
> > > diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
> > > index 92ec2699bc85..061bf35c2582 100644
> > > --- a/fs/f2fs/file.c
> > > +++ b/fs/f2fs/file.c
> > > @@ -3085,9 +3085,8 @@ int f2fs_fileattr_set(struct user_namespace
> > > *mnt_userns,>
> > > return -EIO;
> > >
> > > if (!f2fs_is_checkpoint_ready(F2FS_I_SB(inode)))
> > >
> > > return -ENOSPC;
> > >
> > > - if (fsflags & ~F2FS_GETTABLE_FS_FL)
> > > + if (fsflags & ~F2FS_SETTABLE_FS_FL)
> > >
> > > return -EOPNOTSUPP;
> > >
> > > - fsflags &= F2FS_SETTABLE_FS_FL;
> > >
> > > if (!fa->flags_valid)
> > >
> > > mask &= FS_COMMON_FL;
> >
> > This is intentional, and matches what ext4 does; see the comment in the ext4
> > implementation of this:
> >
> > /*
> > * chattr(1) grabs flags via GETFLAGS, modifies the result and
> > * passes that to SETFLAGS. So we cannot easily make SETFLAGS
> > * more restrictive than just silently masking off visible but
> > * not settable flags as we always did.
> > */
>
> Ah, my apologies. I thought it looked a little too obvious. Clearly I
> should have looked at the ext4 code. Please disregard this patch.
>
> Is there anything else that could be done to improve unsettable
> attribute handling? For example, is there a reason FS_NOCOW_FL is
> gettable but not settable? Could it be added to the settable list?

A lot of flags are gettable by FS_IOC_GETFLAGS but not settable by
FS_IOC_SETFLAGS, typically because they can only be set through a dedicated
interface. For example, the encrypt flag can only be set using
FS_IOC_SET_ENCRYPTION_POLICY, or via inheritance.

> >
> > Also, even if this patch was correct, the Fixes tag is wrong.
>
> Having looked at this a bit more, I assume you are saying this due to
> the missing double quotes around the commit summary? (just so I know for
> next time as this is my first attempt at sending a kernel patch)
>

There's that, but more importantly the commit you listed is wrong. The relevant
code was added by an earlier commit, and that commit just moved it.

- Eric

2022-02-01 09:34:51

by kernel test robot

[permalink] [raw]
Subject: [f2fs] 9ec9c5043d: xfstests.generic.386.fail



Greeting,

FYI, we noticed the following commit (built with gcc-9):

commit: 9ec9c5043d0f4284b84d2fd8eab0ace464e87455 ("[PATCH] f2fs: fix fileattr_set unsupported attribute handling")
url: https://github.com/0day-ci/linux/commits/Harry-Austen/f2fs-fix-fileattr_set-unsupported-attribute-handling/20220122-210057
base: https://git.kernel.org/cgit/linux/kernel/git/jaegeuk/f2fs.git dev-test
patch link: https://lore.kernel.org/linux-f2fs-devel/AM6PR10MB2838873D61CE1C0DB91EEDB9FA5C9@AM6PR10MB2838.EURPRD10.PROD.OUTLOOK.COM

in testcase: xfstests
version: xfstests-x86_64-972d710-1_20220127
with following parameters:

disk: 4HDD
fs: f2fs
test: generic-group-19
ucode: 0xe2

test-description: xfstests is a regression test suite for xfs and other files ystems.
test-url: git://git.kernel.org/pub/scm/fs/xfs/xfstests-dev.git


on test machine: 4 threads Intel(R) Core(TM) i5-6500 CPU @ 3.20GHz with 32G memory

caused below changes (please refer to attached dmesg/kmsg for entire log/backtrace):




If you fix the issue, kindly add following tag
Reported-by: kernel test robot <[email protected]>



generic/386 - output mismatch (see /lkp/benchmarks/xfstests/results//generic/386.out.bad)
--- tests/generic/386.out 2022-01-27 11:54:16.000000000 +0000
+++ /lkp/benchmarks/xfstests/results//generic/386.out.bad 2022-01-29 08:21:27.570723360 +0000
@@ -1,2 +1,4 @@
QA output created by 386
Silence is golden.
+xfs_quota: project quota flag not set on /fs/scratch/test
+xfs_quota: project quota flag not set on /fs/scratch/test
...
(Run 'diff -u /lkp/benchmarks/xfstests/tests/generic/386.out /lkp/benchmarks/xfstests/results//generic/386.out.bad' to see the entire diff)



To reproduce:

git clone https://github.com/intel/lkp-tests.git
cd lkp-tests
sudo bin/lkp install job.yaml # job file is attached in this email
bin/lkp split-job --compatible job.yaml # generate the yaml file for lkp run
sudo bin/lkp run generated-yaml-file

# if come across any failure that blocks the test,
# please remove ~/.lkp and /lkp dir to run from a clean state.



---
0DAY/LKP+ Test Infrastructure Open Source Technology Center
https://lists.01.org/hyperkitty/list/[email protected] Intel Corporation

Thanks,
Oliver Sang


Attachments:
(No filename) (2.35 kB)
config-5.16.0-11203-g9ec9c5043d0f (181.50 kB)
job-script (5.78 kB)
kmsg.xz (29.27 kB)
xfstests (2.99 kB)
job.yaml (4.77 kB)
reproduce (931.00 B)
Download all attachments