Skip to contentSkip to conversation

f2fs: return -EPERM given generic mask

PATCH In review Jaegeuk Kim 3 participants 7 messages May 6, 2021 – May 11, 2021 F2FS file system

lore
Share & tools
lore

Jaegeuk Kim

author maintainer
#0 lore raw

PATCH 1/1 f2fs: return -EPERM given generic mask

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")
---
 fs/f2fs/file.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/f2fs/file.c +3 -1
index e01ce802cf10..38015ef84893 100644
@@ -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))
Signature · 1 line
2.31.1.607.g51e8a6a459-goog
#1 lore raw
Quoted 35 lines · 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")
---
 fs/f2fs/file.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/f2fs/file.c +3 -1
index e01ce802cf10..38015ef84893 100644
@@ -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))
Signature · 1 line
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

author maintainer
#2 lore raw
Quoted 44 lines · Eric Biggers
Quoted 35 lines · 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")
---
 fs/f2fs/file.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/f2fs/file.c +3 -1
index e01ce802cf10..38015ef84893 100644
@@ -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))
Signature · 1 line
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.

Quoted 1 line

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

Thanks. Let me send v2.

Quoted 2 lines

- Eric

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

author maintainer
#3 lore raw

Re: [PATCH v2] f2fs: support iflag change given the mask

In reply to Jaegeuk Kim

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")
---
 fs/f2fs/file.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/f2fs/file.c +2 -1
index 44a4650aea7b..ceb575f99048 100644
@@ -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))
Signature · 8 lines
2.31.1.607.g51e8a6a459-goog



_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
#4 lore raw

Re: [f2fs-dev] [PATCH v2] f2fs: support iflag change given the mask

Quoted 5 lines · Jaegeuk Kim

In f2fs_fileattr_set(),

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

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")
author maintainer
#5 lore raw

Re: [f2fs-dev] [PATCH v2] f2fs: support iflag change given the mask

Quoted 13 lines · Eric Biggers
Quoted 12 lines · Jaegeuk Kim

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)
Quoted 5 lines
Quoted 1 line
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. :)

Reviewed-by
#6 lore raw

Re: [f2fs-dev] [PATCH v2] f2fs: support iflag change given the mask

In reply to Jaegeuk Kim
Quoted 7 lines · Jaegeuk Kim

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.

Quoted 7 lines

/* 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")

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

Thanks,