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.
Showing the changes to include/uapi (2 of 23 files). Show all
Unified · Split
| @@ -855,9 +855,11 @@ __SYSCALL(__NR_clone3, sys_clone3) · 854 unmodified lines | |||
| 855 | __SYSCALL(__NR_openat2, sys_openat2) | 855 | __SYSCALL(__NR_openat2, sys_openat2) |
| 856 | #define __NR_pidfd_getfd 438 | 856 | #define __NR_pidfd_getfd 438 |
| 857 | __SYSCALL(__NR_pidfd_getfd, sys_pidfd_getfd) | 857 | __SYSCALL(__NR_pidfd_getfd, sys_pidfd_getfd) |
| 858 | #define __NR_faccessat2 439 | ||
| 859 | __SYSCALL(__NR_faccessat2, sys_faccessat2) | ||
| 858 | 860 | ||
| 859 | #undef __NR_syscalls | 861 | #undef __NR_syscalls |
| 860 | #define __NR_syscalls 439 | 862 | #define __NR_syscalls 440 |
| 861 | 863 | ||
| 862 | /* | 864 | /* |
| 863 | * 32 bit systems traditionally used different | 865 | * 32 bit systems traditionally used different |
| @@ -84,10 +84,20 @@ · 83 unmodified lines | |||
| 84 | #define DN_ATTRIB 0x00000020 /* File changed attibutes */ | 84 | #define DN_ATTRIB 0x00000020 /* File changed attibutes */ |
| 85 | #define DN_MULTISHOT 0x80000000 /* Don't remove notifier */ | 85 | #define DN_MULTISHOT 0x80000000 /* Don't remove notifier */ |
| 86 | 86 | ||
| 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 | */ | ||
| 87 | #define AT_FDCWD -100 /* Special value used to indicate | 95 | #define AT_FDCWD -100 /* Special value used to indicate |
| 88 | openat should use the current | 96 | openat should use the current |
| 89 | working directory. */ | 97 | working directory. */ |
| 90 | #define AT_SYMLINK_NOFOLLOW 0x100 /* Do not follow symbolic links. */ | 98 | #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. */ | ||
| 91 | #define AT_REMOVEDIR 0x200 /* Remove directory instead of | 101 | #define AT_REMOVEDIR 0x200 /* Remove directory instead of |
| 92 | unlinking file. */ | 102 | unlinking file. */ |
| 93 | #define AT_SYMLINK_FOLLOW 0x400 /* Follow symbolic links. */ | 103 | #define AT_SYMLINK_FOLLOW 0x400 /* Follow symbolic links. */ |