fs: introduce getfsxattrat and setfsxattrat syscalls
Subsystems (19)
PATCH v2 1/1 fs: introduce getfsxattrat and setfsxattrat syscalls
From: Andrey Albershteyn <[email protected]>
Introduce getfsxattrat and setfsxattrat syscalls to manipulate inode extended attributes/flags. The syscalls take parent directory FD and path to the child together with struct fsxattr.
This is an alternative to FS_IOC_FSSETXATTR ioctl with a difference that file don't need to be open. By having this we can manipulated inode extended attributes not only on normal files but also on special ones. This is not possible with FS_IOC_FSSETXATTR ioctl as opening special files returns VFS special inode instead of underlying filesystem one.
This patch adds two new syscalls which allows userspace to set extended inode attributes on special files by using parent directory to open FS inode.
Also, as vfs_fileattr_set() is now will be called on special files too, let's forbid any other attributes except projid and nextents (symlink can have an extent).
---
v1:
https://lore.kernel.org/linuxppc-dev/[email protected]/
Previous discussion:
https://lore.kernel.org/linux-xfs/[email protected]/
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. Moreover, in the case when special files are created in the directory with already existing project quota, these inode inherit extended attributes. This than leaves them with these attributes without the possibility to clear them out. This, in turn, prevents userspace from re-creating quota project on these existing files.
--- 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/inode.c | 99 +++++++++++++++++++++++++++++ fs/ioctl.c | 16 ++++- include/linux/fileattr.h | 1 + include/linux/syscalls.h | 4 ++ include/uapi/asm-generic/unistd.h | 8 ++- 21 files changed, 157 insertions(+), 3 deletions(-)
arch/alpha/kernel/syscalls/syscall.tbl +2 -0
@@ -506,3 +506,5 @@ 574 common getxattrat sys_getxattrat 575 common listxattrat sys_listxattrat 576 common removexattrat sys_removexattrat +577 common getfsxattrat sys_getfsxattrat +578 common setfsxattrat sys_setfsxattrat
arch/arm/tools/syscall.tbl +2 -0
@@ -481,3 +481,5 @@ 464 common getxattrat sys_getxattrat 465 common listxattrat sys_listxattrat 466 common removexattrat sys_removexattrat +467 common getfsxattrat sys_getfsxattrat +468 common setfsxattrat sys_setfsxattrat
arch/arm64/tools/syscall_32.tbl +2 -0
@@ -478,3 +478,5 @@ 464 common getxattrat sys_getxattrat 465 common listxattrat sys_listxattrat 466 common removexattrat sys_removexattrat +467 common getfsxattrat sys_getfsxattrat +468 common setfsxattrat sys_setfsxattrat
arch/m68k/kernel/syscalls/syscall.tbl +2 -0
@@ -466,3 +466,5 @@ 464 common getxattrat sys_getxattrat 465 common listxattrat sys_listxattrat 466 common removexattrat sys_removexattrat +467 common getfsxattrat sys_getfsxattrat +468 common setfsxattrat sys_setfsxattrat
arch/microblaze/kernel/syscalls/syscall.tbl +2 -0
@@ -472,3 +472,5 @@ 464 common getxattrat sys_getxattrat 465 common listxattrat sys_listxattrat 466 common removexattrat sys_removexattrat +467 common getfsxattrat sys_getfsxattrat +468 common setfsxattrat sys_setfsxattrat
arch/mips/kernel/syscalls/syscall_n32.tbl +2 -0
@@ -405,3 +405,5 @@ 464 n32 getxattrat sys_getxattrat 465 n32 listxattrat sys_listxattrat 466 n32 removexattrat sys_removexattrat +467 n32 getfsxattrat sys_getfsxattrat +468 n32 setfsxattrat sys_setfsxattrat
arch/mips/kernel/syscalls/syscall_n64.tbl +2 -0
@@ -381,3 +381,5 @@ 464 n64 getxattrat sys_getxattrat 465 n64 listxattrat sys_listxattrat 466 n64 removexattrat sys_removexattrat +467 n64 getfsxattrat sys_getfsxattrat +468 n64 setfsxattrat sys_setfsxattrat
arch/mips/kernel/syscalls/syscall_o32.tbl +2 -0
@@ -454,3 +454,5 @@ 464 o32 getxattrat sys_getxattrat 465 o32 listxattrat sys_listxattrat 466 o32 removexattrat sys_removexattrat +467 o32 getfsxattrat sys_getfsxattrat +468 o32 setfsxattrat sys_setfsxattrat
arch/parisc/kernel/syscalls/syscall.tbl +2 -0
@@ -465,3 +465,5 @@ 464 common getxattrat sys_getxattrat 465 common listxattrat sys_listxattrat 466 common removexattrat sys_removexattrat +467 common getfsxattrat sys_getfsxattrat +468 common setfsxattrat sys_setfsxattrat
arch/powerpc/kernel/syscalls/syscall.tbl +2 -0
@@ -557,3 +557,5 @@ 464 common getxattrat sys_getxattrat 465 common listxattrat sys_listxattrat 466 common removexattrat sys_removexattrat +467 common getfsxattrat sys_getfsxattrat +468 common setfsxattrat sys_setfsxattrat
arch/s390/kernel/syscalls/syscall.tbl +2 -0
@@ -469,3 +469,5 @@ 464 common getxattrat sys_getxattrat sys_getxattrat 465 common listxattrat sys_listxattrat sys_listxattrat 466 common removexattrat sys_removexattrat sys_removexattrat +467 common getfsxattrat sys_getfsxattrat sys_getfsxattrat +468 common setfsxattrat sys_setfsxattrat sys_setfsxattrat
arch/sh/kernel/syscalls/syscall.tbl +2 -0
@@ -470,3 +470,5 @@ 464 common getxattrat sys_getxattrat 465 common listxattrat sys_listxattrat 466 common removexattrat sys_removexattrat +467 common getfsxattrat sys_getfsxattrat +468 common setfsxattrat sys_setfsxattrat
arch/sparc/kernel/syscalls/syscall.tbl +2 -0
@@ -512,3 +512,5 @@ 464 common getxattrat sys_getxattrat 465 common listxattrat sys_listxattrat 466 common removexattrat sys_removexattrat +467 common getfsxattrat sys_getfsxattrat +468 common setfsxattrat sys_setfsxattrat
arch/x86/entry/syscalls/syscall_32.tbl +2 -0
@@ -472,3 +472,5 @@ 464 i386 getxattrat sys_getxattrat 465 i386 listxattrat sys_listxattrat 466 i386 removexattrat sys_removexattrat +467 i386 getfsxattrat sys_getfsxattrat +468 i386 setfsxattrat sys_setfsxattrat
arch/x86/entry/syscalls/syscall_64.tbl +2 -0
@@ -390,6 +390,8 @@ 464 common getxattrat sys_getxattrat 465 common listxattrat sys_listxattrat 466 common removexattrat sys_removexattrat +467 common getfsxattrat sys_getfsxattrat +468 common setfsxattrat sys_setfsxattrat # # Due to a historical design error, certain syscalls are numbered differently
arch/xtensa/kernel/syscalls/syscall.tbl +2 -0
@@ -437,3 +437,5 @@ 464 common getxattrat sys_getxattrat 465 common listxattrat sys_listxattrat 466 common removexattrat sys_removexattrat +467 common getfsxattrat sys_getfsxattrat +468 common setfsxattrat sys_setfsxattrat
fs/inode.c +99 -0
108 lines not on this page · raw message
fs/ioctl.c +14 -2
@@ -558,8 +558,7 @@ int copy_fsxattr_to_user(const struct fileattr *fa, struct fsxattr __user *ufa) }EXPORT_SYMBOL (copy_fsxattr_to_user); -static int copy_fsxattr_from_user (struct fileattr *fa, -struct fsxattr __user *ufa) +int copy_fsxattr_from_user (struct fileattr *fa,struct fsxattr __user *ufa) {struct fsxattr xfa;
@@ -646,6 +645,19 @@ static int fileattr_set_prepare(struct inode *inode,if (fa->fsx_cowextsize ==0 ) fa->fsx_xflags &= ~FS_XFLAG_COWEXTSIZE ; +/* +* The only use case for special files is to set project ID, forbid any +* other attributes +*/ +if (!(S_ISREG (inode->i_mode) ||S_ISDIR (inode->i_mode))) { +if (fa->fsx_xflags & ~FS_XFLAG_PROJINHERIT ) +return -EINVAL ; +if (!S_ISLNK (inode->i_mode) && fa->fsx_nextents) +return -EINVAL ; +if (fa->fsx_extsize || fa->fsx_cowextsize) +return -EINVAL ; + } +return 0 ; }
include/linux/fileattr.h +1 -0
@@ -34,6 +34,7 @@ struct fileattr { };int copy_fsxattr_to_user (const struct fileattr *fa,struct fsxattr __user *ufa); +int copy_fsxattr_from_user (struct fileattr *fa,struct fsxattr __user *ufa);void fileattr_fill_xflags (struct fileattr *fa,u32 xflags);void fileattr_fill_flags (struct fileattr *fa,u32 flags);
include/linux/syscalls.h +4 -0
@@ -371,6 +371,10 @@ 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_getfsxattrat (int dfd,const char __user *filename, +struct fsxattr *fsx,unsigned int at_flags); +asmlinkage long sys_setfsxattrat (int dfd,const char __user *filename, +struct fsxattr *fsx,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
@@ -850,8 +850,14 @@ __SYSCALL(__NR_listxattrat, sys_listxattrat)#define __NR_removexattrat 466__SYSCALL (__NR_removexattrat, sys_removexattrat) +/* fs/inode.c */ +#define __NR_getfsxattrat 467 +__SYSCALL(__NR_getfsxattrat, sys_getfsxattrat) +#define __NR_setfsxattrat 468 +__SYSCALL(__NR_setfsxattrat, sys_setfsxattrat) +#undef __NR_syscalls -#define __NR_syscalls 467 +#define __NR_syscalls 469/* * 32 bit systems traditionally used different
---
base-commit: 4c538044ee2d11299cc57ac1e92d343e1e83b847
change-id: 20250114-xattrat-syscall-6a1136d2db59
Best regards,
Signature · 1 line
Andrey Albershteyn <[email protected]>
Christian Brauner
maintainerQuoted 8 lines · Andrey Albershteyn
From: Andrey Albershteyn <[email protected]>
Introduce getfsxattrat and setfsxattrat syscalls to manipulate inode extended attributes/flags. The syscalls take parent directory FD and path to the child together with struct fsxattr.
This is an alternative to
FS_IOC_FSSETXATTRioctl with a difference that file don't need to be open. By having this we can manipulated
By that you mean that you can use absolute or relative paths instead of file descriptors?
Quoted 4 lines
inode extended attributes not only on normal files but also on special ones. This is not possible with
FS_IOC_FSSETXATTRioctl as opening special files returns VFS special inode instead of underlying filesystem one.
I'm not following this argument currently. In what sense does opening special files return a VFS special inode and how does that prevent FS_IOC_FSSEETXATTR from working? The inode in
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;
d_inode(dentry)and your:
error = user_path_at(dfd, filename, lookup_flags, &filepath); if (error)
goto out;
d_inode(filepath.dentry)
is the same.
Quoted 251 lines
This patch adds two new syscalls which allows userspace to set extended inode attributes on special files by using parent directory to open FS inode.
Also, as
vfs_fileattr_set()is now will be called on special files too, let's forbid any other attributes except projid and nextents (symlink can have an extent).Signed-off-by Andrey Albershteyn <[email protected]>---
v1:
https://lore.kernel.org/linuxppc-dev/[email protected]/Previous discussion:
https://lore.kernel.org/linux-xfs/[email protected]/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. Moreover, in the case when special files are created in the directory with already existing project quota, these inode inherit extended attributes. This than leaves them with these attributes without the possibility to clear them out. This, in turn, prevents userspace from re-creating quota project on these existing files.--- 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/inode.c | 99 +++++++++++++++++++++++++++++ fs/ioctl.c | 16 ++++- include/linux/fileattr.h | 1 + include/linux/syscalls.h | 4 ++ include/uapi/asm-generic/unistd.h | 8 ++- 21 files changed, 157 insertions(+), 3 deletions(-)arch/alpha/kernel/syscalls/syscall.tbl +2
-0@@ -506,3 +506,5 @@ 574 common getxattrat sys_getxattrat 575 common listxattrat sys_listxattrat 576 common removexattrat sys_removexattrat +577 common getfsxattrat sys_getfsxattrat +578 common setfsxattrat sys_setfsxattratarch/arm/tools/syscall.tbl +2
-0@@ -481,3 +481,5 @@ 464 common getxattrat sys_getxattrat 465 common listxattrat sys_listxattrat 466 common removexattrat sys_removexattrat +467 common getfsxattrat sys_getfsxattrat +468 common setfsxattrat sys_setfsxattratarch/arm64/tools/syscall_32.tbl +2
-0@@ -478,3 +478,5 @@ 464 common getxattrat sys_getxattrat 465 common listxattrat sys_listxattrat 466 common removexattrat sys_removexattrat +467 common getfsxattrat sys_getfsxattrat +468 common setfsxattrat sys_setfsxattratarch/m68k/kernel/syscalls/syscall.tbl +2
-0@@ -466,3 +466,5 @@ 464 common getxattrat sys_getxattrat 465 common listxattrat sys_listxattrat 466 common removexattrat sys_removexattrat +467 common getfsxattrat sys_getfsxattrat +468 common setfsxattrat sys_setfsxattratarch/microblaze/kernel/syscalls/syscall.tbl +2
-0@@ -472,3 +472,5 @@ 464 common getxattrat sys_getxattrat 465 common listxattrat sys_listxattrat 466 common removexattrat sys_removexattrat +467 common getfsxattrat sys_getfsxattrat +468 common setfsxattrat sys_setfsxattratarch/mips/kernel/syscalls/syscall_n32.tbl +2
-0@@ -405,3 +405,5 @@ 464 n32 getxattrat sys_getxattrat 465 n32 listxattrat sys_listxattrat 466 n32 removexattrat sys_removexattrat +467 n32 getfsxattrat sys_getfsxattrat +468 n32 setfsxattrat sys_setfsxattratarch/mips/kernel/syscalls/syscall_n64.tbl +2
-0@@ -381,3 +381,5 @@ 464 n64 getxattrat sys_getxattrat 465 n64 listxattrat sys_listxattrat 466 n64 removexattrat sys_removexattrat +467 n64 getfsxattrat sys_getfsxattrat +468 n64 setfsxattrat sys_setfsxattratarch/mips/kernel/syscalls/syscall_o32.tbl +2
-0@@ -454,3 +454,5 @@ 464 o32 getxattrat sys_getxattrat 465 o32 listxattrat sys_listxattrat 466 o32 removexattrat sys_removexattrat +467 o32 getfsxattrat sys_getfsxattrat +468 o32 setfsxattrat sys_setfsxattratarch/parisc/kernel/syscalls/syscall.tbl +2
-0@@ -465,3 +465,5 @@ 464 common getxattrat sys_getxattrat 465 common listxattrat sys_listxattrat 466 common removexattrat sys_removexattrat +467 common getfsxattrat sys_getfsxattrat +468 common setfsxattrat sys_setfsxattratarch/powerpc/kernel/syscalls/syscall.tbl +2
-0@@ -557,3 +557,5 @@ 464 common getxattrat sys_getxattrat 465 common listxattrat sys_listxattrat 466 common removexattrat sys_removexattrat +467 common getfsxattrat sys_getfsxattrat +468 common setfsxattrat sys_setfsxattratarch/s390/kernel/syscalls/syscall.tbl +2
-0@@ -469,3 +469,5 @@ 464 common getxattrat sys_getxattrat sys_getxattrat 465 common listxattrat sys_listxattrat sys_listxattrat 466 common removexattrat sys_removexattrat sys_removexattrat +467 common getfsxattrat sys_getfsxattrat sys_getfsxattrat +468 common setfsxattrat sys_setfsxattrat sys_setfsxattratarch/sh/kernel/syscalls/syscall.tbl +2
-0@@ -470,3 +470,5 @@ 464 common getxattrat sys_getxattrat 465 common listxattrat sys_listxattrat 466 common removexattrat sys_removexattrat +467 common getfsxattrat sys_getfsxattrat +468 common setfsxattrat sys_setfsxattratarch/sparc/kernel/syscalls/syscall.tbl +2
-0@@ -512,3 +512,5 @@ 464 common getxattrat sys_getxattrat 465 common listxattrat sys_listxattrat 466 common removexattrat sys_removexattrat +467 common getfsxattrat sys_getfsxattrat +468 common setfsxattrat sys_setfsxattratarch/x86/entry/syscalls/syscall_32.tbl +2
-0@@ -472,3 +472,5 @@ 464 i386 getxattrat sys_getxattrat 465 i386 listxattrat sys_listxattrat 466 i386 removexattrat sys_removexattrat +467 i386 getfsxattrat sys_getfsxattrat +468 i386 setfsxattrat sys_setfsxattratarch/x86/entry/syscalls/syscall_64.tbl +2
-0@@ -390,6 +390,8 @@ 464 common getxattrat sys_getxattrat 465 common listxattrat sys_listxattrat 466 common removexattrat sys_removexattrat +467 common getfsxattrat sys_getfsxattrat +468 common setfsxattrat sys_setfsxattrat # # Due to a historical design error, certain syscalls are numbered differentlyarch/xtensa/kernel/syscalls/syscall.tbl +2
-0@@ -437,3 +437,5 @@ 464 common getxattrat sys_getxattrat 465 common listxattrat sys_listxattrat 466 common removexattrat sys_removexattrat +467 common getfsxattrat sys_getfsxattrat +468 common setfsxattrat sys_setfsxattratfs/inode.c +15
-0@@ -23,6 +23,9 @@#include <linux/rw_hint.h> #include <linux/seq_file.h> #include <linux/debugfs.h> +#include <linux/syscalls.h> +#include <linux/fileattr.h> +#include <linux/namei.h> #include <trace/events/writeback.h> #define CREATE_TRACE_POINTS #include <trace/events/timestamp.h> @@ -2953,3 +2956,99 @@ umode_t mode_strip_sgid(struct mnt_idmap *idmap,return mode & ~S_ISGID ; }EXPORT_SYMBOL (mode_strip_sgid); + +SYSCALL_DEFINE4(getfsxattrat, int, dfd, const char __user *, filename, + struct fsxattr __user *, fsx, unsigned int, at_flags) +{ +struct fd dir; +struct fileattr fa; +struct path filepath; +int error; +unsigned int lookup_flags =0 ; + +if ((at_flags & ~(AT_SYMLINK_NOFOLLOW |AT_EMPTY_PATH )) !=0 ) +return -EINVAL ;
fs/inode.c umode_t mode_strip_sgid(struct mnt_idmap *idmap, · line 2980
Quoted 10 lines
fs/inode.c +10
-0+ +if (at_flags &AT_SYMLINK_FOLLOW ) + lookup_flags |=LOOKUP_FOLLOW ; + +if (at_flags &AT_EMPTY_PATH ) + lookup_flags |=LOOKUP_EMPTY ; + + dir =fdget (dfd); +if (!fd_file (dir)) +return -EBADF ;
Please rely on scope-based cleanup:
CLASS(fd, f)(dfd);
if (fd_empty(f))
return -EBADF;
fs/inode.c umode_t mode_strip_sgid(struct mnt_idmap *idmap, · line 2982
Quoted 2 lines
fs/inode.c +2
-0+ +if (!S_ISDIR (file_inode (fd_file (dir))->i_mode)) {
This isn't needed as user_path_at() will return ENOTDIR. Your path as is wuld also preclude AT_EMPTY_PATH with directory file descriptors and afaict there's various filesystems that seem to support this on directory inodes.
fs/inode.c umode_t mode_strip_sgid(struct mnt_idmap *idmap, · line 2989
Quoted 7 lines
fs/inode.c +7
-0+ error = -EBADF ; + goto out; + } + + error =user_path_at (dfd, filename, lookup_flags, &filepath); +if (error) + goto out;
I'm confused. You're using fdget() above but then you don't use the resulting file and call user_path_at() instead? Don't bother with fdget() at all and just call into user_path_at() directly.
Quoted 40 lines
fs/inode.c +40
-0+ + error =vfs_fileattr_get (filepath.dentry, &fa); +if (error) + goto out_path; + +if (copy_fsxattr_to_user (&fa, fsx)) + error = -EFAULT ; + +out_path: +path_put (&filepath); +out: +fdput (dir); +return error; +} + +SYSCALL_DEFINE4(setfsxattrat, int, dfd, const char __user *, filename, + struct fsxattr __user *, fsx, unsigned int, at_flags) +{ +struct fd dir; +struct fileattr fa; +struct path filepath; +int error; +unsigned int lookup_flags =0 ; + +if ((at_flags & ~(AT_SYMLINK_FOLLOW |AT_EMPTY_PATH )) !=0 ) +return -EINVAL ; + +if (at_flags &AT_SYMLINK_FOLLOW ) + lookup_flags |=LOOKUP_FOLLOW ; + +if (at_flags &AT_EMPTY_PATH ) + lookup_flags |=LOOKUP_EMPTY ; + + dir =fdget (dfd); +if (!fd_file (dir)) +return -EBADF ; + +if (!S_ISDIR (file_inode (fd_file (dir))->i_mode)) { + error = -EBADF ; + goto out;
fs/inode.c umode_t mode_strip_sgid(struct mnt_idmap *idmap, · line 3039
Quoted 10 lines
fs/inode.c +10
-0+ } + +if (copy_fsxattr_from_user (&fa, fsx)) { + error = -EFAULT ; + goto out; + } + + error =user_path_at (dfd, filename, lookup_flags, &filepath); +if (error) + goto out;
Same problem as above. fdget() stuff isn't needed if you're calling user_path_at() anyway.
fs/inode.c umode_t mode_strip_sgid(struct mnt_idmap *idmap, · line 3047
Quoted 8 lines
fs/inode.c +8
-0+ + error =mnt_want_write (filepath.mnt); +if (error) + goto out_path; + + error =vfs_fileattr_set (file_mnt_idmap (fd_file (dir)), filepath.dentry, + &fa); +mnt_drop_write (filepath.mnt);
Just use the pattern:
error = user_path_at(dfd, filename, lookup_flags, &filepath);
if (error)
return error; /* once you've removed the fdget() direct return works fine */
error = mnt_want_write(filepath.mnt);
if (!error) {
error = vfs_fileattr_set(file_mnt_idmap(fd_file(dir)), filepath.dentry, &fa);
mnt_drop_write(filepath.mnt);
}return error;
Quoted 97 lines
fs/inode.c +7
-0+ +out_path: +path_put (&filepath); +out: +fdput (dir); +return error; +}fs/ioctl.c +14
-2@@ -558,8 +558,7 @@ int copy_fsxattr_to_user(const struct fileattr *fa, struct fsxattr __user *ufa) }EXPORT_SYMBOL (copy_fsxattr_to_user); -static int copy_fsxattr_from_user (struct fileattr *fa, -struct fsxattr __user *ufa) +int copy_fsxattr_from_user (struct fileattr *fa,struct fsxattr __user *ufa) {struct fsxattr xfa;@@ -646,6 +645,19 @@ static int fileattr_set_prepare(struct inode *inode,if (fa->fsx_cowextsize ==0 ) fa->fsx_xflags &= ~FS_XFLAG_COWEXTSIZE ; +/* +* The only use case for special files is to set project ID, forbid any +* other attributes +*/ +if (!(S_ISREG (inode->i_mode) ||S_ISDIR (inode->i_mode))) { +if (fa->fsx_xflags & ~FS_XFLAG_PROJINHERIT ) +return -EINVAL ; +if (!S_ISLNK (inode->i_mode) && fa->fsx_nextents) +return -EINVAL ; +if (fa->fsx_extsize || fa->fsx_cowextsize) +return -EINVAL ; + } +return 0 ; }include/linux/fileattr.h +1
-0@@ -34,6 +34,7 @@ struct fileattr { };int copy_fsxattr_to_user (const struct fileattr *fa,struct fsxattr __user *ufa); +int copy_fsxattr_from_user (struct fileattr *fa,struct fsxattr __user *ufa);void fileattr_fill_xflags (struct fileattr *fa,u32 xflags);void fileattr_fill_flags (struct fileattr *fa,u32 flags);include/linux/syscalls.h +4
-0@@ -371,6 +371,10 @@ 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_getfsxattrat (int dfd,const char __user *filename, +struct fsxattr *fsx,unsigned int at_flags); +asmlinkage long sys_setfsxattrat (int dfd,const char __user *filename, +struct fsxattr *fsx,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
-2@@ -850,8 +850,14 @@ __SYSCALL(__NR_listxattrat, sys_listxattrat)#define __NR_removexattrat 466__SYSCALL (__NR_removexattrat, sys_removexattrat) +/* fs/inode.c */ +#define __NR_getfsxattrat 467 +__SYSCALL(__NR_getfsxattrat, sys_getfsxattrat) +#define __NR_setfsxattrat 468 +__SYSCALL(__NR_setfsxattrat, sys_setfsxattrat) +#undef __NR_syscalls -#define __NR_syscalls 467 +#define __NR_syscalls 469/* * 32 bit systems traditionally used different --- base-commit:
4c538044ee2d11299cc57ac1e92d343e1e83b847
change-id: 20250114-xattrat-syscall-6a1136d2db59Best regards,
Signature · 1 line
Andrey Albershteyn <[email protected]>
Quoted 7 lines · Christian Brauner
Quoted 6 lines · Andrey Albershteyn
From: Andrey Albershteyn <[email protected]>
Introduce getfsxattrat and setfsxattrat syscalls to manipulate inode extended attributes/flags. The syscalls take parent directory FD and path to the child together with struct fsxattr.
Quoted 5 lines
Quoted 2 lines
This is an alternative to
FS_IOC_FSSETXATTRioctl with a difference that file don't need to be open. By having this we can manipulatedBy that you mean that you can use absolute or relative paths instead of file descriptors?
yes
Quoted 20 lines
Quoted 5 lines
inode extended attributes not only on normal files but also on special ones. This is not possible with
FS_IOC_FSSETXATTRioctl as opening special files returns VFS special inode instead of underlying filesystem one.I'm not following this argument currently. In what sense does opening special files return a VFS special inode and how does that prevent
FS_IOC_FSSEETXATTRfrom working? The inode instatic int
ioctl_fssetxattr(struct file *file, void __user *argp){ struct mnt_idmap *idmap = file_mnt_idmap(file); struct dentry *dentry = file->f_path.dentry; d_inode(dentry)and your:
Quoted 7 lines
error =
user_path_at(dfd, filename, lookup_flags, &filepath); if (error)goto out;
d_inode(filepath.dentry)is the same.
This is probably not a good description. With these special files, like pipe, we can not just open them to call FS_IOC_FSSETXATTR, as with regular ones. As you asked above, with filepath it can be done without opening files in userspace. I don't see how we can open() special files and then call ioctl() on them and with paths we can do it pretty easily.
Quoted 265 lines
Quoted 252 lines
This patch adds two new syscalls which allows userspace to set extended inode attributes on special files by using parent directory to open FS inode.
Also, as
vfs_fileattr_set()is now will be called on special files too, let's forbid any other attributes except projid and nextents (symlink can have an extent).Signed-off-by Andrey Albershteyn <[email protected]>---
v1:
https://lore.kernel.org/linuxppc-dev/[email protected]/Previous discussion:
https://lore.kernel.org/linux-xfs/[email protected]/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. Moreover, in the case when special files are created in the directory with already existing project quota, these inode inherit extended attributes. This than leaves them with these attributes without the possibility to clear them out. This, in turn, prevents userspace from re-creating quota project on these existing files.--- 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/inode.c | 99 +++++++++++++++++++++++++++++ fs/ioctl.c | 16 ++++- include/linux/fileattr.h | 1 + include/linux/syscalls.h | 4 ++ include/uapi/asm-generic/unistd.h | 8 ++- 21 files changed, 157 insertions(+), 3 deletions(-)arch/alpha/kernel/syscalls/syscall.tbl +2
-0@@ -506,3 +506,5 @@ 574 common getxattrat sys_getxattrat 575 common listxattrat sys_listxattrat 576 common removexattrat sys_removexattrat +577 common getfsxattrat sys_getfsxattrat +578 common setfsxattrat sys_setfsxattratarch/arm/tools/syscall.tbl +2
-0@@ -481,3 +481,5 @@ 464 common getxattrat sys_getxattrat 465 common listxattrat sys_listxattrat 466 common removexattrat sys_removexattrat +467 common getfsxattrat sys_getfsxattrat +468 common setfsxattrat sys_setfsxattratarch/arm64/tools/syscall_32.tbl +2
-0@@ -478,3 +478,5 @@ 464 common getxattrat sys_getxattrat 465 common listxattrat sys_listxattrat 466 common removexattrat sys_removexattrat +467 common getfsxattrat sys_getfsxattrat +468 common setfsxattrat sys_setfsxattratarch/m68k/kernel/syscalls/syscall.tbl +2
-0@@ -466,3 +466,5 @@ 464 common getxattrat sys_getxattrat 465 common listxattrat sys_listxattrat 466 common removexattrat sys_removexattrat +467 common getfsxattrat sys_getfsxattrat +468 common setfsxattrat sys_setfsxattratarch/microblaze/kernel/syscalls/syscall.tbl +2
-0@@ -472,3 +472,5 @@ 464 common getxattrat sys_getxattrat 465 common listxattrat sys_listxattrat 466 common removexattrat sys_removexattrat +467 common getfsxattrat sys_getfsxattrat +468 common setfsxattrat sys_setfsxattratarch/mips/kernel/syscalls/syscall_n32.tbl +2
-0@@ -405,3 +405,5 @@ 464 n32 getxattrat sys_getxattrat 465 n32 listxattrat sys_listxattrat 466 n32 removexattrat sys_removexattrat +467 n32 getfsxattrat sys_getfsxattrat +468 n32 setfsxattrat sys_setfsxattratarch/mips/kernel/syscalls/syscall_n64.tbl +2
-0@@ -381,3 +381,5 @@ 464 n64 getxattrat sys_getxattrat 465 n64 listxattrat sys_listxattrat 466 n64 removexattrat sys_removexattrat +467 n64 getfsxattrat sys_getfsxattrat +468 n64 setfsxattrat sys_setfsxattratarch/mips/kernel/syscalls/syscall_o32.tbl +2
-0@@ -454,3 +454,5 @@ 464 o32 getxattrat sys_getxattrat 465 o32 listxattrat sys_listxattrat 466 o32 removexattrat sys_removexattrat +467 o32 getfsxattrat sys_getfsxattrat +468 o32 setfsxattrat sys_setfsxattratarch/parisc/kernel/syscalls/syscall.tbl +2
-0@@ -465,3 +465,5 @@ 464 common getxattrat sys_getxattrat 465 common listxattrat sys_listxattrat 466 common removexattrat sys_removexattrat +467 common getfsxattrat sys_getfsxattrat +468 common setfsxattrat sys_setfsxattratarch/powerpc/kernel/syscalls/syscall.tbl +2
-0@@ -557,3 +557,5 @@ 464 common getxattrat sys_getxattrat 465 common listxattrat sys_listxattrat 466 common removexattrat sys_removexattrat +467 common getfsxattrat sys_getfsxattrat +468 common setfsxattrat sys_setfsxattratarch/s390/kernel/syscalls/syscall.tbl +2
-0@@ -469,3 +469,5 @@ 464 common getxattrat sys_getxattrat sys_getxattrat 465 common listxattrat sys_listxattrat sys_listxattrat 466 common removexattrat sys_removexattrat sys_removexattrat +467 common getfsxattrat sys_getfsxattrat sys_getfsxattrat +468 common setfsxattrat sys_setfsxattrat sys_setfsxattratarch/sh/kernel/syscalls/syscall.tbl +2
-0@@ -470,3 +470,5 @@ 464 common getxattrat sys_getxattrat 465 common listxattrat sys_listxattrat 466 common removexattrat sys_removexattrat +467 common getfsxattrat sys_getfsxattrat +468 common setfsxattrat sys_setfsxattratarch/sparc/kernel/syscalls/syscall.tbl +2
-0@@ -512,3 +512,5 @@ 464 common getxattrat sys_getxattrat 465 common listxattrat sys_listxattrat 466 common removexattrat sys_removexattrat +467 common getfsxattrat sys_getfsxattrat +468 common setfsxattrat sys_setfsxattratarch/x86/entry/syscalls/syscall_32.tbl +2
-0@@ -472,3 +472,5 @@ 464 i386 getxattrat sys_getxattrat 465 i386 listxattrat sys_listxattrat 466 i386 removexattrat sys_removexattrat +467 i386 getfsxattrat sys_getfsxattrat +468 i386 setfsxattrat sys_setfsxattratarch/x86/entry/syscalls/syscall_64.tbl +2
-0@@ -390,6 +390,8 @@ 464 common getxattrat sys_getxattrat 465 common listxattrat sys_listxattrat 466 common removexattrat sys_removexattrat +467 common getfsxattrat sys_getfsxattrat +468 common setfsxattrat sys_setfsxattrat # # Due to a historical design error, certain syscalls are numbered differentlyarch/xtensa/kernel/syscalls/syscall.tbl +2
-0@@ -437,3 +437,5 @@ 464 common getxattrat sys_getxattrat 465 common listxattrat sys_listxattrat 466 common removexattrat sys_removexattrat +467 common getfsxattrat sys_getfsxattrat +468 common setfsxattrat sys_setfsxattratfs/inode.c +15
-0@@ -23,6 +23,9 @@#include <linux/rw_hint.h> #include <linux/seq_file.h> #include <linux/debugfs.h> +#include <linux/syscalls.h> +#include <linux/fileattr.h> +#include <linux/namei.h> #include <trace/events/writeback.h> #define CREATE_TRACE_POINTS #include <trace/events/timestamp.h> @@ -2953,3 +2956,99 @@ umode_t mode_strip_sgid(struct mnt_idmap *idmap,return mode & ~S_ISGID ; }EXPORT_SYMBOL (mode_strip_sgid); + +SYSCALL_DEFINE4(getfsxattrat, int, dfd, const char __user *, filename, + struct fsxattr __user *, fsx, unsigned int, at_flags) +{ +struct fd dir; +struct fileattr fa; +struct path filepath; +int error; +unsigned int lookup_flags =0 ; + +if ((at_flags & ~(AT_SYMLINK_NOFOLLOW |AT_EMPTY_PATH )) !=0 ) +return -EINVAL ;fs/inode.c umode_t mode_strip_sgid(struct mnt_idmap *idmap, · line 2980
Quoted 10 lines
fs/inode.c +10
-0+ +if (at_flags &AT_SYMLINK_FOLLOW ) + lookup_flags |=LOOKUP_FOLLOW ; + +if (at_flags &AT_EMPTY_PATH ) + lookup_flags |=LOOKUP_EMPTY ; + + dir =fdget (dfd); +if (!fd_file (dir)) +return -EBADF ;Please rely on scope-based cleanup:
Quoted 3 lines
CLASS(fd, f)(dfd);
if (fd_empty(f))return -EBADF;
aha, thanks, didn't know about this
Quoted 8 lines
fs/inode.c umode_t mode_strip_sgid(struct mnt_idmap *idmap, · line 2982
Quoted 3 lines
fs/inode.c +2
-0+ +if (!S_ISDIR (file_inode (fd_file (dir))->i_mode)) {This isn't needed as
user_path_at()will return ENOTDIR. Your path as is wuld also precludeAT_EMPTY_PATHwith directory file descriptors and afaict there's various filesystems that seem to support this on directory inodes.
I see, thanks, I will remove that
Quoted 12 lines
fs/inode.c umode_t mode_strip_sgid(struct mnt_idmap *idmap, · line 2989
Quoted 8 lines
fs/inode.c +7
-0+ error = -EBADF ; + goto out; + } + + error =user_path_at (dfd, filename, lookup_flags, &filepath); +if (error) + goto out;I'm confused. You're using
fdget()above but then you don't use the resulting file and calluser_path_at()instead? Don't bother withfdget()at all and just call intouser_path_at()directly.
sure, doesn't needed anymore with your suggestions above
Quoted 71 lines
Quoted 41 lines
fs/inode.c +40
-0+ + error =vfs_fileattr_get (filepath.dentry, &fa); +if (error) + goto out_path; + +if (copy_fsxattr_to_user (&fa, fsx)) + error = -EFAULT ; + +out_path: +path_put (&filepath); +out: +fdput (dir); +return error; +} + +SYSCALL_DEFINE4(setfsxattrat, int, dfd, const char __user *, filename, + struct fsxattr __user *, fsx, unsigned int, at_flags) +{ +struct fd dir; +struct fileattr fa; +struct path filepath; +int error; +unsigned int lookup_flags =0 ; + +if ((at_flags & ~(AT_SYMLINK_FOLLOW |AT_EMPTY_PATH )) !=0 ) +return -EINVAL ; + +if (at_flags &AT_SYMLINK_FOLLOW ) + lookup_flags |=LOOKUP_FOLLOW ; + +if (at_flags &AT_EMPTY_PATH ) + lookup_flags |=LOOKUP_EMPTY ; + + dir =fdget (dfd); +if (!fd_file (dir)) +return -EBADF ; + +if (!S_ISDIR (file_inode (fd_file (dir))->i_mode)) { + error = -EBADF ; + goto out;fs/inode.c umode_t mode_strip_sgid(struct mnt_idmap *idmap, · line 3039
Quoted 10 lines
fs/inode.c +10
-0+ } + +if (copy_fsxattr_from_user (&fa, fsx)) { + error = -EFAULT ; + goto out; + } + + error =user_path_at (dfd, filename, lookup_flags, &filepath); +if (error) + goto out;Same problem as above.
fdget()stuff isn't needed if you're callinguser_path_at()anyway.fs/inode.c umode_t mode_strip_sgid(struct mnt_idmap *idmap, · line 3047
Quoted 8 lines
fs/inode.c +8
-0+ + error =mnt_want_write (filepath.mnt); +if (error) + goto out_path; + + error =vfs_fileattr_set (file_mnt_idmap (fd_file (dir)), filepath.dentry, + &fa); +mnt_drop_write (filepath.mnt);Just use the pattern:
error =
user_path_at(dfd, filename, lookup_flags, &filepath);
if (error)
return error; /* once you've removed thefdget()direct return works fine */
Quoted 7 lines
error =
mnt_want_write(filepath.mnt);if (!error) { error = vfs_fileattr_set(file_mnt_idmap(fd_file(dir)), filepath.dentry, &fa); mnt_drop_write(filepath.mnt); }return error;
sure, I will changed it as suggested
Signature · 1 line
- Andrey
Quoted 99 lines
Quoted 98 lines
fs/inode.c +7
-0+ +out_path: +path_put (&filepath); +out: +fdput (dir); +return error; +}fs/ioctl.c +14
-2@@ -558,8 +558,7 @@ int copy_fsxattr_to_user(const struct fileattr *fa, struct fsxattr __user *ufa) }EXPORT_SYMBOL (copy_fsxattr_to_user); -static int copy_fsxattr_from_user (struct fileattr *fa, -struct fsxattr __user *ufa) +int copy_fsxattr_from_user (struct fileattr *fa,struct fsxattr __user *ufa) {struct fsxattr xfa;@@ -646,6 +645,19 @@ static int fileattr_set_prepare(struct inode *inode,if (fa->fsx_cowextsize ==0 ) fa->fsx_xflags &= ~FS_XFLAG_COWEXTSIZE ; +/* +* The only use case for special files is to set project ID, forbid any +* other attributes +*/ +if (!(S_ISREG (inode->i_mode) ||S_ISDIR (inode->i_mode))) { +if (fa->fsx_xflags & ~FS_XFLAG_PROJINHERIT ) +return -EINVAL ; +if (!S_ISLNK (inode->i_mode) && fa->fsx_nextents) +return -EINVAL ; +if (fa->fsx_extsize || fa->fsx_cowextsize) +return -EINVAL ; + } +return 0 ; }include/linux/fileattr.h +1
-0@@ -34,6 +34,7 @@ struct fileattr { };int copy_fsxattr_to_user (const struct fileattr *fa,struct fsxattr __user *ufa); +int copy_fsxattr_from_user (struct fileattr *fa,struct fsxattr __user *ufa);void fileattr_fill_xflags (struct fileattr *fa,u32 xflags);void fileattr_fill_flags (struct fileattr *fa,u32 flags);include/linux/syscalls.h +4
-0@@ -371,6 +371,10 @@ 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_getfsxattrat (int dfd,const char __user *filename, +struct fsxattr *fsx,unsigned int at_flags); +asmlinkage long sys_setfsxattrat (int dfd,const char __user *filename, +struct fsxattr *fsx,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
-2@@ -850,8 +850,14 @@ __SYSCALL(__NR_listxattrat, sys_listxattrat)#define __NR_removexattrat 466__SYSCALL (__NR_removexattrat, sys_removexattrat) +/* fs/inode.c */ +#define __NR_getfsxattrat 467 +__SYSCALL(__NR_getfsxattrat, sys_getfsxattrat) +#define __NR_setfsxattrat 468 +__SYSCALL(__NR_setfsxattrat, sys_setfsxattrat) +#undef __NR_syscalls -#define __NR_syscalls 467 +#define __NR_syscalls 469/* * 32 bit systems traditionally used different --- base-commit:
4c538044ee2d11299cc57ac1e92d343e1e83b847
change-id: 20250114-xattrat-syscall-6a1136d2db59Best regards,
Signature · 1 line
Andrey Albershteyn <[email protected]>