vfs: add faccessat2 syscall
Subsystems (18)
PATCH 1/1 vfs: add faccessat2 syscall
POSIX defines faccessat() as having a fourth "flags" argument, while the linux syscall doesn't have it. Glibc tries to emulate AT_EACCESS and AT_SYMLINK_NOFOLLOW, but AT_EACCESS emulation is broken.
Add a new faccessat(2) syscall with the added flags argument and implement both flags.
The value of AT_EACCESS is defined in glibc headers to be the same as AT_REMOVEDIR. Use this value for the kernel interface as well, together with the explanatory comment.
--- arch/alpha/kernel/syscalls/syscall.tbl | 1 + arch/arm/tools/syscall.tbl | 1 + arch/arm64/include/asm/unistd.h | 2 +- arch/arm64/include/asm/unistd32.h | 2 + arch/ia64/kernel/syscalls/syscall.tbl | 1 + arch/m68k/kernel/syscalls/syscall.tbl | 1 + arch/microblaze/kernel/syscalls/syscall.tbl | 1 + arch/mips/kernel/syscalls/syscall_n32.tbl | 1 + arch/mips/kernel/syscalls/syscall_n64.tbl | 1 + arch/mips/kernel/syscalls/syscall_o32.tbl | 1 + arch/parisc/kernel/syscalls/syscall.tbl | 1 + arch/powerpc/kernel/syscalls/syscall.tbl | 1 + arch/s390/kernel/syscalls/syscall.tbl | 1 + arch/sh/kernel/syscalls/syscall.tbl | 1 + arch/sparc/kernel/syscalls/syscall.tbl | 1 + arch/x86/entry/syscalls/syscall_32.tbl | 1 + arch/x86/entry/syscalls/syscall_64.tbl | 1 + arch/xtensa/kernel/syscalls/syscall.tbl | 1 + fs/internal.h | 1 - fs/open.c | 56 ++++++++++++++++----- include/linux/syscalls.h | 7 ++- include/uapi/asm-generic/unistd.h | 4 +- include/uapi/linux/fcntl.h | 10 ++++ 23 files changed, 80 insertions(+), 18 deletions(-)
arch/alpha/kernel/syscalls/syscall.tbl +1 -0
@@ -477,3 +477,4 @@ # 545 reserved for clone3 547 common openat2 sys_openat2 548 common pidfd_getfd sys_pidfd_getfd +549 common faccessat2 sys_faccessat2
arch/arm/tools/syscall.tbl +1 -0
@@ -451,3 +451,4 @@ 435 common clone3 sys_clone3 437 common openat2 sys_openat2 438 common pidfd_getfd sys_pidfd_getfd +439 common faccessat2 sys_faccessat2
arch/arm64/include/asm/unistd.h +1 -1
@@ -38,7 +38,7 @@#define __ARM_NR_compat_set_tls (__ARM_NR_COMPAT_BASE + 5)#define __ARM_NR_COMPAT_END (__ARM_NR_COMPAT_BASE + 0x800) -#define __NR_compat_syscalls 439 +#define __NR_compat_syscalls 440#endif #define __ARCH_WANT_SYS_CLONE
arch/arm64/include/asm/unistd32.h +2 -0
@@ -883,6 +883,8 @@ __SYSCALL(__NR_clone3, sys_clone3) __SYSCALL(__NR_openat2, sys_openat2)#define __NR_pidfd_getfd 438 __SYSCALL(__NR_pidfd_getfd, sys_pidfd_getfd) +#define __NR_faccessat2 439 +__SYSCALL (__NR_faccessat2, sys_faccessat2)/* * Please add new compat syscalls above this comment and update
arch/ia64/kernel/syscalls/syscall.tbl +1 -0
@@ -358,3 +358,4 @@ # 435 reserved for clone3 437 common openat2 sys_openat2 438 common pidfd_getfd sys_pidfd_getfd +439 common faccessat2 sys_faccessat2
arch/m68k/kernel/syscalls/syscall.tbl +1 -0
@@ -437,3 +437,4 @@ 435 common clone3 __sys_clone3 437 common openat2 sys_openat2 438 common pidfd_getfd sys_pidfd_getfd +439 common faccessat2 sys_faccessat2
arch/microblaze/kernel/syscalls/syscall.tbl +1 -0
@@ -443,3 +443,4 @@ 435 common clone3 sys_clone3 437 common openat2 sys_openat2 438 common pidfd_getfd sys_pidfd_getfd +439 common faccessat2 sys_faccessat2
arch/mips/kernel/syscalls/syscall_n32.tbl +1 -0
@@ -376,3 +376,4 @@ 435 n32 clone3 __sys_clone3 437 n32 openat2 sys_openat2 438 n32 pidfd_getfd sys_pidfd_getfd +439 n32 faccessat2 sys_faccessat2
arch/mips/kernel/syscalls/syscall_n64.tbl +1 -0
@@ -352,3 +352,4 @@ 435 n64 clone3 __sys_clone3 437 n64 openat2 sys_openat2 438 n64 pidfd_getfd sys_pidfd_getfd +439 n64 faccessat2 sys_faccessat2
arch/mips/kernel/syscalls/syscall_o32.tbl +1 -0
@@ -425,3 +425,4 @@ 435 o32 clone3 __sys_clone3 437 o32 openat2 sys_openat2 438 o32 pidfd_getfd sys_pidfd_getfd +439 o32 faccessat2 sys_faccessat2
arch/parisc/kernel/syscalls/syscall.tbl +1 -0
@@ -435,3 +435,4 @@ 435 common clone3 sys_clone3_wrapper 437 common openat2 sys_openat2 438 common pidfd_getfd sys_pidfd_getfd +439 common faccessat2 sys_faccessat2
arch/powerpc/kernel/syscalls/syscall.tbl +1 -0
@@ -527,3 +527,4 @@ 435 spu clone3 sys_ni_syscall 437 common openat2 sys_openat2 438 common pidfd_getfd sys_pidfd_getfd +439 common faccessat2 sys_faccessat2
arch/s390/kernel/syscalls/syscall.tbl +1 -0
@@ -440,3 +440,4 @@ 435 common clone3 sys_clone3 sys_clone3 437 common openat2 sys_openat2 sys_openat2 438 common pidfd_getfd sys_pidfd_getfd sys_pidfd_getfd +439 common faccessat2 sys_faccessat2 sys_faccessat2
arch/sh/kernel/syscalls/syscall.tbl +1 -0
@@ -440,3 +440,4 @@ # 435 reserved for clone3 437 common openat2 sys_openat2 438 common pidfd_getfd sys_pidfd_getfd +439 common faccessat2 sys_faccessat2
arch/sparc/kernel/syscalls/syscall.tbl +1 -0
@@ -483,3 +483,4 @@ # 435 reserved for clone3 437 common openat2 sys_openat2 438 common pidfd_getfd sys_pidfd_getfd +439 common faccessat2 sys_faccessat2
arch/x86/entry/syscalls/syscall_32.tbl +1 -0
@@ -442,3 +442,4 @@ 435 i386 clone3 sys_clone3 437 i386 openat2 sys_openat2 438 i386 pidfd_getfd sys_pidfd_getfd +439 i386 faccessat2 sys_faccessat2
arch/x86/entry/syscalls/syscall_64.tbl +1 -0
@@ -359,6 +359,7 @@ 435 common clone3 sys_clone3 437 common openat2 sys_openat2 438 common pidfd_getfd sys_pidfd_getfd +439 common faccessat2 sys_faccessat2 # # x32-specific system call numbers start at 512 to avoid cache impact
arch/xtensa/kernel/syscalls/syscall.tbl +1 -0
@@ -408,3 +408,4 @@ 435 common clone3 sys_clone3 437 common openat2 sys_openat2 438 common pidfd_getfd sys_pidfd_getfd +439 common faccessat2 sys_faccessat2
fs/internal.h +0 -1
@@ -126,7 +126,6 @@ extern struct open_how build_open_how(int flags, umode_t mode);extern int build_open_flags (const struct open_how *how,struct open_flags *op);long do_sys_ftruncate (unsigned int fd,loff_t length,int small); -long do_faccessat (int dfd,const char __user *filename,int mode);int do_fchmodat (int dfd,const char __user *filename,umode_t mode);int do_fchownat (int dfd,const char __user *filename,uid_t user,gid_t group,int flag);
fs/open.c +43 -13
89 lines not on this page · raw message
include/linux/syscalls.h +5 -2
@@ -428,6 +428,8 @@ asmlinkage long sys_ftruncate64(unsigned int fd, loff_t length);#endif asmlinkage long sys_fallocate (int fd,int mode,loff_t offset,loff_t len);asmlinkage long sys_faccessat (int dfd,const char __user *filename,int mode); +asmlinkage long sys_faccessat2 (int dfd,const char __user *filename,int mode, +int flags);asmlinkage long sys_chdir (const char __user *filename);asmlinkage long sys_fchdir (unsigned int fd);asmlinkage long sys_chroot (const char __user *filename);
@@ -1333,11 +1335,12 @@ static inline int ksys_chmod(const char __user *filename, umode_t mode)return do_fchmodat (AT_FDCWD , filename, mode); } -extern long do_faccessat (int dfd,const char __user *filename,int mode); +extern long do_faccessat (int dfd,const char __user *filename,int mode, +int flags);static inline long ksys_access (const char __user *filename,int mode) { -return do_faccessat (AT_FDCWD , filename, mode); +return do_faccessat (AT_FDCWD , filename, mode,0 ); } extern int do_fchownat(int dfd, const char __user *filename, uid_t user,
include/uapi/asm-generic/unistd.h +3 -1
@@ -855,9 +855,11 @@ __SYSCALL(__NR_clone3, sys_clone3) __SYSCALL(__NR_openat2, sys_openat2)#define __NR_pidfd_getfd 438 __SYSCALL(__NR_pidfd_getfd, sys_pidfd_getfd) +#define __NR_faccessat2 439 +__SYSCALL(__NR_faccessat2, sys_faccessat2)#undef __NR_syscalls -#define __NR_syscalls 439 +#define __NR_syscalls 440/* * 32 bit systems traditionally used different
include/uapi/linux/fcntl.h +10 -0
@@ -84,10 +84,20 @@#define DN_ATTRIB 0x00000020/* File changed attibutes */ #define DN_MULTISHOT 0x80000000/* Don't remove notifier */ +/* +* The constants AT_REMOVEDIR and AT_EACCESS have the same value. AT_EACCESS is +* meaningful only to faccessat, while AT_REMOVEDIR is meaningful only to +* unlinkat. The two functions do completely different things and therefore, +* the flags can be allowed to overlap. For example, passing AT_REMOVEDIR to +* faccessat would be undefined behavior and thus treating it equivalent to +* AT_EACCESS is valid undefined behavior. +*/ #define AT_FDCWD -100/* Special value used to indicate openat should use the current working directory. */ #define AT_SYMLINK_NOFOLLOW 0x100/* Do not follow symbolic links. */ +#define AT_EACCESS 0x200/* Test access permitted for +effective IDs, not real IDs. */ #define AT_REMOVEDIR 0x200/* Remove directory instead of unlinking file. */ #define AT_SYMLINK_FOLLOW 0x400/* Follow symbolic links. */
Signature · 1 line
2.21.1
* Miklos Szeredi:
Quoted 10 lines
POSIX defines
faccessat()as having a fourth "flags" argument, while the linux syscall doesn't have it. Glibc tries to emulateAT_EACCESSandAT_SYMLINK_NOFOLLOW, butAT_EACCESSemulation is broken.Add a new faccessat(2) syscall with the added flags argument and implement both flags.
The value of
AT_EACCESSis defined in glibc headers to be the same asAT_REMOVEDIR. Use this value for the kernel interface as well, together with the explanatory comment.
Thanks a lot for this!
fs/open.c long do_faccessat(int dfd, const char __user *filename, int mode) · line 409
Quoted 13 lines
fs/open.c +13
-0+long do_faccessat (int dfd,const char __user *filename,int mode,int flags) +{ +const struct cred *old_cred =NULL ; +struct path path; +struct inode *inode; +int res; +unsigned int lookup_flags =LOOKUP_FOLLOW ; + +if (mode & ~S_IRWXO )/* where's F_OK, X_OK, W_OK, R_OK? */ +return -EINVAL ; + +if (flags & ~(AT_EACCESS |AT_SYMLINK_NOFOLLOW )) +return -EINVAL ;
Should this accept AT_EMPTY_PATH as well?
(I can't comment on the rest of the logic of the patch.)
Quoted 15 lines
include/uapi/linux/fcntl.h +7
-0@@ -84,10 +84,20 @@#define DN_ATTRIB 0x00000020/* File changed attibutes */ #define DN_MULTISHOT 0x80000000/* Don't remove notifier */ +/* +* The constants AT_REMOVEDIR and AT_EACCESS have the same value. AT_EACCESS is +* meaningful only to faccessat, while AT_REMOVEDIR is meaningful only to +* unlinkat. The two functions do completely different things and therefore, +* the flags can be allowed to overlap. For example, passing AT_REMOVEDIR to +* faccessat would be undefined behavior and thus treating it equivalent to +* AT_EACCESS is valid undefined behavior.
include/uapi/linux/fcntl.h line 103
Quoted 10 lines
include/uapi/linux/fcntl.h +3
-0+*/ #define AT_FDCWD -100/* Special value used to indicate openat should use the current working directory. */ #define AT_SYMLINK_NOFOLLOW 0x100/* Do not follow symbolic links. */ +#define AT_EACCESS 0x200/* Test access permitted for +effective IDs, not real IDs. */ #define AT_REMOVEDIR 0x200/* Remove directory instead of unlinking file. */ #define AT_SYMLINK_FOLLOW 0x400/* Follow symbolic links. */
I can confirm that this is what glibc does, ofr better or worse.
Thanks,
Florian
Hi Miklos,
Quoted 10 lines
POSIX defines
faccessat()as having a fourth "flags" argument, while the linux syscall doesn't have it. Glibc tries to emulateAT_EACCESSandAT_SYMLINK_NOFOLLOW, butAT_EACCESSemulation is broken.Add a new faccessat(2) syscall with the added flags argument and implement both flags.
The value of
AT_EACCESSis defined in glibc headers to be the same asAT_REMOVEDIR. Use this value for the kernel interface as well, together with the explanatory comment.
It would be nice if resolv_flags would also be passed in addition to the
at flags. See:https://lore.kernel.org/linux-api/CAHk-=wiaL6zznNtCHKg6+MJuCqDxO=yVfms3qR9A0czjKuSSiA@mail.gmail.com/
We should avoid expecting yet another syscall in near future.
metze
Quoted 14 lines · Stefan Metzmacher
Hi Miklos,
Quoted 10 lines
POSIX defines
faccessat()as having a fourth "flags" argument, while the linux syscall doesn't have it. Glibc tries to emulateAT_EACCESSandAT_SYMLINK_NOFOLLOW, butAT_EACCESSemulation is broken.Add a new faccessat(2) syscall with the added flags argument and implement both flags.
The value of
AT_EACCESSis defined in glibc headers to be the same asAT_REMOVEDIR. Use this value for the kernel interface as well, together with the explanatory comment.
Quoted 5 lines
It would be nice if
resolv_flagswould also be passed in addition to the
at flags. See:https://lore.kernel.org/linux-api/CAHk-=wiaL6zznNtCHKg6+MJuCqDxO=yVfms3qR9A0czjKuSSiA@mail.gmail.com/We should avoid expecting yet another syscall in near future.
What is the objection against
openat(... O_PATH)foobarat(fd, AT_EMPTY_PATH, ...)
?
Thanks,
Miklos
Am 18.04.20 um 21:00 schrieb Miklos Szeredi:
Quoted 19 lines · Stefan Metzmacher
Quoted 18 lines
Hi Miklos,
Quoted 10 lines
POSIX defines
faccessat()as having a fourth "flags" argument, while the linux syscall doesn't have it. Glibc tries to emulateAT_EACCESSandAT_SYMLINK_NOFOLLOW, butAT_EACCESSemulation is broken.Add a new faccessat(2) syscall with the added flags argument and implement both flags.
The value of
AT_EACCESSis defined in glibc headers to be the same asAT_REMOVEDIR. Use this value for the kernel interface as well, together with the explanatory comment.It would be nice if
resolv_flagswould also be passed in addition to the
at flags. See:https://lore.kernel.org/linux-api/CAHk-=wiaL6zznNtCHKg6+MJuCqDxO=yVfms3qR9A0czjKuSSiA@mail.gmail.com/
Quoted 6 lines
Quoted 1 line
We should avoid expecting yet another syscall in near future.
What is the objection against
openat(...
O_PATH)foobarat(fd, AT_EMPTY_PATH, ...)
openat2(), foobarat(), close() are 3 syscalls vs. just one.
As we have the new features available, I think it would be good to expose them to userspace for all new syscalls, so that applications can avoid boiler plate stuff around each syscall and get better performance in a world where context switches are not for free.
metze
Quoted 11 lines · Stefan Metzmacher
Quoted 10 lines
POSIX defines
faccessat()as having a fourth "flags" argument, while the linux syscall doesn't have it. Glibc tries to emulateAT_EACCESSandAT_SYMLINK_NOFOLLOW, butAT_EACCESSemulation is broken.Add a new faccessat(2) syscall with the added flags argument and implement both flags.
The value of
AT_EACCESSis defined in glibc headers to be the same asAT_REMOVEDIR. Use this value for the kernel interface as well, together with the explanatory comment.
Quoted 5 lines
It would be nice if
resolv_flagswould also be passed in addition to the
at flags. See:https://lore.kernel.org/linux-api/CAHk-=wiaL6zznNtCHKg6+MJuCqDxO=yVfms3qR9A0czjKuSSiA@mail.gmail.com/We should avoid expecting yet another syscall in near future.
If faccessat2() supported AT_EMPTY_PATH (which I'd be in favour of), there's no need to add resolve flags because you could open the file as O_PATH with whatever resolve flags you want, and then check it with faccessat2().
Signature · 4 lines
Aleksa Sarai Senior Software Engineer (Containers) SUSE Linux GmbH <https://www.cyphar.com/>
Quoted 21 lines · Stefan Metzmacher
Am 18.04.20 um 21:00 schrieb Miklos Szeredi:
Quoted 19 lines · Stefan Metzmacher
Quoted 18 lines
Hi Miklos,
Quoted 10 lines
POSIX defines
faccessat()as having a fourth "flags" argument, while the linux syscall doesn't have it. Glibc tries to emulateAT_EACCESSandAT_SYMLINK_NOFOLLOW, butAT_EACCESSemulation is broken.Add a new faccessat(2) syscall with the added flags argument and implement both flags.
The value of
AT_EACCESSis defined in glibc headers to be the same asAT_REMOVEDIR. Use this value for the kernel interface as well, together with the explanatory comment.It would be nice if
resolv_flagswould also be passed in addition to the
at flags. See:https://lore.kernel.org/linux-api/CAHk-=wiaL6zznNtCHKg6+MJuCqDxO=yVfms3qR9A0czjKuSSiA@mail.gmail.com/
Quoted 8 lines
Quoted 6 lines
Quoted 1 line
We should avoid expecting yet another syscall in near future.
What is the objection against
openat(...
O_PATH)foobarat(fd, AT_EMPTY_PATH, ...)
openat2(),foobarat(),close()are 3 syscalls vs. just one.
That's not a good argument. We could have a million specialized syscalls that all do very useful things. Except it would be a nightmare in terms of maintenance...
"do one thing and do it well"
Quoted 5 lines
As we have the new features available, I think it would be good to expose them to userspace for all new syscalls, so that applications can avoid boiler plate stuff around each syscall and get better performance in a world where context switches are not for free.
The io-uring guys are working on that problem, AFAIK.
Thanks,
Miklos
Am 20.04.20 um 10:58 schrieb Miklos Szeredi:
Quoted 37 lines · Stefan Metzmacher
Quoted 21 lines
Am 18.04.20 um 21:00 schrieb Miklos Szeredi:
Quoted 19 lines · Stefan Metzmacher
Quoted 18 lines
Hi Miklos,
Quoted 10 lines
POSIX defines
faccessat()as having a fourth "flags" argument, while the linux syscall doesn't have it. Glibc tries to emulateAT_EACCESSandAT_SYMLINK_NOFOLLOW, butAT_EACCESSemulation is broken.Add a new faccessat(2) syscall with the added flags argument and implement both flags.
The value of
AT_EACCESSis defined in glibc headers to be the same asAT_REMOVEDIR. Use this value for the kernel interface as well, together with the explanatory comment.It would be nice if
resolv_flagswould also be passed in addition to the
at flags. See:https://lore.kernel.org/linux-api/CAHk-=wiaL6zznNtCHKg6+MJuCqDxO=yVfms3qR9A0czjKuSSiA@mail.gmail.com/Quoted 8 lines
Quoted 6 lines
Quoted 1 line
We should avoid expecting yet another syscall in near future.
What is the objection against
openat(...
O_PATH)foobarat(fd, AT_EMPTY_PATH, ...)
openat2(),foobarat(),close()are 3 syscalls vs. just one.That's not a good argument. We could have a million specialized syscalls that all do very useful things. Except it would be a nightmare in terms of maintenance...
"do one thing and do it well"
Quoted 7 lines
Quoted 5 lines
As we have the new features available, I think it would be good to expose them to userspace for all new syscalls, so that applications can avoid boiler plate stuff around each syscall and get better performance in a world where context switches are not for free.
The io-uring guys are working on that problem, AFAIK.
Ok, I'll try to workout with Jens, how to do optimizations...
metze