From: Jori Koolstra <jkoolstra@xs4all.nl>
To: NeilBrown <neil@brown.name>, NeilBrown <neilb@ownmail.net>,
Al Viro <viro@zeniv.linux.org.uk>
Cc: Aleksa Sarai <cyphar@cyphar.com>,
Christian Brauner <brauner@kernel.org>, Jan Kara <jack@suse.cz>,
Jeff Layton <jlayton@kernel.org>,
Mateusz Guzik <mjguzik@gmail.com>,
linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
Charles Mirabile <cmirabil@redhat.com>
Subject: Re: [RFC PATCH v6 7/9] vfs: add O_CREAT|O_DIRECTORY to open*(2)
Date: Sun, 14 Jun 2026 20:27:52 +0200 (CEST) [thread overview]
Message-ID: <1838729341.1691008.1781461672647@kpc.webmail.kpnmail.nl> (raw)
In-Reply-To: <178028376148.2923901.10614738518137561136@noble.neil.brown.name>
> Op 01-06-2026 05:16 CEST schreef NeilBrown <neilb@ownmail.net>:
> > +
> > +static inline umode_t o_create_mode(struct mnt_idmap *idmap,
> > + const struct inode *dir, umode_t mode, bool create_dir)
> > +{
> > + if (create_dir)
> > + return vfs_prepare_mode(idmap, dir, mode, S_IRWXUGO | S_ISVTX, 0);
> > + else
> > + return vfs_prepare_mode(idmap, dir, mode, S_IALLUGO, S_IFREG);
>
> I still don't see a justification for different permission masks.
> There should be a comment explaining why there is a difference, though
> I'm not convinced a difference is needed.
>
I just copied current semantics from vfs_mkdir() and vfs_create().
Let me add what you wrote before here for context:
> It isn't clear the purpose of this.
> In the create_dir case, shouldn't we pass S_IFDIR as the last arg: type?
>
Yes, you are correct. This is being handled separately.[1] (I know you know
that, but let me add this to provide context for other readers).
> The difference between "S_IRWXUGO | S_ISVTX" and "S_IALLUGO" is not
> immediately obvious, but the former excludes S_ISUID and S_ISGID.
> The setuid bit is meaningless on directories so there is little point in
> stripping it, but I don't object as long as the intent is documented
> here.
> The setgid bit is meaningful but vfs_prepare_mode() seems to already
> handle it correctly for directories if you pass the type as S_IFDIR.
mode_strip_sgid() is just for regular files and is a noop when passed
a S_IFDIR. So I am not quite sure what you mean.
Apparenly, mkdir(2) cannot enable the setgid bit itself. This has been the
case since the initial git commit, which contains:
+ mode &= (S_IRWXUGO|S_ISVTX);
+ error = security_inode_mkdir(dir, dentry, mode);
+ if (error)
+ return error;
+
+ DQUOT_INIT(dir);
+ error = dir->i_op->mkdir(dir, dentry, mode);
I am not sure why.
@Al, you have been around for a long time? Do you know why mkdir(2) cannot
enable the setgid bit?
> If you have a good reason to impose different handling here, that might
> be sensible, but it should be documented.
> > }
> >
> > /*
> > @@ -4379,8 +4409,12 @@ static struct dentry *atomic_open(const struct path *path, struct dentry *dentry
> >
> > file->__f_path.dentry = DENTRY_NOT_SET;
> > file->__f_path.mnt = path->mnt;
> > - error = dir->i_op->atomic_open(dir, dentry, file,
> > - open_to_namei_flags(open_flag), mode);
> > +
> > + if (O_IS_MKDIR(open_flag))
> > + error = EINVAL;
> > + else
> > + error = dir->i_op->atomic_open(dir, dentry, file,
> > + open_to_namei_flags(open_flag), mode);
> > d_lookup_done(dentry);
> > if (!error) {
> > if (file->f_mode & FMODE_OPENED) {
> > @@ -4413,6 +4447,10 @@ static struct dentry *atomic_open(const struct path *path, struct dentry *dentry
> > return dentry;
> > }
> >
> > +static inline
> > +struct dentry *vfs_mkdir_no_perm(struct mnt_idmap *, struct inode *,
> > + struct dentry *, umode_t,
> > + struct delegated_inode *);
>
> forward declaration aren't ideal... This is a new function that you
> introduced. Could you place it earlier when you introduce it?
>
I wanted to keep vfs_mkdir_no_perm() close to vfs_mkdir(). But I can
live with moving it.
Thanks,
Jori.
next prev parent reply other threads:[~2026-06-14 18:28 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-31 18:20 [RFC PATCH v6 0/9] " Jori Koolstra
2026-05-31 18:20 ` [RFC PATCH v6 1/9] fs/namei.c: make lookup_last() use trailing_slashes() Jori Koolstra
2026-06-01 2:09 ` NeilBrown
2026-05-31 18:20 ` [RFC PATCH v6 2/9] fs/namei.c: move create error && negative dentry case in lookup_open up Jori Koolstra
2026-06-01 2:16 ` NeilBrown
2026-05-31 18:20 ` [RFC PATCH v6 3/9] vfs: prepare vfs_creat|mkdir_no_perm for reuse in lookup_open() Jori Koolstra
2026-06-01 3:20 ` NeilBrown
2026-06-02 23:00 ` NeilBrown
2026-06-14 18:39 ` Jori Koolstra
2026-05-31 18:20 ` [RFC PATCH v6 4/9] vfs: lookup_open(): move setting FMODE_CREATED up when calling create() Jori Koolstra
2026-06-01 2:34 ` NeilBrown
2026-06-02 13:41 ` Christian Brauner
2026-06-03 13:19 ` Jori Koolstra
2026-05-31 18:20 ` [RFC PATCH v6 5/9] vfs: lookup_open(): move audit_inode_child() and i_op->create check to before try_break_deleg() Jori Koolstra
2026-06-01 2:56 ` NeilBrown
2026-06-01 16:27 ` Paul Moore
2026-06-14 18:36 ` Jori Koolstra
2026-05-31 18:20 ` [RFC PATCH v6 6/9] vfs: lookup_open(): use vfs_create_no_perm() Jori Koolstra
2026-05-31 18:20 ` [RFC PATCH v6 7/9] vfs: add O_CREAT|O_DIRECTORY to open*(2) Jori Koolstra
2026-06-01 3:16 ` NeilBrown
2026-06-14 18:27 ` Jori Koolstra [this message]
2026-05-31 18:20 ` [RFC PATCH v6 8/9] vfs: move O_IS_MKDIR check out atomic_open() to individual filesystems Jori Koolstra
2026-06-01 3:18 ` NeilBrown
2026-05-31 18:20 ` [RFC PATCH v6 9/9] selftest: add tests for open*(O_CREAT|O_DIRECTORY) 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=1838729341.1691008.1781461672647@kpc.webmail.kpnmail.nl \
--to=jkoolstra@xs4all.nl \
--cc=brauner@kernel.org \
--cc=cmirabil@redhat.com \
--cc=cyphar@cyphar.com \
--cc=jack@suse.cz \
--cc=jlayton@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mjguzik@gmail.com \
--cc=neil@brown.name \
--cc=neilb@ownmail.net \
--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®