From 87ed096657bc2cd06635726e4dd3a96d8664444e Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Fri, 14 Nov 2025 21:36:16 +0100 Subject: [PATCH 1/2] fs-util: simplify open_parent_at() a bit Let's refrain from specifying any access mode when opening a directory, which matches our usual style and allows us to drop one condition. --- src/basic/fs-util.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/basic/fs-util.c b/src/basic/fs-util.c index 8cbe29fc0f..893e95c3c1 100644 --- a/src/basic/fs-util.c +++ b/src/basic/fs-util.c @@ -868,10 +868,8 @@ int open_parent_at(int dir_fd, const char *path, int flags, mode_t mode) { /* Let's insist on O_DIRECTORY since the parent of a file or directory is a directory. Except if we open an * O_TMPFILE file, because in that case we are actually create a regular file below the parent directory. */ - if (FLAGS_SET(flags, O_PATH)) + if (!FLAGS_SET(flags, O_TMPFILE)) flags |= O_DIRECTORY; - else if (!FLAGS_SET(flags, O_TMPFILE)) - flags |= O_DIRECTORY|O_RDONLY; return RET_NERRNO(openat(dir_fd, parent, flags, mode)); } From 0cb7dd5b96310604fc10222b1dc3f675a772f5b9 Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Fri, 14 Nov 2025 21:32:51 +0100 Subject: [PATCH 2/2] fd-util: do not block O_TMPFILE with -EISDIR Follow-up for 7cf4f075670a81babf1501f063f6841cc4e866dd --- src/basic/fd-util.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/basic/fd-util.c b/src/basic/fd-util.c index 310f5b82b5..e0dcbcecd1 100644 --- a/src/basic/fd-util.c +++ b/src/basic/fd-util.c @@ -978,7 +978,10 @@ int fd_vet_accmode(int fd, int mode) { if (flags < 0) return -errno; - if (FLAGS_SET(flags, O_DIRECTORY)) + /* O_TMPFILE in userspace is defined with O_DIRECTORY OR'ed in, so explicitly permit it. + * + * C.f. https://elixir.bootlin.com/linux/v6.17.7/source/include/uapi/asm-generic/fcntl.h#L92 */ + if (FLAGS_SET(flags, O_DIRECTORY) && !FLAGS_SET(flags, O_TMPFILE)) return -EISDIR; if (FLAGS_SET(flags, O_PATH))