From: Pedro Falcato <pfalcato@suse.de>
To: Jori Koolstra <jkoolstra@xs4all.nl>
Cc: Aleksa Sarai <aleksa@amutable.com>,
Jeff Layton <jlayton@kernel.org>,
Christian Brauner <brauner@kernel.org>,
Al Viro <viro@zeniv.linux.org.uk>, NeilBrown <neil@brown.name>,
Amir Goldstein <amir73il@gmail.com>, Jan Kara <jack@suse.cz>,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 09/14] vfs: add O_CREAT|O_DIRECTORY to open*(2)
Date: Tue, 7 Jul 2026 14:55:35 +0100 [thread overview]
Message-ID: <akz_Ik8_eTnXav1H@pedro-suse> (raw)
In-Reply-To: <1464441345.181098.1783418805206@kpc.webmail.kpnmail.nl>
On Tue, Jul 07, 2026 at 12:06:44PM +0200, Jori Koolstra wrote:
> Hi Pedro,
>
> > Op 07-07-2026 10:35 CEST schreef Pedro Falcato <pfalcato@suse.de>:
> >
> > Ok so I genuinely don't see how users are supposed to use O_CREAT | O_DIRECTORY.
> > Lets think about the portability here. This is undefined by POSIX (meaning you
> > cannot rely on a O_CREAT | O_DIRECTORY having particular semantics). FreeBSD
> > and NetBSD each have different semantics (my investigation stopped there
> > ~3 years ago; I vaguely remember that macOS/Darwin does not/did not support
> > O_DIRECTORY. I don't remember what's the deal with OpenBSD/Solaris/Illumos
> > here).
> >
> > So, essentially you can't rely on _any_ common behavior between platforms.
> > Ok. Now, you may say "it's 2026 lol who cares about BSD". So lets look at Linux:
> > - Linux for most of its lifetime had "return open directory, or create
> > a regular file".
> > - It later had the above, with the added caveat that it always returned
> > ENOTDIR.
> > - In 2023 I then found the bug and Christian changed it to always return
> > EINVAL on that combination.
> >
> > Ok. So Linux had 3 behaviors and 2 of them do not make any kind of sense. But
> > that's fine, we return EINVAL now. Except that the other behaviors existed.
> >
> > So, lets say this feature lands as-is. If you're writing something *for Linux*,
> > you have to contend with the previous *3 behaviors* for a grand total of 4
> > behaviors. Including bizarre runtime tests, lest you are running on something
> > pre-6.4 (system calls can be similarly problematic, but at least there its a
> > simple ENOSYS test).
> >
>
> But isn't this a problem with all UAPI design? You introduce a new feature that
> does not exist on old kernels, then userspace can use that feature but must
> provide fallback behaviors for any older kernel that the userspace program wants
> to support. Ideally, this is abstracted away by some library. Then, at some point
> this library raises its minimal supported kernel version bar, and it can clean-up
> the now obsolete fallback code.
Correct, but usually most new UAPIs have very simple checks:
if (syscall(SYS_ponies) < 0 && errno == ENOSYS) {
fallback();
}
or
if (ponies(NEW_FLAG) < 0 && errno == EINVAL) {
fallback();
}
(in fact, many system calls out there can even be silently emulated by the
libc if need be; this one can't, but that's besides the point)
My problem isn't with adding a new uapi, it's that the flag combination has
so horrifically overloaded with weird semantics that it's pretty non-trivial
to find out conclusively whether or not you have the feature, across the recent
lifetime of Linux. I'm not even concerned with repurposing the flags because the
old semantics were so obviously BS.
>
> I am fairly positive for instance that libpathrs would like to use O_CREAT | O_DIRECTORY,
> but it is not going to demand kernel > 7.x anytime soon.
so it will handroll its own tests for the feature which may or may not be
wrong.
>
>
> > If you're writing something that wants to be portable, or that intends to
> > standardize on something, you have some 5 different behaviors all across
> > the FOSS UNIX landscape, not considering everything else. It's also something
> > that will, FWIW, probably never be included in POSIX because no one can agree
> > on the semantics here.
> >
>
> I have no idea how POSIX standardizes things. Does a committee get together and
> revisit old syscalls every now and then?
In theory: System X thinks up a useful feature, systems Y, Z think it's
useful and also implement it. Once there is some sort of consensus, it's
added to POSIX. Remaining systems implement it.
(this is how stuff like O_DIRECTORY and OFD locks landed from Linux to POSIX to
every other UNIX-like)
>
> But yeah, I think POSIX compliance isn't something we are really doing anymore.
The vast majority of the kernel is compliant, and a great portion of software
uses mostly/only portable interfaces.
> Afaik there's nothing in POSIX about openat2(2) either, and we definitely wish
> people would move to that instead of keep relying on open(2) (or even better,
> use libpathrs!)
Hah, good luck! :)
>
> > TL;DR I don't see, given the reasons above, how users are supposed to use
> > this without it being a total minefield.
> >
> > If you're intent on the open() path, I would suggest that perhaps openat2()
> > would be a nice alternative, although definitely not as beautiful as
> > open(O_CREAT | O_DIRECTORY).
> >
>
> Christian told me (somewhere on this list) that at LSFMMBPF all vfs maintainers
> agreed on the O_CREAT | O_DIRECTORY direction. It allows to use all the neat
> options from openat2(2) at the cost of a bit of multiplexing in lookup_open().
> The question remains whether we also want the other things like mknodat_fd().
FWIW, thinking about this a bit more, it's possible that openat2() could serve
as a stricter check for the UAPI in open() in general. Making this less
footgunny to use.
>
> > Just my 2c. And I feel horrible typing this out because you clearly spent
> > a great amount of time and effort between v2 and v3 as you redid this :/
> >
>
> It's been a lot of work, yes :)
>
> But luckily it has allowed me to study path resolution and the open()/mkdir()/etc.
> syscalls in a fun and educative way.
Yay!
--
Pedro
next prev parent reply other threads:[~2026-07-07 13:55 UTC|newest]
Thread overview: 49+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-04 16:41 [PATCH v3 00/14] vfs: add O_CREAT|O_DIRECTORY to open*(2) Jori Koolstra
2026-07-04 16:41 ` [PATCH v3 01/14] fs/namei.c: use trailing_slashes() Jori Koolstra
2026-07-06 3:56 ` NeilBrown
2026-07-06 7:29 ` David Laight
2026-07-06 20:55 ` Jori Koolstra
2026-07-07 7:42 ` David Laight
2026-07-07 10:51 ` Christian Brauner
2026-07-04 16:41 ` [PATCH v3 02/14] vfs: move create error && negative dentry case in lookup_open() up Jori Koolstra
2026-07-04 16:41 ` [PATCH v3 03/14] vfs: prepare vfs_creat|mkdir_no_perm for reuse in lookup_open() Jori Koolstra
2026-07-07 10:51 ` Christian Brauner
2026-07-04 16:41 ` [PATCH v3 04/14] vfs: call audit_inode_child() in lookup_open() on failure too Jori Koolstra
2026-07-06 5:33 ` NeilBrown
2026-07-06 21:20 ` Jori Koolstra
2026-07-06 23:02 ` NeilBrown
2026-07-07 10:51 ` Christian Brauner
2026-07-04 16:41 ` [PATCH v3 05/14] fs/namei.c: update docstring of atomic_open() Jori Koolstra
2026-07-06 5:36 ` NeilBrown
2026-07-07 10:51 ` Christian Brauner
2026-07-04 16:41 ` [PATCH v3 06/14] vfs: lookup_open(): move setting FMODE_CREATED down Jori Koolstra
2026-07-04 16:41 ` [PATCH v3 07/14] vfs: move ->create check in lookup_open() to before try_break_deleg() Jori Koolstra
2026-07-06 5:37 ` NeilBrown
2026-07-07 10:51 ` Christian Brauner
2026-07-04 16:41 ` [PATCH v3 08/14] vfs: lookup_open(): use vfs_create_no_perm() Jori Koolstra
2026-07-06 5:38 ` NeilBrown
2026-07-07 10:51 ` Christian Brauner
2026-07-04 16:41 ` [PATCH v3 09/14] vfs: add O_CREAT|O_DIRECTORY to open*(2) Jori Koolstra
2026-07-06 5:46 ` NeilBrown
2026-07-07 8:35 ` Pedro Falcato
2026-07-07 10:04 ` Christian Brauner
2026-07-07 13:04 ` Pedro Falcato
2026-07-07 13:30 ` Christian Brauner
2026-07-07 10:06 ` Jori Koolstra
2026-07-07 13:55 ` Pedro Falcato [this message]
2026-07-07 14:18 ` Jori Koolstra
2026-07-07 10:51 ` Christian Brauner
2026-07-04 16:41 ` [PATCH v3 10/14] vfs: move O_IS_MKDIR check from lookup_open() into individual filesystems Jori Koolstra
2026-07-06 5:50 ` NeilBrown
2026-07-07 10:51 ` Christian Brauner
2026-07-04 16:41 ` [PATCH v3 11/14] vfs: refuse O_CREAT for directories through a dangling symlink Jori Koolstra
2026-07-06 5:51 ` NeilBrown
2026-07-04 16:41 ` [PATCH v3 12/14] vfs: short-circuit MAY_WRITE access for O_DIRECTORY opens Jori Koolstra
2026-07-06 5:51 ` NeilBrown
2026-07-04 16:41 ` [PATCH v3 13/14] selftest: fix headers in fclog.c Jori Koolstra
2026-07-06 5:57 ` NeilBrown
2026-07-06 21:07 ` Jori Koolstra
2026-07-07 10:51 ` Christian Brauner
2026-07-04 16:41 ` [PATCH v3 14/14] selftest: add tests for open*(O_CREAT|O_DIRECTORY) Jori Koolstra
2026-07-07 10:51 ` Christian Brauner
2026-07-07 10:51 ` [PATCH v3 00/14] vfs: add O_CREAT|O_DIRECTORY to open*(2) Christian Brauner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=akz_Ik8_eTnXav1H@pedro-suse \
--to=pfalcato@suse.de \
--cc=aleksa@amutable.com \
--cc=amir73il@gmail.com \
--cc=brauner@kernel.org \
--cc=jack@suse.cz \
--cc=jkoolstra@xs4all.nl \
--cc=jlayton@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=neil@brown.name \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox