Skip to content

Commit 276e136

Browse files
amir73ilbrauner
authored andcommitted
fs: prepare for extending file_get/setattr()
We intend to add support for more xflags to selective filesystems and We cannot rely on copy_struct_from_user() to detect this extension. In preparation of extending the API, do not allow setting xflags unknown by this kernel version. Also do not pass the read-only flags and read-only field fsx_nextents to filesystem. These changes should not affect existing chattr programs that use the ioctl to get fsxattr before setting the new values. Link: https://lore.kernel.org/linux-fsdevel/[email protected]/ Cc: Pali Rohár <[email protected]> Cc: Andrey Albershteyn <[email protected]> Signed-off-by: Amir Goldstein <[email protected]> Signed-off-by: Andrey Albershteyn <[email protected]> Link: https://lore.kernel.org/[email protected] Reviewed-by: Jan Kara <[email protected]> Signed-off-by: Christian Brauner <[email protected]>
1 parent 474b155 commit 276e136

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

fs/file_attr.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,10 @@ EXPORT_SYMBOL(vfs_fileattr_get);
100100
int copy_fsxattr_to_user(const struct fileattr *fa, struct fsxattr __user *ufa)
101101
{
102102
struct fsxattr xfa;
103+
__u32 mask = FS_XFLAGS_MASK;
103104

104105
memset(&xfa, 0, sizeof(xfa));
105-
xfa.fsx_xflags = fa->fsx_xflags;
106+
xfa.fsx_xflags = fa->fsx_xflags & mask;
106107
xfa.fsx_extsize = fa->fsx_extsize;
107108
xfa.fsx_nextents = fa->fsx_nextents;
108109
xfa.fsx_projid = fa->fsx_projid;
@@ -119,11 +120,16 @@ static int copy_fsxattr_from_user(struct fileattr *fa,
119120
struct fsxattr __user *ufa)
120121
{
121122
struct fsxattr xfa;
123+
__u32 mask = FS_XFLAGS_MASK;
122124

123125
if (copy_from_user(&xfa, ufa, sizeof(xfa)))
124126
return -EFAULT;
125127

128+
if (xfa.fsx_xflags & ~mask)
129+
return -EOPNOTSUPP;
130+
126131
fileattr_fill_xflags(fa, xfa.fsx_xflags);
132+
fa->fsx_xflags &= ~FS_XFLAG_RDONLY_MASK;
127133
fa->fsx_extsize = xfa.fsx_extsize;
128134
fa->fsx_nextents = xfa.fsx_nextents;
129135
fa->fsx_projid = xfa.fsx_projid;

include/linux/fileattr.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,26 @@
1414
FS_XFLAG_NODUMP | FS_XFLAG_NOATIME | FS_XFLAG_DAX | \
1515
FS_XFLAG_PROJINHERIT)
1616

17+
/* Read-only inode flags */
18+
#define FS_XFLAG_RDONLY_MASK \
19+
(FS_XFLAG_PREALLOC | FS_XFLAG_HASATTR)
20+
21+
/* Flags to indicate valid value of fsx_ fields */
22+
#define FS_XFLAG_VALUES_MASK \
23+
(FS_XFLAG_EXTSIZE | FS_XFLAG_COWEXTSIZE)
24+
25+
/* Flags for directories */
26+
#define FS_XFLAG_DIRONLY_MASK \
27+
(FS_XFLAG_RTINHERIT | FS_XFLAG_NOSYMLINKS | FS_XFLAG_EXTSZINHERIT)
28+
29+
/* Misc settable flags */
30+
#define FS_XFLAG_MISC_MASK \
31+
(FS_XFLAG_REALTIME | FS_XFLAG_NODEFRAG | FS_XFLAG_FILESTREAM)
32+
33+
#define FS_XFLAGS_MASK \
34+
(FS_XFLAG_COMMON | FS_XFLAG_RDONLY_MASK | FS_XFLAG_VALUES_MASK | \
35+
FS_XFLAG_DIRONLY_MASK | FS_XFLAG_MISC_MASK)
36+
1737
/*
1838
* Merged interface for miscellaneous file attributes. 'flags' originates from
1939
* ext* and 'fsx_flags' from xfs. There's some overlap between the two, which

0 commit comments

Comments
 (0)