[RFC PATCH v4 0/2] vfs: add O_CREAT|O_DIRECTORY to open*(2)
From: Jori Koolstra
Date: Mon May 18 2026 - 12:55:15 EST
This series implements new semantics for the O_CREAT|O_DIRECTORY flag
combination for open*(2): perform a mkdir and open the resulting
directory; return a pinning fd (which mkdir does not).
Feedback by Christian Brauner and Aleksa Sarai on the v2 rfc of this
patch was to not introduce a new syscall (mkdirat2) but implement this
functionality as O_CREAT|O_DIRECTORY in open*(2). I had some very silly
bugs that syzbot alerted me of in v3, so here is v4...
Three comments from me upfront:
- This patch just EINVAL bans O_CREAT|O_DIRECTORY for filesystems that
define atomic_open(). I figure it is better to (dis)allow on a fs per
fs basis. So feedback per filesystem on what is the appropriate course
of action on receiving O_CREAT|O_DIRECTORY would be very welcome.
- If we create a regular file with mknod, before creation
security_path_mknod() is called, and after creation
security_path_post_mknod(). If we create a regular file using O_CREAT
(and this is also pre-patch) only security_path_mknod() is called. Is
this the correct behaviour?
- open_last_lookups() locks the parent inode like like:
inode_lock(dir->d_inode);
should this perhaps be
inode_lock_nested(dir, I_MUTEX_PARENT);
to stay consistent with the start_dirop() path that is used by
filename_create() for instance in mknod(2)? I get that we are only
locking one inode here at most, so it does not really matter, but
now one regular file create path does set the lockdep and the other
does not.
Jori Koolstra (2):
vfs: add O_CREAT|O_DIRECTORY to open*(2)
selftest: add tests for open*(O_CREAT|O_DIRECTORY)
fs/namei.c | 180 +++++++++++-----
fs/open.c | 25 ++-
include/uapi/asm-generic/fcntl.h | 2 +
.../testing/selftests/filesystems/.gitignore | 1 +
tools/testing/selftests/filesystems/Makefile | 4 +-
tools/testing/selftests/filesystems/fclog.c | 1 +
.../filesystems/open_o_creat_o_dir.c | 200 ++++++++++++++++++
7 files changed, 342 insertions(+), 71 deletions(-)
create mode 100644 tools/testing/selftests/filesystems/open_o_creat_o_dir.c
--
2.54.0