vfs: add faccessat2 syscall
Subsystems (18)
PATCH v2 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.
Also add AT_EMPTY_PATH support, which is not documented by POSIX, but can be useful and is trivial to implement.
Signed-off-by Miklos Szeredi <[email protected]>
---
v2:
- add AT_EMPTY_PATH
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 | 58 ++++++++++++++++----- include/linux/syscalls.h | 7 ++- include/uapi/asm-generic/unistd.h | 4 +- include/uapi/linux/fcntl.h | 10 ++++ 23 files changed, 82 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 +45 -13
91 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