Skip to contentSkip to conversation

vfs: only allow SETFLAGS to set DAX flag on files and dirs

PATCH Superseded Jeffle Xu 2 participants 3 messages Jul 16, 2021 – Jul 19, 2021

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Jeffle Xu

author
#0 lore raw

PATCH 1/1 vfs: only allow SETFLAGS to set DAX flag on files and dirs

This is similar to commit dbc77f31e58b ("vfs: only allow FSSETXATTR to set DAX flag on files and dirs").

Though the underlying filesystems may have filtered invalid flags, e.g., ext4_mask_flags() called in ext4_fileattr_set(), also check it in VFS layer.

---
 fs/ioctl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ioctl.c +1 -1
index 1e2204fa9963..1fe73e148e2d 100644
@@ -835,7 +835,7 @@ static int fileattr_set_prepare(struct inode *inode,
 	 * It is only valid to set the DAX flag on regular files and
 	 * directories on filesystems.
 	 */
-	if ((fa->fsx_xflags & FS_XFLAG_DAX) &&
+	if ((fa->fsx_xflags & FS_XFLAG_DAX || fa->flags & FS_DAX_FL) &&
 	    !(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode)))
 		return -EINVAL;
 
Signature · 1 line
2.27.0
#1 lore raw
Quoted 17 lines · Jeffle Xu

This is similar to commit dbc77f31e58b ("vfs: only allow FSSETXATTR to set DAX flag on files and dirs").

Though the underlying filesystems may have filtered invalid flags, e.g., ext4_mask_flags() called in ext4_fileattr_set(), also check it in VFS layer.

---
 fs/ioctl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ioctl.c +0 -0
index 1e2204fa9963..1fe73e148e2d 100644

fs/ioctl.c static int fileattr_set_prepare(struct inode *inode, · line 838

Quoted 5 lines
fs/ioctl.c +1 -1
@@ -835,7 +835,7 @@ static int fileattr_set_prepare(struct inode *inode,
 	 * It is only valid to set the DAX flag on regular files and
 	 * directories on filesystems.
 	 */
-	if ((fa->fsx_xflags & FS_XFLAG_DAX) &&
+	if ((fa->fsx_xflags & FS_XFLAG_DAX || fa->flags & FS_DAX_FL) &&

I thought we always had to surround flag tests with separate parentheses...?

--D

Quoted 6 lines
fs/ioctl.c +0 -0
 	    !(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode)))
 		return -EINVAL;
 
Signature · 1 line
2.27.0
author
#2 lore raw
Quoted 13 lines · Darrick J. Wong
Quoted 12 lines · Jeffle Xu

This is similar to commit dbc77f31e58b ("vfs: only allow FSSETXATTR to set DAX flag on files and dirs").

Though the underlying filesystems may have filtered invalid flags, e.g., ext4_mask_flags() called in ext4_fileattr_set(), also check it in VFS layer.

---
 fs/ioctl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 13 lines

fs/ioctl.c static int fileattr_set_prepare(struct inode *inode, · line 838

Quoted 10 lines
fs/ioctl.c +1 -1
index 1e2204fa9963..1fe73e148e2d 100644
@@ -835,7 +835,7 @@ static int fileattr_set_prepare(struct inode *inode,
 	 * It is only valid to set the DAX flag on regular files and
 	 * directories on filesystems.
 	 */
-	if ((fa->fsx_xflags & FS_XFLAG_DAX) &&
+	if ((fa->fsx_xflags & FS_XFLAG_DAX || fa->flags & FS_DAX_FL) &&

I thought we always had to surround flag tests with separate parentheses...?

Thanks.

The 'bitwise and' has a higher priority than 'logical or'. But for sure I can add parentheses to make it more readable and precise.

Signature · 2 lines
Thanks,
Jeffle