idmapped mounts
Subsystems (94)
PATCH v6 24/40 fs: make helpers idmap mount aware
In reply to Christian BraunerExtend some inode methods with an additional user namespace argument. A filesystem that is aware of idmapped mounts will receive the user namespace the mount has been marked with. This can be used for additional permission checking and also to enable filesystems to translate between uids and gids if they need to. We have implemented all relevant helpers in earlier patches.
As requested we simply extend the exisiting inode method instead of introducing new ones. This is a little more code churn but it's mostly mechanical and doesnt't leave us with additional inode methods.
---
/* v2 */
- Christoph Hellwig <[email protected]>:
- Don't pollute the vfs with additional helpers simply extend the existing inode methods with an additional argument and switch all callers.
/* v3 */
- kernel test robot <[email protected]>:
- Fix call to simple_rename() in drivers/android/binderfs.c.
- Fix ntfs_setattr() in fs/ntfs/file.c.
/* v4 */
- Serge Hallyn <[email protected]>:
- Use "mnt_userns" to refer to a vfsmount's userns everywhere to make terminology consistent.
/* v5 */
unchanged
base-commit: 7c53f6b671f4aba70ff15e1b05148b10d58c2837
/* v6 */
unchanged
base-commit: 19c329f6808995b142b3966301f217c831e7cf31
--- Documentation/filesystems/vfs.rst | 19 ++++---- arch/powerpc/platforms/cell/spufs/inode.c | 3 +- drivers/android/binderfs.c | 6 ++- fs/9p/acl.c | 4 +- fs/9p/v9fs.h | 3 +- fs/9p/v9fs_vfs.h | 3 +- fs/9p/vfs_inode.c | 26 ++++++----- fs/9p/vfs_inode_dotl.c | 31 +++++++------ fs/adfs/adfs.h | 3 +- fs/adfs/inode.c | 3 +- fs/affs/affs.h | 24 ++++++---- fs/affs/inode.c | 3 +- fs/affs/namei.c | 15 ++++--- fs/afs/dir.c | 34 +++++++------- fs/afs/inode.c | 7 +-- fs/afs/internal.h | 7 +-- fs/afs/security.c | 3 +- fs/attr.c | 4 +- fs/autofs/root.c | 17 ++++--- fs/bad_inode.c | 36 +++++++++------ fs/bfs/dir.c | 10 ++--- fs/btrfs/acl.c | 3 +- fs/btrfs/ctree.h | 3 +- fs/btrfs/inode.c | 33 ++++++++------ fs/ceph/acl.c | 3 +- fs/ceph/dir.c | 23 +++++----- fs/ceph/inode.c | 10 +++-- fs/ceph/super.h | 12 +++-- fs/cifs/cifsfs.c | 3 +- fs/cifs/cifsfs.h | 25 ++++++----- fs/cifs/dir.c | 8 ++-- fs/cifs/inode.c | 16 ++++--- fs/cifs/link.c | 3 +- fs/coda/coda_linux.h | 8 ++-- fs/coda/dir.c | 18 +++++--- fs/coda/inode.c | 7 +-- fs/coda/pioctl.c | 6 ++- fs/configfs/configfs_internal.h | 6 ++- fs/configfs/dir.c | 3 +- fs/configfs/inode.c | 5 ++- fs/configfs/symlink.c | 3 +- fs/debugfs/inode.c | 9 ++-- fs/ecryptfs/inode.c | 30 ++++++++----- fs/efivarfs/inode.c | 4 +- fs/erofs/inode.c | 5 ++- fs/erofs/internal.h | 5 ++- fs/exfat/exfat_fs.h | 8 ++-- fs/exfat/file.c | 8 ++-- fs/exfat/namei.c | 14 +++--- fs/ext2/acl.c | 3 +- fs/ext2/acl.h | 3 +- fs/ext2/ext2.h | 5 ++- fs/ext2/inode.c | 7 +-- fs/ext2/namei.c | 22 +++++---- fs/ext4/acl.c | 3 +- fs/ext4/acl.h | 3 +- fs/ext4/ext4.h | 9 ++-- fs/ext4/inode.c | 12 ++--- fs/ext4/namei.c | 19 ++++---- fs/f2fs/acl.c | 3 +- fs/f2fs/acl.h | 3 +- fs/f2fs/f2fs.h | 7 +-- fs/f2fs/file.c | 7 +-- fs/f2fs/namei.c | 21 +++++---- fs/fat/fat.h | 6 ++- fs/fat/file.c | 9 ++-- fs/fat/namei_msdos.c | 10 +++-- fs/fat/namei_vfat.c | 13 +++--- fs/fuse/acl.c | 3 +- fs/fuse/dir.c | 37 ++++++++------- fs/fuse/fuse_i.h | 4 +- fs/gfs2/acl.c | 3 +- fs/gfs2/acl.h | 3 +- fs/gfs2/file.c | 2 +- fs/gfs2/inode.c | 53 +++++++++++++--------- fs/gfs2/inode.h | 3 +- fs/hfs/dir.c | 13 +++--- fs/hfs/hfs_fs.h | 3 +- fs/hfs/inode.c | 6 ++- fs/hfsplus/dir.c | 22 ++++----- fs/hfsplus/hfsplus_fs.h | 5 ++- fs/hfsplus/inode.c | 8 ++-- fs/hostfs/hostfs_kern.c | 23 ++++++---- fs/hpfs/hpfs_fn.h | 2 +- fs/hpfs/inode.c | 3 +- fs/hpfs/namei.c | 20 +++++---- fs/hugetlbfs/inode.c | 29 +++++++----- fs/jffs2/acl.c | 3 +- fs/jffs2/acl.h | 3 +- fs/jffs2/dir.c | 33 ++++++++------ fs/jffs2/fs.c | 3 +- fs/jffs2/os-linux.h | 2 +- fs/jfs/acl.c | 3 +- fs/jfs/file.c | 3 +- fs/jfs/jfs_acl.h | 3 +- fs/jfs/jfs_inode.h | 2 +- fs/jfs/namei.c | 21 ++++----- fs/kernfs/dir.c | 6 ++- fs/kernfs/inode.c | 9 ++-- fs/kernfs/kernfs-internal.h | 9 ++-- fs/libfs.c | 31 +++++++------ fs/minix/file.c | 3 +- fs/minix/inode.c | 4 +- fs/minix/minix.h | 3 +- fs/minix/namei.c | 24 +++++----- fs/namei.c | 55 +++++++++++++---------- fs/nfs/dir.c | 23 ++++++---- fs/nfs/inode.c | 7 +-- fs/nfs/internal.h | 14 +++--- fs/nfs/namespace.c | 13 +++--- fs/nfs/nfs3_fs.h | 3 +- fs/nfs/nfs3acl.c | 3 +- fs/nilfs2/inode.c | 6 ++- fs/nilfs2/namei.c | 19 ++++---- fs/nilfs2/nilfs.h | 6 ++- fs/ntfs/inode.c | 4 +- fs/ntfs/inode.h | 3 +- fs/ocfs2/acl.c | 3 +- fs/ocfs2/acl.h | 3 +- fs/ocfs2/dlmfs/dlmfs.c | 9 ++-- fs/ocfs2/file.c | 10 +++-- fs/ocfs2/file.h | 11 +++-- fs/ocfs2/namei.c | 19 +++++--- fs/omfs/dir.c | 13 +++--- fs/omfs/file.c | 3 +- fs/orangefs/acl.c | 3 +- fs/orangefs/inode.c | 10 +++-- fs/orangefs/namei.c | 12 +++-- fs/orangefs/orangefs-kernel.h | 13 +++--- fs/overlayfs/dir.c | 21 ++++----- fs/overlayfs/inode.c | 10 +++-- fs/overlayfs/overlayfs.h | 10 +++-- fs/overlayfs/super.c | 2 +- fs/posix_acl.c | 9 ++-- fs/proc/base.c | 16 ++++--- fs/proc/fd.c | 3 +- fs/proc/fd.h | 3 +- fs/proc/generic.c | 6 ++- fs/proc/internal.h | 6 ++- fs/proc/proc_net.c | 3 +- fs/proc/proc_sysctl.c | 9 ++-- fs/proc/root.c | 3 +- fs/ramfs/file-nommu.c | 5 ++- fs/ramfs/inode.c | 16 ++++--- fs/reiserfs/acl.h | 3 +- fs/reiserfs/inode.c | 3 +- fs/reiserfs/namei.c | 19 ++++---- fs/reiserfs/reiserfs.h | 3 +- fs/reiserfs/xattr.c | 11 ++--- fs/reiserfs/xattr.h | 3 +- fs/reiserfs/xattr_acl.c | 3 +- fs/stat.c | 8 ++-- fs/sysv/file.c | 3 +- fs/sysv/itree.c | 4 +- fs/sysv/namei.c | 21 +++++---- fs/sysv/sysv.h | 3 +- fs/tracefs/inode.c | 4 +- fs/ubifs/dir.c | 26 ++++++----- fs/ubifs/file.c | 3 +- fs/ubifs/ubifs.h | 5 ++- fs/udf/file.c | 3 +- fs/udf/namei.c | 24 +++++----- fs/udf/symlink.c | 5 ++- fs/ufs/inode.c | 3 +- fs/ufs/namei.c | 19 ++++---- fs/ufs/ufs.h | 3 +- fs/vboxsf/dir.c | 12 +++-- fs/vboxsf/utils.c | 7 +-- fs/vboxsf/vfsmod.h | 8 ++-- fs/xfs/xfs_acl.c | 3 +- fs/xfs/xfs_acl.h | 3 +- fs/xfs/xfs_iops.c | 52 ++++++++++++--------- fs/zonefs/super.c | 3 +- include/linux/fs.h | 39 ++++++++++------ include/linux/nfs_fs.h | 7 +-- include/linux/posix_acl.h | 3 +- ipc/mqueue.c | 4 +- kernel/bpf/inode.c | 7 +-- mm/shmem.c | 39 ++++++++++------ net/socket.c | 5 ++- security/apparmor/apparmorfs.c | 3 +- security/integrity/evm/evm_secfs.c | 2 +- 182 files changed, 1121 insertions(+), 756 deletions(-)
Documentation/filesystems/vfs.rst +10 -9
@@ -415,28 +415,29 @@ As of kernel 2.6.22, the following members are defined: .. code-block:: c struct inode_operations { - int (*create) (struct inode *,struct dentry *, umode_t, bool); + int (*create) (struct user_namespace *, 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 *); - int (*symlink) (struct inode *,struct dentry *,const char *); - int (*mkdir) (struct inode *,struct dentry *,umode_t); + int (*symlink) (struct user_namespace *, struct inode *,struct dentry *,const char *); + int (*mkdir) (struct user_namespace *, struct inode *,struct dentry *,umode_t); int (*rmdir) (struct inode *,struct dentry *); - int (*mknod) (struct inode *,struct dentry *,umode_t,dev_t); - int (*rename) (struct inode *, struct dentry *, + int (*mknod) (struct user_namespace *, struct inode *,struct dentry *,umode_t,dev_t); + int (*rename) (struct user_namespace *, struct inode *, struct dentry *, struct inode *, struct dentry *, unsigned int); int (*readlink) (struct dentry *, char __user *,int); const char *(*get_link) (struct dentry *, struct inode *, struct delayed_call *); - int (*permission) (struct inode *, int); + int (*permission) (struct user_namespace *, struct inode *, int); int (*get_acl)(struct inode *, int); - int (*setattr) (struct dentry *, struct iattr *); - int (*getattr) (const struct path *, struct kstat *, u32, unsigned int); + int (*setattr) (struct user_namespace *, struct dentry *, struct iattr *); + int (*getattr) (struct user_namespace *, const struct path *, struct kstat *, u32, unsigned int); ssize_t (*listxattr) (struct dentry *, char *, size_t); void (*update_time)(struct inode *, struct timespec *, int); int (*atomic_open)(struct inode *, struct dentry *, struct file *, unsigned open_flag, umode_t create_mode); - int (*tmpfile) (struct inode *, struct dentry *, umode_t); + int (*tmpfile) (struct user_namespace *, struct inode *, struct dentry *, umode_t); + int (*set_acl)(struct user_namespace *, struct inode *, struct posix_acl *, int); }; Again, all methods are called without any locks being held, unless
arch/powerpc/platforms/cell/spufs/inode.c +2 -1
@@ -91,7 +91,8 @@ spufs_new_inode(struct super_block *sb, umode_t mode) }static int -spufs_setattr (struct dentry *dentry,struct iattr *attr) +spufs_setattr (struct user_namespace *mnt_userns,struct dentry *dentry, +struct iattr *attr) {struct inode *inode =d_inode (dentry);
drivers/android/binderfs.c +4 -2
@@ -355,7 +355,8 @@ static inline bool is_binderfs_control_device(const struct dentry *dentry)return info->control_dentry == dentry; } -static int binderfs_rename (struct inode *old_dir,struct dentry *old_dentry, +static int binderfs_rename (struct user_namespace *mnt_userns, +struct inode *old_dir,struct dentry *old_dentry,struct inode *new_dir,struct dentry *new_dentry,unsigned int flags) {
@@ -363,7 +364,8 @@ static int binderfs_rename(struct inode *old_dir, struct dentry *old_dentry, is_binderfs_control_device(new_dentry))return -EPERM ; -return simple_rename (old_dir, old_dentry, new_dir, new_dentry, flags); +return simple_rename (&init_user_ns, old_dir, old_dentry, new_dir, + new_dentry, flags); }static int binderfs_unlink (struct inode *dir,struct dentry *dentry)
fs/9p/acl.c +2 -2
@@ -280,7 +280,7 @@ static int v9fs_xattr_set_acl(const struct xattr_handler *handler,struct iattr iattr = {0 };struct posix_acl *old_acl = acl; - retval =posix_acl_update_mode (mnt_userns, inode, + retval =posix_acl_update_mode (&init_user_ns, inode, &iattr.ia_mode, &acl);if (retval) goto err_out;
@@ -299,7 +299,7 @@ static int v9fs_xattr_set_acl(const struct xattr_handler *handler,* What is the following setxattr update the * mode ? */ -v9fs_vfs_setattr_dotl (dentry, &iattr); +v9fs_vfs_setattr_dotl (&init_user_ns, dentry, &iattr); }break ;case ACL_TYPE_DEFAULT :
fs/9p/v9fs.h +2 -1
@@ -135,7 +135,8 @@ extern struct dentry *v9fs_vfs_lookup(struct inode *dir, struct dentry *dentry, unsigned int flags);extern int v9fs_vfs_unlink (struct inode *i,struct dentry *d);extern int v9fs_vfs_rmdir (struct inode *i,struct dentry *d); -extern int v9fs_vfs_rename (struct inode *old_dir,struct dentry *old_dentry, +extern int v9fs_vfs_rename (struct user_namespace *mnt_userns, +struct inode *old_dir,struct dentry *old_dentry,struct inode *new_dir,struct dentry *new_dentry,unsigned int flags); extern struct inode *v9fs_inode_from_fid(struct v9fs_session_info *v9ses,
fs/9p/v9fs_vfs.h +2 -1
@@ -59,7 +59,8 @@ void v9fs_inode2stat(struct inode *inode, struct p9_wstat *stat);int v9fs_uflags2omode (int uflags,int extended);void v9fs_blank_wstat (struct p9_wstat *wstat); -int v9fs_vfs_setattr_dotl (struct dentry *,struct iattr *); +int v9fs_vfs_setattr_dotl (struct user_namespace *,struct dentry *, +struct iattr *);int v9fs_file_fsync_dotl (struct file *filp,loff_t start,loff_t end,int datasync);int v9fs_refresh_inode (struct p9_fid *fid,struct inode *inode);
fs/9p/vfs_inode.c +15 -11
@@ -676,8 +676,8 @@ v9fs_create(struct v9fs_session_info *v9ses, struct inode *dir,*/ static int -v9fs_vfs_create (struct inode *dir,struct dentry *dentry,umode_t mode, -bool excl) +v9fs_vfs_create (struct user_namespace *mnt_userns,struct inode *dir, +struct dentry *dentry,umode_t mode,bool excl) {struct v9fs_session_info *v9ses =v9fs_inode2v9ses (dir);u32 perm =unixmode2p9mode (v9ses, mode);
@@ -702,7 +702,8 @@ v9fs_vfs_create(struct inode *dir, struct dentry *dentry, umode_t mode,* */ -static int v9fs_vfs_mkdir (struct inode *dir,struct dentry *dentry,umode_t mode) +static int v9fs_vfs_mkdir (struct user_namespace *mnt_userns,struct inode *dir, +struct dentry *dentry,umode_t mode) {int err;u32 perm;
@@ -907,9 +908,9 @@ int v9fs_vfs_rmdir(struct inode *i, struct dentry *d)*/ int -v9fs_vfs_rename (struct inode *old_dir,struct dentry *old_dentry, -struct inode *new_dir,struct dentry *new_dentry, -unsigned int flags) +v9fs_vfs_rename (struct user_namespace *mnt_userns,struct inode *old_dir, +struct dentry *old_dentry,struct inode *new_dir, +struct dentry *new_dentry,unsigned int flags) {int retval;struct inode *old_inode;
@@ -1016,8 +1017,8 @@ v9fs_vfs_rename(struct inode *old_dir, struct dentry *old_dentry,*/ static int -v9fs_vfs_getattr (const struct path *path,struct kstat *stat, -u32 request_mask,unsigned int flags) +v9fs_vfs_getattr (struct user_namespace *mnt_userns,const struct path *path, +struct kstat *stat,u32 request_mask,unsigned int flags) {struct dentry *dentry = path->dentry;struct v9fs_session_info *v9ses;
@@ -1054,7 +1055,8 @@ v9fs_vfs_getattr(const struct path *path, struct kstat *stat,* */ -static int v9fs_vfs_setattr (struct dentry *dentry,struct iattr *iattr) +static int v9fs_vfs_setattr (struct user_namespace *mnt_userns, +struct dentry *dentry,struct iattr *iattr) {int retval, use_dentry =0 ;struct v9fs_session_info *v9ses;
@@ -1295,7 +1297,8 @@ static int v9fs_vfs_mkspecial(struct inode *dir, struct dentry *dentry,*/ static int -v9fs_vfs_symlink (struct inode *dir,struct dentry *dentry,const char *symname) +v9fs_vfs_symlink (struct user_namespace *mnt_userns,struct inode *dir, +struct dentry *dentry,const char *symname) {p9_debug (P9_DEBUG_VFS ," %lu,%pd,%s\n" , dir->i_ino, dentry, symname);
@@ -1348,7 +1351,8 @@ v9fs_vfs_link(struct dentry *old_dentry, struct inode *dir,*/ static int -v9fs_vfs_mknod (struct inode *dir,struct dentry *dentry,umode_t mode,dev_t rdev) +v9fs_vfs_mknod (struct user_namespace *mnt_userns,struct inode *dir, +struct dentry *dentry,umode_t mode,dev_t rdev) {struct v9fs_session_info *v9ses =v9fs_inode2v9ses (dir);int retval;
fs/9p/vfs_inode_dotl.c +17 -14
@@ -33,8 +33,8 @@#include "acl.h" static int -v9fs_vfs_mknod_dotl (struct inode *dir,struct dentry *dentry,umode_t omode, -dev_t rdev); +v9fs_vfs_mknod_dotl (struct user_namespace *mnt_userns,struct inode *dir, +struct dentry *dentry,umode_t omode,dev_t rdev);/** * v9fs_get_fsgid_for_create - Helper function to get the gid for creating a
@@ -218,10 +218,10 @@ int v9fs_open_to_dotl_flags(int flags)*/ static int -v9fs_vfs_create_dotl (struct inode *dir,struct dentry *dentry,umode_t omode, -bool excl) +v9fs_vfs_create_dotl (struct user_namespace *mnt_userns,struct inode *dir, +struct dentry *dentry,umode_t omode,bool excl) { -return v9fs_vfs_mknod_dotl (dir, dentry, omode,0 ); +return v9fs_vfs_mknod_dotl (mnt_userns, dir, dentry, omode,0 ); } static int
@@ -367,8 +367,9 @@ v9fs_vfs_atomic_open_dotl(struct inode *dir, struct dentry *dentry,* */ -static int v9fs_vfs_mkdir_dotl (struct inode *dir, -struct dentry *dentry,umode_t omode) +static int v9fs_vfs_mkdir_dotl (struct user_namespace *mnt_userns, +struct inode *dir,struct dentry *dentry, +umode_t omode) {int err;struct v9fs_session_info *v9ses;
@@ -457,8 +458,9 @@ static int v9fs_vfs_mkdir_dotl(struct inode *dir, }static int -v9fs_vfs_getattr_dotl (const struct path *path,struct kstat *stat, -u32 request_mask,unsigned int flags) +v9fs_vfs_getattr_dotl (struct user_namespace *mnt_userns, +const struct path *path,struct kstat *stat, +u32 request_mask,unsigned int flags) {struct dentry *dentry = path->dentry;struct v9fs_session_info *v9ses;
@@ -540,7 +542,8 @@ static int v9fs_mapped_iattr_valid(int iattr_valid)* */ -int v9fs_vfs_setattr_dotl (struct dentry *dentry,struct iattr *iattr) +int v9fs_vfs_setattr_dotl (struct user_namespace *mnt_userns, +struct dentry *dentry,struct iattr *iattr) {int retval, use_dentry =0 ;struct p9_fid *fid =NULL ;
@@ -684,8 +687,8 @@ v9fs_stat2inode_dotl(struct p9_stat_dotl *stat, struct inode *inode, }static int -v9fs_vfs_symlink_dotl (struct inode *dir,struct dentry *dentry, -const char *symname) +v9fs_vfs_symlink_dotl (struct user_namespace *mnt_userns,struct inode *dir, +struct dentry *dentry,const char *symname) {int err;kgid_t gid;
@@ -824,8 +827,8 @@ v9fs_vfs_link_dotl(struct dentry *old_dentry, struct inode *dir,* */ static int -v9fs_vfs_mknod_dotl (struct inode *dir,struct dentry *dentry,umode_t omode, -dev_t rdev) +v9fs_vfs_mknod_dotl (struct user_namespace *mnt_userns,struct inode *dir, +struct dentry *dentry,umode_t omode,dev_t rdev) {int err;kgid_t gid;
fs/adfs/adfs.h +2 -1
@@ -144,7 +144,8 @@ struct adfs_discmap {/* Inode stuff */ struct inode *adfs_iget (struct super_block *sb,struct object_info *obj);int adfs_write_inode (struct inode *inode,struct writeback_control *wbc); -int adfs_notify_change (struct dentry *dentry,struct iattr *attr); +int adfs_notify_change (struct user_namespace *mnt_userns,struct dentry *dentry, +struct iattr *attr);/* map.c */ int adfs_map_lookup (struct super_block *sb,u32 frag_id,unsigned int offset);
fs/adfs/inode.c +2 -1
@@ -292,7 +292,8 @@ adfs_iget(struct super_block *sb, struct object_info *obj)* later. */ int -adfs_notify_change (struct dentry *dentry,struct iattr *attr) +adfs_notify_change (struct user_namespace *mnt_userns,struct dentry *dentry, +struct iattr *attr) {struct inode *inode =d_inode (dentry);struct super_block *sb = inode->i_sb;
fs/affs/affs.h +15 -9
@@ -167,27 +167,33 @@ 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 inode *dir,struct dentry *dentry,umode_t mode,bool ); -extern int affs_mkdir (struct inode *dir,struct dentry *dentry,umode_t mode); +extern int affs_create (struct user_namespace *mnt_userns,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);extern int affs_rmdir (struct inode *dir,struct dentry *dentry);extern int affs_link (struct dentry *olddentry,struct inode *dir,struct dentry *dentry); -extern int affs_symlink (struct inode *dir,struct dentry *dentry, -const char *symname); -extern int affs_rename2 (struct inode *old_dir,struct dentry *old_dentry, -struct inode *new_dir,struct dentry *new_dentry, -unsigned int flags); +extern int affs_symlink (struct user_namespace *mnt_userns, +struct inode *dir,struct dentry *dentry, +const char *symname); +extern int affs_rename2 (struct user_namespace *mnt_userns, +struct inode *old_dir,struct dentry *old_dentry, +struct inode *new_dir,struct dentry *new_dentry, +unsigned int flags);/* inode.c */ extern struct inode *affs_new_inode (struct inode *dir); -extern int affs_notify_change (struct dentry *dentry,struct iattr *attr); +extern int affs_notify_change (struct user_namespace *mnt_userns, +struct dentry *dentry,struct iattr *attr);extern void affs_evict_inode (struct inode *inode);extern struct inode *affs_iget (struct super_block *sb,unsigned long ino);extern int affs_write_inode (struct inode *inode,struct writeback_control *wbc); -extern int affs_add_entry (struct inode *dir,struct inode *inode,struct dentry *dentry,s32 type); +extern int affs_add_entry (struct inode *dir,struct inode *inode, +struct dentry *dentry,s32 type);/* file.c */
fs/affs/inode.c +2 -1
@@ -216,7 +216,8 @@ affs_write_inode(struct inode *inode, struct writeback_control *wbc) }int -affs_notify_change (struct dentry *dentry,struct iattr *attr) +affs_notify_change (struct user_namespace *mnt_userns,struct dentry *dentry, +struct iattr *attr) {struct inode *inode =d_inode (dentry);int error;
fs/affs/namei.c +9 -6
@@ -242,7 +242,8 @@ affs_unlink(struct inode *dir, struct dentry *dentry) }int -affs_create (struct inode *dir,struct dentry *dentry,umode_t mode,bool excl) +affs_create (struct user_namespace *mnt_userns,struct inode *dir, +struct dentry *dentry,umode_t mode,bool excl) {struct super_block *sb = dir->i_sb;struct inode *inode;
@@ -273,7 +274,8 @@ affs_create(struct inode *dir, struct dentry *dentry, umode_t mode, bool excl) }int -affs_mkdir (struct inode *dir,struct dentry *dentry,umode_t mode) +affs_mkdir (struct user_namespace *mnt_userns,struct inode *dir, +struct dentry *dentry,umode_t mode) {struct inode *inode;int error;
@@ -311,7 +313,8 @@ affs_rmdir(struct inode *dir, struct dentry *dentry) }int -affs_symlink (struct inode *dir,struct dentry *dentry,const char *symname) +affs_symlink (struct user_namespace *mnt_userns,struct inode *dir, +struct dentry *dentry,const char *symname) {struct super_block *sb = dir->i_sb;struct buffer_head *bh;
@@ -498,9 +501,9 @@ affs_xrename(struct inode *old_dir, struct dentry *old_dentry,return retval; } -int affs_rename2 (struct inode *old_dir,struct dentry *old_dentry, -struct inode *new_dir,struct dentry *new_dentry, -unsigned int flags) +int affs_rename2 (struct user_namespace *mnt_userns,struct inode *old_dir, +struct dentry *old_dentry,struct inode *new_dir, +struct dentry *new_dentry,unsigned int flags) {if (flags & ~(RENAME_NOREPLACE |RENAME_EXCHANGE ))
fs/afs/dir.c +18 -16
@@ -28,18 +28,19 @@ static int afs_lookup_one_filldir(struct dir_context *ctx, const char *name, int loff_t fpos, u64 ino, unsigned dtype);static int afs_lookup_filldir (struct dir_context *ctx,const char *name,int nlen,loff_t fpos,u64 ino,unsigned dtype); -static int afs_create (struct inode *dir,struct dentry *dentry,umode_t mode, -bool excl); -static int afs_mkdir (struct inode *dir,struct dentry *dentry,umode_t mode); +static int afs_create (struct user_namespace *mnt_userns,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);static int afs_rmdir (struct inode *dir,struct dentry *dentry);static int afs_unlink (struct inode *dir,struct dentry *dentry);static int afs_link (struct dentry *from,struct inode *dir,struct dentry *dentry); -static int afs_symlink (struct inode *dir,struct dentry *dentry, -const char *content); -static int afs_rename (struct inode *old_dir,struct dentry *old_dentry, -struct inode *new_dir,struct dentry *new_dentry, -unsigned int flags); +static int afs_symlink (struct user_namespace *mnt_userns,struct inode *dir, +struct dentry *dentry,const char *content); +static int afs_rename (struct user_namespace *mnt_userns,struct inode *old_dir, +struct dentry *old_dentry,struct inode *new_dir, +struct dentry *new_dentry,unsigned int flags);static int afs_dir_releasepage (struct page *page,gfp_t gfp_flags);static void afs_dir_invalidatepage (struct page *page,unsigned int offset,unsigned int length);
@@ -1325,7 +1326,8 @@ static const struct afs_operation_ops afs_mkdir_operation = {/* * create a directory on an AFS filesystem */ -static int afs_mkdir (struct inode *dir,struct dentry *dentry,umode_t mode) +static int afs_mkdir (struct user_namespace *mnt_userns,struct inode *dir, +struct dentry *dentry,umode_t mode) {struct afs_operation *op;struct afs_vnode *dvnode =AFS_FS_I (dir);
@@ -1619,8 +1621,8 @@ static const struct afs_operation_ops afs_create_operation = {/* * create a regular file on an AFS filesystem */ -static int afs_create (struct inode *dir,struct dentry *dentry,umode_t mode, -bool excl) +static int afs_create (struct user_namespace *mnt_userns,struct inode *dir, +struct dentry *dentry,umode_t mode,bool excl) {struct afs_operation *op;struct afs_vnode *dvnode =AFS_FS_I (dir);
@@ -1741,8 +1743,8 @@ static const struct afs_operation_ops afs_symlink_operation = {/* * create a symlink in an AFS filesystem */ -static int afs_symlink (struct inode *dir,struct dentry *dentry, -const char *content) +static int afs_symlink (struct user_namespace *mnt_userns,struct inode *dir, +struct dentry *dentry,const char *content) {struct afs_operation *op;struct afs_vnode *dvnode =AFS_FS_I (dir);
@@ -1876,9 +1878,9 @@ static const struct afs_operation_ops afs_rename_operation = {/* * rename a file in an AFS filesystem and/or move it between directories */ -static int afs_rename (struct inode *old_dir,struct dentry *old_dentry, -struct inode *new_dir,struct dentry *new_dentry, -unsigned int flags) +static int afs_rename (struct user_namespace *mnt_userns,struct inode *old_dir, +struct dentry *old_dentry,struct inode *new_dir, +struct dentry *new_dentry,unsigned int flags) {struct afs_operation *op;struct afs_vnode *orig_dvnode, *new_dvnode, *vnode;
fs/afs/inode.c +4 -3
@@ -734,8 +734,8 @@ int afs_validate(struct afs_vnode *vnode, struct key *key)/* * read the attributes of an inode */ -int afs_getattr (const struct path *path,struct kstat *stat, -u32 request_mask,unsigned int query_flags) +int afs_getattr (struct user_namespace *mnt_userns,const struct path *path, +struct kstat *stat,u32 request_mask,unsigned int query_flags) {struct inode *inode =d_inode (path->dentry);struct afs_vnode *vnode =AFS_FS_I (inode);
@@ -857,7 +857,8 @@ static const struct afs_operation_ops afs_setattr_operation = {/* * set the attributes of an inode */ -int afs_setattr (struct dentry *dentry,struct iattr *attr) +int afs_setattr (struct user_namespace *mnt_userns,struct dentry *dentry, +struct iattr *attr) {struct afs_operation *op;struct afs_vnode *vnode =AFS_FS_I (d_inode (dentry));
fs/afs/internal.h +4 -3
@@ -1149,8 +1149,9 @@ extern struct inode *afs_iget(struct afs_operation *, struct afs_vnode_param *);extern struct inode *afs_root_iget (struct super_block *,struct key *);extern bool afs_check_validity (struct afs_vnode *);extern int afs_validate (struct afs_vnode *,struct key *); -extern int afs_getattr (const struct path *,struct kstat *,u32 ,unsigned int ); -extern int afs_setattr (struct dentry *,struct iattr *); +extern int afs_getattr (struct user_namespace *mnt_userns,const struct path *, +struct kstat *,u32 ,unsigned int ); +extern int afs_setattr (struct user_namespace *mnt_userns,struct dentry *,struct iattr *);extern void afs_evict_inode (struct inode *);extern int afs_drop_inode (struct inode *);
@@ -1361,7 +1362,7 @@ extern void afs_zap_permits(struct rcu_head *);extern struct key *afs_request_key (struct afs_cell *);extern struct key *afs_request_key_rcu (struct afs_cell *);extern int afs_check_permit (struct afs_vnode *,struct key *,afs_access_t *); -extern int afs_permission (struct inode *,int ); +extern int afs_permission (struct user_namespace *,struct inode *,int ); extern void __exit afs_clean_up_permit_cache(void);/*
fs/afs/security.c +2 -1
@@ -396,7 +396,8 @@ int afs_check_permit(struct afs_vnode *vnode, struct key *key,* - AFS ACLs are attached to directories only, and a file is controlled by its * parent directory's ACL */ -int afs_permission (struct inode *inode,int mask) +int afs_permission (struct user_namespace *mnt_userns,struct inode *inode, +int mask) {struct afs_vnode *vnode =AFS_FS_I (inode);afs_access_t access;
fs/attr.c +2 -2
@@ -395,9 +395,9 @@ int notify_change(struct user_namespace *mnt_userns, struct dentry *dentry,return error;if (inode->i_op->setattr) - error = inode->i_op->setattr (dentry, attr); + error = inode->i_op->setattr (mnt_userns, dentry, attr);else - error =simple_setattr (dentry, attr); + error =simple_setattr (mnt_userns, dentry, attr);if (!error) {fsnotify_change (dentry, ia_valid);
fs/autofs/root.c +10 -7
@@ -10,10 +10,12 @@#include "autofs_i.h" -static int autofs_dir_symlink (struct inode *,struct dentry *,const char *); +static int autofs_dir_symlink (struct user_namespace *,struct inode *, +struct dentry *,const char *);static int autofs_dir_unlink (struct inode *,struct dentry *);static int autofs_dir_rmdir (struct inode *,struct dentry *); -static int autofs_dir_mkdir (struct inode *,struct dentry *,umode_t ); +static int autofs_dir_mkdir (struct user_namespace *,struct inode *, +struct dentry *,umode_t );static long autofs_root_ioctl (struct file *,unsigned int ,unsigned long );#ifdef CONFIG_COMPAT static long autofs_root_compat_ioctl(struct file *,
@@ -524,9 +526,9 @@ static struct dentry *autofs_lookup(struct inode *dir,return NULL ; } -static int autofs_dir_symlink (struct inode *dir, -struct dentry *dentry, -const char *symname) +static int autofs_dir_symlink (struct user_namespace *mnt_userns, +struct inode *dir,struct dentry *dentry, +const char *symname) {struct autofs_sb_info *sbi =autofs_sbi (dir->i_sb);struct autofs_info *ino =autofs_dentry_ino (dentry);
@@ -715,8 +717,9 @@ static int autofs_dir_rmdir(struct inode *dir, struct dentry *dentry)return 0 ; } -static int autofs_dir_mkdir (struct inode *dir, -struct dentry *dentry,umode_t mode) +static int autofs_dir_mkdir (struct user_namespace *mnt_userns, +struct inode *dir,struct dentry *dentry, +umode_t mode) {struct autofs_sb_info *sbi =autofs_sbi (dir->i_sb);struct autofs_info *ino =autofs_dentry_ino (dentry);
fs/bad_inode.c +22 -14
@@ -27,8 +27,9 @@ static const struct file_operations bad_file_ops = .open = bad_file_open, }; -static int bad_inode_create (struct inode *dir,struct dentry *dentry, -umode_t mode,bool excl) +static int bad_inode_create (struct user_namespace *mnt_userns, +struct inode *dir,struct dentry *dentry, +umode_t mode,bool excl) {return -EIO ; }
@@ -50,14 +51,15 @@ static int bad_inode_unlink(struct inode *dir, struct dentry *dentry)return -EIO ; } -static int bad_inode_symlink (struct inode *dir,struct dentry *dentry, -const char *symname) +static int bad_inode_symlink (struct user_namespace *mnt_userns, +struct inode *dir,struct dentry *dentry, +const char *symname) {return -EIO ; } -static int bad_inode_mkdir (struct inode *dir,struct dentry *dentry, -umode_t mode) +static int bad_inode_mkdir (struct user_namespace *mnt_userns,struct inode *dir, +struct dentry *dentry,umode_t mode) {return -EIO ; }
@@ -67,13 +69,14 @@ static int bad_inode_rmdir (struct inode *dir, struct dentry *dentry)return -EIO ; } -static int bad_inode_mknod (struct inode *dir,struct dentry *dentry, -umode_t mode,dev_t rdev) +static int bad_inode_mknod (struct user_namespace *mnt_userns,struct inode *dir, +struct dentry *dentry,umode_t mode,dev_t rdev) {return -EIO ; } -static int bad_inode_rename2 (struct inode *old_dir,struct dentry *old_dentry, +static int bad_inode_rename2 (struct user_namespace *mnt_userns, +struct inode *old_dir,struct dentry *old_dentry,struct inode *new_dir,struct dentry *new_dentry,unsigned int flags) {
@@ -86,18 +89,21 @@ static int bad_inode_readlink(struct dentry *dentry, char __user *buffer,return -EIO ; } -static int bad_inode_permission (struct inode *inode,int mask) +static int bad_inode_permission (struct user_namespace *mnt_userns, +struct inode *inode,int mask) {return -EIO ; } -static int bad_inode_getattr (const struct path *path,struct kstat *stat, +static int bad_inode_getattr (struct user_namespace *mnt_userns, +const struct path *path,struct kstat *stat,u32 request_mask,unsigned int query_flags) {return -EIO ; } -static int bad_inode_setattr (struct dentry *direntry,struct iattr *attrs) +static int bad_inode_setattr (struct user_namespace *mnt_userns, +struct dentry *direntry,struct iattr *attrs) {return -EIO ; }
@@ -140,13 +146,15 @@ static int bad_inode_atomic_open(struct inode *inode, struct dentry *dentry,return -EIO ; } -static int bad_inode_tmpfile (struct inode *inode,struct dentry *dentry, +static int bad_inode_tmpfile (struct user_namespace *mnt_userns, +struct inode *inode,struct dentry *dentry,umode_t mode) {return -EIO ; } -static int bad_inode_set_acl (struct inode *inode,struct posix_acl *acl, +static int bad_inode_set_acl (struct user_namespace *mnt_userns, +struct inode *inode,struct posix_acl *acl,int type) {return -EIO ;
fs/bfs/dir.c +5 -5
@@ -75,8 +75,8 @@ const struct file_operations bfs_dir_operations = { .llseek = generic_file_llseek, }; -static int bfs_create (struct inode *dir,struct dentry *dentry,umode_t mode, -bool excl) +static int bfs_create (struct user_namespace *mnt_userns,struct inode *dir, +struct dentry *dentry,umode_t mode,bool excl) {int err;struct inode *inode;
@@ -199,9 +199,9 @@ static int bfs_unlink(struct inode *dir, struct dentry *dentry)return error; } -static int bfs_rename (struct inode *old_dir,struct dentry *old_dentry, -struct inode *new_dir,struct dentry *new_dentry, -unsigned int flags) +static int bfs_rename (struct user_namespace *mnt_userns,struct inode *old_dir, +struct dentry *old_dentry,struct inode *new_dir, +struct dentry *new_dentry,unsigned int flags) {struct inode *old_inode, *new_inode;struct buffer_head *old_bh, *new_bh;
fs/btrfs/acl.c +2 -1
@@ -107,7 +107,8 @@ static int __btrfs_set_acl(struct btrfs_trans_handle *trans,return ret; } -int btrfs_set_acl (struct inode *inode,struct posix_acl *acl,int type) +int btrfs_set_acl (struct user_namespace *mnt_userns,struct inode *inode, +struct posix_acl *acl,int type) {int ret;umode_t old_mode = inode->i_mode;
fs/btrfs/ctree.h +2 -1
@@ -3625,7 +3625,8 @@ static inline int __btrfs_fs_compat_ro(struct btrfs_fs_info *fs_info, u64 flag)/* acl.c */ #ifdef CONFIG_BTRFS_FS_POSIX_ACL struct posix_acl *btrfs_get_acl (struct inode *inode,int type); -int btrfs_set_acl (struct inode *inode,struct posix_acl *acl,int type); +int btrfs_set_acl (struct user_namespace *mnt_userns,struct inode *inode, +struct posix_acl *acl,int type);int btrfs_init_acl (struct btrfs_trans_handle *trans,struct inode *inode,struct inode *dir);#else
fs/btrfs/inode.c +19 -14
@@ -5045,7 +5045,8 @@ static int btrfs_setsize(struct inode *inode, struct iattr *attr)return ret; } -static int btrfs_setattr (struct dentry *dentry,struct iattr *attr) +static int btrfs_setattr (struct user_namespace *mnt_userns,struct dentry *dentry, +struct iattr *attr) {struct inode *inode =d_inode (dentry);struct btrfs_root *root =BTRFS_I (inode)->root;
@@ -6352,8 +6353,8 @@ static int btrfs_add_nondir(struct btrfs_trans_handle *trans,return err; } -static int btrfs_mknod (struct inode *dir,struct dentry *dentry, -umode_t mode,dev_t rdev) +static int btrfs_mknod (struct user_namespace *mnt_userns,struct inode *dir, +struct dentry *dentry,umode_t mode,dev_t rdev) {struct btrfs_fs_info *fs_info =btrfs_sb (dir->i_sb);struct btrfs_trans_handle *trans;
@@ -6416,8 +6417,8 @@ static int btrfs_mknod(struct inode *dir, struct dentry *dentry,return err; } -static int btrfs_create (struct inode *dir,struct dentry *dentry, -umode_t mode,bool excl) +static int btrfs_create (struct user_namespace *mnt_userns,struct inode *dir, +struct dentry *dentry,umode_t mode,bool excl) {struct btrfs_fs_info *fs_info =btrfs_sb (dir->i_sb);struct btrfs_trans_handle *trans;
@@ -6561,7 +6562,8 @@ static int btrfs_link(struct dentry *old_dentry, struct inode *dir,return err; } -static int btrfs_mkdir (struct inode *dir,struct dentry *dentry,umode_t mode) +static int btrfs_mkdir (struct user_namespace *mnt_userns,struct inode *dir, +struct dentry *dentry,umode_t mode) {struct btrfs_fs_info *fs_info =btrfs_sb (dir->i_sb);struct inode *inode =NULL ;
@@ -8816,7 +8818,8 @@ int __init btrfs_init_cachep(void)return -ENOMEM ; } -static int btrfs_getattr (const struct path *path,struct kstat *stat, +static int btrfs_getattr (struct user_namespace *mnt_userns, +const struct path *path,struct kstat *stat,u32 request_mask,unsigned int flags) {u64 delalloc_bytes;
@@ -9333,9 +9336,9 @@ static int btrfs_rename(struct inode *old_dir, struct dentry *old_dentry,return ret; } -static int btrfs_rename2 (struct inode *old_dir,struct dentry *old_dentry, -struct inode *new_dir,struct dentry *new_dentry, -unsigned int flags) +static int btrfs_rename2 (struct user_namespace *mnt_userns,struct inode *old_dir, +struct dentry *old_dentry,struct inode *new_dir, +struct dentry *new_dentry,unsigned int flags) {if (flags & ~(RENAME_NOREPLACE |RENAME_EXCHANGE |RENAME_WHITEOUT ))return -EINVAL ;
@@ -9543,8 +9546,8 @@ int btrfs_start_delalloc_roots(struct btrfs_fs_info *fs_info, u64 nr,return ret; } -static int btrfs_symlink (struct inode *dir,struct dentry *dentry, -const char *symname) +static int btrfs_symlink (struct user_namespace *mnt_userns,struct inode *dir, +struct dentry *dentry,const char *symname) {struct btrfs_fs_info *fs_info =btrfs_sb (dir->i_sb);struct btrfs_trans_handle *trans;
@@ -9878,7 +9881,8 @@ static int btrfs_set_page_dirty(struct page *page)return __set_page_dirty_nobuffers (page); } -static int btrfs_permission (struct inode *inode,int mask) +static int btrfs_permission (struct user_namespace *mnt_userns, +struct inode *inode,int mask) {struct btrfs_root *root =BTRFS_I (inode)->root;umode_t mode = inode->i_mode;
@@ -9893,7 +9897,8 @@ static int btrfs_permission(struct inode *inode, int mask)return generic_permission (&init_user_ns, inode, mask); } -static int btrfs_tmpfile (struct inode *dir,struct dentry *dentry,umode_t mode) +static int btrfs_tmpfile (struct user_namespace *mnt_userns,struct inode *dir, +struct dentry *dentry,umode_t mode) {struct btrfs_fs_info *fs_info =btrfs_sb (dir->i_sb);struct btrfs_trans_handle *trans;
fs/ceph/acl.c +2 -1
@@ -82,7 +82,8 @@ struct posix_acl *ceph_get_acl(struct inode *inode, int type)return acl; } -int ceph_set_acl (struct inode *inode,struct posix_acl *acl,int type) +int ceph_set_acl (struct user_namespace *mnt_userns,struct inode *inode, +struct posix_acl *acl,int type) {int ret =0 , size =0 ;const char *name =NULL ;
fs/ceph/dir.c +12 -11
@@ -823,8 +823,8 @@ int ceph_handle_notrace_create(struct inode *dir, struct dentry *dentry)return PTR_ERR (result); } -static int ceph_mknod (struct inode *dir,struct dentry *dentry, -umode_t mode,dev_t rdev) +static int ceph_mknod (struct user_namespace *mnt_userns,struct inode *dir, +struct dentry *dentry,umode_t mode,dev_t rdev) {struct ceph_mds_client *mdsc =ceph_sb_to_mdsc (dir->i_sb);struct ceph_mds_request *req;
@@ -878,14 +878,14 @@ static int ceph_mknod(struct inode *dir, struct dentry *dentry,return err; } -static int ceph_create (struct inode *dir,struct dentry *dentry,umode_t mode, -bool excl) +static int ceph_create (struct user_namespace *mnt_userns,struct inode *dir, +struct dentry *dentry,umode_t mode,bool excl) { -return ceph_mknod (dir, dentry, mode,0 ); +return ceph_mknod (mnt_userns, dir, dentry, mode,0 ); } -static int ceph_symlink (struct inode *dir,struct dentry *dentry, -const char *dest) +static int ceph_symlink (struct user_namespace *mnt_userns,struct inode *dir, +struct dentry *dentry,const char *dest) {struct ceph_mds_client *mdsc =ceph_sb_to_mdsc (dir->i_sb);struct ceph_mds_request *req;
@@ -937,7 +937,8 @@ static int ceph_symlink(struct inode *dir, struct dentry *dentry,return err; } -static int ceph_mkdir (struct inode *dir,struct dentry *dentry,umode_t mode) +static int ceph_mkdir (struct user_namespace *mnt_userns,struct inode *dir, +struct dentry *dentry,umode_t mode) {struct ceph_mds_client *mdsc =ceph_sb_to_mdsc (dir->i_sb);struct ceph_mds_request *req;
@@ -1183,9 +1184,9 @@ static int ceph_unlink(struct inode *dir, struct dentry *dentry)return err; } -static int ceph_rename (struct inode *old_dir,struct dentry *old_dentry, -struct inode *new_dir,struct dentry *new_dentry, -unsigned int flags) +static int ceph_rename (struct user_namespace *mnt_userns,struct inode *old_dir, +struct dentry *old_dentry,struct inode *new_dir, +struct dentry *new_dentry,unsigned int flags) {struct ceph_mds_client *mdsc =ceph_sb_to_mdsc (old_dir->i_sb);struct ceph_mds_request *req;
fs/ceph/inode.c +6 -4
@@ -2238,7 +2238,8 @@ int __ceph_setattr(struct inode *inode, struct iattr *attr)/* * setattr */ -int ceph_setattr (struct dentry *dentry,struct iattr *attr) +int ceph_setattr (struct user_namespace *mnt_userns,struct dentry *dentry, +struct iattr *attr) {struct inode *inode =d_inode (dentry);struct ceph_fs_client *fsc =ceph_inode_to_client (inode);
@@ -2321,7 +2322,8 @@ int __ceph_do_getattr(struct inode *inode, struct page *locked_page,* Check inode permissions. We verify we have a valid value for * the AUTH cap, then call the generic handler. */ -int ceph_permission (struct inode *inode,int mask) +int ceph_permission (struct user_namespace *mnt_userns,struct inode *inode, +int mask) {int err;
@@ -2368,8 +2370,8 @@ static int statx_to_caps(u32 want, umode_t mode)* Get all the attributes. If we have sufficient caps for the requested attrs, * then we can avoid talking to the MDS at all. */ -int ceph_getattr (const struct path *path,struct kstat *stat, -u32 request_mask,unsigned int flags) +int ceph_getattr (struct user_namespace *mnt_userns,const struct path *path, +struct kstat *stat,u32 request_mask,unsigned int flags) {struct inode *inode =d_inode (path->dentry);struct ceph_inode_info *ci =ceph_inode (inode);
fs/ceph/super.h +8 -4
@@ -973,10 +973,13 @@ static inline int ceph_do_getattr(struct inode *inode, int mask, bool force) {return __ceph_do_getattr (inode,NULL , mask, force); } -extern int ceph_permission (struct inode *inode,int mask); +extern int ceph_permission (struct user_namespace *mnt_userns, +struct inode *inode,int mask);extern int __ceph_setattr (struct inode *inode,struct iattr *attr); -extern int ceph_setattr (struct dentry *dentry,struct iattr *attr); -extern int ceph_getattr (const struct path *path,struct kstat *stat, +extern int ceph_setattr (struct user_namespace *mnt_userns, +struct dentry *dentry,struct iattr *attr); +extern int ceph_getattr (struct user_namespace *mnt_userns, +const struct path *path,struct kstat *stat,u32 request_mask,unsigned int flags);/* xattr.c */
@@ -1037,7 +1040,8 @@ void ceph_release_acl_sec_ctx(struct ceph_acl_sec_ctx *as_ctx);#ifdef CONFIG_CEPH_FS_POSIX_ACL struct posix_acl *ceph_get_acl (struct inode *,int ); -int ceph_set_acl (struct inode *inode,struct posix_acl *acl,int type); +int ceph_set_acl (struct user_namespace *mnt_userns, +struct inode *inode,struct posix_acl *acl,int type);int ceph_pre_init_acls (struct inode *dir,umode_t *mode,struct ceph_acl_sec_ctx *as_ctx); void ceph_init_inode_acls(struct inode *inode,
fs/cifs/cifsfs.c +2 -1
@@ -305,7 +305,8 @@ static long cifs_fallocate(struct file *file, int mode, loff_t off, loff_t len)return -EOPNOTSUPP ; } -static int cifs_permission (struct inode *inode,int mask) +static int cifs_permission (struct user_namespace *mnt_userns, +struct inode *inode,int mask) {struct cifs_sb_info *cifs_sb;
fs/cifs/cifsfs.h +15 -10
@@ -62,19 +62,22 @@ 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 inode *,struct dentry *,umode_t , -bool excl); +extern int cifs_create (struct user_namespace *,struct inode *, +struct dentry *,umode_t ,bool excl);extern int cifs_atomic_open (struct inode *,struct dentry *,struct file *,unsigned ,umode_t );extern struct dentry *cifs_lookup (struct inode *,struct dentry *,unsigned int );extern int cifs_unlink (struct inode *dir,struct dentry *dentry);extern int cifs_hardlink (struct dentry *,struct inode *,struct dentry *); -extern int cifs_mknod (struct inode *,struct dentry *,umode_t ,dev_t ); -extern int cifs_mkdir (struct inode *,struct dentry *,umode_t ); +extern int cifs_mknod (struct user_namespace *,struct inode *,struct dentry *, +umode_t ,dev_t ); +extern int cifs_mkdir (struct user_namespace *,struct inode *,struct dentry *, +umode_t );extern int cifs_rmdir (struct inode *,struct dentry *); -extern int cifs_rename2 (struct inode *,struct dentry *,struct inode *, -struct dentry *,unsigned int ); +extern int cifs_rename2 (struct user_namespace *,struct inode *, +struct dentry *,struct inode *,struct dentry *, +unsigned int );extern int cifs_revalidate_file_attr (struct file *filp);extern int cifs_revalidate_dentry_attr (struct dentry *);extern int cifs_revalidate_file (struct file *filp);
@@ -82,8 +85,10 @@ extern int cifs_revalidate_dentry(struct dentry *);extern int cifs_invalidate_mapping (struct inode *inode);extern int cifs_revalidate_mapping (struct inode *inode);extern int cifs_zap_mapping (struct inode *inode); -extern int cifs_getattr (const struct path *,struct kstat *,u32 ,unsigned int ); -extern int cifs_setattr (struct dentry *,struct iattr *); +extern int cifs_getattr (struct user_namespace *,const struct path *, +struct kstat *,u32 ,unsigned int ); +extern int cifs_setattr (struct user_namespace *,struct dentry *, +struct iattr *);extern int cifs_fiemap (struct inode *,struct fiemap_extent_info *,u64 start,u64 len);
@@ -132,8 +137,8 @@ extern struct vfsmount *cifs_dfs_d_automount(struct path *path);/* Functions related to symlinks */ extern const char *cifs_get_link (struct dentry *,struct inode *,struct delayed_call *); -extern int cifs_symlink (struct inode *inode,struct dentry *direntry, -const char *symname); +extern int cifs_symlink (struct user_namespace *mnt_userns,struct inode *inode, +struct dentry *direntry,const char *symname);#ifdef CONFIG_CIFS_XATTR extern const struct xattr_handler *cifs_xattr_handlers[];
fs/cifs/dir.c +4 -4
@@ -567,8 +567,8 @@ cifs_atomic_open(struct inode *inode, struct dentry *direntry,return rc; } -int cifs_create (struct inode *inode,struct dentry *direntry,umode_t mode, -bool excl) +int cifs_create (struct user_namespace *mnt_userns,struct inode *inode, +struct dentry *direntry,umode_t mode,bool excl) {int rc;unsigned int xid =get_xid ();
@@ -611,8 +611,8 @@ int cifs_create(struct inode *inode, struct dentry *direntry, umode_t mode,return rc; } -int cifs_mknod (struct inode *inode,struct dentry *direntry,umode_t mode, -dev_t device_number) +int cifs_mknod (struct user_namespace *mnt_userns,struct inode *inode, +struct dentry *direntry,umode_t mode,dev_t device_number) {int rc = -EPERM ;unsigned int xid;
fs/cifs/inode.c +9 -7
@@ -1857,7 +1857,8 @@ cifs_posix_mkdir(struct inode *inode, struct dentry *dentry, umode_t mode, goto posix_mkdir_out; } -int cifs_mkdir (struct inode *inode,struct dentry *direntry,umode_t mode) +int cifs_mkdir (struct user_namespace *mnt_userns,struct inode *inode, +struct dentry *direntry,umode_t mode) {int rc =0 ;unsigned int xid;
@@ -2067,9 +2068,9 @@ cifs_do_rename(const unsigned int xid, struct dentry *from_dentry, }int -cifs_rename2 (struct inode *source_dir,struct dentry *source_dentry, -struct inode *target_dir,struct dentry *target_dentry, -unsigned int flags) +cifs_rename2 (struct user_namespace *mnt_userns,struct inode *source_dir, +struct dentry *source_dentry,struct inode *target_dir, +struct dentry *target_dentry,unsigned int flags) {char *from_name =NULL ;char *to_name =NULL ;
@@ -2370,8 +2371,8 @@ int cifs_revalidate_dentry(struct dentry *dentry)return cifs_revalidate_mapping (inode); } -int cifs_getattr (const struct path *path,struct kstat *stat, -u32 request_mask,unsigned int flags) +int cifs_getattr (struct user_namespace *mnt_userns,const struct path *path, +struct kstat *stat,u32 request_mask,unsigned int flags) {struct dentry *dentry = path->dentry;struct cifs_sb_info *cifs_sb =CIFS_SB (dentry->d_sb);
@@ -2923,7 +2924,8 @@ cifs_setattr_nounix(struct dentry *direntry, struct iattr *attrs) }int -cifs_setattr (struct dentry *direntry,struct iattr *attrs) +cifs_setattr (struct user_namespace *mnt_userns,struct dentry *direntry, +struct iattr *attrs) {struct cifs_sb_info *cifs_sb =CIFS_SB (direntry->d_sb);struct cifs_tcon *pTcon =cifs_sb_master_tcon (cifs_sb);
fs/cifs/link.c +2 -1
@@ -661,7 +661,8 @@ cifs_get_link(struct dentry *direntry, struct inode *inode, }int -cifs_symlink (struct inode *inode,struct dentry *direntry,const char *symname) +cifs_symlink (struct user_namespace *mnt_userns,struct inode *inode, +struct dentry *direntry,const char *symname) {int rc = -EOPNOTSUPP ;unsigned int xid;
fs/coda/coda_linux.h +5 -3
@@ -46,10 +46,12 @@ extern const struct file_operations coda_ioctl_operations;/* operations shared over more than one file */ int coda_open (struct inode *i,struct file *f);int coda_release (struct inode *i,struct file *f); -int coda_permission (struct inode *inode,int mask); +int coda_permission (struct user_namespace *mnt_userns,struct inode *inode, +int mask);int coda_revalidate_inode (struct inode *); -int coda_getattr (const struct path *,struct kstat *,u32 ,unsigned int ); -int coda_setattr (struct dentry *,struct iattr *); +int coda_getattr (struct user_namespace *,const struct path *,struct kstat *, +u32 ,unsigned int ); +int coda_setattr (struct user_namespace *,struct dentry *,struct iattr *);/* this file: heloers */ char *coda_f2s (struct CodaFid *f);
fs/coda/dir.c +11 -7
@@ -73,7 +73,8 @@ static struct dentry *coda_lookup(struct inode *dir, struct dentry *entry, unsig } -int coda_permission (struct inode *inode,int mask) +int coda_permission (struct user_namespace *mnt_userns,struct inode *inode, +int mask) {int error;
@@ -132,7 +133,8 @@ static inline void coda_dir_drop_nlink(struct inode *dir) }/* creation routines: create, mknod, mkdir, link, symlink */ -static int coda_create (struct inode *dir,struct dentry *de,umode_t mode,bool excl) +static int coda_create (struct user_namespace *mnt_userns,struct inode *dir, +struct dentry *de,umode_t mode,bool excl) {int error;const char *name=de->d_name.name;
@@ -164,7 +166,8 @@ static int coda_create(struct inode *dir, struct dentry *de, umode_t mode, boolreturn error; } -static int coda_mkdir (struct inode *dir,struct dentry *de,umode_t mode) +static int coda_mkdir (struct user_namespace *mnt_userns,struct inode *dir, +struct dentry *de,umode_t mode) {struct inode *inode;struct coda_vattr attrs;
@@ -225,7 +228,8 @@ static int coda_link(struct dentry *source_de, struct inode *dir_inode, } -static int coda_symlink (struct inode *dir_inode,struct dentry *de, +static int coda_symlink (struct user_namespace *mnt_userns, +struct inode *dir_inode,struct dentry *de,const char *symname) {const char *name = de->d_name.name;
@@ -291,9 +295,9 @@ static int coda_rmdir(struct inode *dir, struct dentry *de) }/* rename */ -static int coda_rename (struct inode *old_dir,struct dentry *old_dentry, -struct inode *new_dir,struct dentry *new_dentry, -unsigned int flags) +static int coda_rename (struct user_namespace *mnt_userns,struct inode *old_dir, +struct dentry *old_dentry,struct inode *new_dir, +struct dentry *new_dentry,unsigned int flags) {const char *old_name = old_dentry->d_name.name;const char *new_name = new_dentry->d_name.name;
fs/coda/inode.c +4 -3
@@ -251,8 +251,8 @@ static void coda_evict_inode(struct inode *inode)coda_cache_clear_inode (inode); } -int coda_getattr (const struct path *path,struct kstat *stat, -u32 request_mask,unsigned int flags) +int coda_getattr (struct user_namespace *mnt_userns,const struct path *path, +struct kstat *stat,u32 request_mask,unsigned int flags) {int err =coda_revalidate_inode (d_inode (path->dentry));if (!err)
@@ -260,7 +260,8 @@ int coda_getattr(const struct path *path, struct kstat *stat,return err; } -int coda_setattr (struct dentry *de,struct iattr *iattr) +int coda_setattr (struct user_namespace *mnt_userns,struct dentry *de, +struct iattr *iattr) {struct inode *inode =d_inode (de);struct coda_vattr vattr;
fs/coda/pioctl.c +4 -2
@@ -24,7 +24,8 @@#include "coda_linux.h" /* pioctl ops */ -static int coda_ioctl_permission (struct inode *inode,int mask); +static int coda_ioctl_permission (struct user_namespace *mnt_userns, +struct inode *inode,int mask);static long coda_pioctl (struct file *filp,unsigned int cmd,unsigned long user_data);
@@ -40,7 +41,8 @@ const struct file_operations coda_ioctl_operations = { };/* the coda pioctl inode ops */ -static int coda_ioctl_permission (struct inode *inode,int mask) +static int coda_ioctl_permission (struct user_namespace *mnt_userns, +struct inode *inode,int mask) {return (mask &MAY_EXEC ) ? -EACCES :0 ; }
fs/configfs/configfs_internal.h +4 -2
@@ -79,7 +79,8 @@ extern void configfs_hash_and_remove(struct dentry * dir, const char * name);extern const unsigned char *configfs_get_name (struct configfs_dirent *sd);extern void configfs_drop_dentry (struct configfs_dirent *sd,struct dentry *parent); -extern int configfs_setattr (struct dentry *dentry,struct iattr *iattr); +extern int configfs_setattr (struct user_namespace *mnt_userns, +struct dentry *dentry,struct iattr *iattr);extern struct dentry *configfs_pin_fs (void );extern void configfs_release_fs (void );
@@ -92,7 +93,8 @@ extern const struct inode_operations configfs_root_inode_operations;extern const struct inode_operations configfs_symlink_inode_operations;extern const struct dentry_operations configfs_dentry_ops; -extern int configfs_symlink (struct inode *dir,struct dentry *dentry, +extern int configfs_symlink (struct user_namespace *mnt_userns, +struct inode *dir,struct dentry *dentry,const char *symname);extern int configfs_unlink (struct inode *dir,struct dentry *dentry);
fs/configfs/dir.c +2 -1
@@ -1268,7 +1268,8 @@ int configfs_depend_item_unlocked(struct configfs_subsystem *caller_subsys, }EXPORT_SYMBOL (configfs_depend_item_unlocked); -static int configfs_mkdir (struct inode *dir,struct dentry *dentry,umode_t mode) +static int configfs_mkdir (struct user_namespace *mnt_userns,struct inode *dir, +struct dentry *dentry,umode_t mode) {int ret =0 ;int module_got =0 ;
fs/configfs/inode.c +3 -2
@@ -40,7 +40,8 @@ static const struct inode_operations configfs_inode_operations ={ .setattr = configfs_setattr, }; -int configfs_setattr (struct dentry * dentry,struct iattr * iattr) +int configfs_setattr (struct user_namespace *mnt_userns,struct dentry *dentry, +struct iattr *iattr) {struct inode * inode =d_inode (dentry);struct configfs_dirent * sd = dentry->d_fsdata;
@@ -67,7 +68,7 @@ int configfs_setattr(struct dentry * dentry, struct iattr * iattr) }/* attributes were changed atleast once in past */ - error =simple_setattr (dentry, iattr); + error =simple_setattr (mnt_userns, dentry, iattr);if (error)return error;
fs/configfs/symlink.c +2 -1
@@ -139,7 +139,8 @@ static int get_target(const char *symname, struct path *path, } -int configfs_symlink (struct inode *dir,struct dentry *dentry,const char *symname) +int configfs_symlink (struct user_namespace *mnt_userns,struct inode *dir, +struct dentry *dentry,const char *symname) {int ret;struct path path;
fs/debugfs/inode.c +5 -4
@@ -42,13 +42,14 @@ static unsigned int debugfs_allow = DEFAULT_DEBUGFS_ALLOW_BITS;* so that we can use the file mode as part of a heuristic to determine whether * to lock down individual files. */ -static int debugfs_setattr (struct dentry *dentry,struct iattr *ia) +static int debugfs_setattr (struct user_namespace *mnt_userns, +struct dentry *dentry,struct iattr *ia) {int ret =security_locked_down (LOCKDOWN_DEBUGFS );if (ret && (ia->ia_valid & (ATTR_MODE |ATTR_UID |ATTR_GID )))return ret; -return simple_setattr (dentry, ia); +return simple_setattr (&init_user_ns, dentry, ia); }static const struct inode_operations debugfs_file_inode_operations = {
@@ -775,8 +776,8 @@ struct dentry *debugfs_rename(struct dentry *old_dir, struct dentry *old_dentry,take_dentry_name_snapshot (&old_name, old_dentry); - error =simple_rename (d_inode (old_dir), old_dentry,d_inode (new_dir), - dentry,0 ); + error =simple_rename (&init_user_ns,d_inode (old_dir), old_dentry, +d_inode (new_dir), dentry,0 );if (error) {release_dentry_name_snapshot (&old_name); goto exit;
fs/ecryptfs/inode.c +19 -11
@@ -257,7 +257,8 @@ int ecryptfs_initialize_file(struct dentry *ecryptfs_dentry,* Returns zero on success; non-zero on error condition */ static int -ecryptfs_create (struct inode *directory_inode,struct dentry *ecryptfs_dentry, +ecryptfs_create (struct user_namespace *mnt_userns, +struct inode *directory_inode,struct dentry *ecryptfs_dentry,umode_t mode,bool excl) {struct inode *ecryptfs_inode;
@@ -463,7 +464,8 @@ static int ecryptfs_unlink(struct inode *dir, struct dentry *dentry)return ecryptfs_do_unlink (dir, dentry,d_inode (dentry)); } -static int ecryptfs_symlink (struct inode *dir,struct dentry *dentry, +static int ecryptfs_symlink (struct user_namespace *mnt_userns, +struct inode *dir,struct dentry *dentry,const char *symname) {int rc;
@@ -502,7 +504,8 @@ static int ecryptfs_symlink(struct inode *dir, struct dentry *dentry,return rc; } -static int ecryptfs_mkdir (struct inode *dir,struct dentry *dentry,umode_t mode) +static int ecryptfs_mkdir (struct user_namespace *mnt_userns,struct inode *dir, +struct dentry *dentry,umode_t mode) {int rc;struct dentry *lower_dentry;
@@ -559,7 +562,8 @@ static int ecryptfs_rmdir(struct inode *dir, struct dentry *dentry) }static int -ecryptfs_mknod (struct inode *dir,struct dentry *dentry,umode_t mode,dev_t dev) +ecryptfs_mknod (struct user_namespace *mnt_userns,struct inode *dir, +struct dentry *dentry,umode_t mode,dev_t dev) {int rc;struct dentry *lower_dentry;
@@ -584,9 +588,9 @@ ecryptfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev }static int -ecryptfs_rename (struct inode *old_dir,struct dentry *old_dentry, -struct inode *new_dir,struct dentry *new_dentry, -unsigned int flags) +ecryptfs_rename (struct user_namespace *mnt_userns,struct inode *old_dir, +struct dentry *old_dentry,struct inode *new_dir, +struct dentry *new_dentry,unsigned int flags) {int rc;struct dentry *lower_old_dentry;
@@ -874,7 +878,8 @@ int ecryptfs_truncate(struct dentry *dentry, loff_t new_length) }static int -ecryptfs_permission (struct inode *inode,int mask) +ecryptfs_permission (struct user_namespace *mnt_userns,struct inode *inode, +int mask) {return inode_permission (&init_user_ns,ecryptfs_inode_to_lower (inode), mask);
@@ -892,7 +897,8 @@ ecryptfs_permission(struct inode *inode, int mask)* All other metadata changes will be passed right to the lower filesystem, * and we will just update our inode to look like the lower. */ -static int ecryptfs_setattr (struct dentry *dentry,struct iattr *ia) +static int ecryptfs_setattr (struct user_namespace *mnt_userns, +struct dentry *dentry,struct iattr *ia) {int rc =0 ;struct dentry *lower_dentry;
@@ -979,7 +985,8 @@ static int ecryptfs_setattr(struct dentry *dentry, struct iattr *ia)return rc; } -static int ecryptfs_getattr_link (const struct path *path,struct kstat *stat, +static int ecryptfs_getattr_link (struct user_namespace *mnt_userns, +const struct path *path,struct kstat *stat,u32 request_mask,unsigned int flags) {struct dentry *dentry = path->dentry;
@@ -1004,7 +1011,8 @@ static int ecryptfs_getattr_link(const struct path *path, struct kstat *stat,return rc; } -static int ecryptfs_getattr (const struct path *path,struct kstat *stat, +static int ecryptfs_getattr (struct user_namespace *mnt_userns, +const struct path *path,struct kstat *stat,u32 request_mask,unsigned int flags) {struct dentry *dentry = path->dentry;
fs/efivarfs/inode.c +2 -2
@@ -66,8 +66,8 @@ bool efivarfs_valid_name(const char *str, int len)return uuid_is_valid (s); } -static int efivarfs_create (struct inode *dir,struct dentry *dentry, -umode_t mode,bool excl) +static int efivarfs_create (struct user_namespace *mnt_userns,struct inode *dir, +struct dentry *dentry,umode_t mode,bool excl) {struct inode *inode =NULL ;struct efivar_entry *var;
fs/erofs/inode.c +3 -2
@@ -331,8 +331,9 @@ struct inode *erofs_iget(struct super_block *sb,return inode; } -int erofs_getattr (const struct path *path,struct kstat *stat, -u32 request_mask,unsigned int query_flags) +int erofs_getattr (struct user_namespace *mnt_userns,const struct path *path, +struct kstat *stat,u32 request_mask, +unsigned int query_flags) {struct inode *const inode =d_inode (path->dentry);
fs/erofs/internal.h +3 -2
@@ -373,8 +373,9 @@ extern const struct inode_operations erofs_symlink_iops;extern const struct inode_operations erofs_fast_symlink_iops;struct inode *erofs_iget (struct super_block *sb,erofs_nid_t nid,bool dir); -int erofs_getattr (const struct path *path,struct kstat *stat, -u32 request_mask,unsigned int query_flags); +int erofs_getattr (struct user_namespace *mnt_userns,const struct path *path, +struct kstat *stat,u32 request_mask, +unsigned int query_flags);/* namei.c */ extern const struct inode_operations erofs_dir_iops;
fs/exfat/exfat_fs.h +5 -3
@@ -416,9 +416,11 @@ int exfat_count_used_clusters(struct super_block *sb, unsigned int *ret_count);extern const struct file_operations exfat_file_operations;int __exfat_truncate (struct inode *inode,loff_t new_size);void exfat_truncate (struct inode *inode,loff_t size); -int exfat_setattr (struct dentry *dentry,struct iattr *attr); -int exfat_getattr (const struct path *path,struct kstat *stat, -unsigned int request_mask,unsigned int query_flags); +int exfat_setattr (struct user_namespace *mnt_userns,struct dentry *dentry, +struct iattr *attr); +int exfat_getattr (struct user_namespace *mnt_userns,const struct path *path, +struct kstat *stat,unsigned int request_mask, +unsigned int query_flags);int exfat_file_fsync (struct file *file,loff_t start,loff_t end,int datasync);/* namei.c */
fs/exfat/file.c +5 -3
@@ -267,8 +267,9 @@ void exfat_truncate(struct inode *inode, loff_t size)mutex_unlock (&sbi->s_lock); } -int exfat_getattr (const struct path *path,struct kstat *stat, -unsigned int request_mask,unsigned int query_flags) +int exfat_getattr (struct user_namespace *mnt_uerns,const struct path *path, +struct kstat *stat,unsigned int request_mask, +unsigned int query_flags) {struct inode *inode =d_backing_inode (path->dentry);struct exfat_inode_info *ei =EXFAT_I (inode);
@@ -282,7 +283,8 @@ int exfat_getattr(const struct path *path, struct kstat *stat,return 0 ; } -int exfat_setattr (struct dentry *dentry,struct iattr *attr) +int exfat_setattr (struct user_namespace *mnt_userns,struct dentry *dentry, +struct iattr *attr) {struct exfat_sb_info *sbi =EXFAT_SB (dentry->d_sb);struct inode *inode = dentry->d_inode;
fs/exfat/namei.c +8 -6
@@ -541,8 +541,8 @@ static int exfat_add_entry(struct inode *inode, const char *path,return ret; } -static int exfat_create (struct inode *dir,struct dentry *dentry,umode_t mode, -bool excl) +static int exfat_create (struct user_namespace *mnt_userns,struct inode *dir, +struct dentry *dentry,umode_t mode,bool excl) {struct super_block *sb = dir->i_sb;struct inode *inode;
@@ -827,7 +827,8 @@ static int exfat_unlink(struct inode *dir, struct dentry *dentry)return err; } -static int exfat_mkdir (struct inode *dir,struct dentry *dentry,umode_t mode) +static int exfat_mkdir (struct user_namespace *mnt_userns,struct inode *dir, +struct dentry *dentry,umode_t mode) {struct super_block *sb = dir->i_sb;struct inode *inode;
@@ -1318,9 +1319,10 @@ static int __exfat_rename(struct inode *old_parent_inode,return ret; } -static int exfat_rename (struct inode *old_dir,struct dentry *old_dentry, -struct inode *new_dir,struct dentry *new_dentry, -unsigned int flags) +static int exfat_rename (struct user_namespace *mnt_userns, +struct inode *old_dir,struct dentry *old_dentry, +struct inode *new_dir,struct dentry *new_dentry, +unsigned int flags) {struct inode *old_inode, *new_inode;struct super_block *sb = old_dir->i_sb;
fs/ext2/acl.c +2 -1
@@ -216,7 +216,8 @@ __ext2_set_acl(struct inode *inode, struct posix_acl *acl, int type)* inode->i_mutex: down */ int -ext2_set_acl (struct inode *inode,struct posix_acl *acl,int type) +ext2_set_acl (struct user_namespace *mnt_userns,struct inode *inode, +struct posix_acl *acl,int type) {int error;int update_mode =0 ;
fs/ext2/acl.h +2 -1
@@ -56,7 +56,8 @@ static inline int ext2_acl_count(size_t size)/* acl.c */ extern struct posix_acl *ext2_get_acl (struct inode *inode,int type); -extern int ext2_set_acl (struct inode *inode,struct posix_acl *acl,int type); +extern int ext2_set_acl (struct user_namespace *mnt_userns,struct inode *inode, +struct posix_acl *acl,int type);extern int ext2_init_acl (struct inode *,struct inode *);#else
fs/ext2/ext2.h +3 -2
@@ -764,8 +764,9 @@ extern struct inode *ext2_iget (struct super_block *, unsigned long);extern int ext2_write_inode (struct inode *,struct writeback_control *);extern void ext2_evict_inode (struct inode *);extern int ext2_get_block (struct inode *,sector_t ,struct buffer_head *,int ); -extern int ext2_setattr (struct dentry *,struct iattr *); -extern int ext2_getattr (const struct path *,struct kstat *,u32 ,unsigned int ); +extern int ext2_setattr (struct user_namespace *,struct dentry *,struct iattr *); +extern int ext2_getattr (struct user_namespace *,const struct path *, +struct kstat *,u32 ,unsigned int );extern void ext2_set_inode_flags (struct inode *inode);extern int ext2_fiemap (struct inode *inode,struct fiemap_extent_info *fieinfo,u64 start,u64 len);
fs/ext2/inode.c +4 -3
@@ -1638,8 +1638,8 @@ int ext2_write_inode(struct inode *inode, struct writeback_control *wbc)return __ext2_write_inode (inode, wbc->sync_mode ==WB_SYNC_ALL ); } -int ext2_getattr (const struct path *path,struct kstat *stat, -u32 request_mask,unsigned int query_flags) +int ext2_getattr (struct user_namespace *mnt_userns,const struct path *path, +struct kstat *stat,u32 request_mask,unsigned int query_flags) {struct inode *inode =d_inode (path->dentry);struct ext2_inode_info *ei =EXT2_I (inode);
@@ -1664,7 +1664,8 @@ int ext2_getattr(const struct path *path, struct kstat *stat,return 0 ; } -int ext2_setattr (struct dentry *dentry,struct iattr *iattr) +int ext2_setattr (struct user_namespace *mnt_userns,struct dentry *dentry, +struct iattr *iattr) {struct inode *inode =d_inode (dentry);int error;
fs/ext2/namei.c +14 -8
@@ -100,7 +100,9 @@ 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 inode * dir,struct dentry * dentry,umode_t mode,bool excl) +static int ext2_create (struct user_namespace * mnt_userns, +struct inode * dir,struct dentry * dentry, +umode_t mode,bool excl) {struct inode *inode;int err;
@@ -118,7 +120,8 @@ static int ext2_create (struct inode * dir, struct dentry * dentry, umode_t modereturn ext2_add_nondir (dentry, inode); } -static int ext2_tmpfile (struct inode *dir,struct dentry *dentry,umode_t mode) +static int ext2_tmpfile (struct user_namespace *mnt_userns,struct inode *dir, +struct dentry *dentry,umode_t mode) {struct inode *inode =ext2_new_inode (dir, mode,NULL );if (IS_ERR (inode))
@@ -131,7 +134,8 @@ static int ext2_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode)return 0 ; } -static int ext2_mknod (struct inode * dir,struct dentry *dentry,umode_t mode,dev_t rdev) +static int ext2_mknod (struct user_namespace * mnt_userns,struct inode * dir, +struct dentry *dentry,umode_t mode,dev_t rdev) {struct inode * inode;int err;
@@ -151,8 +155,8 @@ static int ext2_mknod (struct inode * dir, struct dentry *dentry, umode_t mode,return err; } -static int ext2_symlink (struct inode * dir,struct dentry * dentry, -const char * symname) +static int ext2_symlink (struct user_namespace * mnt_userns,struct inode * dir, +struct dentry * dentry,const char * symname) {struct super_block * sb = dir->i_sb;int err = -ENAMETOOLONG ;
@@ -225,7 +229,8 @@ static int ext2_link (struct dentry * old_dentry, struct inode * dir,return err; } -static int ext2_mkdir (struct inode * dir,struct dentry * dentry,umode_t mode) +static int ext2_mkdir (struct user_namespace * mnt_userns, +struct inode * dir,struct dentry * dentry,umode_t mode) {struct inode * inode;int err;
@@ -315,8 +320,9 @@ static int ext2_rmdir (struct inode * dir, struct dentry *dentry)return err; } -static int ext2_rename (struct inode * old_dir,struct dentry * old_dentry, -struct inode * new_dir,struct dentry * new_dentry, +static int ext2_rename (struct user_namespace * mnt_userns, +struct inode * old_dir,struct dentry * old_dentry, +struct inode * new_dir,struct dentry * new_dentry,unsigned int flags) {struct inode * old_inode =d_inode (old_dentry);
fs/ext4/acl.c +2 -1
@@ -222,7 +222,8 @@ __ext4_set_acl(handle_t *handle, struct inode *inode, int type, }int -ext4_set_acl (struct inode *inode,struct posix_acl *acl,int type) +ext4_set_acl (struct user_namespace *mnt_userns,struct inode *inode, +struct posix_acl *acl,int type) {handle_t *handle;int error, credits, retries =0 ;
fs/ext4/acl.h +2 -1
@@ -56,7 +56,8 @@ static inline int ext4_acl_count(size_t size)/* acl.c */ struct posix_acl *ext4_get_acl (struct inode *inode,int type); -int ext4_set_acl (struct inode *inode,struct posix_acl *acl,int type); +int ext4_set_acl (struct user_namespace *mnt_userns,struct inode *inode, +struct posix_acl *acl,int type);extern int ext4_init_acl (handle_t *,struct inode *,struct inode *);#else /* CONFIG_EXT4_FS_POSIX_ACL */
fs/ext4/ext4.h +6 -3
@@ -2877,11 +2877,14 @@ extern struct inode *__ext4_iget(struct super_block *sb, unsigned long ino, __ext4_iget((sb), (ino), (flags), __func__, __LINE__)extern int ext4_write_inode (struct inode *,struct writeback_control *); -extern int ext4_setattr (struct dentry *,struct iattr *); -extern int ext4_getattr (const struct path *,struct kstat *,u32 ,unsigned int ); +extern int ext4_setattr (struct user_namespace *,struct dentry *, +struct iattr *); +extern int ext4_getattr (struct user_namespace *,const struct path *, +struct kstat *,u32 ,unsigned int );extern void ext4_evict_inode (struct inode *);extern void ext4_clear_inode (struct inode *); -extern int ext4_file_getattr (const struct path *,struct kstat *,u32 ,unsigned int ); +extern int ext4_file_getattr (struct user_namespace *,const struct path *, +struct kstat *,u32 ,unsigned int );extern int ext4_sync_inode (handle_t *,struct inode *);extern void ext4_dirty_inode (struct inode *,int );extern int ext4_change_inode_journal_flag (struct inode *,int );
fs/ext4/inode.c +7 -5
@@ -5319,7 +5319,8 @@ static void ext4_wait_for_tail_page_commit(struct inode *inode)* * Called with inode->i_mutex down. */ -int ext4_setattr (struct dentry *dentry,struct iattr *attr) +int ext4_setattr (struct user_namespace *mnt_userns,struct dentry *dentry, +struct iattr *attr) {struct inode *inode =d_inode (dentry);int error, rc =0 ;
@@ -5535,8 +5536,8 @@ int ext4_setattr(struct dentry *dentry, struct iattr *attr)return error; } -int ext4_getattr (const struct path *path,struct kstat *stat, -u32 request_mask,unsigned int query_flags) +int ext4_getattr (struct user_namespace *mnt_userns,const struct path *path, +struct kstat *stat,u32 request_mask,unsigned int query_flags) {struct inode *inode =d_inode (path->dentry);struct ext4_inode *raw_inode;
@@ -5575,13 +5576,14 @@ int ext4_getattr(const struct path *path, struct kstat *stat,return 0 ; } -int ext4_file_getattr (const struct path *path,struct kstat *stat, +int ext4_file_getattr (struct user_namespace *mnt_userns, +const struct path *path,struct kstat *stat,u32 request_mask,unsigned int query_flags) {struct inode *inode =d_inode (path->dentry);u64 delalloc_blocks; -ext4_getattr (path, stat, request_mask, query_flags); +ext4_getattr (&init_user_ns, path, stat, request_mask, query_flags);/* * If there is inline data in the inode, the inode will normally not
fs/ext4/namei.c +11 -8
@@ -2596,8 +2596,8 @@ 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 inode *dir,struct dentry *dentry,umode_t mode, -bool excl) +static int ext4_create (struct user_namespace *mnt_userns,struct inode *dir, +struct dentry *dentry,umode_t mode,bool excl) {handle_t *handle;struct inode *inode;
@@ -2631,8 +2631,8 @@ static int ext4_create(struct inode *dir, struct dentry *dentry, umode_t mode,return err; } -static int ext4_mknod (struct inode *dir,struct dentry *dentry, -umode_t mode,dev_t rdev) +static int ext4_mknod (struct user_namespace *mnt_userns,struct inode *dir, +struct dentry *dentry,umode_t mode,dev_t rdev) {handle_t *handle;struct inode *inode;
@@ -2665,7 +2665,8 @@ static int ext4_mknod(struct inode *dir, struct dentry *dentry,return err; } -static int ext4_tmpfile (struct inode *dir,struct dentry *dentry,umode_t mode) +static int ext4_tmpfile (struct user_namespace *mnt_userns,struct inode *dir, +struct dentry *dentry,umode_t mode) {handle_t *handle;struct inode *inode;
@@ -2774,7 +2775,8 @@ int ext4_init_new_dir(handle_t *handle, struct inode *dir,return err; } -static int ext4_mkdir (struct inode *dir,struct dentry *dentry,umode_t mode) +static int ext4_mkdir (struct user_namespace *mnt_userns,struct inode *dir, +struct dentry *dentry,umode_t mode) {handle_t *handle;struct inode *inode;
@@ -3292,7 +3294,7 @@ static int ext4_unlink(struct inode *dir, struct dentry *dentry)return retval; } -static int ext4_symlink (struct inode *dir, +static int ext4_symlink (struct user_namespace *mnt_userns,struct inode *dir,struct dentry *dentry,const char *symname) {handle_t *handle;
@@ -4085,7 +4087,8 @@ static int ext4_cross_rename(struct inode *old_dir, struct dentry *old_dentry,return retval; } -static int ext4_rename2 (struct inode *old_dir,struct dentry *old_dentry, +static int ext4_rename2 (struct user_namespace *mnt_userns, +struct inode *old_dir,struct dentry *old_dentry,struct inode *new_dir,struct dentry *new_dentry,unsigned int flags) {
fs/f2fs/acl.c +2 -1
@@ -249,7 +249,8 @@ static int __f2fs_set_acl(struct inode *inode, int type,return error; } -int f2fs_set_acl (struct inode *inode,struct posix_acl *acl,int type) +int f2fs_set_acl (struct user_namespace *mnt_userns,struct inode *inode, +struct posix_acl *acl,int type) {if (unlikely (f2fs_cp_error (F2FS_I_SB (inode))))return -EIO ;
fs/f2fs/acl.h +2 -1
@@ -34,7 +34,8 @@ struct f2fs_acl_header {#ifdef CONFIG_F2FS_FS_POSIX_ACL extern struct posix_acl *f2fs_get_acl (struct inode *,int ); -extern int f2fs_set_acl (struct inode *,struct posix_acl *,int ); +extern int f2fs_set_acl (struct user_namespace *,struct inode *, +struct posix_acl *,int );extern int f2fs_init_acl (struct inode *,struct inode *,struct page *,struct page *);#else
fs/f2fs/f2fs.h +4 -3
@@ -3135,9 +3135,10 @@ void f2fs_truncate_data_blocks(struct dnode_of_data *dn);int f2fs_do_truncate_blocks (struct inode *inode,u64 from,bool lock);int f2fs_truncate_blocks (struct inode *inode,u64 from,bool lock);int f2fs_truncate (struct inode *inode); -int f2fs_getattr (const struct path *path,struct kstat *stat, -u32 request_mask,unsigned int flags); -int f2fs_setattr (struct dentry *dentry,struct iattr *attr); +int f2fs_getattr (struct user_namespace *mnt_userns,const struct path *path, +struct kstat *stat,u32 request_mask,unsigned int flags); +int f2fs_setattr (struct user_namespace *mnt_userns,struct dentry *dentry, +struct iattr *attr);int f2fs_truncate_hole (struct inode *inode,pgoff_t pg_start,pgoff_t pg_end);void f2fs_truncate_data_blocks_range (struct dnode_of_data *dn,int count);int f2fs_precache_extents (struct inode *inode);
fs/f2fs/file.c +4 -3
@@ -783,8 +783,8 @@ int f2fs_truncate(struct inode *inode)return 0 ; } -int f2fs_getattr (const struct path *path,struct kstat *stat, -u32 request_mask,unsigned int query_flags) +int f2fs_getattr (struct user_namespace *mnt_userns,const struct path *path, +struct kstat *stat,u32 request_mask,unsigned int query_flags) {struct inode *inode =d_inode (path->dentry);struct f2fs_inode_info *fi =F2FS_I (inode);
@@ -859,7 +859,8 @@ static void __setattr_copy(struct user_namespace *mnt_userns,#define __setattr_copy setattr_copy#endif -int f2fs_setattr (struct dentry *dentry,struct iattr *attr) +int f2fs_setattr (struct user_namespace *mnt_userns,struct dentry *dentry, +struct iattr *attr) {struct inode *inode =d_inode (dentry);int err;
fs/f2fs/namei.c +12 -9
@@ -314,8 +314,8 @@ static void set_compress_inode(struct f2fs_sb_info *sbi, struct inode *inode, } } -static int f2fs_create (struct inode *dir,struct dentry *dentry,umode_t mode, -bool excl) +static int f2fs_create (struct user_namespace *mnt_userns,struct inode *dir, +struct dentry *dentry,umode_t mode,bool excl) {struct f2fs_sb_info *sbi =F2FS_I_SB (dir);struct inode *inode;
@@ -637,8 +637,8 @@ static const char *f2fs_get_link(struct dentry *dentry,return link; } -static int f2fs_symlink (struct inode *dir,struct dentry *dentry, -const char *symname) +static int f2fs_symlink (struct user_namespace *mnt_userns,struct inode *dir, +struct dentry *dentry,const char *symname) {struct f2fs_sb_info *sbi =F2FS_I_SB (dir);struct inode *inode;
@@ -717,7 +717,8 @@ static int f2fs_symlink(struct inode *dir, struct dentry *dentry,return err; } -static int f2fs_mkdir (struct inode *dir,struct dentry *dentry,umode_t mode) +static int f2fs_mkdir (struct user_namespace *mnt_userns,struct inode *dir, +struct dentry *dentry,umode_t mode) {struct f2fs_sb_info *sbi =F2FS_I_SB (dir);struct inode *inode;
@@ -770,8 +771,8 @@ static int f2fs_rmdir(struct inode *dir, struct dentry *dentry)return -ENOTEMPTY ; } -static int f2fs_mknod (struct inode *dir,struct dentry *dentry, -umode_t mode,dev_t rdev) +static int f2fs_mknod (struct user_namespace *mnt_userns,struct inode *dir, +struct dentry *dentry,umode_t mode,dev_t rdev) {struct f2fs_sb_info *sbi =F2FS_I_SB (dir);struct inode *inode;
@@ -874,7 +875,8 @@ static int __f2fs_tmpfile(struct inode *dir, struct dentry *dentry,return err; } -static int f2fs_tmpfile (struct inode *dir,struct dentry *dentry,umode_t mode) +static int f2fs_tmpfile (struct user_namespace *mnt_userns,struct inode *dir, +struct dentry *dentry,umode_t mode) {struct f2fs_sb_info *sbi =F2FS_I_SB (dir);
@@ -1247,7 +1249,8 @@ static int f2fs_cross_rename(struct inode *old_dir, struct dentry *old_dentry,return err; } -static int f2fs_rename2 (struct inode *old_dir,struct dentry *old_dentry, +static int f2fs_rename2 (struct user_namespace *mnt_userns, +struct inode *old_dir,struct dentry *old_dentry,struct inode *new_dir,struct dentry *new_dentry,unsigned int flags) {
fs/fat/fat.h +4 -2
@@ -397,9 +397,11 @@ extern long fat_generic_ioctl(struct file *filp, unsigned int cmd, unsigned long arg);extern const struct file_operations fat_file_operations;extern const struct inode_operations fat_file_inode_operations; -extern int fat_setattr (struct dentry *dentry,struct iattr *attr); +extern int fat_setattr (struct user_namespace *mnt_userns,struct dentry *dentry, +struct iattr *attr);extern void fat_truncate_blocks (struct inode *inode,loff_t offset); -extern int fat_getattr (const struct path *path,struct kstat *stat, +extern int fat_getattr (struct user_namespace *mnt_userns, +const struct path *path,struct kstat *stat,u32 request_mask,unsigned int flags);extern int fat_file_fsync (struct file *file,loff_t start,loff_t end,int datasync);
fs/fat/file.c +5 -4
@@ -95,7 +95,7 @@ static int fat_ioctl_set_attributes(struct file *file, u32 __user *user_attr) goto out_unlock_inode;/* This MUST be done before doing anything irreversible... */ - err =fat_setattr (file->f_path.dentry, &ia); + err =fat_setattr (file_mnt_user_ns (file), file->f_path.dentry, &ia);if (err) goto out_unlock_inode;
@@ -394,8 +394,8 @@ void fat_truncate_blocks(struct inode *inode, loff_t offset)fat_flush_inodes (inode->i_sb, inode,NULL ); } -int fat_getattr (const struct path *path,struct kstat *stat, -u32 request_mask,unsigned int flags) +int fat_getattr (struct user_namespace *mnt_userns,const struct path *path, +struct kstat *stat,u32 request_mask,unsigned int flags) {struct inode *inode =d_inode (path->dentry);generic_fillattr (&init_user_ns, inode, stat);
@@ -466,7 +466,8 @@ static int fat_allow_set_time(struct msdos_sb_info *sbi, struct inode *inode)/* valid file mode bits */ #define FAT_VALID_MODE (S_IFREG | S_IFDIR | S_IRWXUGO) -int fat_setattr (struct dentry *dentry,struct iattr *attr) +int fat_setattr (struct user_namespace *mnt_userns,struct dentry *dentry, +struct iattr *attr) {struct msdos_sb_info *sbi =MSDOS_SB (dentry->d_sb);struct inode *inode =d_inode (dentry);
fs/fat/namei_msdos.c +6 -4
@@ -261,8 +261,8 @@ static int msdos_add_entry(struct inode *dir, const unsigned char *name, }/***** Create a file */ -static int msdos_create (struct inode *dir,struct dentry *dentry,umode_t mode, -bool excl) +static int msdos_create (struct user_namespace *mnt_userns,struct inode *dir, +struct dentry *dentry,umode_t mode,bool excl) {struct super_block *sb = dir->i_sb;struct inode *inode =NULL ;
@@ -339,7 +339,8 @@ static int msdos_rmdir(struct inode *dir, struct dentry *dentry) }/***** Make a directory */ -static int msdos_mkdir (struct inode *dir,struct dentry *dentry,umode_t mode) +static int msdos_mkdir (struct user_namespace *mnt_userns,struct inode *dir, +struct dentry *dentry,umode_t mode) {struct super_block *sb = dir->i_sb;struct fat_slot_info sinfo;
@@ -593,7 +594,8 @@ static int do_msdos_rename(struct inode *old_dir, unsigned char *old_name, }/***** Rename, a wrapper for rename_same_dir & rename_diff_dir */ -static int msdos_rename (struct inode *old_dir,struct dentry *old_dentry, +static int msdos_rename (struct user_namespace *mnt_userns, +struct inode *old_dir,struct dentry *old_dentry,struct inode *new_dir,struct dentry *new_dentry,unsigned int flags) {
fs/fat/namei_vfat.c +7 -6
@@ -756,8 +756,8 @@ static struct dentry *vfat_lookup(struct inode *dir, struct dentry *dentry,return ERR_PTR (err); } -static int vfat_create (struct inode *dir,struct dentry *dentry,umode_t mode, -bool excl) +static int vfat_create (struct user_namespace *mnt_userns,struct inode *dir, +struct dentry *dentry,umode_t mode,bool excl) {struct super_block *sb = dir->i_sb;struct inode *inode;
@@ -846,7 +846,8 @@ static int vfat_unlink(struct inode *dir, struct dentry *dentry)return err; } -static int vfat_mkdir (struct inode *dir,struct dentry *dentry,umode_t mode) +static int vfat_mkdir (struct user_namespace *mnt_userns,struct inode *dir, +struct dentry *dentry,umode_t mode) {struct super_block *sb = dir->i_sb;struct inode *inode;
@@ -892,9 +893,9 @@ static int vfat_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)return err; } -static int vfat_rename (struct inode *old_dir,struct dentry *old_dentry, -struct inode *new_dir,struct dentry *new_dentry, -unsigned int flags) +static int vfat_rename (struct user_namespace *mnt_userns,struct inode *old_dir, +struct dentry *old_dentry,struct inode *new_dir, +struct dentry *new_dentry,unsigned int flags) {struct buffer_head *dotdot_bh;struct msdos_dir_entry *dotdot_de;
fs/fuse/acl.c +2 -1
@@ -50,7 +50,8 @@ struct posix_acl *fuse_get_acl(struct inode *inode, int type)return acl; } -int fuse_set_acl (struct inode *inode,struct posix_acl *acl,int type) +int fuse_set_acl (struct user_namespace *mnt_userns,struct inode *inode, +struct posix_acl *acl,int type) {struct fuse_conn *fc =get_fuse_conn (inode);const char *name;
fs/fuse/dir.c +21 -16
@@ -605,7 +605,8 @@ static int fuse_create_open(struct inode *dir, struct dentry *entry,return err; } -static int fuse_mknod (struct inode *,struct dentry *,umode_t ,dev_t ); +static int fuse_mknod (struct user_namespace *,struct inode *,struct dentry *, +umode_t ,dev_t );static int fuse_atomic_open (struct inode *dir,struct dentry *entry,struct file *file,unsigned flags,umode_t mode)
@@ -645,7 +646,7 @@ static int fuse_atomic_open(struct inode *dir, struct dentry *entry,return err; mknod: - err =fuse_mknod (dir, entry, mode,0 ); + err =fuse_mknod (&init_user_ns, dir, entry, mode,0 );if (err) goto out_dput; no_open:
@@ -715,8 +716,8 @@ static int create_new_entry(struct fuse_mount *fm, struct fuse_args *args,return err; } -static int fuse_mknod (struct inode *dir,struct dentry *entry,umode_t mode, -dev_t rdev) +static int fuse_mknod (struct user_namespace *mnt_userns,struct inode *dir, +struct dentry *entry,umode_t mode,dev_t rdev) {struct fuse_mknod_in inarg;struct fuse_mount *fm =get_fuse_mount (dir);
@@ -738,13 +739,14 @@ static int fuse_mknod(struct inode *dir, struct dentry *entry, umode_t mode,return create_new_entry (fm, &args, dir, entry, mode); } -static int fuse_create (struct inode *dir,struct dentry *entry,umode_t mode, -bool excl) +static int fuse_create (struct user_namespace *mnt_userns,struct inode *dir, +struct dentry *entry,umode_t mode,bool excl) { -return fuse_mknod (dir, entry, mode,0 ); +return fuse_mknod (&init_user_ns, dir, entry, mode,0 ); } -static int fuse_mkdir (struct inode *dir,struct dentry *entry,umode_t mode) +static int fuse_mkdir (struct user_namespace *mnt_userns,struct inode *dir, +struct dentry *entry,umode_t mode) {struct fuse_mkdir_in inarg;struct fuse_mount *fm =get_fuse_mount (dir);
@@ -765,8 +767,8 @@ static int fuse_mkdir(struct inode *dir, struct dentry *entry, umode_t mode)return create_new_entry (fm, &args, dir, entry,S_IFDIR ); } -static int fuse_symlink (struct inode *dir,struct dentry *entry, -const char *link) +static int fuse_symlink (struct user_namespace *mnt_userns,struct inode *dir, +struct dentry *entry,const char *link) {struct fuse_mount *fm =get_fuse_mount (dir);unsigned len =strlen (link) +1 ;
@@ -908,9 +910,9 @@ static int fuse_rename_common(struct inode *olddir, struct dentry *oldent,return err; } -static int fuse_rename2 (struct inode *olddir,struct dentry *oldent, -struct inode *newdir,struct dentry *newent, -unsigned int flags) +static int fuse_rename2 (struct user_namespace *mnt_userns,struct inode *olddir, +struct dentry *oldent,struct inode *newdir, +struct dentry *newent,unsigned int flags) {struct fuse_conn *fc =get_fuse_conn (olddir);int err;
@@ -1249,7 +1251,8 @@ static int fuse_perm_getattr(struct inode *inode, int mask)* access request is sent. Execute permission is still checked * locally based on file mode. */ -static int fuse_permission (struct inode *inode,int mask) +static int fuse_permission (struct user_namespace *mnt_userns, +struct inode *inode,int mask) {struct fuse_conn *fc =get_fuse_conn (inode);bool refreshed = false;
@@ -1757,7 +1760,8 @@ int fuse_do_setattr(struct dentry *dentry, struct iattr *attr,return err; } -static int fuse_setattr (struct dentry *entry,struct iattr *attr) +static int fuse_setattr (struct user_namespace *mnt_userns,struct dentry *entry, +struct iattr *attr) {struct inode *inode =d_inode (entry);struct fuse_conn *fc =get_fuse_conn (inode);
@@ -1819,7 +1823,8 @@ static int fuse_setattr(struct dentry *entry, struct iattr *attr)return ret; } -static int fuse_getattr (const struct path *path,struct kstat *stat, +static int fuse_getattr (struct user_namespace *mnt_userns, +const struct path *path,struct kstat *stat,u32 request_mask,unsigned int flags) {struct inode *inode =d_inode (path->dentry);
fs/fuse/fuse_i.h +2 -2
@@ -1180,8 +1180,8 @@ extern const struct xattr_handler *fuse_no_acl_xattr_handlers[];struct posix_acl ;struct posix_acl *fuse_get_acl (struct inode *inode,int type); -int fuse_set_acl (struct inode *inode,struct posix_acl *acl,int type); - +int fuse_set_acl (struct user_namespace *mnt_userns,struct inode *inode, +struct posix_acl *acl,int type);/* readdir.c */ int fuse_readdir (struct file *file,struct dir_context *ctx);
fs/gfs2/acl.c +2 -1
@@ -106,7 +106,8 @@ int __gfs2_set_acl(struct inode *inode, struct posix_acl *acl, int type)return error; } -int gfs2_set_acl (struct inode *inode,struct posix_acl *acl,int type) +int gfs2_set_acl (struct user_namespace *mnt_userns,struct inode *inode, +struct posix_acl *acl,int type) {struct gfs2_inode *ip =GFS2_I (inode);struct gfs2_holder gh;
fs/gfs2/acl.h +2 -1
@@ -13,6 +13,7 @@extern struct posix_acl *gfs2_get_acl (struct inode *inode,int type);extern int __gfs2_set_acl (struct inode *inode,struct posix_acl *acl,int type); -extern int gfs2_set_acl (struct inode *inode,struct posix_acl *acl,int type); +extern int gfs2_set_acl (struct user_namespace *mnt_userns,struct inode *inode, +struct posix_acl *acl,int type);#endif /* __ACL_DOT_H__ */
fs/gfs2/file.c +1 -1
@@ -256,7 +256,7 @@ static int do_gfs2_set_flags(struct file *filp, u32 reqflags, u32 mask, !capable(CAP_LINUX_IMMUTABLE)) goto out;if (!IS_IMMUTABLE (inode)) { - error =gfs2_permission (inode,MAY_WRITE ); + error =gfs2_permission (&init_user_ns, inode,MAY_WRITE );if (error) goto out; }
fs/gfs2/inode.c +32 -21
153 lines not on this page · raw message
fs/gfs2/inode.h +2 -1
@@ -99,7 +99,8 @@ extern int gfs2_inode_refresh(struct gfs2_inode *ip);extern struct inode *gfs2_lookupi (struct inode *dir,const struct qstr *name,int is_root); -extern int gfs2_permission (struct inode *inode,int mask); +extern int gfs2_permission (struct user_namespace *mnt_userns, +struct inode *inode,int mask);extern int gfs2_setattr_simple (struct inode *inode,struct iattr *attr);extern struct inode *gfs2_lookup_simple (struct inode *dip,const char *name);extern void gfs2_dinode_out (const struct gfs2_inode *ip,void *buf);
fs/hfs/dir.c +7 -6
@@ -189,8 +189,8 @@ 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 inode *dir,struct dentry *dentry,umode_t mode, -bool excl) +static int hfs_create (struct user_namespace *mnt_userns,struct inode *dir, +struct dentry *dentry,umode_t mode,bool excl) {struct inode *inode;int res;
@@ -219,7 +219,8 @@ static int hfs_create(struct inode *dir, struct dentry *dentry, umode_t mode,* in a directory, given the inode for the parent directory and the * name (and its length) of the new directory. */ -static int hfs_mkdir (struct inode *dir,struct dentry *dentry,umode_t mode) +static int hfs_mkdir (struct user_namespace *mnt_userns,struct inode *dir, +struct dentry *dentry,umode_t mode) {struct inode *inode;int res;
@@ -279,9 +280,9 @@ static int hfs_remove(struct inode *dir, struct dentry *dentry)* new file/directory. * XXX: how do you handle must_be dir? */ -static int hfs_rename (struct inode *old_dir,struct dentry *old_dentry, -struct inode *new_dir,struct dentry *new_dentry, -unsigned int flags) +static int hfs_rename (struct user_namespace *mnt_userns,struct inode *old_dir, +struct dentry *old_dentry,struct inode *new_dir, +struct dentry *new_dentry,unsigned int flags) {int res;
fs/hfs/hfs_fs.h +2 -1
@@ -204,7 +204,8 @@ extern const struct address_space_operations hfs_btree_aops;extern struct inode *hfs_new_inode (struct inode *,const struct qstr *,umode_t );extern void hfs_inode_write_fork (struct inode *,struct hfs_extent *,__be32 *,__be32 *);extern int hfs_write_inode (struct inode *,struct writeback_control *); -extern int hfs_inode_setattr (struct dentry *,struct iattr *); +extern int hfs_inode_setattr (struct user_namespace *,struct dentry *, +struct iattr *);extern void hfs_inode_read_fork (struct inode *inode,struct hfs_extent *ext,__be32 log_size,__be32 phys_size,u32 clump_size);extern struct inode *hfs_iget (struct super_block *,struct hfs_cat_key *,hfs_cat_rec *);
fs/hfs/inode.c +4 -2
@@ -602,13 +602,15 @@ static int hfs_file_release(struct inode *inode, struct file *file)* correspond to the same HFS file. */ -int hfs_inode_setattr (struct dentry *dentry,struct iattr * attr) +int hfs_inode_setattr (struct user_namespace *mnt_userns,struct dentry *dentry, +struct iattr *attr) {struct inode *inode =d_inode (dentry);struct hfs_sb_info *hsb =HFS_SB (inode->i_sb);int error; - error =setattr_prepare (&init_user_ns, dentry, attr);/* basic permission checks */ + error =setattr_prepare (&init_user_ns, dentry, + attr);/* basic permission checks */ if (error)return error;
fs/hfsplus/dir.c +12 -10
@@ -434,8 +434,8 @@ static int hfsplus_rmdir(struct inode *dir, struct dentry *dentry)return res; } -static int hfsplus_symlink (struct inode *dir,struct dentry *dentry, -const char *symname) +static int hfsplus_symlink (struct user_namespace *mnt_userns,struct inode *dir, +struct dentry *dentry,const char *symname) {struct hfsplus_sb_info *sbi =HFSPLUS_SB (dir->i_sb);struct inode *inode;
@@ -476,8 +476,8 @@ static int hfsplus_symlink(struct inode *dir, struct dentry *dentry,return res; } -static int hfsplus_mknod (struct inode *dir,struct dentry *dentry, -umode_t mode,dev_t rdev) +static int hfsplus_mknod (struct user_namespace *mnt_userns,struct inode *dir, +struct dentry *dentry,umode_t mode,dev_t rdev) {struct hfsplus_sb_info *sbi =HFSPLUS_SB (dir->i_sb);struct inode *inode;
@@ -517,18 +517,20 @@ static int hfsplus_mknod(struct inode *dir, struct dentry *dentry,return res; } -static int hfsplus_create (struct inode *dir,struct dentry *dentry,umode_t mode, -bool excl) +static int hfsplus_create (struct user_namespace *mnt_userns,struct inode *dir, +struct dentry *dentry,umode_t mode,bool excl) { -return hfsplus_mknod (dir, dentry, mode,0 ); +return hfsplus_mknod (&init_user_ns, dir, dentry, mode,0 ); } -static int hfsplus_mkdir (struct inode *dir,struct dentry *dentry,umode_t mode) +static int hfsplus_mkdir (struct user_namespace *mnt_userns,struct inode *dir, +struct dentry *dentry,umode_t mode) { -return hfsplus_mknod (dir, dentry, mode |S_IFDIR ,0 ); +return hfsplus_mknod (&init_user_ns, dir, dentry, mode |S_IFDIR ,0 ); } -static int hfsplus_rename (struct inode *old_dir,struct dentry *old_dentry, +static int hfsplus_rename (struct user_namespace *mnt_userns, +struct inode *old_dir,struct dentry *old_dentry,struct inode *new_dir,struct dentry *new_dentry,unsigned int flags) {
fs/hfsplus/hfsplus_fs.h +3 -2
@@ -488,8 +488,9 @@ void hfsplus_inode_write_fork(struct inode *inode, struct hfsplus_fork_raw *fork);int hfsplus_cat_read_inode (struct inode *inode,struct hfs_find_data *fd);int hfsplus_cat_write_inode (struct inode *inode); -int hfsplus_getattr (const struct path *path,struct kstat *stat, -u32 request_mask,unsigned int query_flags); +int hfsplus_getattr (struct user_namespace *mnt_userns,const struct path *path, +struct kstat *stat,u32 request_mask, +unsigned int query_flags);int hfsplus_file_fsync (struct file *file,loff_t start,loff_t end,int datasync);
fs/hfsplus/inode.c +5 -3
@@ -241,7 +241,8 @@ static int hfsplus_file_release(struct inode *inode, struct file *file)return 0 ; } -static int hfsplus_setattr (struct dentry *dentry,struct iattr *attr) +static int hfsplus_setattr (struct user_namespace *mnt_userns, +struct dentry *dentry,struct iattr *attr) {struct inode *inode =d_inode (dentry);int error;
@@ -270,8 +271,9 @@ static int hfsplus_setattr(struct dentry *dentry, struct iattr *attr)return 0 ; } -int hfsplus_getattr (const struct path *path,struct kstat *stat, -u32 request_mask,unsigned int query_flags) +int hfsplus_getattr (struct user_namespace *mnt_userns,const struct path *path, +struct kstat *stat,u32 request_mask, +unsigned int query_flags) {struct inode *inode =d_inode (path->dentry);struct hfsplus_inode_info *hip =HFSPLUS_I (inode);
fs/hostfs/hostfs_kern.c +14 -9
@@ -555,8 +555,8 @@ static int read_name(struct inode *ino, char *name)return 0 ; } -static int hostfs_create (struct inode *dir,struct dentry *dentry,umode_t mode, -bool excl) +static int hostfs_create (struct user_namespace *mnt_userns,struct inode *dir, +struct dentry *dentry,umode_t mode,bool excl) {struct inode *inode;char *name;
@@ -654,8 +654,8 @@ static int hostfs_unlink(struct inode *ino, struct dentry *dentry)return err; } -static int hostfs_symlink (struct inode *ino,struct dentry *dentry, -const char *to) +static int hostfs_symlink (struct user_namespace *mnt_userns,struct inode *ino, +struct dentry *dentry,const char *to) {char *file;int err;
@@ -667,7 +667,8 @@ static int hostfs_symlink(struct inode *ino, struct dentry *dentry,return err; } -static int hostfs_mkdir (struct inode *ino,struct dentry *dentry,umode_t mode) +static int hostfs_mkdir (struct user_namespace *mnt_userns,struct inode *ino, +struct dentry *dentry,umode_t mode) {char *file;int err;
@@ -691,7 +692,8 @@ static int hostfs_rmdir(struct inode *ino, struct dentry *dentry)return err; } -static int hostfs_mknod (struct inode *dir,struct dentry *dentry,umode_t mode,dev_t dev) +static int hostfs_mknod (struct user_namespace *mnt_userns,struct inode *dir, +struct dentry *dentry,umode_t mode,dev_t dev) {struct inode *inode;char *name;
@@ -729,7 +731,8 @@ static int hostfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,return err; } -static int hostfs_rename2 (struct inode *old_dir,struct dentry *old_dentry, +static int hostfs_rename2 (struct user_namespace *mnt_userns, +struct inode *old_dir,struct dentry *old_dentry,struct inode *new_dir,struct dentry *new_dentry,unsigned int flags) {
@@ -757,7 +760,8 @@ static int hostfs_rename2(struct inode *old_dir, struct dentry *old_dentry,return err; } -static int hostfs_permission (struct inode *ino,int desired) +static int hostfs_permission (struct user_namespace *mnt_userns, +struct inode *ino,int desired) {char *name;int r =0 , w =0 , x =0 , err;
@@ -783,7 +787,8 @@ static int hostfs_permission(struct inode *ino, int desired)return err; } -static int hostfs_setattr (struct dentry *dentry,struct iattr *attr) +static int hostfs_setattr (struct user_namespace *mnt_userns, +struct dentry *dentry,struct iattr *attr) {struct inode *inode =d_inode (dentry);struct hostfs_iattr attrs;
fs/hpfs/hpfs_fn.h +1 -1
@@ -280,7 +280,7 @@ void hpfs_init_inode(struct inode *);void hpfs_read_inode (struct inode *);void hpfs_write_inode (struct inode *);void hpfs_write_inode_nolock (struct inode *); -int hpfs_setattr (struct dentry *,struct iattr *); +int hpfs_setattr (struct user_namespace *,struct dentry *,struct iattr *);void hpfs_write_if_changed (struct inode *);void hpfs_evict_inode (struct inode *);
fs/hpfs/inode.c +2 -1
@@ -257,7 +257,8 @@ void hpfs_write_inode_nolock(struct inode *i)brelse (bh); } -int hpfs_setattr (struct dentry *dentry,struct iattr *attr) +int hpfs_setattr (struct user_namespace *mnt_userns,struct dentry *dentry, +struct iattr *attr) {struct inode *inode =d_inode (dentry);int error = -EINVAL ;
fs/hpfs/namei.c +12 -8
@@ -20,7 +20,8 @@ static void hpfs_update_directory_times(struct inode *dir)hpfs_write_inode_nolock (dir); } -static int hpfs_mkdir (struct inode *dir,struct dentry *dentry,umode_t mode) +static int hpfs_mkdir (struct user_namespace *mnt_userns,struct inode *dir, +struct dentry *dentry,umode_t mode) {const unsigned char *name = dentry->d_name.name;unsigned len = dentry->d_name.len;
@@ -128,7 +129,8 @@ static int hpfs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)return err; } -static int hpfs_create (struct inode *dir,struct dentry *dentry,umode_t mode,bool excl) +static int hpfs_create (struct user_namespace *mnt_userns,struct inode *dir, +struct dentry *dentry,umode_t mode,bool excl) {const unsigned char *name = dentry->d_name.name;unsigned len = dentry->d_name.len;
@@ -215,7 +217,8 @@ static int hpfs_create(struct inode *dir, struct dentry *dentry, umode_t mode, breturn err; } -static int hpfs_mknod (struct inode *dir,struct dentry *dentry,umode_t mode,dev_t rdev) +static int hpfs_mknod (struct user_namespace *mnt_userns,struct inode *dir, +struct dentry *dentry,umode_t mode,dev_t rdev) {const unsigned char *name = dentry->d_name.name;unsigned len = dentry->d_name.len;
@@ -289,7 +292,8 @@ static int hpfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dereturn err; } -static int hpfs_symlink (struct inode *dir,struct dentry *dentry,const char *symlink) +static int hpfs_symlink (struct user_namespace *mnt_userns,struct inode *dir, +struct dentry *dentry,const char *symlink) {const unsigned char *name = dentry->d_name.name;unsigned len = dentry->d_name.len;
@@ -506,10 +510,10 @@ static int hpfs_symlink_readpage(struct file *file, struct page *page)const struct address_space_operations hpfs_symlink_aops = { .readpage = hpfs_symlink_readpage }; - -static int hpfs_rename (struct inode *old_dir,struct dentry *old_dentry, -struct inode *new_dir,struct dentry *new_dentry, -unsigned int flags) + +static int hpfs_rename (struct user_namespace *mnt_userns,struct inode *old_dir, +struct dentry *old_dentry,struct inode *new_dir, +struct dentry *new_dentry,unsigned int flags) {const unsigned char *old_name = old_dentry->d_name.name;unsigned old_len = old_dentry->d_name.len;
fs/hugetlbfs/inode.c +18 -11
@@ -751,7 +751,8 @@ static long hugetlbfs_fallocate(struct file *file, int mode, loff_t offset,return error; } -static int hugetlbfs_setattr (struct dentry *dentry,struct iattr *attr) +static int hugetlbfs_setattr (struct user_namespace *mnt_userns, +struct dentry *dentry,struct iattr *attr) {struct inode *inode =d_inode (dentry);struct hstate *h =hstate_inode (inode);
@@ -898,33 +899,39 @@ static int do_hugetlbfs_mknod(struct inode *dir,return error; } -static int hugetlbfs_mknod (struct inode *dir, -struct dentry *dentry,umode_t mode,dev_t dev) +static int hugetlbfs_mknod (struct user_namespace *mnt_userns,struct inode *dir, +struct dentry *dentry,umode_t mode,dev_t dev) {return do_hugetlbfs_mknod (dir, dentry, mode, dev, false); } -static int hugetlbfs_mkdir (struct inode *dir,struct dentry *dentry,umode_t mode) +static int hugetlbfs_mkdir (struct user_namespace *mnt_userns,struct inode *dir, +struct dentry *dentry,umode_t mode) { -int retval =hugetlbfs_mknod (dir, dentry, mode |S_IFDIR ,0 ); +int retval =hugetlbfs_mknod (&init_user_ns, dir, dentry, + mode |S_IFDIR ,0 );if (!retval)inc_nlink (dir);return retval; } -static int hugetlbfs_create (struct inode *dir,struct dentry *dentry,umode_t mode,bool excl) +static int hugetlbfs_create (struct user_namespace *mnt_userns, +struct inode *dir,struct dentry *dentry, +umode_t mode,bool excl) { -return hugetlbfs_mknod (dir, dentry, mode |S_IFREG ,0 ); +return hugetlbfs_mknod (&init_user_ns, dir, dentry, mode |S_IFREG ,0 ); } -static int hugetlbfs_tmpfile (struct inode *dir, -struct dentry *dentry,umode_t mode) +static int hugetlbfs_tmpfile (struct user_namespace *mnt_userns, +struct inode *dir,struct dentry *dentry, +umode_t mode) {return do_hugetlbfs_mknod (dir, dentry, mode |S_IFREG ,0 , true); } -static int hugetlbfs_symlink (struct inode *dir, -struct dentry *dentry,const char *symname) +static int hugetlbfs_symlink (struct user_namespace *mnt_userns, +struct inode *dir,struct dentry *dentry, +const char *symname) {struct inode *inode;int error = -ENOSPC ;
fs/jffs2/acl.c +2 -1
@@ -226,7 +226,8 @@ static int __jffs2_set_acl(struct inode *inode, int xprefix, struct posix_acl *areturn rc; } -int jffs2_set_acl (struct inode *inode,struct posix_acl *acl,int type) +int jffs2_set_acl (struct user_namespace *mnt_userns,struct inode *inode, +struct posix_acl *acl,int type) {int rc, xprefix;
fs/jffs2/acl.h +2 -1
@@ -28,7 +28,8 @@ struct jffs2_acl_header {#ifdef CONFIG_JFFS2_FS_POSIX_ACL struct posix_acl *jffs2_get_acl (struct inode *inode,int type); -int jffs2_set_acl (struct inode *inode,struct posix_acl *acl,int type); +int jffs2_set_acl (struct user_namespace *mnt_userns,struct inode *inode, +struct posix_acl *acl,int type);extern int jffs2_init_acl_pre (struct inode *,struct inode *,umode_t *);extern int jffs2_init_acl_post (struct inode *);
fs/jffs2/dir.c +20 -13
@@ -24,18 +24,21 @@static int jffs2_readdir (struct file *,struct dir_context *); -static int jffs2_create (struct inode *,struct dentry *,umode_t , -bool ); +static int jffs2_create (struct user_namespace *,struct inode *, +struct dentry *,umode_t ,bool );static struct dentry *jffs2_lookup (struct inode *,struct dentry *,unsigned int );static int jffs2_link (struct dentry *,struct inode *,struct dentry *);static int jffs2_unlink (struct inode *,struct dentry *); -static int jffs2_symlink (struct inode *,struct dentry *,const char *); -static int jffs2_mkdir (struct inode *,struct dentry *,umode_t ); +static int jffs2_symlink (struct user_namespace *,struct inode *, +struct dentry *,const char *); +static int jffs2_mkdir (struct user_namespace *,struct inode *,struct dentry *, +umode_t );static int jffs2_rmdir (struct inode *,struct dentry *); -static int jffs2_mknod (struct inode *,struct dentry *,umode_t ,dev_t ); -static int jffs2_rename (struct inode *,struct dentry *, -struct inode *,struct dentry *, +static int jffs2_mknod (struct user_namespace *,struct inode *,struct dentry *, +umode_t ,dev_t ); +static int jffs2_rename (struct user_namespace *,struct inode *, +struct dentry *,struct inode *,struct dentry *,unsigned int ); const struct file_operations jffs2_dir_operations =
@@ -157,8 +160,8 @@ static int jffs2_readdir(struct file *file, struct dir_context *ctx)/***********************************************************************/ -static int jffs2_create (struct inode *dir_i,struct dentry *dentry, -umode_t mode,bool excl) +static int jffs2_create (struct user_namespace *mnt_userns,struct inode *dir_i, +struct dentry *dentry,umode_t mode,bool excl) {struct jffs2_raw_inode *ri;struct jffs2_inode_info *f, *dir_f;
@@ -276,7 +279,8 @@ static int jffs2_link (struct dentry *old_dentry, struct inode *dir_i, struct de/***********************************************************************/ -static int jffs2_symlink (struct inode *dir_i,struct dentry *dentry,const char *target) +static int jffs2_symlink (struct user_namespace *mnt_userns,struct inode *dir_i, +struct dentry *dentry,const char *target) {struct jffs2_inode_info *f, *dir_f;struct jffs2_sb_info *c;
@@ -438,7 +442,8 @@ static int jffs2_symlink (struct inode *dir_i, struct dentry *dentry, const char } -static int jffs2_mkdir (struct inode *dir_i,struct dentry *dentry,umode_t mode) +static int jffs2_mkdir (struct user_namespace *mnt_userns,struct inode *dir_i, +struct dentry *dentry,umode_t mode) {struct jffs2_inode_info *f, *dir_f;struct jffs2_sb_info *c;
@@ -609,7 +614,8 @@ static int jffs2_rmdir (struct inode *dir_i, struct dentry *dentry)return ret; } -static int jffs2_mknod (struct inode *dir_i,struct dentry *dentry,umode_t mode,dev_t rdev) +static int jffs2_mknod (struct user_namespace *mnt_userns,struct inode *dir_i, +struct dentry *dentry,umode_t mode,dev_t rdev) {struct jffs2_inode_info *f, *dir_f;struct jffs2_sb_info *c;
@@ -756,7 +762,8 @@ static int jffs2_mknod (struct inode *dir_i, struct dentry *dentry, umode_t modereturn ret; } -static int jffs2_rename (struct inode *old_dir_i,struct dentry *old_dentry, +static int jffs2_rename (struct user_namespace *mnt_userns, +struct inode *old_dir_i,struct dentry *old_dentry,struct inode *new_dir_i,struct dentry *new_dentry,unsigned int flags) {
fs/jffs2/fs.c +2 -1
@@ -190,7 +190,8 @@ int jffs2_do_setattr (struct inode *inode, struct iattr *iattr)return 0 ; } -int jffs2_setattr (struct dentry *dentry,struct iattr *iattr) +int jffs2_setattr (struct user_namespace *mnt_userns,struct dentry *dentry, +struct iattr *iattr) {struct inode *inode =d_inode (dentry);int rc;
fs/jffs2/os-linux.h +1 -1
@@ -164,7 +164,7 @@ long jffs2_ioctl(struct file *, unsigned int, unsigned long);extern const struct inode_operations jffs2_symlink_inode_operations;/* fs.c */ -int jffs2_setattr (struct dentry *,struct iattr *); +int jffs2_setattr (struct user_namespace *,struct dentry *,struct iattr *);int jffs2_do_setattr (struct inode *,struct iattr *);struct inode *jffs2_iget (struct super_block *,unsigned long );void jffs2_evict_inode (struct inode *);
fs/jfs/acl.c +2 -1
@@ -91,7 +91,8 @@ static int __jfs_set_acl(tid_t tid, struct inode *inode, int type,return rc; } -int jfs_set_acl (struct inode *inode,struct posix_acl *acl,int type) +int jfs_set_acl (struct user_namespace *mnt_userns,struct inode *inode, +struct posix_acl *acl,int type) {int rc;tid_t tid;
fs/jfs/file.c +2 -1
@@ -85,7 +85,8 @@ static int jfs_release(struct inode *inode, struct file *file)return 0 ; } -int jfs_setattr (struct dentry *dentry,struct iattr *iattr) +int jfs_setattr (struct user_namespace *mnt_userns,struct dentry *dentry, +struct iattr *iattr) {struct inode *inode =d_inode (dentry);int rc;
fs/jfs/jfs_acl.h +2 -1
@@ -8,7 +8,8 @@#ifdef CONFIG_JFS_POSIX_ACL struct posix_acl *jfs_get_acl (struct inode *inode,int type); -int jfs_set_acl (struct inode *inode,struct posix_acl *acl,int type); +int jfs_set_acl (struct user_namespace *mnt_userns,struct inode *inode, +struct posix_acl *acl,int type);int jfs_init_acl (tid_t ,struct inode *,struct inode *);#else
fs/jfs/jfs_inode.h +1 -1
@@ -26,7 +26,7 @@ extern struct dentry *jfs_fh_to_parent(struct super_block *sb, struct fid *fid, int fh_len, int fh_type);extern void jfs_set_inode_flags (struct inode *);extern int jfs_get_block (struct inode *,sector_t ,struct buffer_head *,int ); -extern int jfs_setattr (struct dentry *,struct iattr *); +extern int jfs_setattr (struct user_namespace *,struct dentry *,struct iattr *);extern const struct address_space_operations jfs_aops;extern const struct inode_operations jfs_dir_inode_operations;
fs/jfs/namei.c +11 -10
@@ -59,8 +59,8 @@ static inline void free_ea_wmap(struct inode *inode)* RETURN: Errors from subroutines * */ -static int jfs_create (struct inode *dip,struct dentry *dentry,umode_t mode, -bool excl) +static int jfs_create (struct user_namespace *mnt_userns,struct inode *dip, +struct dentry *dentry,umode_t mode,bool excl) {int rc =0 ;tid_t tid;/* transaction id */
@@ -192,7 +192,8 @@ static int jfs_create(struct inode *dip, struct dentry *dentry, umode_t mode,* note: * EACCES: user needs search+write permission on the parent directory */ -static int jfs_mkdir (struct inode *dip,struct dentry *dentry,umode_t mode) +static int jfs_mkdir (struct user_namespace *mnt_userns,struct inode *dip, +struct dentry *dentry,umode_t mode) {int rc =0 ;tid_t tid;/* transaction id */
@@ -868,8 +869,8 @@ static int jfs_link(struct dentry *old_dentry,* an intermediate result whose length exceeds PATH_MAX [XPG4.2] */ -static int jfs_symlink (struct inode *dip,struct dentry *dentry, -const char *name) +static int jfs_symlink (struct user_namespace *mnt_userns,struct inode *dip, +struct dentry *dentry,const char *name) {int rc;tid_t tid;
@@ -1058,9 +1059,9 @@ static int jfs_symlink(struct inode *dip, struct dentry *dentry,* * FUNCTION: rename a file or directory */ -static int jfs_rename (struct inode *old_dir,struct dentry *old_dentry, -struct inode *new_dir,struct dentry *new_dentry, -unsigned int flags) +static int jfs_rename (struct user_namespace *mnt_userns,struct inode *old_dir, +struct dentry *old_dentry,struct inode *new_dir, +struct dentry *new_dentry,unsigned int flags) {struct btstack btstack;ino_t ino;
@@ -1344,8 +1345,8 @@ static int jfs_rename(struct inode *old_dir, struct dentry *old_dentry,* * FUNCTION: Create a special file (device) */ -static int jfs_mknod (struct inode *dir,struct dentry *dentry, -umode_t mode,dev_t rdev) +static int jfs_mknod (struct user_namespace *mnt_userns,struct inode *dir, +struct dentry *dentry,umode_t mode,dev_t rdev) {struct jfs_inode_info *jfs_ip;struct btstack btstack;
fs/kernfs/dir.c +4 -2
@@ -1110,7 +1110,8 @@ static struct dentry *kernfs_iop_lookup(struct inode *dir,return ret; } -static int kernfs_iop_mkdir (struct inode *dir,struct dentry *dentry, +static int kernfs_iop_mkdir (struct user_namespace *mnt_userns, +struct inode *dir,struct dentry *dentry,umode_t mode) {struct kernfs_node *parent = dir->i_private;
@@ -1147,7 +1148,8 @@ static int kernfs_iop_rmdir(struct inode *dir, struct dentry *dentry)return ret; } -static int kernfs_iop_rename (struct inode *old_dir,struct dentry *old_dentry, +static int kernfs_iop_rename (struct user_namespace *mnt_userns, +struct inode *old_dir,struct dentry *old_dentry,struct inode *new_dir,struct dentry *new_dentry,unsigned int flags) {
fs/kernfs/inode.c +6 -3
@@ -112,7 +112,8 @@ int kernfs_setattr(struct kernfs_node *kn, const struct iattr *iattr)return ret; } -int kernfs_iop_setattr (struct dentry *dentry,struct iattr *iattr) +int kernfs_iop_setattr (struct user_namespace *mnt_userns,struct dentry *dentry, +struct iattr *iattr) {struct inode *inode =d_inode (dentry);struct kernfs_node *kn = inode->i_private;
@@ -183,7 +184,8 @@ static void kernfs_refresh_inode(struct kernfs_node *kn, struct inode *inode)set_nlink (inode, kn->dir.subdirs +2 ); } -int kernfs_iop_getattr (const struct path *path,struct kstat *stat, +int kernfs_iop_getattr (struct user_namespace *mnt_userns, +const struct path *path,struct kstat *stat,u32 request_mask,unsigned int query_flags) {struct inode *inode =d_inode (path->dentry);
@@ -272,7 +274,8 @@ void kernfs_evict_inode(struct inode *inode)kernfs_put (kn); } -int kernfs_iop_permission (struct inode *inode,int mask) +int kernfs_iop_permission (struct user_namespace *mnt_userns, +struct inode *inode,int mask) {struct kernfs_node *kn;
fs/kernfs/kernfs-internal.h +6 -3
@@ -89,9 +89,12 @@ extern struct kmem_cache *kernfs_node_cache, *kernfs_iattrs_cache;*/ extern const struct xattr_handler *kernfs_xattr_handlers[];void kernfs_evict_inode (struct inode *inode); -int kernfs_iop_permission (struct inode *inode,int mask); -int kernfs_iop_setattr (struct dentry *dentry,struct iattr *iattr); -int kernfs_iop_getattr (const struct path *path,struct kstat *stat, +int kernfs_iop_permission (struct user_namespace *mnt_userns, +struct inode *inode,int mask); +int kernfs_iop_setattr (struct user_namespace *mnt_userns,struct dentry *dentry, +struct iattr *iattr); +int kernfs_iop_getattr (struct user_namespace *mnt_userns, +const struct path *path,struct kstat *stat,u32 request_mask,unsigned int query_flags);ssize_t kernfs_iop_listxattr (struct dentry *dentry,char *buf,size_t size);int __kernfs_setattr (struct kernfs_node *kn,const struct iattr *iattr);
fs/libfs.c +15 -16
@@ -27,8 +27,9 @@#include "internal.h" -int simple_getattr (const struct path *path,struct kstat *stat, -u32 request_mask,unsigned int query_flags) +int simple_getattr (struct user_namespace *mnt_userns,const struct path *path, +struct kstat *stat,u32 request_mask, +unsigned int query_flags) {struct inode *inode =d_inode (path->dentry);generic_fillattr (&init_user_ns, inode, stat);
@@ -447,9 +448,9 @@ int simple_rmdir(struct inode *dir, struct dentry *dentry) }EXPORT_SYMBOL (simple_rmdir); -int simple_rename (struct inode *old_dir,struct dentry *old_dentry, -struct inode *new_dir,struct dentry *new_dentry, -unsigned int flags) +int simple_rename (struct user_namespace *mnt_userns,struct inode *old_dir, +struct dentry *old_dentry,struct inode *new_dir, +struct dentry *new_dentry,unsigned int flags) {struct inode *inode =d_inode (old_dentry);int they_are_dirs =d_is_dir (old_dentry);
@@ -492,18 +493,19 @@ EXPORT_SYMBOL(simple_rename);* on simple regular filesystems. Anything that needs to change on-disk * or wire state on size changes needs its own setattr method. */ -int simple_setattr (struct dentry *dentry,struct iattr *iattr) +int simple_setattr (struct user_namespace *mnt_userns,struct dentry *dentry, +struct iattr *iattr) {struct inode *inode =d_inode (dentry);int error; - error =setattr_prepare (&init_user_ns, dentry, iattr); + error =setattr_prepare (mnt_userns, dentry, iattr);if (error)return error;if (iattr->ia_valid &ATTR_SIZE )truncate_setsize (inode, iattr->ia_size); -setattr_copy (&init_user_ns, inode, iattr); +setattr_copy (mnt_userns, inode, iattr);mark_inode_dirty (inode);return 0 ; }
@@ -1300,7 +1302,8 @@ static struct dentry *empty_dir_lookup(struct inode *dir, struct dentry *dentry,return ERR_PTR (-ENOENT ); } -static int empty_dir_getattr (const struct path *path,struct kstat *stat, +static int empty_dir_getattr (struct user_namespace *mnt_userns, +const struct path *path,struct kstat *stat,u32 request_mask,unsigned int query_flags) {struct inode *inode =d_inode (path->dentry);
@@ -1308,7 +1311,8 @@ static int empty_dir_getattr(const struct path *path, struct kstat *stat,return 0 ; } -static int empty_dir_setattr (struct dentry *dentry,struct iattr *attr) +static int empty_dir_setattr (struct user_namespace *mnt_userns, +struct dentry *dentry,struct iattr *attr) {return -EPERM ; }
@@ -1318,14 +1322,9 @@ static ssize_t empty_dir_listxattr(struct dentry *dentry, char *list, size_t sizreturn -EOPNOTSUPP ; } -static int empty_dir_permission (struct inode *inode,int mask) -{ -return generic_permission (&init_user_ns, inode, mask); -} -static const struct inode_operations empty_dir_inode_operations = { .lookup = empty_dir_lookup, - .permission = empty_dir_permission, + .permission = generic_permission, .setattr = empty_dir_setattr, .getattr = empty_dir_getattr, .listxattr = empty_dir_listxattr,
fs/minix/file.c +2 -1
@@ -22,7 +22,8 @@ const struct file_operations minix_file_operations = { .splice_read = generic_file_splice_read, }; -static int minix_setattr (struct dentry *dentry,struct iattr *attr) +static int minix_setattr (struct user_namespace *mnt_userns, +struct dentry *dentry,struct iattr *attr) {struct inode *inode =d_inode (dentry);int error;
fs/minix/inode.c +2 -2
@@ -652,8 +652,8 @@ static int minix_write_inode(struct inode *inode, struct writeback_control *wbc)return err; } -int minix_getattr (const struct path *path,struct kstat *stat, -u32 request_mask,unsigned int flags) +int minix_getattr (struct user_namespace *mnt_userns,const struct path *path, +struct kstat *stat,u32 request_mask,unsigned int flags) {struct super_block *sb = path->dentry->d_sb;struct inode *inode =d_inode (path->dentry);
fs/minix/minix.h +2 -1
@@ -51,7 +51,8 @@ extern unsigned long minix_count_free_inodes(struct super_block *sb);extern int minix_new_block (struct inode * inode);extern void minix_free_block (struct inode *inode,unsigned long block);extern unsigned long minix_count_free_blocks (struct super_block *sb); -extern int minix_getattr (const struct path *,struct kstat *,u32 ,unsigned int ); +extern int minix_getattr (struct user_namespace *,const struct path *, +struct kstat *,u32 ,unsigned int );extern int minix_prepare_chunk (struct page *page,loff_t pos,unsigned len);extern void V1_minix_truncate (struct inode *);
fs/minix/namei.c +14 -10
@@ -33,7 +33,8 @@ static struct dentry *minix_lookup(struct inode * dir, struct dentry *dentry, unreturn d_splice_alias (inode, dentry); } -static int minix_mknod (struct inode * dir,struct dentry *dentry,umode_t mode,dev_t rdev) +static int minix_mknod (struct user_namespace *mnt_userns,struct inode *dir, +struct dentry *dentry,umode_t mode,dev_t rdev) {int error;struct inode *inode;
@@ -51,7 +52,8 @@ static int minix_mknod(struct inode * dir, struct dentry *dentry, umode_t mode,return error; } -static int minix_tmpfile (struct inode *dir,struct dentry *dentry,umode_t mode) +static int minix_tmpfile (struct user_namespace *mnt_userns,struct inode *dir, +struct dentry *dentry,umode_t mode) {int error;struct inode *inode =minix_new_inode (dir, mode, &error);
@@ -63,14 +65,14 @@ static int minix_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode)return error; } -static int minix_create (struct inode *dir,struct dentry *dentry,umode_t mode, -bool excl) +static int minix_create (struct user_namespace *mnt_userns,struct inode *dir, +struct dentry *dentry,umode_t mode,bool excl) { -return minix_mknod (dir, dentry, mode,0 ); +return minix_mknod (mnt_userns, dir, dentry, mode,0 ); } -static int minix_symlink (struct inode * dir,struct dentry *dentry, -const char * symname) +static int minix_symlink (struct user_namespace *mnt_userns,struct inode *dir, +struct dentry *dentry,const char *symname) {int err = -ENAMETOOLONG ;int i =strlen (symname)+1 ;
@@ -109,7 +111,8 @@ static int minix_link(struct dentry * old_dentry, struct inode * dir,return add_nondir (dentry, inode); } -static int minix_mkdir (struct inode * dir,struct dentry *dentry,umode_t mode) +static int minix_mkdir (struct user_namespace *mnt_userns,struct inode *dir, +struct dentry *dentry,umode_t mode) {struct inode * inode;int err;
@@ -181,8 +184,9 @@ static int minix_rmdir(struct inode * dir, struct dentry *dentry)return err; } -static int minix_rename (struct inode * old_dir,struct dentry *old_dentry, -struct inode * new_dir,struct dentry *new_dentry, +static int minix_rename (struct user_namespace *mnt_userns, +struct inode *old_dir,struct dentry *old_dentry, +struct inode *new_dir,struct dentry *new_dentry,unsigned int flags) {struct inode * old_inode =d_inode (old_dentry);
fs/namei.c +32 -23
193 lines not on this page · raw message
fs/xfs/xfs_iops.c +30 -22
52 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 6 lines
2.30.0 _______________________________________________ Containers mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/containers
Part of the diff is not shown here. View the raw message.
PATCH v6 25/40 apparmor: handle idmapped mounts
In reply to Christian BraunerThe i_uid and i_gid are mostly used when logging for AppArmor. This is broken in a bunch of places where the global root id is reported instead of the i_uid or i_gid of the file. Nonetheless, be kind and log the mapped inode if we're coming from an idmapped mount. If the initial user namespace is passed nothing changes so non-idmapped mounts will see identical behavior as before.
---
/* v2 */
unchanged
/* v3 */
unchanged
/* v4 */
- Serge Hallyn <[email protected]>:
- Use "mnt_userns" to refer to a vfsmount's userns everywhere to make terminology consistent.
/* v5 */
base-commit: 7c53f6b671f4aba70ff15e1b05148b10d58c2837
- Christoph Hellwig <[email protected]>:
- Use new file_mnt_user_ns() helper.
/* v6 */
unchanged
base-commit: 19c329f6808995b142b3966301f217c831e7cf31
--- security/apparmor/domain.c | 9 ++++++--- security/apparmor/file.c | 4 +++- security/apparmor/lsm.c | 21 +++++++++++++++------ 3 files changed, 24 insertions(+), 10 deletions(-)
security/apparmor/domain.c +6 -3
@@ -10,12 +10,14 @@#include <linux/errno.h> #include <linux/fdtable.h> +#include <linux/fs.h> #include <linux/file.h> #include <linux/mount.h> #include <linux/syscalls.h> #include <linux/tracehook.h> #include <linux/personality.h> #include <linux/xattr.h> +#include <linux/user_namespace.h> #include "include/audit.h" #include "include/apparmorfs.h"
@@ -858,8 +860,10 @@ int apparmor_bprm_creds_for_exec(struct linux_binprm *bprm)const char *info =NULL ;int error =0 ;bool unsafe = false; +kuid_t i_uid =i_uid_into_mnt (file_mnt_user_ns (bprm->file), +file_inode (bprm->file));struct path_cond cond = { -file_inode (bprm->file)->i_uid, + i_uid,file_inode (bprm->file)->i_mode };
@@ -967,8 +971,7 @@ int apparmor_bprm_creds_for_exec(struct linux_binprm *bprm) error =fn_for_each (label, profile,aa_audit_file (profile, &nullperms,OP_EXEC ,MAY_EXEC , bprm->filename,NULL , new, -file_inode (bprm->file)->i_uid, info, - error)); + i_uid, info, error));aa_put_label (new); goto done; }
security/apparmor/file.c +3 -1
@@ -11,6 +11,8 @@#include <linux/tty.h> #include <linux/fdtable.h> #include <linux/file.h> +#include <linux/fs.h> +#include <linux/mount.h> #include "include/apparmor.h" #include "include/audit.h"
@@ -509,7 +511,7 @@ static int __file_path_perm(const char *op, struct aa_label *label,struct aa_profile *profile;struct aa_perms perms = {};struct path_cond cond = { - .uid =file_inode (file)->i_uid, + .uid =i_uid_into_mnt (file_mnt_user_ns (file),file_inode (file)), .mode =file_inode (file)->i_mode };char *buffer;
security/apparmor/lsm.c +15 -6
@@ -224,8 +224,10 @@ static int common_perm(const char *op, const struct path *path, u32 mask,*/ static int common_perm_cond (const char *op,const struct path *path,u32 mask) { -struct path_cond cond = {d_backing_inode (path->dentry)->i_uid, -d_backing_inode (path->dentry)->i_mode +struct user_namespace *mnt_userns =mnt_user_ns (path->mnt); +struct path_cond cond = { +i_uid_into_mnt (mnt_userns,d_backing_inode (path->dentry)), +d_backing_inode (path->dentry)->i_mode };if (!path_mediated_fs (path->dentry))
@@ -266,12 +268,13 @@ static int common_perm_rm(const char *op, const struct path *dir, struct dentry *dentry, u32 mask) {struct inode *inode =d_backing_inode (dentry); +struct user_namespace *mnt_userns =mnt_user_ns (dir->mnt);struct path_cond cond = { };if (!inode || !path_mediated_fs (dentry))return 0 ; - cond.uid = inode->i_uid; + cond.uid =i_uid_into_mnt (mnt_userns, inode); cond.mode = inode->i_mode;return common_perm_dir_dentry (op, dir, dentry, mask, &cond);
@@ -361,12 +364,14 @@ static int apparmor_path_rename(const struct path *old_dir, struct dentry *old_d label =begin_current_label_crit_section ();if (!unconfined (label)) { +struct user_namespace *mnt_userns =mnt_user_ns (old_dir->mnt);struct path old_path = { .mnt = old_dir->mnt, .dentry = old_dentry };struct path new_path = { .mnt = new_dir->mnt, .dentry = new_dentry }; -struct path_cond cond = {d_backing_inode (old_dentry)->i_uid, -d_backing_inode (old_dentry)->i_mode +struct path_cond cond = { +i_uid_into_mnt (mnt_userns,d_backing_inode (old_dentry)), +d_backing_inode (old_dentry)->i_mode }; error = aa_path_perm(OP_RENAME_SRC, label, &old_path, 0,
@@ -420,8 +425,12 @@ static int apparmor_file_open(struct file *file) label =aa_get_newest_cred_label (file->f_cred);if (!unconfined (label)) { +struct user_namespace *mnt_userns =file_mnt_user_ns (file);struct inode *inode =file_inode (file); -struct path_cond cond = { inode->i_uid, inode->i_mode }; +struct path_cond cond = { +i_uid_into_mnt (mnt_userns, inode), + inode->i_mode + }; error =aa_path_perm (OP_OPEN , label, &file->f_path,0 ,aa_map_file_to_perms (file), &cond);
Signature · 6 lines
2.30.0 _______________________________________________ Containers mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/containers
PATCH v6 27/40 ecryptfs: do not mount on top of idmapped mounts
In reply to Christian BraunerPrevent ecryptfs from being mounted on top of idmapped mounts. Stacking filesystems need to be prevented from being mounted on top of idmapped mounts until they have have been converted to handle this.
---
/* v2 */
patch introduced
/* v3 */
- David Howells <[email protected]>:
- Adapt check after removing mnt_idmapped() helper.
/* v4 */
unchanged
/* v5 */
unchanged
base-commit: 7c53f6b671f4aba70ff15e1b05148b10d58c2837
/* v6 */
unchanged
base-commit: 19c329f6808995b142b3966301f217c831e7cf31
--- fs/ecryptfs/main.c | 6 ++++++ 1 file changed, 6 insertions(+)
fs/ecryptfs/main.c +6 -0
@@ -531,6 +531,12 @@ static struct dentry *ecryptfs_mount(struct file_system_type *fs_type, int flags goto out_free; } +if (mnt_user_ns (path.mnt) != &init_user_ns) { + rc = -EINVAL ; +printk (KERN_ERR "Mounting on idmapped mounts currently disallowed\n" ); + goto out_free; + } +if (check_ruid && !uid_eq (d_inode (path.dentry)->i_uid,current_uid ())) { rc = -EPERM ; printk(KERN_ERR "Mount of device (uid: %d) not owned by "
Signature · 6 lines
2.30.0 _______________________________________________ Containers mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/containers
Re: [PATCH v6 27/40] ecryptfs: do not mount on top of idmapped mounts
Quoted 10 lines · Christian Brauner
Prevent ecryptfs from being mounted on top of idmapped mounts. Stacking filesystems need to be prevented from being mounted on top of idmapped mounts until they have have been converted to handle this.
Cc Christoph Hellwig <[email protected]>Cc David Howells <[email protected]>Cc Al Viro <[email protected]>Signed-off-by Christian Brauner <[email protected]>
Signature · 7 lines
James Morris <[email protected]> _______________________________________________ Containers mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/containers
PATCH v6 26/39 ima: handle idmapped mounts
In reply to Christian BraunerIMA does sometimes access the inode's i_uid and compares it against the rules' fowner. Enable IMA to handle idmapped mounts by passing down the mount's user namespace. We simply make use of the helpers we introduced before. If the initial user namespace is passed nothing changes so non-idmapped mounts will see identical behavior as before.
---
/* v2 */
unchanged
/* v3 */
unchanged
/* v4 */
- Serge Hallyn <[email protected]>:
- Use "mnt_userns" to refer to a vfsmount's userns everywhere to make terminology consistent.
/* v5 */
base-commit: 7c53f6b671f4aba70ff15e1b05148b10d58c2837
- Christoph Hellwig <[email protected]>:
- Use new file_mnt_user_ns() helper.
/* v6 */
unchanged
base-commit: 19c329f6808995b142b3966301f217c831e7cf31
--- fs/attr.c | 2 +- fs/namei.c | 4 +-- include/linux/ima.h | 18 ++++++---- security/integrity/ima/ima.h | 19 ++++++---- security/integrity/ima/ima_api.c | 10 +++--- security/integrity/ima/ima_appraise.c | 15 ++++---- security/integrity/ima/ima_asymmetric_keys.c | 3 +- security/integrity/ima/ima_main.c | 37 +++++++++++++------- security/integrity/ima/ima_policy.c | 20 ++++++----- security/integrity/ima/ima_queue_keys.c | 4 ++- 10 files changed, 83 insertions(+), 49 deletions(-)
fs/attr.c +1 -1
@@ -401,7 +401,7 @@ int notify_change(struct user_namespace *mnt_userns, struct dentry *dentry,if (!error) {fsnotify_change (dentry, ia_valid); -ima_inode_post_setattr (dentry); +ima_inode_post_setattr (mnt_userns, dentry);evm_inode_post_setattr (dentry, ia_valid); }
fs/namei.c +2 -2
@@ -3422,7 +3422,7 @@ struct dentry *vfs_tmpfile(struct user_namespace *mnt_userns, inode->i_state |=I_LINKABLE ;spin_unlock (&inode->i_lock); } -ima_post_create_tmpfile (inode); +ima_post_create_tmpfile (mnt_userns, inode);return child; out_err:
@@ -3750,7 +3750,7 @@ static long do_mknodat(int dfd, const char __user *filename, umode_t mode, error =vfs_create (mnt_userns, path.dentry->d_inode, dentry, mode, true);if (!error) -ima_post_path_mknod (dentry); +ima_post_path_mknod (mnt_userns, dentry);break ;case S_IFCHR :case S_IFBLK : error = vfs_mknod(mnt_userns, path.dentry->d_inode,
include/linux/ima.h +12 -6
@@ -16,7 +16,8 @@ struct linux_binprm;#ifdef CONFIG_IMA extern int ima_bprm_check (struct linux_binprm *bprm);extern int ima_file_check (struct file *file,int mask); -extern void ima_post_create_tmpfile (struct inode *inode); +extern void ima_post_create_tmpfile (struct user_namespace *mnt_userns, +struct inode *inode);extern void ima_file_free (struct file *file);extern int ima_file_mmap (struct file *file,unsigned long prot);extern int ima_file_mprotect (struct vm_area_struct *vma,unsigned long prot);
@@ -27,7 +28,8 @@ extern int ima_read_file(struct file *file, enum kernel_read_file_id id, bool contents);extern int ima_post_read_file (struct file *file,void *buf,loff_t size,enum kernel_read_file_id id); -extern void ima_post_path_mknod (struct dentry *dentry); +extern void ima_post_path_mknod (struct user_namespace *mnt_userns, +struct dentry *dentry);extern int ima_file_hash (struct file *file,char *buf,size_t buf_size);extern int ima_inode_hash (struct inode *inode,char *buf,size_t buf_size);extern void ima_kexec_cmdline (int kernel_fd,const void *buf,int size);
@@ -68,7 +70,8 @@ static inline int ima_file_check(struct file *file, int mask)return 0 ; } -static inline void ima_post_create_tmpfile (struct inode *inode) +static inline void ima_post_create_tmpfile (struct user_namespace *mnt_userns, +struct inode *inode) { }
@@ -112,7 +115,8 @@ static inline int ima_post_read_file(struct file *file, void *buf, loff_t size,return 0 ; } -static inline void ima_post_path_mknod (struct dentry *dentry) +static inline void ima_post_path_mknod (struct user_namespace *mnt_userns, +struct dentry *dentry) {return ; }
@@ -153,7 +157,8 @@ static inline void ima_post_key_create_or_update(struct key *keyring,#ifdef CONFIG_IMA_APPRAISE extern bool is_ima_appraise_enabled (void ); -extern void ima_inode_post_setattr (struct dentry *dentry); +extern void ima_inode_post_setattr (struct user_namespace *mnt_userns, +struct dentry *dentry);extern int ima_inode_setxattr (struct dentry *dentry,const char *xattr_name,const void *xattr_value,size_t xattr_value_len);extern int ima_inode_removexattr (struct dentry *dentry,const char *xattr_name);
@@ -163,7 +168,8 @@ static inline bool is_ima_appraise_enabled(void)return 0 ; } -static inline void ima_inode_post_setattr (struct dentry *dentry) +static inline void ima_inode_post_setattr (struct user_namespace *mnt_userns, +struct dentry *dentry) {return ; }
security/integrity/ima/ima.h +12 -7
@@ -253,8 +253,9 @@ static inline void ima_process_queued_keys(void) {}#endif /* CONFIG_IMA_QUEUE_EARLY_BOOT_KEYS */ /* LIM API function definitions */ -int ima_get_action (struct inode *inode,const struct cred *cred,u32 secid, -int mask,enum ima_hooks func,int *pcr, +int ima_get_action (struct user_namespace *mnt_userns,struct inode *inode, +const struct cred *cred,u32 secid,int mask, +enum ima_hooks func,int *pcr,struct ima_template_desc **template_desc,const char *keyring);int ima_must_measure (struct inode *inode,int mask,enum ima_hooks func);
@@ -266,7 +267,8 @@ void ima_store_measurement(struct integrity_iint_cache *iint, struct file *file,struct evm_ima_xattr_data *xattr_value, int xattr_len, const struct modsig *modsig, int pcr, struct ima_template_desc *template_desc); -void process_buffer_measurement (struct inode *inode,const void *buf,int size, +void process_buffer_measurement (struct user_namespace *mnt_userns, +struct inode *inode,const void *buf,int size,const char *eventname,enum ima_hooks func,int pcr,const char *keyring); void ima_audit_measurement(struct integrity_iint_cache *iint,
@@ -281,8 +283,9 @@ void ima_free_template_entry(struct ima_template_entry *entry);const char *ima_d_path (const struct path *path,char **pathbuf,char *filename);/* IMA policy related functions */ -int ima_match_policy (struct inode *inode,const struct cred *cred,u32 secid, -enum ima_hooks func,int mask,int flags,int *pcr, +int ima_match_policy (struct user_namespace *mnt_userns,struct inode *inode, +const struct cred *cred,u32 secid,enum ima_hooks func, +int mask,int flags,int *pcr,struct ima_template_desc **template_desc,const char *keyring);void ima_init_policy (void );
@@ -313,7 +316,8 @@ int ima_appraise_measurement(enum ima_hooks func, struct file *file, const unsigned char *filename, struct evm_ima_xattr_data *xattr_value, int xattr_len, const struct modsig *modsig); -int ima_must_appraise (struct inode *inode,int mask,enum ima_hooks func); +int ima_must_appraise (struct user_namespace *mnt_userns,struct inode *inode, +int mask,enum ima_hooks func);void ima_update_xattr (struct integrity_iint_cache *iint,struct file *file);enum integrity_status ima_get_cache_status (struct integrity_iint_cache *iint,enum ima_hooks func);
@@ -340,7 +344,8 @@ static inline int ima_appraise_measurement(enum ima_hooks func,return INTEGRITY_UNKNOWN ; } -static inline int ima_must_appraise (struct inode *inode,int mask, +static inline int ima_must_appraise (struct user_namespace *mnt_userns, +struct inode *inode,int mask,enum ima_hooks func) {return 0 ;
security/integrity/ima/ima_api.c +6 -4
@@ -162,6 +162,7 @@ void ima_add_violation(struct file *file, const unsigned char *filename,/** * ima_get_action - appraise & measure decision based on policy. +* @mnt_userns: user namespace of the mount the inode was found from * @inode: pointer to the inode associated with the object being validated * @cred: pointer to credentials structure to validate * @secid: secid of the task being validated
@@ -183,8 +184,9 @@ void ima_add_violation(struct file *file, const unsigned char *filename,* Returns IMA_MEASURE, IMA_APPRAISE mask. * */ -int ima_get_action (struct inode *inode,const struct cred *cred,u32 secid, -int mask,enum ima_hooks func,int *pcr, +int ima_get_action (struct user_namespace *mnt_userns,struct inode *inode, +const struct cred *cred,u32 secid,int mask, +enum ima_hooks func,int *pcr,struct ima_template_desc **template_desc,const char *keyring) {
@@ -192,8 +194,8 @@ int ima_get_action(struct inode *inode, const struct cred *cred, u32 secid, flags &= ima_policy_flag; -return ima_match_policy (inode, cred, secid, func, mask, flags, pcr, - template_desc, keyring); +return ima_match_policy (mnt_userns, inode, cred, secid, func, mask, + flags, pcr, template_desc, keyring); }/*
security/integrity/ima/ima_appraise.c +9 -6
@@ -68,7 +68,8 @@ bool is_ima_appraise_enabled(void)* * Return 1 to appraise or hash */ -int ima_must_appraise (struct inode *inode,int mask,enum ima_hooks func) +int ima_must_appraise (struct user_namespace *mnt_userns,struct inode *inode, +int mask,enum ima_hooks func) {u32 secid;
@@ -76,8 +77,8 @@ int ima_must_appraise(struct inode *inode, int mask, enum ima_hooks func)return 0 ;security_task_getsecid (current, &secid); -return ima_match_policy (inode,current_cred (), secid, func, mask, -IMA_APPRAISE |IMA_HASH ,NULL ,NULL ,NULL ); +return ima_match_policy (mnt_userns, inode,current_cred (), secid, func, + mask,IMA_APPRAISE |IMA_HASH ,NULL ,NULL ,NULL ); } static int ima_fix_xattr(struct dentry *dentry,
@@ -350,7 +351,7 @@ int ima_check_blacklist(struct integrity_iint_cache *iint, rc =is_binary_blacklisted (digest, digestsize);if ((rc == -EPERM ) && (iint->flags &IMA_MEASURE )) -process_buffer_measurement (NULL , digest, digestsize, +process_buffer_measurement (&init_user_ns,NULL , digest, digestsize,"blacklisted-hash" ,NONE , pcr,NULL ); }
@@ -501,6 +502,7 @@ void ima_update_xattr(struct integrity_iint_cache *iint, struct file *file)/** * ima_inode_post_setattr - reflect file metadata changes +* @mnt_userns: user namespace of the mount the inode was found from * @dentry: pointer to the affected dentry * * Changes to a dentry's metadata might result in needing to appraise.
@@ -508,7 +510,8 @@ void ima_update_xattr(struct integrity_iint_cache *iint, struct file *file)* This function is called from notify_change(), which expects the caller * to lock the inode's i_mutex. */ -void ima_inode_post_setattr (struct dentry *dentry) +void ima_inode_post_setattr (struct user_namespace *mnt_userns, +struct dentry *dentry) {struct inode *inode =d_backing_inode (dentry);struct integrity_iint_cache *iint;
@@ -518,7 +521,7 @@ void ima_inode_post_setattr(struct dentry *dentry) || !(inode->i_opflags & IOP_XATTR))return ; - action =ima_must_appraise (inode,MAY_ACCESS ,POST_SETATTR ); + action =ima_must_appraise (mnt_userns, inode,MAY_ACCESS ,POST_SETATTR );if (!action)__vfs_removexattr (&init_user_ns, dentry,XATTR_NAME_IMA ); iint =integrity_iint_find (inode);
security/integrity/ima/ima_asymmetric_keys.c +2 -1
@@ -10,6 +10,7 @@*/ #include <keys/asymmetric-type.h> +#include <linux/user_namespace.h> #include "ima.h" /**
@@ -58,7 +59,7 @@ void ima_post_key_create_or_update(struct key *keyring, struct key *key,* if the IMA policy is configured to measure a key linked * to the given keyring. */ -process_buffer_measurement (NULL , payload, payload_len, +process_buffer_measurement (&init_user_ns,NULL , payload, payload_len, keyring->description,KEY_CHECK ,0 , keyring->description); }
security/integrity/ima/ima_main.c +24 -13
@@ -218,8 +218,8 @@ static int process_measurement(struct file *file, const struct cred *cred,* bitmask based on the appraise/audit/measurement policy. * Included is the appraise submask. */ - action =ima_get_action (inode, cred, secid, mask, func, &pcr, - &template_desc,NULL ); + action =ima_get_action (file_mnt_user_ns (file), inode, cred, secid, + mask, func, &pcr, &template_desc,NULL ); violation_check = ((func ==FILE_CHECK || func ==MMAP_CHECK ) && (ima_policy_flag &IMA_MEASURE ));if (!action && !violation_check)
@@ -431,8 +431,9 @@ int ima_file_mprotect(struct vm_area_struct *vma, unsigned long prot)security_task_getsecid (current, &secid); inode =file_inode (vma->vm_file); - action =ima_get_action (inode,current_cred (), secid,MAY_EXEC , -MMAP_CHECK , &pcr, &template,0 ); + action =ima_get_action (file_mnt_user_ns (vma->vm_file), inode, +current_cred (), secid,MAY_EXEC ,MMAP_CHECK , + &pcr, &template,0 );/* Is the mmap'ed file in policy? */ if (!(action & (IMA_MEASURE |IMA_APPRAISE_SUBMASK )))
@@ -592,18 +593,21 @@ EXPORT_SYMBOL_GPL(ima_inode_hash);/** * ima_post_create_tmpfile - mark newly created tmpfile as new +* @mnt_userns: user namespace of the mount the inode was found from * @file : newly created tmpfile * * No measuring, appraising or auditing of newly created tmpfiles is needed. * Skip calling process_measurement(), but indicate which newly, created * tmpfiles are in policy. */ -void ima_post_create_tmpfile (struct inode *inode) +void ima_post_create_tmpfile (struct user_namespace *mnt_userns, +struct inode *inode) {struct integrity_iint_cache *iint;int must_appraise; - must_appraise =ima_must_appraise (inode,MAY_ACCESS ,FILE_CHECK ); + must_appraise =ima_must_appraise (mnt_userns, inode,MAY_ACCESS , +FILE_CHECK );if (!must_appraise)return ;
@@ -619,18 +623,21 @@ void ima_post_create_tmpfile(struct inode *inode)/** * ima_post_path_mknod - mark as a new inode +* @mnt_userns: user namespace of the mount the inode was found from * @dentry: newly created dentry * * Mark files created via the mknodat syscall as new, so that the * file data can be written later. */ -void ima_post_path_mknod (struct dentry *dentry) +void ima_post_path_mknod (struct user_namespace *mnt_userns, +struct dentry *dentry) {struct integrity_iint_cache *iint;struct inode *inode = dentry->d_inode;int must_appraise; - must_appraise =ima_must_appraise (inode,MAY_ACCESS ,FILE_CHECK ); + must_appraise =ima_must_appraise (mnt_userns, inode,MAY_ACCESS , +FILE_CHECK );if (!must_appraise)return ;
@@ -810,6 +817,7 @@ int ima_post_load_data(char *buf, loff_t size,/* * process_buffer_measurement - Measure the buffer to ima log. +* @mnt_userns: user namespace of the mount the inode was found from * @inode: inode associated with the object being measured (NULL for KEY_CHECK) * @buf: pointer to the buffer that needs to be added to the log. * @size: size of buffer(in bytes).
@@ -820,7 +828,8 @@ int ima_post_load_data(char *buf, loff_t size,* * Based on policy, the buffer is measured into the ima log. */ -void process_buffer_measurement (struct inode *inode,const void *buf,int size, +void process_buffer_measurement (struct user_namespace *mnt_userns, +struct inode *inode,const void *buf,int size,const char *eventname,enum ima_hooks func,int pcr,const char *keyring) {
@@ -860,8 +869,9 @@ void process_buffer_measurement(struct inode *inode, const void *buf, int size,*/ if (func) {security_task_getsecid (current, &secid); - action =ima_get_action (inode,current_cred (), secid,0 , func, - &pcr, &template, keyring); + action =ima_get_action (mnt_userns, inode,current_cred (), + secid,0 , func, &pcr, &template, + keyring);if (!(action &IMA_MEASURE ))return ; }
@@ -919,8 +929,9 @@ void ima_kexec_cmdline(int kernel_fd, const void *buf, int size)if (!f.file)return ; -process_buffer_measurement (file_inode (f.file), buf, size, -"kexec-cmdline" ,KEXEC_CMDLINE ,0 ,NULL ); +process_buffer_measurement (file_mnt_user_ns (f.file),file_inode (f.file), + buf, size,"kexec-cmdline" ,KEXEC_CMDLINE ,0 , +NULL );fdput (f); }
security/integrity/ima/ima_policy.c +12 -8
@@ -488,6 +488,7 @@ static bool ima_match_keyring(struct ima_rule_entry *rule,/** * ima_match_rules - determine whether an inode matches the policy rule. * @rule: a pointer to a rule +* @mnt_userns: user namespace of the mount the inode was found from * @inode: a pointer to an inode * @cred: a pointer to a credentials structure for user validation * @secid: the secid of the task to be validated
@@ -497,9 +498,10 @@ static bool ima_match_keyring(struct ima_rule_entry *rule,* * Returns true on rule match, false on failure. */ -static bool ima_match_rules (struct ima_rule_entry *rule,struct inode *inode, -const struct cred *cred,u32 secid, -enum ima_hooks func,int mask, +static bool ima_match_rules (struct ima_rule_entry *rule, +struct user_namespace *mnt_userns, +struct inode *inode,const struct cred *cred, +u32 secid,enum ima_hooks func,int mask,const char *keyring) {int i;
@@ -539,7 +541,7 @@ static bool ima_match_rules(struct ima_rule_entry *rule, struct inode *inode, }if ((rule->flags &IMA_FOWNER ) && - !rule->fowner_op (inode->i_uid, rule->fowner)) + !rule->fowner_op (i_uid_into_mnt (mnt_userns, inode), rule->fowner))return false;for (i =0 ; i <MAX_LSM_RULES ; i++) {int rc =0 ;
@@ -602,6 +604,7 @@ static int get_subaction(struct ima_rule_entry *rule, enum ima_hooks func)/** * ima_match_policy - decision based on LSM and other conditions +* @mnt_userns: user namespace of the mount the inode was found from * @inode: pointer to an inode for which the policy decision is being made * @cred: pointer to a credentials structure for which the policy decision is * being made
@@ -620,8 +623,9 @@ static int get_subaction(struct ima_rule_entry *rule, enum ima_hooks func)* list when walking it. Reads are many orders of magnitude more numerous * than writes so ima_match_policy() is classical RCU candidate. */ -int ima_match_policy (struct inode *inode,const struct cred *cred,u32 secid, -enum ima_hooks func,int mask,int flags,int *pcr, +int ima_match_policy (struct user_namespace *mnt_userns,struct inode *inode, +const struct cred *cred,u32 secid,enum ima_hooks func, +int mask,int flags,int *pcr,struct ima_template_desc **template_desc,const char *keyring) {
@@ -637,8 +641,8 @@ int ima_match_policy(struct inode *inode, const struct cred *cred, u32 secid,if (!(entry->action & actmask))continue ; -if (!ima_match_rules (entry, inode, cred, secid, func, mask, - keyring)) +if (!ima_match_rules (entry, mnt_userns, inode, cred, secid, + func, mask, keyring))continue ; action |= entry->flags &IMA_ACTION_FLAGS ;
security/integrity/ima/ima_queue_keys.c +3 -1
@@ -8,6 +8,7 @@* Enables deferred processing of keys */ +#include <linux/user_namespace.h> #include <linux/workqueue.h> #include <keys/asymmetric-type.h> #include "ima.h"
@@ -158,7 +159,8 @@ void ima_process_queued_keys(void)list_for_each_entry_safe (entry, tmp, &ima_keys, list) {if (!timer_expired) - process_buffer_measurement(NULL, entry->payload, + process_buffer_measurement(&init_user_ns, NULL, + entry->payload, entry->payload_len, entry->keyring_name, KEY_CHECK, 0,
Signature · 6 lines
2.30.0 _______________________________________________ Containers mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/containers
PATCH v6 28/40 overlayfs: do not mount on top of idmapped mounts
In reply to Christian BraunerPrevent overlayfs from being mounted on top of idmapped mounts. Stacking filesystems need to be prevented from being mounted on top of idmapped mounts until they have have been converted to handle this.
---
/* v2 */
patch introduced
/* v3 */
- Amir Goldstein <[email protected]>:
- Move check for idmapped lower layers into ovl_mount_dir_noesc().
- David Howells <[email protected]>:
- Adapt check after removing mnt_idmapped() helper.
/* v4 */
unchanged
/* v5 */
unchanged
base-commit: 7c53f6b671f4aba70ff15e1b05148b10d58c2837
/* v6 */
unchanged
base-commit: 19c329f6808995b142b3966301f217c831e7cf31
--- fs/overlayfs/super.c | 4 ++++ 1 file changed, 4 insertions(+)
fs/overlayfs/super.c +4 -0
@@ -858,6 +858,10 @@ static int ovl_mount_dir_noesc(const char *name, struct path *path)pr_err ("filesystem on '%s' not supported\n" , name); goto out_put; } +if (mnt_user_ns (path->mnt) != &init_user_ns) { +pr_err ("idmapped layers are currently not supported\n" ); + goto out_put; + }if (!d_is_dir (path->dentry)) {pr_err ("'%s' not a directory\n" , name); goto out_put;
Signature · 6 lines
2.30.0 _______________________________________________ Containers mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/containers
Re: [PATCH v6 28/40] overlayfs: do not mount on top of idmapped mounts
Quoted 10 lines · Christian Brauner
Prevent overlayfs from being mounted on top of idmapped mounts. Stacking filesystems need to be prevented from being mounted on top of idmapped mounts until they have have been converted to handle this.
Cc Christoph Hellwig <[email protected]>Cc David Howells <[email protected]>Cc Al Viro <[email protected]>Signed-off-by Christian Brauner <[email protected]>
Signature · 7 lines
James Morris <[email protected]> _______________________________________________ Containers mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/containers
PATCH v6 29/40 namespace: take lock_mount_hash() directly when changing flags
In reply to Christian BraunerChanging mount options always ends up taking lock_mount_hash() but when MNT_READONLY is requested and neither the mount nor the superblock are MNT_READONLY we end up taking the lock, dropping it, and retaking it to change the other mount attributes. Instead, let's acquire the lock once when changing the mount attributes. This simplifies the locking in these codepath, makes them easier to reason about and avoids having to reacquire the lock right after dropping it.
---
/* v2 */
- Christoph Hellwig <[email protected]>:
- Remove pointless __mnt_unmake_readonly() helper.
- Even though Christoph suggested to lockdep_assert_held() into places that require {lock,unlock}_mount_hash() it seems that seqlock's don't support it.
/* v3 */
unchanged
/* v4 */
unchanged
/* v5 */
unchanged
base-commit: 7c53f6b671f4aba70ff15e1b05148b10d58c2837
/* v6 */
unchanged
base-commit: 19c329f6808995b142b3966301f217c831e7cf31
--- fs/namespace.c | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-)
fs/namespace.c +8 -14
@@ -464,7 +464,6 @@ static int mnt_make_readonly(struct mount *mnt) {int ret =0 ; -lock_mount_hash (); mnt->mnt.mnt_flags |=MNT_WRITE_HOLD ;/* * After storing MNT_WRITE_HOLD, we'll read the counters. This store
@@ -498,18 +497,9 @@ static int mnt_make_readonly(struct mount *mnt)*/ smp_wmb (); mnt->mnt.mnt_flags &= ~MNT_WRITE_HOLD ; -unlock_mount_hash ();return ret; } -static int __mnt_unmake_readonly (struct mount *mnt) -{ -lock_mount_hash (); - mnt->mnt.mnt_flags &= ~MNT_READONLY ; -unlock_mount_hash (); -return 0 ; -} -int sb_prepare_remount_readonly (struct super_block *sb) {struct mount *mnt;
@@ -2523,7 +2513,8 @@ static int change_mount_ro_state(struct mount *mnt, unsigned int mnt_flags)if (readonly_request)return mnt_make_readonly (mnt); -return __mnt_unmake_readonly (mnt); + mnt->mnt.mnt_flags &= ~MNT_READONLY ; +return 0 ; }/*
@@ -2532,11 +2523,9 @@ static int change_mount_ro_state(struct mount *mnt, unsigned int mnt_flags)*/ static void set_mount_attributes (struct mount *mnt,unsigned int mnt_flags) { -lock_mount_hash (); mnt_flags |= mnt->mnt.mnt_flags & ~MNT_USER_SETTABLE_MASK ; mnt->mnt.mnt_flags = mnt_flags;touch_mnt_namespace (mnt->mnt_ns); -unlock_mount_hash (); }static void mnt_warn_timestamp_expiry (struct path *mountpoint,struct vfsmount *mnt)
@@ -2582,9 +2571,11 @@ static int do_reconfigure_mnt(struct path *path, unsigned int mnt_flags)return -EPERM ;down_write (&sb->s_umount); +lock_mount_hash (); ret =change_mount_ro_state (mnt, mnt_flags);if (ret ==0 )set_mount_attributes (mnt, mnt_flags); +unlock_mount_hash ();up_write (&sb->s_umount);mnt_warn_timestamp_expiry (path, &mnt->mnt);
@@ -2625,8 +2616,11 @@ static int do_remount(struct path *path, int ms_flags, int sb_flags, err = -EPERM ;if (ns_capable (sb->s_user_ns,CAP_SYS_ADMIN )) { err =reconfigure_super (fc); -if (!err) +if (!err) { +lock_mount_hash ();set_mount_attributes (mnt, mnt_flags); +unlock_mount_hash (); + } }up_write (&sb->s_umount); }
Signature · 6 lines
2.30.0 _______________________________________________ Containers mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/containers
PATCH v6 30/40 mount: make {lock,unlock}_mount_hash() static
In reply to Christian BraunerThe lock_mount_hash() and unlock_mount_hash() helpers are never called outside a single file. Remove them from the header and make them static to reflect this fact. There's no need to have them callable from other places right now, as Christoph observed.
---
/* v2 */
- Christoph Hellwig <[email protected]>:
- Add a patch to make {lock,unlock)_mount_hash() static.
/* v3 */
unchanged
/* v4 */
unchanged
/* v5 */
unchanged
base-commit: 7c53f6b671f4aba70ff15e1b05148b10d58c2837
/* v6 */
unchanged
base-commit: 19c329f6808995b142b3966301f217c831e7cf31
--- fs/mount.h | 10 ---------- fs/namespace.c | 10 ++++++++++ 2 files changed, 10 insertions(+), 10 deletions(-)
fs/mount.h +0 -10
@@ -124,16 +124,6 @@ static inline void get_mnt_ns(struct mnt_namespace *ns)extern seqlock_t mount_lock; -static inline void lock_mount_hash (void ) -{ -write_seqlock (&mount_lock); -} - -static inline void unlock_mount_hash (void ) -{ -write_sequnlock (&mount_lock); -} -struct proc_mounts {struct mnt_namespace *ns;struct path root;
fs/namespace.c +10 -0
@@ -87,6 +87,16 @@ EXPORT_SYMBOL_GPL(fs_kobj);*/ __cacheline_aligned_in_smp DEFINE_SEQLOCK (mount_lock ); +static inline void lock_mount_hash (void ) +{ +write_seqlock (&mount_lock); +} + +static inline void unlock_mount_hash (void ) +{ +write_sequnlock (&mount_lock); +} +static inline struct hlist_head *m_hash (struct vfsmount *mnt,struct dentry *dentry) {unsigned long tmp = ((unsigned long )mnt /L1_CACHE_BYTES );
Signature · 6 lines
2.30.0 _______________________________________________ Containers mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/containers
PATCH v6 31/40 namespace: only take read lock in do_reconfigure_mnt()
In reply to Christian Braunerdo_reconfigure_mnt() used to take the down_write(&sb->s_umount) lock which seems unnecessary since we're not changing the superblock. We're only checking whether it is already read-only. Setting other mount attributes is protected by lock_mount_hash() afaict and not by s_umount.
The history of down_write(&sb->s_umount) lock being taken when setting mount attributes dates back to the introduction of MNT_READONLY in [2]. This introduced the concept of having read-only mounts in contrast to just having a read-only superblock. When it got introduced it was simply plumbed into do_remount() which already took down_write(&sb->s_umount) because it was only used to actually change the superblock before [2]. Afaict, it would've already been possible back then to only use down_read(&sb->s_umount) for MS_BIND | MS_REMOUNT since actual mount options were protected by the vfsmount lock already. But that would've meant special casing the locking for MS_BIND | MS_REMOUNT in do_remount() which people might not have considered worth it. Then in [1] MS_BIND | MS_REMOUNT mount option changes were split out of do_remount() into do_reconfigure_mnt() but the down_write(&sb->s_umount) lock was simply copied over.
Now that we have this be a separate helper only take the down_read(&sb->s_umount) lock since we're only interested in checking whether the super block is currently read-only and blocking any writers from changing it. Essentially, checking that the super block is read-only has the advantage that we can avoid having to go into the slowpath and through MNT_WRITE_HOLD and can simply set the read-only flag on the mount in set_mount_attributes().
[1]: commit 43f5e655eff7 ("vfs: Separate changing mount flags full remount") [2]: commit 2e4b7fcd9260 ("[PATCH] r/o bind mounts: honor mount writer counts at remount")
---
/* v2 */
unchanged
/* v3 */
unchanged
/* v4 */
unchanged
/* v5 */
unchanged
base-commit: 7c53f6b671f4aba70ff15e1b05148b10d58c2837
/* v6 */
unchanged
base-commit: 19c329f6808995b142b3966301f217c831e7cf31
--- fs/namespace.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
fs/namespace.c +6 -6
@@ -2527,10 +2527,6 @@ static int change_mount_ro_state(struct mount *mnt, unsigned int mnt_flags)return 0 ; } -/* -* Update the user-settable attributes on a mount. The caller must hold -* sb->s_umount for writing. -*/ static void set_mount_attributes (struct mount *mnt,unsigned int mnt_flags) { mnt_flags |= mnt->mnt.mnt_flags & ~MNT_USER_SETTABLE_MASK ;
@@ -2580,13 +2576,17 @@ static int do_reconfigure_mnt(struct path *path, unsigned int mnt_flags)if (!can_change_locked_flags (mnt, mnt_flags))return -EPERM ; -down_write (&sb->s_umount); +/* +* We're only checking whether the superblock is read-only not +* changing it, so only take down_read(&sb->s_umount). +*/ +down_read (&sb->s_umount);lock_mount_hash (); ret =change_mount_ro_state (mnt, mnt_flags);if (ret ==0 )set_mount_attributes (mnt, mnt_flags);unlock_mount_hash (); -up_write (&sb->s_umount); +up_read (&sb->s_umount);mnt_warn_timestamp_expiry (path, &mnt->mnt);
Signature · 6 lines
2.30.0 _______________________________________________ Containers mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/containers
PATCH v6 32/40 fs: split out functions to hold writers
In reply to Christian BraunerWhen a mount is marked read-only we set MNT_WRITE_HOLD on it if there aren't currently any active writers. Split this logic out into simple helpers that we can use in follow-up patches.
---
/* v2 */
patch not present
/* v3 */
patch not present
/* v4 */
patch introduced
/* v5 */
unchanged
base-commit: 7c53f6b671f4aba70ff15e1b05148b10d58c2837
/* v6 */
unchanged
base-commit: 19c329f6808995b142b3966301f217c831e7cf31
--- fs/namespace.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-)
fs/namespace.c +18 -6
@@ -470,10 +470,8 @@ void mnt_drop_write_file(struct file *file) }EXPORT_SYMBOL (mnt_drop_write_file); -static int mnt_make_readonly (struct mount *mnt) +static inline int mnt_hold_writers (struct mount *mnt) { -int ret =0 ; - mnt->mnt.mnt_flags |=MNT_WRITE_HOLD ;/* * After storing MNT_WRITE_HOLD, we'll read the counters. This store
@@ -498,15 +496,29 @@ static int mnt_make_readonly(struct mount *mnt)* we're counting up here. */ if (mnt_get_writers (mnt) >0 ) - ret = -EBUSY ; -else - mnt->mnt.mnt_flags |=MNT_READONLY ; +return -EBUSY ; + +return 0 ; +} + +static inline void mnt_unhold_writers (struct mount *mnt) +{/* * MNT_READONLY must become visible before ~MNT_WRITE_HOLD, so writers * that become unheld will see MNT_READONLY. */ smp_wmb (); mnt->mnt.mnt_flags &= ~MNT_WRITE_HOLD ; +} + +static int mnt_make_readonly (struct mount *mnt) +{ +int ret; + + ret =mnt_hold_writers (mnt); +if (!ret) + mnt->mnt.mnt_flags |=MNT_READONLY ; +mnt_unhold_writers (mnt);return ret; }
Signature · 6 lines
2.30.0 _______________________________________________ Containers mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/containers
PATCH v6 33/40 fs: add attr_flags_to_mnt_flags helper
In reply to Christian BraunerAdd a simple helper to translate uapi MOUNT_ATTR_* flags to MNT_* flags which we will use in follow-up patches too.
---
/* v2 */
patch not present
/* v3 */
patch not present
/* v4 */
patch introduced
/* v5 */
unchanged
base-commit: 7c53f6b671f4aba70ff15e1b05148b10d58c2837
/* v6 */
unchanged
base-commit: 19c329f6808995b142b3966301f217c831e7cf31
--- fs/namespace.c | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-)
fs/namespace.c +24 -16
@@ -3465,6 +3465,28 @@ SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,return ret; } +#define FSMOUNT_VALID_FLAGS \ + (MOUNT_ATTR_RDONLY | MOUNT_ATTR_NOSUID | MOUNT_ATTR_NODEV | \ + MOUNT_ATTR_NOEXEC | MOUNT_ATTR__ATIME | MOUNT_ATTR_NODIRATIME) + +static unsigned int attr_flags_to_mnt_flags (u64 attr_flags) +{ +unsigned int mnt_flags =0 ; + +if (attr_flags &MOUNT_ATTR_RDONLY ) + mnt_flags |=MNT_READONLY ; +if (attr_flags &MOUNT_ATTR_NOSUID ) + mnt_flags |=MNT_NOSUID ; +if (attr_flags &MOUNT_ATTR_NODEV ) + mnt_flags |=MNT_NODEV ; +if (attr_flags &MOUNT_ATTR_NOEXEC ) + mnt_flags |=MNT_NOEXEC ; +if (attr_flags &MOUNT_ATTR_NODIRATIME ) + mnt_flags |=MNT_NODIRATIME ; + +return mnt_flags; +} +/* * Create a kernel mount representation for a new, prepared superblock * (specified by fs_fd) and attach to an open_tree-like file descriptor.
@@ -3487,24 +3509,10 @@ SYSCALL_DEFINE3(fsmount, int, fs_fd, unsigned int, flags,if ((flags & ~(FSMOUNT_CLOEXEC )) !=0 )return -EINVAL ; -if (attr_flags & ~(MOUNT_ATTR_RDONLY | -MOUNT_ATTR_NOSUID | -MOUNT_ATTR_NODEV | -MOUNT_ATTR_NOEXEC | -MOUNT_ATTR__ATIME | -MOUNT_ATTR_NODIRATIME )) +if (attr_flags & ~FSMOUNT_VALID_FLAGS )return -EINVAL ; -if (attr_flags &MOUNT_ATTR_RDONLY ) - mnt_flags |=MNT_READONLY ; -if (attr_flags &MOUNT_ATTR_NOSUID ) - mnt_flags |=MNT_NOSUID ; -if (attr_flags &MOUNT_ATTR_NODEV ) - mnt_flags |=MNT_NODEV ; -if (attr_flags &MOUNT_ATTR_NOEXEC ) - mnt_flags |=MNT_NOEXEC ; -if (attr_flags &MOUNT_ATTR_NODIRATIME ) - mnt_flags |=MNT_NODIRATIME ; + mnt_flags =attr_flags_to_mnt_flags (attr_flags);switch (attr_flags &MOUNT_ATTR__ATIME ) {case MOUNT_ATTR_STRICTATIME :
Signature · 6 lines
2.30.0 _______________________________________________ Containers mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/containers
PATCH v6 34/40 fs: add mount_setattr()
In reply to Christian BraunerThis implements the missing mount_setattr() syscall. While the new mount api allows to change the properties of a superblock there is currently no way to change the properties of a mount or a mount tree using file descriptors which the new mount api is based on. In addition the old mount api has the restriction that mount options cannot be applied recursively. This hasn't changed since changing mount options on a per-mount basis was implemented in [1] and has been a frequent request not just for convenience but also for security reasons. The legacy mount syscall is unable to accommodate this behavior without introducing a whole new set of flags because MS_REC | MS_REMOUNT | MS_BIND | MS_RDONLY | MS_NOEXEC | [...] only apply the mount option to the topmost mount. Changing MS_REC to apply to the whole mount tree would mean introducing a significant uapi change and would likely cause significant regressions.
The new mount_setattr() syscall allows to recursively clear and set mount options in one shot. Multiple calls to change mount options requesting the same changes are idempotent:
int mount_setattr(int dfd, const char *path, unsigned flags,
struct mount_attr *uattr, size_t usize);
Flags to modify path resolution behavior are specified in the @flags argument. Currently, AT_EMPTY_PATH, AT_RECURSIVE, AT_SYMLINK_NOFOLLOW, and AT_NO_AUTOMOUNT are supported. If useful, additional lookup flags to restrict path resolution as introduced with openat2() might be supported in the future.
The mount_setattr() syscall can be expected to grow over time and is designed with extensibility in mind. It follows the extensible syscall pattern we have used with other syscalls such as openat2(), clone3(), sched_{set,get}attr(), and others.
The set of mount options is passed in the uapi struct mount_attr which currently has the following layout:
struct mount_attr {
__u64 attr_set;
__u64 attr_clr;
__u64 propagation;
};The @attr_set and @attr_clr members are used to clear and set mount options. This way a user can e.g. request that a set of flags is to be raised such as turning mounts readonly by raising MOUNT_ATTR_RDONLY in @attr_set while at the same time requesting that another set of flags is to be lowered such as removing noexec from a mount tree by specifying MOUNT_ATTR_NOEXEC in @attr_clr.
Note, since the MOUNT_ATTR_<atime> values are an enum starting from 0, not a bitmap, users wanting to transition to a different atime setting cannot simply specify the atime setting in @attr_set, but must also specify MOUNT_ATTR__ATIME in the @attr_clr field. So we ensure that MOUNT_ATTR__ATIME can't be partially set in @attr_clr and that @attr_set can't have any atime bits set if MOUNT_ATTR__ATIME isn't set in @attr_clr.
The @propagation field lets callers specify the propagation type of a mount tree. Propagation is a single property that has four different settings and as such is not really a flag argument but an enum. Specifically, it would be unclear what setting and clearing propagation settings in combination would amount to. The legacy mount() syscall thus forbids the combination of multiple propagation settings too. The goal is to keep the semantics of mount propagation somewhat simple as they are overly complex as it is.
[1]: commit 2e4b7fcd9260 ("[PATCH] r/o bind mounts: honor mount writer counts at remount")
---
/* v2 */
- Christoph Hellwig <[email protected]>:
- Split into multiple helpers.
/* v3 */
- kernel test robot <[email protected]>:
- Fix unknown __u64 type by including linux/types.h in linux/mount.h.
/* v4 */
- Christoph Hellwig <[email protected]>:
- Make sure lines wrap at 80 chars.
- Move struct mount_kattr out of the internal.h header and completely into fs/namespace.c as it's not used outside of that file.
- Add missing space between ( and { when initializing mount_kattr.
- Split flag validation and calculation into separate preparatory patch.
- Simplify flag validation in build_mount_kattr() to avoid upper_32_bits() and lower_32_bits() calls. This will also lead to better code generation.
- Remove new propagation enums and simply use the old flags.
- Strictly adhere to 80 char limit.
- Restructure the time setting code in build_mount_kattr().
/* v5 */
base-commit: 7c53f6b671f4aba70ff15e1b05148b10d58c2837
- Christoph Hellwig <[email protected]>:
- Simplify mount propagation flag checking.
- Wrap overly long line.
/* v6 */
unchanged
base-commit: 19c329f6808995b142b3966301f217c831e7cf31
--- arch/alpha/kernel/syscalls/syscall.tbl | 1 + arch/arm/tools/syscall.tbl | 1 + arch/arm64/include/asm/unistd.h | 2 +- arch/arm64/include/asm/unistd32.h | 2 + arch/ia64/kernel/syscalls/syscall.tbl | 1 + arch/m68k/kernel/syscalls/syscall.tbl | 1 + arch/microblaze/kernel/syscalls/syscall.tbl | 1 + arch/mips/kernel/syscalls/syscall_n32.tbl | 1 + arch/mips/kernel/syscalls/syscall_n64.tbl | 1 + arch/mips/kernel/syscalls/syscall_o32.tbl | 1 + arch/parisc/kernel/syscalls/syscall.tbl | 1 + arch/powerpc/kernel/syscalls/syscall.tbl | 1 + arch/s390/kernel/syscalls/syscall.tbl | 1 + arch/sh/kernel/syscalls/syscall.tbl | 1 + arch/sparc/kernel/syscalls/syscall.tbl | 1 + arch/x86/entry/syscalls/syscall_32.tbl | 1 + arch/x86/entry/syscalls/syscall_64.tbl | 1 + arch/xtensa/kernel/syscalls/syscall.tbl | 1 + fs/namespace.c | 260 ++++++++++++++++++++ include/linux/syscalls.h | 4 + include/uapi/asm-generic/unistd.h | 4 +- include/uapi/linux/mount.h | 14 ++ tools/include/uapi/asm-generic/unistd.h | 4 +- 23 files changed, 303 insertions(+), 3 deletions(-)
arch/alpha/kernel/syscalls/syscall.tbl +1 -0
@@ -481,3 +481,4 @@ 549 common faccessat2 sys_faccessat2 550 common process_madvise sys_process_madvise 551 common epoll_pwait2 sys_epoll_pwait2 +552 common mount_setattr sys_mount_setattr
arch/arm/tools/syscall.tbl +1 -0
@@ -455,3 +455,4 @@ 439 common faccessat2 sys_faccessat2 440 common process_madvise sys_process_madvise 441 common epoll_pwait2 sys_epoll_pwait2 +442 common mount_setattr sys_mount_setattr
arch/arm64/include/asm/unistd.h +1 -1
@@ -38,7 +38,7 @@#define __ARM_NR_compat_set_tls (__ARM_NR_COMPAT_BASE + 5)#define __ARM_NR_COMPAT_END (__ARM_NR_COMPAT_BASE + 0x800) -#define __NR_compat_syscalls 442 +#define __NR_compat_syscalls 443#endif #define __ARCH_WANT_SYS_CLONE
arch/arm64/include/asm/unistd32.h +2 -0
@@ -891,6 +891,8 @@ __SYSCALL(__NR_faccessat2, sys_faccessat2) __SYSCALL(__NR_process_madvise, sys_process_madvise)#define __NR_epoll_pwait2 441 __SYSCALL(__NR_epoll_pwait2, compat_sys_epoll_pwait2) +#define __NR_mount_setattr 442 +__SYSCALL (__NR_mount_setattr, sys_mount_setattr)/* * Please add new compat syscalls above this comment and update
arch/ia64/kernel/syscalls/syscall.tbl +1 -0
@@ -362,3 +362,4 @@ 439 common faccessat2 sys_faccessat2 440 common process_madvise sys_process_madvise 441 common epoll_pwait2 sys_epoll_pwait2 +442 common mount_setattr sys_mount_setattr
arch/m68k/kernel/syscalls/syscall.tbl +1 -0
@@ -441,3 +441,4 @@ 439 common faccessat2 sys_faccessat2 440 common process_madvise sys_process_madvise 441 common epoll_pwait2 sys_epoll_pwait2 +442 common mount_setattr sys_mount_setattr
arch/microblaze/kernel/syscalls/syscall.tbl +1 -0
@@ -447,3 +447,4 @@ 439 common faccessat2 sys_faccessat2 440 common process_madvise sys_process_madvise 441 common epoll_pwait2 sys_epoll_pwait2 +442 common mount_setattr sys_mount_setattr
arch/mips/kernel/syscalls/syscall_n32.tbl +1 -0
@@ -380,3 +380,4 @@ 439 n32 faccessat2 sys_faccessat2 440 n32 process_madvise sys_process_madvise 441 n32 epoll_pwait2 compat_sys_epoll_pwait2 +442 n32 mount_setattr sys_mount_setattr
arch/mips/kernel/syscalls/syscall_n64.tbl +1 -0
@@ -356,3 +356,4 @@ 439 n64 faccessat2 sys_faccessat2 440 n64 process_madvise sys_process_madvise 441 n64 epoll_pwait2 sys_epoll_pwait2 +442 n64 mount_setattr sys_mount_setattr
arch/mips/kernel/syscalls/syscall_o32.tbl +1 -0
@@ -429,3 +429,4 @@ 439 o32 faccessat2 sys_faccessat2 440 o32 process_madvise sys_process_madvise 441 o32 epoll_pwait2 sys_epoll_pwait2 compat_sys_epoll_pwait2 +442 o32 mount_setattr sys_mount_setattr
arch/parisc/kernel/syscalls/syscall.tbl +1 -0
@@ -439,3 +439,4 @@ 439 common faccessat2 sys_faccessat2 440 common process_madvise sys_process_madvise 441 common epoll_pwait2 sys_epoll_pwait2 compat_sys_epoll_pwait2 +442 common mount_setattr sys_mount_setattr
arch/powerpc/kernel/syscalls/syscall.tbl +1 -0
@@ -531,3 +531,4 @@ 439 common faccessat2 sys_faccessat2 440 common process_madvise sys_process_madvise 441 common epoll_pwait2 sys_epoll_pwait2 compat_sys_epoll_pwait2 +442 common mount_setattr sys_mount_setattr
arch/s390/kernel/syscalls/syscall.tbl +1 -0
@@ -444,3 +444,4 @@ 439 common faccessat2 sys_faccessat2 sys_faccessat2 440 common process_madvise sys_process_madvise sys_process_madvise 441 common epoll_pwait2 sys_epoll_pwait2 compat_sys_epoll_pwait2 +442 common mount_setattr sys_mount_setattr sys_mount_setattr
arch/sh/kernel/syscalls/syscall.tbl +1 -0
@@ -444,3 +444,4 @@ 439 common faccessat2 sys_faccessat2 440 common process_madvise sys_process_madvise 441 common epoll_pwait2 sys_epoll_pwait2 +442 common mount_setattr sys_mount_setattr
arch/sparc/kernel/syscalls/syscall.tbl +1 -0
@@ -487,3 +487,4 @@ 439 common faccessat2 sys_faccessat2 440 common process_madvise sys_process_madvise 441 common epoll_pwait2 sys_epoll_pwait2 compat_sys_epoll_pwait2 +442 common mount_setattr sys_mount_setattr
arch/x86/entry/syscalls/syscall_32.tbl +1 -0
@@ -446,3 +446,4 @@ 439 i386 faccessat2 sys_faccessat2 440 i386 process_madvise sys_process_madvise 441 i386 epoll_pwait2 sys_epoll_pwait2 compat_sys_epoll_pwait2 +442 i386 mount_setattr sys_mount_setattr
arch/x86/entry/syscalls/syscall_64.tbl +1 -0
@@ -363,6 +363,7 @@ 439 common faccessat2 sys_faccessat2 440 common process_madvise sys_process_madvise 441 common epoll_pwait2 sys_epoll_pwait2 +442 common mount_setattr sys_mount_setattr # # Due to a historical design error, certain syscalls are numbered differently
arch/xtensa/kernel/syscalls/syscall.tbl +1 -0
@@ -412,3 +412,4 @@ 439 common faccessat2 sys_faccessat2 440 common process_madvise sys_process_madvise 441 common epoll_pwait2 sys_epoll_pwait2 +442 common mount_setattr sys_mount_setattr
fs/namespace.c +260 -0
278 lines not on this page · raw message
include/linux/syscalls.h +4 -0
@@ -68,6 +68,7 @@ union bpf_attr;struct io_uring_params ;struct clone_args ;struct open_how ; +struct mount_attr ;#include <linux/types.h> #include <linux/aio_abi.h>
@@ -1028,6 +1029,9 @@ asmlinkage long sys_open_tree(int dfd, const char __user *path, unsigned flags);asmlinkage long sys_move_mount (int from_dfd,const char __user *from_path,int to_dfd,const char __user *to_path,unsigned int ms_flags); +asmlinkage long sys_mount_setattr (int dfd,const char __user *path, +unsigned int flags, +struct mount_attr __user *uattr,size_t usize);asmlinkage long sys_fsopen (const char __user *fs_name,unsigned int flags);asmlinkage long sys_fsconfig (int fs_fd,unsigned int cmd,const char __user *key,const void __user *value,int aux);
include/uapi/asm-generic/unistd.h +3 -1
@@ -861,9 +861,11 @@ __SYSCALL(__NR_faccessat2, sys_faccessat2) __SYSCALL(__NR_process_madvise, sys_process_madvise)#define __NR_epoll_pwait2 441 __SC_COMP(__NR_epoll_pwait2, sys_epoll_pwait2, compat_sys_epoll_pwait2) +#define __NR_mount_setattr 442 +__SYSCALL(__NR_mount_setattr, sys_mount_setattr)#undef __NR_syscalls -#define __NR_syscalls 442 +#define __NR_syscalls 443/* * 32 bit systems traditionally used different
include/uapi/linux/mount.h +14 -0
@@ -1,6 +1,8 @@#ifndef _UAPI_LINUX_MOUNT_H#define _UAPI_LINUX_MOUNT_H +#include <linux/types.h> +/* * These are the fs-independent mount-flags: up to 32 flags are supported *
@@ -118,4 +120,16 @@ enum fsconfig_command {#define MOUNT_ATTR_STRICTATIME 0x00000020/* - Always perform atime updates */ #define MOUNT_ATTR_NODIRATIME 0x00000080/* Do not update directory access times */ +/* +* mount_setattr() +*/ +struct mount_attr { +__u64 attr_set; +__u64 attr_clr; +__u64 propagation; +}; + +/* List of all mount_attr versions. */ +#define MOUNT_ATTR_SIZE_VER0 24/* sizeof first published struct */ +#endif /* _UAPI_LINUX_MOUNT_H */
tools/include/uapi/asm-generic/unistd.h +3 -1
@@ -861,9 +861,11 @@ __SYSCALL(__NR_faccessat2, sys_faccessat2) __SYSCALL(__NR_process_madvise, sys_process_madvise)#define __NR_epoll_pwait2 441 __SC_COMP(__NR_epoll_pwait2, sys_epoll_pwait2, compat_sys_epoll_pwait2) +#define __NR_mount_setattr 442 +__SYSCALL(__NR_mount_setattr, sys_mount_setattr)#undef __NR_syscalls -#define __NR_syscalls 442 +#define __NR_syscalls 443/* * 32 bit systems traditionally used different
Signature · 6 lines
2.30.0 _______________________________________________ Containers mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/containers
PATCH v6 35/40 fs: introduce MOUNT_ATTR_IDMAP
In reply to Christian BraunerIntroduce a new mount bind mount property to allow idmapping mounts. The MOUNT_ATTR_IDMAP flag can be set via the new mount_setattr() syscall together with a file descriptor referring to a user namespace.
The user namespace referenced by the namespace file descriptor will be attached to the bind mount. All interactions with the filesystem going through that mount will be mapped according to the mapping specified in the user namespace attached to it.
Using user namespaces to mark mounts means we can reuse all the existing infrastructure in the kernel that already exists to handle idmappings and can also use this for permission checking to allow unprivileged user to create idmapped mounts in the future.
Idmapping a mount is decoupled from the caller's user and mount namespace. This means idmapped mounts can be created in the initial user namespace which is an important use-case for systemd-homed, portable usb-sticks between systems, sharing data between the initial user namespace and unprivileged containers, and other use-cases that have been brought up. For example, assume a home directory where all files are owned by uid and gid 1000 and the home directory is brought to a new laptop where the user has id 12345. The system administrator can simply create a mount of this home directory with a mapping of 1000:12345:1 and other mappings to indicate the ids should be kept. (With this it is e.g. also possible to create idmapped mounts on the host with an identity mapping 1:1:100000 where the root user is not mapped. A user with root access that e.g. has been pivot rooted into such a mount on the host will be not be able to execute, read, write, or create files as root.)
Given that mapping a mount is decoupled from the caller's user namespace a sufficiently privileged process such as a container manager can set up an idmapped mount for the container and the container can simply pivot root to it. There's no need for the container to do anything. The mount will appear correctly mapped independent of the user namespace the container uses. This means we don't need to mark a mount as idmappable.
In order to create an idmapped mount the caller must currently be privileged in the user namespace of the superblock the mount belongs to. Once a mount has been idmapped we don't allow it to change its mapping. This keeps permission checking and life-cycle management simple. Users wanting to change the idmapped can always create a new detached mount with a different idmapping.
---
/* v2 */
- Christoph Hellwig <[email protected]>:
- Drop kconfig option to make vfs idmappings unconditional.
- Move introduction of MOUNT_ATTR_IDMAP to the end of the series after all internal changes have been done.
- Move MOUNT_ATTR_IDMAP handling from build_mount_kattr() to separate build_mount_idmapped() helper.
- Move MNT_IDMAPPED handling from do_mount_setattr() into separate do_mount_idmap() helper.
- Use more helpers instead of one big function for mount attribute changes.
- Mauricio Vásquez Bernal <[email protected]>:
- Recalculate flags before checking can_change_locked_flags().
/* v3 */
- David Howells <[email protected]>:
- Use smp_load_acquire() and smp_store_release() in mnt_user_ns() and do_idmap_mount().
- Remove all references to MNT_IDMAPPED now that the flag has been removed.
/* v4 */
- Serge Hallyn <[email protected]>:
- Use "mnt_userns" to refer to a vfsmount's userns everywhere to make terminology consistent.
/* v5 */
unchanged
base-commit: 7c53f6b671f4aba70ff15e1b05148b10d58c2837
/* v6 */
base-commit: 19c329f6808995b142b3966301f217c831e7cf31
- Christoph Hellwig <[email protected]>:
- Include userns_fd in MOUNT_ATTR_SIZE_VER0 instead of introducing a separate MOUNT_ATTR_SIZE_VER1.
--- fs/namespace.c | 115 +++++++++++++++++++++++++++++++++++-- fs/proc_namespace.c | 3 + include/linux/mount.h | 3 +- include/uapi/linux/mount.h | 4 +- 4 files changed, 119 insertions(+), 6 deletions(-)
fs/namespace.c +111 -4
@@ -25,6 +25,7 @@#include <linux/proc_ns.h> #include <linux/magic.h> #include <linux/memblock.h> +#include <linux/proc_fs.h> #include <linux/task_work.h> #include <linux/sched/task.h> #include <uapi/linux/mount.h>
@@ -79,6 +80,7 @@ struct mount_kattr {unsigned int propagation;unsigned int lookup_flags;bool recurse; +struct user_namespace *mnt_userns; };/* /sys/fs */
@@ -3477,7 +3479,7 @@ SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name, (MOUNT_ATTR_RDONLY |MOUNT_ATTR_NOSUID |MOUNT_ATTR_NODEV | \ MOUNT_ATTR_NOEXEC | MOUNT_ATTR__ATIME | MOUNT_ATTR_NODIRATIME) -#define MOUNT_SETATTR_VALID_FLAGS FSMOUNT_VALID_FLAGS +#define MOUNT_SETATTR_VALID_FLAGS (FSMOUNT_VALID_FLAGS | MOUNT_ATTR_IDMAP)#define MOUNT_SETATTR_PROPAGATION_FLAGS \ (MS_UNBINDABLE | MS_PRIVATE | MS_SLAVE | MS_SHARED)
@@ -3845,6 +3847,32 @@ static unsigned int recalc_flags(struct mount_kattr *kattr, struct mount *mnt)return flags; } +static int can_idmap_mount (const struct mount_kattr *kattr,struct mount *mnt) +{ +struct vfsmount *m = &mnt->mnt; + +if (!kattr->mnt_userns) +return 0 ; + +/* +* Once a mount has been idmapped we don't allow it to change its +* mapping. It makes things simpler and callers can just create +* another bind-mount they can idmap if they want to. +*/ +if (mnt_user_ns (m) != &init_user_ns) +return -EPERM ; + +/* The underlying filesystem doesn't support idmapped mounts yet. */ +if (!(m->mnt_sb->s_type->fs_flags &FS_ALLOW_IDMAP )) +return -EINVAL ; + +/* We're not controlling the superblock. */ +if (!ns_capable (m->mnt_sb->s_user_ns,CAP_SYS_ADMIN )) +return -EPERM ; + +return 0 ; +} +static struct mount *mount_setattr_prepare (struct mount_kattr *kattr,struct mount *mnt,int *err) {
@@ -3869,6 +3897,10 @@ static struct mount *mount_setattr_prepare(struct mount_kattr *kattr, goto out; } + *err =can_idmap_mount (kattr, m); +if (*err) + goto out; + last = m; if ((kattr->attr_set & MNT_READONLY) &&
@@ -3883,6 +3915,18 @@ static struct mount *mount_setattr_prepare(struct mount_kattr *kattr,return last; } +static void do_idmap_mount (const struct mount_kattr *kattr,struct mount *mnt) +{ +struct user_namespace *mnt_userns; + +if (!kattr->mnt_userns) +return ; + + mnt_userns =get_user_ns (kattr->mnt_userns); +/* Pairs with smp_load_acquire() in mnt_user_ns(). */ +smp_store_release (&mnt->mnt.mnt_userns, mnt_userns); +} +static void mount_setattr_commit (struct mount_kattr *kattr,struct mount *mnt,struct mount *last,int err)
@@ -3893,6 +3937,7 @@ static void mount_setattr_commit(struct mount_kattr *kattr,if (!err) {unsigned int flags; +do_idmap_mount (kattr, m); flags =recalc_flags (kattr, m);WRITE_ONCE (m->mnt.mnt_flags, flags); }
@@ -3965,7 +4010,62 @@ static int do_mount_setattr(struct path *path, struct mount_kattr *kattr)return err; } -static int build_mount_kattr (const struct mount_attr *attr, +static int build_mount_idmapped (const struct mount_attr *attr,size_t usize, +struct mount_kattr *kattr,unsigned int flags) +{ +int err =0 ; +struct ns_common *ns; +struct user_namespace *mnt_userns; +struct file *file; + +if (!((attr->attr_set | attr->attr_clr) &MOUNT_ATTR_IDMAP )) +return 0 ; + +/* +* We currently do not support clearing an idmapped mount. If this ever +* is a use-case we can revisit this but for now let's keep it simple +* and not allow it. +*/ +if (attr->attr_clr &MOUNT_ATTR_IDMAP ) +return -EINVAL ; + +if (attr->userns_fd >INT_MAX ) +return -EINVAL ; + + file =fget (attr->userns_fd); +if (!file) +return -EBADF ; + +if (!proc_ns_file (file)) { + err = -EINVAL ; + goto out_fput; + } + + ns =get_proc_ns (file_inode (file)); +if (ns->ops->type !=CLONE_NEWUSER ) { + err = -EINVAL ; + goto out_fput; + } + +/* +* The init_user_ns is used to indicate that a vfsmount is not idmapped. +* This is simpler than just having to treat NULL as unmapped. Users +* wanting to idmap a mount to init_user_ns can just use a namespace +* with an identity mapping. +*/ + mnt_userns = container_of(ns, struct user_namespace, ns); +if (mnt_userns == &init_user_ns) { + err = -EPERM ; + goto out_fput; + } + kattr->mnt_userns =get_user_ns (mnt_userns); + +out_fput: +fput (file); +return err; +} + +static int build_mount_kattr (const struct mount_attr *attr,size_t usize,struct mount_kattr *kattr,unsigned int flags) {unsigned int lookup_flags =LOOKUP_AUTOMOUNT |LOOKUP_FOLLOW ;
@@ -4029,7 +4129,13 @@ static int build_mount_kattr(const struct mount_attr *attr,return -EINVAL ; } -return 0 ; +return build_mount_idmapped (attr, usize, kattr, flags); +} + +static void finish_mount_kattr (struct mount_kattr *kattr) +{ +put_user_ns (kattr->mnt_userns); + kattr->mnt_userns =NULL ; } SYSCALL_DEFINE5(mount_setattr, int, dfd, const char __user *, path,
@@ -4067,7 +4173,7 @@ SYSCALL_DEFINE5(mount_setattr, int, dfd, const char __user *, path, attr.propagation == 0)return 0 ; - err =build_mount_kattr (&attr, &kattr, flags); + err =build_mount_kattr (&attr, usize, &kattr, flags);if (err)return err;
@@ -4076,6 +4182,7 @@ SYSCALL_DEFINE5(mount_setattr, int, dfd, const char __user *, path,return err; err =do_mount_setattr (&target, &kattr); +finish_mount_kattr (&kattr);path_put (&target);return err; }
fs/proc_namespace.c +3 -0
@@ -79,6 +79,9 @@ static void show_mnt_opts(struct seq_file *m, struct vfsmount *mnt)if (mnt->mnt_flags & fs_infop->flag)seq_puts (m, fs_infop->str); } + +if (mnt_user_ns (mnt) != &init_user_ns) +seq_puts (m,",idmapped" ); }static inline void mangle (struct seq_file *m,const char *s)
include/linux/mount.h +2 -1
@@ -77,7 +77,8 @@ struct vfsmount {static inline struct user_namespace *mnt_user_ns (const struct vfsmount *mnt) { -return mnt->mnt_userns; +/* Pairs with smp_store_release() in do_idmap_mount(). */ +return smp_load_acquire (&mnt->mnt_userns); }struct file ;/* forward dec */
include/uapi/linux/mount.h +3 -1
@@ -119,6 +119,7 @@ enum fsconfig_command {#define MOUNT_ATTR_NOATIME 0x00000010/* - Do not update access times. */ #define MOUNT_ATTR_STRICTATIME 0x00000020/* - Always perform atime updates */ #define MOUNT_ATTR_NODIRATIME 0x00000080/* Do not update directory access times */ +#define MOUNT_ATTR_IDMAP 0x00100000/* Idmap mount to @userns_fd in struct mount_attr. */ /* * mount_setattr()
@@ -127,9 +128,10 @@ struct mount_attr {__u64 attr_set;__u64 attr_clr;__u64 propagation; + __u64 userns_fd; };/* List of all mount_attr versions. */ -#define MOUNT_ATTR_SIZE_VER0 24/* sizeof first published struct */ +#define MOUNT_ATTR_SIZE_VER0 32/* sizeof first published struct */ #endif /* _UAPI_LINUX_MOUNT_H */
Signature · 6 lines
2.30.0 _______________________________________________ Containers mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/containers
Re: [PATCH v6 35/40] fs: introduce MOUNT_ATTR_IDMAP
include/uapi/linux/mount.h struct mount_attr { · line 135
Quoted 12 lines
/*
*mount_setattr()include/uapi/linux/mount.h +2
-1@@ -127,9 +128,10 @@ struct mount_attr {__u64 attr_set;__u64 attr_clr;__u64 propagation; +__u64 userns_fd; };/* List of all mount_attr versions. */ -#define MOUNT_ATTR_SIZE_VER0 24/* sizeof first published struct */ +#define MOUNT_ATTR_SIZE_VER0 32/* sizeof first published struct */
I think this hunk needs to go into the patch adding the structure.
_______________________________________________
Containers mailing list [email protected]
https://lists.linuxfoundation.org/mailman/listinfo/containers
Christoph Hellwig
Reviewed-byRe: [PATCH v6 35/40] fs: introduce MOUNT_ATTR_IDMAP
Quoted 9 lines · Christoph Hellwig
Quoted 9 lines
/*
*mount_setattr()include/uapi/linux/mount.h +1
-0@@ -127,9 +128,10 @@ struct mount_attr {__u64 attr_set;__u64 attr_clr;__u64 propagation; +__u64 userns_fd; };
Quoted 5 lines
include/uapi/linux/mount.h struct mount_attr { · line 135
Quoted 3 lines
include/uapi/linux/mount.h +1
-1/* List of all mount_attr versions. */ -#define MOUNT_ATTR_SIZE_VER0 24/* sizeof first published struct */ +#define MOUNT_ATTR_SIZE_VER0 32/* sizeof first published struct */ I think this hunk needs to go into the patch adding the structure.
But except for that the patch looks fine:
_______________________________________________
Containers mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/containers
PATCH v6 36/40 tests: add mount_setattr() selftests
In reply to Christian BraunerAdd a range of selftests for the new mount_setattr() syscall to verify that it works as expected. This tests that:
- no invalid flags can be specified
- changing properties of a single mount works and leaves other mounts in the mount tree unchanged
- changing a mount tre to read-only when one of the mounts has writers fails and leaves the whole mount tree unchanged
- changing mount properties from multiple threads works
- changing atime settings works
- changing mount propagation works
- changing the mount options of a mount tree where the individual mounts in the tree have different mount options only changes the flags that were requested to change
- changing mount options from another mount namespace fails
- changing mount options from another user namespace fails
- idmapped mounts
Note, the main test-suite for idmapped mounts is part of xfstests and is pretty huge. These tests here just make sure that the syscalls bits work correctly.
TAP version 13
1..20
# Starting 20 tests from 3 test cases.
# RUN mount_setattr.invalid_attributes ...
# OK mount_setattr.invalid_attributes
ok 1 mount_setattr.invalid_attributes
# RUN mount_setattr.extensibility ...
# OK mount_setattr.extensibility
ok 2 mount_setattr.extensibility
# RUN mount_setattr.basic ...
# OK mount_setattr.basic
ok 3 mount_setattr.basic
# RUN mount_setattr.basic_recursive ...
# OK mount_setattr.basic_recursive
ok 4 mount_setattr.basic_recursive
# RUN mount_setattr.mount_has_writers ...
# OK mount_setattr.mount_has_writers
ok 5 mount_setattr.mount_has_writers
# RUN mount_setattr.mixed_mount_options ...
# OK mount_setattr.mixed_mount_options
ok 6 mount_setattr.mixed_mount_options
# RUN mount_setattr.time_changes ...
# OK mount_setattr.time_changes
ok 7 mount_setattr.time_changes
# RUN mount_setattr.multi_threaded ...
# OK mount_setattr.multi_threaded
ok 8 mount_setattr.multi_threaded
# RUN mount_setattr.wrong_user_namespace ...
# OK mount_setattr.wrong_user_namespace
ok 9 mount_setattr.wrong_user_namespace
# RUN mount_setattr.wrong_mount_namespace ...
# OK mount_setattr.wrong_mount_namespace
ok 10 mount_setattr.wrong_mount_namespace
# RUN mount_setattr_idmapped.invalid_fd_negative ...
# OK mount_setattr_idmapped.invalid_fd_negative
ok 11 mount_setattr_idmapped.invalid_fd_negative
# RUN mount_setattr_idmapped.invalid_fd_large ...
# OK mount_setattr_idmapped.invalid_fd_large
ok 12 mount_setattr_idmapped.invalid_fd_large
# RUN mount_setattr_idmapped.invalid_fd_closed ...
# OK mount_setattr_idmapped.invalid_fd_closed
ok 13 mount_setattr_idmapped.invalid_fd_closed
# RUN mount_setattr_idmapped.invalid_fd_initial_userns ...
# OK mount_setattr_idmapped.invalid_fd_initial_userns
ok 14 mount_setattr_idmapped.invalid_fd_initial_userns
# RUN mount_setattr_idmapped.attached_mount_inside_current_mount_namespace ...
# OK mount_setattr_idmapped.attached_mount_inside_current_mount_namespace
ok 15 mount_setattr_idmapped.attached_mount_inside_current_mount_namespace
# RUN mount_setattr_idmapped.attached_mount_outside_current_mount_namespace ...
# OK mount_setattr_idmapped.attached_mount_outside_current_mount_namespace
ok 16 mount_setattr_idmapped.attached_mount_outside_current_mount_namespace
# RUN mount_setattr_idmapped.detached_mount_inside_current_mount_namespace ...
# OK mount_setattr_idmapped.detached_mount_inside_current_mount_namespace
ok 17 mount_setattr_idmapped.detached_mount_inside_current_mount_namespace
# RUN mount_setattr_idmapped.detached_mount_outside_current_mount_namespace ...
# OK mount_setattr_idmapped.detached_mount_outside_current_mount_namespace
ok 18 mount_setattr_idmapped.detached_mount_outside_current_mount_namespace
# RUN mount_setattr_idmapped.change_idmapping ...
# OK mount_setattr_idmapped.change_idmapping
ok 19 mount_setattr_idmapped.change_idmapping
# RUN mount_setattr_idmapped.idmap_mount_tree_invalid ...
# OK mount_setattr_idmapped.idmap_mount_tree_invalid
ok 20 mount_setattr_idmapped.idmap_mount_tree_invalid
# PASSED: 20 / 20 tests passed.
# Totals: pass:20 fail:0 xfail:0 xpass:0 skip:0 error:0
---
/* v2 */
unchanged
/* v3 */
- Christoph Hellwig <[email protected]>, Darrick J. Wong <[email protected]>:
- Port main test-suite to xfstests.
/* v4 */
unchanged
/* v5 */
unchanged
base-commit: 7c53f6b671f4aba70ff15e1b05148b10d58c2837
/* v6 */
unchanged
base-commit: 19c329f6808995b142b3966301f217c831e7cf31
--- tools/testing/selftests/Makefile | 1 + .../selftests/mount_setattr/.gitignore | 1 + .../testing/selftests/mount_setattr/Makefile | 7 + tools/testing/selftests/mount_setattr/config | 1 + .../mount_setattr/mount_setattr_test.c | 1424 +++++++++++++++++ 5 files changed, 1434 insertions(+) create mode 100644 tools/testing/selftests/mount_setattr/.gitignore create mode 100644 tools/testing/selftests/mount_setattr/Makefile create mode 100644 tools/testing/selftests/mount_setattr/config create mode 100644 tools/testing/selftests/mount_setattr/mount_setattr_test.c
tools/testing/selftests/Makefile +1 -0
@@ -33,6 +33,7 @@ TARGETS += memfd TARGETS += memory-hotplug TARGETS += mincore TARGETS += mount +TARGETS += mount_setattr TARGETS += mqueue TARGETS += net TARGETS += net/forwarding
tools/testing/selftests/mount_setattr/.gitignore new file +1 -0
@@ -0,0 +1 @@ +mount_setattr_test
tools/testing/selftests/mount_setattr/Makefile new file +7 -0
@@ -0,0 +1,7 @@ +# SPDX-License-Identifier: GPL-2.0 +# Makefile for mount selftests. +CFLAGS = -g -I../../../../usr/include/ -Wall -O2 -pthread + +TEST_GEN_FILES += mount_setattr_test + +include ../lib.mk
tools/testing/selftests/mount_setattr/config new file +1 -0
@@ -0,0 +1 @@ +CONFIG_USER_NS=y
tools/testing/selftests/mount_setattr/mount_setattr_test.c new file +1424 -0
1,424 lines not on this page · raw message
Signature · 6 lines
2.30.0 _______________________________________________ Containers mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/containers
PATCH v6 37/40 fat: handle idmapped mounts
In reply to Christian BraunerLet fat handle idmapped mounts. This allows to have the same fat mount appear in multiple locations with different id mappings. This allows to expose a vfat formatted USB stick to multiple user with different ids on the host or in user namespaces allowing for dac permissions:
mount -o uid=1000,gid=1000 /dev/sdb /mnt
u1001@f2-vm:/lower1$ ls -ln /mnt/ total 4 -rwxr-xr-x 1 1000 1000 4 Oct 28 03:44 aaa -rwxr-xr-x 1 1000 1000 0 Oct 28 01:09 bbb -rwxr-xr-x 1 1000 1000 0 Oct 28 01:10 ccc -rwxr-xr-x 1 1000 1000 0 Oct 28 03:46 ddd -rwxr-xr-x 1 1000 1000 0 Oct 28 04:01 eee
mount-idmapped --map-mount b:1000:1001:1
u1001@f2-vm:/lower1$ ls -ln /lower1/ total 4 -rwxr-xr-x 1 1001 1001 4 Oct 28 03:44 aaa -rwxr-xr-x 1 1001 1001 0 Oct 28 01:09 bbb -rwxr-xr-x 1 1001 1001 0 Oct 28 01:10 ccc -rwxr-xr-x 1 1001 1001 0 Oct 28 03:46 ddd -rwxr-xr-x 1 1001 1001 0 Oct 28 04:01 eee
u1001@f2-vm:/lower1$ touch /lower1/fff
u1001@f2-vm:/lower1$ ls -ln /lower1/fff -rwxr-xr-x 1 1001 1001 0 Oct 28 04:03 /lower1/fff
u1001@f2-vm:/lower1$ ls -ln /mnt/fff -rwxr-xr-x 1 1000 1000 0 Oct 28 04:03 /mnt/fff
---
/* v2 */
unchanged
/* v3 */
unchanged
/* v4 */
- Mauricio Vásquez Bernal <[email protected]>:
- Fix mount example in commit message.
- Serge Hallyn <[email protected]>:
- Use "mnt_userns" to refer to a vfsmount's userns everywhere to make terminology consistent.
/* v5 */
unchanged
base-commit: 7c53f6b671f4aba70ff15e1b05148b10d58c2837
/* v6 */
unchanged
base-commit: 19c329f6808995b142b3966301f217c831e7cf31
--- fs/fat/file.c | 15 ++++++++------- fs/fat/namei_msdos.c | 2 +- fs/fat/namei_vfat.c | 2 +- 3 files changed, 10 insertions(+), 9 deletions(-)
fs/fat/file.c +8 -7
@@ -398,7 +398,7 @@ int fat_getattr(struct user_namespace *mnt_userns, const struct path *path, struct kstat *stat, u32 request_mask, unsigned int flags) { struct inode *inode = d_inode(path->dentry); -generic_fillattr (&init_user_ns, inode, stat); +generic_fillattr (mnt_userns, inode, stat); stat->blksize =MSDOS_SB (inode->i_sb)->cluster_size;if (MSDOS_SB (inode->i_sb)->options.nfs ==FAT_NFS_NOSTALE_RO ) {
@@ -447,12 +447,13 @@ static int fat_sanitize_mode(const struct msdos_sb_info *sbi,return 0 ; } -static int fat_allow_set_time (struct msdos_sb_info *sbi,struct inode *inode) +static int fat_allow_set_time (struct user_namespace *mnt_userns, +struct msdos_sb_info *sbi,struct inode *inode) {umode_t allow_utime = sbi->options.allow_utime; -if (!uid_eq (current_fsuid (), inode->i_uid)) { -if (in_group_p (inode->i_gid)) +if (!uid_eq (current_fsuid (),i_uid_into_mnt (mnt_userns, inode))) { +if (in_group_p (i_gid_into_mnt (mnt_userns, inode))) allow_utime >>=3 ;if (allow_utime &MAY_WRITE )return 1 ;
@@ -477,11 +478,11 @@ int fat_setattr(struct user_namespace *mnt_userns, struct dentry *dentry,/* Check for setting the inode time. */ ia_valid = attr->ia_valid;if (ia_valid &TIMES_SET_FLAGS ) { -if (fat_allow_set_time (sbi, inode)) +if (fat_allow_set_time (mnt_userns, sbi, inode)) attr->ia_valid &= ~TIMES_SET_FLAGS ; } - error =setattr_prepare (&init_user_ns, dentry, attr); + error =setattr_prepare (mnt_userns, dentry, attr); attr->ia_valid = ia_valid;if (error) {if (sbi->options.quiet)
@@ -551,7 +552,7 @@ int fat_setattr(struct user_namespace *mnt_userns, struct dentry *dentry,fat_truncate_time (inode, &attr->ia_mtime,S_MTIME ); attr->ia_valid &= ~(ATTR_ATIME |ATTR_CTIME |ATTR_MTIME ); -setattr_copy (&init_user_ns, inode, attr); +setattr_copy (mnt_userns, inode, attr);mark_inode_dirty (inode); out:return error;
fs/fat/namei_msdos.c +1 -1
@@ -667,7 +667,7 @@ static struct file_system_type msdos_fs_type = { .name = "msdos", .mount = msdos_mount, .kill_sb = kill_block_super, - .fs_flags = FS_REQUIRES_DEV, + .fs_flags = FS_REQUIRES_DEV | FS_ALLOW_IDMAP, };MODULE_ALIAS_FS ("msdos" );
fs/fat/namei_vfat.c +1 -1
@@ -1063,7 +1063,7 @@ static struct file_system_type vfat_fs_type = { .name = "vfat", .mount = vfat_mount, .kill_sb = kill_block_super, - .fs_flags = FS_REQUIRES_DEV, + .fs_flags = FS_REQUIRES_DEV | FS_ALLOW_IDMAP, };MODULE_ALIAS_FS ("vfat" );
Signature · 6 lines
2.30.0 _______________________________________________ Containers mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/containers
PATCH v6 38/40 ext4: support idmapped mounts
In reply to Christian BraunerEnable idmapped mounts for ext4. All dedicated helpers we need for this exist. So this basically just means we're passing down the user_namespace argument from the VFS methods to the relevant helpers.
Let's create simple example where we idmap an ext4 filesystem:
root@f2-vm:~# truncate -s 5G ext4.img
root@f2-vm:~# mkfs.ext4 ./ext4.img
mke2fs 1.45.5 (07-Jan-2020)
Discarding device blocks: done
Creating filesystem with 1310720 4k blocks and 327680 inodes
Filesystem UUID: 3fd91794-c6ca-4b0f-9964-289a000919cf
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736 Allocating group tables: done
Writing inode tables: done
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done
root@f2-vm:~# losetup -f --show ./ext4.img /dev/loop0
root@f2-vm:~# mount /dev/loop0 /mnt
root@f2-vm:~# ls -al /mnt/ total 24 drwxr-xr-x 3 root root 4096 Oct 28 13:34 . drwxr-xr-x 30 root root 4096 Oct 28 13:22 .. drwx------ 2 root root 16384 Oct 28 13:34 lost+found
# Let's create an idmapped mount at /idmapped1 where we map uid and gid # 0 to uid and gid 1000
root@f2-vm:/# ./mount-idmapped --map-mount b:0:1000:1 /mnt/ /idmapped1/
root@f2-vm:/# ls -al /idmapped1/ total 24 drwxr-xr-x 3 ubuntu ubuntu 4096 Oct 28 13:34 . drwxr-xr-x 30 root root 4096 Oct 28 13:22 .. drwx------ 2 ubuntu ubuntu 16384 Oct 28 13:34 lost+found
# Let's create an idmapped mount at /idmapped2 where we map uid and gid # 0 to uid and gid 2000
root@f2-vm:/# ./mount-idmapped --map-mount b:0:2000:1 /mnt/ /idmapped2/
root@f2-vm:/# ls -al /idmapped2/ total 24 drwxr-xr-x 3 2000 2000 4096 Oct 28 13:34 . drwxr-xr-x 31 root root 4096 Oct 28 13:39 .. drwx------ 2 2000 2000 16384 Oct 28 13:34 lost+found
Let's create another example where we idmap the rootfs filesystem without a mapping for uid 0 and gid 0:
# Create an idmapped mount of for a full POSIX range of rootfs under
# /mnt but without a mapping for uid 0 to reduce attack surface
root@f2-vm:/# ./mount-idmapped --map-mount b:1:1:65536 / /mnt/
# Since we don't have a mapping for uid and gid 0 all files owned by
# uid and gid 0 should show up as uid and gid 65534: root@f2-vm:/# ls -al /mnt/ total 664 drwxr-xr-x 31 nobody nogroup 4096 Oct 28 13:39 . drwxr-xr-x 31 root root 4096 Oct 28 13:39 .. lrwxrwxrwx 1 nobody nogroup 7 Aug 25 07:44 bin -> usr/bin drwxr-xr-x 4 nobody nogroup 4096 Oct 28 13:17 boot drwxr-xr-x 2 nobody nogroup 4096 Aug 25 07:48 dev drwxr-xr-x 81 nobody nogroup 4096 Oct 28 04:00 etc drwxr-xr-x 4 nobody nogroup 4096 Oct 28 04:00 home lrwxrwxrwx 1 nobody nogroup 7 Aug 25 07:44 lib -> usr/lib lrwxrwxrwx 1 nobody nogroup 9 Aug 25 07:44 lib32 -> usr/lib32 lrwxrwxrwx 1 nobody nogroup 9 Aug 25 07:44 lib64 -> usr/lib64 lrwxrwxrwx 1 nobody nogroup 10 Aug 25 07:44 libx32 -> usr/libx32 drwx------ 2 nobody nogroup 16384 Aug 25 07:47 lost+found drwxr-xr-x 2 nobody nogroup 4096 Aug 25 07:44 media drwxr-xr-x 31 nobody nogroup 4096 Oct 28 13:39 mnt drwxr-xr-x 2 nobody nogroup 4096 Aug 25 07:44 opt drwxr-xr-x 2 nobody nogroup 4096 Apr 15 2020 proc drwx--x--x 6 nobody nogroup 4096 Oct 28 13:34 root drwxr-xr-x 2 nobody nogroup 4096 Aug 25 07:46 run lrwxrwxrwx 1 nobody nogroup 8 Aug 25 07:44 sbin -> usr/sbin drwxr-xr-x 2 nobody nogroup 4096 Aug 25 07:44 srv drwxr-xr-x 2 nobody nogroup 4096 Apr 15 2020 sys drwxrwxrwt 10 nobody nogroup 4096 Oct 28 13:19 tmp drwxr-xr-x 14 nobody nogroup 4096 Oct 20 13:00 usr drwxr-xr-x 12 nobody nogroup 4096 Aug 25 07:45 var
# Since we do have a mapping for uid and gid 1000 all files owned by
# uid and gid 1000 should simply show up as uid and gid 1000: root@f2-vm:/# ls -al /mnt/home/ubuntu/ total 40 drwxr-xr-x 3 ubuntu ubuntu 4096 Oct 28 00:43 . drwxr-xr-x 4 nobody nogroup 4096 Oct 28 04:00 .. -rw------- 1 ubuntu ubuntu 2936 Oct 28 12:26 .bash_history -rw-r--r-- 1 ubuntu ubuntu 220 Feb 25 2020 .bash_logout -rw-r--r-- 1 ubuntu ubuntu 3771 Feb 25 2020 .bashrc -rw-r--r-- 1 ubuntu ubuntu 807 Feb 25 2020 .profile -rw-r--r-- 1 ubuntu ubuntu 0 Oct 16 16:11 .sudo_as_admin_successful -rw------- 1 ubuntu ubuntu 1144 Oct 28 00:43 .viminfo
---
/* v2 */
unchanged
/* v3 */
unchanged
/* v4 */
- Mauricio Vásquez Bernal <[email protected]>:
- Fix spelling mistake in ext4's new idmapped mount config option.
- Christoph Hellwig <[email protected]>:
- Drop the config option. If ever want an administrator to disable this feature we can simply introduce a sysctl.
- Serge Hallyn <[email protected]>:
- Use "mnt_userns" to refer to a vfsmount's userns everywhere to make terminology consistent.
/* v5 */
base-commit: 7c53f6b671f4aba70ff15e1b05148b10d58c2837
- Christoph Hellwig <[email protected]>:
- Use new file_mnt_user_ns() helper.
- Christian Brauner <[email protected]>:
- Improve commit message.
/* v6 */
unchanged
base-commit: 19c329f6808995b142b3966301f217c831e7cf31
--- fs/ext4/acl.c | 3 +-- fs/ext4/ext4.h | 13 +++++++------ fs/ext4/ialloc.c | 7 ++++--- fs/ext4/inode.c | 11 ++++++----- fs/ext4/ioctl.c | 19 +++++++++++-------- fs/ext4/namei.c | 30 ++++++++++++++++-------------- fs/ext4/super.c | 2 +- 7 files changed, 46 insertions(+), 39 deletions(-)
fs/ext4/acl.c +1 -2
@@ -246,8 +246,7 @@ ext4_set_acl(struct user_namespace *mnt_userns, struct inode *inode,ext4_fc_start_update (inode);if ((type ==ACL_TYPE_ACCESS ) && acl) { - error =posix_acl_update_mode (&init_user_ns, inode, &mode, - &acl); + error =posix_acl_update_mode (mnt_userns, inode, &mode, &acl);if (error) goto out_stop;if (mode != inode->i_mode)
fs/ext4/ext4.h +7 -6
@@ -2755,18 +2755,19 @@ extern int ext4fs_dirhash(const struct inode *dir, const char *name, int len,/* ialloc.c */ extern int ext4_mark_inode_used (struct super_block *sb,int ino); -extern struct inode *__ext4_new_inode (handle_t *,struct inode *,umode_t , +extern struct inode *__ext4_new_inode (struct user_namespace *,handle_t *, +struct inode *,umode_t ,const struct qstr *qstr,__u32 goal,uid_t *owner,__u32 i_flags,int handle_type,unsigned int line_no,int nblocks); -#define ext4_new_inode (handle, dir, mode, qstr, goal, owner, i_flags) \ - __ext4_new_inode((handle), (dir), (mode), (qstr), (goal), (owner), \ - i_flags, 0, 0, 0) -#define ext4_new_inode_start_handle (dir, mode, qstr, goal, owner, \ +#define ext4_new_inode (handle, dir, mode, qstr, goal, owner, i_flags) \ + __ext4_new_inode(&init_user_ns, (handle), (dir), (mode), (qstr), \ + (goal), (owner), i_flags, 0, 0, 0) +#define ext4_new_inode_start_handle (mnt_userns, dir, mode, qstr, goal, owner, \ type, nblocks) \ - __ext4_new_inode(NULL, (dir), (mode), (qstr), (goal), (owner), \ + __ext4_new_inode((mnt_userns), NULL, (dir), (mode), (qstr), (goal), (owner), \ 0, (type), __LINE__, (nblocks))
fs/ext4/ialloc.c +4 -3
@@ -919,7 +919,8 @@ static int ext4_xattr_credits_for_new_inode(struct inode *dir, mode_t mode,* For other inodes, search forward from the parent directory's block * group to find a free inode. */ -struct inode *__ext4_new_inode(handle_t *handle, struct inode *dir, +struct inode *__ext4_new_inode(struct user_namespace *mnt_userns, + handle_t *handle, struct inode *dir, umode_t mode, const struct qstr *qstr, __u32 goal, uid_t *owner, __u32 i_flags, int handle_type, unsigned int line_no,
@@ -969,10 +970,10 @@ struct inode *__ext4_new_inode(handle_t *handle, struct inode *dir,i_gid_write (inode, owner[1 ]); }else if (test_opt (sb,GRPID )) { inode->i_mode = mode; - inode->i_uid =current_fsuid (); + inode->i_uid =fsuid_into_mnt (mnt_userns); inode->i_gid = dir->i_gid; }else -inode_init_owner (&init_user_ns, inode, dir, mode); +inode_init_owner (mnt_userns, inode, dir, mode);if (ext4_has_feature_project (sb) &&ext4_test_inode_flag (dir,EXT4_INODE_PROJINHERIT ))
fs/ext4/inode.c +6 -5
@@ -20,6 +20,7 @@*/ #include <linux/fs.h> +#include <linux/mount.h> #include <linux/time.h> #include <linux/highuid.h> #include <linux/pagemap.h>
@@ -5338,7 +5339,7 @@ int ext4_setattr(struct user_namespace *mnt_userns, struct dentry *dentry, ATTR_GID | ATTR_TIMES_SET))))return -EPERM ; - error =setattr_prepare (&init_user_ns, dentry, attr); + error =setattr_prepare (mnt_userns, dentry, attr);if (error)return error;
@@ -5513,7 +5514,7 @@ int ext4_setattr(struct user_namespace *mnt_userns, struct dentry *dentry, }if (!error) { -setattr_copy (&init_user_ns, inode, attr); +setattr_copy (mnt_userns, inode, attr);mark_inode_dirty (inode); }
@@ -5525,7 +5526,7 @@ int ext4_setattr(struct user_namespace *mnt_userns, struct dentry *dentry,ext4_orphan_del (NULL , inode);if (!error && (ia_valid &ATTR_MODE )) - rc =posix_acl_chmod (&init_user_ns, inode, inode->i_mode); + rc =posix_acl_chmod (mnt_userns, inode, inode->i_mode); err_out:if (error)
@@ -5572,7 +5573,7 @@ int ext4_getattr(struct user_namespace *mnt_userns, const struct path *path,STATX_ATTR_NODUMP | STATX_ATTR_VERITY); -generic_fillattr (&init_user_ns, inode, stat); +generic_fillattr (mnt_userns, inode, stat);return 0 ; }
@@ -5583,7 +5584,7 @@ int ext4_file_getattr(struct user_namespace *mnt_userns,struct inode *inode =d_inode (path->dentry);u64 delalloc_blocks; -ext4_getattr (&init_user_ns, path, stat, request_mask, query_flags); +ext4_getattr (mnt_userns, path, stat, request_mask, query_flags);/* * If there is inline data in the inode, the inode will normally not
fs/ext4/ioctl.c +11 -8
@@ -107,10 +107,12 @@ void ext4_reset_inode_seed(struct inode *inode)* important fields of the inodes. * * @sb: the super block of the filesystem +* @mnt_userns: user namespace of the mount the inode was found from * @inode: the inode to swap with EXT4_BOOT_LOADER_INO * */ static long swap_inode_boot_loader (struct super_block *sb, +struct user_namespace *mnt_userns,struct inode *inode) {handle_t *handle;
@@ -139,7 +141,7 @@ static long swap_inode_boot_loader(struct super_block *sb, }if (IS_RDONLY (inode) ||IS_APPEND (inode) ||IS_IMMUTABLE (inode) || - !inode_owner_or_capable (&init_user_ns, inode) || + !inode_owner_or_capable (mnt_userns, inode) || !capable (CAP_SYS_ADMIN )) { err = -EPERM ; goto journal_err_out;
@@ -815,6 +817,7 @@ static long __ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)struct inode *inode =file_inode (filp);struct super_block *sb = inode->i_sb;struct ext4_inode_info *ei =EXT4_I (inode); +struct user_namespace *mnt_userns =file_mnt_user_ns (filp);unsigned int flags;ext4_debug ("cmd = %u, arg = %lu\n" , cmd, arg);
@@ -830,7 +833,7 @@ static long __ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)case FS_IOC_SETFLAGS : {int err; -if (!inode_owner_or_capable (&init_user_ns, inode)) +if (!inode_owner_or_capable (mnt_userns, inode))return -EACCES ;if (get_user (flags, (int __user *) arg))
@@ -872,7 +875,7 @@ static long __ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)__u32 generation;int err; -if (!inode_owner_or_capable (&init_user_ns, inode)) +if (!inode_owner_or_capable (mnt_userns, inode))return -EPERM ;if (ext4_has_metadata_csum (inode->i_sb)) {
@@ -1011,7 +1014,7 @@ static long __ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)case EXT4_IOC_MIGRATE : {int err; -if (!inode_owner_or_capable (&init_user_ns, inode)) +if (!inode_owner_or_capable (mnt_userns, inode))return -EACCES ; err =mnt_want_write_file (filp);
@@ -1033,7 +1036,7 @@ static long __ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)case EXT4_IOC_ALLOC_DA_BLKS : {int err; -if (!inode_owner_or_capable (&init_user_ns, inode)) +if (!inode_owner_or_capable (mnt_userns, inode))return -EACCES ; err =mnt_want_write_file (filp);
@@ -1052,7 +1055,7 @@ static long __ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) err =mnt_want_write_file (filp);if (err)return err; - err =swap_inode_boot_loader (sb, inode); + err =swap_inode_boot_loader (sb, mnt_userns, inode);mnt_drop_write_file (filp);return err; }
@@ -1218,7 +1221,7 @@ static long __ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)case EXT4_IOC_CLEAR_ES_CACHE : { -if (!inode_owner_or_capable (&init_user_ns, inode)) +if (!inode_owner_or_capable (mnt_userns, inode))return -EACCES ;ext4_clear_inode_es (inode);return 0 ;
@@ -1264,7 +1267,7 @@ static long __ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)return -EFAULT ;/* Make sure caller has proper permission */ -if (!inode_owner_or_capable (&init_user_ns, inode)) +if (!inode_owner_or_capable (mnt_userns, inode))return -EACCES ;if (fa.fsx_xflags & ~EXT4_SUPPORTED_FS_XFLAGS )
fs/ext4/namei.c +16 -14
@@ -2610,8 +2610,8 @@ static int ext4_create(struct user_namespace *mnt_userns, struct inode *dir, credits = (EXT4_DATA_TRANS_BLOCKS (dir->i_sb) +EXT4_INDEX_EXTRA_TRANS_BLOCKS +3 ); retry: - inode =ext4_new_inode_start_handle (dir, mode, &dentry->d_name,0 , -NULL ,EXT4_HT_DIR , credits); + inode =ext4_new_inode_start_handle (mnt_userns, dir, mode, &dentry->d_name, +0 ,NULL ,EXT4_HT_DIR , credits); handle =ext4_journal_current_handle (); err =PTR_ERR (inode);if (!IS_ERR (inode)) {
@@ -2645,8 +2645,8 @@ static int ext4_mknod(struct user_namespace *mnt_userns, struct inode *dir, credits = (EXT4_DATA_TRANS_BLOCKS (dir->i_sb) +EXT4_INDEX_EXTRA_TRANS_BLOCKS +3 ); retry: - inode =ext4_new_inode_start_handle (dir, mode, &dentry->d_name,0 , -NULL ,EXT4_HT_DIR , credits); + inode =ext4_new_inode_start_handle (mnt_userns, dir, mode, &dentry->d_name, +0 ,NULL ,EXT4_HT_DIR , credits); handle =ext4_journal_current_handle (); err =PTR_ERR (inode);if (!IS_ERR (inode)) {
@@ -2677,7 +2677,7 @@ static int ext4_tmpfile(struct user_namespace *mnt_userns, struct inode *dir,return err; retry: - inode = ext4_new_inode_start_handle(dir, mode, + inode = ext4_new_inode_start_handle(mnt_userns, dir, mode, NULL, 0, NULL, EXT4_HT_DIR, EXT4_MAXQUOTAS_INIT_BLOCKS(dir->i_sb) +
@@ -2792,7 +2792,7 @@ static int ext4_mkdir(struct user_namespace *mnt_userns, struct inode *dir, credits = (EXT4_DATA_TRANS_BLOCKS (dir->i_sb) +EXT4_INDEX_EXTRA_TRANS_BLOCKS +3 ); retry: - inode =ext4_new_inode_start_handle (dir,S_IFDIR | mode, + inode =ext4_new_inode_start_handle (mnt_userns, dir,S_IFDIR | mode, &dentry->d_name,0 ,NULL ,EXT4_HT_DIR , credits); handle =ext4_journal_current_handle ();
@@ -3335,7 +3335,7 @@ static int ext4_symlink(struct user_namespace *mnt_userns, struct inode *dir,EXT4_INDEX_EXTRA_TRANS_BLOCKS +3 ; } - inode =ext4_new_inode_start_handle (dir,S_IFLNK |S_IRWXUGO , + inode =ext4_new_inode_start_handle (mnt_userns, dir,S_IFLNK |S_IRWXUGO , &dentry->d_name,0 ,NULL ,EXT4_HT_DIR , credits); handle =ext4_journal_current_handle ();
@@ -3664,7 +3664,8 @@ static void ext4_update_dir_count(handle_t *handle, struct ext4_renament *ent) } } -static struct inode *ext4_whiteout_for_rename (struct ext4_renament *ent, +static struct inode *ext4_whiteout_for_rename (struct user_namespace *mnt_userns, +struct ext4_renament *ent,int credits,handle_t **h) {struct inode *wh;
@@ -3678,7 +3679,8 @@ static struct inode *ext4_whiteout_for_rename(struct ext4_renament *ent, credits += (EXT4_MAXQUOTAS_TRANS_BLOCKS (ent->dir->i_sb) +EXT4_XATTR_TRANS_BLOCKS +4 ); retry: - wh =ext4_new_inode_start_handle (ent->dir,S_IFCHR |WHITEOUT_MODE , + wh =ext4_new_inode_start_handle (mnt_userns, ent->dir, +S_IFCHR |WHITEOUT_MODE , &ent->dentry->d_name,0 ,NULL ,EXT4_HT_DIR , credits);
@@ -3705,9 +3707,9 @@ static struct inode *ext4_whiteout_for_rename(struct ext4_renament *ent,* while new_{dentry,inode) refers to the destination dentry/inode * This comes from rename(const char *oldpath, const char *newpath) */ -static int ext4_rename (struct inode *old_dir,struct dentry *old_dentry, -struct inode *new_dir,struct dentry *new_dentry, -unsigned int flags) +static int ext4_rename (struct user_namespace *mnt_userns,struct inode *old_dir, +struct dentry *old_dentry,struct inode *new_dir, +struct dentry *new_dentry,unsigned int flags) {handle_t *handle =NULL ;struct ext4_renament old = {
@@ -3791,7 +3793,7 @@ static int ext4_rename(struct inode *old_dir, struct dentry *old_dentry, goto end_rename; } }else { - whiteout =ext4_whiteout_for_rename (&old, credits, &handle); + whiteout =ext4_whiteout_for_rename (mnt_userns, &old, credits, &handle);if (IS_ERR (whiteout)) { retval =PTR_ERR (whiteout); whiteout =NULL ;
@@ -4110,7 +4112,7 @@ static int ext4_rename2(struct user_namespace *mnt_userns, new_dir, new_dentry); } -return ext4_rename (old_dir, old_dentry, new_dir, new_dentry, flags); +return ext4_rename (mnt_userns, old_dir, old_dentry, new_dir, new_dentry, flags); }/*
fs/ext4/super.c +1 -1
@@ -6654,7 +6654,7 @@ static struct file_system_type ext4_fs_type = { .name = "ext4", .mount = ext4_mount, .kill_sb = kill_block_super, - .fs_flags = FS_REQUIRES_DEV, + .fs_flags = FS_REQUIRES_DEV | FS_ALLOW_IDMAP, };MODULE_ALIAS_FS ("ext4" );
Signature · 6 lines
2.30.0 _______________________________________________ Containers mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/containers
PATCH v6 39/40 xfs: support idmapped mounts
In reply to Christian BraunerFrom: Christoph Hellwig <[email protected]>
Enable idmapped mounts for xfs. This basically just means passing down the user_namespace argument from the VFS methods down to where it is passed to the relevant helpers.
Note that full-filesystem bulkstat is not supported from inside idmapped mounts as it is an administrative operation that acts on the whole file system. The limitation is not applied to the bulkstat single operation that just operates on a single inode.
---
/* v2 */
/* v3 */
/* v4 */
/* v5 */
base-commit: 7c53f6b671f4aba70ff15e1b05148b10d58c2837
/* v6 */
unchanged
base-commit: 19c329f6808995b142b3966301f217c831e7cf31
--- fs/xfs/xfs_acl.c | 3 +-- fs/xfs/xfs_file.c | 4 +++- fs/xfs/xfs_inode.c | 26 +++++++++++++++-------- fs/xfs/xfs_inode.h | 16 +++++++++------ fs/xfs/xfs_ioctl.c | 35 ++++++++++++++++++------------- fs/xfs/xfs_ioctl32.c | 6 ++++-- fs/xfs/xfs_iops.c | 49 +++++++++++++++++++++++++------------------- fs/xfs/xfs_iops.h | 3 ++- fs/xfs/xfs_itable.c | 17 +++++++++++---- fs/xfs/xfs_itable.h | 1 + fs/xfs/xfs_qm.c | 3 ++- fs/xfs/xfs_super.c | 2 +- fs/xfs/xfs_symlink.c | 5 +++-- fs/xfs/xfs_symlink.h | 5 +++-- 14 files changed, 110 insertions(+), 65 deletions(-)
fs/xfs/xfs_acl.c +1 -2
@@ -253,8 +253,7 @@ xfs_set_acl(struct user_namespace *mnt_userns, struct inode *inode,return error;if (type ==ACL_TYPE_ACCESS ) { - error =posix_acl_update_mode (&init_user_ns, inode, &mode, - &acl); + error =posix_acl_update_mode (mnt_userns, inode, &mode, &acl);if (error)return error; set_mode = true;
fs/xfs/xfs_file.c +3 -1
@@ -29,6 +29,7 @@#include <linux/backing-dev.h> #include <linux/mman.h> #include <linux/fadvise.h> +#include <linux/mount.h> static const struct vm_operations_struct xfs_file_vm_ops;
@@ -994,7 +995,8 @@ xfs_file_fallocate( iattr.ia_valid =ATTR_SIZE ; iattr.ia_size = new_size; - error =xfs_vn_setattr_size (file_dentry (file), &iattr); + error =xfs_vn_setattr_size (file_mnt_user_ns (file), +file_dentry (file), &iattr);if (error) goto out_unlock; }
fs/xfs/xfs_inode.c +18 -8
@@ -766,6 +766,7 @@ xfs_inode_inherit_flags2(*/ static int xfs_init_new_inode( + struct user_namespace *mnt_userns, struct xfs_trans *tp, struct xfs_inode *pip, xfs_ino_t ino,
@@ -806,7 +807,7 @@ xfs_init_new_inode( inode =VFS_I (ip); inode->i_mode = mode;set_nlink (inode, nlink); - inode->i_uid =current_fsuid (); + inode->i_uid =fsuid_into_mnt (mnt_userns); inode->i_rdev = rdev; ip->i_d.di_projid = prid;
@@ -815,7 +816,7 @@ xfs_init_new_inode(if ((VFS_I (pip)->i_mode &S_ISGID ) &&S_ISDIR (mode)) inode->i_mode |=S_ISGID ; }else { - inode->i_gid =current_fsgid (); + inode->i_gid =fsgid_into_mnt (mnt_userns); }/*
@@ -824,7 +825,8 @@ xfs_init_new_inode(* (and only if the irix_sgid_inherit compatibility variable is set). */ if (irix_sgid_inherit && - (inode->i_mode &S_ISGID ) && !in_group_p (inode->i_gid)) + (inode->i_mode &S_ISGID ) && + !in_group_p (i_gid_into_mnt (mnt_userns, inode))) inode->i_mode &= ~S_ISGID ; ip->i_d.di_size =0 ;
@@ -901,6 +903,7 @@ xfs_init_new_inode(*/ int xfs_dir_ialloc( + struct user_namespace *mnt_userns, struct xfs_trans **tpp, struct xfs_inode *dp, umode_t mode,
@@ -933,7 +936,8 @@ xfs_dir_ialloc(return error;ASSERT (ino !=NULLFSINO ); -return xfs_init_new_inode (*tpp, dp, ino, mode, nlink, rdev, prid, ipp); +return xfs_init_new_inode (mnt_userns, *tpp, dp, ino, mode, nlink, rdev, + prid, ipp); }/*
@@ -973,6 +977,7 @@ xfs_bumplink( int xfs_create( + struct user_namespace *mnt_userns, xfs_inode_t *dp, struct xfs_name *name, umode_t mode,
@@ -1047,7 +1052,8 @@ xfs_create(* entry pointing to them, but a directory also the "." entry * pointing to itself. */ - error =xfs_dir_ialloc (&tp, dp, mode, is_dir ?2 :1 , rdev, prid, &ip); + error =xfs_dir_ialloc (mnt_userns, &tp, dp, mode, is_dir ?2 :1 , rdev, + prid, &ip);if (error) goto out_trans_cancel;
@@ -1128,6 +1134,7 @@ xfs_create(int xfs_create_tmpfile ( +struct user_namespace *mnt_userns,struct xfs_inode *dp,umode_t mode,struct xfs_inode **ipp)
@@ -1169,7 +1176,7 @@ xfs_create_tmpfile(if (error) goto out_trans_cancel; - error =xfs_dir_ialloc (&tp, dp, mode,0 ,0 , prid, &ip); + error =xfs_dir_ialloc (mnt_userns, &tp, dp, mode,0 ,0 , prid, &ip);if (error) goto out_trans_cancel;
@@ -2977,13 +2984,15 @@ xfs_cross_rename(*/ static int xfs_rename_alloc_whiteout ( +struct user_namespace *mnt_userns,struct xfs_inode *dp,struct xfs_inode **wip) {struct xfs_inode *tmpfile;int error; - error =xfs_create_tmpfile (dp,S_IFCHR |WHITEOUT_MODE , &tmpfile); + error =xfs_create_tmpfile (mnt_userns, dp,S_IFCHR |WHITEOUT_MODE , + &tmpfile);if (error)return error;
@@ -3005,6 +3014,7 @@ xfs_rename_alloc_whiteout(*/ int xfs_rename( + struct user_namespace *mnt_userns, struct xfs_inode *src_dp, struct xfs_name *src_name, struct xfs_inode *src_ip,
@@ -3036,7 +3046,7 @@ xfs_rename(*/ if (flags &RENAME_WHITEOUT ) {ASSERT (!(flags & (RENAME_NOREPLACE |RENAME_EXCHANGE ))); - error =xfs_rename_alloc_whiteout (target_dp, &wip); + error =xfs_rename_alloc_whiteout (mnt_userns, target_dp, &wip);if (error)return error;
fs/xfs/xfs_inode.h +10 -6
@@ -369,15 +369,18 @@ int xfs_release(struct xfs_inode *ip);void xfs_inactive (struct xfs_inode *ip);int xfs_lookup (struct xfs_inode *dp,struct xfs_name *name,struct xfs_inode **ipp,struct xfs_name *ci_name); -int xfs_create (struct xfs_inode *dp,struct xfs_name *name, +int xfs_create (struct user_namespace *mnt_userns, +struct xfs_inode *dp,struct xfs_name *name,umode_t mode,dev_t rdev,struct xfs_inode **ipp); -int xfs_create_tmpfile (struct xfs_inode *dp,umode_t mode, +int xfs_create_tmpfile (struct user_namespace *mnt_userns, +struct xfs_inode *dp,umode_t mode,struct xfs_inode **ipp);int xfs_remove (struct xfs_inode *dp,struct xfs_name *name,struct xfs_inode *ip);int xfs_link (struct xfs_inode *tdp,struct xfs_inode *sip,struct xfs_name *target_name); -int xfs_rename (struct xfs_inode *src_dp,struct xfs_name *src_name, +int xfs_rename (struct user_namespace *mnt_userns, +struct xfs_inode *src_dp,struct xfs_name *src_name,struct xfs_inode *src_ip,struct xfs_inode *target_dp,struct xfs_name *target_name,struct xfs_inode *target_ip,unsigned int flags);
@@ -407,9 +410,10 @@ void xfs_lock_two_inodes(struct xfs_inode *ip0, uint ip0_mode,xfs_extlen_t xfs_get_extsz_hint (struct xfs_inode *ip);xfs_extlen_t xfs_get_cowextsz_hint (struct xfs_inode *ip); -int xfs_dir_ialloc (struct xfs_trans **tpp,struct xfs_inode *dp,umode_t mode, -xfs_nlink_t nlink,dev_t dev,prid_t prid, -struct xfs_inode **ipp); +int xfs_dir_ialloc (struct user_namespace *mnt_userns, +struct xfs_trans **tpp,struct xfs_inode *dp, +umode_t mode,xfs_nlink_t nlink,dev_t dev, +prid_t prid,struct xfs_inode **ipp);static inline int xfs_itruncate_extents(
fs/xfs/xfs_ioctl.c +21 -14
@@ -693,7 +693,8 @@ xfs_ioc_space( iattr.ia_valid =ATTR_SIZE ; iattr.ia_size = bf->l_start; - error =xfs_vn_setattr_size (file_dentry (filp), &iattr); + error =xfs_vn_setattr_size (file_mnt_user_ns (filp),file_dentry (filp), + &iattr);if (error) goto out_unlock;
@@ -734,13 +735,15 @@ xfs_fsinumbers_fmt( STATIC intxfs_ioc_fsbulkstat ( -xfs_mount_t *mp, +struct file *file,unsigned int cmd,void __user *arg) { +struct xfs_mount *mp =XFS_I (file_inode (file))->i_mount;struct xfs_fsop_bulkreq bulkreq;struct xfs_ibulk breq = { .mp = mp, + .mnt_userns =file_mnt_user_ns (file), .ocount =0 , };xfs_ino_t lastino;
@@ -908,13 +911,15 @@ xfs_bulk_ireq_teardown(/* Handle the v5 bulkstat ioctl. */ STATIC intxfs_ioc_bulkstat ( -struct xfs_mount *mp, +struct file *file,unsigned int cmd,struct xfs_bulkstat_req __user *arg) { +struct xfs_mount *mp =XFS_I (file_inode (file))->i_mount;struct xfs_bulk_ireq hdr;struct xfs_ibulk breq = { .mp = mp, + .mnt_userns =file_mnt_user_ns (file), };int error;
@@ -1275,8 +1280,9 @@ xfs_ioctl_setattr_prepare_dax(*/ static struct xfs_trans *xfs_ioctl_setattr_get_trans ( -struct xfs_inode *ip) +struct file *file) { +struct xfs_inode *ip =XFS_I (file_inode (file));struct xfs_mount *mp = ip->i_mount;struct xfs_trans *tp;int error = -EROFS ;
@@ -1300,7 +1306,7 @@ xfs_ioctl_setattr_get_trans(* The user ID of the calling process must be equal to the file owner * ID, except in cases where the CAP_FSETID capability is applicable. */ -if (!inode_owner_or_capable (&init_user_ns,VFS_I (ip))) { +if (!inode_owner_or_capable (file_mnt_user_ns (file),VFS_I (ip))) { error = -EPERM ; goto out_cancel; }
@@ -1428,9 +1434,11 @@ xfs_ioctl_setattr_check_projid( STATIC intxfs_ioctl_setattr ( -xfs_inode_t *ip, +struct file *file,struct fsxattr *fa) { +struct user_namespace *mnt_userns =file_mnt_user_ns (file); +struct xfs_inode *ip =XFS_I (file_inode (file));struct fsxattr old_fa;struct xfs_mount *mp = ip->i_mount;struct xfs_trans *tp;
@@ -1462,7 +1470,7 @@ xfs_ioctl_setattr(xfs_ioctl_setattr_prepare_dax (ip, fa); - tp =xfs_ioctl_setattr_get_trans (ip); + tp =xfs_ioctl_setattr_get_trans (file);if (IS_ERR (tp)) { code =PTR_ERR (tp); goto error_free_dquots;
@@ -1502,7 +1510,7 @@ xfs_ioctl_setattr(*/ if ((VFS_I (ip)->i_mode & (S_ISUID |S_ISGID )) && - !capable_wrt_inode_uidgid (&init_user_ns,VFS_I (ip),CAP_FSETID )) + !capable_wrt_inode_uidgid (mnt_userns,VFS_I (ip),CAP_FSETID ))VFS_I (ip)->i_mode &= ~(S_ISUID |S_ISGID );/* Change the ownerships and register project quota modifications */
@@ -1549,7 +1557,6 @@ xfs_ioctl_setattr( STATIC intxfs_ioc_fssetxattr ( -xfs_inode_t *ip,struct file *filp,void __user *arg) {
@@ -1562,7 +1569,7 @@ xfs_ioc_fssetxattr( error =mnt_want_write_file (filp);if (error)return error; - error =xfs_ioctl_setattr (ip, &fa); + error =xfs_ioctl_setattr (filp, &fa);mnt_drop_write_file (filp);return error; }
@@ -1608,7 +1615,7 @@ xfs_ioc_setxflags(xfs_ioctl_setattr_prepare_dax (ip, &fa); - tp =xfs_ioctl_setattr_get_trans (ip); + tp =xfs_ioctl_setattr_get_trans (filp);if (IS_ERR (tp)) { error =PTR_ERR (tp); goto out_drop_write;
@@ -2119,10 +2126,10 @@ xfs_file_ioctl(case XFS_IOC_FSBULKSTAT_SINGLE :case XFS_IOC_FSBULKSTAT :case XFS_IOC_FSINUMBERS : -return xfs_ioc_fsbulkstat (mp, cmd, arg); +return xfs_ioc_fsbulkstat (filp, cmd, arg);case XFS_IOC_BULKSTAT : -return xfs_ioc_bulkstat (mp, cmd, arg); +return xfs_ioc_bulkstat (filp, cmd, arg);case XFS_IOC_INUMBERS :return xfs_ioc_inumbers (mp, cmd, arg);
@@ -2144,7 +2151,7 @@ xfs_file_ioctl(case XFS_IOC_FSGETXATTRA :return xfs_ioc_fsgetxattr (ip,1 , arg);case XFS_IOC_FSSETXATTR : -return xfs_ioc_fssetxattr (ip, filp, arg); +return xfs_ioc_fssetxattr (filp, arg);case XFS_IOC_GETXFLAGS :return xfs_ioc_getxflags (ip, arg);case XFS_IOC_SETXFLAGS :
fs/xfs/xfs_ioctl32.c +4 -2
@@ -209,14 +209,16 @@ xfs_fsbulkstat_one_fmt_compat(/* copied from xfs_ioctl.c */ STATIC intxfs_compat_ioc_fsbulkstat ( -xfs_mount_t *mp, +struct file *file,unsigned int cmd,struct compat_xfs_fsop_bulkreq __user *p32) { +struct xfs_mount *mp =XFS_I (file_inode (file))->i_mount;u32 addr;struct xfs_fsop_bulkreq bulkreq;struct xfs_ibulk breq = { .mp = mp, + .mnt_userns =file_mnt_user_ns (file), .ocount =0 , };xfs_ino_t lastino;
@@ -507,7 +509,7 @@ xfs_file_compat_ioctl(case XFS_IOC_FSBULKSTAT_32 :case XFS_IOC_FSBULKSTAT_SINGLE_32 :case XFS_IOC_FSINUMBERS_32 : -return xfs_compat_ioc_fsbulkstat (mp, cmd, arg); +return xfs_compat_ioc_fsbulkstat (filp, cmd, arg);case XFS_IOC_FD_TO_HANDLE_32 :case XFS_IOC_PATH_TO_HANDLE_32 :case XFS_IOC_PATH_TO_FSHANDLE_32 : {
fs/xfs/xfs_iops.c +28 -21
165 lines not on this page · raw message
fs/xfs/xfs_iops.h +2 -1
@@ -14,6 +14,7 @@ extern const struct file_operations xfs_dir_file_operations;extern ssize_t xfs_vn_listxattr (struct dentry *,char *data,size_t size);extern void xfs_setattr_time (struct xfs_inode *ip,struct iattr *iattr); -extern int xfs_vn_setattr_size (struct dentry *dentry,struct iattr *vap); +int xfs_vn_setattr_size (struct user_namespace *mnt_userns, +struct dentry *dentry,struct iattr *vap);#endif /* __XFS_IOPS_H__ */
fs/xfs/xfs_itable.c +13 -4
@@ -54,10 +54,12 @@ struct xfs_bstat_chunk { STATIC intxfs_bulkstat_one_int (struct xfs_mount *mp, +struct user_namespace *mnt_userns,struct xfs_trans *tp,xfs_ino_t ino,struct xfs_bstat_chunk *bc) { +struct user_namespace *sb_userns = mp->m_super->s_user_ns;struct xfs_icdinode *dic;/* dinode core info pointer */ struct xfs_inode *ip;/* incore inode pointer */ struct inode *inode;
@@ -86,8 +88,8 @@ xfs_bulkstat_one_int(*/ buf->bs_projectid = ip->i_d.di_projid; buf->bs_ino = ino; - buf->bs_uid =i_uid_read (inode); - buf->bs_gid =i_gid_read (inode); + buf->bs_uid =from_kuid (sb_userns,i_uid_into_mnt (mnt_userns, inode)); + buf->bs_gid =from_kgid (sb_userns,i_gid_into_mnt (mnt_userns, inode)); buf->bs_size = dic->di_size; buf->bs_nlink = inode->i_nlink;
@@ -173,7 +175,8 @@ xfs_bulkstat_one(if (!bc.buf)return -ENOMEM ; - error =xfs_bulkstat_one_int (breq->mp,NULL , breq->startino, &bc); + error =xfs_bulkstat_one_int (breq->mp, breq->mnt_userns,NULL , + breq->startino, &bc);kmem_free (bc.buf);
@@ -194,9 +197,10 @@ xfs_bulkstat_iwalk(xfs_ino_t ino, void *data) { + struct xfs_bstat_chunk *bc = data;int error; - error =xfs_bulkstat_one_int (mp, tp, ino, data); + error =xfs_bulkstat_one_int (mp, bc->breq->mnt_userns, tp, ino, data);/* bulkstat just skips over missing inodes */ if (error == -ENOENT || error == -EINVAL )return 0 ;
@@ -239,6 +243,11 @@ xfs_bulkstat( };int error; +if (breq->mnt_userns != &init_user_ns) { +xfs_warn_ratelimited (breq->mp, +"bulkstat not supported inside of idmapped mounts." ); +return -EINVAL ; + }if (xfs_bulkstat_already_done (breq->mp, breq->startino))return 0 ;
fs/xfs/xfs_itable.h +1 -0
@@ -8,6 +8,7 @@/* In-memory representation of a userspace request for batch inode data. */ struct xfs_ibulk {struct xfs_mount *mp; +struct user_namespace *mnt_userns;void __user *ubuffer;/* user output buffer */ xfs_ino_t startino;/* start with this inode */ unsigned int icount;/* number of elements in ubuffer */
fs/xfs/xfs_qm.c +2 -1
@@ -787,7 +787,8 @@ xfs_qm_qino_alloc(return error;if (need_alloc) { - error =xfs_dir_ialloc (&tp,NULL ,S_IFREG ,1 ,0 ,0 , ipp); + error =xfs_dir_ialloc (&init_user_ns, &tp,NULL ,S_IFREG ,1 ,0 , +0 , ipp);if (error) {xfs_trans_cancel (tp);return error;
fs/xfs/xfs_super.c +1 -1
@@ -1912,7 +1912,7 @@ static struct file_system_type xfs_fs_type = { .init_fs_context = xfs_init_fs_context, .parameters = xfs_fs_parameters, .kill_sb = kill_block_super, - .fs_flags = FS_REQUIRES_DEV, + .fs_flags = FS_REQUIRES_DEV | FS_ALLOW_IDMAP, };MODULE_ALIAS_FS ("xfs" );
fs/xfs/xfs_symlink.c +3 -2
@@ -134,6 +134,7 @@ xfs_readlink( int xfs_symlink( + struct user_namespace *mnt_userns, struct xfs_inode *dp, struct xfs_name *link_name, const char *target_path,
@@ -223,8 +224,8 @@ xfs_symlink(/* * Allocate an inode for the symlink. */ - error =xfs_dir_ialloc (&tp, dp,S_IFLNK | (mode & ~S_IFMT ),1 ,0 , - prid, &ip); + error =xfs_dir_ialloc (mnt_userns, &tp, dp,S_IFLNK | (mode & ~S_IFMT ), +1 ,0 , prid, &ip);if (error) goto out_trans_cancel;
fs/xfs/xfs_symlink.h +3 -2
@@ -7,8 +7,9 @@/* Kernel only symlink definitions */ -int xfs_symlink (struct xfs_inode *dp,struct xfs_name *link_name, -const char *target_path,umode_t mode,struct xfs_inode **ipp); +int xfs_symlink (struct user_namespace *mnt_userns,struct xfs_inode *dp, +struct xfs_name *link_name,const char *target_path, +umode_t mode,struct xfs_inode **ipp);int xfs_readlink_bmap_ilocked (struct xfs_inode *ip,char *link);int xfs_readlink (struct xfs_inode *ip,char *link);int xfs_inactive_symlink (struct xfs_inode *ip);
Signature · 6 lines
2.30.0 _______________________________________________ Containers mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/containers
Re: [PATCH v6 39/40] xfs: support idmapped mounts
Quoted 26 lines · Christian Brauner
From: Christoph Hellwig <[email protected]>
Enable idmapped mounts for xfs. This basically just means passing down the
user_namespaceargument from the VFS methods down to where it is passed to the relevant helpers.Note that full-filesystem bulkstat is not supported from inside idmapped mounts as it is an administrative operation that acts on the whole file system. The limitation is not applied to the bulkstat single operation that just operates on a single inode.
Signed-off-by Christoph Hellwig <[email protected]>Signed-off-by Christian Brauner <[email protected]>---
/* v2 *//* v3 */
/* v4 */
/* v5 */
base-commit:7c53f6b671f4aba70ff15e1b05148b10d58c2837/* v6 */
unchanged
base-commit:19c329f6808995b142b3966301f217c831e7cf31
Quoted 16 lines
--- fs/xfs/xfs_acl.c | 3 +-- fs/xfs/xfs_file.c | 4 +++- fs/xfs/xfs_inode.c | 26 +++++++++++++++-------- fs/xfs/xfs_inode.h | 16 +++++++++------ fs/xfs/xfs_ioctl.c | 35 ++++++++++++++++++------------- fs/xfs/xfs_ioctl32.c | 6 ++++-- fs/xfs/xfs_iops.c | 49 +++++++++++++++++++++++++------------------- fs/xfs/xfs_iops.h | 3 ++- fs/xfs/xfs_itable.c | 17 +++++++++++---- fs/xfs/xfs_itable.h | 1 + fs/xfs/xfs_qm.c | 3 ++- fs/xfs/xfs_super.c | 2 +- fs/xfs/xfs_symlink.c | 5 +++-- fs/xfs/xfs_symlink.h | 5 +++-- 14 files changed, 110 insertions(+), 65 deletions(-)
<snip> Sorry for not noticing until after this went upstream, but...
Quoted 51 lines
fs/xfs/xfs_itable.c +8
-4@@ -54,10 +54,12 @@ struct xfs_bstat_chunk { STATIC intxfs_bulkstat_one_int (struct xfs_mount *mp, +struct user_namespace *mnt_userns,struct xfs_trans *tp,xfs_ino_t ino,struct xfs_bstat_chunk *bc) { +struct user_namespace *sb_userns = mp->m_super->s_user_ns;struct xfs_icdinode *dic;/* dinode core info pointer */ struct xfs_inode *ip;/* incore inode pointer */ struct inode *inode;@@ -86,8 +88,8 @@ xfs_bulkstat_one_int(*/ buf->bs_projectid = ip->i_d.di_projid; buf->bs_ino = ino; - buf->bs_uid =i_uid_read (inode); - buf->bs_gid =i_gid_read (inode); + buf->bs_uid =from_kuid (sb_userns,i_uid_into_mnt (mnt_userns, inode)); + buf->bs_gid =from_kgid (sb_userns,i_gid_into_mnt (mnt_userns, inode)); buf->bs_size = dic->di_size; buf->bs_nlink = inode->i_nlink;@@ -173,7 +175,8 @@ xfs_bulkstat_one(if (!bc.buf)return -ENOMEM ; - error =xfs_bulkstat_one_int (breq->mp,NULL , breq->startino, &bc); + error =xfs_bulkstat_one_int (breq->mp, breq->mnt_userns,NULL , + breq->startino, &bc);kmem_free (bc.buf);@@ -194,9 +197,10 @@ xfs_bulkstat_iwalk(xfs_ino_t ino, void *data) { + struct xfs_bstat_chunk *bc = data;int error; - error =xfs_bulkstat_one_int (mp, tp, ino, data); + error =xfs_bulkstat_one_int (mp, bc->breq->mnt_userns, tp, ino, data);/* bulkstat just skips over missing inodes */ if (error == -ENOENT || error == -EINVAL )return 0 ;
fs/xfs/xfs_itable.c xfs_bulkstat( · line 249
Quoted 7 lines
fs/xfs/xfs_itable.c +4
-0@@ -239,6 +243,11 @@ xfs_bulkstat( };int error; +if (breq->mnt_userns != &init_user_ns) { +xfs_warn_ratelimited (breq->mp, +"bulkstat not supported inside of idmapped mounts." ); +return -EINVAL ;
Shouldn't this be -EPERM?
Or -EOPNOTSUPP?
Also, I'm not sure why bulkstat won't work in an idmapped mount but bulkstat_single does? You can use the singleton version to stat inodes that aren't inside the submount.
--D
Quoted 85 lines
fs/xfs/xfs_itable.c +1
-0+ }if (xfs_bulkstat_already_done (breq->mp, breq->startino))return 0 ;fs/xfs/xfs_itable.h +1
-0@@ -8,6 +8,7 @@/* In-memory representation of a userspace request for batch inode data. */ struct xfs_ibulk {struct xfs_mount *mp; +struct user_namespace *mnt_userns;void __user *ubuffer;/* user output buffer */ xfs_ino_t startino;/* start with this inode */ unsigned int icount;/* number of elements in ubuffer */ fs/xfs/xfs_qm.c +2
-1@@ -787,7 +787,8 @@ xfs_qm_qino_alloc(return error;if (need_alloc) { - error =xfs_dir_ialloc (&tp,NULL ,S_IFREG ,1 ,0 ,0 , ipp); + error =xfs_dir_ialloc (&init_user_ns, &tp,NULL ,S_IFREG ,1 ,0 , +0 , ipp);if (error) {xfs_trans_cancel (tp);return error;fs/xfs/xfs_super.c +1
-1@@ -1912,7 +1912,7 @@ static struct file_system_type xfs_fs_type = { .init_fs_context = xfs_init_fs_context, .parameters = xfs_fs_parameters, .kill_sb = kill_block_super, - .fs_flags = FS_REQUIRES_DEV, + .fs_flags = FS_REQUIRES_DEV | FS_ALLOW_IDMAP, };MODULE_ALIAS_FS ("xfs" );fs/xfs/xfs_symlink.c +3
-2@@ -134,6 +134,7 @@ xfs_readlink( int xfs_symlink( + struct user_namespace *mnt_userns, struct xfs_inode *dp, struct xfs_name *link_name, const char *target_path,@@ -223,8 +224,8 @@ xfs_symlink(/* * Allocate an inode for the symlink. */ - error =xfs_dir_ialloc (&tp, dp,S_IFLNK | (mode & ~S_IFMT ),1 ,0 , - prid, &ip); + error =xfs_dir_ialloc (mnt_userns, &tp, dp,S_IFLNK | (mode & ~S_IFMT ), +1 ,0 , prid, &ip);if (error) goto out_trans_cancel;fs/xfs/xfs_symlink.h +3
-2@@ -7,8 +7,9 @@/* Kernel only symlink definitions */ -int xfs_symlink (struct xfs_inode *dp,struct xfs_name *link_name, -const char *target_path,umode_t mode,struct xfs_inode **ipp); +int xfs_symlink (struct user_namespace *mnt_userns,struct xfs_inode *dp, +struct xfs_name *link_name,const char *target_path, +umode_t mode,struct xfs_inode **ipp);int xfs_readlink_bmap_ilocked (struct xfs_inode *ip,char *link);int xfs_readlink (struct xfs_inode *ip,char *link);int xfs_inactive_symlink (struct xfs_inode *ip);Signature · 1 line
2.30.0
_______________________________________________
Containers mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/containers
Re: [PATCH v6 39/40] xfs: support idmapped mounts
Quoted 44 lines · Darrick J. Wong
Quoted 26 lines · Christian Brauner
From: Christoph Hellwig <[email protected]>
Enable idmapped mounts for xfs. This basically just means passing down the
user_namespaceargument from the VFS methods down to where it is passed to the relevant helpers.Note that full-filesystem bulkstat is not supported from inside idmapped mounts as it is an administrative operation that acts on the whole file system. The limitation is not applied to the bulkstat single operation that just operates on a single inode.
Signed-off-by Christoph Hellwig <[email protected]>Signed-off-by Christian Brauner <[email protected]>---
/* v2 *//* v3 */
/* v4 */
/* v5 */
base-commit:7c53f6b671f4aba70ff15e1b05148b10d58c2837/* v6 */
unchanged
base-commit:19c329f6808995b142b3966301f217c831e7cf31Quoted 16 lines
--- fs/xfs/xfs_acl.c | 3 +-- fs/xfs/xfs_file.c | 4 +++- fs/xfs/xfs_inode.c | 26 +++++++++++++++-------- fs/xfs/xfs_inode.h | 16 +++++++++------ fs/xfs/xfs_ioctl.c | 35 ++++++++++++++++++------------- fs/xfs/xfs_ioctl32.c | 6 ++++-- fs/xfs/xfs_iops.c | 49 +++++++++++++++++++++++++------------------- fs/xfs/xfs_iops.h | 3 ++- fs/xfs/xfs_itable.c | 17 +++++++++++---- fs/xfs/xfs_itable.h | 1 + fs/xfs/xfs_qm.c | 3 ++- fs/xfs/xfs_super.c | 2 +- fs/xfs/xfs_symlink.c | 5 +++-- fs/xfs/xfs_symlink.h | 5 +++-- 14 files changed, 110 insertions(+), 65 deletions(-)
Quoted 1 line
<snip> Sorry for not noticing until after this went upstream, but...
No problem at all.
Quoted 55 lines
Quoted 55 lines
fs/xfs/xfs_itable.c +8
-4@@ -54,10 +54,12 @@ struct xfs_bstat_chunk { STATIC intxfs_bulkstat_one_int (struct xfs_mount *mp, +struct user_namespace *mnt_userns,struct xfs_trans *tp,xfs_ino_t ino,struct xfs_bstat_chunk *bc) { +struct user_namespace *sb_userns = mp->m_super->s_user_ns;struct xfs_icdinode *dic;/* dinode core info pointer */ struct xfs_inode *ip;/* incore inode pointer */ struct inode *inode;@@ -86,8 +88,8 @@ xfs_bulkstat_one_int(*/ buf->bs_projectid = ip->i_d.di_projid; buf->bs_ino = ino; - buf->bs_uid =i_uid_read (inode); - buf->bs_gid =i_gid_read (inode); + buf->bs_uid =from_kuid (sb_userns,i_uid_into_mnt (mnt_userns, inode)); + buf->bs_gid =from_kgid (sb_userns,i_gid_into_mnt (mnt_userns, inode)); buf->bs_size = dic->di_size; buf->bs_nlink = inode->i_nlink;@@ -173,7 +175,8 @@ xfs_bulkstat_one(if (!bc.buf)return -ENOMEM ; - error =xfs_bulkstat_one_int (breq->mp,NULL , breq->startino, &bc); + error =xfs_bulkstat_one_int (breq->mp, breq->mnt_userns,NULL , + breq->startino, &bc);kmem_free (bc.buf);@@ -194,9 +197,10 @@ xfs_bulkstat_iwalk(xfs_ino_t ino, void *data) { + struct xfs_bstat_chunk *bc = data;int error; - error =xfs_bulkstat_one_int (mp, tp, ino, data); + error =xfs_bulkstat_one_int (mp, bc->breq->mnt_userns, tp, ino, data);/* bulkstat just skips over missing inodes */ if (error == -ENOENT || error == -EINVAL )return 0 ;@@ -239,6 +243,11 @@ xfs_bulkstat( };int error;
Quoted 8 lines
fs/xfs/xfs_itable.c xfs_bulkstat( · line 249
Quoted 4 lines
fs/xfs/xfs_itable.c +4
-0+if (breq->mnt_userns != &init_user_ns) { +xfs_warn_ratelimited (breq->mp, +"bulkstat not supported inside of idmapped mounts." ); +return -EINVAL ;Shouldn't this be
-EPERM?Or
-EOPNOTSUPP?
EOPNOTSUPP seems a good choice. Whether or not it's better than EINVAL I don't know. With my userspace maintainer hat on I would probably say that EOPNOTSUPP feels a bit more natural and might have the advantage that it is less overloaded then EINVAL.
Quoted 4 lines
Also, I'm not sure why bulkstat won't work in an idmapped mount but
bulkstat_singledoes? You can use the singleton version to stat inodes that aren't inside the submount.
Christoph will very likely have a better informed opinion than I have but as long as bulkstat is able to discern inodes that need to be reported idmapped and inodes that don't then I see no reason why this shouldn't work (at least for privileged users on the host which I think is the case already).
In any case these changes, if any, aren't vfs changes and so you can just take them as bugfixes through the xfs tree anyway. So no harm done in you not spotting it earlier. :)
Thanks for taking another look!
Christian
_______________________________________________
Containers mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/containers
Re: [PATCH v6 39/40] xfs: support idmapped mounts
In reply to Darrick J. WongQuoted 8 lines · Darrick J. Wong
fs/xfs/xfs_itable.c xfs_bulkstat( · line 249
Quoted 4 lines
fs/xfs/xfs_itable.c +4
-0+if (breq->mnt_userns != &init_user_ns) { +xfs_warn_ratelimited (breq->mp, +"bulkstat not supported inside of idmapped mounts." ); +return -EINVAL ;Shouldn't this be
-EPERM?Or
-EOPNOTSUPP?
-EINVAL is what we return for all our nor suppored ioctls, so I think it is the right choice here, and should generally trigger the right fallbacks.
Quoted 3 lines
Also, I'm not sure why bulkstat won't work in an idmapped mount but
bulkstat_singledoes? You can use the singleton version to stat inodes that aren't inside the submount.
Looking at it again I think we should fail BULKSTAT_SINGLE as well. I had somehow assumed BULKSTAT_SINGLE would operate on the inode of the open file, in which case it would be fine. But it doesn't so that argument doesn't count.
_______________________________________________
Containers mailing list [email protected]
https://lists.linuxfoundation.org/mailman/listinfo/containers
PATCH v6 40/40 generic/622: add fstests for idmapped mounts
In reply to Christian BraunerAdd a test suite to verify the behavior of idmapped mounts. The test suite also includes a range of vfs tests to verify that no regressions are introduced by idmapped mounts. The following tests are currently available with more to come in the future:
01. posix acls on regular and idmapped mounts
02. create operations in user namespace
03. device node creation in user namespace
04. expected ownership on idmapped mounts
05. fscaps on regular mounts
06. fscaps on idmapped mounts
07. fscaps on idmapped mounts in user namespace
08. fscaps on idmapped mounts in user namespace
with different id mappings
09. mapped fsids
10. unmapped fsids
11. cross mount hardlink
12. cross idmapped mount hardlink
13. hardlinks from idmapped mounts
14. hardlinks from idmapped mounts in user namespace
15. io_uring
16. io_uring in user namespace
17. io_uring from idmapped mounts
18. io_uring from idmapped mounts in user namespace
19. io_uring from idmapped mounts with unmapped ids
20. io_uring from idmapped mounts with unmapped ids in user namespace
21. following protected symlinks on regular mounts
22. following protected symlinks on idmapped mounts
23. following protected symlinks on idmapped mounts in user namespace
24. cross mount rename
25. cross idmapped mount rename
26. rename from idmapped mounts
27. rename from idmapped mounts in user namespace
28. symlink from regular mounts
29. symlink from idmapped mounts
30. symlink from idmapped mounts in user namespace
31. setid binaries on regular mounts
32. setid binaries on idmapped mounts
33. setid binaries on idmapped mounts in user namespace
34. setid binaries on idmapped mounts in user namespace
with different id mappings
35. sticky bit unlink operations on regular mounts
36. sticky bit unlink operations on idmapped mounts
37. sticky bit unlink operations on idmapped mounts in user namespace
38. sticky bit rename operations on regular mounts
39. sticky bit rename operations on idmapped mounts
40. sticky bit rename operations on idmapped mounts in user namespace
41. create operations in directories with setgid bit set
42. create operations in directories with setgid bit set
on idmapped mounts
43. create operations in directories with setgid bit set
on idmapped mounts in user namespace
44. verify create operations and ownership with racing threads idmapping a mount
45. setattr truncate operations on regular mounts
46. setattr truncate operations on idmapped mounts
47. setattr truncate operations on idmapped mounts in user namespace
---
/* v2 */
test-suite part of the kernel selftest framework
/* v3 */
patch introduced (ported form kernel selftest framework)
/* v4 */
- Amir Goldstein <[email protected]>:
- Don't Cc fstests mailing list on the testing patches for now.
- Add setgid creation tests.
/* v5 */
new base: 2080ad637bbb4d2c24c4d63939799dab178eb407
- Christoph Hellwig <[email protected]>:
- Enable xfs testing.
- Improve idmapped mount testing support.
- Christian Brauner <[email protected]>:
- Fix protected symlink tests.
- Introduce xfs specific helpers.
- Expand setgid bit tests to xfs.
/* v6 */
- Christian Brauner <[email protected]>:
- After Christoph fixed setgid handling on xfs remove all xfs specific parts apart from irix_sgid_inheritance checking.
- Add idmapped-mounts binary to .gitignore
- Fix feature testing.
- Add truncation tests.
--- .gitignore | 1 + common/rc | 25 + configure.ac | 2 + include/builddefs.in | 1 + m4/Makefile | 1 + m4/package_libcap.m4 | 4 + src/Makefile | 5 + src/feature.c | 40 +- src/idmapped-mounts/Makefile | 35 + src/idmapped-mounts/idmapped-mounts.c | 8513 +++++++++++++++++++++++++ src/idmapped-mounts/missing.h | 155 + src/idmapped-mounts/utils.c | 134 + src/idmapped-mounts/utils.h | 29 + tests/generic/622 | 43 + tests/generic/622.out | 2 + tests/generic/group | 1 + 16 files changed, 8987 insertions(+), 4 deletions(-) create mode 100644 m4/package_libcap.m4 create mode 100644 src/idmapped-mounts/Makefile create mode 100644 src/idmapped-mounts/idmapped-mounts.c create mode 100644 src/idmapped-mounts/missing.h create mode 100644 src/idmapped-mounts/utils.c create mode 100644 src/idmapped-mounts/utils.h create mode 100755 tests/generic/622 create mode 100644 tests/generic/622.out
.gitignore +1 -0
@@ -175,6 +175,7 @@ /src/aio-dio-regress/aio-last-ref-held-by-io /src/aio-dio-regress/aiocp /src/aio-dio-regress/aiodio_sparse2 +/src/idmapped-mounts/idmapped-mounts /src/log-writes/replay-log /src/perf/*.pyc
common/rc +25 -0
@@ -2003,6 +2003,31 @@ _require_io_uring() esac } +# test whether the mount_setattr syscall is available +_require_mount_setattr() +{ + $here/src/feature -r + case $? in + 0) + ;; + 1) + _notrun "kernel does not support mount_setattr syscall" + ;; + *) + _fail "unexpected error testing for mount_setattr support" + ;; + esac +} + +# test whether idmapped mounts are supported +_require_idmapped_mounts() +{ + IDMAPPED_MOUNTS_TEST=$here/src/idmapped-mounts/idmapped-mounts + [ -x $IDMAPPED_MOUNTS_TEST ] || _notrun "idmapped-mounts utilities required" + + _require_mount_setattr +} + # this test requires that a test program exists under src/ # $1 - command (require) #
configure.ac +2 -0
@@ -63,6 +63,7 @@ AC_PACKAGE_WANT_GDBM AC_PACKAGE_WANT_AIO AC_PACKAGE_WANT_URING AC_PACKAGE_WANT_DMAPI +AC_PACKAGE_WANT_LIBCAP AC_PACKAGE_WANT_LINUX_FIEMAP_H AC_PACKAGE_WANT_FALLOCATE AC_PACKAGE_WANT_OPEN_BY_HANDLE_AT
@@ -73,6 +74,7 @@ AC_PACKAGE_WANT_LIBBTRFSUTIL AC_HAVE_COPY_FILE_RANGE AC_CHECK_FUNCS([renameat2]) +AC_CHECK_TYPES([struct mount_attr], [], [], [[#include <linux/mount.h>]]) AC_CONFIG_HEADER(include/config.h) AC_CONFIG_FILES([include/builddefs])
include/builddefs.in +1 -0
@@ -62,6 +62,7 @@ ENABLE_SHARED = @enable_shared@ HAVE_DB = @have_db@ HAVE_AIO = @have_aio@ HAVE_URING = @have_uring@ +HAVE_LIBCAP = @have_libcap@ HAVE_FALLOCATE = @have_fallocate@ HAVE_OPEN_BY_HANDLE_AT = @have_open_by_handle_at@ HAVE_DMAPI = @have_dmapi@
m4/Makefile +1 -0
@@ -13,6 +13,7 @@ LSRCFILES = \ package_attrdev.m4 \ package_dmapidev.m4 \ package_globals.m4 \ + package_libcap.m4 \ package_libcdev.m4 \ package_liburing.m4 \ package_ncurses.m4 \
m4/package_libcap.m4 new file +4 -0
@@ -0,0 +1,4 @@ +AC_DEFUN([AC_PACKAGE_WANT_LIBCAP], + [ AC_CHECK_HEADERS(sys/capability.h, [ have_libcap=true ], [ have_libcap=false ]) + AC_SUBST(have_libcap) + ])
src/Makefile +5 -0
@@ -70,6 +70,11 @@ ifeq ($(HAVE_URING), true) LLDLIBS += -luring endif +SUBDIRS += idmapped-mounts +ifeq ($(HAVE_LIBCAP), true) +LLDLIBS += -lcap +endif + CFILES = $(TARGETS:=.c) LDIRT = $(TARGETS) fssum
src/feature.c +36 -4
@@ -19,6 +19,7 @@* * Test for machine features * -A test whether AIO syscalls are available +* -r test whether mount_setattr syscall is supported * -R test whether IO_URING syscalls are available * -o report a number of online cpus * -s report pagesize
@@ -30,6 +31,7 @@#include <sys/quota.h> #include <sys/resource.h> #include <signal.h> +#include <syscall.h> #include <unistd.h> #ifdef HAVE_XFS_XQM_H
@@ -44,6 +46,8 @@#include <liburing.h> #endif +#include "idmapped-mounts/missing.h" +#ifndef USRQUOTA #define USRQUOTA 0#endif
@@ -64,7 +68,7 @@ usage(void)fprintf (stderr,"Usage: feature [-v] -<q|u|g|p|U|G|P> <filesystem>\n" );fprintf (stderr," feature [-v] -c <file>\n" );fprintf (stderr," feature [-v] -t <file>\n" ); -fprintf (stderr," feature -A | -R | -o | -s | -w\n" ); +fprintf (stderr," feature -A | -r | -R | -o | -s | -w\n" );exit (1 ); }
@@ -243,6 +247,27 @@ check_uring_support(void)#endif } +static int +check_mount_setattr_support (void ) +{ +int err; +struct mount_attr attr = { + .attr_set =MOUNT_ATTR_IDMAP , + .userns_fd = -EBADF , + }; + +/* mount_setattr() syscall not supported. */ + err =sys_mount_setattr (-EBADF ,"" ,AT_EMPTY_PATH ,NULL ,0 ); +if (err && errno ==ENOSYS ) +return 1 ; + +/* idmapped mounts not supported */ + err =sys_mount_setattr (-EBADF ,"." ,AT_EMPTY_PATH , &attr,sizeof (attr)); +if (err && errno ==E2BIG ) +return 1 ; + +return 0 ; +}int main (int argc,char **argv)
@@ -256,6 +281,7 @@ main(int argc, char **argv)int pflag =0 ;int Pflag =0 ;int qflag =0 ; +int rflag =0 ;int Rflag =0 ;int sflag =0 ;int uflag =0 ;
@@ -264,7 +290,7 @@ main(int argc, char **argv)int oflag =0 ;char *fs =NULL ; -while ((c =getopt (argc, argv,"ActgGopPqRsuUvw" )) !=EOF ) { +while ((c =getopt (argc, argv,"ActgGopPqrRsuUvw" )) !=EOF ) {switch (c) {case 'A' : Aflag++;
@@ -293,6 +319,9 @@ main(int argc, char **argv)case 'q' : qflag++;break ; +case 'r' : + rflag++; +break ;case 'R' : Rflag++;break ;
@@ -321,10 +350,10 @@ main(int argc, char **argv)if (optind != argc-1 )/* need a device */ usage (); fs = argv[argc-1 ]; - }else if (Aflag || Rflag || wflag || sflag || oflag) { + }else if (Aflag || rflag || Rflag || wflag || sflag || oflag) {if (optind != argc)usage (); - }else + }else usage ();if (cflag)
@@ -349,6 +378,9 @@ main(int argc, char **argv)if (Aflag)return (check_aio_support ()); +if (rflag) +return (check_mount_setattr_support ()); +if (Rflag)return (check_uring_support ());
src/idmapped-mounts/Makefile new file +35 -0
@@ -0,0 +1,35 @@ +# SPDX-License-Identifier: GPL-2.0 + +TOPDIR = ../.. +include $(TOPDIR)/include/builddefs + +TARGETS = idmapped-mounts + +CFILES = idmapped-mounts.c utils.c +HFILES = missing.h utils.h +LLDLIBS += -pthread +LDIRT = $(TARGETS) + +ifeq ($(HAVE_LIBCAP), true) +LLDLIBS += -lcap +endif + +ifeq ($(HAVE_URING), true) +LLDLIBS += -luring +endif + +default: depend $(TARGETS) + +depend: .dep + +include $(BUILDRULES) + +$(TARGETS): $(CFILES) + @echo " [CC] $@" + $(Q)$(LTLINK) $(CFILES) -o $@ $(CFLAGS) $(LDFLAGS) $(LDLIBS) + +install: + $(INSTALL) -m 755 -d $(PKG_LIB_DIR)/src/idmapped-mounts + $(INSTALL) -m 755 $(TARGETS) $(PKG_LIB_DIR)/src/idmapped-mounts + +-include .dep
src/idmapped-mounts/idmapped-mounts.c new file +8513 -0
2,782 lines not on this page · raw message
src/idmapped-mounts/missing.h new file +155 -0
155 lines not on this page · raw message
src/idmapped-mounts/utils.c new file +134 -0
134 lines not on this page · raw message
tests/generic/622 new file +43 -0
43 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
base-commit: 0e195a4ca997436f4237cb6d21edefb6db1f93d7
Signature · 1 line
2.30.0
Part of the diff is not shown here. View the raw message.
Serge E. Hallyn
maintainerQuoted 126 lines · Christian Brauner
Hey everyone,
The only major change is the updated version of hch's pach to port xfs to support idmapped mounts. Thanks again to Christoph for doing that work.
(Otherwise Acked-bys and Reviewed-bys were added and the tree reordered
to decouple filesystem specific conversion from the vfs work so they can proceed independent.
For a full list of major changes between versions see the end of this cover letter. Please also note the large xfstests testsuite in patch 42 that has been kept as part of this series. It verifies correct vfs behavior with and without idmapped mounts including covering newer vfs features such asio_uring.
I currently still plan to target the v5.12 merge window.)With this patchset we make it possible to attach idmappings to mounts, i.e. simply put different bind mounts can expose the same file or directory with different ownership.
Shifting of ownership on a per-mount basis handles a wide range of long standing use-cases. Here are just a few:
- Shifting of a subset of ownership-less filesystems (vfat) for use by multiple users, effectively allowing for DAC on such devices (systemd, Android, ...)
- Allow remapping uid/gid on external filesystems or paths (USB sticks, network filesystem, ...) to match the local system's user and groups. (David Howells intends to port AFS as a first candidate.)
- Shifting of a container rootfs or base image without having to mangle every file (runc, Docker, containerd, k8s, LXD, systemd ...)
- Sharing of data between host or privileged containers with unprivileged containers (runC, Docker, containerd, k8s, LXD, ...)
- Data sharing between multiple user namespaces with incompatible maps (LXD, k8s, ...)There has been significant interest in this patchset as evidenced by user commenting on previous version of this patchset. They include containerd, ChromeOS, systemd, LXD and a range of others. There is already a patchset up for containerd, the default Kubernetes container runtime https://github.com/containerd/containerd/pull/4734
to make use of this. systemd intends to use it in their systemd-homed implementation for portable home directories. ChromeOS wants to make use of it to share data between the host and the Linux containers they run on Chrome- and Pixelbooks. There's also a few talks that of people who are going to make use of this. The most recent one was a CNCF webinar
https://www.cncf.io/wp-content/uploads/2020/12/Rootless-Containers-in-Gitpod.pdf
and upcoming talk during FOSDEM.
(Fwiw, for fun and since I wanted to do this for a long time I've ported
my home directory to be completely portable with a simple service file that now mounts my home directory on an ext4 formatted usb stick with an id mapping mapping all files to the random uid I'm assigned at login.)Making it possible to share directories and mounts between users with different uids and gids is itself quite an important use-case in distributed systems environments. It's of course especially useful in general for portable usb sticks, sharing data between multiple users in, and sharing home directories between multiple users. The last example is now elegantly expressed in systemd's homed concept for portable home directories. As mentioned above, idmapped mounts also allow data from the host to be shared with unprivileged containers, between privileged and unprivileged containers simultaneously and in addition also between unprivileged containers with different idmappings whenever they are used to isolate one container completely from another container.
We have implemented and proposed multiple solutions to this before. This included the introduction of fsid mappings, a tiny filesystem I've authored with Seth Forshee that is currently carried in Ubuntu that has shown to be the wrong approach, and the conceptual hack of calling override creds directly in the vfs. In addition, to some of these solutions being hacky none of these solutions have covered all of the above use-cases.
Idmappings become a property of struct vfsmount instead of tying it to a process being inside of a user namespace which has been the case for all other proposed approaches. It also allows to pass down the user namespace into the filesystems which is a clean way instead of violating calling conventions by strapping the user namespace information that is a property of the mount to the caller's credentials or similar hacks. Each mount can have a separate idmapping and idmapped mounts can even be created in the initial user namespace unblocking a range of use-cases.
To this end the vfsmount struct gains a new struct
user_namespacemember. The idmapping of the user namespace becomes the idmapping of the mount. A caller that is privileged with respect to the user namespace of the superblock of the underlying filesystem can create an idmapped mount. In the future, we can enable unprivileged use-cases by checking whether the caller is privileged wrt to the user namespace that an already idmapped mount has been marked with, allowing them to change the idmapping. For now, keep things simple until the need arises. Note, that with syscall interception it is already possible to intercept idmapped mount requests from unprivileged containers and handle them in a sufficiently privileged container manager. Support for this is already available in LXD and will be available in runC where syscall interception is currently in the process of becoming part of the runtime
spec: https://github.com/opencontainers/runtime-spec/pull/1074.The user namespace the mount will be marked with can be specified by passing a file descriptor refering to the user namespace as an argument to the new
mount_setattr()syscall together with the newMOUNT_ATTR_IDMAPflag. By default vfsmounts are marked with the initial user namespace and no behavioral or performance changes are observed. All mapping operations are nops for the initial user namespace. When a file/inode is accessed through an idmapped mount thei_uidandi_gidof the inode will be remapped according to the user namespace the mount has been marked with.In order to support idmapped mounts, filesystems need to be changed and mark themselves with the
FS_ALLOW_IDMAPflag infs_flags. The initial version contains fat, ext4, and xfs including a list of examples. But patches for other filesystems are actively worked on and will be sent out separately. We are here to see this through and there are multiple people involved in converting filesystems. So filesystem developers are not left alone with this and are provided with a large testsuite to verify that their port is correct.There is a simple tool available at
https://github.com/brauner/mount-idmapped that allows to create idmapped mounts so people can play with this patch series. Here are a few illustrations:1. Create a simple idmapped mount of another user's home directory
u1001@f2-vm:/$ sudo ./mount-idmapped --map-mount b:1000:1001:1 /home/ubuntu/ /mnt u1001@f2-vm:/$ ls -al /home/ubuntu/ total 28 drwxr-xr-x 2 ubuntu ubuntu 4096 Oct 28 22:07 . drwxr-xr-x 4 root root 4096 Oct 28 04:00 ..
Review
Quoted 6 lines
(quoted diff) +0
-6-rw------- 1 ubuntu ubuntu 3154 Oct 28 22:12 .bash_history -rw-r--r-- 1 ubuntu ubuntu 220 Feb 25 2020 .bash_logout -rw-r--r-- 1 ubuntu ubuntu 3771 Feb 25 2020 .bashrc -rw-r--r-- 1 ubuntu ubuntu 807 Feb 25 2020 .profile -rw-r--r-- 1 ubuntu ubuntu 0 Oct 16 16:11 .sudo_as_admin_successful -rw------- 1 ubuntu ubuntu 1144 Oct 28 00:43 .viminfo
So I assume this falls under the buyer beware warning, but it's probably important to warn people loudly of the fact that, at this point, the user with uid 1001 can chmod u+s any binary under /mnt and then run it from /home/ubuntu with euid=1000. In other words, that while this has excellent uses, if you *can* use shared group membership, you should :)
Very cool though.
_______________________________________________
Containers mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/containers
PATCH v6 9/40 xattr: handle idmapped mounts
From: Tycho Andersen <[email protected]>
When interacting with extended attributes the vfs verifies that the caller is privileged over the inode with which the extended attribute is associated. For posix access and posix default extended attributes a uid or gid can be stored on-disk. Let the functions handle posix extended attributes on idmapped mounts. If the inode is accessed through an idmapped mount we need to map it according to the mount's user namespace. Afterwards the checks are identical to non-idmapped mounts. This has no effect for e.g. security xattrs since they don't store uids or gids and don't perform permission checks on them like posix acls do.
---
/* v2 */
- Christoph Hellwig <[email protected]>:
- Don't pollute the vfs with additional helpers simply extend the existing helpers with an additional argument and switch all callers.
/* v3 */
unchanged
/* v4 */
- Serge Hallyn <[email protected]>:
- Use "mnt_userns" to refer to a vfsmount's userns everywhere to make terminology consistent.
/* v5 */
unchanged
base-commit: 7c53f6b671f4aba70ff15e1b05148b10d58c2837
/* v6 */
base-commit: 19c329f6808995b142b3966301f217c831e7cf31
- Christoph Hellwig <[email protected]>:
- Remove local variables in favor of calling file_mnt_user_ns() directly.
--- fs/cachefiles/xattr.c | 29 +++---- fs/ecryptfs/crypto.c | 4 +- fs/ecryptfs/inode.c | 5 +- fs/ecryptfs/mmap.c | 4 +- fs/nfsd/vfs.c | 14 +-- fs/overlayfs/copy_up.c | 14 +-- fs/overlayfs/dir.c | 2 +- fs/overlayfs/inode.c | 9 +- fs/overlayfs/overlayfs.h | 6 +- fs/overlayfs/super.c | 6 +- fs/xattr.c | 120 +++++++++++++++----------- include/linux/xattr.h | 27 ++++-- security/apparmor/domain.c | 4 +- security/commoncap.c | 6 +- security/integrity/evm/evm_crypto.c | 11 +-- security/integrity/evm/evm_main.c | 4 +- security/integrity/ima/ima_appraise.c | 8 +- security/selinux/hooks.c | 3 +- security/smack/smack_lsm.c | 8 +- 19 files changed, 160 insertions(+), 124 deletions(-)
fs/cachefiles/xattr.c +14 -15
@@ -39,8 +39,8 @@ int cachefiles_check_object_type(struct cachefiles_object *object)_enter ("%p{%s}" , object, type);/* attempt to install a type label directly */ - ret =vfs_setxattr (dentry, cachefiles_xattr_cache, type,2 , -XATTR_CREATE ); + ret =vfs_setxattr (&init_user_ns, dentry, cachefiles_xattr_cache, type, +2 ,XATTR_CREATE );if (ret ==0 ) {_debug ("SET" );/* we succeeded */ goto error;
@@ -54,7 +54,8 @@ int cachefiles_check_object_type(struct cachefiles_object *object) }/* read the current type label */ - ret =vfs_getxattr (dentry, cachefiles_xattr_cache, xtype,3 ); + ret =vfs_getxattr (&init_user_ns, dentry, cachefiles_xattr_cache, xtype, +3 );if (ret <0 ) {if (ret == -ERANGE ) goto bad_type_length;
@@ -110,9 +111,8 @@ int cachefiles_set_object_xattr(struct cachefiles_object *object,_debug ("SET #%u" , auxdata->len);clear_bit (FSCACHE_COOKIE_AUX_UPDATED , &object->fscache.cookie->flags); - ret =vfs_setxattr (dentry, cachefiles_xattr_cache, - &auxdata->type, auxdata->len, -XATTR_CREATE ); + ret =vfs_setxattr (&init_user_ns, dentry, cachefiles_xattr_cache, + &auxdata->type, auxdata->len,XATTR_CREATE );if (ret <0 && ret != -ENOMEM ) cachefiles_io_error_obj( object,
@@ -140,9 +140,8 @@ int cachefiles_update_object_xattr(struct cachefiles_object *object,_debug ("SET #%u" , auxdata->len);clear_bit (FSCACHE_COOKIE_AUX_UPDATED , &object->fscache.cookie->flags); - ret =vfs_setxattr (dentry, cachefiles_xattr_cache, - &auxdata->type, auxdata->len, -XATTR_REPLACE ); + ret =vfs_setxattr (&init_user_ns, dentry, cachefiles_xattr_cache, + &auxdata->type, auxdata->len,XATTR_REPLACE );if (ret <0 && ret != -ENOMEM ) cachefiles_io_error_obj( object,
@@ -171,7 +170,7 @@ int cachefiles_check_auxdata(struct cachefiles_object *object)if (!auxbuf)return -ENOMEM ; - xlen =vfs_getxattr (dentry, cachefiles_xattr_cache, + xlen =vfs_getxattr (&init_user_ns, dentry, cachefiles_xattr_cache, &auxbuf->type,512 +1 ); ret = -ESTALE ; if (xlen < 1 ||
@@ -213,7 +212,7 @@ int cachefiles_check_object_xattr(struct cachefiles_object *object, }/* read the current type label */ - ret =vfs_getxattr (dentry, cachefiles_xattr_cache, + ret =vfs_getxattr (&init_user_ns, dentry, cachefiles_xattr_cache, &auxbuf->type,512 +1 );if (ret <0 ) {if (ret == -ENODATA )
@@ -270,9 +269,9 @@ int cachefiles_check_object_xattr(struct cachefiles_object *object, }/* update the current label */ - ret =vfs_setxattr (dentry, cachefiles_xattr_cache, - &auxdata->type, auxdata->len, -XATTR_REPLACE ); + ret =vfs_setxattr (&init_user_ns, dentry, + cachefiles_xattr_cache, &auxdata->type, + auxdata->len,XATTR_REPLACE );if (ret <0 ) {cachefiles_io_error_obj (object, "Can't update xattr on %lu"
@@ -309,7 +308,7 @@ int cachefiles_remove_object_xattr(struct cachefiles_cache *cache, {int ret; - ret =vfs_removexattr (dentry, cachefiles_xattr_cache); + ret =vfs_removexattr (&init_user_ns, dentry, cachefiles_xattr_cache);if (ret <0 ) {if (ret == -ENOENT || ret == -ENODATA ) ret =0 ;
fs/ecryptfs/crypto.c +2 -2
@@ -1110,8 +1110,8 @@ ecryptfs_write_metadata_to_xattr(struct dentry *ecryptfs_dentry, }inode_lock (lower_inode); - rc =__vfs_setxattr (lower_dentry, lower_inode,ECRYPTFS_XATTR_NAME , - page_virt, size,0 ); + rc =__vfs_setxattr (&init_user_ns, lower_dentry, lower_inode, +ECRYPTFS_XATTR_NAME , page_virt, size,0 );if (!rc && ecryptfs_inode)fsstack_copy_attr_all (ecryptfs_inode, lower_inode);inode_unlock (lower_inode);
fs/ecryptfs/inode.c +3 -2
@@ -1024,7 +1024,8 @@ ecryptfs_setxattr(struct dentry *dentry, struct inode *inode, rc = -EOPNOTSUPP ; goto out; } - rc =vfs_setxattr (lower_dentry, name, value, size, flags); + rc =vfs_setxattr (&init_user_ns, lower_dentry, name, value, size, + flags);if (!rc && inode)fsstack_copy_attr_all (inode,d_inode (lower_dentry)); out:
@@ -1089,7 +1090,7 @@ static int ecryptfs_removexattr(struct dentry *dentry, struct inode *inode, goto out; }inode_lock (lower_inode); - rc =__vfs_removexattr (lower_dentry, name); + rc =__vfs_removexattr (&init_user_ns, lower_dentry, name);inode_unlock (lower_inode); out:return rc;
fs/ecryptfs/mmap.c +2 -2
@@ -426,8 +426,8 @@ 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 (lower_dentry, lower_inode,ECRYPTFS_XATTR_NAME , - xattr_virt, size,0 ); + rc =__vfs_setxattr (&init_user_ns, lower_dentry, lower_inode, +ECRYPTFS_XATTR_NAME , xattr_virt, size,0 );inode_unlock (lower_inode);if (rc) printk(KERN_ERR "Error whilst attempting to write inode size "
fs/nfsd/vfs.c +8 -6
@@ -499,7 +499,8 @@ int nfsd4_is_junction(struct dentry *dentry)return 0 ;if (!(inode->i_mode &S_ISVTX ))return 0 ; -if (vfs_getxattr (dentry,NFSD_JUNCTION_XATTR_NAME ,NULL ,0 ) <=0 ) +if (vfs_getxattr (&init_user_ns, dentry,NFSD_JUNCTION_XATTR_NAME , +NULL ,0 ) <=0 )return 0 ;return 1 ; }
@@ -2149,7 +2150,7 @@ nfsd_getxattr(struct svc_rqst *rqstp, struct svc_fh *fhp, char *name,inode_lock_shared (inode); - len =vfs_getxattr (dentry, name,NULL ,0 ); + len =vfs_getxattr (&init_user_ns, dentry, name,NULL ,0 );/* * Zero-length attribute, just return.
@@ -2176,7 +2177,7 @@ nfsd_getxattr(struct svc_rqst *rqstp, struct svc_fh *fhp, char *name, goto out; } - len =vfs_getxattr (dentry, name, buf, len); + len =vfs_getxattr (&init_user_ns, dentry, name, buf, len);if (len <=0 ) {kvfree (buf); buf =NULL ;
@@ -2283,7 +2284,8 @@ nfsd_removexattr(struct svc_rqst *rqstp, struct svc_fh *fhp, char *name)fh_lock (fhp); - ret =__vfs_removexattr_locked (fhp->fh_dentry, name,NULL ); + ret =__vfs_removexattr_locked (&init_user_ns, fhp->fh_dentry, + name,NULL );fh_unlock (fhp);fh_drop_write (fhp);
@@ -2307,8 +2309,8 @@ nfsd_setxattr(struct svc_rqst *rqstp, struct svc_fh *fhp, char *name,return nfserrno (ret);fh_lock (fhp); - ret =__vfs_setxattr_locked (fhp->fh_dentry, name, buf, len, flags, -NULL ); + ret =__vfs_setxattr_locked (&init_user_ns, fhp->fh_dentry, name, buf, + len, flags,NULL );fh_unlock (fhp);fh_drop_write (fhp);
fs/overlayfs/copy_up.c +7 -7
@@ -85,9 +85,9 @@ int ovl_copy_xattr(struct super_block *sb, struct dentry *old,if (ovl_is_private_xattr (sb, name))continue ; retry: - size =vfs_getxattr (old, name, value, value_size); + size =vfs_getxattr (&init_user_ns, old, name, value, value_size);if (size == -ERANGE ) - size =vfs_getxattr (old, name,NULL ,0 ); + size =vfs_getxattr (&init_user_ns, old, name,NULL ,0 );if (size <0 ) { error = size;
@@ -114,7 +114,7 @@ int ovl_copy_xattr(struct super_block *sb, struct dentry *old, error =0 ;continue ;/* Discard */ } - error =vfs_setxattr (new, name, value, size,0 ); + error =vfs_setxattr (&init_user_ns, new, name, value, size,0 );if (error) {if (error != -EOPNOTSUPP ||ovl_must_copy_xattr (name))break ;
@@ -795,7 +795,7 @@ static ssize_t ovl_getxattr(struct dentry *dentry, char *name, char **value)ssize_t res;char *buf; - res =vfs_getxattr (dentry, name,NULL ,0 ); + res =vfs_getxattr (&init_user_ns, dentry, name,NULL ,0 );if (res == -ENODATA || res == -EOPNOTSUPP ) res =0 ;
@@ -804,7 +804,7 @@ static ssize_t ovl_getxattr(struct dentry *dentry, char *name, char **value)if (!buf)return -ENOMEM ; - res =vfs_getxattr (dentry, name, buf, res); + res =vfs_getxattr (&init_user_ns, dentry, name, buf, res);if (res <0 )kfree (buf);else
@@ -846,8 +846,8 @@ static int ovl_copy_up_meta_inode_data(struct ovl_copy_up_ctx *c)* don't want that to happen for normal copy-up operation. */ if (capability) { - err =vfs_setxattr (upperpath.dentry,XATTR_NAME_CAPS , - capability, cap_size,0 ); + err =vfs_setxattr (&init_user_ns, upperpath.dentry, +XATTR_NAME_CAPS , capability, cap_size,0 );if (err) goto out_free; }
fs/overlayfs/dir.c +1 -1
@@ -449,7 +449,7 @@ static int ovl_set_upper_acl(struct dentry *upperdentry, const char *name,if (err <0 ) goto out_free; - err =vfs_setxattr (upperdentry, name, buffer, size,XATTR_CREATE ); + err =vfs_setxattr (&init_user_ns, upperdentry, name, buffer, size,XATTR_CREATE ); out_free:kfree (buffer);return err;
fs/overlayfs/inode.c +5 -4
@@ -352,7 +352,7 @@ int ovl_xattr_set(struct dentry *dentry, struct inode *inode, const char *name, goto out;if (!value && !upperdentry) { - err =vfs_getxattr (realdentry, name,NULL ,0 ); + err =vfs_getxattr (&init_user_ns, realdentry, name,NULL ,0 );if (err <0 ) goto out_drop_write; }
@@ -367,10 +367,11 @@ int ovl_xattr_set(struct dentry *dentry, struct inode *inode, const char *name, old_cred =ovl_override_creds (dentry->d_sb);if (value) - err =vfs_setxattr (realdentry, name, value, size, flags); + err =vfs_setxattr (&init_user_ns, realdentry, name, value, size, + flags);else {WARN_ON (flags !=XATTR_REPLACE ); - err =vfs_removexattr (realdentry, name); + err =vfs_removexattr (&init_user_ns, realdentry, name); }revert_creds (old_cred);
@@ -392,7 +393,7 @@ int ovl_xattr_get(struct dentry *dentry, struct inode *inode, const char *name,ovl_i_dentry_upper (inode) ?:ovl_dentry_lower (dentry); old_cred =ovl_override_creds (dentry->d_sb); - res =vfs_getxattr (realdentry, name, value, size); + res =vfs_getxattr (&init_user_ns, realdentry, name, value, size);revert_creds (old_cred);return res; }
fs/overlayfs/overlayfs.h +3 -3
@@ -186,7 +186,7 @@ static inline ssize_t ovl_do_getxattr(struct ovl_fs *ofs, struct dentry *dentry, size_t size) {const char *name =ovl_xattr (ofs, ox); -return vfs_getxattr (dentry, name, value, size); +return vfs_getxattr (&init_user_ns, dentry, name, value, size); } static inline int ovl_do_setxattr(struct ovl_fs *ofs, struct dentry *dentry,
@@ -194,7 +194,7 @@ static inline int ovl_do_setxattr(struct ovl_fs *ofs, struct dentry *dentry, size_t size) {const char *name =ovl_xattr (ofs, ox); -int err =vfs_setxattr (dentry, name, value, size,0 ); +int err =vfs_setxattr (&init_user_ns, dentry, name, value, size,0 );pr_debug ("setxattr(%pd2, \"%s\", \"%*pE\", %zu, 0) = %i\n" , dentry, name,min ((int )size,48 ), value, size, err);return err;
@@ -204,7 +204,7 @@ static inline int ovl_do_removexattr(struct ovl_fs *ofs, struct dentry *dentry, enum ovl_xattr ox) {const char *name =ovl_xattr (ofs, ox); -int err =vfs_removexattr (dentry, name); +int err =vfs_removexattr (&init_user_ns, dentry, name);pr_debug ("removexattr(%pd2, \"%s\") = %i\n" , dentry, name, err);return err; }
fs/overlayfs/super.c +4 -2
@@ -794,11 +794,13 @@ static struct dentry *ovl_workdir_create(struct ovl_fs *ofs,* allowed as upper are limited to "normal" ones, where checking * for the above two errors is sufficient. */ - err =vfs_removexattr (work,XATTR_NAME_POSIX_ACL_DEFAULT ); + err =vfs_removexattr (&init_user_ns, work, +XATTR_NAME_POSIX_ACL_DEFAULT );if (err && err != -ENODATA && err != -EOPNOTSUPP ) goto out_dput; - err =vfs_removexattr (work,XATTR_NAME_POSIX_ACL_ACCESS ); + err =vfs_removexattr (&init_user_ns, work, +XATTR_NAME_POSIX_ACL_ACCESS );if (err && err != -ENODATA && err != -EOPNOTSUPP ) goto out_dput;
fs/xattr.c +69 -51
344 lines not on this page · raw message
include/linux/xattr.h +18 -9
@@ -16,6 +16,7 @@#include <linux/types.h> #include <linux/spinlock.h> #include <linux/mm.h> +#include <linux/user_namespace.h> #include <uapi/linux/xattr.h> struct inode ;
@@ -49,18 +50,26 @@ struct xattr { };ssize_t __vfs_getxattr (struct dentry *,struct inode *,const char *,void *,size_t ); -ssize_t vfs_getxattr (struct dentry *,const char *,void *,size_t ); +ssize_t vfs_getxattr (struct user_namespace *,struct dentry *,const char *, +void *,size_t );ssize_t vfs_listxattr (struct dentry *d,char *list,size_t size); -int __vfs_setxattr (struct dentry *,struct inode *,const char *,const void *,size_t ,int ); -int __vfs_setxattr_noperm (struct dentry *,const char *,const void *,size_t ,int ); -int __vfs_setxattr_locked (struct dentry *,const char *,const void *,size_t ,int ,struct inode **); -int vfs_setxattr (struct dentry *,const char *,const void *,size_t ,int ); -int __vfs_removexattr (struct dentry *,const char *); -int __vfs_removexattr_locked (struct dentry *,const char *,struct inode **); -int vfs_removexattr (struct dentry *,const char *); +int __vfs_setxattr (struct user_namespace *,struct dentry *,struct inode *, +const char *,const void *,size_t ,int ); +int __vfs_setxattr_noperm (struct user_namespace *,struct dentry *, +const char *,const void *,size_t ,int ); +int __vfs_setxattr_locked (struct user_namespace *,struct dentry *, +const char *,const void *,size_t ,int , +struct inode **); +int vfs_setxattr (struct user_namespace *,struct dentry *,const char *, +const void *,size_t ,int ); +int __vfs_removexattr (struct user_namespace *,struct dentry *,const char *); +int __vfs_removexattr_locked (struct user_namespace *,struct dentry *, +const char *,struct inode **); +int vfs_removexattr (struct user_namespace *,struct dentry *,const char *);ssize_t generic_listxattr (struct dentry *dentry,char *buffer,size_t buffer_size); -ssize_t vfs_getxattr_alloc (struct dentry *dentry,const char *name, +ssize_t vfs_getxattr_alloc (struct user_namespace *mnt_userns, +struct dentry *dentry,const char *name,char **xattr_value,size_t size,gfp_t flags);int xattr_supported_namespace (struct inode *inode,const char *prefix);
security/apparmor/domain.c +2 -2
@@ -324,8 +324,8 @@ static int aa_xattrs_match(const struct linux_binprm *bprm, d = bprm->file->f_path.dentry;for (i =0 ; i < profile->xattr_count; i++) { - size =vfs_getxattr_alloc (d, profile->xattrs[i], &value, - value_size,GFP_KERNEL ); + size =vfs_getxattr_alloc (&init_user_ns, d, profile->xattrs[i], + &value, value_size,GFP_KERNEL );if (size >=0 ) {u32 perm;
security/commoncap.c +3 -3
@@ -313,7 +313,7 @@ int cap_inode_killpriv(struct dentry *dentry) {int error; - error =__vfs_removexattr (dentry,XATTR_NAME_CAPS ); + error =__vfs_removexattr (&init_user_ns, dentry,XATTR_NAME_CAPS );if (error == -EOPNOTSUPP ) error =0 ;return error;
@@ -386,8 +386,8 @@ int cap_inode_getsecurity(struct inode *inode, const char *name, void **buffer,return -EINVAL ; size =sizeof (struct vfs_ns_cap_data ); - ret = (int )vfs_getxattr_alloc (dentry,XATTR_NAME_CAPS , - &tmpbuf, size,GFP_NOFS ); + ret = (int )vfs_getxattr_alloc (&init_user_ns, dentry,XATTR_NAME_CAPS , + &tmpbuf, size,GFP_NOFS );dput (dentry);if (ret <0 )
security/integrity/evm/evm_crypto.c +6 -5
@@ -222,7 +222,7 @@ static int evm_calc_hmac_or_hash(struct dentry *dentry, ima_present = true;continue ; } - size =vfs_getxattr_alloc (dentry, xattr->name, + size =vfs_getxattr_alloc (&init_user_ns, dentry, xattr->name, &xattr_value, xattr_size,GFP_NOFS );if (size == -ENOMEM ) { error = -ENOMEM ;
@@ -275,8 +275,8 @@ static int evm_is_immutable(struct dentry *dentry, struct inode *inode)return 1 ;/* Do this the hard way */ - rc =vfs_getxattr_alloc (dentry,XATTR_NAME_EVM , (char **)&xattr_data,0 , -GFP_NOFS ); + rc =vfs_getxattr_alloc (&init_user_ns, dentry,XATTR_NAME_EVM , + (char **)&xattr_data,0 ,GFP_NOFS );if (rc <=0 ) {if (rc == -ENODATA )return 0 ;
@@ -319,11 +319,12 @@ int evm_update_evmxattr(struct dentry *dentry, const char *xattr_name, xattr_value_len, &data);if (rc ==0 ) { data.hdr.xattr.sha1.type =EVM_XATTR_HMAC ; - rc =__vfs_setxattr_noperm (dentry,XATTR_NAME_EVM , + rc =__vfs_setxattr_noperm (&init_user_ns, dentry, +XATTR_NAME_EVM , &data.hdr.xattr.data[1 ],SHA1_DIGEST_SIZE +1 ,0 ); }else if (rc == -ENODATA && (inode->i_opflags &IOP_XATTR )) { - rc =__vfs_removexattr (dentry,XATTR_NAME_EVM ); + rc =__vfs_removexattr (&init_user_ns, dentry,XATTR_NAME_EVM ); }return rc; }
security/integrity/evm/evm_main.c +2 -2
@@ -146,8 +146,8 @@ static enum integrity_status evm_verify_hmac(struct dentry *dentry,/* if status is not PASS, try to check again - against -ENOMEM */ /* first need to know the sig type */ - rc =vfs_getxattr_alloc (dentry,XATTR_NAME_EVM , (char **)&xattr_data,0 , -GFP_NOFS ); + rc =vfs_getxattr_alloc (&init_user_ns, dentry,XATTR_NAME_EVM , + (char **)&xattr_data,0 ,GFP_NOFS );if (rc <=0 ) { evm_status =INTEGRITY_FAIL ;if (rc == -ENODATA ) {
security/integrity/ima/ima_appraise.c +4 -4
@@ -94,7 +94,7 @@ static int ima_fix_xattr(struct dentry *dentry, iint->ima_hash->xattr.ng.type =IMA_XATTR_DIGEST_NG ; iint->ima_hash->xattr.ng.algo = algo; } - rc =__vfs_setxattr_noperm (dentry,XATTR_NAME_IMA , + rc =__vfs_setxattr_noperm (&init_user_ns, dentry,XATTR_NAME_IMA , &iint->ima_hash->xattr.data[offset], (sizeof (iint->ima_hash->xattr) - offset) + iint->ima_hash->length,0 );
@@ -215,8 +215,8 @@ int ima_read_xattr(struct dentry *dentry, {ssize_t ret; - ret =vfs_getxattr_alloc (dentry,XATTR_NAME_IMA , (char **)xattr_value, -0 ,GFP_NOFS ); + ret =vfs_getxattr_alloc (&init_user_ns, dentry,XATTR_NAME_IMA , + (char **)xattr_value,0 ,GFP_NOFS );if (ret == -EOPNOTSUPP ) ret =0 ;return ret;
@@ -520,7 +520,7 @@ void ima_inode_post_setattr(struct dentry *dentry) action =ima_must_appraise (inode,MAY_ACCESS ,POST_SETATTR );if (!action) -__vfs_removexattr (dentry,XATTR_NAME_IMA ); +__vfs_removexattr (&init_user_ns, dentry,XATTR_NAME_IMA ); iint =integrity_iint_find (inode);if (iint) {set_bit (IMA_CHANGE_ATTR , &iint->atomic_flags);
security/selinux/hooks.c +2 -1
@@ -6526,7 +6526,8 @@ static int selinux_inode_notifysecctx(struct inode *inode, void *ctx, u32 ctxlen*/ static int selinux_inode_setsecctx (struct dentry *dentry,void *ctx,u32 ctxlen) { -return __vfs_setxattr_noperm (dentry,XATTR_NAME_SELINUX , ctx, ctxlen,0 ); +return __vfs_setxattr_noperm (&init_user_ns, dentry,XATTR_NAME_SELINUX , + ctx, ctxlen,0 ); }static int selinux_inode_getsecctx (struct inode *inode,void **ctx,u32 *ctxlen)
security/smack/smack_lsm.c +5 -3
@@ -3425,7 +3425,7 @@ static void smack_d_instantiate(struct dentry *opt_dentry, struct inode *inode)*/ if (isp->smk_flags &SMK_INODE_CHANGED ) { isp->smk_flags &= ~SMK_INODE_CHANGED ; - rc =__vfs_setxattr (dp, inode, + rc =__vfs_setxattr (&init_user_ns, dp, inode,XATTR_NAME_SMACKTRANSMUTE ,TRANS_TRUE ,TRANS_TRUE_SIZE ,0 );
@@ -4597,12 +4597,14 @@ static int smack_secctx_to_secid(const char *secdata, u32 seclen, u32 *secid)static int smack_inode_notifysecctx (struct inode *inode,void *ctx,u32 ctxlen) { -return smack_inode_setsecurity (inode,XATTR_SMACK_SUFFIX , ctx, ctxlen,0 ); +return smack_inode_setsecurity (inode,XATTR_SMACK_SUFFIX , ctx, + ctxlen,0 ); }static int smack_inode_setsecctx (struct dentry *dentry,void *ctx,u32 ctxlen) { -return __vfs_setxattr_noperm (dentry,XATTR_NAME_SMACK , ctx, ctxlen,0 ); +return __vfs_setxattr_noperm (&init_user_ns, dentry,XATTR_NAME_SMACK , + ctx, ctxlen,0 ); }static int smack_inode_getsecctx (struct inode *inode,void **ctx,u32 *ctxlen)
Signature · 6 lines
2.30.0 _______________________________________________ Containers mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/containers
Re: [PATCH v6 09/40] xattr: handle idmapped mounts
Quoted 12 lines · Christian Brauner
From: Tycho Andersen <[email protected]>
When interacting with extended attributes the vfs verifies that the caller is privileged over the inode with which the extended attribute is associated. For posix access and posix default extended attributes a uid or gid can be stored on-disk. Let the functions handle posix extended attributes on idmapped mounts. If the inode is accessed through an idmapped mount we need to map it according to the mount's user namespace. Afterwards the checks are identical to non-idmapped mounts. This has no effect for e.g. security xattrs since they don't store uids or gids and don't perform permission checks on them like posix acls do.
Quoted 8 lines
Cc Christoph Hellwig <[email protected]>Cc David Howells <[email protected]>Cc Al Viro <[email protected]>Reviewed-by Christoph Hellwig <[email protected]>Signed-off-by Tycho Andersen <[email protected]>Signed-off-by Christian Brauner <[email protected]>
Signature · 7 lines
James Morris <[email protected]> _______________________________________________ Containers mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/containers
David Howells
maintainerRe: [PATCH v6 09/40] xattr: handle idmapped mounts
In reply to Christian Braunerfs/cachefiles/xattr.c int cachefiles_check_object_type(struct cachefiles_object *object) · line 43
Quoted 12 lines · Christian Brauner
fs/cachefiles/xattr.c +2
-2@@ -39,8 +39,8 @@ int cachefiles_check_object_type(struct cachefiles_object *object)_enter ("%p{%s}" , object, type);/* attempt to install a type label directly */ - ret =vfs_setxattr (dentry, cachefiles_xattr_cache, type,2 , -XATTR_CREATE ); + ret =vfs_setxattr (&init_user_ns, dentry, cachefiles_xattr_cache, type, +2 ,XATTR_CREATE );
Actually, on further consideration, this might be the wrong thing to do in cachefiles. The creds are (or should be) overridden when accesses to the underlying filesystem are being made.
I wonder if this should be using current_cred()->user_ns or cache->cache_cred->user_ns instead.
David
_______________________________________________
Containers mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/containers
Re: [PATCH v6 09/40] xattr: handle idmapped mounts
Quoted 9 lines · David Howells
Quoted 7 lines · Christian Brauner
fs/cachefiles/xattr.c +0
-0@@ -39,8 +39,8 @@ int cachefiles_check_object_type(struct cachefiles_object *object)_enter ("%p{%s}" , object, type);
Quoted 6 lines
fs/cachefiles/xattr.c int cachefiles_check_object_type(struct cachefiles_object *object) · line 43
Quoted 5 lines
fs/cachefiles/xattr.c +2
-2/* attempt to install a type label directly */ - ret =vfs_setxattr (dentry, cachefiles_xattr_cache, type,2 , -XATTR_CREATE ); + ret =vfs_setxattr (&init_user_ns, dentry, cachefiles_xattr_cache, type, +2 ,XATTR_CREATE );
Hey David,
(Ok, recovered from my run-in with the swapfile bug. I even managed to get my emails back.)
Quoted 6 lines
Actually, on further consideration, this might be the wrong thing to do in cachefiles. The creds are (or should be) overridden when accesses to the underlying filesystem are being made.
I wonder if this should be using current_cred()->user_ns or
cache->cache_cred->user_nsinstead.
Before I go into the second question please note that this is a no-op change. So if this is wrong it was wrong before. Which is your point, I guess.
Please also note that the mnt_userns is _never_ used for (capability) permission checking, only for idmapping vfs objects and permission checks based on the i_uid and i_gid. So if your argument about passing one of those two user namespaces above has anything to do with permission checking on caps it's most likely wrong. :)
In order to answer this more confidently I need to know a bit more about how cachefiles are supposed to work.
From what I gather here it seemed what this code is trying to set here is an internal "CacheFiles.cache" extended attribute on the indode. This extended attribute doesn't store any uids and gids or filesystem capabilities so the user namespace isn't relevant for that since there doesn't need to be any conversion.
What I need to know is what information do you use for cachefiles to determine whether someone can set that "Cachefiles.cache" extended attribute on the inode:
- Is it the mnt_userns of a/the mount of the filesystem you're caching for?
- The mnt_userns of the mnt of struct cachefiles_cache?
- Or the stashed or current creds of the caller?
Christian
_______________________________________________
Containers mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/containers
David Howells
maintainerRe: [PATCH v6 09/40] xattr: handle idmapped mounts
Quoted 9 lines · Christian Brauner
In order to answer this more confidently I need to know a bit more about how cachefiles are supposed to work.
From what I gather here it seemed what this code is trying to set here is an internal "CacheFiles.cache" extended attribute on the indode. This extended attribute doesn't store any uids and gids or filesystem capabilities so the user namespace isn't relevant for that since there doesn't need to be any conversion.
Quoted 6 lines
What I need to know is what information do you use for cachefiles to determine whether someone can set that "Cachefiles.cache" extended attribute on the inode:
- Is it themnt_usernsof a/the mount of the filesystem you're caching for?
- Themnt_usernsof the mnt of structcachefiles_cache?
- Or the stashed or current creds of the caller?
Mostly it's about permission checking. The cache driver wants to do accesses onto the files in cache using the context of whatever process writes the "bind" command to /dev/cachefiles, not the context of whichever process issued a read or write, say, on an NFS file that is being cached.
This causes standard UNIX perm checking, SELinux checking, etc. all to be switched to the appropriate context. It also controls what appears in the audit logs.
There is an exception to this: It also governs the ownership of new files and directories created in the cache and what security labels will be set on them.
Quite possibly this doesn't matter for the xattr stuff. It's hard to tell since we use user namespaces to convey so many different things at different times.
David
_______________________________________________
Containers mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/containers
Re: [PATCH v6 09/40] xattr: handle idmapped mounts
Quoted 18 lines · David Howells
Quoted 9 lines · Christian Brauner
In order to answer this more confidently I need to know a bit more about how cachefiles are supposed to work.
From what I gather here it seemed what this code is trying to set here is an internal "CacheFiles.cache" extended attribute on the indode. This extended attribute doesn't store any uids and gids or filesystem capabilities so the user namespace isn't relevant for that since there doesn't need to be any conversion.
Quoted 6 lines
What I need to know is what information do you use for cachefiles to determine whether someone can set that "Cachefiles.cache" extended attribute on the inode:
- Is it themnt_usernsof a/the mount of the filesystem you're caching for?
- Themnt_usernsof the mnt of structcachefiles_cache?
- Or the stashed or current creds of the caller?
Quoted 8 lines
Mostly it's about permission checking. The cache driver wants to do accesses onto the files in cache using the context of whatever process writes the "bind" command to
/dev/cachefiles, not the context of whichever process issued a read or write, say, on an NFS file that is being cached.This causes standard UNIX perm checking, SELinux checking, etc. all to be switched to the appropriate context. It also controls what appears in the audit logs.
(Audit always translates from and to init_user_ns. The changes to make it aware of user namespaces proper are delayed until the audit id thing is merged as Paul pointed out to me.)
Quoted 3 lines
There is an exception to this: It also governs the ownership of new files and directories created in the cache and what security labels will be set on them.
So from our offline discussion I gather that cachefilesd creates a cache on a local filesystem (ext4, xfs etc.) for a network filesystem. The way this is done is by writing "bind" to /dev/cachefiles and pointing it to a directory to use as the cache.
This directory can currently also be an idmapped mount, say:
mount --bind --idmap /mnt /mnt
and then pointing cachefilesd via a "bind" operation to
/mnt
What I would expect is for cachefilesd to now take that idmapping into account when creating files in /mnt but as it stands now, it doesn't. This could leave users confused as the ownership of the files wouldn't match to what they expressed in the idmapping. Since you're reworking cachefilesd currently anyway, I would suggest we port cachefilesd to support idmapped mounts once as part of your rework. I can help there and until then we do:
fs/cachefiles/bind.c +6 -0
@@ -115,6 +115,12 @@ static int cachefiles_daemon_add_cache(struct cachefiles_cache *cache)if (ret <0 ) goto error_open_root; +if (mnt_user_ns (path.mnt) != &init_user_ns) { + ret = -EPERM ; +pr_err ("Caches on idmapped mounts are currently not supported\n" ); + goto error_open_root; + } + cache->mnt = path.mnt; root = path.dentry;
This is safe to do because if a mount is visible in the filesystem it can't change it's idmapping.
(Might even be worth if you add a helper at this point:
static inline bool mnt_is_idmapped(struct vfsmount *mnt)
{
return mnt_user_ns(mnt) != &init_user_ns;
})
Christian
_______________________________________________
Containers mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/containers