mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jan Kara <jack@suse.cz>
To: Jori Koolstra <jkoolstra@xs4all.nl>
Cc: Christian Brauner <brauner@kernel.org>,
	NeilBrown <neil@brown.name>,
	 Alexander Viro <viro@zeniv.linux.org.uk>,
	Jan Kara <jack@suse.cz>,
	linux-fsdevel@vger.kernel.org,  linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 01/31] vfs: pass S_IFDIR mode to vfs_prepare_mode()
Date: Wed, 1 Jul 2026 12:08:53 +0200	[thread overview]
Message-ID: <mr3sedjwzhc2khnx43qlhq7nddzg4yfee66ckgd2mjtn4jfemw@w3gqbr76pnby> (raw)
In-Reply-To: <20260630105400.68459-2-jkoolstra@xs4all.nl>

On Tue 30-06-26 12:53:30, Jori Koolstra wrote:
> There is a comment in vfs_prepare_mode() that says:
> 
>   Note that it's currently valid for @type to be 0 if a directory is
>   created. Filesystems raise that flag individually and we need to check
>   whether each filesystem can deal with receiving S_IFDIR from the vfs
>   before we enforce a non-zero type.
> 
> It is safe to do this clean-up except that three filesystems (fuse,
> cifs, and coda) forward the mkdir @mode unchanged to something outside
> the kernel. Mask S_IFDIR back out in coda_mkdir(), fuse_mkdir() and
> cifs_mkdir() so that what is sent outside the kernel is unchanged.
> Their maintainers can drop the mask once they have confirmed it is safe.
> 
> Assisted-by: Claude Opus 4.8 (1M context)
> Signed-off-by: Jori Koolstra <jkoolstra@xs4all.nl>

Looks good. Feel free to add:

Reviewed-by: Jan Kara <jack@suse.cz>

								Honza

> ---
>  fs/coda/dir.c         | 7 ++++++-
>  fs/fuse/dir.c         | 8 ++++++++
>  fs/namei.c            | 7 +------
>  fs/smb/client/inode.c | 7 +++++++
>  4 files changed, 22 insertions(+), 7 deletions(-)
> 
> diff --git a/fs/coda/dir.c b/fs/coda/dir.c
> index 835eb7fdfdad..9ad4d217c8b6 100644
> --- a/fs/coda/dir.c
> +++ b/fs/coda/dir.c
> @@ -179,7 +179,12 @@ static struct dentry *coda_mkdir(struct mnt_idmap *idmap, struct inode *dir,
>  	if (is_root_inode(dir) && coda_iscontrol(name, len))
>  		return ERR_PTR(-EPERM);
>  
> -	attrs.va_mode = mode;
> +	/*
> +	 * vfs_mkdir() now passes S_IFDIR in @mode, but @mode is forwarded
> +	 * verbatim to userspace, which has only ever been given the permission
> +	 * bits. Strip the type bit until venus is known to cope with it.
> +	 */
> +	attrs.va_mode = mode & ~S_IFDIR;
>  	error = venus_mkdir(dir->i_sb, coda_i2f(dir),
>  			       name, len, &newfid, &attrs);
>  	if (error)
> diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
> index 0e2a1039fa43..7decbe4ea48a 100644
> --- a/fs/fuse/dir.c
> +++ b/fs/fuse/dir.c
> @@ -1117,6 +1117,14 @@ static struct dentry *fuse_mkdir(struct mnt_idmap *idmap, struct inode *dir,
>  	if (!fm->fc->dont_mask)
>  		mode &= ~current_umask();
>  
> +	/*
> +	 * vfs_mkdir() now passes S_IFDIR in @mode, but @mode is forwarded
> +	 * verbatim to the userspace server which has only ever been given the
> +	 * permission bits. Strip the type bit until the protocol is known to
> +	 * cope with it.
> +	 */
> +	mode &= ~S_IFDIR;
> +
>  	memset(&inarg, 0, sizeof(inarg));
>  	inarg.mode = mode;
>  	inarg.umask = current_umask();
> diff --git a/fs/namei.c b/fs/namei.c
> index 5cc9f0f466b8..6554803d6903 100644
> --- a/fs/namei.c
> +++ b/fs/namei.c
> @@ -4140,11 +4140,6 @@ EXPORT_SYMBOL(end_renaming);
>   * after setgid stripping allows the same ordering for both non-POSIX ACL and
>   * POSIX ACL supporting filesystems.
>   *
> - * Note that it's currently valid for @type to be 0 if a directory is created.
> - * Filesystems raise that flag individually and we need to check whether each
> - * filesystem can deal with receiving S_IFDIR from the vfs before we enforce a
> - * non-zero type.
> - *
>   * Returns: mode to be passed to the filesystem
>   */
>  static inline umode_t vfs_prepare_mode(struct mnt_idmap *idmap,
> @@ -5256,7 +5251,7 @@ struct dentry *vfs_mkdir(struct mnt_idmap *idmap, struct inode *dir,
>  	if (!dir->i_op->mkdir)
>  		goto err;
>  
> -	mode = vfs_prepare_mode(idmap, dir, mode, S_IRWXUGO | S_ISVTX, 0);
> +	mode = vfs_prepare_mode(idmap, dir, mode, S_IRWXUGO | S_ISVTX, S_IFDIR);
>  	error = security_inode_mkdir(dir, dentry, mode);
>  	if (error)
>  		goto err;
> diff --git a/fs/smb/client/inode.c b/fs/smb/client/inode.c
> index 1dbcfd163ff0..369dfd56c1e6 100644
> --- a/fs/smb/client/inode.c
> +++ b/fs/smb/client/inode.c
> @@ -2282,6 +2282,13 @@ struct dentry *cifs_mkdir(struct mnt_idmap *idmap, struct inode *inode,
>  	const char *full_path;
>  	void *page;
>  
> +	/*
> +	 * vfs_mkdir() now passes S_IFDIR in @mode, but @mode is forwarded
> +	 * verbatim to the server and in the past only contained permission
> +	 * bits. Strip the type bit until SMB is verified to deal with it.
> +	 */
> +	mode &= ~S_IFDIR;
> +
>  	cifs_dbg(FYI, "In cifs_mkdir, mode = %04ho inode = 0x%p\n",
>  		 mode, inode);
>  
> -- 
> 2.54.0
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

  reply	other threads:[~2026-07-01 10:08 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-30 10:53 [PATCH v2 00/31] " Jori Koolstra
2026-06-30 10:53 ` [PATCH v2 01/31] " Jori Koolstra
2026-07-01 10:08   ` Jan Kara [this message]
2026-06-30 10:53 ` [PATCH v2 02/31] 9p: drop redundant S_IFDIR from mkdir Jori Koolstra
2026-06-30 10:53 ` [PATCH v2 03/31] affs: " Jori Koolstra
2026-06-30 10:53 ` [PATCH v2 04/31] afs: " Jori Koolstra
2026-06-30 10:53 ` [PATCH v2 05/31] autofs: " Jori Koolstra
2026-06-30 10:53 ` [PATCH v2 06/31] btrfs: " Jori Koolstra
2026-06-30 10:53 ` [PATCH v2 07/31] ceph: " Jori Koolstra
2026-06-30 10:53 ` [PATCH v2 08/31] ext2: " Jori Koolstra
2026-07-01 10:09   ` Jan Kara
2026-06-30 10:53 ` [PATCH v2 09/31] ext4: " Jori Koolstra
2026-07-01 10:09   ` Jan Kara
2026-06-30 10:53 ` [PATCH v2 10/31] f2fs: " Jori Koolstra
2026-06-30 10:53 ` [PATCH v2 11/31] gfs2: " Jori Koolstra
2026-06-30 10:53 ` [PATCH v2 12/31] hfs: " Jori Koolstra
2026-06-30 10:53 ` [PATCH v2 13/31] hfsplus: " Jori Koolstra
2026-06-30 10:53 ` [PATCH v2 14/31] hpfs: " Jori Koolstra
2026-06-30 10:53 ` [PATCH v2 15/31] hugetlbfs: " Jori Koolstra
2026-06-30 10:53 ` [PATCH v2 16/31] jffs2: " Jori Koolstra
2026-06-30 10:53 ` [PATCH v2 17/31] jfs: " Jori Koolstra
2026-06-30 10:53 ` [PATCH v2 18/31] minix: " Jori Koolstra
2026-07-01 10:09   ` Jan Kara
2026-06-30 10:53 ` [PATCH v2 19/31] nilfs2: " Jori Koolstra
2026-06-30 10:53 ` [PATCH v2 20/31] ntfs3: " Jori Koolstra
2026-06-30 10:53 ` [PATCH v2 21/31] ocfs2: " Jori Koolstra
2026-07-01 10:12   ` Jan Kara
2026-06-30 10:53 ` [PATCH v2 22/31] ocfs2: dlmfs: " Jori Koolstra
2026-07-01 10:13   ` Jan Kara
2026-06-30 10:53 ` [PATCH v2 23/31] omfs: " Jori Koolstra
2026-06-30 10:53 ` [PATCH v2 24/31] orangefs: " Jori Koolstra
2026-06-30 10:53 ` [PATCH v2 25/31] ramfs: " Jori Koolstra
2026-07-01 10:10   ` Jan Kara
2026-06-30 10:53 ` [PATCH v2 26/31] udf: " Jori Koolstra
2026-07-01 10:10   ` Jan Kara
2026-06-30 10:53 ` [PATCH v2 27/31] ufs: " Jori Koolstra
2026-06-30 10:53 ` [PATCH v2 28/31] nfs: " Jori Koolstra
2026-06-30 10:53 ` [PATCH v2 29/31] ubifs: " Jori Koolstra
2026-06-30 10:53 ` [PATCH v2 30/31] xfs: " Jori Koolstra
2026-06-30 10:54 ` [PATCH v2 31/31] ntfs: " Jori Koolstra
2026-06-30 22:37 ` [PATCH v2 00/31] vfs: pass S_IFDIR mode to vfs_prepare_mode() NeilBrown
2026-07-01 11:04   ` Jori Koolstra
2026-07-01 10:51 ` Christian Brauner
2026-07-01 11:07   ` Jori Koolstra
2026-07-01 12:42     ` 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=mr3sedjwzhc2khnx43qlhq7nddzg4yfee66ckgd2mjtn4jfemw@w3gqbr76pnby \
    --to=jack@suse.cz \
    --cc=brauner@kernel.org \
    --cc=jkoolstra@xs4all.nl \
    --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