Skip to content

Commit

Permalink
fs: port xattr to 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 4609e1f commit 39f60c1
Show file tree
Hide file tree
Showing 65 changed files with 203 additions and 204 deletions.
2 changes: 1 addition & 1 deletion Documentation/filesystems/locking.rst
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ prototypes::
struct inode *inode, const char *name, void *buffer,
size_t size);
int (*set)(const struct xattr_handler *handler,
struct user_namespace *mnt_userns,
struct mnt_idmap *idmap,
struct dentry *dentry, struct inode *inode, const char *name,
const void *buffer, size_t size, int flags);

Expand Down
2 changes: 1 addition & 1 deletion fs/9p/xattr.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ static int v9fs_xattr_handler_get(const struct xattr_handler *handler,
}

static int v9fs_xattr_handler_set(const struct xattr_handler *handler,
struct user_namespace *mnt_userns,
struct mnt_idmap *idmap,
struct dentry *dentry, struct inode *inode,
const char *name, const void *value,
size_t size, int flags)
Expand Down
4 changes: 2 additions & 2 deletions fs/afs/xattr.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ static const struct afs_operation_ops afs_store_acl_operation = {
* Set a file's AFS3 ACL.
*/
static int afs_xattr_set_acl(const struct xattr_handler *handler,
struct user_namespace *mnt_userns,
struct mnt_idmap *idmap,
struct dentry *dentry,
struct inode *inode, const char *name,
const void *buffer, size_t size, int flags)
Expand Down Expand Up @@ -228,7 +228,7 @@ static const struct afs_operation_ops yfs_store_opaque_acl2_operation = {
* Set a file's YFS ACL.
*/
static int afs_xattr_set_yfs(const struct xattr_handler *handler,
struct user_namespace *mnt_userns,
struct mnt_idmap *idmap,
struct dentry *dentry,
struct inode *inode, const char *name,
const void *buffer, size_t size, int flags)
Expand Down
4 changes: 2 additions & 2 deletions fs/attr.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ int setattr_prepare(struct mnt_idmap *idmap, struct dentry *dentry,
if (ia_valid & ATTR_KILL_PRIV) {
int error;

error = security_inode_killpriv(mnt_userns, dentry);
error = security_inode_killpriv(idmap, dentry);
if (error)
return error;
}
Expand Down Expand Up @@ -489,7 +489,7 @@ int notify_change(struct mnt_idmap *idmap, struct dentry *dentry,

if (!error) {
fsnotify_change(dentry, ia_valid);
ima_inode_post_setattr(mnt_userns, dentry);
ima_inode_post_setattr(idmap, dentry);
evm_inode_post_setattr(dentry, ia_valid);
}

Expand Down
4 changes: 2 additions & 2 deletions fs/btrfs/xattr.c
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ static int btrfs_xattr_handler_get(const struct xattr_handler *handler,
}

static int btrfs_xattr_handler_set(const struct xattr_handler *handler,
struct user_namespace *mnt_userns,
struct mnt_idmap *idmap,
struct dentry *unused, struct inode *inode,
const char *name, const void *buffer,
size_t size, int flags)
Expand All @@ -383,7 +383,7 @@ static int btrfs_xattr_handler_set(const struct xattr_handler *handler,
}

static int btrfs_xattr_handler_set_prop(const struct xattr_handler *handler,
struct user_namespace *mnt_userns,
struct mnt_idmap *idmap,
struct dentry *unused, struct inode *inode,
const char *name, const void *value,
size_t size, int flags)
Expand Down
2 changes: 1 addition & 1 deletion fs/ceph/xattr.c
Original file line number Diff line number Diff line change
Expand Up @@ -1285,7 +1285,7 @@ static int ceph_get_xattr_handler(const struct xattr_handler *handler,
}

static int ceph_set_xattr_handler(const struct xattr_handler *handler,
struct user_namespace *mnt_userns,
struct mnt_idmap *idmap,
struct dentry *unused, struct inode *inode,
const char *name, const void *value,
size_t size, int flags)
Expand Down
2 changes: 1 addition & 1 deletion fs/cifs/xattr.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ static int cifs_creation_time_set(unsigned int xid, struct cifs_tcon *pTcon,
}

static int cifs_xattr_set(const struct xattr_handler *handler,
struct user_namespace *mnt_userns,
struct mnt_idmap *idmap,
struct dentry *dentry, struct inode *inode,
const char *name, const void *value,
size_t size, int flags)
Expand Down
2 changes: 1 addition & 1 deletion fs/ecryptfs/crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -1105,7 +1105,7 @@ ecryptfs_write_metadata_to_xattr(struct dentry *ecryptfs_dentry,
}

inode_lock(lower_inode);
rc = __vfs_setxattr(&init_user_ns, lower_dentry, lower_inode,
rc = __vfs_setxattr(&nop_mnt_idmap, lower_dentry, lower_inode,
ECRYPTFS_XATTR_NAME, page_virt, size, 0);
if (!rc && ecryptfs_inode)
fsstack_copy_attr_all(ecryptfs_inode, lower_inode);
Expand Down
4 changes: 2 additions & 2 deletions fs/ecryptfs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -1099,7 +1099,7 @@ static int ecryptfs_removexattr(struct dentry *dentry, struct inode *inode,
goto out;
}
inode_lock(lower_inode);
rc = __vfs_removexattr(&init_user_ns, lower_dentry, name);
rc = __vfs_removexattr(&nop_mnt_idmap, lower_dentry, name);
inode_unlock(lower_inode);
out:
return rc;
Expand Down Expand Up @@ -1190,7 +1190,7 @@ static int ecryptfs_xattr_get(const struct xattr_handler *handler,
}

static int ecryptfs_xattr_set(const struct xattr_handler *handler,
struct user_namespace *mnt_userns,
struct mnt_idmap *idmap,
struct dentry *dentry, struct inode *inode,
const char *name, const void *value, size_t size,
int flags)
Expand Down
2 changes: 1 addition & 1 deletion fs/ecryptfs/mmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ static int ecryptfs_write_inode_size_to_xattr(struct inode *ecryptfs_inode)
if (size < 0)
size = 8;
put_unaligned_be64(i_size_read(ecryptfs_inode), xattr_virt);
rc = __vfs_setxattr(&init_user_ns, lower_dentry, lower_inode,
rc = __vfs_setxattr(&nop_mnt_idmap, lower_dentry, lower_inode,
ECRYPTFS_XATTR_NAME, xattr_virt, size, 0);
inode_unlock(lower_inode);
if (rc)
Expand Down
2 changes: 1 addition & 1 deletion fs/ext2/xattr_security.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ ext2_xattr_security_get(const struct xattr_handler *handler,

static int
ext2_xattr_security_set(const struct xattr_handler *handler,
struct user_namespace *mnt_userns,
struct mnt_idmap *idmap,
struct dentry *unused, struct inode *inode,
const char *name, const void *value,
size_t size, int flags)
Expand Down
2 changes: 1 addition & 1 deletion fs/ext2/xattr_trusted.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ ext2_xattr_trusted_get(const struct xattr_handler *handler,

static int
ext2_xattr_trusted_set(const struct xattr_handler *handler,
struct user_namespace *mnt_userns,
struct mnt_idmap *idmap,
struct dentry *unused, struct inode *inode,
const char *name, const void *value,
size_t size, int flags)
Expand Down
2 changes: 1 addition & 1 deletion fs/ext2/xattr_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ ext2_xattr_user_get(const struct xattr_handler *handler,

static int
ext2_xattr_user_set(const struct xattr_handler *handler,
struct user_namespace *mnt_userns,
struct mnt_idmap *idmap,
struct dentry *unused, struct inode *inode,
const char *name, const void *value,
size_t size, int flags)
Expand Down
2 changes: 1 addition & 1 deletion fs/ext4/xattr_hurd.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ ext4_xattr_hurd_get(const struct xattr_handler *handler,

static int
ext4_xattr_hurd_set(const struct xattr_handler *handler,
struct user_namespace *mnt_userns,
struct mnt_idmap *idmap,
struct dentry *unused, struct inode *inode,
const char *name, const void *value,
size_t size, int flags)
Expand Down
2 changes: 1 addition & 1 deletion fs/ext4/xattr_security.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ ext4_xattr_security_get(const struct xattr_handler *handler,

static int
ext4_xattr_security_set(const struct xattr_handler *handler,
struct user_namespace *mnt_userns,
struct mnt_idmap *idmap,
struct dentry *unused, struct inode *inode,
const char *name, const void *value,
size_t size, int flags)
Expand Down
2 changes: 1 addition & 1 deletion fs/ext4/xattr_trusted.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ ext4_xattr_trusted_get(const struct xattr_handler *handler,

static int
ext4_xattr_trusted_set(const struct xattr_handler *handler,
struct user_namespace *mnt_userns,
struct mnt_idmap *idmap,
struct dentry *unused, struct inode *inode,
const char *name, const void *value,
size_t size, int flags)
Expand Down
2 changes: 1 addition & 1 deletion fs/ext4/xattr_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ ext4_xattr_user_get(const struct xattr_handler *handler,

static int
ext4_xattr_user_set(const struct xattr_handler *handler,
struct user_namespace *mnt_userns,
struct mnt_idmap *idmap,
struct dentry *unused, struct inode *inode,
const char *name, const void *value,
size_t size, int flags)
Expand Down
4 changes: 2 additions & 2 deletions fs/f2fs/xattr.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ static int f2fs_xattr_generic_get(const struct xattr_handler *handler,
}

static int f2fs_xattr_generic_set(const struct xattr_handler *handler,
struct user_namespace *mnt_userns,
struct mnt_idmap *idmap,
struct dentry *unused, struct inode *inode,
const char *name, const void *value,
size_t size, int flags)
Expand Down Expand Up @@ -109,7 +109,7 @@ static int f2fs_xattr_advise_get(const struct xattr_handler *handler,
}

static int f2fs_xattr_advise_set(const struct xattr_handler *handler,
struct user_namespace *mnt_userns,
struct mnt_idmap *idmap,
struct dentry *unused, struct inode *inode,
const char *name, const void *value,
size_t size, int flags)
Expand Down
4 changes: 2 additions & 2 deletions fs/fuse/xattr.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ static int fuse_xattr_get(const struct xattr_handler *handler,
}

static int fuse_xattr_set(const struct xattr_handler *handler,
struct user_namespace *mnt_userns,
struct mnt_idmap *idmap,
struct dentry *dentry, struct inode *inode,
const char *name, const void *value, size_t size,
int flags)
Expand All @@ -216,7 +216,7 @@ static int no_xattr_get(const struct xattr_handler *handler,
}

static int no_xattr_set(const struct xattr_handler *handler,
struct user_namespace *mnt_userns,
struct mnt_idmap *idmap,
struct dentry *dentry, struct inode *nodee,
const char *name, const void *value,
size_t size, int flags)
Expand Down
2 changes: 1 addition & 1 deletion fs/gfs2/xattr.c
Original file line number Diff line number Diff line change
Expand Up @@ -1225,7 +1225,7 @@ int __gfs2_xattr_set(struct inode *inode, const char *name,
}

static int gfs2_xattr_set(const struct xattr_handler *handler,
struct user_namespace *mnt_userns,
struct mnt_idmap *idmap,
struct dentry *unused, struct inode *inode,
const char *name, const void *value,
size_t size, int flags)
Expand Down
2 changes: 1 addition & 1 deletion fs/hfs/attr.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ static int hfs_xattr_get(const struct xattr_handler *handler,
}

static int hfs_xattr_set(const struct xattr_handler *handler,
struct user_namespace *mnt_userns,
struct mnt_idmap *idmap,
struct dentry *unused, struct inode *inode,
const char *name, const void *value, size_t size,
int flags)
Expand Down
2 changes: 1 addition & 1 deletion fs/hfsplus/xattr.c
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,7 @@ static int hfsplus_osx_getxattr(const struct xattr_handler *handler,
}

static int hfsplus_osx_setxattr(const struct xattr_handler *handler,
struct user_namespace *mnt_userns,
struct mnt_idmap *idmap,
struct dentry *unused, struct inode *inode,
const char *name, const void *buffer,
size_t size, int flags)
Expand Down
2 changes: 1 addition & 1 deletion fs/hfsplus/xattr_security.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ static int hfsplus_security_getxattr(const struct xattr_handler *handler,
}

static int hfsplus_security_setxattr(const struct xattr_handler *handler,
struct user_namespace *mnt_userns,
struct mnt_idmap *idmap,
struct dentry *unused, struct inode *inode,
const char *name, const void *buffer,
size_t size, int flags)
Expand Down
2 changes: 1 addition & 1 deletion fs/hfsplus/xattr_trusted.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ static int hfsplus_trusted_getxattr(const struct xattr_handler *handler,
}

static int hfsplus_trusted_setxattr(const struct xattr_handler *handler,
struct user_namespace *mnt_userns,
struct mnt_idmap *idmap,
struct dentry *unused, struct inode *inode,
const char *name, const void *buffer,
size_t size, int flags)
Expand Down
2 changes: 1 addition & 1 deletion fs/hfsplus/xattr_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ static int hfsplus_user_getxattr(const struct xattr_handler *handler,
}

static int hfsplus_user_setxattr(const struct xattr_handler *handler,
struct user_namespace *mnt_userns,
struct mnt_idmap *idmap,
struct dentry *unused, struct inode *inode,
const char *name, const void *buffer,
size_t size, int flags)
Expand Down
2 changes: 1 addition & 1 deletion fs/jffs2/security.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ static int jffs2_security_getxattr(const struct xattr_handler *handler,
}

static int jffs2_security_setxattr(const struct xattr_handler *handler,
struct user_namespace *mnt_userns,
struct mnt_idmap *idmap,
struct dentry *unused, struct inode *inode,
const char *name, const void *buffer,
size_t size, int flags)
Expand Down
2 changes: 1 addition & 1 deletion fs/jffs2/xattr_trusted.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ static int jffs2_trusted_getxattr(const struct xattr_handler *handler,
}

static int jffs2_trusted_setxattr(const struct xattr_handler *handler,
struct user_namespace *mnt_userns,
struct mnt_idmap *idmap,
struct dentry *unused, struct inode *inode,
const char *name, const void *buffer,
size_t size, int flags)
Expand Down
2 changes: 1 addition & 1 deletion fs/jffs2/xattr_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ static int jffs2_user_getxattr(const struct xattr_handler *handler,
}

static int jffs2_user_setxattr(const struct xattr_handler *handler,
struct user_namespace *mnt_userns,
struct mnt_idmap *idmap,
struct dentry *unused, struct inode *inode,
const char *name, const void *buffer,
size_t size, int flags)
Expand Down
4 changes: 2 additions & 2 deletions fs/jfs/xattr.c
Original file line number Diff line number Diff line change
Expand Up @@ -932,7 +932,7 @@ static int jfs_xattr_get(const struct xattr_handler *handler,
}

static int jfs_xattr_set(const struct xattr_handler *handler,
struct user_namespace *mnt_userns,
struct mnt_idmap *idmap,
struct dentry *unused, struct inode *inode,
const char *name, const void *value,
size_t size, int flags)
Expand All @@ -951,7 +951,7 @@ static int jfs_xattr_get_os2(const struct xattr_handler *handler,
}

static int jfs_xattr_set_os2(const struct xattr_handler *handler,
struct user_namespace *mnt_userns,
struct mnt_idmap *idmap,
struct dentry *unused, struct inode *inode,
const char *name, const void *value,
size_t size, int flags)
Expand Down
4 changes: 2 additions & 2 deletions fs/kernfs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ static int kernfs_vfs_xattr_get(const struct xattr_handler *handler,
}

static int kernfs_vfs_xattr_set(const struct xattr_handler *handler,
struct user_namespace *mnt_userns,
struct mnt_idmap *idmap,
struct dentry *unused, struct inode *inode,
const char *suffix, const void *value,
size_t size, int flags)
Expand Down Expand Up @@ -391,7 +391,7 @@ static int kernfs_vfs_user_xattr_rm(struct kernfs_node *kn,
}

static int kernfs_vfs_user_xattr_set(const struct xattr_handler *handler,
struct user_namespace *mnt_userns,
struct mnt_idmap *idmap,
struct dentry *unused, struct inode *inode,
const char *suffix, const void *value,
size_t size, int flags)
Expand Down
6 changes: 2 additions & 4 deletions fs/namei.c
Original file line number Diff line number Diff line change
Expand Up @@ -3633,7 +3633,7 @@ static int vfs_tmpfile(struct mnt_idmap *idmap,
inode->i_state |= I_LINKABLE;
spin_unlock(&inode->i_lock);
}
ima_post_create_tmpfile(mnt_userns, inode);
ima_post_create_tmpfile(idmap, inode);
return 0;
}

Expand Down Expand Up @@ -3953,7 +3953,6 @@ static int do_mknodat(int dfd, struct filename *name, umode_t mode,
unsigned int dev)
{
struct mnt_idmap *idmap;
struct user_namespace *mnt_userns;
struct dentry *dentry;
struct path path;
int error;
Expand All @@ -3974,13 +3973,12 @@ static int do_mknodat(int dfd, struct filename *name, umode_t mode,
goto out2;

idmap = mnt_idmap(path.mnt);
mnt_userns = mnt_idmap_owner(idmap);
switch (mode & S_IFMT) {
case 0: case S_IFREG:
error = vfs_create(idmap, path.dentry->d_inode,
dentry, mode, true);
if (!error)
ima_post_path_mknod(mnt_userns, dentry);
ima_post_path_mknod(idmap, dentry);
break;
case S_IFCHR: case S_IFBLK:
error = vfs_mknod(idmap, path.dentry->d_inode,
Expand Down
Loading

0 comments on commit 39f60c1

Please sign in to comment.