linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] f2fs: return -EPERM given generic mask
@ 2021-05-06 19:13 Jaegeuk Kim
  2021-05-07  6:26 ` [f2fs-dev] " Eric Biggers
  2021-05-10 14:42 ` [PATCH v2] f2fs: support iflag change given the mask Jaegeuk Kim
  0 siblings, 2 replies; 7+ messages in thread
From: Jaegeuk Kim @ 2021-05-06 19:13 UTC (permalink / raw)
  To: linux-kernel, linux-f2fs-devel; +Cc: Jaegeuk Kim

In f2fs_fileattr_set(),

	if (!fa->flags_valid)
		mask &= FS_COMMON_FL;

In this case, we should not allow to set FS_COMPR_FL, instead of BUG_ON.

/* Flags shared betwen flags/xflags */
	(FS_SYNC_FL | FS_IMMUTABLE_FL | FS_APPEND_FL | \
	 FS_NODUMP_FL |	FS_NOATIME_FL | FS_DAX_FL | \
	 FS_PROJINHERIT_FL)

Fixes: 4c5b47997521 ("vfs: add fileattr ops")
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
---
 fs/f2fs/file.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index e01ce802cf10..38015ef84893 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -1817,7 +1817,9 @@ static int f2fs_setflags_common(struct inode *inode, u32 iflags, u32 mask)
 	struct f2fs_inode_info *fi = F2FS_I(inode);
 	u32 masked_flags = fi->i_flags & mask;
 
-	f2fs_bug_on(F2FS_I_SB(inode), (iflags & ~mask));
+	/* mask can be shrunk by flags_valid selector */
+	if (iflags & ~mask)
+		return -EPERM;
 
 	/* Is it quota file? Do not allow user to mess with it */
 	if (IS_NOQUOTA(inode))
-- 
2.31.1.607.g51e8a6a459-goog


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [f2fs-dev] [PATCH] f2fs: return -EPERM given generic mask
  2021-05-06 19:13 [PATCH] f2fs: return -EPERM given generic mask Jaegeuk Kim
@ 2021-05-07  6:26 ` Eric Biggers
  2021-05-10 14:39   ` Jaegeuk Kim
  2021-05-10 14:42 ` [PATCH v2] f2fs: support iflag change given the mask Jaegeuk Kim
  1 sibling, 1 reply; 7+ messages in thread
From: Eric Biggers @ 2021-05-07  6:26 UTC (permalink / raw)
  To: Jaegeuk Kim; +Cc: linux-kernel, linux-f2fs-devel

On Thu, May 06, 2021 at 12:13:47PM -0700, Jaegeuk Kim wrote:
> In f2fs_fileattr_set(),
> 
> 	if (!fa->flags_valid)
> 		mask &= FS_COMMON_FL;
> 
> In this case, we should not allow to set FS_COMPR_FL, instead of BUG_ON.
> 
> /* Flags shared betwen flags/xflags */
> 	(FS_SYNC_FL | FS_IMMUTABLE_FL | FS_APPEND_FL | \
> 	 FS_NODUMP_FL |	FS_NOATIME_FL | FS_DAX_FL | \
> 	 FS_PROJINHERIT_FL)
> 
> Fixes: 4c5b47997521 ("vfs: add fileattr ops")
> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
> ---
>  fs/f2fs/file.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
> index e01ce802cf10..38015ef84893 100644
> --- a/fs/f2fs/file.c
> +++ b/fs/f2fs/file.c
> @@ -1817,7 +1817,9 @@ static int f2fs_setflags_common(struct inode *inode, u32 iflags, u32 mask)
>  	struct f2fs_inode_info *fi = F2FS_I(inode);
>  	u32 masked_flags = fi->i_flags & mask;
>  
> -	f2fs_bug_on(F2FS_I_SB(inode), (iflags & ~mask));
> +	/* mask can be shrunk by flags_valid selector */
> +	if (iflags & ~mask)
> +		return -EPERM;
>  
>  	/* Is it quota file? Do not allow user to mess with it */
>  	if (IS_NOQUOTA(inode))
> -- 
> 2.31.1.607.g51e8a6a459-goog

This looks like the wrong fix.  AFAICS, 'mask' is the set of inode flags that
the specific ioctl (FS_IOC_SETFLAGS or FS_IOC_FSSETXATTR) can potentially
modify, while 'iflags' is the new set of inode flags among the set that either
ioctl can potentially modify.  So this change will stop FS_IOC_FSSETXATTR from
working on files that have already flags set which are only modifiable by
FS_IOC_SETFLAGS, e.g. the compression flag.

I think the correct fix would be to just do something like 'iflags &= mask'.

- Eric

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [f2fs-dev] [PATCH] f2fs: return -EPERM given generic mask
  2021-05-07  6:26 ` [f2fs-dev] " Eric Biggers
@ 2021-05-10 14:39   ` Jaegeuk Kim
  0 siblings, 0 replies; 7+ messages in thread
From: Jaegeuk Kim @ 2021-05-10 14:39 UTC (permalink / raw)
  To: Eric Biggers; +Cc: linux-kernel, linux-f2fs-devel

On 05/06, Eric Biggers wrote:
> On Thu, May 06, 2021 at 12:13:47PM -0700, Jaegeuk Kim wrote:
> > In f2fs_fileattr_set(),
> > 
> > 	if (!fa->flags_valid)
> > 		mask &= FS_COMMON_FL;
> > 
> > In this case, we should not allow to set FS_COMPR_FL, instead of BUG_ON.
> > 
> > /* Flags shared betwen flags/xflags */
> > 	(FS_SYNC_FL | FS_IMMUTABLE_FL | FS_APPEND_FL | \
> > 	 FS_NODUMP_FL |	FS_NOATIME_FL | FS_DAX_FL | \
> > 	 FS_PROJINHERIT_FL)
> > 
> > Fixes: 4c5b47997521 ("vfs: add fileattr ops")
> > Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
> > ---
> >  fs/f2fs/file.c | 4 +++-
> >  1 file changed, 3 insertions(+), 1 deletion(-)
> > 
> > diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
> > index e01ce802cf10..38015ef84893 100644
> > --- a/fs/f2fs/file.c
> > +++ b/fs/f2fs/file.c
> > @@ -1817,7 +1817,9 @@ static int f2fs_setflags_common(struct inode *inode, u32 iflags, u32 mask)
> >  	struct f2fs_inode_info *fi = F2FS_I(inode);
> >  	u32 masked_flags = fi->i_flags & mask;
> >  
> > -	f2fs_bug_on(F2FS_I_SB(inode), (iflags & ~mask));
> > +	/* mask can be shrunk by flags_valid selector */
> > +	if (iflags & ~mask)
> > +		return -EPERM;
> >  
> >  	/* Is it quota file? Do not allow user to mess with it */
> >  	if (IS_NOQUOTA(inode))
> > -- 
> > 2.31.1.607.g51e8a6a459-goog
> 
> This looks like the wrong fix.  AFAICS, 'mask' is the set of inode flags that
> the specific ioctl (FS_IOC_SETFLAGS or FS_IOC_FSSETXATTR) can potentially
> modify, while 'iflags' is the new set of inode flags among the set that either
> ioctl can potentially modify.  So this change will stop FS_IOC_FSSETXATTR from
> working on files that have already flags set which are only modifiable by
> FS_IOC_SETFLAGS, e.g. the compression flag.
> 
> I think the correct fix would be to just do something like 'iflags &= mask'.

Thanks. Let me send v2.

> 
> - Eric

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] f2fs: support iflag change given the mask
  2021-05-06 19:13 [PATCH] f2fs: return -EPERM given generic mask Jaegeuk Kim
  2021-05-07  6:26 ` [f2fs-dev] " Eric Biggers
@ 2021-05-10 14:42 ` Jaegeuk Kim
  2021-05-10 22:28   ` [f2fs-dev] " Eric Biggers
  2021-05-11  1:43   ` Chao Yu
  1 sibling, 2 replies; 7+ messages in thread
From: Jaegeuk Kim @ 2021-05-10 14:42 UTC (permalink / raw)
  To: linux-kernel, linux-f2fs-devel

In f2fs_fileattr_set(),

	if (!fa->flags_valid)
		mask &= FS_COMMON_FL;

In this case, we can set supported flags by mask only instead of BUG_ON.

/* Flags shared betwen flags/xflags */
	(FS_SYNC_FL | FS_IMMUTABLE_FL | FS_APPEND_FL | \
	 FS_NODUMP_FL |	FS_NOATIME_FL | FS_DAX_FL | \
	 FS_PROJINHERIT_FL)

Fixes: 4c5b47997521 ("vfs: add fileattr ops")
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
---
 fs/f2fs/file.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index 44a4650aea7b..ceb575f99048 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -1817,7 +1817,8 @@ static int f2fs_setflags_common(struct inode *inode, u32 iflags, u32 mask)
 	struct f2fs_inode_info *fi = F2FS_I(inode);
 	u32 masked_flags = fi->i_flags & mask;
 
-	f2fs_bug_on(F2FS_I_SB(inode), (iflags & ~mask));
+	/* mask can be shrunk by flags_valid selector */
+	iflags &= mask;
 
 	/* Is it quota file? Do not allow user to mess with it */
 	if (IS_NOQUOTA(inode))
-- 
2.31.1.607.g51e8a6a459-goog


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [f2fs-dev] [PATCH v2] f2fs: support iflag change given the mask
  2021-05-10 14:42 ` [PATCH v2] f2fs: support iflag change given the mask Jaegeuk Kim
@ 2021-05-10 22:28   ` Eric Biggers
  2021-05-11  0:21     ` Jaegeuk Kim
  2021-05-11  1:43   ` Chao Yu
  1 sibling, 1 reply; 7+ messages in thread
From: Eric Biggers @ 2021-05-10 22:28 UTC (permalink / raw)
  To: Jaegeuk Kim; +Cc: linux-kernel, linux-f2fs-devel

On Mon, May 10, 2021 at 07:42:27AM -0700, Jaegeuk Kim wrote:
> In f2fs_fileattr_set(),
> 
> 	if (!fa->flags_valid)
> 		mask &= FS_COMMON_FL;
> 
> In this case, we can set supported flags by mask only instead of BUG_ON.
> 
> /* Flags shared betwen flags/xflags */
> 	(FS_SYNC_FL | FS_IMMUTABLE_FL | FS_APPEND_FL | \
> 	 FS_NODUMP_FL |	FS_NOATIME_FL | FS_DAX_FL | \
> 	 FS_PROJINHERIT_FL)
> 
> Fixes: 4c5b47997521 ("vfs: add fileattr ops")

Shouldn't it be:

Fixes: 9b1bb01c8ae7 ("f2fs: convert to fileattr")

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [f2fs-dev] [PATCH v2] f2fs: support iflag change given the mask
  2021-05-10 22:28   ` [f2fs-dev] " Eric Biggers
@ 2021-05-11  0:21     ` Jaegeuk Kim
  0 siblings, 0 replies; 7+ messages in thread
From: Jaegeuk Kim @ 2021-05-11  0:21 UTC (permalink / raw)
  To: Eric Biggers; +Cc: linux-kernel, linux-f2fs-devel

On 05/10, Eric Biggers wrote:
> On Mon, May 10, 2021 at 07:42:27AM -0700, Jaegeuk Kim wrote:
> > In f2fs_fileattr_set(),
> > 
> > 	if (!fa->flags_valid)
> > 		mask &= FS_COMMON_FL;
> > 
> > In this case, we can set supported flags by mask only instead of BUG_ON.
> > 
> > /* Flags shared betwen flags/xflags */
> > 	(FS_SYNC_FL | FS_IMMUTABLE_FL | FS_APPEND_FL | \
> > 	 FS_NODUMP_FL |	FS_NOATIME_FL | FS_DAX_FL | \
> > 	 FS_PROJINHERIT_FL)
> > 
> > Fixes: 4c5b47997521 ("vfs: add fileattr ops")
> 
> Shouldn't it be:
> 
> Fixes: 9b1bb01c8ae7 ("f2fs: convert to fileattr")

Heh, thank you. I applied this change in the git. :)

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [f2fs-dev] [PATCH v2] f2fs: support iflag change given the mask
  2021-05-10 14:42 ` [PATCH v2] f2fs: support iflag change given the mask Jaegeuk Kim
  2021-05-10 22:28   ` [f2fs-dev] " Eric Biggers
@ 2021-05-11  1:43   ` Chao Yu
  1 sibling, 0 replies; 7+ messages in thread
From: Chao Yu @ 2021-05-11  1:43 UTC (permalink / raw)
  To: Jaegeuk Kim, linux-kernel, linux-f2fs-devel

On 2021/5/10 22:42, Jaegeuk Kim wrote:
> In f2fs_fileattr_set(),
> 
> 	if (!fa->flags_valid)
> 		mask &= FS_COMMON_FL;
> 
> In this case, we can set supported flags by mask only instead of BUG_ON.
> 
> /* Flags shared betwen flags/xflags */
> 	(FS_SYNC_FL | FS_IMMUTABLE_FL | FS_APPEND_FL | \
> 	 FS_NODUMP_FL |	FS_NOATIME_FL | FS_DAX_FL | \
> 	 FS_PROJINHERIT_FL)
> 
> Fixes: 4c5b47997521 ("vfs: add fileattr ops")
> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>

Except fixes line issue pointed out by Eric, other part looks good
to me.

Reviewed-by: Chao Yu <yuchao0@huawei.com>

Thanks,

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-05-11  1:43 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-06 19:13 [PATCH] f2fs: return -EPERM given generic mask Jaegeuk Kim
2021-05-07  6:26 ` [f2fs-dev] " Eric Biggers
2021-05-10 14:39   ` Jaegeuk Kim
2021-05-10 14:42 ` [PATCH v2] f2fs: support iflag change given the mask Jaegeuk Kim
2021-05-10 22:28   ` [f2fs-dev] " Eric Biggers
2021-05-11  0:21     ` Jaegeuk Kim
2021-05-11  1:43   ` Chao Yu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).