History

vfs: add O_EMPTYPATH to openat(2)/openat2(2)

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.

Jori Koolstra committed 6 months ago

Commit 31cf44e1 parent 3e0be8c4 files · +10 −4Browse files

Showing the changes to include/uapi (1 of 4 files). Show all

Unified · Split

include/uapi/asm-generic/fcntl.h+4−0
@@ -88,6 +88,10 @@ · 87 unmodified lines
8888 #define __O_TMPFILE 020000000
8989 #endif
9090
91+#ifndef O_EMPTYPATH
92+#define O_EMPTYPATH (1 << 26) /* allow empty path */
93+#endif
94+
9195 /* a horrid kludge trying to make sure that this will fail on old kernels */
9296 #define O_TMPFILE (__O_TMPFILE | O_DIRECTORY)
9397