fs: introduce file_getattr and file_setattr syscalls
Subsystems (40)
v6 cover fs: introduce file_getattr and file_setattr syscalls
This patchset introduced two new syscalls file_getattr() and file_setattr(). These syscalls are similar to FS_IOC_FSSETXATTR ioctl() except they use *at() semantics. Therefore, there's no need to open the file to get a fd.
These syscalls allow userspace to set filesystem inode attributes on special files. One of the usage examples is XFS quota projects.
XFS has project quotas which could be attached to a directory. All new inodes in these directories inherit project ID set on parent directory.
The project is created from userspace by opening and calling FS_IOC_FSSETXATTR on each inode. This is not possible for special files such as FIFO, SOCK, BLK etc. Therefore, some inodes are left with empty project ID. Those inodes then are not shown in the quota accounting but still exist in the directory. This is not critical but in the case when special files are created in the directory with already existing project quota, these new inodes inherit extended attributes. This creates a mix of special files with and without attributes. Moreover, special files with attributes don't have a possibility to become clear or change the attributes. This, in turn, prevents userspace from re-creating quota project on these existing files.
An xfstests test generic/766 with basic coverage is at:
https://github.com/alberand/xfstests/commits/b4/file-attr/
NAME
file_getattr/file_setattr - get/set filesystem inode attributes
SYNOPSIS
#include <sys/syscall.h> /* Definition of SYS_* constants */
#include <unistd.h>
long syscall(SYS_file_getattr, int dirfd, const char *pathname,
struct fsx_fileattr *fsx, size_t size, unsigned int at_flags);
long syscall(SYS_file_setattr, int dirfd, const char *pathname,
struct fsx_fileattr *fsx, size_t size, unsigned int at_flags);
Note: glibc doesn't provide for file_getattr()/file_setattr(), use syscall(2) instead.
DESCRIPTION
The file_getattr()/file_setattr() are used to set extended file attributes. These syscalls take dirfd in conjunction with the pathname argument. The syscall then operates on inode opened according to openat(2) semantics.
This is an alternative to FS_IOC_FSGETXATTR/FS_IOC_FSSETXATTR ioctl with a difference that file don't need to be open as file can be referenced with a path instead of fd. By having this one can manipulated filesystem inode attributes not only on regular files but also on special ones. This is not possible with FS_IOC_FSSETXATTR ioctl as ioctl() can not be called on special files directly for the filesystem inode.
at_flags can be set to AT_SYMLINK_NOFOLLOW or AT_EMPTY_PATH.
RETURN VALUE
On success, 0 is returned. On error, -1 is returned, and errno is set to indicate the error.
ERRORS
EINVAL Invalid at_flag specified (only
AT_SYMLINK_NOFOLLOW and AT_EMPTY_PATH is supported).
EINVAL Size was smaller than any known version of
struct fsx_fileattr.
EINVAL Invalid combination of parameters provided in
fsx_fileattr for this type of file.
E2BIG Size of input argument struct fsx_fileattr
is too big.
EBADF Invalid file descriptor was provided.
EPERM No permission to change this file.
EOPNOTSUPP Filesystem does not support setting attributes
on this type of inode
HISTORY
Added in Linux 6.16.
EXAMPLE
Create directory and file "mkdir ./dir && touch ./dir/foo" and then execute the following program:
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include <linux/fs.h>
#include <stdio.h>
#include <sys/syscall.h>
#include <unistd.h>
#if !defined(SYS_file_getattr) && defined(__x86_64__)
#define SYS_file_getattr 468
#define SYS_file_setattr 469
struct fsx_fileattr {
__u32 fsx_xflags;
__u32 fsx_extsize;
__u32 fsx_nextents;
__u32 fsx_projid;
__u32 fsx_cowextsize;
};
#endif
int
main(int argc, char **argv) {
int dfd;
int error;
struct fsx_fileattr fsx;
dfd = open("./dir", O_RDONLY);
if (dfd == -1) {
printf("can not open ./dir");
return dfd;
}
error = syscall(SYS_file_getattr, dfd, "./foo", &fsx,
sizeof(struct fsx_fileattr), 0);
if (error) {
printf("can not call SYS_file_getattr: %s",
strerror(errno));
return error;
}
printf("./dir/foo flags: %d\n", fsx.fsx_xflags);
fsx.fsx_xflags |= FS_XFLAG_NODUMP;
error = syscall(SYS_file_setattr, dfd, "./foo", &fsx,
sizeof(struct fsx_fileattr), 0);
if (error) {
printf("can not call SYS_file_setattr: %s",
strerror(errno));
return error;
}
printf("./dir/foo flags: %d\n", fsx.fsx_xflags);
return error;
}SEE ALSO
ioctl(2), ioctl_iflags(2), ioctl_xfs_fsgetxattr(2), openat(2)
---
Changes in v6:
- Update cover letter example and docs
- Applied __free() attribute for syscall stack objects
- Introduced struct fsx_fileattr
- Replace 'struct fsxattr' with 'struct fsx_fileattr'
- Add helper to fill in fsx_fileattr from fileattr
- Dropped copy_fsx_to_user() header declaration
- Link to v5: https://lore.kernel.org/r/[email protected]
Changes in v5:
- Remove setting of LOOKUP_EMPTY flags which does not have any effect
- Return -ENOSUPP from vfs_fileattr_set()
- Add fsxattr masking (by Amir)
- Fix UAF issue dentry
- Fix getname_maybe_null() issue with NULL path
- Implement file_getattr/file_setattr hooks
- Return LSM return code from file_setattr
- Rename from getfsxattrat/setfsxattrat to file_getattr/file_setattr
- Link to v4: https://lore.kernel.org/r/[email protected]
Changes in v4:
- Use getname_maybe_null() for correct handling of dfd + path semantic
- Remove restriction for special files on which flags are allowed
- Utilize copy_struct_from_user() for better future compatibility
- Add draft man page to cover letter
- Convert -ENOIOCTLCMD to -EOPNOSUPP as more appropriate for syscall
- Add missing __user to header declaration of syscalls
- Link to v3: https://lore.kernel.org/r/[email protected]
Changes in v3:
- Remove unnecessary "dfd is dir" check as it checked in user_path_at()
- Remove unnecessary "same filesystem" check
- Use CLASS() instead of directly calling fdget/fdput
- Link to v2: https://lore.kernel.org/r/[email protected]
v1:
https://lore.kernel.org/linuxppc-dev/[email protected]/
Previous discussion:
https://lore.kernel.org/linux-xfs/[email protected]/
---
Amir Goldstein (1):
fs: prepare for extending file_get/setattr()
Andrey Albershteyn (5):
fs: split fileattr related helpers into separate file
lsm: introduce new hooks for setting/getting inode fsxattr
selinux: implement inode_file_[g|s]etattr hooks
fs: make vfs_fileattr_[get|set] return -EOPNOSUPP
fs: introduce file_getattr and file_setattr syscalls
arch/alpha/kernel/syscalls/syscall.tbl | 2 + arch/arm/tools/syscall.tbl | 2 + arch/arm64/tools/syscall_32.tbl | 2 + arch/m68k/kernel/syscalls/syscall.tbl | 2 + arch/microblaze/kernel/syscalls/syscall.tbl | 2 + arch/mips/kernel/syscalls/syscall_n32.tbl | 2 + arch/mips/kernel/syscalls/syscall_n64.tbl | 2 + arch/mips/kernel/syscalls/syscall_o32.tbl | 2 + arch/parisc/kernel/syscalls/syscall.tbl | 2 + arch/powerpc/kernel/syscalls/syscall.tbl | 2 + arch/s390/kernel/syscalls/syscall.tbl | 2 + arch/sh/kernel/syscalls/syscall.tbl | 2 + arch/sparc/kernel/syscalls/syscall.tbl | 2 + arch/x86/entry/syscalls/syscall_32.tbl | 2 + arch/x86/entry/syscalls/syscall_64.tbl | 2 + arch/xtensa/kernel/syscalls/syscall.tbl | 2 + fs/Makefile | 3 +- fs/ecryptfs/inode.c | 8 +- fs/file_attr.c | 493 ++++++++++++++++++++++++++++ fs/ioctl.c | 309 ----------------- fs/overlayfs/inode.c | 2 +- include/linux/fileattr.h | 24 ++ include/linux/lsm_hook_defs.h | 2 + include/linux/security.h | 16 + include/linux/syscalls.h | 6 + include/uapi/asm-generic/unistd.h | 8 +- include/uapi/linux/fs.h | 18 + scripts/syscall.tbl | 2 + security/security.c | 30 ++ security/selinux/hooks.c | 14 + 30 files changed, 654 insertions(+), 313 deletions(-)
---
base-commit: d0b3b7b22dfa1f4b515fd3a295b3fd958f9e81af
change-id: 20250114-xattrat-syscall-6a1136d2db59
Best regards,
Signature · 1 line
Andrey Albershteyn <[email protected]>
PATCH v6 1/6 fs: split fileattr related helpers into separate file
From: Andrey Albershteyn <[email protected]>
This patch moves function related to file extended attributes manipulations to separate file. Refactoring only.
--- fs/Makefile | 3 +- fs/file_attr.c | 318 +++++++++++++++++++++++++++++++++++++++++++++++ fs/ioctl.c | 309 --------------------------------------------- include/linux/fileattr.h | 4 + 4 files changed, 324 insertions(+), 310 deletions(-)
fs/Makefile +2 -1
@@ -15,7 +15,8 @@ obj-y := open.o read_write.o file_table.o super.o \ pnode.o splice.o sync.o utimes.o d_path.o \ stack.o fs_struct.o statfs.o fs_pin.o nsfs.o \ fs_types.o fs_context.o fs_parser.o fsopen.o init.o \ - kernel_read_file.o mnt_idmapping.o remap_range.o pidfs.o + kernel_read_file.o mnt_idmapping.o remap_range.o pidfs.o \ + file_attr.o obj-$(CONFIG_BUFFER_HEAD) += buffer.o mpage.o obj-$(CONFIG_PROC_FS) += proc_namespace.o
fs/file_attr.c new file +318 -0
318 lines not on this page · raw message
fs/ioctl.c +0 -309
315 lines not on this page · raw message
include/linux/fileattr.h +4 -0
@@ -55,5 +55,9 @@ static inline bool fileattr_has_fsx(const struct fileattr *fa)int vfs_fileattr_get (struct dentry *dentry,struct fileattr *fa);int vfs_fileattr_set (struct mnt_idmap *idmap,struct dentry *dentry,struct fileattr *fa); +int ioctl_getflags (struct file *file,unsigned int __user *argp); +int ioctl_setflags (struct file *file,unsigned int __user *argp); +int ioctl_fsgetxattr (struct file *file,void __user *argp); +int ioctl_fssetxattr (struct file *file,void __user *argp);#endif /* _LINUX_FILEATTR_H */
Signature · 1 line
2.47.2
Re: [PATCH v6 1/6] fs: split fileattr related helpers into separate file
Quoted 7 lines · Andrey Albershteyn
From: Andrey Albershteyn <[email protected]>
This patch moves function related to file extended attributes manipulations to separate file. Refactoring only.
Signed-off-by Andrey Albershteyn <[email protected]>
Quoted 683 lines
--- fs/Makefile | 3 +- fs/file_attr.c | 318 +++++++++++++++++++++++++++++++++++++++++++++++ fs/ioctl.c | 309 --------------------------------------------- include/linux/fileattr.h | 4 + 4 files changed, 324 insertions(+), 310 deletions(-)fs/Makefile +2
-1@@ -15,7 +15,8 @@ obj-y := open.o read_write.o file_table.o super.o \ pnode.o splice.o sync.o utimes.o d_path.o \ stack.o fs_struct.o statfs.o fs_pin.o nsfs.o \ fs_types.o fs_context.o fs_parser.o fsopen.o init.o \ - kernel_read_file.o mnt_idmapping.o remap_range.o pidfs.o + kernel_read_file.o mnt_idmapping.o remap_range.o pidfs.o \ + file_attr.o obj-$(CONFIG_BUFFER_HEAD) += buffer.o mpage.o obj-$(CONFIG_PROC_FS) += proc_namespace.ofs/file_attr.c new file +318
-0@@ -0,0 +1,318 @@ +// SPDX-License-Identifier: GPL-2.0 +#include <linux/fs.h> +#include <linux/security.h> +#include <linux/fscrypt.h> +#include <linux/fileattr.h> + +/** +* fileattr_fill_xflags - initialize fileattr with xflags +* @fa: fileattr pointer +* @xflags: FS_XFLAG_* flags +* +* Set ->fsx_xflags, ->fsx_valid and ->flags (translated xflags). All +* other fields are zeroed. +*/ +void fileattr_fill_xflags (struct fileattr *fa,u32 xflags) +{ +memset (fa,0 ,sizeof (*fa)); + fa->fsx_valid = true; + fa->fsx_xflags = xflags; +if (fa->fsx_xflags &FS_XFLAG_IMMUTABLE ) + fa->flags |=FS_IMMUTABLE_FL ; +if (fa->fsx_xflags &FS_XFLAG_APPEND ) + fa->flags |=FS_APPEND_FL ; +if (fa->fsx_xflags &FS_XFLAG_SYNC ) + fa->flags |=FS_SYNC_FL ; +if (fa->fsx_xflags &FS_XFLAG_NOATIME ) + fa->flags |=FS_NOATIME_FL ; +if (fa->fsx_xflags &FS_XFLAG_NODUMP ) + fa->flags |=FS_NODUMP_FL ; +if (fa->fsx_xflags &FS_XFLAG_DAX ) + fa->flags |=FS_DAX_FL ; +if (fa->fsx_xflags &FS_XFLAG_PROJINHERIT ) + fa->flags |=FS_PROJINHERIT_FL ; +} +EXPORT_SYMBOL (fileattr_fill_xflags); + +/** +* fileattr_fill_flags - initialize fileattr with flags +* @fa: fileattr pointer +* @flags: FS_*_FL flags +* +* Set ->flags, ->flags_valid and ->fsx_xflags (translated flags). +* All other fields are zeroed. +*/ +void fileattr_fill_flags (struct fileattr *fa,u32 flags) +{ +memset (fa,0 ,sizeof (*fa)); + fa->flags_valid = true; + fa->flags = flags; +if (fa->flags &FS_SYNC_FL ) + fa->fsx_xflags |=FS_XFLAG_SYNC ; +if (fa->flags &FS_IMMUTABLE_FL ) + fa->fsx_xflags |=FS_XFLAG_IMMUTABLE ; +if (fa->flags &FS_APPEND_FL ) + fa->fsx_xflags |=FS_XFLAG_APPEND ; +if (fa->flags &FS_NODUMP_FL ) + fa->fsx_xflags |=FS_XFLAG_NODUMP ; +if (fa->flags &FS_NOATIME_FL ) + fa->fsx_xflags |=FS_XFLAG_NOATIME ; +if (fa->flags &FS_DAX_FL ) + fa->fsx_xflags |=FS_XFLAG_DAX ; +if (fa->flags &FS_PROJINHERIT_FL ) + fa->fsx_xflags |=FS_XFLAG_PROJINHERIT ; +} +EXPORT_SYMBOL (fileattr_fill_flags); + +/** +* vfs_fileattr_get - retrieve miscellaneous file attributes +* @dentry: the object to retrieve from +* @fa: fileattr pointer +* +* Call i_op->fileattr_get() callback, if exists. +* +* Return: 0 on success, or a negative error on failure. +*/ +int vfs_fileattr_get (struct dentry *dentry,struct fileattr *fa) +{ +struct inode *inode =d_inode (dentry); + +if (!inode->i_op->fileattr_get) +return -ENOIOCTLCMD ; + +return inode->i_op->fileattr_get (dentry, fa); +} +EXPORT_SYMBOL (vfs_fileattr_get); + +/** +* copy_fsxattr_to_user - copy fsxattr to userspace. +* @fa: fileattr pointer +* @ufa: fsxattr user pointer +* +* Return: 0 on success, or -EFAULT on failure. +*/ +int copy_fsxattr_to_user (const struct fileattr *fa,struct fsxattr __user *ufa) +{ +struct fsxattr xfa; + +memset (&xfa,0 ,sizeof (xfa)); + xfa.fsx_xflags = fa->fsx_xflags; + xfa.fsx_extsize = fa->fsx_extsize; + xfa.fsx_nextents = fa->fsx_nextents; + xfa.fsx_projid = fa->fsx_projid; + xfa.fsx_cowextsize = fa->fsx_cowextsize; + +if (copy_to_user (ufa, &xfa,sizeof (xfa))) +return -EFAULT ; + +return 0 ; +} +EXPORT_SYMBOL (copy_fsxattr_to_user); + +static int copy_fsxattr_from_user (struct fileattr *fa, +struct fsxattr __user *ufa) +{ +struct fsxattr xfa; + +if (copy_from_user (&xfa, ufa,sizeof (xfa))) +return -EFAULT ; + +fileattr_fill_xflags (fa, xfa.fsx_xflags); + fa->fsx_extsize = xfa.fsx_extsize; + fa->fsx_nextents = xfa.fsx_nextents; + fa->fsx_projid = xfa.fsx_projid; + fa->fsx_cowextsize = xfa.fsx_cowextsize; + +return 0 ; +} + +/* +* Generic function to check FS_IOC_FSSETXATTR/FS_IOC_SETFLAGS values and reject +* any invalid configurations. +* +* Note: must be called with inode lock held. +*/ +static int fileattr_set_prepare (struct inode *inode, +const struct fileattr *old_ma, +struct fileattr *fa) +{ +int err; + +/* +* The IMMUTABLE and APPEND_ONLY flags can only be changed by +* the relevant capability. +*/ +if ((fa->flags ^ old_ma->flags) & (FS_APPEND_FL |FS_IMMUTABLE_FL ) && + !capable (CAP_LINUX_IMMUTABLE )) +return -EPERM ; + + err =fscrypt_prepare_setflags (inode, old_ma->flags, fa->flags); +if (err) +return err; + +/* +* Project Quota ID state is only allowed to change from within the init +* namespace. Enforce that restriction only if we are trying to change +* the quota ID state. Everything else is allowed in user namespaces. +*/ +if (current_user_ns () != &init_user_ns) { +if (old_ma->fsx_projid != fa->fsx_projid) +return -EINVAL ; +if ((old_ma->fsx_xflags ^ fa->fsx_xflags) & +FS_XFLAG_PROJINHERIT ) +return -EINVAL ; + }else { +/* +* Caller is allowed to change the project ID. If it is being +* changed, make sure that the new value is valid. +*/ +if (old_ma->fsx_projid != fa->fsx_projid && + !projid_valid (make_kprojid (&init_user_ns, fa->fsx_projid))) +return -EINVAL ; + } + +/* Check extent size hints. */ +if ((fa->fsx_xflags &FS_XFLAG_EXTSIZE ) && !S_ISREG (inode->i_mode)) +return -EINVAL ; + +if ((fa->fsx_xflags &FS_XFLAG_EXTSZINHERIT ) && + !S_ISDIR (inode->i_mode)) +return -EINVAL ; + +if ((fa->fsx_xflags &FS_XFLAG_COWEXTSIZE ) && + !S_ISREG (inode->i_mode) && !S_ISDIR (inode->i_mode)) +return -EINVAL ; + +/* +* It is only valid to set the DAX flag on regular files and +* directories on filesystems. +*/ +if ((fa->fsx_xflags &FS_XFLAG_DAX ) && + !(S_ISREG (inode->i_mode) ||S_ISDIR (inode->i_mode))) +return -EINVAL ; + +/* Extent size hints of zero turn off the flags. */ +if (fa->fsx_extsize ==0 ) + fa->fsx_xflags &= ~(FS_XFLAG_EXTSIZE |FS_XFLAG_EXTSZINHERIT ); +if (fa->fsx_cowextsize ==0 ) + fa->fsx_xflags &= ~FS_XFLAG_COWEXTSIZE ; + +return 0 ; +} + +/** +* vfs_fileattr_set - change miscellaneous file attributes +* @idmap: idmap of the mount +* @dentry: the object to change +* @fa: fileattr pointer +* +* After verifying permissions, call i_op->fileattr_set() callback, if +* exists. +* +* Verifying attributes involves retrieving current attributes with +* i_op->fileattr_get(), this also allows initializing attributes that have +* not been set by the caller to current values. Inode lock is held +* thoughout to prevent racing with another instance. +* +* Return: 0 on success, or a negative error on failure. +*/ +int vfs_fileattr_set (struct mnt_idmap *idmap,struct dentry *dentry, +struct fileattr *fa) +{ +struct inode *inode =d_inode (dentry); +struct fileattr old_ma = {}; +int err; + +if (!inode->i_op->fileattr_set) +return -ENOIOCTLCMD ; + +if (!inode_owner_or_capable (idmap, inode)) +return -EPERM ; + +inode_lock (inode); + err =vfs_fileattr_get (dentry, &old_ma); +if (!err) { +/* initialize missing bits from old_ma */ +if (fa->flags_valid) { + fa->fsx_xflags |= old_ma.fsx_xflags & ~FS_XFLAG_COMMON ; + fa->fsx_extsize = old_ma.fsx_extsize; + fa->fsx_nextents = old_ma.fsx_nextents; + fa->fsx_projid = old_ma.fsx_projid; + fa->fsx_cowextsize = old_ma.fsx_cowextsize; + }else { + fa->flags |= old_ma.flags & ~FS_COMMON_FL ; + } + err =fileattr_set_prepare (inode, &old_ma, fa); +if (!err) + err = inode->i_op->fileattr_set (idmap, dentry, fa); + } +inode_unlock (inode); + +return err; +} +EXPORT_SYMBOL (vfs_fileattr_set); + +int ioctl_getflags (struct file *file,unsigned int __user *argp) +{ +struct fileattr fa = { .flags_valid = true };/* hint only */ +int err; + + err =vfs_fileattr_get (file->f_path.dentry, &fa); +if (!err) + err =put_user (fa.flags, argp); +return err; +} +EXPORT_SYMBOL (ioctl_getflags); + +int ioctl_setflags (struct file *file,unsigned int __user *argp) +{ +struct mnt_idmap *idmap =file_mnt_idmap (file); +struct dentry *dentry = file->f_path.dentry; +struct fileattr fa; +unsigned int flags; +int err; + + err =get_user (flags, argp); +if (!err) { + err =mnt_want_write_file (file); +if (!err) { +fileattr_fill_flags (&fa, flags); + err =vfs_fileattr_set (idmap, dentry, &fa); +mnt_drop_write_file (file); + } + } +return err; +} +EXPORT_SYMBOL (ioctl_setflags); + +int ioctl_fsgetxattr (struct file *file,void __user *argp) +{ +struct fileattr fa = { .fsx_valid = true };/* hint only */ +int err; + + err =vfs_fileattr_get (file->f_path.dentry, &fa); +if (!err) + err =copy_fsxattr_to_user (&fa, argp); + +return err; +} +EXPORT_SYMBOL (ioctl_fsgetxattr); + +int ioctl_fssetxattr (struct file *file,void __user *argp) +{ +struct mnt_idmap *idmap =file_mnt_idmap (file); +struct dentry *dentry = file->f_path.dentry; +struct fileattr fa; +int err; + + err =copy_fsxattr_from_user (&fa, argp); +if (!err) { + err =mnt_want_write_file (file); +if (!err) { + err =vfs_fileattr_set (idmap, dentry, &fa); +mnt_drop_write_file (file); + } + } +return err; +} +EXPORT_SYMBOL (ioctl_fssetxattr);fs/ioctl.c +0
-309@@ -453,315 +453,6 @@ static int ioctl_file_dedupe_range(struct file *file,return ret; } -/** -* fileattr_fill_xflags - initialize fileattr with xflags -* @fa: fileattr pointer -* @xflags: FS_XFLAG_* flags -* -* Set ->fsx_xflags, ->fsx_valid and ->flags (translated xflags). All -* other fields are zeroed. -*/ -void fileattr_fill_xflags (struct fileattr *fa,u32 xflags) -{ -memset (fa,0 ,sizeof (*fa)); - fa->fsx_valid = true; - fa->fsx_xflags = xflags; -if (fa->fsx_xflags &FS_XFLAG_IMMUTABLE ) - fa->flags |=FS_IMMUTABLE_FL ; -if (fa->fsx_xflags &FS_XFLAG_APPEND ) - fa->flags |=FS_APPEND_FL ; -if (fa->fsx_xflags &FS_XFLAG_SYNC ) - fa->flags |=FS_SYNC_FL ; -if (fa->fsx_xflags &FS_XFLAG_NOATIME ) - fa->flags |=FS_NOATIME_FL ; -if (fa->fsx_xflags &FS_XFLAG_NODUMP ) - fa->flags |=FS_NODUMP_FL ; -if (fa->fsx_xflags &FS_XFLAG_DAX ) - fa->flags |=FS_DAX_FL ; -if (fa->fsx_xflags &FS_XFLAG_PROJINHERIT ) - fa->flags |=FS_PROJINHERIT_FL ; -} -EXPORT_SYMBOL (fileattr_fill_xflags); - -/** -* fileattr_fill_flags - initialize fileattr with flags -* @fa: fileattr pointer -* @flags: FS_*_FL flags -* -* Set ->flags, ->flags_valid and ->fsx_xflags (translated flags). -* All other fields are zeroed. -*/ -void fileattr_fill_flags (struct fileattr *fa,u32 flags) -{ -memset (fa,0 ,sizeof (*fa)); - fa->flags_valid = true; - fa->flags = flags; -if (fa->flags &FS_SYNC_FL ) - fa->fsx_xflags |=FS_XFLAG_SYNC ; -if (fa->flags &FS_IMMUTABLE_FL ) - fa->fsx_xflags |=FS_XFLAG_IMMUTABLE ; -if (fa->flags &FS_APPEND_FL ) - fa->fsx_xflags |=FS_XFLAG_APPEND ; -if (fa->flags &FS_NODUMP_FL ) - fa->fsx_xflags |=FS_XFLAG_NODUMP ; -if (fa->flags &FS_NOATIME_FL ) - fa->fsx_xflags |=FS_XFLAG_NOATIME ; -if (fa->flags &FS_DAX_FL ) - fa->fsx_xflags |=FS_XFLAG_DAX ; -if (fa->flags &FS_PROJINHERIT_FL ) - fa->fsx_xflags |=FS_XFLAG_PROJINHERIT ; -} -EXPORT_SYMBOL (fileattr_fill_flags); - -/** -* vfs_fileattr_get - retrieve miscellaneous file attributes -* @dentry: the object to retrieve from -* @fa: fileattr pointer -* -* Call i_op->fileattr_get() callback, if exists. -* -* Return: 0 on success, or a negative error on failure. -*/ -int vfs_fileattr_get (struct dentry *dentry,struct fileattr *fa) -{ -struct inode *inode =d_inode (dentry); - -if (!inode->i_op->fileattr_get) -return -ENOIOCTLCMD ; - -return inode->i_op->fileattr_get (dentry, fa); -} -EXPORT_SYMBOL (vfs_fileattr_get); - -/** -* copy_fsxattr_to_user - copy fsxattr to userspace. -* @fa: fileattr pointer -* @ufa: fsxattr user pointer -* -* Return: 0 on success, or -EFAULT on failure. -*/ -int copy_fsxattr_to_user (const struct fileattr *fa,struct fsxattr __user *ufa) -{ -struct fsxattr xfa; - -memset (&xfa,0 ,sizeof (xfa)); - xfa.fsx_xflags = fa->fsx_xflags; - xfa.fsx_extsize = fa->fsx_extsize; - xfa.fsx_nextents = fa->fsx_nextents; - xfa.fsx_projid = fa->fsx_projid; - xfa.fsx_cowextsize = fa->fsx_cowextsize; - -if (copy_to_user (ufa, &xfa,sizeof (xfa))) -return -EFAULT ; - -return 0 ; -} -EXPORT_SYMBOL (copy_fsxattr_to_user); - -static int copy_fsxattr_from_user (struct fileattr *fa, -struct fsxattr __user *ufa) -{ -struct fsxattr xfa; - -if (copy_from_user (&xfa, ufa,sizeof (xfa))) -return -EFAULT ; - -fileattr_fill_xflags (fa, xfa.fsx_xflags); - fa->fsx_extsize = xfa.fsx_extsize; - fa->fsx_nextents = xfa.fsx_nextents; - fa->fsx_projid = xfa.fsx_projid; - fa->fsx_cowextsize = xfa.fsx_cowextsize; - -return 0 ; -} - -/* -* Generic function to check FS_IOC_FSSETXATTR/FS_IOC_SETFLAGS values and reject -* any invalid configurations. -* -* Note: must be called with inode lock held. -*/ -static int fileattr_set_prepare (struct inode *inode, -const struct fileattr *old_ma, -struct fileattr *fa) -{ -int err; - -/* -* The IMMUTABLE and APPEND_ONLY flags can only be changed by -* the relevant capability. -*/ -if ((fa->flags ^ old_ma->flags) & (FS_APPEND_FL |FS_IMMUTABLE_FL ) && - !capable (CAP_LINUX_IMMUTABLE )) -return -EPERM ; - - err =fscrypt_prepare_setflags (inode, old_ma->flags, fa->flags); -if (err) -return err; - -/* -* Project Quota ID state is only allowed to change from within the init -* namespace. Enforce that restriction only if we are trying to change -* the quota ID state. Everything else is allowed in user namespaces. -*/ -if (current_user_ns () != &init_user_ns) { -if (old_ma->fsx_projid != fa->fsx_projid) -return -EINVAL ; -if ((old_ma->fsx_xflags ^ fa->fsx_xflags) & -FS_XFLAG_PROJINHERIT ) -return -EINVAL ; - }else { -/* -* Caller is allowed to change the project ID. If it is being -* changed, make sure that the new value is valid. -*/ -if (old_ma->fsx_projid != fa->fsx_projid && - !projid_valid (make_kprojid (&init_user_ns, fa->fsx_projid))) -return -EINVAL ; - } - -/* Check extent size hints. */ -if ((fa->fsx_xflags &FS_XFLAG_EXTSIZE ) && !S_ISREG (inode->i_mode)) -return -EINVAL ; - -if ((fa->fsx_xflags &FS_XFLAG_EXTSZINHERIT ) && - !S_ISDIR (inode->i_mode)) -return -EINVAL ; - -if ((fa->fsx_xflags &FS_XFLAG_COWEXTSIZE ) && - !S_ISREG (inode->i_mode) && !S_ISDIR (inode->i_mode)) -return -EINVAL ; - -/* -* It is only valid to set the DAX flag on regular files and -* directories on filesystems. -*/ -if ((fa->fsx_xflags &FS_XFLAG_DAX ) && - !(S_ISREG (inode->i_mode) ||S_ISDIR (inode->i_mode))) -return -EINVAL ; - -/* Extent size hints of zero turn off the flags. */ -if (fa->fsx_extsize ==0 ) - fa->fsx_xflags &= ~(FS_XFLAG_EXTSIZE |FS_XFLAG_EXTSZINHERIT ); -if (fa->fsx_cowextsize ==0 ) - fa->fsx_xflags &= ~FS_XFLAG_COWEXTSIZE ; - -return 0 ; -} - -/** -* vfs_fileattr_set - change miscellaneous file attributes -* @idmap: idmap of the mount -* @dentry: the object to change -* @fa: fileattr pointer -* -* After verifying permissions, call i_op->fileattr_set() callback, if -* exists. -* -* Verifying attributes involves retrieving current attributes with -* i_op->fileattr_get(), this also allows initializing attributes that have -* not been set by the caller to current values. Inode lock is held -* thoughout to prevent racing with another instance. -* -* Return: 0 on success, or a negative error on failure. -*/ -int vfs_fileattr_set (struct mnt_idmap *idmap,struct dentry *dentry, -struct fileattr *fa) -{ -struct inode *inode =d_inode (dentry); -struct fileattr old_ma = {}; -int err; - -if (!inode->i_op->fileattr_set) -return -ENOIOCTLCMD ; - -if (!inode_owner_or_capable (idmap, inode)) -return -EPERM ; - -inode_lock (inode); - err =vfs_fileattr_get (dentry, &old_ma); -if (!err) { -/* initialize missing bits from old_ma */ -if (fa->flags_valid) { - fa->fsx_xflags |= old_ma.fsx_xflags & ~FS_XFLAG_COMMON ; - fa->fsx_extsize = old_ma.fsx_extsize; - fa->fsx_nextents = old_ma.fsx_nextents; - fa->fsx_projid = old_ma.fsx_projid; - fa->fsx_cowextsize = old_ma.fsx_cowextsize; - }else { - fa->flags |= old_ma.flags & ~FS_COMMON_FL ; - } - err =fileattr_set_prepare (inode, &old_ma, fa); -if (!err) - err = inode->i_op->fileattr_set (idmap, dentry, fa); - } -inode_unlock (inode); - -return err; -} -EXPORT_SYMBOL (vfs_fileattr_set); - -static int ioctl_getflags (struct file *file,unsigned int __user *argp) -{ -struct fileattr fa = { .flags_valid = true };/* hint only */ -int err; - - err =vfs_fileattr_get (file->f_path.dentry, &fa); -if (!err) - err =put_user (fa.flags, argp); -return err; -} - -static int ioctl_setflags (struct file *file,unsigned int __user *argp) -{ -struct mnt_idmap *idmap =file_mnt_idmap (file); -struct dentry *dentry = file->f_path.dentry; -struct fileattr fa; -unsigned int flags; -int err; - - err =get_user (flags, argp); -if (!err) { - err =mnt_want_write_file (file); -if (!err) { -fileattr_fill_flags (&fa, flags); - err =vfs_fileattr_set (idmap, dentry, &fa); -mnt_drop_write_file (file); - } - } -return err; -} - -static int ioctl_fsgetxattr (struct file *file,void __user *argp) -{ -struct fileattr fa = { .fsx_valid = true };/* hint only */ -int err; - - err =vfs_fileattr_get (file->f_path.dentry, &fa); -if (!err) - err =copy_fsxattr_to_user (&fa, argp); - -return err; -} - -static int ioctl_fssetxattr (struct file *file,void __user *argp) -{ -struct mnt_idmap *idmap =file_mnt_idmap (file); -struct dentry *dentry = file->f_path.dentry; -struct fileattr fa; -int err; - - err =copy_fsxattr_from_user (&fa, argp); -if (!err) { - err =mnt_want_write_file (file); -if (!err) { - err =vfs_fileattr_set (idmap, dentry, &fa); -mnt_drop_write_file (file); - } - } -return err; -} -static int ioctl_getfsuuid (struct file *file,void __user *argp) {struct super_block *sb =file_inode (file)->i_sb;include/linux/fileattr.h +4
-1@@ -55,5 +55,9 @@ static inline bool fileattr_has_fsx(const struct fileattr *fa)int vfs_fileattr_get (struct dentry *dentry,struct fileattr *fa);int vfs_fileattr_set (struct mnt_idmap *idmap,struct dentry *dentry,struct fileattr *fa); +int ioctl_getflags (struct file *file,unsigned int __user *argp); +int ioctl_setflags (struct file *file,unsigned int __user *argp); +int ioctl_fsgetxattr (struct file *file,void __user *argp); +int ioctl_fssetxattr (struct file *file,void __user *argp);#endif /* _LINUX_FILEATTR_H */ --2.47.2
Re: [PATCH v6 1/6] fs: split fileattr related helpers into separate file
In reply to Andrey AlbershteynQuoted 6 lines · Andrey Albershteyn
From: Andrey Albershteyn <[email protected]>
This patch moves function related to file extended attributes manipulations to separate file. Refactoring only.
Signed-off-by Andrey Albershteyn <[email protected]>
Looks good. Feel free to add:
Honza
Quoted 683 lines
--- fs/Makefile | 3 +- fs/file_attr.c | 318 +++++++++++++++++++++++++++++++++++++++++++++++ fs/ioctl.c | 309 --------------------------------------------- include/linux/fileattr.h | 4 + 4 files changed, 324 insertions(+), 310 deletions(-)fs/Makefile +2
-1@@ -15,7 +15,8 @@ obj-y := open.o read_write.o file_table.o super.o \ pnode.o splice.o sync.o utimes.o d_path.o \ stack.o fs_struct.o statfs.o fs_pin.o nsfs.o \ fs_types.o fs_context.o fs_parser.o fsopen.o init.o \ - kernel_read_file.o mnt_idmapping.o remap_range.o pidfs.o + kernel_read_file.o mnt_idmapping.o remap_range.o pidfs.o \ + file_attr.o obj-$(CONFIG_BUFFER_HEAD) += buffer.o mpage.o obj-$(CONFIG_PROC_FS) += proc_namespace.ofs/file_attr.c new file +318
-0@@ -0,0 +1,318 @@ +// SPDX-License-Identifier: GPL-2.0 +#include <linux/fs.h> +#include <linux/security.h> +#include <linux/fscrypt.h> +#include <linux/fileattr.h> + +/** +* fileattr_fill_xflags - initialize fileattr with xflags +* @fa: fileattr pointer +* @xflags: FS_XFLAG_* flags +* +* Set ->fsx_xflags, ->fsx_valid and ->flags (translated xflags). All +* other fields are zeroed. +*/ +void fileattr_fill_xflags (struct fileattr *fa,u32 xflags) +{ +memset (fa,0 ,sizeof (*fa)); + fa->fsx_valid = true; + fa->fsx_xflags = xflags; +if (fa->fsx_xflags &FS_XFLAG_IMMUTABLE ) + fa->flags |=FS_IMMUTABLE_FL ; +if (fa->fsx_xflags &FS_XFLAG_APPEND ) + fa->flags |=FS_APPEND_FL ; +if (fa->fsx_xflags &FS_XFLAG_SYNC ) + fa->flags |=FS_SYNC_FL ; +if (fa->fsx_xflags &FS_XFLAG_NOATIME ) + fa->flags |=FS_NOATIME_FL ; +if (fa->fsx_xflags &FS_XFLAG_NODUMP ) + fa->flags |=FS_NODUMP_FL ; +if (fa->fsx_xflags &FS_XFLAG_DAX ) + fa->flags |=FS_DAX_FL ; +if (fa->fsx_xflags &FS_XFLAG_PROJINHERIT ) + fa->flags |=FS_PROJINHERIT_FL ; +} +EXPORT_SYMBOL (fileattr_fill_xflags); + +/** +* fileattr_fill_flags - initialize fileattr with flags +* @fa: fileattr pointer +* @flags: FS_*_FL flags +* +* Set ->flags, ->flags_valid and ->fsx_xflags (translated flags). +* All other fields are zeroed. +*/ +void fileattr_fill_flags (struct fileattr *fa,u32 flags) +{ +memset (fa,0 ,sizeof (*fa)); + fa->flags_valid = true; + fa->flags = flags; +if (fa->flags &FS_SYNC_FL ) + fa->fsx_xflags |=FS_XFLAG_SYNC ; +if (fa->flags &FS_IMMUTABLE_FL ) + fa->fsx_xflags |=FS_XFLAG_IMMUTABLE ; +if (fa->flags &FS_APPEND_FL ) + fa->fsx_xflags |=FS_XFLAG_APPEND ; +if (fa->flags &FS_NODUMP_FL ) + fa->fsx_xflags |=FS_XFLAG_NODUMP ; +if (fa->flags &FS_NOATIME_FL ) + fa->fsx_xflags |=FS_XFLAG_NOATIME ; +if (fa->flags &FS_DAX_FL ) + fa->fsx_xflags |=FS_XFLAG_DAX ; +if (fa->flags &FS_PROJINHERIT_FL ) + fa->fsx_xflags |=FS_XFLAG_PROJINHERIT ; +} +EXPORT_SYMBOL (fileattr_fill_flags); + +/** +* vfs_fileattr_get - retrieve miscellaneous file attributes +* @dentry: the object to retrieve from +* @fa: fileattr pointer +* +* Call i_op->fileattr_get() callback, if exists. +* +* Return: 0 on success, or a negative error on failure. +*/ +int vfs_fileattr_get (struct dentry *dentry,struct fileattr *fa) +{ +struct inode *inode =d_inode (dentry); + +if (!inode->i_op->fileattr_get) +return -ENOIOCTLCMD ; + +return inode->i_op->fileattr_get (dentry, fa); +} +EXPORT_SYMBOL (vfs_fileattr_get); + +/** +* copy_fsxattr_to_user - copy fsxattr to userspace. +* @fa: fileattr pointer +* @ufa: fsxattr user pointer +* +* Return: 0 on success, or -EFAULT on failure. +*/ +int copy_fsxattr_to_user (const struct fileattr *fa,struct fsxattr __user *ufa) +{ +struct fsxattr xfa; + +memset (&xfa,0 ,sizeof (xfa)); + xfa.fsx_xflags = fa->fsx_xflags; + xfa.fsx_extsize = fa->fsx_extsize; + xfa.fsx_nextents = fa->fsx_nextents; + xfa.fsx_projid = fa->fsx_projid; + xfa.fsx_cowextsize = fa->fsx_cowextsize; + +if (copy_to_user (ufa, &xfa,sizeof (xfa))) +return -EFAULT ; + +return 0 ; +} +EXPORT_SYMBOL (copy_fsxattr_to_user); + +static int copy_fsxattr_from_user (struct fileattr *fa, +struct fsxattr __user *ufa) +{ +struct fsxattr xfa; + +if (copy_from_user (&xfa, ufa,sizeof (xfa))) +return -EFAULT ; + +fileattr_fill_xflags (fa, xfa.fsx_xflags); + fa->fsx_extsize = xfa.fsx_extsize; + fa->fsx_nextents = xfa.fsx_nextents; + fa->fsx_projid = xfa.fsx_projid; + fa->fsx_cowextsize = xfa.fsx_cowextsize; + +return 0 ; +} + +/* +* Generic function to check FS_IOC_FSSETXATTR/FS_IOC_SETFLAGS values and reject +* any invalid configurations. +* +* Note: must be called with inode lock held. +*/ +static int fileattr_set_prepare (struct inode *inode, +const struct fileattr *old_ma, +struct fileattr *fa) +{ +int err; + +/* +* The IMMUTABLE and APPEND_ONLY flags can only be changed by +* the relevant capability. +*/ +if ((fa->flags ^ old_ma->flags) & (FS_APPEND_FL |FS_IMMUTABLE_FL ) && + !capable (CAP_LINUX_IMMUTABLE )) +return -EPERM ; + + err =fscrypt_prepare_setflags (inode, old_ma->flags, fa->flags); +if (err) +return err; + +/* +* Project Quota ID state is only allowed to change from within the init +* namespace. Enforce that restriction only if we are trying to change +* the quota ID state. Everything else is allowed in user namespaces. +*/ +if (current_user_ns () != &init_user_ns) { +if (old_ma->fsx_projid != fa->fsx_projid) +return -EINVAL ; +if ((old_ma->fsx_xflags ^ fa->fsx_xflags) & +FS_XFLAG_PROJINHERIT ) +return -EINVAL ; + }else { +/* +* Caller is allowed to change the project ID. If it is being +* changed, make sure that the new value is valid. +*/ +if (old_ma->fsx_projid != fa->fsx_projid && + !projid_valid (make_kprojid (&init_user_ns, fa->fsx_projid))) +return -EINVAL ; + } + +/* Check extent size hints. */ +if ((fa->fsx_xflags &FS_XFLAG_EXTSIZE ) && !S_ISREG (inode->i_mode)) +return -EINVAL ; + +if ((fa->fsx_xflags &FS_XFLAG_EXTSZINHERIT ) && + !S_ISDIR (inode->i_mode)) +return -EINVAL ; + +if ((fa->fsx_xflags &FS_XFLAG_COWEXTSIZE ) && + !S_ISREG (inode->i_mode) && !S_ISDIR (inode->i_mode)) +return -EINVAL ; + +/* +* It is only valid to set the DAX flag on regular files and +* directories on filesystems. +*/ +if ((fa->fsx_xflags &FS_XFLAG_DAX ) && + !(S_ISREG (inode->i_mode) ||S_ISDIR (inode->i_mode))) +return -EINVAL ; + +/* Extent size hints of zero turn off the flags. */ +if (fa->fsx_extsize ==0 ) + fa->fsx_xflags &= ~(FS_XFLAG_EXTSIZE |FS_XFLAG_EXTSZINHERIT ); +if (fa->fsx_cowextsize ==0 ) + fa->fsx_xflags &= ~FS_XFLAG_COWEXTSIZE ; + +return 0 ; +} + +/** +* vfs_fileattr_set - change miscellaneous file attributes +* @idmap: idmap of the mount +* @dentry: the object to change +* @fa: fileattr pointer +* +* After verifying permissions, call i_op->fileattr_set() callback, if +* exists. +* +* Verifying attributes involves retrieving current attributes with +* i_op->fileattr_get(), this also allows initializing attributes that have +* not been set by the caller to current values. Inode lock is held +* thoughout to prevent racing with another instance. +* +* Return: 0 on success, or a negative error on failure. +*/ +int vfs_fileattr_set (struct mnt_idmap *idmap,struct dentry *dentry, +struct fileattr *fa) +{ +struct inode *inode =d_inode (dentry); +struct fileattr old_ma = {}; +int err; + +if (!inode->i_op->fileattr_set) +return -ENOIOCTLCMD ; + +if (!inode_owner_or_capable (idmap, inode)) +return -EPERM ; + +inode_lock (inode); + err =vfs_fileattr_get (dentry, &old_ma); +if (!err) { +/* initialize missing bits from old_ma */ +if (fa->flags_valid) { + fa->fsx_xflags |= old_ma.fsx_xflags & ~FS_XFLAG_COMMON ; + fa->fsx_extsize = old_ma.fsx_extsize; + fa->fsx_nextents = old_ma.fsx_nextents; + fa->fsx_projid = old_ma.fsx_projid; + fa->fsx_cowextsize = old_ma.fsx_cowextsize; + }else { + fa->flags |= old_ma.flags & ~FS_COMMON_FL ; + } + err =fileattr_set_prepare (inode, &old_ma, fa); +if (!err) + err = inode->i_op->fileattr_set (idmap, dentry, fa); + } +inode_unlock (inode); + +return err; +} +EXPORT_SYMBOL (vfs_fileattr_set); + +int ioctl_getflags (struct file *file,unsigned int __user *argp) +{ +struct fileattr fa = { .flags_valid = true };/* hint only */ +int err; + + err =vfs_fileattr_get (file->f_path.dentry, &fa); +if (!err) + err =put_user (fa.flags, argp); +return err; +} +EXPORT_SYMBOL (ioctl_getflags); + +int ioctl_setflags (struct file *file,unsigned int __user *argp) +{ +struct mnt_idmap *idmap =file_mnt_idmap (file); +struct dentry *dentry = file->f_path.dentry; +struct fileattr fa; +unsigned int flags; +int err; + + err =get_user (flags, argp); +if (!err) { + err =mnt_want_write_file (file); +if (!err) { +fileattr_fill_flags (&fa, flags); + err =vfs_fileattr_set (idmap, dentry, &fa); +mnt_drop_write_file (file); + } + } +return err; +} +EXPORT_SYMBOL (ioctl_setflags); + +int ioctl_fsgetxattr (struct file *file,void __user *argp) +{ +struct fileattr fa = { .fsx_valid = true };/* hint only */ +int err; + + err =vfs_fileattr_get (file->f_path.dentry, &fa); +if (!err) + err =copy_fsxattr_to_user (&fa, argp); + +return err; +} +EXPORT_SYMBOL (ioctl_fsgetxattr); + +int ioctl_fssetxattr (struct file *file,void __user *argp) +{ +struct mnt_idmap *idmap =file_mnt_idmap (file); +struct dentry *dentry = file->f_path.dentry; +struct fileattr fa; +int err; + + err =copy_fsxattr_from_user (&fa, argp); +if (!err) { + err =mnt_want_write_file (file); +if (!err) { + err =vfs_fileattr_set (idmap, dentry, &fa); +mnt_drop_write_file (file); + } + } +return err; +} +EXPORT_SYMBOL (ioctl_fssetxattr);fs/ioctl.c +0
-309@@ -453,315 +453,6 @@ static int ioctl_file_dedupe_range(struct file *file,return ret; } -/** -* fileattr_fill_xflags - initialize fileattr with xflags -* @fa: fileattr pointer -* @xflags: FS_XFLAG_* flags -* -* Set ->fsx_xflags, ->fsx_valid and ->flags (translated xflags). All -* other fields are zeroed. -*/ -void fileattr_fill_xflags (struct fileattr *fa,u32 xflags) -{ -memset (fa,0 ,sizeof (*fa)); - fa->fsx_valid = true; - fa->fsx_xflags = xflags; -if (fa->fsx_xflags &FS_XFLAG_IMMUTABLE ) - fa->flags |=FS_IMMUTABLE_FL ; -if (fa->fsx_xflags &FS_XFLAG_APPEND ) - fa->flags |=FS_APPEND_FL ; -if (fa->fsx_xflags &FS_XFLAG_SYNC ) - fa->flags |=FS_SYNC_FL ; -if (fa->fsx_xflags &FS_XFLAG_NOATIME ) - fa->flags |=FS_NOATIME_FL ; -if (fa->fsx_xflags &FS_XFLAG_NODUMP ) - fa->flags |=FS_NODUMP_FL ; -if (fa->fsx_xflags &FS_XFLAG_DAX ) - fa->flags |=FS_DAX_FL ; -if (fa->fsx_xflags &FS_XFLAG_PROJINHERIT ) - fa->flags |=FS_PROJINHERIT_FL ; -} -EXPORT_SYMBOL (fileattr_fill_xflags); - -/** -* fileattr_fill_flags - initialize fileattr with flags -* @fa: fileattr pointer -* @flags: FS_*_FL flags -* -* Set ->flags, ->flags_valid and ->fsx_xflags (translated flags). -* All other fields are zeroed. -*/ -void fileattr_fill_flags (struct fileattr *fa,u32 flags) -{ -memset (fa,0 ,sizeof (*fa)); - fa->flags_valid = true; - fa->flags = flags; -if (fa->flags &FS_SYNC_FL ) - fa->fsx_xflags |=FS_XFLAG_SYNC ; -if (fa->flags &FS_IMMUTABLE_FL ) - fa->fsx_xflags |=FS_XFLAG_IMMUTABLE ; -if (fa->flags &FS_APPEND_FL ) - fa->fsx_xflags |=FS_XFLAG_APPEND ; -if (fa->flags &FS_NODUMP_FL ) - fa->fsx_xflags |=FS_XFLAG_NODUMP ; -if (fa->flags &FS_NOATIME_FL ) - fa->fsx_xflags |=FS_XFLAG_NOATIME ; -if (fa->flags &FS_DAX_FL ) - fa->fsx_xflags |=FS_XFLAG_DAX ; -if (fa->flags &FS_PROJINHERIT_FL ) - fa->fsx_xflags |=FS_XFLAG_PROJINHERIT ; -} -EXPORT_SYMBOL (fileattr_fill_flags); - -/** -* vfs_fileattr_get - retrieve miscellaneous file attributes -* @dentry: the object to retrieve from -* @fa: fileattr pointer -* -* Call i_op->fileattr_get() callback, if exists. -* -* Return: 0 on success, or a negative error on failure. -*/ -int vfs_fileattr_get (struct dentry *dentry,struct fileattr *fa) -{ -struct inode *inode =d_inode (dentry); - -if (!inode->i_op->fileattr_get) -return -ENOIOCTLCMD ; - -return inode->i_op->fileattr_get (dentry, fa); -} -EXPORT_SYMBOL (vfs_fileattr_get); - -/** -* copy_fsxattr_to_user - copy fsxattr to userspace. -* @fa: fileattr pointer -* @ufa: fsxattr user pointer -* -* Return: 0 on success, or -EFAULT on failure. -*/ -int copy_fsxattr_to_user (const struct fileattr *fa,struct fsxattr __user *ufa) -{ -struct fsxattr xfa; - -memset (&xfa,0 ,sizeof (xfa)); - xfa.fsx_xflags = fa->fsx_xflags; - xfa.fsx_extsize = fa->fsx_extsize; - xfa.fsx_nextents = fa->fsx_nextents; - xfa.fsx_projid = fa->fsx_projid; - xfa.fsx_cowextsize = fa->fsx_cowextsize; - -if (copy_to_user (ufa, &xfa,sizeof (xfa))) -return -EFAULT ; - -return 0 ; -} -EXPORT_SYMBOL (copy_fsxattr_to_user); - -static int copy_fsxattr_from_user (struct fileattr *fa, -struct fsxattr __user *ufa) -{ -struct fsxattr xfa; - -if (copy_from_user (&xfa, ufa,sizeof (xfa))) -return -EFAULT ; - -fileattr_fill_xflags (fa, xfa.fsx_xflags); - fa->fsx_extsize = xfa.fsx_extsize; - fa->fsx_nextents = xfa.fsx_nextents; - fa->fsx_projid = xfa.fsx_projid; - fa->fsx_cowextsize = xfa.fsx_cowextsize; - -return 0 ; -} - -/* -* Generic function to check FS_IOC_FSSETXATTR/FS_IOC_SETFLAGS values and reject -* any invalid configurations. -* -* Note: must be called with inode lock held. -*/ -static int fileattr_set_prepare (struct inode *inode, -const struct fileattr *old_ma, -struct fileattr *fa) -{ -int err; - -/* -* The IMMUTABLE and APPEND_ONLY flags can only be changed by -* the relevant capability. -*/ -if ((fa->flags ^ old_ma->flags) & (FS_APPEND_FL |FS_IMMUTABLE_FL ) && - !capable (CAP_LINUX_IMMUTABLE )) -return -EPERM ; - - err =fscrypt_prepare_setflags (inode, old_ma->flags, fa->flags); -if (err) -return err; - -/* -* Project Quota ID state is only allowed to change from within the init -* namespace. Enforce that restriction only if we are trying to change -* the quota ID state. Everything else is allowed in user namespaces. -*/ -if (current_user_ns () != &init_user_ns) { -if (old_ma->fsx_projid != fa->fsx_projid) -return -EINVAL ; -if ((old_ma->fsx_xflags ^ fa->fsx_xflags) & -FS_XFLAG_PROJINHERIT ) -return -EINVAL ; - }else { -/* -* Caller is allowed to change the project ID. If it is being -* changed, make sure that the new value is valid. -*/ -if (old_ma->fsx_projid != fa->fsx_projid && - !projid_valid (make_kprojid (&init_user_ns, fa->fsx_projid))) -return -EINVAL ; - } - -/* Check extent size hints. */ -if ((fa->fsx_xflags &FS_XFLAG_EXTSIZE ) && !S_ISREG (inode->i_mode)) -return -EINVAL ; - -if ((fa->fsx_xflags &FS_XFLAG_EXTSZINHERIT ) && - !S_ISDIR (inode->i_mode)) -return -EINVAL ; - -if ((fa->fsx_xflags &FS_XFLAG_COWEXTSIZE ) && - !S_ISREG (inode->i_mode) && !S_ISDIR (inode->i_mode)) -return -EINVAL ; - -/* -* It is only valid to set the DAX flag on regular files and -* directories on filesystems. -*/ -if ((fa->fsx_xflags &FS_XFLAG_DAX ) && - !(S_ISREG (inode->i_mode) ||S_ISDIR (inode->i_mode))) -return -EINVAL ; - -/* Extent size hints of zero turn off the flags. */ -if (fa->fsx_extsize ==0 ) - fa->fsx_xflags &= ~(FS_XFLAG_EXTSIZE |FS_XFLAG_EXTSZINHERIT ); -if (fa->fsx_cowextsize ==0 ) - fa->fsx_xflags &= ~FS_XFLAG_COWEXTSIZE ; - -return 0 ; -} - -/** -* vfs_fileattr_set - change miscellaneous file attributes -* @idmap: idmap of the mount -* @dentry: the object to change -* @fa: fileattr pointer -* -* After verifying permissions, call i_op->fileattr_set() callback, if -* exists. -* -* Verifying attributes involves retrieving current attributes with -* i_op->fileattr_get(), this also allows initializing attributes that have -* not been set by the caller to current values. Inode lock is held -* thoughout to prevent racing with another instance. -* -* Return: 0 on success, or a negative error on failure. -*/ -int vfs_fileattr_set (struct mnt_idmap *idmap,struct dentry *dentry, -struct fileattr *fa) -{ -struct inode *inode =d_inode (dentry); -struct fileattr old_ma = {}; -int err; - -if (!inode->i_op->fileattr_set) -return -ENOIOCTLCMD ; - -if (!inode_owner_or_capable (idmap, inode)) -return -EPERM ; - -inode_lock (inode); - err =vfs_fileattr_get (dentry, &old_ma); -if (!err) { -/* initialize missing bits from old_ma */ -if (fa->flags_valid) { - fa->fsx_xflags |= old_ma.fsx_xflags & ~FS_XFLAG_COMMON ; - fa->fsx_extsize = old_ma.fsx_extsize; - fa->fsx_nextents = old_ma.fsx_nextents; - fa->fsx_projid = old_ma.fsx_projid; - fa->fsx_cowextsize = old_ma.fsx_cowextsize; - }else { - fa->flags |= old_ma.flags & ~FS_COMMON_FL ; - } - err =fileattr_set_prepare (inode, &old_ma, fa); -if (!err) - err = inode->i_op->fileattr_set (idmap, dentry, fa); - } -inode_unlock (inode); - -return err; -} -EXPORT_SYMBOL (vfs_fileattr_set); - -static int ioctl_getflags (struct file *file,unsigned int __user *argp) -{ -struct fileattr fa = { .flags_valid = true };/* hint only */ -int err; - - err =vfs_fileattr_get (file->f_path.dentry, &fa); -if (!err) - err =put_user (fa.flags, argp); -return err; -} - -static int ioctl_setflags (struct file *file,unsigned int __user *argp) -{ -struct mnt_idmap *idmap =file_mnt_idmap (file); -struct dentry *dentry = file->f_path.dentry; -struct fileattr fa; -unsigned int flags; -int err; - - err =get_user (flags, argp); -if (!err) { - err =mnt_want_write_file (file); -if (!err) { -fileattr_fill_flags (&fa, flags); - err =vfs_fileattr_set (idmap, dentry, &fa); -mnt_drop_write_file (file); - } - } -return err; -} - -static int ioctl_fsgetxattr (struct file *file,void __user *argp) -{ -struct fileattr fa = { .fsx_valid = true };/* hint only */ -int err; - - err =vfs_fileattr_get (file->f_path.dentry, &fa); -if (!err) - err =copy_fsxattr_to_user (&fa, argp); - -return err; -} - -static int ioctl_fssetxattr (struct file *file,void __user *argp) -{ -struct mnt_idmap *idmap =file_mnt_idmap (file); -struct dentry *dentry = file->f_path.dentry; -struct fileattr fa; -int err; - - err =copy_fsxattr_from_user (&fa, argp); -if (!err) { - err =mnt_want_write_file (file); -if (!err) { - err =vfs_fileattr_set (idmap, dentry, &fa); -mnt_drop_write_file (file); - } - } -return err; -} -static int ioctl_getfsuuid (struct file *file,void __user *argp) {struct super_block *sb =file_inode (file)->i_sb;include/linux/fileattr.h +4
-0@@ -55,5 +55,9 @@ static inline bool fileattr_has_fsx(const struct fileattr *fa)int vfs_fileattr_get (struct dentry *dentry,struct fileattr *fa);int vfs_fileattr_set (struct mnt_idmap *idmap,struct dentry *dentry,struct fileattr *fa); +int ioctl_getflags (struct file *file,unsigned int __user *argp); +int ioctl_setflags (struct file *file,unsigned int __user *argp); +int ioctl_fsgetxattr (struct file *file,void __user *argp); +int ioctl_fssetxattr (struct file *file,void __user *argp);#endif /* _LINUX_FILEATTR_H */ Signature · 2 lines
-- 2.47.2
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Re: [PATCH v6 1/6] fs: split fileattr related helpers into separate file
In reply to Andrey AlbershteynQuoted 6 lines · Andrey Albershteyn
From: Andrey Albershteyn <[email protected]>
This patch moves function related to file extended attributes manipulations to separate file. Refactoring only.
Signed-off-by Andrey Albershteyn <[email protected]>
Seems fine to me to move that to a separate file.
--D
Quoted 684 lines
--- fs/Makefile | 3 +- fs/file_attr.c | 318 +++++++++++++++++++++++++++++++++++++++++++++++ fs/ioctl.c | 309 --------------------------------------------- include/linux/fileattr.h | 4 + 4 files changed, 324 insertions(+), 310 deletions(-)fs/Makefile +2
-1@@ -15,7 +15,8 @@ obj-y := open.o read_write.o file_table.o super.o \ pnode.o splice.o sync.o utimes.o d_path.o \ stack.o fs_struct.o statfs.o fs_pin.o nsfs.o \ fs_types.o fs_context.o fs_parser.o fsopen.o init.o \ - kernel_read_file.o mnt_idmapping.o remap_range.o pidfs.o + kernel_read_file.o mnt_idmapping.o remap_range.o pidfs.o \ + file_attr.o obj-$(CONFIG_BUFFER_HEAD) += buffer.o mpage.o obj-$(CONFIG_PROC_FS) += proc_namespace.ofs/file_attr.c new file +318
-0@@ -0,0 +1,318 @@ +// SPDX-License-Identifier: GPL-2.0 +#include <linux/fs.h> +#include <linux/security.h> +#include <linux/fscrypt.h> +#include <linux/fileattr.h> + +/** +* fileattr_fill_xflags - initialize fileattr with xflags +* @fa: fileattr pointer +* @xflags: FS_XFLAG_* flags +* +* Set ->fsx_xflags, ->fsx_valid and ->flags (translated xflags). All +* other fields are zeroed. +*/ +void fileattr_fill_xflags (struct fileattr *fa,u32 xflags) +{ +memset (fa,0 ,sizeof (*fa)); + fa->fsx_valid = true; + fa->fsx_xflags = xflags; +if (fa->fsx_xflags &FS_XFLAG_IMMUTABLE ) + fa->flags |=FS_IMMUTABLE_FL ; +if (fa->fsx_xflags &FS_XFLAG_APPEND ) + fa->flags |=FS_APPEND_FL ; +if (fa->fsx_xflags &FS_XFLAG_SYNC ) + fa->flags |=FS_SYNC_FL ; +if (fa->fsx_xflags &FS_XFLAG_NOATIME ) + fa->flags |=FS_NOATIME_FL ; +if (fa->fsx_xflags &FS_XFLAG_NODUMP ) + fa->flags |=FS_NODUMP_FL ; +if (fa->fsx_xflags &FS_XFLAG_DAX ) + fa->flags |=FS_DAX_FL ; +if (fa->fsx_xflags &FS_XFLAG_PROJINHERIT ) + fa->flags |=FS_PROJINHERIT_FL ; +} +EXPORT_SYMBOL (fileattr_fill_xflags); + +/** +* fileattr_fill_flags - initialize fileattr with flags +* @fa: fileattr pointer +* @flags: FS_*_FL flags +* +* Set ->flags, ->flags_valid and ->fsx_xflags (translated flags). +* All other fields are zeroed. +*/ +void fileattr_fill_flags (struct fileattr *fa,u32 flags) +{ +memset (fa,0 ,sizeof (*fa)); + fa->flags_valid = true; + fa->flags = flags; +if (fa->flags &FS_SYNC_FL ) + fa->fsx_xflags |=FS_XFLAG_SYNC ; +if (fa->flags &FS_IMMUTABLE_FL ) + fa->fsx_xflags |=FS_XFLAG_IMMUTABLE ; +if (fa->flags &FS_APPEND_FL ) + fa->fsx_xflags |=FS_XFLAG_APPEND ; +if (fa->flags &FS_NODUMP_FL ) + fa->fsx_xflags |=FS_XFLAG_NODUMP ; +if (fa->flags &FS_NOATIME_FL ) + fa->fsx_xflags |=FS_XFLAG_NOATIME ; +if (fa->flags &FS_DAX_FL ) + fa->fsx_xflags |=FS_XFLAG_DAX ; +if (fa->flags &FS_PROJINHERIT_FL ) + fa->fsx_xflags |=FS_XFLAG_PROJINHERIT ; +} +EXPORT_SYMBOL (fileattr_fill_flags); + +/** +* vfs_fileattr_get - retrieve miscellaneous file attributes +* @dentry: the object to retrieve from +* @fa: fileattr pointer +* +* Call i_op->fileattr_get() callback, if exists. +* +* Return: 0 on success, or a negative error on failure. +*/ +int vfs_fileattr_get (struct dentry *dentry,struct fileattr *fa) +{ +struct inode *inode =d_inode (dentry); + +if (!inode->i_op->fileattr_get) +return -ENOIOCTLCMD ; + +return inode->i_op->fileattr_get (dentry, fa); +} +EXPORT_SYMBOL (vfs_fileattr_get); + +/** +* copy_fsxattr_to_user - copy fsxattr to userspace. +* @fa: fileattr pointer +* @ufa: fsxattr user pointer +* +* Return: 0 on success, or -EFAULT on failure. +*/ +int copy_fsxattr_to_user (const struct fileattr *fa,struct fsxattr __user *ufa) +{ +struct fsxattr xfa; + +memset (&xfa,0 ,sizeof (xfa)); + xfa.fsx_xflags = fa->fsx_xflags; + xfa.fsx_extsize = fa->fsx_extsize; + xfa.fsx_nextents = fa->fsx_nextents; + xfa.fsx_projid = fa->fsx_projid; + xfa.fsx_cowextsize = fa->fsx_cowextsize; + +if (copy_to_user (ufa, &xfa,sizeof (xfa))) +return -EFAULT ; + +return 0 ; +} +EXPORT_SYMBOL (copy_fsxattr_to_user); + +static int copy_fsxattr_from_user (struct fileattr *fa, +struct fsxattr __user *ufa) +{ +struct fsxattr xfa; + +if (copy_from_user (&xfa, ufa,sizeof (xfa))) +return -EFAULT ; + +fileattr_fill_xflags (fa, xfa.fsx_xflags); + fa->fsx_extsize = xfa.fsx_extsize; + fa->fsx_nextents = xfa.fsx_nextents; + fa->fsx_projid = xfa.fsx_projid; + fa->fsx_cowextsize = xfa.fsx_cowextsize; + +return 0 ; +} + +/* +* Generic function to check FS_IOC_FSSETXATTR/FS_IOC_SETFLAGS values and reject +* any invalid configurations. +* +* Note: must be called with inode lock held. +*/ +static int fileattr_set_prepare (struct inode *inode, +const struct fileattr *old_ma, +struct fileattr *fa) +{ +int err; + +/* +* The IMMUTABLE and APPEND_ONLY flags can only be changed by +* the relevant capability. +*/ +if ((fa->flags ^ old_ma->flags) & (FS_APPEND_FL |FS_IMMUTABLE_FL ) && + !capable (CAP_LINUX_IMMUTABLE )) +return -EPERM ; + + err =fscrypt_prepare_setflags (inode, old_ma->flags, fa->flags); +if (err) +return err; + +/* +* Project Quota ID state is only allowed to change from within the init +* namespace. Enforce that restriction only if we are trying to change +* the quota ID state. Everything else is allowed in user namespaces. +*/ +if (current_user_ns () != &init_user_ns) { +if (old_ma->fsx_projid != fa->fsx_projid) +return -EINVAL ; +if ((old_ma->fsx_xflags ^ fa->fsx_xflags) & +FS_XFLAG_PROJINHERIT ) +return -EINVAL ; + }else { +/* +* Caller is allowed to change the project ID. If it is being +* changed, make sure that the new value is valid. +*/ +if (old_ma->fsx_projid != fa->fsx_projid && + !projid_valid (make_kprojid (&init_user_ns, fa->fsx_projid))) +return -EINVAL ; + } + +/* Check extent size hints. */ +if ((fa->fsx_xflags &FS_XFLAG_EXTSIZE ) && !S_ISREG (inode->i_mode)) +return -EINVAL ; + +if ((fa->fsx_xflags &FS_XFLAG_EXTSZINHERIT ) && + !S_ISDIR (inode->i_mode)) +return -EINVAL ; + +if ((fa->fsx_xflags &FS_XFLAG_COWEXTSIZE ) && + !S_ISREG (inode->i_mode) && !S_ISDIR (inode->i_mode)) +return -EINVAL ; + +/* +* It is only valid to set the DAX flag on regular files and +* directories on filesystems. +*/ +if ((fa->fsx_xflags &FS_XFLAG_DAX ) && + !(S_ISREG (inode->i_mode) ||S_ISDIR (inode->i_mode))) +return -EINVAL ; + +/* Extent size hints of zero turn off the flags. */ +if (fa->fsx_extsize ==0 ) + fa->fsx_xflags &= ~(FS_XFLAG_EXTSIZE |FS_XFLAG_EXTSZINHERIT ); +if (fa->fsx_cowextsize ==0 ) + fa->fsx_xflags &= ~FS_XFLAG_COWEXTSIZE ; + +return 0 ; +} + +/** +* vfs_fileattr_set - change miscellaneous file attributes +* @idmap: idmap of the mount +* @dentry: the object to change +* @fa: fileattr pointer +* +* After verifying permissions, call i_op->fileattr_set() callback, if +* exists. +* +* Verifying attributes involves retrieving current attributes with +* i_op->fileattr_get(), this also allows initializing attributes that have +* not been set by the caller to current values. Inode lock is held +* thoughout to prevent racing with another instance. +* +* Return: 0 on success, or a negative error on failure. +*/ +int vfs_fileattr_set (struct mnt_idmap *idmap,struct dentry *dentry, +struct fileattr *fa) +{ +struct inode *inode =d_inode (dentry); +struct fileattr old_ma = {}; +int err; + +if (!inode->i_op->fileattr_set) +return -ENOIOCTLCMD ; + +if (!inode_owner_or_capable (idmap, inode)) +return -EPERM ; + +inode_lock (inode); + err =vfs_fileattr_get (dentry, &old_ma); +if (!err) { +/* initialize missing bits from old_ma */ +if (fa->flags_valid) { + fa->fsx_xflags |= old_ma.fsx_xflags & ~FS_XFLAG_COMMON ; + fa->fsx_extsize = old_ma.fsx_extsize; + fa->fsx_nextents = old_ma.fsx_nextents; + fa->fsx_projid = old_ma.fsx_projid; + fa->fsx_cowextsize = old_ma.fsx_cowextsize; + }else { + fa->flags |= old_ma.flags & ~FS_COMMON_FL ; + } + err =fileattr_set_prepare (inode, &old_ma, fa); +if (!err) + err = inode->i_op->fileattr_set (idmap, dentry, fa); + } +inode_unlock (inode); + +return err; +} +EXPORT_SYMBOL (vfs_fileattr_set); + +int ioctl_getflags (struct file *file,unsigned int __user *argp) +{ +struct fileattr fa = { .flags_valid = true };/* hint only */ +int err; + + err =vfs_fileattr_get (file->f_path.dentry, &fa); +if (!err) + err =put_user (fa.flags, argp); +return err; +} +EXPORT_SYMBOL (ioctl_getflags); + +int ioctl_setflags (struct file *file,unsigned int __user *argp) +{ +struct mnt_idmap *idmap =file_mnt_idmap (file); +struct dentry *dentry = file->f_path.dentry; +struct fileattr fa; +unsigned int flags; +int err; + + err =get_user (flags, argp); +if (!err) { + err =mnt_want_write_file (file); +if (!err) { +fileattr_fill_flags (&fa, flags); + err =vfs_fileattr_set (idmap, dentry, &fa); +mnt_drop_write_file (file); + } + } +return err; +} +EXPORT_SYMBOL (ioctl_setflags); + +int ioctl_fsgetxattr (struct file *file,void __user *argp) +{ +struct fileattr fa = { .fsx_valid = true };/* hint only */ +int err; + + err =vfs_fileattr_get (file->f_path.dentry, &fa); +if (!err) + err =copy_fsxattr_to_user (&fa, argp); + +return err; +} +EXPORT_SYMBOL (ioctl_fsgetxattr); + +int ioctl_fssetxattr (struct file *file,void __user *argp) +{ +struct mnt_idmap *idmap =file_mnt_idmap (file); +struct dentry *dentry = file->f_path.dentry; +struct fileattr fa; +int err; + + err =copy_fsxattr_from_user (&fa, argp); +if (!err) { + err =mnt_want_write_file (file); +if (!err) { + err =vfs_fileattr_set (idmap, dentry, &fa); +mnt_drop_write_file (file); + } + } +return err; +} +EXPORT_SYMBOL (ioctl_fssetxattr);fs/ioctl.c +0
-309@@ -453,315 +453,6 @@ static int ioctl_file_dedupe_range(struct file *file,return ret; } -/** -* fileattr_fill_xflags - initialize fileattr with xflags -* @fa: fileattr pointer -* @xflags: FS_XFLAG_* flags -* -* Set ->fsx_xflags, ->fsx_valid and ->flags (translated xflags). All -* other fields are zeroed. -*/ -void fileattr_fill_xflags (struct fileattr *fa,u32 xflags) -{ -memset (fa,0 ,sizeof (*fa)); - fa->fsx_valid = true; - fa->fsx_xflags = xflags; -if (fa->fsx_xflags &FS_XFLAG_IMMUTABLE ) - fa->flags |=FS_IMMUTABLE_FL ; -if (fa->fsx_xflags &FS_XFLAG_APPEND ) - fa->flags |=FS_APPEND_FL ; -if (fa->fsx_xflags &FS_XFLAG_SYNC ) - fa->flags |=FS_SYNC_FL ; -if (fa->fsx_xflags &FS_XFLAG_NOATIME ) - fa->flags |=FS_NOATIME_FL ; -if (fa->fsx_xflags &FS_XFLAG_NODUMP ) - fa->flags |=FS_NODUMP_FL ; -if (fa->fsx_xflags &FS_XFLAG_DAX ) - fa->flags |=FS_DAX_FL ; -if (fa->fsx_xflags &FS_XFLAG_PROJINHERIT ) - fa->flags |=FS_PROJINHERIT_FL ; -} -EXPORT_SYMBOL (fileattr_fill_xflags); - -/** -* fileattr_fill_flags - initialize fileattr with flags -* @fa: fileattr pointer -* @flags: FS_*_FL flags -* -* Set ->flags, ->flags_valid and ->fsx_xflags (translated flags). -* All other fields are zeroed. -*/ -void fileattr_fill_flags (struct fileattr *fa,u32 flags) -{ -memset (fa,0 ,sizeof (*fa)); - fa->flags_valid = true; - fa->flags = flags; -if (fa->flags &FS_SYNC_FL ) - fa->fsx_xflags |=FS_XFLAG_SYNC ; -if (fa->flags &FS_IMMUTABLE_FL ) - fa->fsx_xflags |=FS_XFLAG_IMMUTABLE ; -if (fa->flags &FS_APPEND_FL ) - fa->fsx_xflags |=FS_XFLAG_APPEND ; -if (fa->flags &FS_NODUMP_FL ) - fa->fsx_xflags |=FS_XFLAG_NODUMP ; -if (fa->flags &FS_NOATIME_FL ) - fa->fsx_xflags |=FS_XFLAG_NOATIME ; -if (fa->flags &FS_DAX_FL ) - fa->fsx_xflags |=FS_XFLAG_DAX ; -if (fa->flags &FS_PROJINHERIT_FL ) - fa->fsx_xflags |=FS_XFLAG_PROJINHERIT ; -} -EXPORT_SYMBOL (fileattr_fill_flags); - -/** -* vfs_fileattr_get - retrieve miscellaneous file attributes -* @dentry: the object to retrieve from -* @fa: fileattr pointer -* -* Call i_op->fileattr_get() callback, if exists. -* -* Return: 0 on success, or a negative error on failure. -*/ -int vfs_fileattr_get (struct dentry *dentry,struct fileattr *fa) -{ -struct inode *inode =d_inode (dentry); - -if (!inode->i_op->fileattr_get) -return -ENOIOCTLCMD ; - -return inode->i_op->fileattr_get (dentry, fa); -} -EXPORT_SYMBOL (vfs_fileattr_get); - -/** -* copy_fsxattr_to_user - copy fsxattr to userspace. -* @fa: fileattr pointer -* @ufa: fsxattr user pointer -* -* Return: 0 on success, or -EFAULT on failure. -*/ -int copy_fsxattr_to_user (const struct fileattr *fa,struct fsxattr __user *ufa) -{ -struct fsxattr xfa; - -memset (&xfa,0 ,sizeof (xfa)); - xfa.fsx_xflags = fa->fsx_xflags; - xfa.fsx_extsize = fa->fsx_extsize; - xfa.fsx_nextents = fa->fsx_nextents; - xfa.fsx_projid = fa->fsx_projid; - xfa.fsx_cowextsize = fa->fsx_cowextsize; - -if (copy_to_user (ufa, &xfa,sizeof (xfa))) -return -EFAULT ; - -return 0 ; -} -EXPORT_SYMBOL (copy_fsxattr_to_user); - -static int copy_fsxattr_from_user (struct fileattr *fa, -struct fsxattr __user *ufa) -{ -struct fsxattr xfa; - -if (copy_from_user (&xfa, ufa,sizeof (xfa))) -return -EFAULT ; - -fileattr_fill_xflags (fa, xfa.fsx_xflags); - fa->fsx_extsize = xfa.fsx_extsize; - fa->fsx_nextents = xfa.fsx_nextents; - fa->fsx_projid = xfa.fsx_projid; - fa->fsx_cowextsize = xfa.fsx_cowextsize; - -return 0 ; -} - -/* -* Generic function to check FS_IOC_FSSETXATTR/FS_IOC_SETFLAGS values and reject -* any invalid configurations. -* -* Note: must be called with inode lock held. -*/ -static int fileattr_set_prepare (struct inode *inode, -const struct fileattr *old_ma, -struct fileattr *fa) -{ -int err; - -/* -* The IMMUTABLE and APPEND_ONLY flags can only be changed by -* the relevant capability. -*/ -if ((fa->flags ^ old_ma->flags) & (FS_APPEND_FL |FS_IMMUTABLE_FL ) && - !capable (CAP_LINUX_IMMUTABLE )) -return -EPERM ; - - err =fscrypt_prepare_setflags (inode, old_ma->flags, fa->flags); -if (err) -return err; - -/* -* Project Quota ID state is only allowed to change from within the init -* namespace. Enforce that restriction only if we are trying to change -* the quota ID state. Everything else is allowed in user namespaces. -*/ -if (current_user_ns () != &init_user_ns) { -if (old_ma->fsx_projid != fa->fsx_projid) -return -EINVAL ; -if ((old_ma->fsx_xflags ^ fa->fsx_xflags) & -FS_XFLAG_PROJINHERIT ) -return -EINVAL ; - }else { -/* -* Caller is allowed to change the project ID. If it is being -* changed, make sure that the new value is valid. -*/ -if (old_ma->fsx_projid != fa->fsx_projid && - !projid_valid (make_kprojid (&init_user_ns, fa->fsx_projid))) -return -EINVAL ; - } - -/* Check extent size hints. */ -if ((fa->fsx_xflags &FS_XFLAG_EXTSIZE ) && !S_ISREG (inode->i_mode)) -return -EINVAL ; - -if ((fa->fsx_xflags &FS_XFLAG_EXTSZINHERIT ) && - !S_ISDIR (inode->i_mode)) -return -EINVAL ; - -if ((fa->fsx_xflags &FS_XFLAG_COWEXTSIZE ) && - !S_ISREG (inode->i_mode) && !S_ISDIR (inode->i_mode)) -return -EINVAL ; - -/* -* It is only valid to set the DAX flag on regular files and -* directories on filesystems. -*/ -if ((fa->fsx_xflags &FS_XFLAG_DAX ) && - !(S_ISREG (inode->i_mode) ||S_ISDIR (inode->i_mode))) -return -EINVAL ; - -/* Extent size hints of zero turn off the flags. */ -if (fa->fsx_extsize ==0 ) - fa->fsx_xflags &= ~(FS_XFLAG_EXTSIZE |FS_XFLAG_EXTSZINHERIT ); -if (fa->fsx_cowextsize ==0 ) - fa->fsx_xflags &= ~FS_XFLAG_COWEXTSIZE ; - -return 0 ; -} - -/** -* vfs_fileattr_set - change miscellaneous file attributes -* @idmap: idmap of the mount -* @dentry: the object to change -* @fa: fileattr pointer -* -* After verifying permissions, call i_op->fileattr_set() callback, if -* exists. -* -* Verifying attributes involves retrieving current attributes with -* i_op->fileattr_get(), this also allows initializing attributes that have -* not been set by the caller to current values. Inode lock is held -* thoughout to prevent racing with another instance. -* -* Return: 0 on success, or a negative error on failure. -*/ -int vfs_fileattr_set (struct mnt_idmap *idmap,struct dentry *dentry, -struct fileattr *fa) -{ -struct inode *inode =d_inode (dentry); -struct fileattr old_ma = {}; -int err; - -if (!inode->i_op->fileattr_set) -return -ENOIOCTLCMD ; - -if (!inode_owner_or_capable (idmap, inode)) -return -EPERM ; - -inode_lock (inode); - err =vfs_fileattr_get (dentry, &old_ma); -if (!err) { -/* initialize missing bits from old_ma */ -if (fa->flags_valid) { - fa->fsx_xflags |= old_ma.fsx_xflags & ~FS_XFLAG_COMMON ; - fa->fsx_extsize = old_ma.fsx_extsize; - fa->fsx_nextents = old_ma.fsx_nextents; - fa->fsx_projid = old_ma.fsx_projid; - fa->fsx_cowextsize = old_ma.fsx_cowextsize; - }else { - fa->flags |= old_ma.flags & ~FS_COMMON_FL ; - } - err =fileattr_set_prepare (inode, &old_ma, fa); -if (!err) - err = inode->i_op->fileattr_set (idmap, dentry, fa); - } -inode_unlock (inode); - -return err; -} -EXPORT_SYMBOL (vfs_fileattr_set); - -static int ioctl_getflags (struct file *file,unsigned int __user *argp) -{ -struct fileattr fa = { .flags_valid = true };/* hint only */ -int err; - - err =vfs_fileattr_get (file->f_path.dentry, &fa); -if (!err) - err =put_user (fa.flags, argp); -return err; -} - -static int ioctl_setflags (struct file *file,unsigned int __user *argp) -{ -struct mnt_idmap *idmap =file_mnt_idmap (file); -struct dentry *dentry = file->f_path.dentry; -struct fileattr fa; -unsigned int flags; -int err; - - err =get_user (flags, argp); -if (!err) { - err =mnt_want_write_file (file); -if (!err) { -fileattr_fill_flags (&fa, flags); - err =vfs_fileattr_set (idmap, dentry, &fa); -mnt_drop_write_file (file); - } - } -return err; -} - -static int ioctl_fsgetxattr (struct file *file,void __user *argp) -{ -struct fileattr fa = { .fsx_valid = true };/* hint only */ -int err; - - err =vfs_fileattr_get (file->f_path.dentry, &fa); -if (!err) - err =copy_fsxattr_to_user (&fa, argp); - -return err; -} - -static int ioctl_fssetxattr (struct file *file,void __user *argp) -{ -struct mnt_idmap *idmap =file_mnt_idmap (file); -struct dentry *dentry = file->f_path.dentry; -struct fileattr fa; -int err; - - err =copy_fsxattr_from_user (&fa, argp); -if (!err) { - err =mnt_want_write_file (file); -if (!err) { - err =vfs_fileattr_set (idmap, dentry, &fa); -mnt_drop_write_file (file); - } - } -return err; -} -static int ioctl_getfsuuid (struct file *file,void __user *argp) {struct super_block *sb =file_inode (file)->i_sb;include/linux/fileattr.h +4
-0@@ -55,5 +55,9 @@ static inline bool fileattr_has_fsx(const struct fileattr *fa)int vfs_fileattr_get (struct dentry *dentry,struct fileattr *fa);int vfs_fileattr_set (struct mnt_idmap *idmap,struct dentry *dentry,struct fileattr *fa); +int ioctl_getflags (struct file *file,unsigned int __user *argp); +int ioctl_setflags (struct file *file,unsigned int __user *argp); +int ioctl_fsgetxattr (struct file *file,void __user *argp); +int ioctl_fssetxattr (struct file *file,void __user *argp);#endif /* _LINUX_FILEATTR_H */ Signature · 2 lines
-- 2.47.2
PATCH v6 2/6 lsm: introduce new hooks for setting/getting inode fsxattr
In reply to Andrey AlbershteynIntroduce new hooks for setting and getting filesystem extended attributes on inode (FS_IOC_FSGETXATTR).
--- fs/file_attr.c | 19 ++++++++++++++++--- include/linux/lsm_hook_defs.h | 2 ++ include/linux/security.h | 16 ++++++++++++++++ security/security.c | 30 ++++++++++++++++++++++++++++++ 4 files changed, 64 insertions(+), 3 deletions(-)
fs/file_attr.c +16 -3
@@ -76,10 +76,15 @@ EXPORT_SYMBOL(fileattr_fill_flags);int vfs_fileattr_get (struct dentry *dentry,struct fileattr *fa) {struct inode *inode =d_inode (dentry); +int error;if (!inode->i_op->fileattr_get)return -ENOIOCTLCMD ; + error =security_inode_file_getattr (dentry, fa); +if (error) +return error; +return inode->i_op->fileattr_get (dentry, fa); }EXPORT_SYMBOL (vfs_fileattr_get);
@@ -242,12 +247,20 @@ int vfs_fileattr_set(struct mnt_idmap *idmap, struct dentry *dentry, }else { fa->flags |= old_ma.flags & ~FS_COMMON_FL ; } + err =fileattr_set_prepare (inode, &old_ma, fa); -if (!err) - err = inode->i_op->fileattr_set (idmap, dentry, fa); +if (err) + goto out; + err =security_inode_file_setattr (dentry, fa); +if (err) + goto out; + err = inode->i_op->fileattr_set (idmap, dentry, fa); +if (err) + goto out; } + +out:inode_unlock (inode); -return err; }EXPORT_SYMBOL (vfs_fileattr_set);
include/linux/lsm_hook_defs.h +2 -0
@@ -157,6 +157,8 @@ LSM_HOOK(int, 0, inode_removexattr, struct mnt_idmap *idmap, struct dentry *dentry, const char *name) LSM_HOOK(void, LSM_RET_VOID, inode_post_removexattr, struct dentry *dentry, const char *name) +LSM_HOOK(int, 0, inode_file_setattr, struct dentry *dentry, struct fileattr *fa) +LSM_HOOK(int, 0, inode_file_getattr, struct dentry *dentry, struct fileattr *fa) LSM_HOOK(int, 0, inode_set_acl, struct mnt_idmap *idmap, struct dentry *dentry, const char *acl_name, struct posix_acl *kacl) LSM_HOOK(void, LSM_RET_VOID, inode_post_set_acl, struct dentry *dentry,
include/linux/security.h +16 -0
@@ -451,6 +451,10 @@ int security_inode_listxattr(struct dentry *dentry);int security_inode_removexattr (struct mnt_idmap *idmap,struct dentry *dentry,const char *name);void security_inode_post_removexattr (struct dentry *dentry,const char *name); +int security_inode_file_setattr (struct dentry *dentry, +struct fileattr *fa); +int security_inode_file_getattr (struct dentry *dentry, +struct fileattr *fa);int security_inode_need_killpriv (struct dentry *dentry);int security_inode_killpriv (struct mnt_idmap *idmap,struct dentry *dentry); int security_inode_getsecurity(struct mnt_idmap *idmap,
@@ -1052,6 +1056,18 @@ static inline void security_inode_post_removexattr(struct dentry *dentry, const char *name) { } +static inline int security_inode_file_setattr (struct dentry *dentry, +struct fileattr *fa) +{ +return 0 ; +} + +static inline int security_inode_file_getattr (struct dentry *dentry, +struct fileattr *fa) +{ +return 0 ; +} +static inline int security_inode_need_killpriv (struct dentry *dentry) {return cap_inode_need_killpriv (dentry);
security/security.c +30 -0
@@ -2622,6 +2622,36 @@ void security_inode_post_removexattr(struct dentry *dentry, const char *name)call_void_hook (inode_post_removexattr, dentry, name); } +/** +* security_inode_file_setattr() - check if setting fsxattr is allowed +* @dentry: file to set filesystem extended attributes on +* @fa: extended attributes to set on the inode +* +* Called when file_setattr() syscall or FS_IOC_FSSETXATTR ioctl() is called on +* inode +* +* Return: Returns 0 if permission is granted. +*/ +int security_inode_file_setattr (struct dentry *dentry,struct fileattr *fa) +{ +return call_int_hook (inode_file_setattr, dentry, fa); +} + +/** +* security_inode_file_getattr() - check if retrieving fsxattr is allowed +* @dentry: file to retrieve filesystem extended attributes from +* @fa: extended attributes to get +* +* Called when file_getattr() syscall or FS_IOC_FSGETXATTR ioctl() is called on +* inode +* +* Return: Returns 0 if permission is granted. +*/ +int security_inode_file_getattr (struct dentry *dentry,struct fileattr *fa) +{ +return call_int_hook (inode_file_getattr, dentry, fa); +} +/** * security_inode_need_killpriv() - Check if security_inode_killpriv() required * @dentry: associated dentry
Signature · 1 line
2.47.2
Re: [PATCH v6 2/6] lsm: introduce new hooks for setting/getting inode fsxattr
Quoted 8 lines · Andrey Albershteyn
Introduce new hooks for setting and getting filesystem extended attributes on inode (
FS_IOC_FSGETXATTR).Cc Paul Moore <[email protected]>Acked-by Paul Moore <[email protected]>Signed-off-by Andrey Albershteyn <[email protected]>
Looks good. Feel free to add:
Honza
Quoted 143 lines
--- fs/file_attr.c | 19 ++++++++++++++++--- include/linux/lsm_hook_defs.h | 2 ++ include/linux/security.h | 16 ++++++++++++++++ security/security.c | 30 ++++++++++++++++++++++++++++++ 4 files changed, 64 insertions(+), 3 deletions(-)fs/file_attr.c +16
-3@@ -76,10 +76,15 @@ EXPORT_SYMBOL(fileattr_fill_flags);int vfs_fileattr_get (struct dentry *dentry,struct fileattr *fa) {struct inode *inode =d_inode (dentry); +int error;if (!inode->i_op->fileattr_get)return -ENOIOCTLCMD ; + error =security_inode_file_getattr (dentry, fa); +if (error) +return error; +return inode->i_op->fileattr_get (dentry, fa); }EXPORT_SYMBOL (vfs_fileattr_get);@@ -242,12 +247,20 @@ int vfs_fileattr_set(struct mnt_idmap *idmap, struct dentry *dentry, }else { fa->flags |= old_ma.flags & ~FS_COMMON_FL ; } + err =fileattr_set_prepare (inode, &old_ma, fa); -if (!err) - err = inode->i_op->fileattr_set (idmap, dentry, fa); +if (err) + goto out; + err =security_inode_file_setattr (dentry, fa); +if (err) + goto out; + err = inode->i_op->fileattr_set (idmap, dentry, fa); +if (err) + goto out; } + +out:inode_unlock (inode); -return err; }EXPORT_SYMBOL (vfs_fileattr_set);include/linux/lsm_hook_defs.h +2
-0@@ -157,6 +157,8 @@ LSM_HOOK(int, 0, inode_removexattr, struct mnt_idmap *idmap, struct dentry *dentry, const char *name) LSM_HOOK(void, LSM_RET_VOID, inode_post_removexattr, struct dentry *dentry, const char *name) +LSM_HOOK(int, 0, inode_file_setattr, struct dentry *dentry, struct fileattr *fa) +LSM_HOOK(int, 0, inode_file_getattr, struct dentry *dentry, struct fileattr *fa) LSM_HOOK(int, 0, inode_set_acl, struct mnt_idmap *idmap, struct dentry *dentry, const char *acl_name, struct posix_acl *kacl) LSM_HOOK(void, LSM_RET_VOID, inode_post_set_acl, struct dentry *dentry,include/linux/security.h +16
-0@@ -451,6 +451,10 @@ int security_inode_listxattr(struct dentry *dentry);int security_inode_removexattr (struct mnt_idmap *idmap,struct dentry *dentry,const char *name);void security_inode_post_removexattr (struct dentry *dentry,const char *name); +int security_inode_file_setattr (struct dentry *dentry, +struct fileattr *fa); +int security_inode_file_getattr (struct dentry *dentry, +struct fileattr *fa);int security_inode_need_killpriv (struct dentry *dentry);int security_inode_killpriv (struct mnt_idmap *idmap,struct dentry *dentry); int security_inode_getsecurity(struct mnt_idmap *idmap,@@ -1052,6 +1056,18 @@ static inline void security_inode_post_removexattr(struct dentry *dentry, const char *name) { } +static inline int security_inode_file_setattr (struct dentry *dentry, +struct fileattr *fa) +{ +return 0 ; +} + +static inline int security_inode_file_getattr (struct dentry *dentry, +struct fileattr *fa) +{ +return 0 ; +} +static inline int security_inode_need_killpriv (struct dentry *dentry) {return cap_inode_need_killpriv (dentry);security/security.c +30
-0@@ -2622,6 +2622,36 @@ void security_inode_post_removexattr(struct dentry *dentry, const char *name)call_void_hook (inode_post_removexattr, dentry, name); } +/** +* security_inode_file_setattr() - check if setting fsxattr is allowed +* @dentry: file to set filesystem extended attributes on +* @fa: extended attributes to set on the inode +* +* Called when file_setattr() syscall or FS_IOC_FSSETXATTR ioctl() is called on +* inode +* +* Return: Returns 0 if permission is granted. +*/ +int security_inode_file_setattr (struct dentry *dentry,struct fileattr *fa) +{ +return call_int_hook (inode_file_setattr, dentry, fa); +} + +/** +* security_inode_file_getattr() - check if retrieving fsxattr is allowed +* @dentry: file to retrieve filesystem extended attributes from +* @fa: extended attributes to get +* +* Called when file_getattr() syscall or FS_IOC_FSGETXATTR ioctl() is called on +* inode +* +* Return: Returns 0 if permission is granted. +*/ +int security_inode_file_getattr (struct dentry *dentry,struct fileattr *fa) +{ +return call_int_hook (inode_file_getattr, dentry, fa); +} +/** * security_inode_need_killpriv() - Check if security_inode_killpriv() required * @dentry: associated dentry Signature · 2 lines
-- 2.47.2
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Re: [PATCH v6 2/6] lsm: introduce new hooks for setting/getting inode fsxattr
In reply to Andrey AlbershteynQuoted 8 lines · Andrey Albershteyn
Introduce new hooks for setting and getting filesystem extended attributes on inode (
FS_IOC_FSGETXATTR).Cc Paul Moore <[email protected]>Acked-by Paul Moore <[email protected]>Signed-off-by Andrey Albershteyn <[email protected]>
I wonder, were FS_IOC_FS[GS]ETXATTR already covered by the security_file_ioctl hook? If so, will an out of date security policy on a 6.17 kernel now fail to check the new file_[gs]etattr syscalls?
Though AFAICT the future of managing these "extra" file attributes is the system call so it's probably appropriate to have an explicit callout to LSMs.
--D
Quoted 144 lines
--- fs/file_attr.c | 19 ++++++++++++++++--- include/linux/lsm_hook_defs.h | 2 ++ include/linux/security.h | 16 ++++++++++++++++ security/security.c | 30 ++++++++++++++++++++++++++++++ 4 files changed, 64 insertions(+), 3 deletions(-)fs/file_attr.c +16
-3@@ -76,10 +76,15 @@ EXPORT_SYMBOL(fileattr_fill_flags);int vfs_fileattr_get (struct dentry *dentry,struct fileattr *fa) {struct inode *inode =d_inode (dentry); +int error;if (!inode->i_op->fileattr_get)return -ENOIOCTLCMD ; + error =security_inode_file_getattr (dentry, fa); +if (error) +return error; +return inode->i_op->fileattr_get (dentry, fa); }EXPORT_SYMBOL (vfs_fileattr_get);@@ -242,12 +247,20 @@ int vfs_fileattr_set(struct mnt_idmap *idmap, struct dentry *dentry, }else { fa->flags |= old_ma.flags & ~FS_COMMON_FL ; } + err =fileattr_set_prepare (inode, &old_ma, fa); -if (!err) - err = inode->i_op->fileattr_set (idmap, dentry, fa); +if (err) + goto out; + err =security_inode_file_setattr (dentry, fa); +if (err) + goto out; + err = inode->i_op->fileattr_set (idmap, dentry, fa); +if (err) + goto out; } + +out:inode_unlock (inode); -return err; }EXPORT_SYMBOL (vfs_fileattr_set);include/linux/lsm_hook_defs.h +2
-0@@ -157,6 +157,8 @@ LSM_HOOK(int, 0, inode_removexattr, struct mnt_idmap *idmap, struct dentry *dentry, const char *name) LSM_HOOK(void, LSM_RET_VOID, inode_post_removexattr, struct dentry *dentry, const char *name) +LSM_HOOK(int, 0, inode_file_setattr, struct dentry *dentry, struct fileattr *fa) +LSM_HOOK(int, 0, inode_file_getattr, struct dentry *dentry, struct fileattr *fa) LSM_HOOK(int, 0, inode_set_acl, struct mnt_idmap *idmap, struct dentry *dentry, const char *acl_name, struct posix_acl *kacl) LSM_HOOK(void, LSM_RET_VOID, inode_post_set_acl, struct dentry *dentry,include/linux/security.h +16
-0@@ -451,6 +451,10 @@ int security_inode_listxattr(struct dentry *dentry);int security_inode_removexattr (struct mnt_idmap *idmap,struct dentry *dentry,const char *name);void security_inode_post_removexattr (struct dentry *dentry,const char *name); +int security_inode_file_setattr (struct dentry *dentry, +struct fileattr *fa); +int security_inode_file_getattr (struct dentry *dentry, +struct fileattr *fa);int security_inode_need_killpriv (struct dentry *dentry);int security_inode_killpriv (struct mnt_idmap *idmap,struct dentry *dentry); int security_inode_getsecurity(struct mnt_idmap *idmap,@@ -1052,6 +1056,18 @@ static inline void security_inode_post_removexattr(struct dentry *dentry, const char *name) { } +static inline int security_inode_file_setattr (struct dentry *dentry, +struct fileattr *fa) +{ +return 0 ; +} + +static inline int security_inode_file_getattr (struct dentry *dentry, +struct fileattr *fa) +{ +return 0 ; +} +static inline int security_inode_need_killpriv (struct dentry *dentry) {return cap_inode_need_killpriv (dentry);security/security.c +30
-0@@ -2622,6 +2622,36 @@ void security_inode_post_removexattr(struct dentry *dentry, const char *name)call_void_hook (inode_post_removexattr, dentry, name); } +/** +* security_inode_file_setattr() - check if setting fsxattr is allowed +* @dentry: file to set filesystem extended attributes on +* @fa: extended attributes to set on the inode +* +* Called when file_setattr() syscall or FS_IOC_FSSETXATTR ioctl() is called on +* inode +* +* Return: Returns 0 if permission is granted. +*/ +int security_inode_file_setattr (struct dentry *dentry,struct fileattr *fa) +{ +return call_int_hook (inode_file_setattr, dentry, fa); +} + +/** +* security_inode_file_getattr() - check if retrieving fsxattr is allowed +* @dentry: file to retrieve filesystem extended attributes from +* @fa: extended attributes to get +* +* Called when file_getattr() syscall or FS_IOC_FSGETXATTR ioctl() is called on +* inode +* +* Return: Returns 0 if permission is granted. +*/ +int security_inode_file_getattr (struct dentry *dentry,struct fileattr *fa) +{ +return call_int_hook (inode_file_getattr, dentry, fa); +} +/** * security_inode_need_killpriv() - Check if security_inode_killpriv() required * @dentry: associated dentry Signature · 2 lines
-- 2.47.2
Re: [PATCH v6 2/6] lsm: introduce new hooks for setting/getting inode fsxattr
Quoted 4 lines · Darrick J. Wong
Quoted 3 lines · Andrey Albershteyn
Introduce new hooks for setting and getting filesystem extended attributes on inode (
FS_IOC_FSGETXATTR).
Quoted 8 lines
Quoted 5 lines
Cc Paul Moore <[email protected]>Acked-by Paul Moore <[email protected]>Signed-off-by Andrey Albershteyn <[email protected]>I wonder, were FS_IOC_FS[GS]ETXATTR already covered by the
security_file_ioctlhook?
looks like
Quoted 2 lines
If so, will an out of date security policy
on a 6.17 kernel now fail to check the new file_[gs]etattr syscalls?
Yeah, probably, not sure if policies can have 'don't allow unknown' but this is probably will need to be updated in the policy
Quoted 154 lines
Though AFAICT the future of managing these "extra" file attributes is the system call so it's probably appropriate to have an explicit callout to LSMs.
--D
Quoted 144 lines
--- fs/file_attr.c | 19 ++++++++++++++++--- include/linux/lsm_hook_defs.h | 2 ++ include/linux/security.h | 16 ++++++++++++++++ security/security.c | 30 ++++++++++++++++++++++++++++++ 4 files changed, 64 insertions(+), 3 deletions(-)fs/file_attr.c +16
-3@@ -76,10 +76,15 @@ EXPORT_SYMBOL(fileattr_fill_flags);int vfs_fileattr_get (struct dentry *dentry,struct fileattr *fa) {struct inode *inode =d_inode (dentry); +int error;if (!inode->i_op->fileattr_get)return -ENOIOCTLCMD ; + error =security_inode_file_getattr (dentry, fa); +if (error) +return error; +return inode->i_op->fileattr_get (dentry, fa); }EXPORT_SYMBOL (vfs_fileattr_get);@@ -242,12 +247,20 @@ int vfs_fileattr_set(struct mnt_idmap *idmap, struct dentry *dentry, }else { fa->flags |= old_ma.flags & ~FS_COMMON_FL ; } + err =fileattr_set_prepare (inode, &old_ma, fa); -if (!err) - err = inode->i_op->fileattr_set (idmap, dentry, fa); +if (err) + goto out; + err =security_inode_file_setattr (dentry, fa); +if (err) + goto out; + err = inode->i_op->fileattr_set (idmap, dentry, fa); +if (err) + goto out; } + +out:inode_unlock (inode); -return err; }EXPORT_SYMBOL (vfs_fileattr_set);include/linux/lsm_hook_defs.h +2
-0@@ -157,6 +157,8 @@ LSM_HOOK(int, 0, inode_removexattr, struct mnt_idmap *idmap, struct dentry *dentry, const char *name) LSM_HOOK(void, LSM_RET_VOID, inode_post_removexattr, struct dentry *dentry, const char *name) +LSM_HOOK(int, 0, inode_file_setattr, struct dentry *dentry, struct fileattr *fa) +LSM_HOOK(int, 0, inode_file_getattr, struct dentry *dentry, struct fileattr *fa) LSM_HOOK(int, 0, inode_set_acl, struct mnt_idmap *idmap, struct dentry *dentry, const char *acl_name, struct posix_acl *kacl) LSM_HOOK(void, LSM_RET_VOID, inode_post_set_acl, struct dentry *dentry,include/linux/security.h +16
-0@@ -451,6 +451,10 @@ int security_inode_listxattr(struct dentry *dentry);int security_inode_removexattr (struct mnt_idmap *idmap,struct dentry *dentry,const char *name);void security_inode_post_removexattr (struct dentry *dentry,const char *name); +int security_inode_file_setattr (struct dentry *dentry, +struct fileattr *fa); +int security_inode_file_getattr (struct dentry *dentry, +struct fileattr *fa);int security_inode_need_killpriv (struct dentry *dentry);int security_inode_killpriv (struct mnt_idmap *idmap,struct dentry *dentry); int security_inode_getsecurity(struct mnt_idmap *idmap,@@ -1052,6 +1056,18 @@ static inline void security_inode_post_removexattr(struct dentry *dentry, const char *name) { } +static inline int security_inode_file_setattr (struct dentry *dentry, +struct fileattr *fa) +{ +return 0 ; +} + +static inline int security_inode_file_getattr (struct dentry *dentry, +struct fileattr *fa) +{ +return 0 ; +} +static inline int security_inode_need_killpriv (struct dentry *dentry) {return cap_inode_need_killpriv (dentry);security/security.c +30
-0@@ -2622,6 +2622,36 @@ void security_inode_post_removexattr(struct dentry *dentry, const char *name)call_void_hook (inode_post_removexattr, dentry, name); } +/** +* security_inode_file_setattr() - check if setting fsxattr is allowed +* @dentry: file to set filesystem extended attributes on +* @fa: extended attributes to set on the inode +* +* Called when file_setattr() syscall or FS_IOC_FSSETXATTR ioctl() is called on +* inode +* +* Return: Returns 0 if permission is granted. +*/ +int security_inode_file_setattr (struct dentry *dentry,struct fileattr *fa) +{ +return call_int_hook (inode_file_setattr, dentry, fa); +} + +/** +* security_inode_file_getattr() - check if retrieving fsxattr is allowed +* @dentry: file to retrieve filesystem extended attributes from +* @fa: extended attributes to get +* +* Called when file_getattr() syscall or FS_IOC_FSGETXATTR ioctl() is called on +* inode +* +* Return: Returns 0 if permission is granted. +*/ +int security_inode_file_getattr (struct dentry *dentry,struct fileattr *fa) +{ +return call_int_hook (inode_file_getattr, dentry, fa); +} +/** * security_inode_need_killpriv() - Check if security_inode_killpriv() required * @dentry: associated dentry Signature · 2 lines
-- 2.47.2
Signature · 1 line
- Andrey
PATCH v6 3/6 selinux: implement inode_file_[g|s]etattr hooks
In reply to Andrey AlbershteynThese hooks are called on inode extended attribute retrieval/change.
--- security/selinux/hooks.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
security/selinux/hooks.c +14 -0
@@ -3480,6 +3480,18 @@ static int selinux_inode_removexattr(struct mnt_idmap *idmap,return -EACCES ; } +static int selinux_inode_file_setattr (struct dentry *dentry, +struct fileattr *fa) +{ +return dentry_has_perm (current_cred (), dentry,FILE__SETATTR ); +} + +static int selinux_inode_file_getattr (struct dentry *dentry, +struct fileattr *fa) +{ +return dentry_has_perm (current_cred (), dentry,FILE__GETATTR ); +} +static int selinux_path_notify (const struct path *path,u64 mask,unsigned int obj_type) {
@@ -7350,6 +7362,8 @@ static struct security_hook_list selinux_hooks[] __ro_after_init = {LSM_HOOK_INIT (inode_getxattr, selinux_inode_getxattr),LSM_HOOK_INIT (inode_listxattr, selinux_inode_listxattr),LSM_HOOK_INIT (inode_removexattr, selinux_inode_removexattr), +LSM_HOOK_INIT (inode_file_getattr, selinux_inode_file_getattr), +LSM_HOOK_INIT (inode_file_setattr, selinux_inode_file_setattr),LSM_HOOK_INIT (inode_set_acl, selinux_inode_set_acl),LSM_HOOK_INIT (inode_get_acl, selinux_inode_get_acl), LSM_HOOK_INIT(inode_remove_acl, selinux_inode_remove_acl),
Signature · 1 line
2.47.2
PATCH v6 4/6 fs: make vfs_fileattr_[get|set] return -EOPNOSUPP
In reply to Andrey AlbershteynFuture patches will add new syscalls which use these functions. As this interface won't be used for ioctls only, the EOPNOSUPP is more appropriate return code.
This patch converts return code from ENOIOCTLCMD to EOPNOSUPP for vfs_fileattr_get and vfs_fileattr_set. To save old behavior translate EOPNOSUPP back for current users - overlayfs, encryptfs and fs/ioctl.c.
--- fs/ecryptfs/inode.c | 8 +++++++- fs/file_attr.c | 12 ++++++++++-- fs/overlayfs/inode.c | 2 +- 3 files changed, 18 insertions(+), 4 deletions(-)
fs/ecryptfs/inode.c +7 -1
@@ -1126,7 +1126,13 @@ static int ecryptfs_removexattr(struct dentry *dentry, struct inode *inode,static int ecryptfs_fileattr_get (struct dentry *dentry,struct fileattr *fa) { -return vfs_fileattr_get (ecryptfs_dentry_to_lower (dentry), fa); +int rc; + + rc =vfs_fileattr_get (ecryptfs_dentry_to_lower (dentry), fa); +if (rc == -EOPNOTSUPP ) + rc = -ENOIOCTLCMD ; + +return rc; } static int ecryptfs_fileattr_set(struct mnt_idmap *idmap,
fs/file_attr.c +10 -2
@@ -79,7 +79,7 @@ int vfs_fileattr_get(struct dentry *dentry, struct fileattr *fa)int error;if (!inode->i_op->fileattr_get) -return -ENOIOCTLCMD ; +return -EOPNOTSUPP ; error =security_inode_file_getattr (dentry, fa);if (error)
@@ -229,7 +229,7 @@ int vfs_fileattr_set(struct mnt_idmap *idmap, struct dentry *dentry,int err;if (!inode->i_op->fileattr_set) -return -ENOIOCTLCMD ; +return -EOPNOTSUPP ;if (!inode_owner_or_capable (idmap, inode))return -EPERM ;
@@ -271,6 +271,8 @@ int ioctl_getflags(struct file *file, unsigned int __user *argp)int err; err =vfs_fileattr_get (file->f_path.dentry, &fa); +if (err == -EOPNOTSUPP ) + err = -ENOIOCTLCMD ;if (!err) err =put_user (fa.flags, argp);return err;
@@ -292,6 +294,8 @@ int ioctl_setflags(struct file *file, unsigned int __user *argp)fileattr_fill_flags (&fa, flags); err =vfs_fileattr_set (idmap, dentry, &fa);mnt_drop_write_file (file); +if (err == -EOPNOTSUPP ) + err = -ENOIOCTLCMD ; } }return err;
@@ -304,6 +308,8 @@ int ioctl_fsgetxattr(struct file *file, void __user *argp)int err; err =vfs_fileattr_get (file->f_path.dentry, &fa); +if (err == -EOPNOTSUPP ) + err = -ENOIOCTLCMD ;if (!err) err =copy_fsxattr_to_user (&fa, argp);
@@ -324,6 +330,8 @@ int ioctl_fssetxattr(struct file *file, void __user *argp)if (!err) { err =vfs_fileattr_set (idmap, dentry, &fa);mnt_drop_write_file (file); +if (err == -EOPNOTSUPP ) + err = -ENOIOCTLCMD ; } }return err;
fs/overlayfs/inode.c +1 -1
@@ -721,7 +721,7 @@ int ovl_real_fileattr_get(const struct path *realpath, struct fileattr *fa)return err; err =vfs_fileattr_get (realpath->dentry, fa); -if (err == -ENOIOCTLCMD ) +if (err == -EOPNOTSUPP ) err = -ENOTTY ;return err; }
Signature · 1 line
2.47.2
Re: [PATCH v6 4/6] fs: make vfs_fileattr_[get|set] return -EOPNOSUPP
nit: typo in commit subject and description: Missing T in EOPNO*T*SUPP. But please do not resend whole patch series just because of this. That is not needed.
Quoted 109 lines · On Monday 30 June 2025 18:20:14 Andrey Albershteyn wrote:
Future patches will add new syscalls which use these functions. As this interface won't be used for ioctls only, the EOPNOSUPP is more appropriate return code.
This patch converts return code from ENOIOCTLCMD to EOPNOSUPP for
vfs_fileattr_getandvfs_fileattr_set. To save old behavior translate EOPNOSUPP back for current users - overlayfs, encryptfs andfs/ioctl.c.Signed-off-by Andrey Albershteyn <[email protected]>--- fs/ecryptfs/inode.c | 8 +++++++- fs/file_attr.c | 12 ++++++++++-- fs/overlayfs/inode.c | 2 +- 3 files changed, 18 insertions(+), 4 deletions(-)fs/ecryptfs/inode.c +7
-1@@ -1126,7 +1126,13 @@ static int ecryptfs_removexattr(struct dentry *dentry, struct inode *inode,static int ecryptfs_fileattr_get (struct dentry *dentry,struct fileattr *fa) { -return vfs_fileattr_get (ecryptfs_dentry_to_lower (dentry), fa); +int rc; + + rc =vfs_fileattr_get (ecryptfs_dentry_to_lower (dentry), fa); +if (rc == -EOPNOTSUPP ) + rc = -ENOIOCTLCMD ; + +return rc; } static int ecryptfs_fileattr_set(struct mnt_idmap *idmap,fs/file_attr.c +10
-2@@ -79,7 +79,7 @@ int vfs_fileattr_get(struct dentry *dentry, struct fileattr *fa)int error;if (!inode->i_op->fileattr_get) -return -ENOIOCTLCMD ; +return -EOPNOTSUPP ; error =security_inode_file_getattr (dentry, fa);if (error)@@ -229,7 +229,7 @@ int vfs_fileattr_set(struct mnt_idmap *idmap, struct dentry *dentry,int err;if (!inode->i_op->fileattr_set) -return -ENOIOCTLCMD ; +return -EOPNOTSUPP ;if (!inode_owner_or_capable (idmap, inode))return -EPERM ;@@ -271,6 +271,8 @@ int ioctl_getflags(struct file *file, unsigned int __user *argp)int err; err =vfs_fileattr_get (file->f_path.dentry, &fa); +if (err == -EOPNOTSUPP ) + err = -ENOIOCTLCMD ;if (!err) err =put_user (fa.flags, argp);return err;@@ -292,6 +294,8 @@ int ioctl_setflags(struct file *file, unsigned int __user *argp)fileattr_fill_flags (&fa, flags); err =vfs_fileattr_set (idmap, dentry, &fa);mnt_drop_write_file (file); +if (err == -EOPNOTSUPP ) + err = -ENOIOCTLCMD ; } }return err;@@ -304,6 +308,8 @@ int ioctl_fsgetxattr(struct file *file, void __user *argp)int err; err =vfs_fileattr_get (file->f_path.dentry, &fa); +if (err == -EOPNOTSUPP ) + err = -ENOIOCTLCMD ;if (!err) err =copy_fsxattr_to_user (&fa, argp);@@ -324,6 +330,8 @@ int ioctl_fssetxattr(struct file *file, void __user *argp)if (!err) { err =vfs_fileattr_set (idmap, dentry, &fa);mnt_drop_write_file (file); +if (err == -EOPNOTSUPP ) + err = -ENOIOCTLCMD ; } }return err;fs/overlayfs/inode.c +1
-1@@ -721,7 +721,7 @@ int ovl_real_fileattr_get(const struct path *realpath, struct fileattr *fa)return err; err =vfs_fileattr_get (realpath->dentry, fa); -if (err == -ENOIOCTLCMD ) +if (err == -EOPNOTSUPP ) err = -ENOTTY ;return err; }Signature · 2 lines
-- 2.47.2
Amir Goldstein
maintainerRe: [PATCH v6 4/6] fs: make vfs_fileattr_[get|set] return -EOPNOSUPP
In reply to Andrey AlbershteynQuoted 24 lines · Andrey Albershteyn
Future patches will add new syscalls which use these functions. As this interface won't be used for ioctls only, the EOPNOSUPP is more appropriate return code.
This patch converts return code from ENOIOCTLCMD to EOPNOSUPP for
vfs_fileattr_getandvfs_fileattr_set. To save old behavior translate EOPNOSUPP back for current users - overlayfs, encryptfs andfs/ioctl.c.Signed-off-by Andrey Albershteyn <[email protected]>--- fs/ecryptfs/inode.c | 8 +++++++- fs/file_attr.c | 12 ++++++++++-- fs/overlayfs/inode.c | 2 +- 3 files changed, 18 insertions(+), 4 deletions(-)fs/ecryptfs/inode.c +0
-0@@ -1126,7 +1126,13 @@ static int ecryptfs_removexattr(struct dentry *dentry, struct inode *inode,static int ecryptfs_fileattr_get (struct dentry *dentry,struct fileattr *fa) {
fs/ecryptfs/inode.c static int ecryptfs_removexattr(struct dentry *dentry, struct inode *inode, · line 1137
Quoted 10 lines
fs/ecryptfs/inode.c +7
-1-return vfs_fileattr_get (ecryptfs_dentry_to_lower (dentry), fa); +int rc; + + rc =vfs_fileattr_get (ecryptfs_dentry_to_lower (dentry), fa); +if (rc == -EOPNOTSUPP ) + rc = -ENOIOCTLCMD ; + +return rc; }
I think the semantics should be
"This patch converts return code of vfs_fileattr_[gs]et and ->fileattr_[gs]et() from ENOIOCTLCMD to EOPNOSUPP"
ENOIOCTLCMD belongs only in the ioctl frontend, so above conversion is not needed.
Quoted 64 lines
fs/ecryptfs/inode.c +0
-0static int ecryptfs_fileattr_set(struct mnt_idmap *idmap,fs/file_attr.c +10
-2@@ -79,7 +79,7 @@ int vfs_fileattr_get(struct dentry *dentry, struct fileattr *fa)int error;if (!inode->i_op->fileattr_get) -return -ENOIOCTLCMD ; +return -EOPNOTSUPP ; error =security_inode_file_getattr (dentry, fa);if (error)@@ -229,7 +229,7 @@ int vfs_fileattr_set(struct mnt_idmap *idmap, struct dentry *dentry,int err;if (!inode->i_op->fileattr_set) -return -ENOIOCTLCMD ; +return -EOPNOTSUPP ;if (!inode_owner_or_capable (idmap, inode))return -EPERM ;@@ -271,6 +271,8 @@ int ioctl_getflags(struct file *file, unsigned int __user *argp)int err; err =vfs_fileattr_get (file->f_path.dentry, &fa); +if (err == -EOPNOTSUPP ) + err = -ENOIOCTLCMD ;if (!err) err =put_user (fa.flags, argp);return err;@@ -292,6 +294,8 @@ int ioctl_setflags(struct file *file, unsigned int __user *argp)fileattr_fill_flags (&fa, flags); err =vfs_fileattr_set (idmap, dentry, &fa);mnt_drop_write_file (file); +if (err == -EOPNOTSUPP ) + err = -ENOIOCTLCMD ; } }return err;@@ -304,6 +308,8 @@ int ioctl_fsgetxattr(struct file *file, void __user *argp)int err; err =vfs_fileattr_get (file->f_path.dentry, &fa); +if (err == -EOPNOTSUPP ) + err = -ENOIOCTLCMD ;if (!err) err =copy_fsxattr_to_user (&fa, argp);@@ -324,6 +330,8 @@ int ioctl_fssetxattr(struct file *file, void __user *argp)if (!err) { err =vfs_fileattr_set (idmap, dentry, &fa);mnt_drop_write_file (file); +if (err == -EOPNOTSUPP ) + err = -ENOIOCTLCMD ; } }return err;fs/overlayfs/inode.c +0
-0
fs/overlayfs/inode.c int ovl_real_fileattr_get(const struct path *realpath, struct fileattr *fa) · line 727
Quoted 8 lines
fs/overlayfs/inode.c +1
-1@@ -721,7 +721,7 @@ int ovl_real_fileattr_get(const struct path *realpath, struct fileattr *fa)return err; err =vfs_fileattr_get (realpath->dentry, fa); -if (err == -ENOIOCTLCMD ) +if (err == -EOPNOTSUPP ) err = -ENOTTY ;return err; }
That's the wrong way, because it hides the desired -EOPNOTSUPP return code from ovl_fileattr_get().
The conversion to -ENOTTY was done for 5b0a414d06c3 ("ovl: fix filattr copy-up failure"), so please do this instead:
fs/overlayfs/inode.c +0 -0
@@ -722,7 +722,7 @@ int ovl_real_fileattr_get(const struct path
*realpath, struct fileattr *fa)
err = vfs_fileattr_get(realpath->dentry, fa);
if (err == -ENOIOCTLCMD)
- err = -ENOTTY;
+ err = -EOPNOTSUPP;
return err;}
fs/overlayfs/copy_up.c +0 -0
@@ -178,7 +178,7 @@ static int ovl_copy_fileattr(struct inode *inode,
const struct path *old,
err = ovl_real_fileattr_get(old, &oldfa);
if (err) {
/* Ntfs-3g returns -EINVAL for "no fileattr support" */
- if (err == -ENOTTY || err == -EINVAL)
+ if (err == -ENOTTY || err == -EINVAL || err == -EOPNOTSUPP)
return 0;
pr_warn("failed to retrieve lower fileattr (%pd2, err=%i)\n",
old->dentry, err);Thanks,
Amir.
Jan Kara
maintainerRe: [PATCH v6 4/6] fs: make vfs_fileattr_[get|set] return -EOPNOSUPP
Quoted 11 lines · Amir Goldstein
Quoted 10 lines · Andrey Albershteyn
Future patches will add new syscalls which use these functions. As this interface won't be used for ioctls only, the EOPNOSUPP is more appropriate return code.
This patch converts return code from ENOIOCTLCMD to EOPNOSUPP for
vfs_fileattr_getandvfs_fileattr_set. To save old behavior translate EOPNOSUPP back for current users - overlayfs, encryptfs andfs/ioctl.c.Signed-off-by Andrey Albershteyn <[email protected]>
...
Quoted 22 lines
fs/overlayfs/inode.c int ovl_real_fileattr_get(const struct path *realpath, struct fileattr *fa) · line 727
Quoted 11 lines
fs/overlayfs/inode.c +1
-1@@ -721,7 +721,7 @@ int ovl_real_fileattr_get(const struct path *realpath, struct fileattr *fa)return err; err =vfs_fileattr_get (realpath->dentry, fa); -if (err == -ENOIOCTLCMD ) +if (err == -EOPNOTSUPP ) err = -ENOTTY ;return err; }That's the wrong way, because it hides the desired
-EOPNOTSUPPreturn code fromovl_fileattr_get().The conversion to
-ENOTTYwas done for5b0a414d06c3("ovl: fix filattr copy-up failure"), so please do this instead:
fs/overlayfs/inode.c int ovl_real_fileattr_get(const struct path · line 726
Quoted 6 lines
fs/overlayfs/inode.c +1
-1@@ -722,7 +722,7 @@ int ovl_real_fileattr_get(const struct path *realpath, struct fileattr *fa) err =vfs_fileattr_get (realpath->dentry, fa);if (err == -ENOIOCTLCMD ) - err = -ENOTTY ; + err = -EOPNOTSUPP ;
Is this really needed? AFAICS nobody returns ENOIOCTLCMD after this patch...
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Amir Goldstein
maintainerRe: [PATCH v6 4/6] fs: make vfs_fileattr_[get|set] return -EOPNOSUPP
Quoted 38 lines · Jan Kara
Quoted 11 lines · Amir Goldstein
Quoted 10 lines · Andrey Albershteyn
Future patches will add new syscalls which use these functions. As this interface won't be used for ioctls only, the EOPNOSUPP is more appropriate return code.
This patch converts return code from ENOIOCTLCMD to EOPNOSUPP for
vfs_fileattr_getandvfs_fileattr_set. To save old behavior translate EOPNOSUPP back for current users - overlayfs, encryptfs andfs/ioctl.c.Signed-off-by Andrey Albershteyn <[email protected]>...
Quoted 24 lines
fs/overlayfs/inode.c int ovl_real_fileattr_get(const struct path *realpath, struct fileattr *fa) · line 727
Quoted 11 lines
fs/overlayfs/inode.c +1
-1@@ -721,7 +721,7 @@ int ovl_real_fileattr_get(const struct path *realpath, struct fileattr *fa)return err; err =vfs_fileattr_get (realpath->dentry, fa); -if (err == -ENOIOCTLCMD ) +if (err == -EOPNOTSUPP ) err = -ENOTTY ;return err; }That's the wrong way, because it hides the desired
-EOPNOTSUPPreturn code fromovl_fileattr_get().The conversion to
-ENOTTYwas done for5b0a414d06c3("ovl: fix filattr copy-up failure"), so please do this instead:fs/overlayfs/inode.c +0
-0@@ -722,7 +722,7 @@ int ovl_real_fileattr_get(const struct path *realpath, struct fileattr *fa)
Quoted 7 lines
fs/overlayfs/inode.c int ovl_real_fileattr_get(const struct path · line 726
Quoted 4 lines
fs/overlayfs/inode.c +1
-1err =vfs_fileattr_get (realpath->dentry, fa);if (err == -ENOIOCTLCMD ) - err = -ENOTTY ; + err = -EOPNOTSUPP ;Is this really needed? AFAICS nobody returns ENOIOCTLCMD after this patch...
you are right it is not needed
Attaching the patch with missing bits of fuse and overlayfs to make this conversion complete.
Christian, please squash my patch
and afterward make sure there is no conversion remaining in ovl_real_fileattr_get() as well as in ecryptfs_fileattr_get() Both those helpers should return the value they
got from vfs_fileattr_get() as is.
Thanks,
Amir.
From 85d097f639518670c57827513b02f497950071de Mon Sep 17 00:00:00 2001
From: Amir Goldstein <[email protected]>
Date: Tue, 1 Jul 2025 16:06:44 +0200
Subject: [PATCH] fuse: return -EOPNOTSUPP from ->fileattr_[gs]et() instead of
-ENOTTY
As part of changing calling convenstion of ->fileattr_[gs]et() to return -EOPNOTSUPP and fix related overlayfs code.
--- fs/fuse/ioctl.c | 4 ++++ fs/overlayfs/copy_up.c | 2 +- fs/overlayfs/inode.c | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-)
fs/fuse/ioctl.c +4 -0
@@ -536,6 +536,8 @@ int fuse_fileattr_get(struct dentry *dentry, struct fileattr *fa) cleanup:fuse_priv_ioctl_cleanup (inode, ff); +if (err == -ENOTTY ) + err = -EOPNOTSUPP ;return err; }
@@ -572,5 +574,7 @@ int fuse_fileattr_set(struct mnt_idmap *idmap, cleanup:fuse_priv_ioctl_cleanup (inode, ff); +if (err == -ENOTTY ) + err = -EOPNOTSUPP ;return err; }
fs/overlayfs/copy_up.c +1 -1
@@ -178,7 +178,7 @@ static int ovl_copy_fileattr(struct inode *inode, const struct path *old, err =ovl_real_fileattr_get (old, &oldfa);if (err) {/* Ntfs-3g returns -EINVAL for "no fileattr support" */ -if (err == -ENOTTY || err == -EINVAL ) +if (err == -EOPNOTSUPP || err == -EINVAL )return 0 ;pr_warn ("failed to retrieve lower fileattr (%pd2, err=%i)\n" , old->dentry, err);
fs/overlayfs/inode.c +1 -1
@@ -722,7 +722,7 @@ int ovl_real_fileattr_get(const struct path *realpath, struct fileattr *fa) err =vfs_fileattr_get (realpath->dentry, fa);if (err == -ENOIOCTLCMD ) - err = -ENOTTY ; + err = -EOPNOTSUPP ;return err; }
Signature · 1 line
2.43.0
Re: [PATCH v6 4/6] fs: make vfs_fileattr_[get|set] return -EOPNOSUPP
In reply to Andrey AlbershteynQuoted 9 lines · Andrey Albershteyn
Future patches will add new syscalls which use these functions. As this interface won't be used for ioctls only, the EOPNOSUPP is more appropriate return code.
This patch converts return code from ENOIOCTLCMD to EOPNOSUPP for
vfs_fileattr_getandvfs_fileattr_set. To save old behavior translate EOPNOSUPP back for current users - overlayfs, encryptfs andfs/ioctl.c.Signed-off-by Andrey Albershteyn <[email protected]>
Modulo the small nits already pointed out this looks good to me. Feel free to add:
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Re: [PATCH v6 4/6] fs: make vfs_fileattr_[get|set] return -EOPNOSUPP
In reply to Andrey AlbershteynQuoted 9 lines · Andrey Albershteyn
Future patches will add new syscalls which use these functions. As this interface won't be used for ioctls only, the EOPNOSUPP is more appropriate return code.
This patch converts return code from ENOIOCTLCMD to EOPNOSUPP for
vfs_fileattr_getandvfs_fileattr_set. To save old behavior translate EOPNOSUPP back for current users - overlayfs, encryptfs andfs/ioctl.c.Signed-off-by Andrey Albershteyn <[email protected]>
With EOPNOSUPP -> EOPNOTSUPP corrected,
--D
Quoted 101 lines
--- fs/ecryptfs/inode.c | 8 +++++++- fs/file_attr.c | 12 ++++++++++-- fs/overlayfs/inode.c | 2 +- 3 files changed, 18 insertions(+), 4 deletions(-)fs/ecryptfs/inode.c +7
-1@@ -1126,7 +1126,13 @@ static int ecryptfs_removexattr(struct dentry *dentry, struct inode *inode,static int ecryptfs_fileattr_get (struct dentry *dentry,struct fileattr *fa) { -return vfs_fileattr_get (ecryptfs_dentry_to_lower (dentry), fa); +int rc; + + rc =vfs_fileattr_get (ecryptfs_dentry_to_lower (dentry), fa); +if (rc == -EOPNOTSUPP ) + rc = -ENOIOCTLCMD ; + +return rc; } static int ecryptfs_fileattr_set(struct mnt_idmap *idmap,fs/file_attr.c +10
-2@@ -79,7 +79,7 @@ int vfs_fileattr_get(struct dentry *dentry, struct fileattr *fa)int error;if (!inode->i_op->fileattr_get) -return -ENOIOCTLCMD ; +return -EOPNOTSUPP ; error =security_inode_file_getattr (dentry, fa);if (error)@@ -229,7 +229,7 @@ int vfs_fileattr_set(struct mnt_idmap *idmap, struct dentry *dentry,int err;if (!inode->i_op->fileattr_set) -return -ENOIOCTLCMD ; +return -EOPNOTSUPP ;if (!inode_owner_or_capable (idmap, inode))return -EPERM ;@@ -271,6 +271,8 @@ int ioctl_getflags(struct file *file, unsigned int __user *argp)int err; err =vfs_fileattr_get (file->f_path.dentry, &fa); +if (err == -EOPNOTSUPP ) + err = -ENOIOCTLCMD ;if (!err) err =put_user (fa.flags, argp);return err;@@ -292,6 +294,8 @@ int ioctl_setflags(struct file *file, unsigned int __user *argp)fileattr_fill_flags (&fa, flags); err =vfs_fileattr_set (idmap, dentry, &fa);mnt_drop_write_file (file); +if (err == -EOPNOTSUPP ) + err = -ENOIOCTLCMD ; } }return err;@@ -304,6 +308,8 @@ int ioctl_fsgetxattr(struct file *file, void __user *argp)int err; err =vfs_fileattr_get (file->f_path.dentry, &fa); +if (err == -EOPNOTSUPP ) + err = -ENOIOCTLCMD ;if (!err) err =copy_fsxattr_to_user (&fa, argp);@@ -324,6 +330,8 @@ int ioctl_fssetxattr(struct file *file, void __user *argp)if (!err) { err =vfs_fileattr_set (idmap, dentry, &fa);mnt_drop_write_file (file); +if (err == -EOPNOTSUPP ) + err = -ENOIOCTLCMD ; } }return err;fs/overlayfs/inode.c +1
-1@@ -721,7 +721,7 @@ int ovl_real_fileattr_get(const struct path *realpath, struct fileattr *fa)return err; err =vfs_fileattr_get (realpath->dentry, fa); -if (err == -ENOIOCTLCMD ) +if (err == -EOPNOTSUPP ) err = -ENOTTY ;return err; }Signature · 2 lines
-- 2.47.2
Re: [PATCH v6 4/6] fs: make vfs_fileattr_[get|set] return -EOPNOSUPP
In reply to Andrey AlbershteynQuoted 9 lines · Andrey Albershteyn
Future patches will add new syscalls which use these functions. As this interface won't be used for ioctls only, the EOPNOSUPP is more appropriate return code.
This patch converts return code from ENOIOCTLCMD to EOPNOSUPP for
vfs_fileattr_getandvfs_fileattr_set. To save old behavior translate EOPNOSUPP back for current users - overlayfs, encryptfs andfs/ioctl.c.Signed-off-by Andrey Albershteyn <[email protected]>
...
fs/file_attr.c int ioctl_setflags(struct file *file, unsigned int __user *argp) · line 298
Quoted 6 lines
fs/file_attr.c +2
-0@@ -292,6 +294,8 @@ int ioctl_setflags(struct file *file, unsigned int __user *argp)fileattr_fill_flags (&fa, flags); err =vfs_fileattr_set (idmap, dentry, &fa);mnt_drop_write_file (file); +if (err == -EOPNOTSUPP ) + err = -ENOIOCTLCMD ;
This breaks borg code (unit tests already) as it expects EOPNOTSUPP, not ENOIOCTLCMD/ENOTTY:
https://github.com/borgbackup/borg/blob/1c6ef7a200c7f72f8d1204d727fea32168616ceb/src/borg/platform/linux.pyx#L147
I.e. setflags now returns ENOIOCTLCMD/ENOTTY for cases where 6.16 used to return EOPNOTSUPP.
This minimal testcase program doing ioctl(fd2, FS_IOC_SETFLAGS, &FS_NODUMP_FL):
https://github.com/jirislaby/collected_sources/tree/master/ioctl_setflags
dumps in 6.16:
sf: ioctl: Operation not supported
with the above patch:
sf: ioctl: Inappropriate ioctl for device
Is this expected?
thanks,
Signature · 2 lines
js suse labs
Arnd Bergmann
maintainerRe: [PATCH v6 4/6] fs: make vfs_fileattr_[get|set] return -EOPNOSUPP
Quoted 9 lines · Jiri Slaby
Quoted 8 lines · Andrey Albershteyn
Future patches will add new syscalls which use these functions. As this interface won't be used for ioctls only, the EOPNOSUPP is more appropriate return code.
This patch converts return code from ENOIOCTLCMD to EOPNOSUPP for
vfs_fileattr_getandvfs_fileattr_set. To save old behavior translate EOPNOSUPP back for current users - overlayfs, encryptfs andfs/ioctl.c.
...
Quoted 8 lines
dumps in 6.16:
sf: ioctl: Operation not supportedwith the above patch:
sf: ioctl: Inappropriate ioctl for deviceIs this expected?
This does look like an unintentional bug: As far as I can see, the -ENOIOCTLCMD was previously used to indicate that a particular filesystem does not have a fileattr_{get,set} callback at all, while individual filesystems used EOPNOSUPP to indicate that a particular attribute flag is unsupported. With the double conversion, both error codes get turned into a single one.
Arnd
Jan Kara
maintainerRe: [PATCH v6 4/6] fs: make vfs_fileattr_[get|set] return -EOPNOSUPP
In reply to Jiri SlabyQuoted 29 lines · Jiri Slaby
Quoted 9 lines · Andrey Albershteyn
Future patches will add new syscalls which use these functions. As this interface won't be used for ioctls only, the EOPNOSUPP is more appropriate return code.
This patch converts return code from ENOIOCTLCMD to EOPNOSUPP for
vfs_fileattr_getandvfs_fileattr_set. To save old behavior translate EOPNOSUPP back for current users - overlayfs, encryptfs andfs/ioctl.c.Signed-off-by Andrey Albershteyn <[email protected]>...
fs/file_attr.c int ioctl_setflags(struct file *file, unsigned int __user *argp) · line 298
Quoted 6 lines
fs/file_attr.c +2
-0@@ -292,6 +294,8 @@ int ioctl_setflags(struct file *file, unsigned int __user *argp)fileattr_fill_flags (&fa, flags); err =vfs_fileattr_set (idmap, dentry, &fa);mnt_drop_write_file (file); +if (err == -EOPNOTSUPP ) + err = -ENOIOCTLCMD ;This breaks borg code (unit tests already) as it expects EOPNOTSUPP, not ENOIOCTLCMD/ENOTTY:
https://github.com/borgbackup/borg/blob/1c6ef7a200c7f72f8d1204d727fea32168616ceb/src/borg/platform/linux.pyx#L147I.e. setflags now returns ENOIOCTLCMD/ENOTTY for cases where 6.16 used to return EOPNOTSUPP.
This minimal testcase program doing
ioctl(fd2, FS_IOC_SETFLAGS, &FS_NODUMP_FL):
https://github.com/jirislaby/collected_sources/tree/master/ioctl_setflags
Quoted 7 lines
dumps in 6.16:
sf: ioctl: Operation not supportedwith the above patch:
sf: ioctl: Inappropriate ioctl for deviceIs this expected?
No, that's a bug and a clear userspace regression so we need to fix it. I think we need to revert this commit and instead convert ENOIOCTLCMD from vfs_fileattr_get/set() to EOPNOTSUPP in appropriate places. Andrey?
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Re: [PATCH v6 4/6] fs: make vfs_fileattr_[get|set] return -EOPNOSUPP
Quoted 33 lines · Jan Kara
Quoted 32 lines · Jiri Slaby
Quoted 9 lines · Andrey Albershteyn
Future patches will add new syscalls which use these functions. As this interface won't be used for ioctls only, the EOPNOSUPP is more appropriate return code.
This patch converts return code from ENOIOCTLCMD to EOPNOSUPP for
vfs_fileattr_getandvfs_fileattr_set. To save old behavior translate EOPNOSUPP back for current users - overlayfs, encryptfs andfs/ioctl.c.Signed-off-by Andrey Albershteyn <[email protected]>...
fs/file_attr.c int ioctl_setflags(struct file *file, unsigned int __user *argp) · line 298
Quoted 6 lines
fs/file_attr.c +2
-0@@ -292,6 +294,8 @@ int ioctl_setflags(struct file *file, unsigned int __user *argp)fileattr_fill_flags (&fa, flags); err =vfs_fileattr_set (idmap, dentry, &fa);mnt_drop_write_file (file); +if (err == -EOPNOTSUPP ) + err = -ENOIOCTLCMD ;This breaks borg code (unit tests already) as it expects EOPNOTSUPP, not ENOIOCTLCMD/ENOTTY:
https://github.com/borgbackup/borg/blob/1c6ef7a200c7f72f8d1204d727fea32168616ceb/src/borg/platform/linux.pyx#L147I.e. setflags now returns ENOIOCTLCMD/ENOTTY for cases where 6.16 used to return EOPNOTSUPP.
This minimal testcase program doing
ioctl(fd2, FS_IOC_SETFLAGS, &FS_NODUMP_FL):
https://github.com/jirislaby/collected_sources/tree/master/ioctl_setflagsdumps in 6.16:
sf: ioctl: Operation not supported
Quoted 8 lines
Quoted 4 lines
with the above patch:
sf: ioctl: Inappropriate ioctl for deviceIs this expected?
No, that's a bug and a clear userspace regression so we need to fix it. I think we need to revert this commit and instead convert ENOIOCTLCMD from vfs_fileattr_get/set() to EOPNOTSUPP in appropriate places. Andrey?
I will prepare a patch soon
Quoted 6 lines
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Signature · 1 line
- Andrey
Christian Brauner
maintainerRe: [PATCH v6 4/6] fs: make vfs_fileattr_[get|set] return -EOPNOSUPP
Quoted 31 lines · Andrey Albershteyn
Quoted 30 lines · Jan Kara
Quoted 29 lines · Jiri Slaby
Quoted 9 lines · Andrey Albershteyn
Future patches will add new syscalls which use these functions. As this interface won't be used for ioctls only, the EOPNOSUPP is more appropriate return code.
This patch converts return code from ENOIOCTLCMD to EOPNOSUPP for
vfs_fileattr_getandvfs_fileattr_set. To save old behavior translate EOPNOSUPP back for current users - overlayfs, encryptfs andfs/ioctl.c.Signed-off-by Andrey Albershteyn <[email protected]>...
fs/file_attr.c int ioctl_setflags(struct file *file, unsigned int __user *argp) · line 298
Quoted 6 lines
fs/file_attr.c +2
-0@@ -292,6 +294,8 @@ int ioctl_setflags(struct file *file, unsigned int __user *argp)fileattr_fill_flags (&fa, flags); err =vfs_fileattr_set (idmap, dentry, &fa);mnt_drop_write_file (file); +if (err == -EOPNOTSUPP ) + err = -ENOIOCTLCMD ;This breaks borg code (unit tests already) as it expects EOPNOTSUPP, not ENOIOCTLCMD/ENOTTY:
https://github.com/borgbackup/borg/blob/1c6ef7a200c7f72f8d1204d727fea32168616ceb/src/borg/platform/linux.pyx#L147I.e. setflags now returns ENOIOCTLCMD/ENOTTY for cases where 6.16 used to return EOPNOTSUPP.
This minimal testcase program doing
ioctl(fd2, FS_IOC_SETFLAGS, &FS_NODUMP_FL):
https://github.com/jirislaby/collected_sources/tree/master/ioctl_setflags
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
dumps in 6.16:
sf: ioctl: Operation not supportedwith the above patch:
sf: ioctl: Inappropriate ioctl for deviceIs this expected?
Nope, unintentional regression as Arnd noted.
Quoted 6 lines
Quoted 4 lines
No, that's a bug and a clear userspace regression so we need to fix it. I think we need to revert this commit and instead convert ENOIOCTLCMD from vfs_fileattr_get/set() to EOPNOTSUPP in appropriate places. Andrey?
I will prepare a patch soon
Thanks!
PATCH v6 5/6 fs: prepare for extending file_get/setattr()
In reply to Andrey AlbershteynFrom: Amir Goldstein <[email protected]>
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.
--- fs/file_attr.c | 8 +++++++- include/linux/fileattr.h | 20 ++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-)
fs/file_attr.c +7 -1
@@ -99,9 +99,10 @@ EXPORT_SYMBOL(vfs_fileattr_get);int copy_fsxattr_to_user (const struct fileattr *fa,struct fsxattr __user *ufa) {struct fsxattr xfa; +__u32 mask =FS_XFLAGS_MASK ;memset (&xfa,0 ,sizeof (xfa)); - xfa.fsx_xflags = fa->fsx_xflags; + xfa.fsx_xflags = fa->fsx_xflags & mask; xfa.fsx_extsize = fa->fsx_extsize; xfa.fsx_nextents = fa->fsx_nextents; xfa.fsx_projid = fa->fsx_projid;
@@ -118,11 +119,16 @@ static int copy_fsxattr_from_user(struct fileattr *fa, struct fsxattr __user *ufa) {struct fsxattr xfa; +__u32 mask =FS_XFLAGS_MASK ;if (copy_from_user (&xfa, ufa,sizeof (xfa)))return -EFAULT ; +if (xfa.fsx_xflags & ~mask) +return -EINVAL ; +fileattr_fill_xflags (fa, xfa.fsx_xflags); + fa->fsx_xflags &= ~FS_XFLAG_RDONLY_MASK ; fa->fsx_extsize = xfa.fsx_extsize; fa->fsx_nextents = xfa.fsx_nextents; fa->fsx_projid = xfa.fsx_projid;
include/linux/fileattr.h +20 -0
@@ -14,6 +14,26 @@ FS_XFLAG_NODUMP | FS_XFLAG_NOATIME | FS_XFLAG_DAX | \ FS_XFLAG_PROJINHERIT) +/* Read-only inode flags */ +#define FS_XFLAG_RDONLY_MASK \ + (FS_XFLAG_PREALLOC | FS_XFLAG_HASATTR) + +/* Flags to indicate valid value of fsx_ fields */ +#define FS_XFLAG_VALUES_MASK \ + (FS_XFLAG_EXTSIZE | FS_XFLAG_COWEXTSIZE) + +/* Flags for directories */ +#define FS_XFLAG_DIRONLY_MASK \ + (FS_XFLAG_RTINHERIT | FS_XFLAG_NOSYMLINKS | FS_XFLAG_EXTSZINHERIT) + +/* Misc settable flags */ +#define FS_XFLAG_MISC_MASK \ + (FS_XFLAG_REALTIME | FS_XFLAG_NODEFRAG | FS_XFLAG_FILESTREAM) + +#define FS_XFLAGS_MASK \ + (FS_XFLAG_COMMON | FS_XFLAG_RDONLY_MASK | FS_XFLAG_VALUES_MASK | \ + FS_XFLAG_DIRONLY_MASK | FS_XFLAG_MISC_MASK) +/* * Merged interface for miscellaneous file attributes. 'flags' originates from * ext* and 'fsx_flags' from xfs. There's some overlap between the two, which
Signature · 1 line
2.47.2
Re: [PATCH v6 5/6] fs: prepare for extending file_get/setattr()
Quoted 11 lines · Andrey Albershteyn
From: Amir Goldstein <[email protected]>
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_nextentsto filesystem.
Quoted 8 lines
These changes should not affect existing chattr programs that use the ioctl to get fsxattr before setting the new values.
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]>
Looks good. Feel free to add:
I'd just note that:
Quoted 4 lines
fs/file_attr.c +0
-0@@ -118,11 +119,16 @@ static int copy_fsxattr_from_user(struct fileattr *fa, struct fsxattr __user *ufa) {struct fsxattr xfa;
fs/file_attr.c static int copy_fsxattr_from_user(struct fileattr *fa, · line 131
Quoted 10 lines
fs/file_attr.c +5
-0+__u32 mask =FS_XFLAGS_MASK ;if (copy_from_user (&xfa, ufa,sizeof (xfa)))return -EFAULT ; +if (xfa.fsx_xflags & ~mask) +return -EINVAL ; +fileattr_fill_xflags (fa, xfa.fsx_xflags); + fa->fsx_xflags &= ~FS_XFLAG_RDONLY_MASK ;
This means that the two flags in FS_XFLAG_RDONLY_MASK cannot easily become writeable in the future due to this. I think it is a sensible compromise but I wanted to mention it.
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Re: [PATCH v6 5/6] fs: prepare for extending file_get/setattr()
In reply to Andrey AlbershteynQuoted 29 lines · Andrey Albershteyn
From: Amir Goldstein <[email protected]>
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_nextentsto filesystem.These changes should not affect existing chattr programs that use the ioctl to get fsxattr before setting the new values.
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]>--- fs/file_attr.c | 8 +++++++- include/linux/fileattr.h | 20 ++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-)fs/file_attr.c +0
-0
fs/file_attr.c EXPORT_SYMBOL(vfs_fileattr_get); · line 105
Quoted 8 lines
fs/file_attr.c +2
-1@@ -99,9 +99,10 @@ EXPORT_SYMBOL(vfs_fileattr_get);int copy_fsxattr_to_user (const struct fileattr *fa,struct fsxattr __user *ufa) {struct fsxattr xfa; +__u32 mask =FS_XFLAGS_MASK ;memset (&xfa,0 ,sizeof (xfa)); - xfa.fsx_xflags = fa->fsx_xflags; + xfa.fsx_xflags = fa->fsx_xflags & mask;
I wonder, should it be an error if a filesystem sets an fsx_xflags bit outside of FS_XFLAGS_MASK? I guess that's one way to prevent filesystems from overriding the VFS bits. ;)
Though couldn't that be:
xfa.fsx_xflags = fa->fsx_xflags & FS_XFLAGS_MASK;
instead? And same below?
Quoted 4 lines
fs/file_attr.c +0
-0xfa.fsx_extsize = fa->fsx_extsize; xfa.fsx_nextents = fa->fsx_nextents; xfa.fsx_projid = fa->fsx_projid;
fs/file_attr.c static int copy_fsxattr_from_user(struct fileattr *fa, · line 128
Quoted 10 lines
fs/file_attr.c +3
-0@@ -118,11 +119,16 @@ static int copy_fsxattr_from_user(struct fileattr *fa, struct fsxattr __user *ufa) {struct fsxattr xfa; +__u32 mask =FS_XFLAGS_MASK ;if (copy_from_user (&xfa, ufa,sizeof (xfa)))return -EFAULT ; +if (xfa.fsx_xflags & ~mask) +return -EINVAL ;
I wonder if you want EOPNOTSUPP here? We don't know how to support unknown xflags. OTOH if you all have beaten this to death while I was out then don't start another round just for me. :P
--D
Quoted 42 lines
fs/file_attr.c +2
-0+fileattr_fill_xflags (fa, xfa.fsx_xflags); + fa->fsx_xflags &= ~FS_XFLAG_RDONLY_MASK ; fa->fsx_extsize = xfa.fsx_extsize; fa->fsx_nextents = xfa.fsx_nextents; fa->fsx_projid = xfa.fsx_projid;include/linux/fileattr.h +20
-0@@ -14,6 +14,26 @@ FS_XFLAG_NODUMP | FS_XFLAG_NOATIME | FS_XFLAG_DAX | \ FS_XFLAG_PROJINHERIT) +/* Read-only inode flags */ +#define FS_XFLAG_RDONLY_MASK \ + (FS_XFLAG_PREALLOC | FS_XFLAG_HASATTR) + +/* Flags to indicate valid value of fsx_ fields */ +#define FS_XFLAG_VALUES_MASK \ + (FS_XFLAG_EXTSIZE | FS_XFLAG_COWEXTSIZE) + +/* Flags for directories */ +#define FS_XFLAG_DIRONLY_MASK \ + (FS_XFLAG_RTINHERIT | FS_XFLAG_NOSYMLINKS | FS_XFLAG_EXTSZINHERIT) + +/* Misc settable flags */ +#define FS_XFLAG_MISC_MASK \ + (FS_XFLAG_REALTIME | FS_XFLAG_NODEFRAG | FS_XFLAG_FILESTREAM) + +#define FS_XFLAGS_MASK \ + (FS_XFLAG_COMMON | FS_XFLAG_RDONLY_MASK | FS_XFLAG_VALUES_MASK | \ + FS_XFLAG_DIRONLY_MASK | FS_XFLAG_MISC_MASK) +/* * Merged interface for miscellaneous file attributes. 'flags' originates from * ext* and 'fsx_flags' from xfs. There's some overlap between the two, which Signature · 2 lines
-- 2.47.2
Amir Goldstein
maintainerRe: [PATCH v6 5/6] fs: prepare for extending file_get/setattr()
Quoted 36 lines · Darrick J. Wong
Quoted 34 lines · Andrey Albershteyn
From: Amir Goldstein <[email protected]>
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_nextentsto filesystem.These changes should not affect existing chattr programs that use the ioctl to get fsxattr before setting the new values.
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]>--- fs/file_attr.c | 8 +++++++- include/linux/fileattr.h | 20 ++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-)fs/file_attr.c +1
-0@@ -99,9 +99,10 @@ EXPORT_SYMBOL(vfs_fileattr_get);int copy_fsxattr_to_user (const struct fileattr *fa,struct fsxattr __user *ufa) {struct fsxattr xfa; +__u32 mask =FS_XFLAGS_MASK ;
Quoted 7 lines
fs/file_attr.c EXPORT_SYMBOL(vfs_fileattr_get); · line 105
Quoted 3 lines
fs/file_attr.c +1
-1memset (&xfa,0 ,sizeof (xfa)); - xfa.fsx_xflags = fa->fsx_xflags; + xfa.fsx_xflags = fa->fsx_xflags & mask;I wonder, should it be an error if a filesystem sets an
fsx_xflagsbit outside ofFS_XFLAGS_MASK? I guess that's one way to prevent filesystems from overriding the VFS bits. ;)
I think Pali has a plan on how to ensure that later when the mask is provided via the API.
Quoted 7 lines
Though couldn't that be:
xfa.fsx_xflags = fa->fsx_xflags & FS_XFLAGS_MASK;instead? And same below?
Indeed. There is a reason for the var, because the next series by Pali will use a user provided mask, which defaults to FS_XFLAGS_MASK, so I left it this way.
I don't see a problem with it keeping as is, but if it bothers you I guess we can re-add the var later.
Quoted 12 lines
Quoted 12 lines
fs/file_attr.c +1
-0xfa.fsx_extsize = fa->fsx_extsize; xfa.fsx_nextents = fa->fsx_nextents; xfa.fsx_projid = fa->fsx_projid;@@ -118,11 +119,16 @@ static int copy_fsxattr_from_user(struct fileattr *fa, struct fsxattr __user *ufa) {struct fsxattr xfa; +__u32 mask =FS_XFLAGS_MASK ;if (copy_from_user (&xfa, ufa,sizeof (xfa)))return -EFAULT ;
Quoted 6 lines
fs/file_attr.c static int copy_fsxattr_from_user(struct fileattr *fa, · line 128
Quoted 2 lines
fs/file_attr.c +2
-0+if (xfa.fsx_xflags & ~mask) +return -EINVAL ;I wonder if you want EOPNOTSUPP here? We don't know how to support unknown xflags. OTOH if you all have beaten this to death while I was out then don't start another round just for me. :P
We have beaten this API almost to death for sure ;) I don't remember if we discussed this specific aspect, but I am personally in favor of
EOPNOTSUPP := the fs does not support the set/get operation EINVAL := some flags provided as value is invalid
For example, if the get API provides you with a mask of the valid flags that you can set, if you try to set flags outside of that mask you get EINVAL.
That's my interpretation, but I agree that EOPNOTSUPP can also make sense in this situation.
Thanks,
Amir.
Re: [PATCH v6 5/6] fs: prepare for extending file_get/setattr()
Quoted 56 lines · Amir Goldstein
Quoted 36 lines · Darrick J. Wong
Quoted 34 lines · Andrey Albershteyn
From: Amir Goldstein <[email protected]>
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_nextentsto filesystem.These changes should not affect existing chattr programs that use the ioctl to get fsxattr before setting the new values.
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]>--- fs/file_attr.c | 8 +++++++- include/linux/fileattr.h | 20 ++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-)fs/file_attr.c +1
-0@@ -99,9 +99,10 @@ EXPORT_SYMBOL(vfs_fileattr_get);int copy_fsxattr_to_user (const struct fileattr *fa,struct fsxattr __user *ufa) {struct fsxattr xfa; +__u32 mask =FS_XFLAGS_MASK ;Quoted 7 lines
fs/file_attr.c EXPORT_SYMBOL(vfs_fileattr_get); · line 105
Quoted 3 lines
fs/file_attr.c +1
-1memset (&xfa,0 ,sizeof (xfa)); - xfa.fsx_xflags = fa->fsx_xflags; + xfa.fsx_xflags = fa->fsx_xflags & mask;I wonder, should it be an error if a filesystem sets an
fsx_xflagsbit outside ofFS_XFLAGS_MASK? I guess that's one way to prevent filesystems from overriding the VFS bits. ;)I think Pali has a plan on how to ensure that later when the mask is provided via the API.
Quoted 7 lines
Though couldn't that be:
xfa.fsx_xflags = fa->fsx_xflags & FS_XFLAGS_MASK;instead? And same below?
Quoted 6 lines
Indeed. There is a reason for the var, because the next series by Pali will use a user provided mask, which defaults to
FS_XFLAGS_MASK, so I left it this way.I don't see a problem with it keeping as is, but if it bothers you I guess we can re-add the var later.
Nah, it doesn't bother me that much.
Quoted 25 lines
Quoted 12 lines
Quoted 12 lines
fs/file_attr.c +1
-0xfa.fsx_extsize = fa->fsx_extsize; xfa.fsx_nextents = fa->fsx_nextents; xfa.fsx_projid = fa->fsx_projid;@@ -118,11 +119,16 @@ static int copy_fsxattr_from_user(struct fileattr *fa, struct fsxattr __user *ufa) {struct fsxattr xfa; +__u32 mask =FS_XFLAGS_MASK ;if (copy_from_user (&xfa, ufa,sizeof (xfa)))return -EFAULT ;Quoted 6 lines
fs/file_attr.c static int copy_fsxattr_from_user(struct fileattr *fa, · line 128
Quoted 2 lines
fs/file_attr.c +2
-0+if (xfa.fsx_xflags & ~mask) +return -EINVAL ;I wonder if you want EOPNOTSUPP here? We don't know how to support unknown xflags. OTOH if you all have beaten this to death while I was out then don't start another round just for me. :P
We have beaten this API almost to death for sure ;) I don't remember if we discussed this specific aspect, but I am personally in favor of
EOPNOTSUPP := the fs does not support the set/get operation EINVAL := some flags provided as value is invalid
Quoted 6 lines
For example, if the get API provides you with a mask of the valid flags that you can set, if you try to set flags outside of that mask you get EINVAL.
That's my interpretation, but I agree that EOPNOTSUPP can also make sense in this situation.
<nod> I think I'd rather EOPNOTSUPP for "bits are set that the kernel doesn't recognize" and EINVAL (or maybe something else like EPROTONOSUPPORT) for "fs driver will not let you change this bit". At least for the syscall interface; we probably have to flatten that to EOPNOTSUPP for both legacy ioctls.
--D
Quoted 3 lines
Thanks,
Amir.
Re: [PATCH v6 5/6] fs: prepare for extending file_get/setattr()
Quoted 95 lines · On Tuesday 01 July 2025 12:40:02 Darrick J. Wong wrote:
Quoted 56 lines · Amir Goldstein
Quoted 36 lines · Darrick J. Wong
Quoted 34 lines · Andrey Albershteyn
From: Amir Goldstein <[email protected]>
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_nextentsto filesystem.These changes should not affect existing chattr programs that use the ioctl to get fsxattr before setting the new values.
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]>--- fs/file_attr.c | 8 +++++++- include/linux/fileattr.h | 20 ++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-)fs/file_attr.c +1
-0@@ -99,9 +99,10 @@ EXPORT_SYMBOL(vfs_fileattr_get);int copy_fsxattr_to_user (const struct fileattr *fa,struct fsxattr __user *ufa) {struct fsxattr xfa; +__u32 mask =FS_XFLAGS_MASK ;Quoted 7 lines
fs/file_attr.c EXPORT_SYMBOL(vfs_fileattr_get); · line 105
Quoted 3 lines
fs/file_attr.c +1
-1memset (&xfa,0 ,sizeof (xfa)); - xfa.fsx_xflags = fa->fsx_xflags; + xfa.fsx_xflags = fa->fsx_xflags & mask;I wonder, should it be an error if a filesystem sets an
fsx_xflagsbit outside ofFS_XFLAGS_MASK? I guess that's one way to prevent filesystems from overriding the VFS bits. ;)I think Pali has a plan on how to ensure that later when the mask is provided via the API.
Quoted 7 lines
Though couldn't that be:
xfa.fsx_xflags = fa->fsx_xflags & FS_XFLAGS_MASK;instead? And same below?
Quoted 6 lines
Indeed. There is a reason for the var, because the next series by Pali will use a user provided mask, which defaults to
FS_XFLAGS_MASK, so I left it this way.I don't see a problem with it keeping as is, but if it bothers you I guess we can re-add the var later.
Nah, it doesn't bother me that much.
Quoted 29 lines
Quoted 12 lines
Quoted 12 lines
fs/file_attr.c +1
-0xfa.fsx_extsize = fa->fsx_extsize; xfa.fsx_nextents = fa->fsx_nextents; xfa.fsx_projid = fa->fsx_projid;@@ -118,11 +119,16 @@ static int copy_fsxattr_from_user(struct fileattr *fa, struct fsxattr __user *ufa) {struct fsxattr xfa; +__u32 mask =FS_XFLAGS_MASK ;if (copy_from_user (&xfa, ufa,sizeof (xfa)))return -EFAULT ;Quoted 6 lines
fs/file_attr.c static int copy_fsxattr_from_user(struct fileattr *fa, · line 128
Quoted 2 lines
fs/file_attr.c +2
-0+if (xfa.fsx_xflags & ~mask) +return -EINVAL ;I wonder if you want EOPNOTSUPP here? We don't know how to support unknown xflags. OTOH if you all have beaten this to death while I was out then don't start another round just for me. :P
We have beaten this API almost to death for sure ;) I don't remember if we discussed this specific aspect, but I am personally in favor of
EOPNOTSUPP := the fs does not support the set/get operation EINVAL := some flags provided as value is invalidFor example, if the get API provides you with a mask of the valid flags that you can set, if you try to set flags outside of that mask you get EINVAL.
Quoted 8 lines
Quoted 2 lines
That's my interpretation, but I agree that EOPNOTSUPP can also make sense in this situation.
<nod> I think I'd rather EOPNOTSUPP for "bits are set that the kernel doesn't recognize" and EINVAL (or maybe something else like EPROTONOSUPPORT) for "fs driver will not let you change this bit". At least for the syscall interface; we probably have to flatten that to EOPNOTSUPP for both legacy ioctls.
... and this starting to be complicated if the "fs driver" is network based (as fs driver can support, but remote server not). See also:
https://lore.kernel.org/linux-fsdevel/20241224160535.pi6nazpugqkhvfns@pali/t/#u
For backup/restore application it would be very useful to distinguish between:
- "kernel does not support flag X"
- "target filesystem does not support flag X"
- "wrong structure was passed / syscall incorrectly called"
third option is bug in application - fatal error. second option is just a warning for user (sorry, we cannot set NEW FEATURE on FAT32, but if you would do restore to other fs, it is supported). and first option happens when you run new application on older kernel version, it is an recoverable error (or warning to user, but with more important level then second option as switching to different FS would not help).
Could we return different errnos for these 3 situations?
Quoted 5 lines
--D
Quoted 3 lines
Thanks,
Amir.
Amir Goldstein
maintainerRe: [PATCH v6 5/6] fs: prepare for extending file_get/setattr()
Quoted 97 lines · Pali Rohár
Quoted 95 lines · On Tuesday 01 July 2025 12:40:02 Darrick J. Wong wrote:
Quoted 56 lines · Amir Goldstein
Quoted 36 lines · Darrick J. Wong
Quoted 34 lines · Andrey Albershteyn
From: Amir Goldstein <[email protected]>
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_nextentsto filesystem.These changes should not affect existing chattr programs that use the ioctl to get fsxattr before setting the new values.
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]>--- fs/file_attr.c | 8 +++++++- include/linux/fileattr.h | 20 ++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-)fs/file_attr.c +1
-0@@ -99,9 +99,10 @@ EXPORT_SYMBOL(vfs_fileattr_get);int copy_fsxattr_to_user (const struct fileattr *fa,struct fsxattr __user *ufa) {struct fsxattr xfa; +__u32 mask =FS_XFLAGS_MASK ;Quoted 7 lines
fs/file_attr.c EXPORT_SYMBOL(vfs_fileattr_get); · line 105
Quoted 3 lines
fs/file_attr.c +1
-1memset (&xfa,0 ,sizeof (xfa)); - xfa.fsx_xflags = fa->fsx_xflags; + xfa.fsx_xflags = fa->fsx_xflags & mask;I wonder, should it be an error if a filesystem sets an
fsx_xflagsbit outside ofFS_XFLAGS_MASK? I guess that's one way to prevent filesystems from overriding the VFS bits. ;)I think Pali has a plan on how to ensure that later when the mask is provided via the API.
Quoted 7 lines
Though couldn't that be:
xfa.fsx_xflags = fa->fsx_xflags & FS_XFLAGS_MASK;instead? And same below?
Quoted 6 lines
Indeed. There is a reason for the var, because the next series by Pali will use a user provided mask, which defaults to
FS_XFLAGS_MASK, so I left it this way.I don't see a problem with it keeping as is, but if it bothers you I guess we can re-add the var later.
Nah, it doesn't bother me that much.
Quoted 29 lines
Quoted 12 lines
Quoted 12 lines
fs/file_attr.c +1
-0xfa.fsx_extsize = fa->fsx_extsize; xfa.fsx_nextents = fa->fsx_nextents; xfa.fsx_projid = fa->fsx_projid;@@ -118,11 +119,16 @@ static int copy_fsxattr_from_user(struct fileattr *fa, struct fsxattr __user *ufa) {struct fsxattr xfa; +__u32 mask =FS_XFLAGS_MASK ;if (copy_from_user (&xfa, ufa,sizeof (xfa)))return -EFAULT ;Quoted 6 lines
fs/file_attr.c static int copy_fsxattr_from_user(struct fileattr *fa, · line 128
Quoted 2 lines
fs/file_attr.c +2
-0+if (xfa.fsx_xflags & ~mask) +return -EINVAL ;I wonder if you want EOPNOTSUPP here? We don't know how to support unknown xflags. OTOH if you all have beaten this to death while I was out then don't start another round just for me. :P
We have beaten this API almost to death for sure ;) I don't remember if we discussed this specific aspect, but I am personally in favor of
EOPNOTSUPP := the fs does not support the set/get operation EINVAL := some flags provided as value is invalidFor example, if the get API provides you with a mask of the valid flags that you can set, if you try to set flags outside of that mask you get EINVAL.
Quoted 8 lines
Quoted 8 lines
Quoted 2 lines
That's my interpretation, but I agree that EOPNOTSUPP can also make sense in this situation.
<nod> I think I'd rather EOPNOTSUPP for "bits are set that the kernel doesn't recognize" and EINVAL (or maybe something else like EPROTONOSUPPORT) for "fs driver will not let you change this bit". At least for the syscall interface; we probably have to flatten that to EOPNOTSUPP for both legacy ioctls.
Given the precedents of returning EOPNOTSUPP in xfs_fileattr_set() and ext4_ioctl_setflags() for flags that cannot be set, I agree.
Quoted 10 lines
... and this starting to be complicated if the "fs driver" is network based (as fs driver can support, but remote server not). See also:
https://lore.kernel.org/linux-fsdevel/20241224160535.pi6nazpugqkhvfns@pali/t/#uFor backup/restore application it would be very useful to distinguish between:
- "kernel does not support flag X"
- "target filesystem does not support flag X"
- "wrong structure was passed / syscall incorrectly called"
Quoted 8 lines
third option is bug in application - fatal error. second option is just a warning for user (sorry, we cannot set NEW FEATURE on FAT32, but if you would do restore to other fs, it is supported). and first option happens when you run new application on older kernel version, it is an recoverable error (or warning to user, but with more important level then second option as switching to different FS would not help).
Could we return different errnos for these 3 situations?
That would be nice, but actually according to your plan the get API returns the mask of flags supported by the filesystem (on that specific object even), so userspace in fact has a way to distinguish between the first two EOPNOTSUPP cases.
Thanks,
Amir.
Amir Goldstein
maintainerRe: [PATCH v6 5/6] fs: prepare for extending file_get/setattr()
Quoted 102 lines · Amir Goldstein
Quoted 100 lines · Pali Rohár
Quoted 98 lines · On Tuesday 01 July 2025 12:40:02 Darrick J. Wong wrote:
Quoted 56 lines · Amir Goldstein
Quoted 36 lines · Darrick J. Wong
Quoted 34 lines · Andrey Albershteyn
From: Amir Goldstein <[email protected]>
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_nextentsto filesystem.These changes should not affect existing chattr programs that use the ioctl to get fsxattr before setting the new values.
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]>--- fs/file_attr.c | 8 +++++++- include/linux/fileattr.h | 20 ++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-)fs/file_attr.c +1
-0@@ -99,9 +99,10 @@ EXPORT_SYMBOL(vfs_fileattr_get);int copy_fsxattr_to_user (const struct fileattr *fa,struct fsxattr __user *ufa) {struct fsxattr xfa; +__u32 mask =FS_XFLAGS_MASK ;Quoted 7 lines
fs/file_attr.c EXPORT_SYMBOL(vfs_fileattr_get); · line 105
Quoted 3 lines
fs/file_attr.c +1
-1memset (&xfa,0 ,sizeof (xfa)); - xfa.fsx_xflags = fa->fsx_xflags; + xfa.fsx_xflags = fa->fsx_xflags & mask;I wonder, should it be an error if a filesystem sets an
fsx_xflagsbit outside ofFS_XFLAGS_MASK? I guess that's one way to prevent filesystems from overriding the VFS bits. ;)I think Pali has a plan on how to ensure that later when the mask is provided via the API.
Quoted 7 lines
Though couldn't that be:
xfa.fsx_xflags = fa->fsx_xflags & FS_XFLAGS_MASK;instead? And same below?
Quoted 6 lines
Indeed. There is a reason for the var, because the next series by Pali will use a user provided mask, which defaults to
FS_XFLAGS_MASK, so I left it this way.I don't see a problem with it keeping as is, but if it bothers you I guess we can re-add the var later.
Nah, it doesn't bother me that much.
Quoted 31 lines
Quoted 12 lines
Quoted 12 lines
fs/file_attr.c +1
-0xfa.fsx_extsize = fa->fsx_extsize; xfa.fsx_nextents = fa->fsx_nextents; xfa.fsx_projid = fa->fsx_projid;@@ -118,11 +119,16 @@ static int copy_fsxattr_from_user(struct fileattr *fa, struct fsxattr __user *ufa) {struct fsxattr xfa; +__u32 mask =FS_XFLAGS_MASK ;if (copy_from_user (&xfa, ufa,sizeof (xfa)))return -EFAULT ;Quoted 6 lines
fs/file_attr.c static int copy_fsxattr_from_user(struct fileattr *fa, · line 128
Quoted 2 lines
fs/file_attr.c +2
-0+if (xfa.fsx_xflags & ~mask) +return -EINVAL ;I wonder if you want EOPNOTSUPP here? We don't know how to support unknown xflags. OTOH if you all have beaten this to death while I was out then don't start another round just for me. :P
We have beaten this API almost to death for sure ;) I don't remember if we discussed this specific aspect, but I am personally in favor of
EOPNOTSUPP := the fs does not support the set/get operation EINVAL := some flags provided as value is invalidFor example, if the get API provides you with a mask of the valid flags that you can set, if you try to set flags outside of that mask you get EINVAL.
That's my interpretation, but I agree that EOPNOTSUPP can also make sense in this situation.
Quoted 9 lines
Quoted 5 lines
Quoted 5 lines
<nod> I think I'd rather EOPNOTSUPP for "bits are set that the kernel doesn't recognize" and EINVAL (or maybe something else like EPROTONOSUPPORT) for "fs driver will not let you change this bit". At least for the syscall interface; we probably have to flatten that to EOPNOTSUPP for both legacy ioctls.
Given the precedents of returning EOPNOTSUPP in
xfs_fileattr_set()andext4_ioctl_setflags()for flags that cannot be set, I agree.
Wait, I misparsed what you wrote, so I think I "agreed" only to the first part of your suggestion.
My claim is that unlike the xfs_has_v3inodes() check in xfs_ioctl_setattr_xflags(),
ext4/f2fs etc return EOPNOTSUPP for various flags depending on supported fs features (e.g. casefold,dax,encryption), so I think it will be hard to impose a strict rule
where "fs does not support the feature" returns EINVAL in the syscalls API.
Therefore, I propose to change the code in this patch to return EOPNOTSUPP for flags that kernel does not support and with coming changes from Pali, it will also return the same EOPNOTSUPP for flags that the fs instance does not support.
Christian,
Can you please amend the return value in the following chunk:
@@ -119,11 +120,16 @@ static int copy_fsxattr_from_user(struct fileattr *fa,
struct fsxattr __user *ufa)
{
struct fsxattr xfa;+ __u32 mask = FS_XFLAGS_MASK;
if (copy_from_user(&xfa, ufa, sizeof(xfa)))
return -EFAULT;+ if (xfa.fsx_xflags & ~mask)
+ return -EOPNOTSUPP;
+
Thanks,
Amir.
Christian Brauner
maintainerRe: [PATCH v6 5/6] fs: prepare for extending file_get/setattr()
Quoted 6 lines
Christian,
Can you please amend the return value in the following chunk:
(quoted diff) +0
-0@@ -119,11 +120,16 @@ static int copy_fsxattr_from_user(struct fileattr *fa, struct fsxattr __user *ufa)
Review static int copy_fsxattr_from_user(struct fileattr *fa, · line 130
Quoted 10 lines
(quoted diff) +4
-0{ struct fsxattr xfa; + __u32 mask = FS_XFLAGS_MASK; if (copy_from_user(&xfa, ufa, sizeof(xfa))) return -EFAULT; + if (xfa.fsx_xflags & ~mask) + return -EOPNOTSUPP; +
Done.
PATCH v6 6/6 fs: introduce file_getattr and file_setattr syscalls
In reply to Andrey AlbershteynFrom: Andrey Albershteyn <[email protected]>
Introduce file_getattr() and file_setattr() syscalls to manipulate inode extended attributes. The syscalls takes pair of file descriptor and pathname. Then it operates on inode opened accroding to openat() semantics. The struct fsx_fileattr is passed to obtain/change extended attributes.
This is an alternative to FS_IOC_FSSETXATTR ioctl with a difference that file don't need to be open as we can reference it with a path instead of fd. By having this we can manipulated inode extended attributes not only on regular files but also on special ones. This is not possible with FS_IOC_FSSETXATTR ioctl as with special files we can not call ioctl() directly on the filesystem inode using fd.
This patch adds two new syscalls which allows userspace to get/set extended inode attributes on special files by using parent directory and a path - *at() like syscall.
--- arch/alpha/kernel/syscalls/syscall.tbl | 2 + arch/arm/tools/syscall.tbl | 2 + arch/arm64/tools/syscall_32.tbl | 2 + arch/m68k/kernel/syscalls/syscall.tbl | 2 + arch/microblaze/kernel/syscalls/syscall.tbl | 2 + arch/mips/kernel/syscalls/syscall_n32.tbl | 2 + arch/mips/kernel/syscalls/syscall_n64.tbl | 2 + arch/mips/kernel/syscalls/syscall_o32.tbl | 2 + arch/parisc/kernel/syscalls/syscall.tbl | 2 + arch/powerpc/kernel/syscalls/syscall.tbl | 2 + arch/s390/kernel/syscalls/syscall.tbl | 2 + arch/sh/kernel/syscalls/syscall.tbl | 2 + arch/sparc/kernel/syscalls/syscall.tbl | 2 + arch/x86/entry/syscalls/syscall_32.tbl | 2 + arch/x86/entry/syscalls/syscall_64.tbl | 2 + arch/xtensa/kernel/syscalls/syscall.tbl | 2 + fs/file_attr.c | 148 ++++++++++++++++++++++++++++ include/linux/syscalls.h | 6 ++ include/uapi/asm-generic/unistd.h | 8 +- include/uapi/linux/fs.h | 18 ++++ scripts/syscall.tbl | 2 + 21 files changed, 213 insertions(+), 1 deletion(-)
arch/alpha/kernel/syscalls/syscall.tbl +2 -0
@@ -507,3 +507,5 @@ 575 common listxattrat sys_listxattrat 576 common removexattrat sys_removexattrat 577 common open_tree_attr sys_open_tree_attr +578 common file_getattr sys_file_getattr +579 common file_setattr sys_file_setattr
arch/arm/tools/syscall.tbl +2 -0
@@ -482,3 +482,5 @@ 465 common listxattrat sys_listxattrat 466 common removexattrat sys_removexattrat 467 common open_tree_attr sys_open_tree_attr +468 common file_getattr sys_file_getattr +469 common file_setattr sys_file_setattr
arch/arm64/tools/syscall_32.tbl +2 -0
@@ -479,3 +479,5 @@ 465 common listxattrat sys_listxattrat 466 common removexattrat sys_removexattrat 467 common open_tree_attr sys_open_tree_attr +468 common file_getattr sys_file_getattr +469 common file_setattr sys_file_setattr
arch/m68k/kernel/syscalls/syscall.tbl +2 -0
@@ -467,3 +467,5 @@ 465 common listxattrat sys_listxattrat 466 common removexattrat sys_removexattrat 467 common open_tree_attr sys_open_tree_attr +468 common file_getattr sys_file_getattr +469 common file_setattr sys_file_setattr
arch/microblaze/kernel/syscalls/syscall.tbl +2 -0
@@ -473,3 +473,5 @@ 465 common listxattrat sys_listxattrat 466 common removexattrat sys_removexattrat 467 common open_tree_attr sys_open_tree_attr +468 common file_getattr sys_file_getattr +469 common file_setattr sys_file_setattr
arch/mips/kernel/syscalls/syscall_n32.tbl +2 -0
@@ -406,3 +406,5 @@ 465 n32 listxattrat sys_listxattrat 466 n32 removexattrat sys_removexattrat 467 n32 open_tree_attr sys_open_tree_attr +468 n32 file_getattr sys_file_getattr +469 n32 file_setattr sys_file_setattr
arch/mips/kernel/syscalls/syscall_n64.tbl +2 -0
@@ -382,3 +382,5 @@ 465 n64 listxattrat sys_listxattrat 466 n64 removexattrat sys_removexattrat 467 n64 open_tree_attr sys_open_tree_attr +468 n64 file_getattr sys_file_getattr +469 n64 file_setattr sys_file_setattr
arch/mips/kernel/syscalls/syscall_o32.tbl +2 -0
@@ -455,3 +455,5 @@ 465 o32 listxattrat sys_listxattrat 466 o32 removexattrat sys_removexattrat 467 o32 open_tree_attr sys_open_tree_attr +468 o32 file_getattr sys_file_getattr +469 o32 file_setattr sys_file_setattr
arch/parisc/kernel/syscalls/syscall.tbl +2 -0
@@ -466,3 +466,5 @@ 465 common listxattrat sys_listxattrat 466 common removexattrat sys_removexattrat 467 common open_tree_attr sys_open_tree_attr +468 common file_getattr sys_file_getattr +469 common file_setattr sys_file_setattr
arch/powerpc/kernel/syscalls/syscall.tbl +2 -0
@@ -558,3 +558,5 @@ 465 common listxattrat sys_listxattrat 466 common removexattrat sys_removexattrat 467 common open_tree_attr sys_open_tree_attr +468 common file_getattr sys_file_getattr +469 common file_setattr sys_file_setattr
arch/s390/kernel/syscalls/syscall.tbl +2 -0
@@ -470,3 +470,5 @@ 465 common listxattrat sys_listxattrat sys_listxattrat 466 common removexattrat sys_removexattrat sys_removexattrat 467 common open_tree_attr sys_open_tree_attr sys_open_tree_attr +468 common file_getattr sys_file_getattr sys_file_getattr +469 common file_setattr sys_file_setattr sys_file_setattr
arch/sh/kernel/syscalls/syscall.tbl +2 -0
@@ -471,3 +471,5 @@ 465 common listxattrat sys_listxattrat 466 common removexattrat sys_removexattrat 467 common open_tree_attr sys_open_tree_attr +468 common file_getattr sys_file_getattr +469 common file_setattr sys_file_setattr
arch/sparc/kernel/syscalls/syscall.tbl +2 -0
@@ -513,3 +513,5 @@ 465 common listxattrat sys_listxattrat 466 common removexattrat sys_removexattrat 467 common open_tree_attr sys_open_tree_attr +468 common file_getattr sys_file_getattr +469 common file_setattr sys_file_setattr
arch/x86/entry/syscalls/syscall_32.tbl +2 -0
@@ -473,3 +473,5 @@ 465 i386 listxattrat sys_listxattrat 466 i386 removexattrat sys_removexattrat 467 i386 open_tree_attr sys_open_tree_attr +468 i386 file_getattr sys_file_getattr +469 i386 file_setattr sys_file_setattr
arch/x86/entry/syscalls/syscall_64.tbl +2 -0
@@ -391,6 +391,8 @@ 465 common listxattrat sys_listxattrat 466 common removexattrat sys_removexattrat 467 common open_tree_attr sys_open_tree_attr +468 common file_getattr sys_file_getattr +469 common file_setattr sys_file_setattr # # Due to a historical design error, certain syscalls are numbered differently
arch/xtensa/kernel/syscalls/syscall.tbl +2 -0
@@ -438,3 +438,5 @@ 465 common listxattrat sys_listxattrat 466 common removexattrat sys_removexattrat 467 common open_tree_attr sys_open_tree_attr +468 common file_getattr sys_file_getattr +469 common file_setattr sys_file_setattr
fs/file_attr.c +148 -0
169 lines not on this page · raw message
include/linux/syscalls.h +6 -0
@@ -371,6 +371,12 @@ asmlinkage long sys_removexattrat(int dfd, const char __user *path,asmlinkage long sys_lremovexattr (const char __user *path,const char __user *name);asmlinkage long sys_fremovexattr (int fd,const char __user *name); +asmlinkage long sys_file_getattr (int dfd,const char __user *filename, +struct fsx_fileattr __user *ufsx,size_t usize, +unsigned int at_flags); +asmlinkage long sys_file_setattr (int dfd,const char __user *filename, +struct fsx_fileattr __user *ufsx,size_t usize, +unsigned int at_flags);asmlinkage long sys_getcwd (char __user *buf,unsigned long size);asmlinkage long sys_eventfd2 (unsigned int count,int flags);asmlinkage long sys_epoll_create1 (int flags);
include/uapi/asm-generic/unistd.h +7 -1
@@ -852,8 +852,14 @@ __SYSCALL(__NR_removexattrat, sys_removexattrat)#define __NR_open_tree_attr 467__SYSCALL (__NR_open_tree_attr, sys_open_tree_attr) +/* fs/inode.c */ +#define __NR_file_getattr 468 +__SYSCALL(__NR_file_getattr, sys_file_getattr) +#define __NR_file_setattr 469 +__SYSCALL(__NR_file_setattr, sys_file_setattr) +#undef __NR_syscalls -#define __NR_syscalls 468 +#define __NR_syscalls 470/* * 32 bit systems traditionally used different
include/uapi/linux/fs.h +18 -0
@@ -148,6 +148,24 @@ struct fsxattr {unsigned char fsx_pad[8 ]; }; +/* +* Variable size structure for file_[sg]et_attr(). +* +* Note. This is alternative to the structure 'struct fileattr'/'struct fsxattr'. +* As this structure is passed to/from userspace with its size, this can +* be versioned based on the size. +*/ +struct fsx_fileattr { +__u32 fsx_xflags;/* xflags field value (get/set) */ +__u32 fsx_extsize;/* extsize field value (get/set)*/ +__u32 fsx_nextents;/* nextents field value (get) */ +__u32 fsx_projid;/* project identifier (get/set) */ +__u32 fsx_cowextsize;/* CoW extsize field value (get/set) */ +}; + +#define FSX_FILEATTR_SIZE_VER0 20 +#define FSX_FILEATTR_SIZE_LATEST FSX_FILEATTR_SIZE_VER0 +/* * Flags for the fsx_xflags field */
scripts/syscall.tbl +2 -0
@@ -408,3 +408,5 @@ 465 common listxattrat sys_listxattrat 466 common removexattrat sys_removexattrat 467 common open_tree_attr sys_open_tree_attr +468 common file_getattr sys_file_getattr +469 common file_setattr sys_file_setattr
Signature · 1 line
2.47.2
Christian Brauner
maintainerQuoted 227 lines · Andrey Albershteyn
From: Andrey Albershteyn <[email protected]>
Introduce
file_getattr()andfile_setattr()syscalls to manipulate inode extended attributes. The syscalls takes pair of file descriptor and pathname. Then it operates on inode opened accroding toopenat()semantics. The structfsx_fileattris passed to obtain/change extended attributes.This is an alternative to
FS_IOC_FSSETXATTRioctl with a difference that file don't need to be open as we can reference it with a path instead of fd. By having this we can manipulated inode extended attributes not only on regular files but also on special ones. This is not possible withFS_IOC_FSSETXATTRioctl as with special files we can not callioctl()directly on the filesystem inode using fd.This patch adds two new syscalls which allows userspace to get/set extended inode attributes on special files by using parent directory and a path -
*at()like syscall.Signed-off-by Andrey Albershteyn <[email protected]>Acked-by Arnd Bergmann <[email protected]>--- arch/alpha/kernel/syscalls/syscall.tbl | 2 + arch/arm/tools/syscall.tbl | 2 + arch/arm64/tools/syscall_32.tbl | 2 + arch/m68k/kernel/syscalls/syscall.tbl | 2 + arch/microblaze/kernel/syscalls/syscall.tbl | 2 + arch/mips/kernel/syscalls/syscall_n32.tbl | 2 + arch/mips/kernel/syscalls/syscall_n64.tbl | 2 + arch/mips/kernel/syscalls/syscall_o32.tbl | 2 + arch/parisc/kernel/syscalls/syscall.tbl | 2 + arch/powerpc/kernel/syscalls/syscall.tbl | 2 + arch/s390/kernel/syscalls/syscall.tbl | 2 + arch/sh/kernel/syscalls/syscall.tbl | 2 + arch/sparc/kernel/syscalls/syscall.tbl | 2 + arch/x86/entry/syscalls/syscall_32.tbl | 2 + arch/x86/entry/syscalls/syscall_64.tbl | 2 + arch/xtensa/kernel/syscalls/syscall.tbl | 2 + fs/file_attr.c | 148 ++++++++++++++++++++++++++++ include/linux/syscalls.h | 6 ++ include/uapi/asm-generic/unistd.h | 8 +- include/uapi/linux/fs.h | 18 ++++ scripts/syscall.tbl | 2 + 21 files changed, 213 insertions(+), 1 deletion(-)arch/alpha/kernel/syscalls/syscall.tbl +2
-0@@ -507,3 +507,5 @@ 575 common listxattrat sys_listxattrat 576 common removexattrat sys_removexattrat 577 common open_tree_attr sys_open_tree_attr +578 common file_getattr sys_file_getattr +579 common file_setattr sys_file_setattrarch/arm/tools/syscall.tbl +2
-0@@ -482,3 +482,5 @@ 465 common listxattrat sys_listxattrat 466 common removexattrat sys_removexattrat 467 common open_tree_attr sys_open_tree_attr +468 common file_getattr sys_file_getattr +469 common file_setattr sys_file_setattrarch/arm64/tools/syscall_32.tbl +2
-0@@ -479,3 +479,5 @@ 465 common listxattrat sys_listxattrat 466 common removexattrat sys_removexattrat 467 common open_tree_attr sys_open_tree_attr +468 common file_getattr sys_file_getattr +469 common file_setattr sys_file_setattrarch/m68k/kernel/syscalls/syscall.tbl +2
-0@@ -467,3 +467,5 @@ 465 common listxattrat sys_listxattrat 466 common removexattrat sys_removexattrat 467 common open_tree_attr sys_open_tree_attr +468 common file_getattr sys_file_getattr +469 common file_setattr sys_file_setattrarch/microblaze/kernel/syscalls/syscall.tbl +2
-0@@ -473,3 +473,5 @@ 465 common listxattrat sys_listxattrat 466 common removexattrat sys_removexattrat 467 common open_tree_attr sys_open_tree_attr +468 common file_getattr sys_file_getattr +469 common file_setattr sys_file_setattrarch/mips/kernel/syscalls/syscall_n32.tbl +2
-0@@ -406,3 +406,5 @@ 465 n32 listxattrat sys_listxattrat 466 n32 removexattrat sys_removexattrat 467 n32 open_tree_attr sys_open_tree_attr +468 n32 file_getattr sys_file_getattr +469 n32 file_setattr sys_file_setattrarch/mips/kernel/syscalls/syscall_n64.tbl +2
-0@@ -382,3 +382,5 @@ 465 n64 listxattrat sys_listxattrat 466 n64 removexattrat sys_removexattrat 467 n64 open_tree_attr sys_open_tree_attr +468 n64 file_getattr sys_file_getattr +469 n64 file_setattr sys_file_setattrarch/mips/kernel/syscalls/syscall_o32.tbl +2
-0@@ -455,3 +455,5 @@ 465 o32 listxattrat sys_listxattrat 466 o32 removexattrat sys_removexattrat 467 o32 open_tree_attr sys_open_tree_attr +468 o32 file_getattr sys_file_getattr +469 o32 file_setattr sys_file_setattrarch/parisc/kernel/syscalls/syscall.tbl +2
-0@@ -466,3 +466,5 @@ 465 common listxattrat sys_listxattrat 466 common removexattrat sys_removexattrat 467 common open_tree_attr sys_open_tree_attr +468 common file_getattr sys_file_getattr +469 common file_setattr sys_file_setattrarch/powerpc/kernel/syscalls/syscall.tbl +2
-0@@ -558,3 +558,5 @@ 465 common listxattrat sys_listxattrat 466 common removexattrat sys_removexattrat 467 common open_tree_attr sys_open_tree_attr +468 common file_getattr sys_file_getattr +469 common file_setattr sys_file_setattrarch/s390/kernel/syscalls/syscall.tbl +2
-0@@ -470,3 +470,5 @@ 465 common listxattrat sys_listxattrat sys_listxattrat 466 common removexattrat sys_removexattrat sys_removexattrat 467 common open_tree_attr sys_open_tree_attr sys_open_tree_attr +468 common file_getattr sys_file_getattr sys_file_getattr +469 common file_setattr sys_file_setattr sys_file_setattrarch/sh/kernel/syscalls/syscall.tbl +2
-0@@ -471,3 +471,5 @@ 465 common listxattrat sys_listxattrat 466 common removexattrat sys_removexattrat 467 common open_tree_attr sys_open_tree_attr +468 common file_getattr sys_file_getattr +469 common file_setattr sys_file_setattrarch/sparc/kernel/syscalls/syscall.tbl +2
-0@@ -513,3 +513,5 @@ 465 common listxattrat sys_listxattrat 466 common removexattrat sys_removexattrat 467 common open_tree_attr sys_open_tree_attr +468 common file_getattr sys_file_getattr +469 common file_setattr sys_file_setattrarch/x86/entry/syscalls/syscall_32.tbl +2
-0@@ -473,3 +473,5 @@ 465 i386 listxattrat sys_listxattrat 466 i386 removexattrat sys_removexattrat 467 i386 open_tree_attr sys_open_tree_attr +468 i386 file_getattr sys_file_getattr +469 i386 file_setattr sys_file_setattrarch/x86/entry/syscalls/syscall_64.tbl +2
-0@@ -391,6 +391,8 @@ 465 common listxattrat sys_listxattrat 466 common removexattrat sys_removexattrat 467 common open_tree_attr sys_open_tree_attr +468 common file_getattr sys_file_getattr +469 common file_setattr sys_file_setattr # # Due to a historical design error, certain syscalls are numbered differentlyarch/xtensa/kernel/syscalls/syscall.tbl +2
-0@@ -438,3 +438,5 @@ 465 common listxattrat sys_listxattrat 466 common removexattrat sys_removexattrat 467 common open_tree_attr sys_open_tree_attr +468 common file_getattr sys_file_getattr +469 common file_setattr sys_file_setattrfs/file_attr.c +4
-0@@ -3,6 +3,10 @@#include <linux/security.h> #include <linux/fscrypt.h> #include <linux/fileattr.h> +#include <linux/syscalls.h> +#include <linux/namei.h> + +#include "internal.h" /** * fileattr_fill_xflags - initialize fileattr with xflags
fs/file_attr.c int vfs_fileattr_get(struct dentry *dentry, struct fileattr *fa) · line 101
Quoted 9 lines
fs/file_attr.c +6
-0@@ -89,6 +93,19 @@ int vfs_fileattr_get(struct dentry *dentry, struct fileattr *fa) }EXPORT_SYMBOL (vfs_fileattr_get); +static void fileattr_to_fsx_fileattr (const struct fileattr *fa, +struct fsx_fileattr *fsx) +{ +__u32 mask =FS_XFLAGS_MASK ; + +memset (fsx,0 ,sizeof (struct fsx_fileattr ));
Fwiw, what also works is:
*fsx = (struct fsx_fileattr){
.fsx_xflags = fa->fsx_xflags & mask,
.fsx_extsize = fa->fsx_extsize,
.fsx_nextents = fa->fsx_nextents,
.fsx_projid = fa->fsx_projid,
.fsx_cowextsize = fa->fsx_cowextsize,
}avoiding the memset(). Anyway, all minor nits.
Quoted 38 lines
fs/file_attr.c +24
-0+ fsx->fsx_xflags = fa->fsx_xflags & mask; + fsx->fsx_extsize = fa->fsx_extsize; + fsx->fsx_nextents = fa->fsx_nextents; + fsx->fsx_projid = fa->fsx_projid; + fsx->fsx_cowextsize = fa->fsx_cowextsize; +} +/** * copy_fsxattr_to_user - copy fsxattr to userspace. * @fa: fileattr pointer @@ -115,6 +132,23 @@ int copy_fsxattr_to_user(const struct fileattr *fa, struct fsxattr __user *ufa) }EXPORT_SYMBOL (copy_fsxattr_to_user); +static int fsx_fileattr_to_fileattr (const struct fsx_fileattr *fsx, +struct fileattr *fa) +{ +__u32 mask =FS_XFLAGS_MASK ; + +if (fsx->fsx_xflags & ~mask) +return -EINVAL ; + +fileattr_fill_xflags (fa, fsx->fsx_xflags); + fa->fsx_xflags &= ~FS_XFLAG_RDONLY_MASK ; + fa->fsx_extsize = fsx->fsx_extsize; + fa->fsx_projid = fsx->fsx_projid; + fa->fsx_cowextsize = fsx->fsx_cowextsize; + +return 0 ; +} +static int copy_fsxattr_from_user (struct fileattr *fa,struct fsxattr __user *ufa) {@@ -343,3 +377,117 @@ int ioctl_fssetxattr(struct file *file, void __user *argp)return err; }EXPORT_SYMBOL (ioctl_fssetxattr);
fs/file_attr.c int ioctl_fssetxattr(struct file *file, void __user *argp) · line 389
Quoted 10 lines
fs/file_attr.c +10
-0+ +SYSCALL_DEFINE5(file_getattr, int, dfd, const char __user *, filename, + struct fsx_fileattr __user *, ufsx, size_t, usize, + unsigned int, at_flags) +{ +struct fileattr fa; + struct path filepath __free(path_put) = {}; +int error; +unsigned int lookup_flags =0 ; + struct filename *name __free(putname) = NULL;
Fwiw, cleanup guards should always be grouped together at the top like:
struct path filepath __free(path_put) = {};
struct filename *name __free(putname) = NULL;
struct fileattr fa;
int error;
unsigned int lookup_flags = 0;
This makes it easy to spot them when reading a function with multiple variables on top.
Quoted 93 lines
fs/file_attr.c +92
-0+struct fsx_fileattr fsx; +struct fsx_fileattr fsx; + +BUILD_BUG_ON (sizeof (struct fsx_fileattr ) <FSX_FILEATTR_SIZE_VER0 ); +BUILD_BUG_ON (sizeof (struct fsx_fileattr ) !=FSX_FILEATTR_SIZE_LATEST ); + +if ((at_flags & ~(AT_SYMLINK_NOFOLLOW |AT_EMPTY_PATH )) !=0 ) +return -EINVAL ; + +if (!(at_flags &AT_SYMLINK_NOFOLLOW )) + lookup_flags |=LOOKUP_FOLLOW ; + +if (usize >PAGE_SIZE ) +return -E2BIG ; + +if (usize <FSX_FILEATTR_SIZE_VER0 ) +return -EINVAL ; + + name =getname_maybe_null (filename, at_flags); +if (IS_ERR (name)) +return PTR_ERR (name); + +if (!name && dfd >=0 ) { +CLASS (fd, f)(dfd); + + filepath =fd_file (f)->f_path; +path_get (&filepath); + }else { + error =filename_lookup (dfd, name, lookup_flags, &filepath, +NULL ); +if (error) +return error; + } + + error =vfs_fileattr_get (filepath.dentry, &fa); +if (error) +return error; + +fileattr_to_fsx_fileattr (&fa, &fsx); + error =copy_struct_to_user (ufsx, usize, &fsx, +sizeof (struct fsx_fileattr ),NULL ); + +return error; +} + +SYSCALL_DEFINE5(file_setattr, int, dfd, const char __user *, filename, + struct fsx_fileattr __user *, ufsx, size_t, usize, + unsigned int, at_flags) +{ +struct fileattr fa; + struct path filepath __free(path_put) = {}; +int error; +unsigned int lookup_flags =0 ; + struct filename *name __free(putname) = NULL; +struct fsx_fileattr fsx; + +BUILD_BUG_ON (sizeof (struct fsx_fileattr ) <FSX_FILEATTR_SIZE_VER0 ); +BUILD_BUG_ON (sizeof (struct fsx_fileattr ) !=FSX_FILEATTR_SIZE_LATEST ); + +if ((at_flags & ~(AT_SYMLINK_NOFOLLOW |AT_EMPTY_PATH )) !=0 ) +return -EINVAL ; + +if (!(at_flags &AT_SYMLINK_NOFOLLOW )) + lookup_flags |=LOOKUP_FOLLOW ; + +if (usize >PAGE_SIZE ) +return -E2BIG ; + +if (usize <FSX_FILEATTR_SIZE_VER0 ) +return -EINVAL ; + + error =copy_struct_from_user (&fsx,sizeof (struct fsx_fileattr ), ufsx, + usize); +if (error) +return error; + + error =fsx_fileattr_to_fileattr (&fsx, &fa); +if (error) +return error; + + name =getname_maybe_null (filename, at_flags); +if (IS_ERR (name)) +return PTR_ERR (name); + +if (!name && dfd >=0 ) { +CLASS (fd, f)(dfd); + + filepath =fd_file (f)->f_path; +path_get (&filepath); + }else { + error =filename_lookup (dfd, name, lookup_flags, &filepath, +NULL );
fs/file_attr.c int ioctl_fssetxattr(struct file *file, void __user *argp) · line 490
Quoted 10 lines
fs/file_attr.c +10
-0+if (error) +return error; + } + + error =mnt_want_write (filepath.mnt); +if (!error) { + error =vfs_fileattr_set (mnt_idmap (filepath.mnt), + filepath.dentry, &fa); +mnt_drop_write (filepath.mnt); + }
Note-to-self: I really want scoped_guard()s for mnt_want_write() going forward...
Quoted 51 lines
fs/file_attr.c +3
-0+ +return error; +}include/linux/syscalls.h +6
-0@@ -371,6 +371,12 @@ asmlinkage long sys_removexattrat(int dfd, const char __user *path,asmlinkage long sys_lremovexattr (const char __user *path,const char __user *name);asmlinkage long sys_fremovexattr (int fd,const char __user *name); +asmlinkage long sys_file_getattr (int dfd,const char __user *filename, +struct fsx_fileattr __user *ufsx,size_t usize, +unsigned int at_flags); +asmlinkage long sys_file_setattr (int dfd,const char __user *filename, +struct fsx_fileattr __user *ufsx,size_t usize, +unsigned int at_flags);asmlinkage long sys_getcwd (char __user *buf,unsigned long size);asmlinkage long sys_eventfd2 (unsigned int count,int flags);asmlinkage long sys_epoll_create1 (int flags);include/uapi/asm-generic/unistd.h +7
-1@@ -852,8 +852,14 @@ __SYSCALL(__NR_removexattrat, sys_removexattrat)#define __NR_open_tree_attr 467__SYSCALL (__NR_open_tree_attr, sys_open_tree_attr) +/* fs/inode.c */ +#define __NR_file_getattr 468 +__SYSCALL(__NR_file_getattr, sys_file_getattr) +#define __NR_file_setattr 469 +__SYSCALL(__NR_file_setattr, sys_file_setattr) +#undef __NR_syscalls -#define __NR_syscalls 468 +#define __NR_syscalls 470/* * 32 bit systems traditionally used different include/uapi/linux/fs.h +3
-0@@ -148,6 +148,24 @@ struct fsxattr {unsigned char fsx_pad[8 ]; }; +/* +* Variable size structure for file_[sg]et_attr(). +*
include/uapi/linux/fs.h struct fsxattr { · line 163
Quoted 10 lines
include/uapi/linux/fs.h +10
-0+* Note. This is alternative to the structure 'struct fileattr'/'struct fsxattr'. +* As this structure is passed to/from userspace with its size, this can +* be versioned based on the size. +*/ +struct fsx_fileattr { +__u32 fsx_xflags;/* xflags field value (get/set) */ +__u32 fsx_extsize;/* extsize field value (get/set)*/ +__u32 fsx_nextents;/* nextents field value (get) */ +__u32 fsx_projid;/* project identifier (get/set) */ +__u32 fsx_cowextsize;/* CoW extsize field value (get/set) */
This misses a:
__u32 __spare;
so there's no holes in the struct. :)
Quoted 22 lines
include/uapi/linux/fs.h +5
-0+}; + +#define FSX_FILEATTR_SIZE_VER0 20 +#define FSX_FILEATTR_SIZE_LATEST FSX_FILEATTR_SIZE_VER0 +/* * Flags for the fsx_xflags field */ scripts/syscall.tbl +2
-0@@ -408,3 +408,5 @@ 465 common listxattrat sys_listxattrat 466 common removexattrat sys_removexattrat 467 common open_tree_attr sys_open_tree_attr +468 common file_getattr sys_file_getattr +469 common file_setattr sys_file_setattrSignature · 2 lines
-- 2.47.2
Amir Goldstein
maintainerQuoted 16 lines
include/uapi/linux/fs.h struct fsxattr { · line 163
Quoted 13 lines
include/uapi/linux/fs.h +13
-0+/* +* Variable size structure for file_[sg]et_attr(). +* +* Note. This is alternative to the structure 'struct fileattr'/'struct fsxattr'. +* As this structure is passed to/from userspace with its size, this can +* be versioned based on the size. +*/ +struct fsx_fileattr { +__u32 fsx_xflags;/* xflags field value (get/set) */ +__u32 fsx_extsize;/* extsize field value (get/set)*/ +__u32 fsx_nextents;/* nextents field value (get) */ +__u32 fsx_projid;/* project identifier (get/set) */ +__u32 fsx_cowextsize;/* CoW extsize field value (get/set) */ This misses a:
Quoted 3 lines
__u32__spare;so there's no holes in the struct. :)
Adding __spare and not verifying that it is zeroed gets us to the point that we are not able to replace __spare with a real field later.
I suggest to resolve this hole as Darrick and Pali suggested by making it __u64 fsx_xflags
w.r.t Darrick's comment, I kind of like it that the name for the UAPI struct (fsxattr)
differs from the name of the kernel internal representation (fileattr), but I agree that fsx_fileattr does not give a good hint on what it is.
I think that renaming struct fsx_fileattr to struct fsxattr64 along with changing the
width of fsx_xflags will help reduce the confusion of users.
What do you guys think?
Thanks,
Amir.
Quoted 5 lines · Andrey Albershteyn
From: Andrey Albershteyn <[email protected]>
Introduce
file_getattr()andfile_setattr()syscalls to manipulate inode extended attributes. The syscalls takes pair of file descriptor and pathname. Then it operates on inode opened accroding toopenat()
^^^ according
Quoted 5 lines
semantics. The struct
fsx_fileattris passed to obtain/change extended attributes.This is an alternative to
FS_IOC_FSSETXATTRioctl with a difference that file don't need to be open as we can reference it with a path
^^^ doesn't
Quoted 9 lines
instead of fd. By having this we can manipulated inode extended attributes not only on regular files but also on special ones. This is not possible with
FS_IOC_FSSETXATTRioctl as with special files we can not callioctl()directly on the filesystem inode using fd.This patch adds two new syscalls which allows userspace to get/set extended inode attributes on special files by using parent directory and a path -
*at()like syscall.
Quoted 5 lines
Signed-off-by Andrey Albershteyn <[email protected]>Acked-by Arnd Bergmann <[email protected]>
There's possible NULL ptr deref bug below (2x) that's easy to fix. Once done feel free to add:
Quoted 29 lines
fs/file_attr.c +25
-0@@ -343,3 +377,117 @@ int ioctl_fssetxattr(struct file *file, void __user *argp)return err; }EXPORT_SYMBOL (ioctl_fssetxattr); + +SYSCALL_DEFINE5(file_getattr, int, dfd, const char __user *, filename, + struct fsx_fileattr __user *, ufsx, size_t, usize, + unsigned int, at_flags) +{ +struct fileattr fa; + struct path filepath __free(path_put) = {}; +int error; +unsigned int lookup_flags =0 ; + struct filename *name __free(putname) = NULL; +struct fsx_fileattr fsx; + +BUILD_BUG_ON (sizeof (struct fsx_fileattr ) <FSX_FILEATTR_SIZE_VER0 ); +BUILD_BUG_ON (sizeof (struct fsx_fileattr ) !=FSX_FILEATTR_SIZE_LATEST ); + +if ((at_flags & ~(AT_SYMLINK_NOFOLLOW |AT_EMPTY_PATH )) !=0 ) +return -EINVAL ; + +if (!(at_flags &AT_SYMLINK_NOFOLLOW )) + lookup_flags |=LOOKUP_FOLLOW ; + +if (usize >PAGE_SIZE ) +return -E2BIG ; + +if (usize <FSX_FILEATTR_SIZE_VER0 )
fs/file_attr.c int ioctl_fssetxattr(struct file *file, void __user *argp) · line 414
Quoted 10 lines
fs/file_attr.c +10
-0+return -EINVAL ; + + name =getname_maybe_null (filename, at_flags); +if (IS_ERR (name)) +return PTR_ERR (name); + +if (!name && dfd >=0 ) { +CLASS (fd, f)(dfd); + + filepath =fd_file (f)->f_path;
If dfd is not correct fd, then this will dereference NULL AFAICT. I think you need here:
if (fd_empty(f)) return -EBADF;
Quoted 51 lines
fs/file_attr.c +51
-0+path_get (&filepath); + }else { + error =filename_lookup (dfd, name, lookup_flags, &filepath, +NULL ); +if (error) +return error; + } + + error =vfs_fileattr_get (filepath.dentry, &fa); +if (error) +return error; + +fileattr_to_fsx_fileattr (&fa, &fsx); + error =copy_struct_to_user (ufsx, usize, &fsx, +sizeof (struct fsx_fileattr ),NULL ); + +return error; +} + +SYSCALL_DEFINE5(file_setattr, int, dfd, const char __user *, filename, + struct fsx_fileattr __user *, ufsx, size_t, usize, + unsigned int, at_flags) +{ +struct fileattr fa; + struct path filepath __free(path_put) = {}; +int error; +unsigned int lookup_flags =0 ; + struct filename *name __free(putname) = NULL; +struct fsx_fileattr fsx; + +BUILD_BUG_ON (sizeof (struct fsx_fileattr ) <FSX_FILEATTR_SIZE_VER0 ); +BUILD_BUG_ON (sizeof (struct fsx_fileattr ) !=FSX_FILEATTR_SIZE_LATEST ); + +if ((at_flags & ~(AT_SYMLINK_NOFOLLOW |AT_EMPTY_PATH )) !=0 ) +return -EINVAL ; + +if (!(at_flags &AT_SYMLINK_NOFOLLOW )) + lookup_flags |=LOOKUP_FOLLOW ; + +if (usize >PAGE_SIZE ) +return -E2BIG ; + +if (usize <FSX_FILEATTR_SIZE_VER0 ) +return -EINVAL ; + + error =copy_struct_from_user (&fsx,sizeof (struct fsx_fileattr ), ufsx, + usize); +if (error) +return error; + + error =fsx_fileattr_to_fileattr (&fsx, &fa);
fs/file_attr.c int ioctl_fssetxattr(struct file *file, void __user *argp) · line 475
Quoted 10 lines
fs/file_attr.c +10
-0+if (error) +return error; + + name =getname_maybe_null (filename, at_flags); +if (IS_ERR (name)) +return PTR_ERR (name); + +if (!name && dfd >=0 ) { +CLASS (fd, f)(dfd); +
Same comment here as above.
Quoted 8 lines
fs/file_attr.c +8
-0+ filepath =fd_file (f)->f_path; +path_get (&filepath); + }else { + error =filename_lookup (dfd, name, lookup_flags, &filepath, +NULL ); +if (error) +return error; + }
fs/file_attr.c int ioctl_fssetxattr(struct file *file, void __user *argp) · line 493
Quoted 10 lines
fs/file_attr.c +10
-0+ + error =mnt_want_write (filepath.mnt); +if (!error) { + error =vfs_fileattr_set (mnt_idmap (filepath.mnt), + filepath.dentry, &fa); +mnt_drop_write (filepath.mnt); + } + +return error; +}
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Quoted 19 lines · Andrey Albershteyn
From: Andrey Albershteyn <[email protected]>
Introduce
file_getattr()andfile_setattr()syscalls to manipulate inode extended attributes. The syscalls takes pair of file descriptor and pathname. Then it operates on inode opened accroding toopenat()semantics. The structfsx_fileattris passed to obtain/change extended attributes.This is an alternative to
FS_IOC_FSSETXATTRioctl with a difference that file don't need to be open as we can reference it with a path instead of fd. By having this we can manipulated inode extended attributes not only on regular files but also on special ones. This is not possible withFS_IOC_FSSETXATTRioctl as with special files we can not callioctl()directly on the filesystem inode using fd.This patch adds two new syscalls which allows userspace to get/set extended inode attributes on special files by using parent directory and a path -
*at()like syscall.
Quoted 6 lines
Signed-off-by Andrey Albershteyn <[email protected]>Acked-by Arnd Bergmann <[email protected]>---
<snip syscall table>
Quoted 16 lines
fs/file_attr.c +4
-0@@ -3,6 +3,10 @@#include <linux/security.h> #include <linux/fscrypt.h> #include <linux/fileattr.h> +#include <linux/syscalls.h> +#include <linux/namei.h> + +#include "internal.h" /** * fileattr_fill_xflags - initialize fileattr with xflags
fs/file_attr.c int vfs_fileattr_get(struct dentry *dentry, struct fileattr *fa) · line 97
Quoted 5 lines
fs/file_attr.c +2
-0@@ -89,6 +93,19 @@ int vfs_fileattr_get(struct dentry *dentry, struct fileattr *fa) }EXPORT_SYMBOL (vfs_fileattr_get); +static void fileattr_to_fsx_fileattr (const struct fileattr *fa, +struct fsx_fileattr *fsx)
Er... "fsx_fileattr" is the struct that the system call uses?
That's a little confusing considering that xfs already has a xfs_fill_fsxattr function that actually fills a struct fileattr. That could be renamed xfs_fill_fileattr.
I dunno. There's a part of me that would really rather that the file_getattr and file_setattr syscalls operate on a struct file_attr.
More whining/bikeshedding to come.
<snip stuff that looks ok to me>
<<well, I still dislike the CLASS(fd, fd)(fd) syntax...>>
Quoted 7 lines
include/uapi/linux/fs.h +0
-0@@ -148,6 +148,24 @@ struct fsxattr {unsigned char fsx_pad[8 ]; };
include/uapi/linux/fs.h struct fsxattr { · line 159
Quoted 10 lines
include/uapi/linux/fs.h +9
-0+/* +* Variable size structure for file_[sg]et_attr(). +* +* Note. This is alternative to the structure 'struct fileattr'/'struct fsxattr'. +* As this structure is passed to/from userspace with its size, this can +* be versioned based on the size. +*/ +struct fsx_fileattr { +__u32 fsx_xflags;/* xflags field value (get/set) */
Should this to be __u64 from the start? Seeing as (a) this struct is not already a multiple of 8 bytes and (b) it's likely that we'll have to add a u64 field at some point. That would also address brauner's comment about padding.
--D
Quoted 27 lines
include/uapi/linux/fs.h +9
-0+__u32 fsx_extsize;/* extsize field value (get/set)*/ +__u32 fsx_nextents;/* nextents field value (get) */ +__u32 fsx_projid;/* project identifier (get/set) */ +__u32 fsx_cowextsize;/* CoW extsize field value (get/set) */ +}; + +#define FSX_FILEATTR_SIZE_VER0 20 +#define FSX_FILEATTR_SIZE_LATEST FSX_FILEATTR_SIZE_VER0 +/* * Flags for the fsx_xflags field */ scripts/syscall.tbl +2
-0@@ -408,3 +408,5 @@ 465 common listxattrat sys_listxattrat 466 common removexattrat sys_removexattrat 467 common open_tree_attr sys_open_tree_attr +468 common file_getattr sys_file_getattr +469 common file_setattr sys_file_setattrSignature · 2 lines
-- 2.47.2
Quoted 9 lines · On Tuesday 01 July 2025 11:43:17 Darrick J. Wong wrote:
Quoted 8 lines · Andrey Albershteyn
include/uapi/linux/fs.h +0
-0@@ -148,6 +148,24 @@ struct fsxattr {unsigned char fsx_pad[8 ]; };
Quoted 14 lines
include/uapi/linux/fs.h struct fsxattr { · line 159
Quoted 9 lines
include/uapi/linux/fs.h +9
-0+/* +* Variable size structure for file_[sg]et_attr(). +* +* Note. This is alternative to the structure 'struct fileattr'/'struct fsxattr'. +* As this structure is passed to/from userspace with its size, this can +* be versioned based on the size. +*/ +struct fsx_fileattr { +__u32 fsx_xflags;/* xflags field value (get/set) */ Should this to be
__u64from the start? Seeing as (a) this struct is not already a multiple of 8 bytes and (b) it's likely that we'll have to add a u64 field at some point. That would also address brauner's comment about padding.
Hello!
As I have already mentioned, after this syscall API/ABI is finished, I'm planning to prepare patches for changing just selected fields / flags by introducing a new mask field, and support for additional flags used by existing filesystems (like windows flags).
My idea is extending this structure for a new "u32 fsx_xflags_mask" and new "u32 fsx_xflags2" + "u32 fsx_xflags2_mask". (field names are just examples).
So in case you are extending the structure now, please consider if it makes sense to add all members, so we do not have to define 2 or 3 structure versions in near feature.
Your idea of __u64 for fsx_xflags means that it will already cover the "u32 fsx_xflags2" field.
Quoted 29 lines
--D
Quoted 27 lines
include/uapi/linux/fs.h +9
-0+__u32 fsx_extsize;/* extsize field value (get/set)*/ +__u32 fsx_nextents;/* nextents field value (get) */ +__u32 fsx_projid;/* project identifier (get/set) */ +__u32 fsx_cowextsize;/* CoW extsize field value (get/set) */ +}; + +#define FSX_FILEATTR_SIZE_VER0 20 +#define FSX_FILEATTR_SIZE_LATEST FSX_FILEATTR_SIZE_VER0 +/* * Flags for the fsx_xflags field */ scripts/syscall.tbl +2
-0@@ -408,3 +408,5 @@ 465 common listxattrat sys_listxattrat 466 common removexattrat sys_removexattrat 467 common open_tree_attr sys_open_tree_attr +468 common file_getattr sys_file_getattr +469 common file_setattr sys_file_setattrSignature · 2 lines
-- 2.47.2
Quoted 36 lines · Pali Rohár
Quoted 9 lines · On Tuesday 01 July 2025 11:43:17 Darrick J. Wong wrote:
Quoted 8 lines · Andrey Albershteyn
include/uapi/linux/fs.h +0
-0@@ -148,6 +148,24 @@ struct fsxattr {unsigned char fsx_pad[8 ]; };Quoted 14 lines
include/uapi/linux/fs.h struct fsxattr { · line 159
Quoted 9 lines
include/uapi/linux/fs.h +9
-0+/* +* Variable size structure for file_[sg]et_attr(). +* +* Note. This is alternative to the structure 'struct fileattr'/'struct fsxattr'. +* As this structure is passed to/from userspace with its size, this can +* be versioned based on the size. +*/ +struct fsx_fileattr { +__u32 fsx_xflags;/* xflags field value (get/set) */ Should this to be
__u64from the start? Seeing as (a) this struct is not already a multiple of 8 bytes and (b) it's likely that we'll have to add a u64 field at some point. That would also address brauner's comment about padding.Hello!
As I have already mentioned, after this syscall API/ABI is finished, I'm planning to prepare patches for changing just selected fields / flags by introducing a new mask field, and support for additional flags used by existing filesystems (like windows flags).
My idea is extending this structure for a new "u32
fsx_xflags_mask" and new "u32fsx_xflags2" + "u32fsx_xflags2_mask". (field names are just examples).
Quoted 6 lines
So in case you are extending the structure now, please consider if it makes sense to add all members, so we do not have to define 2 or 3 structure versions in near feature.
Your idea of
__u64forfsx_xflagsmeans that it will already cover the "u32fsx_xflags2" field.
Ah, ok, so that work *is* still coming. :)
Are you still planning to add masks for xflags bits that are clearable and settable? i.e.
__u64 fa_xflags; /* state */ ... <end of V0 structure> __u64 fa_xflags_mask; /* bits for setattr to examine */ __u64 fa_xflags_clearable; /* clearable bits */ __u64 fa_xflags_settable; /* settable bits */
I think it's easier just to define u64 in the V0 structure and then add the three new fields in V1. What do you think?
--D
Quoted 30 lines
Quoted 29 lines
--D
Quoted 27 lines
include/uapi/linux/fs.h +9
-0+__u32 fsx_extsize;/* extsize field value (get/set)*/ +__u32 fsx_nextents;/* nextents field value (get) */ +__u32 fsx_projid;/* project identifier (get/set) */ +__u32 fsx_cowextsize;/* CoW extsize field value (get/set) */ +}; + +#define FSX_FILEATTR_SIZE_VER0 20 +#define FSX_FILEATTR_SIZE_LATEST FSX_FILEATTR_SIZE_VER0 +/* * Flags for the fsx_xflags field */ scripts/syscall.tbl +2
-0@@ -408,3 +408,5 @@ 465 common listxattrat sys_listxattrat 466 common removexattrat sys_removexattrat 467 common open_tree_attr sys_open_tree_attr +468 common file_getattr sys_file_getattr +469 common file_setattr sys_file_setattrSignature · 2 lines
-- 2.47.2
Quoted 37 lines · On Tuesday 01 July 2025 12:08:57 Darrick J. Wong wrote:
Quoted 36 lines · Pali Rohár
Quoted 9 lines · On Tuesday 01 July 2025 11:43:17 Darrick J. Wong wrote:
Quoted 8 lines · Andrey Albershteyn
include/uapi/linux/fs.h +0
-0@@ -148,6 +148,24 @@ struct fsxattr {unsigned char fsx_pad[8 ]; };Quoted 14 lines
include/uapi/linux/fs.h struct fsxattr { · line 159
Quoted 9 lines
include/uapi/linux/fs.h +9
-0+/* +* Variable size structure for file_[sg]et_attr(). +* +* Note. This is alternative to the structure 'struct fileattr'/'struct fsxattr'. +* As this structure is passed to/from userspace with its size, this can +* be versioned based on the size. +*/ +struct fsx_fileattr { +__u32 fsx_xflags;/* xflags field value (get/set) */ Should this to be
__u64from the start? Seeing as (a) this struct is not already a multiple of 8 bytes and (b) it's likely that we'll have to add a u64 field at some point. That would also address brauner's comment about padding.Hello!
As I have already mentioned, after this syscall API/ABI is finished, I'm planning to prepare patches for changing just selected fields / flags by introducing a new mask field, and support for additional flags used by existing filesystems (like windows flags).
My idea is extending this structure for a new "u32
fsx_xflags_mask" and new "u32fsx_xflags2" + "u32fsx_xflags2_mask". (field names are just examples).
Quoted 8 lines
Quoted 6 lines
So in case you are extending the structure now, please consider if it makes sense to add all members, so we do not have to define 2 or 3 structure versions in near feature.
Your idea of
__u64forfsx_xflagsmeans that it will already cover the "u32fsx_xflags2" field.Ah, ok, so that work *is* still coming. :)
Yes. I'm just waiting until this patch series is accepted.
In past I have already sent RFC patches to the list which modifies the existing ioctl interface. So you can look at it if you want :-)
Quoted 11 lines
Are you still planning to add masks for xflags bits that are clearable and settable? i.e.
__u64 fa_xflags; /* state */ ... <end of V0 structure> __u64 fa_xflags_mask; /* bits for setattr to examine */ __u64 fa_xflags_clearable; /* clearable bits */ __u64 fa_xflags_settable; /* settable bits */
Quoted 2 lines
I think it's easier just to define u64 in the V0 structure and then add the three new fields in V1. What do you think?
I wanted the interface which would allow to atomically change specified bit/flag without the need for get-modify-set. And I think that this would not work as the fa_xflags requires the state.
My idea is following:
__u64 fa_xflags;
...
<end of V0 structure>
__u64 fa_xflags_mask;
The fa_xflags_mask will specify which bits from the fa_xflags and from other fa_* fields in V0 struct are going to be changed.
Quoted 32 lines
--D
Quoted 30 lines
Quoted 29 lines
--D
Quoted 27 lines
include/uapi/linux/fs.h +9
-0+__u32 fsx_extsize;/* extsize field value (get/set)*/ +__u32 fsx_nextents;/* nextents field value (get) */ +__u32 fsx_projid;/* project identifier (get/set) */ +__u32 fsx_cowextsize;/* CoW extsize field value (get/set) */ +}; + +#define FSX_FILEATTR_SIZE_VER0 20 +#define FSX_FILEATTR_SIZE_LATEST FSX_FILEATTR_SIZE_VER0 +/* * Flags for the fsx_xflags field */ scripts/syscall.tbl +2
-0@@ -408,3 +408,5 @@ 465 common listxattrat sys_listxattrat 466 common removexattrat sys_removexattrat 467 common open_tree_attr sys_open_tree_attr +468 common file_getattr sys_file_getattr +469 common file_setattr sys_file_setattrSignature · 2 lines
-- 2.47.2
Christian Brauner
maintainerQuoted 8 lines
Er... "
fsx_fileattr" is the struct that the system call uses?That's a little confusing considering that xfs already has a
xfs_fill_fsxattrfunction that actually fills a struct fileattr. That could be renamedxfs_fill_fileattr.I dunno. There's a part of me that would really rather that the
file_getattrandfile_setattrsyscalls operate on a structfile_attr.
Agreed, I'm pretty sure I suggested this during an earlier review. Fits in line with struct mount_attr and others. Fwiw, struct fileattr (the kernel internal thing) should've really been struct file_kattr or struct kernel_file_attr. This is a common pattern now:
struct mount_attr vs struct mount_kattr
struct clone_args vs struct kernel_clone_kargs
etc.
Quoted 6 lines
More whining/bikeshedding to come.
<snip stuff that looks ok to me>
<<well, I still dislike the
CLASS(fd, fd)(fd) syntax...>>
Noted, and duly ignored...
Quoted 9 lines
Quoted 9 lines
include/uapi/linux/fs.h +0
-0@@ -148,6 +148,24 @@ struct fsxattr {unsigned char fsx_pad[8 ]; };
Quoted 11 lines
include/uapi/linux/fs.h struct fsxattr { · line 159
Quoted 9 lines
include/uapi/linux/fs.h +9
-0+/* +* Variable size structure for file_[sg]et_attr(). +* +* Note. This is alternative to the structure 'struct fileattr'/'struct fsxattr'. +* As this structure is passed to/from userspace with its size, this can +* be versioned based on the size. +*/ +struct fsx_fileattr { +__u32 fsx_xflags;/* xflags field value (get/set) */ Should this to be
__u64from the start? Seeing as (a) this struct is
Agreed. I changed that.
Amir Goldstein
maintainerQuoted 15 lines · Christian Brauner
Quoted 9 lines
Er... "
fsx_fileattr" is the struct that the system call uses?That's a little confusing considering that xfs already has a
xfs_fill_fsxattrfunction that actually fills a struct fileattr. That could be renamedxfs_fill_fileattr.I dunno. There's a part of me that would really rather that the
file_getattrandfile_setattrsyscalls operate on a structfile_attr.Agreed, I'm pretty sure I suggested this during an earlier review. Fits in line with struct
mount_attrand others. Fwiw, struct fileattr (the kernel internal thing) should've really been structfile_kattror structkernel_file_attr. This is a common pattern now:
Quoted 6 lines
struct
mount_attrvs structmount_kattrstruct
clone_argsvs structkernel_clone_kargsetc.
file_attr
I can see the allure, but we have a long history here with fsxattr, so I think it serves the users better to reference this history with fsxattr64.
That, and also, avoid the churn of s/fileattr/file_kattr/ If you want to do this renaming, please do it in the same PR because I don't like the idea of having both file_attr and fileattr in the tree for an unknown period.
Thanks,
Amir.
Quoted 18 lines · Amir Goldstein
Quoted 17 lines · Christian Brauner
Quoted 9 lines
Er... "
fsx_fileattr" is the struct that the system call uses?That's a little confusing considering that xfs already has a
xfs_fill_fsxattrfunction that actually fills a struct fileattr. That could be renamedxfs_fill_fileattr.I dunno. There's a part of me that would really rather that the
file_getattrandfile_setattrsyscalls operate on a structfile_attr.Agreed, I'm pretty sure I suggested this during an earlier review. Fits in line with struct
mount_attrand others. Fwiw, struct fileattr (the kernel internal thing) should've really been structfile_kattror structkernel_file_attr. This is a common pattern now:struct
mount_attrvs structmount_kattr
Quoted 8 lines
Quoted 4 lines
struct
clone_argsvs structkernel_clone_kargsetc.
file_attrI can see the allure, but we have a long history here with fsxattr, so I think it serves the users better to reference this history with fsxattr64.
<shrug> XFS has a long history with 'struct fsxattr' (the structure you passed to XFS_IOC_FSGETXATTR) but the rest of the kernel needn't be so fixated upon the historical name. ext4/f2fs/overlay afaict are just going along for the ride.
IOWs I like brauner's struct file_attr and struct file_kattr suggestions.
Quoted 4 lines
That, and also, avoid the churn of s/fileattr/file_kattr/ If you want to do this renaming, please do it in the same PR because I don't like the idea of having both
file_attrand fileattr in the tree for an unknown period.
But yeah, that ought to be a treewide change done at the same time.
--D
Quoted 4 lines
Thanks,
Amir.
Christian Brauner
maintainerQuoted 36 lines · Darrick J. Wong
Quoted 18 lines · Amir Goldstein
Quoted 17 lines · Christian Brauner
Quoted 9 lines
Er... "
fsx_fileattr" is the struct that the system call uses?That's a little confusing considering that xfs already has a
xfs_fill_fsxattrfunction that actually fills a struct fileattr. That could be renamedxfs_fill_fileattr.I dunno. There's a part of me that would really rather that the
file_getattrandfile_setattrsyscalls operate on a structfile_attr.Agreed, I'm pretty sure I suggested this during an earlier review. Fits in line with struct
mount_attrand others. Fwiw, struct fileattr (the kernel internal thing) should've really been structfile_kattror structkernel_file_attr. This is a common pattern now:struct
mount_attrvs structmount_kattrQuoted 8 lines
Quoted 4 lines
struct
clone_argsvs structkernel_clone_kargsetc.
file_attrI can see the allure, but we have a long history here with fsxattr, so I think it serves the users better to reference this history with fsxattr64.
<shrug> XFS has a long history with 'struct fsxattr' (the structure you passed to
XFS_IOC_FSGETXATTR) but the rest of the kernel needn't be so fixated upon the historical name. ext4/f2fs/overlay afaict are just going along for the ride.IOWs I like brauner's struct
file_attrand structfile_kattrsuggestions.
Quoted 6 lines
Quoted 4 lines
That, and also, avoid the churn of s/fileattr/file_kattr/ If you want to do this renaming, please do it in the same PR because I don't like the idea of having both
file_attrand fileattr in the tree for an unknown period.But yeah, that ought to be a treewide change done at the same time.
Why do you all hate me? ;)
See the appended patch.
From 3a5f5c281e7993342cf285285fa0a496d4fca2b7 Mon Sep 17 00:00:00 2001
From: Christian Brauner <[email protected]>
Date: Thu, 3 Jul 2025 09:36:41 +0200
Subject: [PATCH] tree-wide: s/struct fileattr/struct file_kattr/g
Now that we expose struct file_attr as our uapi struct rename all the internal struct to struct file_kattr to clearly communicate that it is a kernel internal struct. This is similar to struct mount_{k}attr and others.
--- Documentation/filesystems/locking.rst | 4 ++-- Documentation/filesystems/vfs.rst | 4 ++-- fs/bcachefs/fs.c | 4 ++-- fs/btrfs/ioctl.c | 4 ++-- fs/btrfs/ioctl.h | 6 ++--- fs/ecryptfs/inode.c | 4 ++-- fs/efivarfs/inode.c | 4 ++-- fs/ext2/ext2.h | 4 ++-- fs/ext2/ioctl.c | 4 ++-- fs/ext4/ext4.h | 4 ++-- fs/ext4/ioctl.c | 4 ++-- fs/f2fs/f2fs.h | 4 ++-- fs/f2fs/file.c | 4 ++-- fs/file_attr.c | 34 +++++++++++++-------------- fs/fuse/fuse_i.h | 4 ++-- fs/fuse/ioctl.c | 4 ++-- fs/gfs2/file.c | 4 ++-- fs/gfs2/inode.h | 4 ++-- fs/hfsplus/hfsplus_fs.h | 4 ++-- fs/hfsplus/inode.c | 4 ++-- fs/jfs/ioctl.c | 4 ++-- fs/jfs/jfs_inode.h | 4 ++-- fs/nilfs2/ioctl.c | 4 ++-- fs/nilfs2/nilfs.h | 4 ++-- fs/ocfs2/ioctl.c | 4 ++-- fs/ocfs2/ioctl.h | 4 ++-- fs/orangefs/inode.c | 4 ++-- fs/overlayfs/copy_up.c | 4 ++-- fs/overlayfs/inode.c | 12 +++++----- fs/overlayfs/overlayfs.h | 10 ++++---- fs/overlayfs/util.c | 2 +- fs/ubifs/ioctl.c | 4 ++-- fs/ubifs/ubifs.h | 4 ++-- fs/xfs/xfs_ioctl.c | 18 +++++++------- fs/xfs/xfs_ioctl.h | 4 ++-- include/linux/fileattr.h | 14 +++++------ include/linux/fs.h | 6 ++--- include/linux/lsm_hook_defs.h | 4 ++-- include/linux/security.h | 8 +++---- include/uapi/linux/fs.h | 2 +- mm/shmem.c | 4 ++-- security/security.c | 4 ++-- security/selinux/hooks.c | 4 ++-- 43 files changed, 122 insertions(+), 122 deletions(-)
Documentation/filesystems/locking.rst +2 -2
@@ -87,8 +87,8 @@ prototypes:: int (*tmpfile) (struct mnt_idmap *, struct inode *, struct file *, umode_t); int (*fileattr_set)(struct mnt_idmap *idmap, - struct dentry *dentry, struct fileattr *fa); - int (*fileattr_get)(struct dentry *dentry, struct fileattr *fa); + struct dentry *dentry, struct file_kattr *fa); + int (*fileattr_get)(struct dentry *dentry, struct file_kattr *fa); struct posix_acl * (*get_acl)(struct mnt_idmap *, struct dentry *, int); struct offset_ctx *(*get_offset_ctx)(struct inode *inode);
Documentation/filesystems/vfs.rst +2 -2
@@ -515,8 +515,8 @@ As of kernel 2.6.22, the following members are defined: struct posix_acl * (*get_acl)(struct mnt_idmap *, struct dentry *, int); int (*set_acl)(struct mnt_idmap *, struct dentry *, struct posix_acl *, int); int (*fileattr_set)(struct mnt_idmap *idmap, - struct dentry *dentry, struct fileattr *fa); - int (*fileattr_get)(struct dentry *dentry, struct fileattr *fa); + struct dentry *dentry, struct file_kattr *fa); + int (*fileattr_get)(struct dentry *dentry, struct file_kattr *fa); struct offset_ctx *(*get_offset_ctx)(struct inode *inode); };
fs/bcachefs/fs.c +2 -2
@@ -1619,7 +1619,7 @@ static const __maybe_unused unsigned bch_flags_to_xflags[] = { };static int bch2_fileattr_get (struct dentry *dentry, -struct fileattr *fa) +struct file_kattr *fa) {struct bch_inode_info *inode =to_bch_ei (d_inode (dentry));struct bch_fs *c = inode->v.i_sb->s_fs_info;
@@ -1682,7 +1682,7 @@ static int fssetxattr_inode_update_fn(struct btree_trans *trans,static int bch2_fileattr_set (struct mnt_idmap *idmap,struct dentry *dentry, -struct fileattr *fa) +struct file_kattr *fa) {struct bch_inode_info *inode =to_bch_ei (d_inode (dentry));struct bch_fs *c = inode->v.i_sb->s_fs_info;
fs/btrfs/ioctl.c +2 -2
@@ -245,7 +245,7 @@ static int btrfs_check_ioctl_vol_args2_subvol_name(const struct btrfs_ioctl_vol_* Set flags/xflags from the internal inode flags. The remaining items of * fsxattr are zeroed. */ -int btrfs_fileattr_get (struct dentry *dentry,struct fileattr *fa) +int btrfs_fileattr_get (struct dentry *dentry,struct file_kattr *fa) {const struct btrfs_inode *inode =BTRFS_I (d_inode (dentry));
@@ -254,7 +254,7 @@ int btrfs_fileattr_get(struct dentry *dentry, struct fileattr *fa) }int btrfs_fileattr_set (struct mnt_idmap *idmap, -struct dentry *dentry,struct fileattr *fa) +struct dentry *dentry,struct file_kattr *fa) {struct btrfs_inode *inode =BTRFS_I (d_inode (dentry));struct btrfs_root *root = inode->root;
fs/btrfs/ioctl.h +3 -3
@@ -8,7 +8,7 @@struct file ;struct dentry ;struct mnt_idmap ; -struct fileattr ; +struct file_kattr ;struct io_uring_cmd ;struct btrfs_inode ;struct btrfs_fs_info ;
@@ -16,9 +16,9 @@ struct btrfs_ioctl_balance_args;long btrfs_ioctl (struct file *file,unsigned int cmd,unsigned long arg);long btrfs_compat_ioctl (struct file *file,unsigned int cmd,unsigned long arg); -int btrfs_fileattr_get (struct dentry *dentry,struct fileattr *fa); +int btrfs_fileattr_get (struct dentry *dentry,struct file_kattr *fa);int btrfs_fileattr_set (struct mnt_idmap *idmap, -struct dentry *dentry,struct fileattr *fa); +struct dentry *dentry,struct file_kattr *fa);int btrfs_ioctl_get_supported_features (void __user *arg);void btrfs_sync_inode_flags_to_i_flags (struct btrfs_inode *inode); void btrfs_update_ioctl_balance_args(struct btrfs_fs_info *fs_info,
fs/ecryptfs/inode.c +2 -2
@@ -1124,13 +1124,13 @@ static int ecryptfs_removexattr(struct dentry *dentry, struct inode *inode,return rc; } -static int ecryptfs_fileattr_get (struct dentry *dentry,struct fileattr *fa) +static int ecryptfs_fileattr_get (struct dentry *dentry,struct file_kattr *fa) {return vfs_fileattr_get (ecryptfs_dentry_to_lower (dentry), fa); }static int ecryptfs_fileattr_set (struct mnt_idmap *idmap, -struct dentry *dentry,struct fileattr *fa) +struct dentry *dentry,struct file_kattr *fa) {struct dentry *lower_dentry =ecryptfs_dentry_to_lower (dentry);int rc;
fs/efivarfs/inode.c +2 -2
@@ -138,7 +138,7 @@ const struct inode_operations efivarfs_dir_inode_operations = { };static int -efivarfs_fileattr_get (struct dentry *dentry,struct fileattr *fa) +efivarfs_fileattr_get (struct dentry *dentry,struct file_kattr *fa) {unsigned int i_flags;unsigned int flags =0 ;
@@ -154,7 +154,7 @@ efivarfs_fileattr_get(struct dentry *dentry, struct fileattr *fa)static int efivarfs_fileattr_set (struct mnt_idmap *idmap, -struct dentry *dentry,struct fileattr *fa) +struct dentry *dentry,struct file_kattr *fa) {unsigned int i_flags =0 ;
fs/ext2/ext2.h +2 -2
@@ -750,9 +750,9 @@ extern int ext2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, u64 start, u64 len);/* ioctl.c */ -extern int ext2_fileattr_get (struct dentry *dentry,struct fileattr *fa); +extern int ext2_fileattr_get (struct dentry *dentry,struct file_kattr *fa);extern int ext2_fileattr_set (struct mnt_idmap *idmap, -struct dentry *dentry,struct fileattr *fa); +struct dentry *dentry,struct file_kattr *fa);extern long ext2_ioctl (struct file *,unsigned int ,unsigned long );extern long ext2_compat_ioctl (struct file *,unsigned int ,unsigned long );
fs/ext2/ioctl.c +2 -2
@@ -18,7 +18,7 @@#include <linux/uaccess.h> #include <linux/fileattr.h> -int ext2_fileattr_get (struct dentry *dentry,struct fileattr *fa) +int ext2_fileattr_get (struct dentry *dentry,struct file_kattr *fa) {struct ext2_inode_info *ei =EXT2_I (d_inode (dentry));
@@ -28,7 +28,7 @@ int ext2_fileattr_get(struct dentry *dentry, struct fileattr *fa) }int ext2_fileattr_set (struct mnt_idmap *idmap, -struct dentry *dentry,struct fileattr *fa) +struct dentry *dentry,struct file_kattr *fa) {struct inode *inode =d_inode (dentry);struct ext2_inode_info *ei =EXT2_I (inode);
fs/ext4/ext4.h +2 -2
@@ -3103,8 +3103,8 @@ extern int ext4_ind_remove_space(handle_t *handle, struct inode *inode,extern long ext4_ioctl (struct file *,unsigned int ,unsigned long );extern long ext4_compat_ioctl (struct file *,unsigned int ,unsigned long );int ext4_fileattr_set (struct mnt_idmap *idmap, -struct dentry *dentry,struct fileattr *fa); -int ext4_fileattr_get (struct dentry *dentry,struct fileattr *fa); +struct dentry *dentry,struct file_kattr *fa); +int ext4_fileattr_get (struct dentry *dentry,struct file_kattr *fa);extern void ext4_reset_inode_seed (struct inode *inode);int ext4_update_overhead (struct super_block *sb,bool force);int ext4_force_shutdown (struct super_block *sb,u32 flags);
fs/ext4/ioctl.c +2 -2
@@ -980,7 +980,7 @@ static long ext4_ioctl_group_add(struct file *file,return err; } -int ext4_fileattr_get (struct dentry *dentry,struct fileattr *fa) +int ext4_fileattr_get (struct dentry *dentry,struct file_kattr *fa) {struct inode *inode =d_inode (dentry);struct ext4_inode_info *ei =EXT4_I (inode);
@@ -997,7 +997,7 @@ int ext4_fileattr_get(struct dentry *dentry, struct fileattr *fa) }int ext4_fileattr_set (struct mnt_idmap *idmap, -struct dentry *dentry,struct fileattr *fa) +struct dentry *dentry,struct file_kattr *fa) {struct inode *inode =d_inode (dentry);u32 flags = fa->flags;
fs/f2fs/f2fs.h +2 -2
@@ -3615,9 +3615,9 @@ void f2fs_truncate_data_blocks_range(struct dnode_of_data *dn, int count);int f2fs_do_shutdown (struct f2fs_sb_info *sbi,unsigned int flag,bool readonly,bool need_lock);int f2fs_precache_extents (struct inode *inode); -int f2fs_fileattr_get (struct dentry *dentry,struct fileattr *fa); +int f2fs_fileattr_get (struct dentry *dentry,struct file_kattr *fa);int f2fs_fileattr_set (struct mnt_idmap *idmap, -struct dentry *dentry,struct fileattr *fa); +struct dentry *dentry,struct file_kattr *fa);long f2fs_ioctl (struct file *filp,unsigned int cmd,unsigned long arg);long f2fs_compat_ioctl (struct file *file,unsigned int cmd,unsigned long arg);int f2fs_transfer_project_quota (struct inode *inode,kprojid_t kprojid);
fs/f2fs/file.c +2 -2
@@ -3356,7 +3356,7 @@ static int f2fs_ioc_setproject(struct inode *inode, __u32 projid) }#endif -int f2fs_fileattr_get (struct dentry *dentry,struct fileattr *fa) +int f2fs_fileattr_get (struct dentry *dentry,struct file_kattr *fa) {struct inode *inode =d_inode (dentry);struct f2fs_inode_info *fi =F2FS_I (inode);
@@ -3380,7 +3380,7 @@ int f2fs_fileattr_get(struct dentry *dentry, struct fileattr *fa) }int f2fs_fileattr_set (struct mnt_idmap *idmap, -struct dentry *dentry,struct fileattr *fa) +struct dentry *dentry,struct file_kattr *fa) {struct inode *inode =d_inode (dentry);u32 fsflags = fa->flags, mask =F2FS_SETTABLE_FS_FL ;
fs/file_attr.c +17 -17
@@ -17,7 +17,7 @@* Set ->fsx_xflags, ->fsx_valid and ->flags (translated xflags). All * other fields are zeroed. */ -void fileattr_fill_xflags (struct fileattr *fa,u32 xflags) +void fileattr_fill_xflags (struct file_kattr *fa,u32 xflags) {memset (fa,0 ,sizeof (*fa)); fa->fsx_valid = true;
@@ -47,7 +47,7 @@ EXPORT_SYMBOL(fileattr_fill_xflags);* Set ->flags, ->flags_valid and ->fsx_xflags (translated flags). * All other fields are zeroed. */ -void fileattr_fill_flags (struct fileattr *fa,u32 flags) +void fileattr_fill_flags (struct file_kattr *fa,u32 flags) {memset (fa,0 ,sizeof (*fa)); fa->flags_valid = true;
@@ -78,7 +78,7 @@ EXPORT_SYMBOL(fileattr_fill_flags);* * Return: 0 on success, or a negative error on failure. */ -int vfs_fileattr_get (struct dentry *dentry,struct fileattr *fa) +int vfs_fileattr_get (struct dentry *dentry,struct file_kattr *fa) {struct inode *inode =d_inode (dentry);int error;
@@ -94,7 +94,7 @@ int vfs_fileattr_get(struct dentry *dentry, struct fileattr *fa) }EXPORT_SYMBOL (vfs_fileattr_get); -static void fileattr_to_file_attr (const struct fileattr *fa, +static void fileattr_to_file_attr (const struct file_kattr *fa,struct file_attr *fattr) {__u32 mask =FS_XFLAGS_MASK ;
@@ -114,7 +114,7 @@ static void fileattr_to_file_attr(const struct fileattr *fa,* * Return: 0 on success, or -EFAULT on failure. */ -int copy_fsxattr_to_user (const struct fileattr *fa,struct fsxattr __user *ufa) +int copy_fsxattr_to_user (const struct file_kattr *fa,struct fsxattr __user *ufa) {struct fsxattr xfa;__u32 mask =FS_XFLAGS_MASK ;
@@ -134,7 +134,7 @@ int copy_fsxattr_to_user(const struct fileattr *fa, struct fsxattr __user *ufa)EXPORT_SYMBOL (copy_fsxattr_to_user);static int file_attr_to_fileattr (const struct file_attr *fattr, -struct fileattr *fa) +struct file_kattr *fa) {__u32 mask =FS_XFLAGS_MASK ;
@@ -150,7 +150,7 @@ static int file_attr_to_fileattr(const struct file_attr *fattr,return 0 ; } -static int copy_fsxattr_from_user (struct fileattr *fa, +static int copy_fsxattr_from_user (struct file_kattr *fa,struct fsxattr __user *ufa) {struct fsxattr xfa;
@@ -179,8 +179,8 @@ static int copy_fsxattr_from_user(struct fileattr *fa,* Note: must be called with inode lock held. */ static int fileattr_set_prepare (struct inode *inode, -const struct fileattr *old_ma, -struct fileattr *fa) +const struct file_kattr *old_ma, +struct file_kattr *fa) {int err;
@@ -263,10 +263,10 @@ static int fileattr_set_prepare(struct inode *inode,* Return: 0 on success, or a negative error on failure. */ int vfs_fileattr_set (struct mnt_idmap *idmap,struct dentry *dentry, -struct fileattr *fa) +struct file_kattr *fa) {struct inode *inode =d_inode (dentry); -struct fileattr old_ma = {}; +struct file_kattr old_ma = {};int err;if (!inode->i_op->fileattr_set)
@@ -308,7 +308,7 @@ EXPORT_SYMBOL(vfs_fileattr_set);int ioctl_getflags (struct file *file,unsigned int __user *argp) { -struct fileattr fa = { .flags_valid = true };/* hint only */ +struct file_kattr fa = { .flags_valid = true };/* hint only */ int err; err =vfs_fileattr_get (file->f_path.dentry, &fa);
@@ -324,7 +324,7 @@ int ioctl_setflags(struct file *file, unsigned int __user *argp) {struct mnt_idmap *idmap =file_mnt_idmap (file);struct dentry *dentry = file->f_path.dentry; -struct fileattr fa; +struct file_kattr fa;unsigned int flags;int err;
@@ -345,7 +345,7 @@ EXPORT_SYMBOL(ioctl_setflags);int ioctl_fsgetxattr (struct file *file,void __user *argp) { -struct fileattr fa = { .fsx_valid = true };/* hint only */ +struct file_kattr fa = { .fsx_valid = true };/* hint only */ int err; err =vfs_fileattr_get (file->f_path.dentry, &fa);
@@ -362,7 +362,7 @@ int ioctl_fssetxattr(struct file *file, void __user *argp) {struct mnt_idmap *idmap =file_mnt_idmap (file);struct dentry *dentry = file->f_path.dentry; -struct fileattr fa; +struct file_kattr fa;int err; err =copy_fsxattr_from_user (&fa, argp);
@@ -387,7 +387,7 @@ SYSCALL_DEFINE5(file_getattr, int, dfd, const char __user *, filename, struct filename *name __free(putname) = NULL;unsigned int lookup_flags =0 ;struct file_attr fattr; -struct fileattr fa; +struct file_kattr fa;int error;BUILD_BUG_ON (sizeof (struct file_attr ) <FILE_ATTR_SIZE_VER0 );
@@ -442,7 +442,7 @@ SYSCALL_DEFINE5(file_setattr, int, dfd, const char __user *, filename, struct filename *name __free(putname) = NULL;unsigned int lookup_flags =0 ;struct file_attr fattr; -struct fileattr fa; +struct file_kattr fa;int error;BUILD_BUG_ON (sizeof (struct file_attr ) <FILE_ATTR_SIZE_VER0 );
fs/fuse/fuse_i.h +2 -2
@@ -1486,9 +1486,9 @@ void fuse_dax_cancel_work(struct fuse_conn *fc);long fuse_file_ioctl (struct file *file,unsigned int cmd,unsigned long arg);long fuse_file_compat_ioctl (struct file *file,unsigned int cmd,unsigned long arg); -int fuse_fileattr_get (struct dentry *dentry,struct fileattr *fa); +int fuse_fileattr_get (struct dentry *dentry,struct file_kattr *fa);int fuse_fileattr_set (struct mnt_idmap *idmap, -struct dentry *dentry,struct fileattr *fa); +struct dentry *dentry,struct file_kattr *fa);/* iomode.c */ int fuse_file_cached_io_open (struct inode *inode,struct fuse_file *ff);
fs/fuse/ioctl.c +2 -2
@@ -502,7 +502,7 @@ static void fuse_priv_ioctl_cleanup(struct inode *inode, struct fuse_file *ff)fuse_file_release (inode, ff,O_RDONLY ,NULL ,S_ISDIR (inode->i_mode)); } -int fuse_fileattr_get (struct dentry *dentry,struct fileattr *fa) +int fuse_fileattr_get (struct dentry *dentry,struct file_kattr *fa) {struct inode *inode =d_inode (dentry);struct fuse_file *ff;
@@ -542,7 +542,7 @@ int fuse_fileattr_get(struct dentry *dentry, struct fileattr *fa) }int fuse_fileattr_set (struct mnt_idmap *idmap, -struct dentry *dentry,struct fileattr *fa) +struct dentry *dentry,struct file_kattr *fa) {struct inode *inode =d_inode (dentry);struct fuse_file *ff;
fs/gfs2/file.c +2 -2
@@ -155,7 +155,7 @@ static inline u32 gfs2_gfsflags_to_fsflags(struct inode *inode, u32 gfsflags)return fsflags; } -int gfs2_fileattr_get (struct dentry *dentry,struct fileattr *fa) +int gfs2_fileattr_get (struct dentry *dentry,struct file_kattr *fa) {struct inode *inode =d_inode (dentry);struct gfs2_inode *ip =GFS2_I (inode);
@@ -276,7 +276,7 @@ static int do_gfs2_set_flags(struct inode *inode, u32 reqflags, u32 mask) }int gfs2_fileattr_set (struct mnt_idmap *idmap, -struct dentry *dentry,struct fileattr *fa) +struct dentry *dentry,struct file_kattr *fa) {struct inode *inode =d_inode (dentry);u32 fsflags = fa->flags, gfsflags =0 ;
fs/gfs2/inode.h +2 -2
@@ -107,9 +107,9 @@ loff_t gfs2_seek_hole(struct file *file, loff_t offset);extern const struct file_operations gfs2_file_fops_nolock;extern const struct file_operations gfs2_dir_fops_nolock; -int gfs2_fileattr_get (struct dentry *dentry,struct fileattr *fa); +int gfs2_fileattr_get (struct dentry *dentry,struct file_kattr *fa);int gfs2_fileattr_set (struct mnt_idmap *idmap, -struct dentry *dentry,struct fileattr *fa); +struct dentry *dentry,struct file_kattr *fa);void gfs2_set_inode_flags (struct inode *inode);#ifdef CONFIG_GFS2_FS_LOCKING_DLM
fs/hfsplus/hfsplus_fs.h +2 -2
@@ -489,9 +489,9 @@ int hfsplus_getattr(struct mnt_idmap *idmap, const struct path *path, unsigned int query_flags);int hfsplus_file_fsync (struct file *file,loff_t start,loff_t end,int datasync); -int hfsplus_fileattr_get (struct dentry *dentry,struct fileattr *fa); +int hfsplus_fileattr_get (struct dentry *dentry,struct file_kattr *fa);int hfsplus_fileattr_set (struct mnt_idmap *idmap, -struct dentry *dentry,struct fileattr *fa); +struct dentry *dentry,struct file_kattr *fa);/* ioctl.c */ long hfsplus_ioctl (struct file *filp,unsigned int cmd,unsigned long arg);
fs/hfsplus/inode.c +2 -2
@@ -654,7 +654,7 @@ int hfsplus_cat_write_inode(struct inode *inode)return res; } -int hfsplus_fileattr_get (struct dentry *dentry,struct fileattr *fa) +int hfsplus_fileattr_get (struct dentry *dentry,struct file_kattr *fa) {struct inode *inode =d_inode (dentry);struct hfsplus_inode_info *hip =HFSPLUS_I (inode);
@@ -673,7 +673,7 @@ int hfsplus_fileattr_get(struct dentry *dentry, struct fileattr *fa) }int hfsplus_fileattr_set (struct mnt_idmap *idmap, -struct dentry *dentry,struct fileattr *fa) +struct dentry *dentry,struct file_kattr *fa) {struct inode *inode =d_inode (dentry);struct hfsplus_inode_info *hip =HFSPLUS_I (inode);
fs/jfs/ioctl.c +2 -2
@@ -57,7 +57,7 @@ static long jfs_map_ext2(unsigned long flags, int from)return mapped; } -int jfs_fileattr_get (struct dentry *dentry,struct fileattr *fa) +int jfs_fileattr_get (struct dentry *dentry,struct file_kattr *fa) {struct jfs_inode_info *jfs_inode =JFS_IP (d_inode (dentry));unsigned int flags = jfs_inode->mode2 &JFS_FL_USER_VISIBLE ;
@@ -71,7 +71,7 @@ int jfs_fileattr_get(struct dentry *dentry, struct fileattr *fa) }int jfs_fileattr_set (struct mnt_idmap *idmap, -struct dentry *dentry,struct fileattr *fa) +struct dentry *dentry,struct file_kattr *fa) {struct inode *inode =d_inode (dentry);struct jfs_inode_info *jfs_inode =JFS_IP (inode);
fs/jfs/jfs_inode.h +2 -2
@@ -9,9 +9,9 @@ struct fid;extern struct inode *ialloc (struct inode *,umode_t );extern int jfs_fsync (struct file *,loff_t ,loff_t ,int ); -extern int jfs_fileattr_get (struct dentry *dentry,struct fileattr *fa); +extern int jfs_fileattr_get (struct dentry *dentry,struct file_kattr *fa);extern int jfs_fileattr_set (struct mnt_idmap *idmap, -struct dentry *dentry,struct fileattr *fa); +struct dentry *dentry,struct file_kattr *fa);extern long jfs_ioctl (struct file *,unsigned int ,unsigned long );extern struct inode *jfs_iget (struct super_block *,unsigned long );extern int jfs_commit_inode (struct inode *,int );
fs/nilfs2/ioctl.c +2 -2
@@ -118,7 +118,7 @@ static int nilfs_ioctl_wrap_copy(struct the_nilfs *nilfs,* * Return: always 0 as success. */ -int nilfs_fileattr_get (struct dentry *dentry,struct fileattr *fa) +int nilfs_fileattr_get (struct dentry *dentry,struct file_kattr *fa) {struct inode *inode =d_inode (dentry);
@@ -136,7 +136,7 @@ int nilfs_fileattr_get(struct dentry *dentry, struct fileattr *fa)* Return: 0 on success, or a negative error code on failure. */ int nilfs_fileattr_set (struct mnt_idmap *idmap, -struct dentry *dentry,struct fileattr *fa) +struct dentry *dentry,struct file_kattr *fa) {struct inode *inode =d_inode (dentry);struct nilfs_transaction_info ti;
fs/nilfs2/nilfs.h +2 -2
@@ -268,9 +268,9 @@ int nilfs_set_link(struct inode *dir, struct nilfs_dir_entry *de,extern int nilfs_sync_file (struct file *,loff_t ,loff_t ,int );/* ioctl.c */ -int nilfs_fileattr_get (struct dentry *dentry,struct fileattr *m); +int nilfs_fileattr_get (struct dentry *dentry,struct file_kattr *m);int nilfs_fileattr_set (struct mnt_idmap *idmap, -struct dentry *dentry,struct fileattr *fa); +struct dentry *dentry,struct file_kattr *fa);long nilfs_ioctl (struct file *,unsigned int ,unsigned long );long nilfs_compat_ioctl (struct file *file,unsigned int cmd,unsigned long arg); int nilfs_ioctl_prepare_clean_segments(struct the_nilfs *, struct nilfs_argv *,
fs/ocfs2/ioctl.c +2 -2
@@ -62,7 +62,7 @@ static inline int o2info_coherent(struct ocfs2_info_request *req)return (!(req->ir_flags &OCFS2_INFO_FL_NON_COHERENT )); } -int ocfs2_fileattr_get (struct dentry *dentry,struct fileattr *fa) +int ocfs2_fileattr_get (struct dentry *dentry,struct file_kattr *fa) {struct inode *inode =d_inode (dentry);unsigned int flags;
@@ -83,7 +83,7 @@ int ocfs2_fileattr_get(struct dentry *dentry, struct fileattr *fa) }int ocfs2_fileattr_set (struct mnt_idmap *idmap, -struct dentry *dentry,struct fileattr *fa) +struct dentry *dentry,struct file_kattr *fa) {struct inode *inode =d_inode (dentry);unsigned int flags = fa->flags;
fs/ocfs2/ioctl.h +2 -2
@@ -11,9 +11,9 @@#ifndef OCFS2_IOCTL_PROTO_H #define OCFS2_IOCTL_PROTO_H -int ocfs2_fileattr_get (struct dentry *dentry,struct fileattr *fa); +int ocfs2_fileattr_get (struct dentry *dentry,struct file_kattr *fa);int ocfs2_fileattr_set (struct mnt_idmap *idmap, -struct dentry *dentry,struct fileattr *fa); +struct dentry *dentry,struct file_kattr *fa);long ocfs2_ioctl (struct file *filp,unsigned int cmd,unsigned long arg);long ocfs2_compat_ioctl (struct file *file,unsigned cmd,unsigned long arg);
fs/orangefs/inode.c +2 -2
@@ -887,7 +887,7 @@ int orangefs_update_time(struct inode *inode, int flags)return __orangefs_setattr (inode, &iattr); } -static int orangefs_fileattr_get (struct dentry *dentry,struct fileattr *fa) +static int orangefs_fileattr_get (struct dentry *dentry,struct file_kattr *fa) {u64 val =0 ;int ret;
@@ -908,7 +908,7 @@ static int orangefs_fileattr_get(struct dentry *dentry, struct fileattr *fa) }static int orangefs_fileattr_set (struct mnt_idmap *idmap, -struct dentry *dentry,struct fileattr *fa) +struct dentry *dentry,struct file_kattr *fa) {u64 val =0 ;
fs/overlayfs/copy_up.c +2 -2
@@ -171,8 +171,8 @@ int ovl_copy_xattr(struct super_block *sb, const struct path *oldpath, struct destatic int ovl_copy_fileattr (struct inode *inode,const struct path *old,const struct path *new) { -struct fileattr oldfa = { .flags_valid = true }; -struct fileattr newfa = { .flags_valid = true }; +struct file_kattr oldfa = { .flags_valid = true }; +struct file_kattr newfa = { .flags_valid = true };int err; err =ovl_real_fileattr_get (old, &oldfa);
fs/overlayfs/inode.c +6 -6
@@ -610,7 +610,7 @@ static int ovl_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,* Introducing security_inode_fileattr_get/set() hooks would solve this issue * properly. */ -static int ovl_security_fileattr (const struct path *realpath,struct fileattr *fa, +static int ovl_security_fileattr (const struct path *realpath,struct file_kattr *fa,bool set) {struct file *file;
@@ -637,7 +637,7 @@ static int ovl_security_fileattr(const struct path *realpath, struct fileattr *freturn err; } -int ovl_real_fileattr_set (const struct path *realpath,struct fileattr *fa) +int ovl_real_fileattr_set (const struct path *realpath,struct file_kattr *fa) {int err;
@@ -649,7 +649,7 @@ int ovl_real_fileattr_set(const struct path *realpath, struct fileattr *fa) }int ovl_fileattr_set (struct mnt_idmap *idmap, -struct dentry *dentry,struct fileattr *fa) +struct dentry *dentry,struct file_kattr *fa) {struct inode *inode =d_inode (dentry);struct path upperpath;
@@ -697,7 +697,7 @@ int ovl_fileattr_set(struct mnt_idmap *idmap, }/* Convert inode protection flags to fileattr flags */ -static void ovl_fileattr_prot_flags (struct inode *inode,struct fileattr *fa) +static void ovl_fileattr_prot_flags (struct inode *inode,struct file_kattr *fa) {BUILD_BUG_ON (OVL_PROT_FS_FLAGS_MASK & ~FS_COMMON_FL );BUILD_BUG_ON (OVL_PROT_FSX_FLAGS_MASK & ~FS_XFLAG_COMMON );
@@ -712,7 +712,7 @@ static void ovl_fileattr_prot_flags(struct inode *inode, struct fileattr *fa) } } -int ovl_real_fileattr_get (const struct path *realpath,struct fileattr *fa) +int ovl_real_fileattr_get (const struct path *realpath,struct file_kattr *fa) {int err;
@@ -723,7 +723,7 @@ int ovl_real_fileattr_get(const struct path *realpath, struct fileattr *fa)return vfs_fileattr_get (realpath->dentry, fa); } -int ovl_fileattr_get (struct dentry *dentry,struct fileattr *fa) +int ovl_fileattr_get (struct dentry *dentry,struct file_kattr *fa) {struct inode *inode =d_inode (dentry);struct path realpath;
fs/overlayfs/overlayfs.h +5 -5
@@ -815,7 +815,7 @@ void ovl_copyattr(struct inode *to);void ovl_check_protattr (struct inode *inode,struct dentry *upper);int ovl_set_protattr (struct inode *inode,struct dentry *upper, -struct fileattr *fa); +struct file_kattr *fa);static inline void ovl_copyflags (struct inode *from,struct inode *to) {
@@ -847,11 +847,11 @@ struct dentry *ovl_create_temp(struct ovl_fs *ofs, struct dentry *workdir,/* file.c */ extern const struct file_operations ovl_file_operations; -int ovl_real_fileattr_get (const struct path *realpath,struct fileattr *fa); -int ovl_real_fileattr_set (const struct path *realpath,struct fileattr *fa); -int ovl_fileattr_get (struct dentry *dentry,struct fileattr *fa); +int ovl_real_fileattr_get (const struct path *realpath,struct file_kattr *fa); +int ovl_real_fileattr_set (const struct path *realpath,struct file_kattr *fa); +int ovl_fileattr_get (struct dentry *dentry,struct file_kattr *fa);int ovl_fileattr_set (struct mnt_idmap *idmap, -struct dentry *dentry,struct fileattr *fa); +struct dentry *dentry,struct file_kattr *fa);struct ovl_file ;struct ovl_file *ovl_file_alloc (struct file *realfile);void ovl_file_free (struct ovl_file *of);
fs/overlayfs/util.c +1 -1
@@ -959,7 +959,7 @@ void ovl_check_protattr(struct inode *inode, struct dentry *upper) }int ovl_set_protattr (struct inode *inode,struct dentry *upper, -struct fileattr *fa) +struct file_kattr *fa) {struct ovl_fs *ofs =OVL_FS (inode->i_sb);char buf[OVL_PROTATTR_MAX ];
fs/ubifs/ioctl.c +2 -2
@@ -130,7 +130,7 @@ static int setflags(struct inode *inode, int flags)return err; } -int ubifs_fileattr_get (struct dentry *dentry,struct fileattr *fa) +int ubifs_fileattr_get (struct dentry *dentry,struct file_kattr *fa) {struct inode *inode =d_inode (dentry);int flags =ubifs2ioctl (ubifs_inode (inode)->flags);
@@ -145,7 +145,7 @@ int ubifs_fileattr_get(struct dentry *dentry, struct fileattr *fa) }int ubifs_fileattr_set (struct mnt_idmap *idmap, -struct dentry *dentry,struct fileattr *fa) +struct dentry *dentry,struct file_kattr *fa) {struct inode *inode =d_inode (dentry);int flags = fa->flags;
fs/ubifs/ubifs.h +2 -2
@@ -2073,9 +2073,9 @@ int ubifs_recover_size(struct ubifs_info *c, bool in_place);void ubifs_destroy_size_tree (struct ubifs_info *c);/* ioctl.c */ -int ubifs_fileattr_get (struct dentry *dentry,struct fileattr *fa); +int ubifs_fileattr_get (struct dentry *dentry,struct file_kattr *fa);int ubifs_fileattr_set (struct mnt_idmap *idmap, -struct dentry *dentry,struct fileattr *fa); +struct dentry *dentry,struct file_kattr *fa);long ubifs_ioctl (struct file *file,unsigned int cmd,unsigned long arg);void ubifs_set_inode_flags (struct inode *inode);#ifdef CONFIG_COMPAT
fs/xfs/xfs_ioctl.c +9 -9
@@ -444,7 +444,7 @@ static voidxfs_fill_fsxattr ( struct xfs_inode *ip, int whichfork, - struct fileattr *fa) + struct file_kattr *fa) { struct xfs_mount *mp = ip->i_mount;struct xfs_ifork *ifp =xfs_ifork_ptr (ip, whichfork);
@@ -496,7 +496,7 @@ xfs_ioc_fsgetxattra( xfs_inode_t *ip, void __user *arg) { -struct fileattr fa; +struct file_kattr fa;xfs_ilock (ip,XFS_ILOCK_SHARED );xfs_fill_fsxattr (ip,XFS_ATTR_FORK , &fa);
@@ -508,7 +508,7 @@ xfs_ioc_fsgetxattra(int xfs_fileattr_get (struct dentry *dentry, -struct fileattr *fa) +struct file_kattr *fa) {struct xfs_inode *ip =XFS_I (d_inode (dentry));
@@ -526,7 +526,7 @@ static intxfs_ioctl_setattr_xflags ( struct xfs_trans *tp, struct xfs_inode *ip, - struct fileattr *fa) + struct file_kattr *fa) { struct xfs_mount *mp = ip->i_mount;bool rtflag = (fa->fsx_xflags &FS_XFLAG_REALTIME );
@@ -582,7 +582,7 @@ xfs_ioctl_setattr_xflags(static void xfs_ioctl_setattr_prepare_dax (struct xfs_inode *ip, -struct fileattr *fa) +struct file_kattr *fa) {struct xfs_mount *mp = ip->i_mount;struct inode *inode =VFS_I (ip);
@@ -642,7 +642,7 @@ xfs_ioctl_setattr_get_trans(static int xfs_ioctl_setattr_check_extsize (struct xfs_inode *ip, -struct fileattr *fa) +struct file_kattr *fa) {struct xfs_mount *mp = ip->i_mount;xfs_failaddr_t failaddr;
@@ -684,7 +684,7 @@ xfs_ioctl_setattr_check_extsize(static int xfs_ioctl_setattr_check_cowextsize (struct xfs_inode *ip, -struct fileattr *fa) +struct file_kattr *fa) {struct xfs_mount *mp = ip->i_mount;xfs_failaddr_t failaddr;
@@ -709,7 +709,7 @@ xfs_ioctl_setattr_check_cowextsize(static int xfs_ioctl_setattr_check_projid (struct xfs_inode *ip, -struct fileattr *fa) +struct file_kattr *fa) {if (!fa->fsx_valid)return 0 ;
@@ -725,7 +725,7 @@ intxfs_fileattr_set ( struct mnt_idmap *idmap, struct dentry *dentry, - struct fileattr *fa) + struct file_kattr *fa) { struct xfs_inode *ip = XFS_I(d_inode(dentry));struct xfs_mount *mp = ip->i_mount;
fs/xfs/xfs_ioctl.h +2 -2
@@ -17,13 +17,13 @@ xfs_ioc_swapext(extern int xfs_fileattr_get (struct dentry *dentry, -struct fileattr *fa); +struct file_kattr *fa);extern int xfs_fileattr_set (struct mnt_idmap *idmap,struct dentry *dentry, -struct fileattr *fa); +struct file_kattr *fa);extern long xfs_file_ioctl(
include/linux/fileattr.h +7 -7
@@ -40,7 +40,7 @@* is handled by the VFS helpers, so filesystems are free to implement just one * or both of these sub-interfaces. */ -struct fileattr { +struct file_kattr {u32 flags;/* flags (FS_IOC_GETFLAGS/FS_IOC_SETFLAGS) */ /* struct fsxattr: */ u32 fsx_xflags;/* xflags field value (get/set) */
@@ -53,10 +53,10 @@ struct fileattr { bool fsx_valid:1; }; -int copy_fsxattr_to_user (const struct fileattr *fa,struct fsxattr __user *ufa); +int copy_fsxattr_to_user (const struct file_kattr *fa,struct fsxattr __user *ufa); -void fileattr_fill_xflags (struct fileattr *fa,u32 xflags); -void fileattr_fill_flags (struct fileattr *fa,u32 flags); +void fileattr_fill_xflags (struct file_kattr *fa,u32 xflags); +void fileattr_fill_flags (struct file_kattr *fa,u32 flags);/** * fileattr_has_fsx - check for extended flags/attributes
@@ -65,16 +65,16 @@ void fileattr_fill_flags(struct fileattr *fa, u32 flags);* Return: true if any attributes are present that are not represented in * ->flags. */ -static inline bool fileattr_has_fsx (const struct fileattr *fa) +static inline bool fileattr_has_fsx (const struct file_kattr *fa) {return fa->fsx_valid && ((fa->fsx_xflags & ~FS_XFLAG_COMMON ) || fa->fsx_extsize !=0 || fa->fsx_projid !=0 || fa->fsx_cowextsize !=0 ); } -int vfs_fileattr_get (struct dentry *dentry,struct fileattr *fa); +int vfs_fileattr_get (struct dentry *dentry,struct file_kattr *fa);int vfs_fileattr_set (struct mnt_idmap *idmap,struct dentry *dentry, -struct fileattr *fa); +struct file_kattr *fa);int ioctl_getflags (struct file *file,unsigned int __user *argp);int ioctl_setflags (struct file *file,unsigned int __user *argp);int ioctl_fsgetxattr (struct file *file,void __user *argp);
include/linux/fs.h +3 -3
@@ -80,7 +80,7 @@ struct fsnotify_mark_connector;struct fsnotify_sb_info ;struct fs_context ;struct fs_parameter_spec ; -struct fileattr ; +struct file_kattr ;struct iomap_ops ;extern void __init inode_init (void );
@@ -2254,8 +2254,8 @@ struct inode_operations {int (*set_acl)(struct mnt_idmap *,struct dentry *,struct posix_acl *,int );int (*fileattr_set)(struct mnt_idmap *idmap, -struct dentry *dentry,struct fileattr *fa); -int (*fileattr_get)(struct dentry *dentry,struct fileattr *fa); +struct dentry *dentry,struct file_kattr *fa); +int (*fileattr_get)(struct dentry *dentry,struct file_kattr *fa);struct offset_ctx *(*get_offset_ctx)(struct inode *inode); }____cacheline_aligned ;
include/linux/lsm_hook_defs.h +2 -2
@@ -157,8 +157,8 @@ LSM_HOOK(int, 0, inode_removexattr, struct mnt_idmap *idmap, struct dentry *dentry, const char *name) LSM_HOOK(void, LSM_RET_VOID, inode_post_removexattr, struct dentry *dentry, const char *name) -LSM_HOOK(int, 0, inode_file_setattr, struct dentry *dentry, struct fileattr *fa) -LSM_HOOK(int, 0, inode_file_getattr, struct dentry *dentry, struct fileattr *fa) +LSM_HOOK(int, 0, inode_file_setattr, struct dentry *dentry, struct file_kattr *fa) +LSM_HOOK(int, 0, inode_file_getattr, struct dentry *dentry, struct file_kattr *fa) LSM_HOOK(int, 0, inode_set_acl, struct mnt_idmap *idmap, struct dentry *dentry, const char *acl_name, struct posix_acl *kacl) LSM_HOOK(void, LSM_RET_VOID, inode_post_set_acl, struct dentry *dentry,
include/linux/security.h +4 -4
@@ -452,9 +452,9 @@ int security_inode_removexattr(struct mnt_idmap *idmap, struct dentry *dentry, const char *name);void security_inode_post_removexattr (struct dentry *dentry,const char *name);int security_inode_file_setattr (struct dentry *dentry, -struct fileattr *fa); +struct file_kattr *fa);int security_inode_file_getattr (struct dentry *dentry, -struct fileattr *fa); +struct file_kattr *fa);int security_inode_need_killpriv (struct dentry *dentry);int security_inode_killpriv (struct mnt_idmap *idmap,struct dentry *dentry); int security_inode_getsecurity(struct mnt_idmap *idmap,
@@ -1057,13 +1057,13 @@ static inline void security_inode_post_removexattr(struct dentry *dentry, { }static inline int security_inode_file_setattr (struct dentry *dentry, -struct fileattr *fa) +struct file_kattr *fa) {return 0 ; }static inline int security_inode_file_getattr (struct dentry *dentry, -struct fileattr *fa) +struct file_kattr *fa) {return 0 ; }
include/uapi/linux/fs.h +1 -1
@@ -151,7 +151,7 @@ struct fsxattr {/* * Variable size structure for file_[sg]et_attr(). * -* Note. This is alternative to the structure 'struct fileattr'/'struct fsxattr'. +* Note. This is alternative to the structure 'struct file_kattr'/'struct fsxattr'. * As this structure is passed to/from userspace with its size, this can * be versioned based on the size. */
mm/shmem.c +2 -2
@@ -4183,7 +4183,7 @@ static const char *shmem_get_link(struct dentry *dentry, struct inode *inode,#ifdef CONFIG_TMPFS_XATTR -static int shmem_fileattr_get (struct dentry *dentry,struct fileattr *fa) +static int shmem_fileattr_get (struct dentry *dentry,struct file_kattr *fa) {struct shmem_inode_info *info =SHMEM_I (d_inode (dentry));
@@ -4193,7 +4193,7 @@ static int shmem_fileattr_get(struct dentry *dentry, struct fileattr *fa) }static int shmem_fileattr_set (struct mnt_idmap *idmap, -struct dentry *dentry,struct fileattr *fa) +struct dentry *dentry,struct file_kattr *fa) {struct inode *inode =d_inode (dentry);struct shmem_inode_info *info =SHMEM_I (inode);
security/security.c +2 -2
@@ -2632,7 +2632,7 @@ void security_inode_post_removexattr(struct dentry *dentry, const char *name)* * Return: Returns 0 if permission is granted. */ -int security_inode_file_setattr (struct dentry *dentry,struct fileattr *fa) +int security_inode_file_setattr (struct dentry *dentry,struct file_kattr *fa) {return call_int_hook (inode_file_setattr, dentry, fa); }
@@ -2647,7 +2647,7 @@ int security_inode_file_setattr(struct dentry *dentry, struct fileattr *fa)* * Return: Returns 0 if permission is granted. */ -int security_inode_file_getattr (struct dentry *dentry,struct fileattr *fa) +int security_inode_file_getattr (struct dentry *dentry,struct file_kattr *fa) {return call_int_hook (inode_file_getattr, dentry, fa); }
security/selinux/hooks.c +2 -2
@@ -3481,13 +3481,13 @@ static int selinux_inode_removexattr(struct mnt_idmap *idmap, }static int selinux_inode_file_setattr (struct dentry *dentry, -struct fileattr *fa) +struct file_kattr *fa) {return dentry_has_perm (current_cred (), dentry,FILE__SETATTR ); }static int selinux_inode_file_getattr (struct dentry *dentry, -struct fileattr *fa) +struct file_kattr *fa) {return dentry_has_perm (current_cred (), dentry,FILE__GETATTR ); }
Signature · 1 line
2.47.2
Amir Goldstein
maintainerQuoted 43 lines · Christian Brauner
Quoted 41 lines · Darrick J. Wong
Quoted 18 lines · Amir Goldstein
Quoted 17 lines · Christian Brauner
Quoted 9 lines
Er... "
fsx_fileattr" is the struct that the system call uses?That's a little confusing considering that xfs already has a
xfs_fill_fsxattrfunction that actually fills a struct fileattr. That could be renamedxfs_fill_fileattr.I dunno. There's a part of me that would really rather that the
file_getattrandfile_setattrsyscalls operate on a structfile_attr.Agreed, I'm pretty sure I suggested this during an earlier review. Fits in line with struct
mount_attrand others. Fwiw, struct fileattr (the kernel internal thing) should've really been structfile_kattror structkernel_file_attr. This is a common pattern now:struct
mount_attrvs structmount_kattrQuoted 8 lines
Quoted 4 lines
struct
clone_argsvs structkernel_clone_kargsetc.
file_attrI can see the allure, but we have a long history here with fsxattr, so I think it serves the users better to reference this history with fsxattr64.
<shrug> XFS has a long history with 'struct fsxattr' (the structure you passed to
XFS_IOC_FSGETXATTR) but the rest of the kernel needn't be so fixated upon the historical name. ext4/f2fs/overlay afaict are just going along for the ride.IOWs I like brauner's struct
file_attrand structfile_kattrsuggestions.Quoted 4 lines
That, and also, avoid the churn of s/fileattr/file_kattr/ If you want to do this renaming, please do it in the same PR because I don't like the idea of having both
file_attrand fileattr in the tree for an unknown period.
Quoted 4 lines
Quoted 1 line
But yeah, that ought to be a treewide change done at the same time.
Why do you all hate me? ;)
See the appended patch.
This looks obviously fine, but I wonder how much conflicts that would cause in linux-next?
It may just be small enough to get by.
Thanks,
Amir.
Christian Brauner
maintainerQuoted 44 lines · Amir Goldstein
Quoted 43 lines · Christian Brauner
Quoted 41 lines · Darrick J. Wong
Quoted 18 lines · Amir Goldstein
Quoted 17 lines · Christian Brauner
Quoted 9 lines
Er... "
fsx_fileattr" is the struct that the system call uses?That's a little confusing considering that xfs already has a
xfs_fill_fsxattrfunction that actually fills a struct fileattr. That could be renamedxfs_fill_fileattr.I dunno. There's a part of me that would really rather that the
file_getattrandfile_setattrsyscalls operate on a structfile_attr.Agreed, I'm pretty sure I suggested this during an earlier review. Fits in line with struct
mount_attrand others. Fwiw, struct fileattr (the kernel internal thing) should've really been structfile_kattror structkernel_file_attr. This is a common pattern now:struct
mount_attrvs structmount_kattrQuoted 8 lines
Quoted 4 lines
struct
clone_argsvs structkernel_clone_kargsetc.
file_attrI can see the allure, but we have a long history here with fsxattr, so I think it serves the users better to reference this history with fsxattr64.
<shrug> XFS has a long history with 'struct fsxattr' (the structure you passed to
XFS_IOC_FSGETXATTR) but the rest of the kernel needn't be so fixated upon the historical name. ext4/f2fs/overlay afaict are just going along for the ride.IOWs I like brauner's struct
file_attrand structfile_kattrsuggestions.Quoted 4 lines
That, and also, avoid the churn of s/fileattr/file_kattr/ If you want to do this renaming, please do it in the same PR because I don't like the idea of having both
file_attrand fileattr in the tree for an unknown period.
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
But yeah, that ought to be a treewide change done at the same time.
Why do you all hate me? ;)
See the appended patch.This looks obviously fine, but I wonder how much conflicts that would cause in linux-next?
It may just be small enough to get by.
With such changes that's always a possibility but really I'll just provide a branch with the resolutions for Linus to pull.
Quoted 50 lines · Christian Brauner
Quoted 49 lines · Amir Goldstein
Quoted 47 lines · Christian Brauner
Quoted 36 lines · Darrick J. Wong
Quoted 18 lines · Amir Goldstein
Quoted 17 lines · Christian Brauner
Quoted 9 lines
Er... "
fsx_fileattr" is the struct that the system call uses?That's a little confusing considering that xfs already has a
xfs_fill_fsxattrfunction that actually fills a struct fileattr. That could be renamedxfs_fill_fileattr.I dunno. There's a part of me that would really rather that the
file_getattrandfile_setattrsyscalls operate on a structfile_attr.Agreed, I'm pretty sure I suggested this during an earlier review. Fits in line with struct
mount_attrand others. Fwiw, struct fileattr (the kernel internal thing) should've really been structfile_kattror structkernel_file_attr. This is a common pattern now:struct
mount_attrvs structmount_kattrQuoted 8 lines
Quoted 4 lines
struct
clone_argsvs structkernel_clone_kargsetc.
file_attrI can see the allure, but we have a long history here with fsxattr, so I think it serves the users better to reference this history with fsxattr64.
<shrug> XFS has a long history with 'struct fsxattr' (the structure you passed to
XFS_IOC_FSGETXATTR) but the rest of the kernel needn't be so fixated upon the historical name. ext4/f2fs/overlay afaict are just going along for the ride.IOWs I like brauner's struct
file_attrand structfile_kattrsuggestions.Quoted 6 lines
Quoted 4 lines
That, and also, avoid the churn of s/fileattr/file_kattr/ If you want to do this renaming, please do it in the same PR because I don't like the idea of having both
file_attrand fileattr in the tree for an unknown period.But yeah, that ought to be a treewide change done at the same time.
Why do you all hate me? ;)
See the appended patch.
Quoted 6 lines
Quoted 3 lines
This looks obviously fine, but I wonder how much conflicts that would cause in linux-next?
It may just be small enough to get by.With such changes that's always a possibility but really I'll just provide a branch with the resolutions for Linus to pull.
<nod> That looks good to me. :)
At worst you can always ask Linus "Hey I want to do a treewide name change of $X to $Y, can I stuff that in at the very end of the merge window?" and IME he'll let you do that. Even better if someone keeps him supplied with fresh change patches.
--D
Amir Goldstein
maintainerQuoted 161 lines · Andrey Albershteyn
This patchset introduced two new syscalls
file_getattr()andfile_setattr(). These syscalls are similar toFS_IOC_FSSETXATTRioctl()except they use*at()semantics. Therefore, there's no need to open the file to get a fd.These syscalls allow userspace to set filesystem inode attributes on special files. One of the usage examples is XFS quota projects.
XFS has project quotas which could be attached to a directory. All new inodes in these directories inherit project ID set on parent directory.
The project is created from userspace by opening and calling
FS_IOC_FSSETXATTRon each inode. This is not possible for special files such as FIFO, SOCK, BLK etc. Therefore, some inodes are left with empty project ID. Those inodes then are not shown in the quota accounting but still exist in the directory. This is not critical but in the case when special files are created in the directory with already existing project quota, these new inodes inherit extended attributes. This creates a mix of special files with and without attributes. Moreover, special files with attributes don't have a possibility to become clear or change the attributes. This, in turn, prevents userspace from re-creating quota project on these existing files.An xfstests test generic/766 with basic coverage is at:
https://github.com/alberand/xfstests/commits/b4/file-attr/NAME
file_getattr/file_setattr - get/set filesystem inode attributes
SYNOPSIS
#include <
sys/syscall.h> /* Definition of SYS_* constants */
#include <unistd.h>long syscall(SYS_file_getattr, int dirfd, const char *pathname,
structfsx_fileattr*fsx,size_tsize, unsigned intat_flags);
long syscall(SYS_file_setattr, int dirfd, const char *pathname,
structfsx_fileattr*fsx,size_tsize, unsigned intat_flags);Note: glibc doesn't provide for file_getattr()/file_setattr(), use syscall(2) instead.
DESCRIPTION
The file_getattr()/file_setattr() are used to set extended file attributes. These syscalls take dirfd in conjunction with the pathname argument. The syscall then operates on inode opened according to openat(2) semantics.
This is an alternative to FS_IOC_FSGETXATTR/FS_IOC_FSSETXATTR ioctl with a difference that file don't need to be open as file can be referenced with a path instead of fd. By having this one can manipulated filesystem inode attributes not only on regular files but also on special ones. This is not possible with
FS_IOC_FSSETXATTRioctl asioctl()can not be called on special files directly for the filesystem inode.
at_flagscan be set toAT_SYMLINK_NOFOLLOWorAT_EMPTY_PATH.RETURN VALUE
On success, 0 is returned. On error, -1 is returned, and errno is set to indicate the error.
ERRORS
EINVAL Invalid
at_flagspecified (only
AT_SYMLINK_NOFOLLOWandAT_EMPTY_PATHis supported).EINVAL Size was smaller than any known version of
structfsx_fileattr.EINVAL Invalid combination of parameters provided in
fsx_fileattrfor this type of file.E2BIG Size of input argument struct
fsx_fileattr
is too big.EBADF Invalid file descriptor was provided.
EPERM No permission to change this file.
EOPNOTSUPP Filesystem does not support setting attributes
on this type of inodeHISTORY
Added in Linux 6.16.
EXAMPLE
Create directory and file "mkdir ./dir && touch ./dir/foo" and then execute the following program:
#include <fcntl.h> #include <errno.h> #include <string.h> #include <linux/fs.h> #include <stdio.h> #include <sys/syscall.h> #include <unistd.h> #if !defined(SYS_file_getattr) && defined(__x86_64__) #define SYS_file_getattr 468 #define SYS_file_setattr 469 struct fsx_fileattr { __u32 fsx_xflags; __u32 fsx_extsize; __u32 fsx_nextents; __u32 fsx_projid; __u32 fsx_cowextsize; }; #endif int main(int argc, char **argv) { int dfd; int error; struct fsx_fileattr fsx; dfd = open("./dir", O_RDONLY); if (dfd == -1) { printf("can not open ./dir"); return dfd; } error = syscall(SYS_file_getattr, dfd, "./foo", &fsx, sizeof(struct fsx_fileattr), 0); if (error) { printf("can not call SYS_file_getattr: %s", strerror(errno)); return error; } printf("./dir/foo flags: %d\n", fsx.fsx_xflags); fsx.fsx_xflags |= FS_XFLAG_NODUMP; error = syscall(SYS_file_setattr, dfd, "./foo", &fsx, sizeof(struct fsx_fileattr), 0); if (error) { printf("can not call SYS_file_setattr: %s", strerror(errno)); return error; } printf("./dir/foo flags: %d\n", fsx.fsx_xflags); return error; }SEE ALSO
ioctl(2), ioctl_iflags(2), ioctl_xfs_fsgetxattr(2), openat(2)
Quoted 10 lines
---
Changes in v6:
- Update cover letter example and docs
- Applied__free()attribute for syscall stack objects
- Introduced structfsx_fileattr
- Replace 'struct fsxattr' with 'structfsx_fileattr'
- Add helper to fill infsx_fileattrfrom fileattr
- Droppedcopy_fsx_to_user()header declaration
- Link to v5: https://lore.kernel.org/r/[email protected]
Series looks good.
For mine and Pali's minor comments on patch 4 no need to resend. I think they could be fixed on commit.
Thanks,
Amir.
Quoted 82 lines
Changes in v5:
- Remove setting ofLOOKUP_EMPTYflags which does not have any effect
- Return-ENOSUPPfromvfs_fileattr_set()
- Add fsxattr masking (by Amir)
- Fix UAF issue dentry
- Fixgetname_maybe_null()issue with NULL path
- Implement file_getattr/file_setattr hooks
- Return LSM return code fromfile_setattr
- Rename from getfsxattrat/setfsxattrat to file_getattr/file_setattr
- Link to v4: https://lore.kernel.org/r/[email protected]Changes in v4:
- Usegetname_maybe_null()for correct handling of dfd + path semantic
- Remove restriction for special files on which flags are allowed
- Utilizecopy_struct_from_user()for better future compatibility
- Add draft man page to cover letter
- Convert-ENOIOCTLCMDto-EOPNOSUPPas more appropriate for syscall
- Add missing__userto header declaration of syscalls
- Link to v3: https://lore.kernel.org/r/[email protected]Changes in v3:
- Remove unnecessary "dfd is dir" check as it checked inuser_path_at()
- Remove unnecessary "same filesystem" check
- UseCLASS()instead of directly calling fdget/fdput
- Link to v2: https://lore.kernel.org/r/[email protected]v1:
https://lore.kernel.org/linuxppc-dev/[email protected]/Previous discussion:
https://lore.kernel.org/linux-xfs/[email protected]/---
Amir Goldstein (1):
fs: prepare for extending file_get/setattr()Andrey Albershteyn (5):
fs: split fileattr related helpers into separate file
lsm: introduce new hooks for setting/getting inode fsxattr
selinux: implement inode_file_[g|s]etattr hooks
fs: make vfs_fileattr_[get|set] return-EOPNOSUPP
fs: introducefile_getattrandfile_setattrsyscallsarch/alpha/kernel/syscalls/syscall.tbl | 2 + arch/arm/tools/syscall.tbl | 2 + arch/arm64/tools/syscall_32.tbl | 2 + arch/m68k/kernel/syscalls/syscall.tbl | 2 + arch/microblaze/kernel/syscalls/syscall.tbl | 2 + arch/mips/kernel/syscalls/syscall_n32.tbl | 2 + arch/mips/kernel/syscalls/syscall_n64.tbl | 2 + arch/mips/kernel/syscalls/syscall_o32.tbl | 2 + arch/parisc/kernel/syscalls/syscall.tbl | 2 + arch/powerpc/kernel/syscalls/syscall.tbl | 2 + arch/s390/kernel/syscalls/syscall.tbl | 2 + arch/sh/kernel/syscalls/syscall.tbl | 2 + arch/sparc/kernel/syscalls/syscall.tbl | 2 + arch/x86/entry/syscalls/syscall_32.tbl | 2 + arch/x86/entry/syscalls/syscall_64.tbl | 2 + arch/xtensa/kernel/syscalls/syscall.tbl | 2 + fs/Makefile | 3 +- fs/ecryptfs/inode.c | 8 +- fs/file_attr.c | 493 ++++++++++++++++++++++++++++ fs/ioctl.c | 309 ----------------- fs/overlayfs/inode.c | 2 +- include/linux/fileattr.h | 24 ++ include/linux/lsm_hook_defs.h | 2 + include/linux/security.h | 16 + include/linux/syscalls.h | 6 + include/uapi/asm-generic/unistd.h | 8 +- include/uapi/linux/fs.h | 18 + scripts/syscall.tbl | 2 + security/security.c | 30 ++ security/selinux/hooks.c | 14 + 30 files changed, 654 insertions(+), 313 deletions(-)---
base-commit:d0b3b7b22dfa1f4b515fd3a295b3fd958f9e81af
change-id: 20250114-xattrat-syscall-6a1136d2db59Best regards,
--
Andrey Albershteyn <[email protected]>
Christian Brauner
maintainerQuoted 12 lines · Andrey Albershteyn
This patchset introduced two new syscalls
file_getattr()andfile_setattr(). These syscalls are similar toFS_IOC_FSSETXATTRioctl()except they use*at()semantics. Therefore, there's no need to open the file to get a fd.These syscalls allow userspace to set filesystem inode attributes on special files. One of the usage examples is XFS quota projects.
XFS has project quotas which could be attached to a directory. All new inodes in these directories inherit project ID set on parent directory.
Quoted 11 lines
The project is created from userspace by opening and calling
FS_IOC_FSSETXATTRon each inode. This is not possible for special files such as FIFO, SOCK, BLK etc. Therefore, some inodes are left with empty project ID. Those inodes then are not shown in the quota accounting but still exist in the directory. This is not critical but in the case when special files are created in the directory with already existing project quota, these new inodes inherit extended attributes. This creates a mix of special files with and without attributes. Moreover, special files with attributes don't have a possibility to become clear or change the attributes. This, in turn, prevents userspace from re-creating quota project on these existing files.
Only small nits I'm going to comment on that I can fix myself. Otherwise looks great.
Quoted 25 lines · Christian Brauner
Quoted 12 lines · Andrey Albershteyn
This patchset introduced two new syscalls
file_getattr()andfile_setattr(). These syscalls are similar toFS_IOC_FSSETXATTRioctl()except they use*at()semantics. Therefore, there's no need to open the file to get a fd.These syscalls allow userspace to set filesystem inode attributes on special files. One of the usage examples is XFS quota projects.
XFS has project quotas which could be attached to a directory. All new inodes in these directories inherit project ID set on parent directory.
Quoted 11 lines
The project is created from userspace by opening and calling
FS_IOC_FSSETXATTRon each inode. This is not possible for special files such as FIFO, SOCK, BLK etc. Therefore, some inodes are left with empty project ID. Those inodes then are not shown in the quota accounting but still exist in the directory. This is not critical but in the case when special files are created in the directory with already existing project quota, these new inodes inherit extended attributes. This creates a mix of special files with and without attributes. Moreover, special files with attributes don't have a possibility to become clear or change the attributes. This, in turn, prevents userspace from re-creating quota project on these existing files.
Quoted 3 lines
Only small nits I'm going to comment on that I can fix myself. Otherwise looks great.
Hi Christian,
Let me know if you would like a new revision with all the comments included (and your patch on file_kattr rename) or you good with applying them while commit
Signature · 1 line
- Andrey
Christian Brauner
maintainerQuoted 30 lines · Andrey Albershteyn
Quoted 25 lines · Christian Brauner
Quoted 12 lines · Andrey Albershteyn
This patchset introduced two new syscalls
file_getattr()andfile_setattr(). These syscalls are similar toFS_IOC_FSSETXATTRioctl()except they use*at()semantics. Therefore, there's no need to open the file to get a fd.These syscalls allow userspace to set filesystem inode attributes on special files. One of the usage examples is XFS quota projects.
XFS has project quotas which could be attached to a directory. All new inodes in these directories inherit project ID set on parent directory.
Quoted 11 lines
The project is created from userspace by opening and calling
FS_IOC_FSSETXATTRon each inode. This is not possible for special files such as FIFO, SOCK, BLK etc. Therefore, some inodes are left with empty project ID. Those inodes then are not shown in the quota accounting but still exist in the directory. This is not critical but in the case when special files are created in the directory with already existing project quota, these new inodes inherit extended attributes. This creates a mix of special files with and without attributes. Moreover, special files with attributes don't have a possibility to become clear or change the attributes. This, in turn, prevents userspace from re-creating quota project on these existing files.Quoted 3 lines
Only small nits I'm going to comment on that I can fix myself. Otherwise looks great.
Quoted 5 lines
Hi Christian,
Let me know if you would like a new revision with all the comments included (and your patch on
file_kattrrename) or you good with applying them while commit
It's all been in -next for a few days already. :)
Quoted 31 lines · Christian Brauner
Quoted 30 lines · Andrey Albershteyn
Quoted 28 lines · Christian Brauner
Quoted 12 lines · Andrey Albershteyn
This patchset introduced two new syscalls
file_getattr()andfile_setattr(). These syscalls are similar toFS_IOC_FSSETXATTRioctl()except they use*at()semantics. Therefore, there's no need to open the file to get a fd.These syscalls allow userspace to set filesystem inode attributes on special files. One of the usage examples is XFS quota projects.
XFS has project quotas which could be attached to a directory. All new inodes in these directories inherit project ID set on parent directory.
Quoted 11 lines
The project is created from userspace by opening and calling
FS_IOC_FSSETXATTRon each inode. This is not possible for special files such as FIFO, SOCK, BLK etc. Therefore, some inodes are left with empty project ID. Those inodes then are not shown in the quota accounting but still exist in the directory. This is not critical but in the case when special files are created in the directory with already existing project quota, these new inodes inherit extended attributes. This creates a mix of special files with and without attributes. Moreover, special files with attributes don't have a possibility to become clear or change the attributes. This, in turn, prevents userspace from re-creating quota project on these existing files.Only small nits I'm going to comment on that I can fix myself. Otherwise looks great.
Quoted 8 lines
Quoted 5 lines
Hi Christian,
Let me know if you would like a new revision with all the comments included (and your patch on
file_kattrrename) or you good with applying them while commitIt's all been in -next for a few days already. :)
Oh sorry, missed that, thanks!
Signature · 1 line
- Andrey
Quoted 9 lines · Andrey Albershteyn
This patchset introduced two new syscalls
file_getattr()andfile_setattr(). These syscalls are similar toFS_IOC_FSSETXATTRioctl()except they use*at()semantics. Therefore, there's no need to open the file to get a fd.These syscalls allow userspace to set filesystem inode attributes on special files. One of the usage examples is XFS quota projects.
[...]
Applied to the vfs-6.17.fileattr branch of the vfs/vfs.git tree. Patches in the vfs-6.17.fileattr branch should appear in linux-next soon.
Please report any outstanding bugs that were missed during review in a new review to the original patch series allowing us to drop it.
It's encouraged to provide Acked-bys and Reviewed-bys even though the patch has now been applied. If possible patch trailers will be updated.
Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. If in doubt, please check the listed branch.
tree: https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git branch: vfs-6.17.fileattr
[1/6] fs: split fileattr related helpers into separate file
https://git.kernel.org/vfs/vfs/c/2f952c9e8fe1 [2/6] lsm: introduce new hooks for setting/getting inode fsxattr https://git.kernel.org/vfs/vfs/c/defdd02d783c [3/6] selinux: implement inode_file_[g|s]etattr hooks https://git.kernel.org/vfs/vfs/c/bd14e462bb52 [4/6] fs: make vfs_fileattr_[get|set] return -EOPNOSUPP https://git.kernel.org/vfs/vfs/c/474b155adf39 [5/6] fs: prepare for extending file_get/setattr() https://git.kernel.org/vfs/vfs/c/276e136bff7e [6/6] fs: introduce file_getattr and file_setattr syscalls https://git.kernel.org/vfs/vfs/c/be7efb2d20d6