To get an operable version of an O_PATH file descriptor, it is possible to use openat(fd, ".", O_DIRECTORY) for directories, but other files currently require going through open("/proc/<pid>/fd/<nr>"), which depends on a functioning procfs. This patch adds the O_EMPTYPATH flag to openat(2)/openat2(2). If passed, LOOKUP_EMPTY is set at path resolution time. Note: This implies that you cannot rely anymore on disabling procfs from being mounted (e.g. inside a container without procfs mounted and with CAP_SYS_ADMIN dropped) to prevent O_PATH fds from being re-opened read-write.
Showing the changes to include/uapi (1 of 4 files). Show all
Unified · Split
| @@ -88,6 +88,10 @@ · 87 unmodified lines | |||
| 88 | #define __O_TMPFILE 020000000 | 88 | #define __O_TMPFILE 020000000 |
| 89 | #endif | 89 | #endif |
| 90 | 90 | ||
| 91 | #ifndef O_EMPTYPATH | ||
| 92 | #define O_EMPTYPATH (1 << 26) /* allow empty path */ | ||
| 93 | #endif | ||
| 94 | |||
| 91 | /* a horrid kludge trying to make sure that this will fail on old kernels */ | 95 | /* a horrid kludge trying to make sure that this will fail on old kernels */ |
| 92 | #define O_TMPFILE (__O_TMPFILE | O_DIRECTORY) | 96 | #define O_TMPFILE (__O_TMPFILE | O_DIRECTORY) |
| 93 | 97 | ||