Skip to content

Commit

Permalink
fs: port ->create() to pass mnt_idmap
Browse files Browse the repository at this point in the history
Convert to struct mnt_idmap.

Last cycle we merged the necessary infrastructure in
256c8ae ("fs: introduce dedicated idmap type for mounts").
This is just the conversion to struct mnt_idmap.

Currently we still pass around the plain namespace that was attached to a
mount. This is in general pretty convenient but it makes it easy to
conflate namespaces that are relevant on the filesystem with namespaces
that are relevent on the mount level. Especially for non-vfs developers
without detailed knowledge in this area this can be a potential source for
bugs.

Once the conversion to struct mnt_idmap is done all helpers down to the
really low-level helpers will take a struct mnt_idmap argument instead of
two namespace arguments. This way it becomes impossible to conflate the two
eliminating the possibility of any bugs. All of the vfs and all filesystems
only operate on struct mnt_idmap.

Acked-by: Dave Chinner <[email protected]>
Reviewed-by: Christoph Hellwig <[email protected]>
Signed-off-by: Christian Brauner (Microsoft) <[email protected]>
  • Loading branch information
brauner committed Jan 19, 2023
1 parent b74d24f commit 6c960e6
Show file tree
Hide file tree
Showing 54 changed files with 71 additions and 62 deletions.
2 changes: 1 addition & 1 deletion Documentation/filesystems/locking.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ inode_operations

prototypes::

int (*create) (struct inode *,struct dentry *,umode_t, bool);
int (*create) (struct mnt_idmap *, struct inode *,struct dentry *,umode_t, bool);
struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
int (*link) (struct dentry *,struct inode *,struct dentry *);
int (*unlink) (struct inode *,struct dentry *);
Expand Down
2 changes: 1 addition & 1 deletion Documentation/filesystems/vfs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ As of kernel 2.6.22, the following members are defined:
.. code-block:: c
struct inode_operations {
int (*create) (struct user_namespace *, struct inode *,struct dentry *, umode_t, bool);
int (*create) (struct mnt_idmap *, struct inode *,struct dentry *, umode_t, bool);
struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
int (*link) (struct dentry *,struct inode *,struct dentry *);
int (*unlink) (struct inode *,struct dentry *);
Expand Down
4 changes: 2 additions & 2 deletions fs/9p/vfs_inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ v9fs_create(struct v9fs_session_info *v9ses, struct inode *dir,

/**
* v9fs_vfs_create - VFS hook to create a regular file
* @mnt_userns: The user namespace of the mount
* @idmap: idmap of the mount
* @dir: The parent directory
* @dentry: The name of file to be created
* @mode: The UNIX file mode to set
Expand All @@ -684,7 +684,7 @@ v9fs_create(struct v9fs_session_info *v9ses, struct inode *dir,
*/

static int
v9fs_vfs_create(struct user_namespace *mnt_userns, struct inode *dir,
v9fs_vfs_create(struct mnt_idmap *idmap, struct inode *dir,
struct dentry *dentry, umode_t mode, bool excl)
{
struct v9fs_session_info *v9ses = v9fs_inode2v9ses(dir);
Expand Down
5 changes: 3 additions & 2 deletions fs/9p/vfs_inode_dotl.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,17 +211,18 @@ int v9fs_open_to_dotl_flags(int flags)

/**
* v9fs_vfs_create_dotl - VFS hook to create files for 9P2000.L protocol.
* @mnt_userns: The user namespace of the mount
* @idmap: The user namespace of the mount
* @dir: directory inode that is being created
* @dentry: dentry that is being deleted
* @omode: create permissions
* @excl: True if the file must not yet exist
*
*/
static int
v9fs_vfs_create_dotl(struct user_namespace *mnt_userns, struct inode *dir,
v9fs_vfs_create_dotl(struct mnt_idmap *idmap, struct inode *dir,
struct dentry *dentry, umode_t omode, bool excl)
{
struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
return v9fs_vfs_mknod_dotl(mnt_userns, dir, dentry, omode, 0);
}

Expand Down
2 changes: 1 addition & 1 deletion fs/affs/affs.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ extern const struct export_operations affs_export_ops;
extern int affs_hash_name(struct super_block *sb, const u8 *name, unsigned int len);
extern struct dentry *affs_lookup(struct inode *dir, struct dentry *dentry, unsigned int);
extern int affs_unlink(struct inode *dir, struct dentry *dentry);
extern int affs_create(struct user_namespace *mnt_userns, struct inode *dir,
extern int affs_create(struct mnt_idmap *idmap, struct inode *dir,
struct dentry *dentry, umode_t mode, bool);
extern int affs_mkdir(struct user_namespace *mnt_userns, struct inode *dir,
struct dentry *dentry, umode_t mode);
Expand Down
2 changes: 1 addition & 1 deletion fs/affs/namei.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ affs_unlink(struct inode *dir, struct dentry *dentry)
}

int
affs_create(struct user_namespace *mnt_userns, struct inode *dir,
affs_create(struct mnt_idmap *idmap, struct inode *dir,
struct dentry *dentry, umode_t mode, bool excl)
{
struct super_block *sb = dir->i_sb;
Expand Down
4 changes: 2 additions & 2 deletions fs/afs/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ static bool afs_lookup_one_filldir(struct dir_context *ctx, const char *name, in
loff_t fpos, u64 ino, unsigned dtype);
static bool afs_lookup_filldir(struct dir_context *ctx, const char *name, int nlen,
loff_t fpos, u64 ino, unsigned dtype);
static int afs_create(struct user_namespace *mnt_userns, struct inode *dir,
static int afs_create(struct mnt_idmap *idmap, struct inode *dir,
struct dentry *dentry, umode_t mode, bool excl);
static int afs_mkdir(struct user_namespace *mnt_userns, struct inode *dir,
struct dentry *dentry, umode_t mode);
Expand Down Expand Up @@ -1630,7 +1630,7 @@ static const struct afs_operation_ops afs_create_operation = {
/*
* create a regular file on an AFS filesystem
*/
static int afs_create(struct user_namespace *mnt_userns, struct inode *dir,
static int afs_create(struct mnt_idmap *idmap, struct inode *dir,
struct dentry *dentry, umode_t mode, bool excl)
{
struct afs_operation *op;
Expand Down
2 changes: 1 addition & 1 deletion fs/bad_inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ static const struct file_operations bad_file_ops =
.open = bad_file_open,
};

static int bad_inode_create(struct user_namespace *mnt_userns,
static int bad_inode_create(struct mnt_idmap *idmap,
struct inode *dir, struct dentry *dentry,
umode_t mode, bool excl)
{
Expand Down
2 changes: 1 addition & 1 deletion fs/bfs/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const struct file_operations bfs_dir_operations = {
.llseek = generic_file_llseek,
};

static int bfs_create(struct user_namespace *mnt_userns, struct inode *dir,
static int bfs_create(struct mnt_idmap *idmap, struct inode *dir,
struct dentry *dentry, umode_t mode, bool excl)
{
int err;
Expand Down
3 changes: 2 additions & 1 deletion fs/btrfs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -6739,9 +6739,10 @@ static int btrfs_mknod(struct user_namespace *mnt_userns, struct inode *dir,
return btrfs_create_common(dir, dentry, inode);
}

static int btrfs_create(struct user_namespace *mnt_userns, struct inode *dir,
static int btrfs_create(struct mnt_idmap *idmap, struct inode *dir,
struct dentry *dentry, umode_t mode, bool excl)
{
struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
struct inode *inode;

inode = new_inode(dir->i_sb);
Expand Down
3 changes: 2 additions & 1 deletion fs/ceph/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -905,9 +905,10 @@ static int ceph_mknod(struct user_namespace *mnt_userns, struct inode *dir,
return err;
}

static int ceph_create(struct user_namespace *mnt_userns, struct inode *dir,
static int ceph_create(struct mnt_idmap *idmap, struct inode *dir,
struct dentry *dentry, umode_t mode, bool excl)
{
struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
return ceph_mknod(mnt_userns, dir, dentry, mode, 0);
}

Expand Down
2 changes: 1 addition & 1 deletion fs/cifs/cifsfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ extern void cifs_sb_deactive(struct super_block *sb);
/* Functions related to inodes */
extern const struct inode_operations cifs_dir_inode_ops;
extern struct inode *cifs_root_iget(struct super_block *);
extern int cifs_create(struct user_namespace *, struct inode *,
extern int cifs_create(struct mnt_idmap *, struct inode *,
struct dentry *, umode_t, bool excl);
extern int cifs_atomic_open(struct inode *, struct dentry *,
struct file *, unsigned, umode_t);
Expand Down
2 changes: 1 addition & 1 deletion fs/cifs/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ cifs_atomic_open(struct inode *inode, struct dentry *direntry,
return rc;
}

int cifs_create(struct user_namespace *mnt_userns, struct inode *inode,
int cifs_create(struct mnt_idmap *idmap, struct inode *inode,
struct dentry *direntry, umode_t mode, bool excl)
{
int rc;
Expand Down
2 changes: 1 addition & 1 deletion fs/coda/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ static inline void coda_dir_drop_nlink(struct inode *dir)
}

/* creation routines: create, mknod, mkdir, link, symlink */
static int coda_create(struct user_namespace *mnt_userns, struct inode *dir,
static int coda_create(struct mnt_idmap *idmap, struct inode *dir,
struct dentry *de, umode_t mode, bool excl)
{
int error;
Expand Down
2 changes: 1 addition & 1 deletion fs/ecryptfs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ int ecryptfs_initialize_file(struct dentry *ecryptfs_dentry,
* Returns zero on success; non-zero on error condition
*/
static int
ecryptfs_create(struct user_namespace *mnt_userns,
ecryptfs_create(struct mnt_idmap *idmap,
struct inode *directory_inode, struct dentry *ecryptfs_dentry,
umode_t mode, bool excl)
{
Expand Down
2 changes: 1 addition & 1 deletion fs/efivarfs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ bool efivarfs_valid_name(const char *str, int len)
return uuid_is_valid(s);
}

static int efivarfs_create(struct user_namespace *mnt_userns, struct inode *dir,
static int efivarfs_create(struct mnt_idmap *idmap, struct inode *dir,
struct dentry *dentry, umode_t mode, bool excl)
{
struct inode *inode = NULL;
Expand Down
2 changes: 1 addition & 1 deletion fs/exfat/namei.c
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ static int exfat_add_entry(struct inode *inode, const char *path,
return ret;
}

static int exfat_create(struct user_namespace *mnt_userns, struct inode *dir,
static int exfat_create(struct mnt_idmap *idmap, struct inode *dir,
struct dentry *dentry, umode_t mode, bool excl)
{
struct super_block *sb = dir->i_sb;
Expand Down
2 changes: 1 addition & 1 deletion fs/ext2/namei.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ struct dentry *ext2_get_parent(struct dentry *child)
* If the create succeeds, we fill in the inode information
* with d_instantiate().
*/
static int ext2_create (struct user_namespace * mnt_userns,
static int ext2_create (struct mnt_idmap * idmap,
struct inode * dir, struct dentry * dentry,
umode_t mode, bool excl)
{
Expand Down
3 changes: 2 additions & 1 deletion fs/ext4/namei.c
Original file line number Diff line number Diff line change
Expand Up @@ -2792,9 +2792,10 @@ static int ext4_add_nondir(handle_t *handle,
* If the create succeeds, we fill in the inode information
* with d_instantiate().
*/
static int ext4_create(struct user_namespace *mnt_userns, struct inode *dir,
static int ext4_create(struct mnt_idmap *idmap, struct inode *dir,
struct dentry *dentry, umode_t mode, bool excl)
{
struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
handle_t *handle;
struct inode *inode;
int err, credits, retries = 0;
Expand Down
3 changes: 2 additions & 1 deletion fs/f2fs/namei.c
Original file line number Diff line number Diff line change
Expand Up @@ -333,9 +333,10 @@ static struct inode *f2fs_new_inode(struct user_namespace *mnt_userns,
return ERR_PTR(err);
}

static int f2fs_create(struct user_namespace *mnt_userns, struct inode *dir,
static int f2fs_create(struct mnt_idmap *idmap, struct inode *dir,
struct dentry *dentry, umode_t mode, bool excl)
{
struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
struct inode *inode;
nid_t ino = 0;
Expand Down
2 changes: 1 addition & 1 deletion fs/fat/namei_msdos.c
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ static int msdos_add_entry(struct inode *dir, const unsigned char *name,
}

/***** Create a file */
static int msdos_create(struct user_namespace *mnt_userns, struct inode *dir,
static int msdos_create(struct mnt_idmap *idmap, struct inode *dir,
struct dentry *dentry, umode_t mode, bool excl)
{
struct super_block *sb = dir->i_sb;
Expand Down
2 changes: 1 addition & 1 deletion fs/fat/namei_vfat.c
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,7 @@ static struct dentry *vfat_lookup(struct inode *dir, struct dentry *dentry,
return ERR_PTR(err);
}

static int vfat_create(struct user_namespace *mnt_userns, struct inode *dir,
static int vfat_create(struct mnt_idmap *idmap, struct inode *dir,
struct dentry *dentry, umode_t mode, bool excl)
{
struct super_block *sb = dir->i_sb;
Expand Down
2 changes: 1 addition & 1 deletion fs/fuse/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@ static int fuse_mknod(struct user_namespace *mnt_userns, struct inode *dir,
return create_new_entry(fm, &args, dir, entry, mode);
}

static int fuse_create(struct user_namespace *mnt_userns, struct inode *dir,
static int fuse_create(struct mnt_idmap *idmap, struct inode *dir,
struct dentry *entry, umode_t mode, bool excl)
{
return fuse_mknod(&init_user_ns, dir, entry, mode, 0);
Expand Down
4 changes: 2 additions & 2 deletions fs/gfs2/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,7 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry,

/**
* gfs2_create - Create a file
* @mnt_userns: User namespace of the mount the inode was found from
* @idmap: idmap of the mount the inode was found from
* @dir: The directory in which to create the file
* @dentry: The dentry of the new file
* @mode: The mode of the new file
Expand All @@ -852,7 +852,7 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry,
* Returns: errno
*/

static int gfs2_create(struct user_namespace *mnt_userns, struct inode *dir,
static int gfs2_create(struct mnt_idmap *idmap, struct inode *dir,
struct dentry *dentry, umode_t mode, bool excl)
{
return gfs2_create_inode(dir, dentry, NULL, S_IFREG | mode, 0, NULL, 0, excl);
Expand Down
2 changes: 1 addition & 1 deletion fs/hfs/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ static int hfs_dir_release(struct inode *inode, struct file *file)
* a directory and return a corresponding inode, given the inode for
* the directory and the name (and its length) of the new file.
*/
static int hfs_create(struct user_namespace *mnt_userns, struct inode *dir,
static int hfs_create(struct mnt_idmap *idmap, struct inode *dir,
struct dentry *dentry, umode_t mode, bool excl)
{
struct inode *inode;
Expand Down
2 changes: 1 addition & 1 deletion fs/hfsplus/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ static int hfsplus_mknod(struct user_namespace *mnt_userns, struct inode *dir,
return res;
}

static int hfsplus_create(struct user_namespace *mnt_userns, struct inode *dir,
static int hfsplus_create(struct mnt_idmap *idmap, struct inode *dir,
struct dentry *dentry, umode_t mode, bool excl)
{
return hfsplus_mknod(&init_user_ns, dir, dentry, mode, 0);
Expand Down
2 changes: 1 addition & 1 deletion fs/hostfs/hostfs_kern.c
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ static int read_name(struct inode *ino, char *name)
return 0;
}

static int hostfs_create(struct user_namespace *mnt_userns, struct inode *dir,
static int hostfs_create(struct mnt_idmap *idmap, struct inode *dir,
struct dentry *dentry, umode_t mode, bool excl)
{
struct inode *inode;
Expand Down
2 changes: 1 addition & 1 deletion fs/hpfs/namei.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ static int hpfs_mkdir(struct user_namespace *mnt_userns, struct inode *dir,
return err;
}

static int hpfs_create(struct user_namespace *mnt_userns, struct inode *dir,
static int hpfs_create(struct mnt_idmap *idmap, struct inode *dir,
struct dentry *dentry, umode_t mode, bool excl)
{
const unsigned char *name = dentry->d_name.name;
Expand Down
2 changes: 1 addition & 1 deletion fs/hugetlbfs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -1043,7 +1043,7 @@ static int hugetlbfs_mkdir(struct user_namespace *mnt_userns, struct inode *dir,
return retval;
}

static int hugetlbfs_create(struct user_namespace *mnt_userns,
static int hugetlbfs_create(struct mnt_idmap *idmap,
struct inode *dir, struct dentry *dentry,
umode_t mode, bool excl)
{
Expand Down
4 changes: 2 additions & 2 deletions fs/jffs2/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

static int jffs2_readdir (struct file *, struct dir_context *);

static int jffs2_create (struct user_namespace *, struct inode *,
static int jffs2_create (struct mnt_idmap *, struct inode *,
struct dentry *, umode_t, bool);
static struct dentry *jffs2_lookup (struct inode *,struct dentry *,
unsigned int);
Expand Down Expand Up @@ -160,7 +160,7 @@ static int jffs2_readdir(struct file *file, struct dir_context *ctx)
/***********************************************************************/


static int jffs2_create(struct user_namespace *mnt_userns, struct inode *dir_i,
static int jffs2_create(struct mnt_idmap *idmap, struct inode *dir_i,
struct dentry *dentry, umode_t mode, bool excl)
{
struct jffs2_raw_inode *ri;
Expand Down
2 changes: 1 addition & 1 deletion fs/jfs/namei.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ static inline void free_ea_wmap(struct inode *inode)
* RETURN: Errors from subroutines
*
*/
static int jfs_create(struct user_namespace *mnt_userns, struct inode *dip,
static int jfs_create(struct mnt_idmap *idmap, struct inode *dip,
struct dentry *dentry, umode_t mode, bool excl)
{
int rc = 0;
Expand Down
4 changes: 2 additions & 2 deletions fs/minix/namei.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ static int minix_tmpfile(struct user_namespace *mnt_userns, struct inode *dir,
return finish_open_simple(file, error);
}

static int minix_create(struct user_namespace *mnt_userns, struct inode *dir,
static int minix_create(struct mnt_idmap *idmap, struct inode *dir,
struct dentry *dentry, umode_t mode, bool excl)
{
return minix_mknod(mnt_userns, dir, dentry, mode, 0);
return minix_mknod(&init_user_ns, dir, dentry, mode, 0);
}

static int minix_symlink(struct user_namespace *mnt_userns, struct inode *dir,
Expand Down
8 changes: 5 additions & 3 deletions fs/namei.c
Original file line number Diff line number Diff line change
Expand Up @@ -3115,7 +3115,7 @@ int vfs_create(struct mnt_idmap *idmap, struct inode *dir,
error = security_inode_create(dir, dentry, mode);
if (error)
return error;
error = dir->i_op->create(mnt_userns, dir, dentry, mode, want_excl);
error = dir->i_op->create(idmap, dir, dentry, mode, want_excl);
if (!error)
fsnotify_create(dir, dentry);
return error;
Expand Down Expand Up @@ -3322,6 +3322,7 @@ static struct dentry *lookup_open(struct nameidata *nd, struct file *file,
const struct open_flags *op,
bool got_write)
{
struct mnt_idmap *idmap;
struct user_namespace *mnt_userns;
struct dentry *dir = nd->path.dentry;
struct inode *dir_inode = dir->d_inode;
Expand Down Expand Up @@ -3370,7 +3371,8 @@ static struct dentry *lookup_open(struct nameidata *nd, struct file *file,
*/
if (unlikely(!got_write))
open_flag &= ~O_TRUNC;
mnt_userns = mnt_user_ns(nd->path.mnt);
idmap = mnt_idmap(nd->path.mnt);
mnt_userns = mnt_idmap_owner(idmap);
if (open_flag & O_CREAT) {
if (open_flag & O_EXCL)
open_flag &= ~O_TRUNC;
Expand Down Expand Up @@ -3413,7 +3415,7 @@ static struct dentry *lookup_open(struct nameidata *nd, struct file *file,
goto out_dput;
}

error = dir_inode->i_op->create(mnt_userns, dir_inode, dentry,
error = dir_inode->i_op->create(idmap, dir_inode, dentry,
mode, open_flag & O_EXCL);
if (error)
goto out_dput;
Expand Down
2 changes: 1 addition & 1 deletion fs/nfs/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -2296,7 +2296,7 @@ EXPORT_SYMBOL_GPL(nfs_instantiate);
* that the operation succeeded on the server, but an error in the
* reply path made it appear to have failed.
*/
int nfs_create(struct user_namespace *mnt_userns, struct inode *dir,
int nfs_create(struct mnt_idmap *idmap, struct inode *dir,
struct dentry *dentry, umode_t mode, bool excl)
{
struct iattr attr;
Expand Down
Loading

0 comments on commit 6c960e6

Please sign in to comment.