From: Jori Koolstra <jkoolstra@xs4all.nl>
To: Askar Safin <safinaskar@gmail.com>
Cc: amir73il@gmail.com, brauner@kernel.org, cyphar@cyphar.com,
gregkh@linuxfoundation.org, jack@suse.cz, jlayton@kernel.org,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
neil@brown.name, shakeel.butt@linux.dev, tj@kernel.org,
viro@zeniv.linux.org.uk
Subject: Re: [PATCH v8 07/12] vfs: short-circuit MAY_WRITE access for O_DIRECTORY opens
Date: Wed, 25 Nov 2026 10:31:04 +0100 (CET) [thread overview]
Message-ID: <1709003566.2632299.1795599064030@kpc.webmail.kpnmail.nl> (raw)
In-Reply-To: <20261125062146.940336-1-safinaskar@gmail.com>
> Op 25-11-2026 01:21 EST schreef Askar Safin <safinaskar@gmail.com>:
>
>
> Jori Koolstra <jkoolstra@xs4all.nl>:
> > Requesting write access on a directory can never succeed. Rather
> > than performing a path-walk to determine whether the target is
> > actually a directory (-EISDIR) or not (-ENOTDIR), or does not exist
> > (-ENOENT), etc., we short-circuit to -ENOTDIR.
> >
> > Currently O_WRONLY for directories is only blocked in may_open(),
> > which happens after we have the inode for the target, so after any
> > create via O_CREAT|O_DIRECTORY.
> >
> > The advantage of short-circuiting is that we don't have to add even more
> > logic to lookup_open() to differentiate -EISDIR/-ENOTDIR. Also, for
> > filesystems that define ->atomic_open, handling this cannot even be done
> > at the VFS level, as we can't know ahead what the result of the lookup
> > will be.
> >
> > Suggested-by: Christian Brauner (Amutable) <brauner@kernel.org>
> > Reviewed-by: NeilBrown <neil@brown.name>
> > Signed-off-by: Jori Koolstra <jkoolstra@xs4all.nl>
> > ---
> > fs/open.c | 9 +++++++++
> > 1 file changed, 9 insertions(+)
> >
> > diff --git a/fs/open.c b/fs/open.c
> > index e43f02ff64ac..4334f30bb7ff 100644
> > --- a/fs/open.c
> > +++ b/fs/open.c
> > @@ -1343,6 +1343,15 @@ inline int build_open_flags(const struct open_how *how, struct open_flags *op)
> >
> > op->intent = flags & O_PATH ? 0 : LOOKUP_OPEN;
> >
> > + /*
> > + * Requesting write access on a directory can never succeed. Rather
> > + * than performing a path-walk to determine whether the target is
> > + * actually a directory (-EISDIR) or not (-ENOTDIR), we short-circuit
> > + * to -ENOTDIR.
> > + */
> > + if ((flags & O_DIRECTORY) && !(flags & __O_TMPFILE) && (acc_mode & MAY_WRITE))
> > + return -ENOTDIR;
> > +
>
> Please, do -EISDIR here, not -ENOTDIR. You returning error here, **because** user attempts to write to **directory**. EISDIR is natural here, ENOTDIR is not.
>
That's a fair point, and I have thought about this. The downside is that
if we return -EISDIR there, that will also be returned if you open(O_DIRECTORY)
what turns out to be a regular file. So you may then get -EISDIR for something not
a directory.
The semantics of -ENOTDIR here that I had in my mind is something like "the thing
you are trying to do can NOT be done _with_ a DIRectory." It made a bit more sense
to me (but only a bit.) Really it should be -ENOTWITHDIR or something...
> (I'm human, not LLM.)
>
Glad :)
Best,
Jori.
> --
> Askar Safin
next prev parent reply other threads:[~2026-11-25 9:31 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-24 21:35 [PATCH v8 00/12] vfs: add O_CREAT|O_DIRECTORY to open*(2) Jori Koolstra
2026-10-24 21:35 ` [PATCH v8 01/12] fs/namei.c: use trailing_slashes() Jori Koolstra
2026-10-24 21:35 ` [PATCH v8 02/12] vfs: prepare vfs_creat|mkdir_no_perm for reuse in lookup_open() Jori Koolstra
2026-10-24 21:35 ` [PATCH v8 03/12] vfs: lookup_open(): move setting FMODE_CREATED down Jori Koolstra
2026-10-24 21:35 ` [PATCH v8 04/12] vfs: move ->create check in lookup_open() to before try_break_deleg() Jori Koolstra
2026-10-24 21:35 ` [PATCH v8 05/12] vfs: lookup_open(): use vfs_create_no_perm() Jori Koolstra
2026-10-24 21:35 ` [PATCH v8 06/12] vfs: lookup_open(): lock the parent as I_MUTEX_PARENT Jori Koolstra
2026-10-24 21:35 ` [PATCH v8 07/12] vfs: short-circuit MAY_WRITE access for O_DIRECTORY opens Jori Koolstra
2026-11-25 6:21 ` Askar Safin
2026-11-25 9:31 ` Jori Koolstra [this message]
2026-11-25 9:42 ` NeilBrown
2026-10-24 21:35 ` [PATCH v8 08/12] kernfs: hold kernfs_iattr_rwsem when initializing a new inode Jori Koolstra
2026-10-24 21:35 ` [PATCH v8 09/12] vfs: add O_CREAT|O_DIRECTORY to open*(2) Jori Koolstra
2026-10-24 21:35 ` [PATCH v8 10/12] vfs: use finish_lookup() helper in __lookup_slow() and lookup_open() Jori Koolstra
2026-10-24 21:35 ` [PATCH v8 11/12] vfs: change ->create/->mkdir operations unavailable errno Jori Koolstra
2026-10-24 21:35 ` [PATCH v8 12/12] selftest: add tests for open*(O_CREAT|O_DIRECTORY) Jori Koolstra
2026-11-04 23:44 ` [PATCH v8 00/12] vfs: add O_CREAT|O_DIRECTORY to open*(2) John Ericson
2026-11-06 14:33 ` Christian Brauner
2026-11-18 16:30 ` Christian Brauner
2026-11-18 16:42 ` Shakeel Butt
2026-11-20 8:59 ` Christian Brauner
2026-11-22 21:20 ` Jori Koolstra
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=1709003566.2632299.1795599064030@kpc.webmail.kpnmail.nl \
--to=jkoolstra@xs4all.nl \
--cc=amir73il@gmail.com \
--cc=brauner@kernel.org \
--cc=cyphar@cyphar.com \
--cc=gregkh@linuxfoundation.org \
--cc=jack@suse.cz \
--cc=jlayton@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=neil@brown.name \
--cc=safinaskar@gmail.com \
--cc=shakeel.butt@linux.dev \
--cc=tj@kernel.org \
--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
all inboxes | Powered by JetHome®