History

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.

Miklos Szeredi committed 6 years ago

Commit c8ffd8b1 parent 55923e423 files · +62 −13Browse files

Showing the changes to include/uapi (2 of 23 files). Show all

Unified · Split

2 files
  1. include/uapi/asm-generic/unistd.h +3 −1
  2. include/uapi/linux/fcntl.h +10 −0
include/uapi/asm-generic/unistd.h+3−1
@@ -855,9 +855,11 @@ __SYSCALL(__NR_clone3, sys_clone3) · 854 unmodified lines
855855 __SYSCALL(__NR_openat2, sys_openat2)
856856 #define __NR_pidfd_getfd 438
857857 __SYSCALL(__NR_pidfd_getfd, sys_pidfd_getfd)
858+#define __NR_faccessat2 439
859+__SYSCALL(__NR_faccessat2, sys_faccessat2)
858860
859861 #undef __NR_syscalls
860−#define __NR_syscalls 439
862+#define __NR_syscalls 440
861863
862864 /*
863865 * 32 bit systems traditionally used different
include/uapi/linux/fcntl.h+10−0
@@ -84,10 +84,20 @@ · 83 unmodified lines
8484 #define DN_ATTRIB 0x00000020 /* File changed attibutes */
8585 #define DN_MULTISHOT 0x80000000 /* Don't remove notifier */
8686
87+/*
88+ * The constants AT_REMOVEDIR and AT_EACCESS have the same value. AT_EACCESS is
89+ * meaningful only to faccessat, while AT_REMOVEDIR is meaningful only to
90+ * unlinkat. The two functions do completely different things and therefore,
91+ * the flags can be allowed to overlap. For example, passing AT_REMOVEDIR to
92+ * faccessat would be undefined behavior and thus treating it equivalent to
93+ * AT_EACCESS is valid undefined behavior.
94+ */
8795 #define AT_FDCWD -100 /* Special value used to indicate
8896 openat should use the current
8997 working directory. */
9098 #define AT_SYMLINK_NOFOLLOW 0x100 /* Do not follow symbolic links. */
99+#define AT_EACCESS 0x200 /* Test access permitted for
100+ effective IDs, not real IDs. */
91101 #define AT_REMOVEDIR 0x200 /* Remove directory instead of
92102 unlinking file. */
93103 #define AT_SYMLINK_FOLLOW 0x400 /* Follow symbolic links. */