mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2026-05-24 11:18:52 +03:00
Support idmapped mount in user namespace
Linux 5.17 commit torvalds/linux@5dfbfe71e enables "the idmapping infrastructure to support idmapped mounts of filesystems mounted with an idmapping". Update the OpenZFS accordingly to improve the idmapped mount support. This pull request contains the following changes: - xattr setter functions are fixed to take mnt_ns argument. Without this, cp -p would fail for an idmapped mount in a user namespace. - idmap_util is enhanced/fixed for its use in a user ns context. - One test case added to test idmapped mount in a user ns. Reviewed-by: Christian Brauner <christian@brauner.io> Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Signed-off-by: Youzhong Yang <yyang@mathworks.com> Closes #14097
This commit is contained in:
@@ -118,16 +118,16 @@ zpl_vap_init(vattr_t *vap, struct inode *dir, umode_t mode, cred_t *cr,
|
||||
vap->va_mask = ATTR_MODE;
|
||||
vap->va_mode = mode;
|
||||
|
||||
vap->va_uid = zfs_uid_from_mnt((struct user_namespace *)mnt_ns,
|
||||
crgetuid(cr));
|
||||
vap->va_uid = zfs_vfsuid_to_uid((struct user_namespace *)mnt_ns,
|
||||
zfs_i_user_ns(dir), crgetuid(cr));
|
||||
|
||||
if (dir && dir->i_mode & S_ISGID) {
|
||||
vap->va_gid = KGID_TO_SGID(dir->i_gid);
|
||||
if (S_ISDIR(mode))
|
||||
vap->va_mode |= S_ISGID;
|
||||
} else {
|
||||
vap->va_gid = zfs_gid_from_mnt((struct user_namespace *)mnt_ns,
|
||||
crgetgid(cr));
|
||||
vap->va_gid = zfs_vfsgid_to_gid((struct user_namespace *)mnt_ns,
|
||||
zfs_i_user_ns(dir), crgetgid(cr));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,7 +145,7 @@ zpl_create(struct inode *dir, struct dentry *dentry, umode_t mode, bool flag)
|
||||
int error;
|
||||
fstrans_cookie_t cookie;
|
||||
#ifndef HAVE_IOPS_CREATE_USERNS
|
||||
zuserns_t *user_ns = NULL;
|
||||
zuserns_t *user_ns = kcred->user_ns;
|
||||
#endif
|
||||
|
||||
crhold(cr);
|
||||
@@ -192,7 +192,7 @@ zpl_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
|
||||
int error;
|
||||
fstrans_cookie_t cookie;
|
||||
#ifndef HAVE_IOPS_MKNOD_USERNS
|
||||
zuserns_t *user_ns = NULL;
|
||||
zuserns_t *user_ns = kcred->user_ns;
|
||||
#endif
|
||||
|
||||
/*
|
||||
@@ -247,7 +247,7 @@ zpl_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode)
|
||||
int error;
|
||||
fstrans_cookie_t cookie;
|
||||
#ifndef HAVE_TMPFILE_USERNS
|
||||
zuserns_t *userns = NULL;
|
||||
zuserns_t *userns = kcred->user_ns;
|
||||
#endif
|
||||
|
||||
crhold(cr);
|
||||
@@ -325,7 +325,7 @@ zpl_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
|
||||
int error;
|
||||
fstrans_cookie_t cookie;
|
||||
#ifndef HAVE_IOPS_MKDIR_USERNS
|
||||
zuserns_t *user_ns = NULL;
|
||||
zuserns_t *user_ns = kcred->user_ns;
|
||||
#endif
|
||||
|
||||
crhold(cr);
|
||||
@@ -468,8 +468,20 @@ zpl_setattr(struct dentry *dentry, struct iattr *ia)
|
||||
vap = kmem_zalloc(sizeof (vattr_t), KM_SLEEP);
|
||||
vap->va_mask = ia->ia_valid & ATTR_IATTR_MASK;
|
||||
vap->va_mode = ia->ia_mode;
|
||||
vap->va_uid = KUID_TO_SUID(ia->ia_uid);
|
||||
vap->va_gid = KGID_TO_SGID(ia->ia_gid);
|
||||
if (ia->ia_valid & ATTR_UID)
|
||||
#ifdef HAVE_IATTR_VFSID
|
||||
vap->va_uid = zfs_vfsuid_to_uid(user_ns, zfs_i_user_ns(ip),
|
||||
__vfsuid_val(ia->ia_vfsuid));
|
||||
#else
|
||||
vap->va_uid = KUID_TO_SUID(ia->ia_uid);
|
||||
#endif
|
||||
if (ia->ia_valid & ATTR_GID)
|
||||
#ifdef HAVE_IATTR_VFSID
|
||||
vap->va_gid = zfs_vfsgid_to_gid(user_ns, zfs_i_user_ns(ip),
|
||||
__vfsgid_val(ia->ia_vfsgid));
|
||||
#else
|
||||
vap->va_gid = KGID_TO_SGID(ia->ia_gid);
|
||||
#endif
|
||||
vap->va_size = ia->ia_size;
|
||||
vap->va_atime = ia->ia_atime;
|
||||
vap->va_mtime = ia->ia_mtime;
|
||||
@@ -482,7 +494,7 @@ zpl_setattr(struct dentry *dentry, struct iattr *ia)
|
||||
#ifdef HAVE_SETATTR_PREPARE_USERNS
|
||||
error = -zfs_setattr(ITOZ(ip), vap, 0, cr, user_ns);
|
||||
#else
|
||||
error = -zfs_setattr(ITOZ(ip), vap, 0, cr, NULL);
|
||||
error = -zfs_setattr(ITOZ(ip), vap, 0, cr, kcred->user_ns);
|
||||
#endif
|
||||
if (!error && (ia->ia_valid & ATTR_MODE))
|
||||
error = zpl_chmod_acl(ip);
|
||||
@@ -510,7 +522,7 @@ zpl_rename2(struct inode *sdip, struct dentry *sdentry,
|
||||
int error;
|
||||
fstrans_cookie_t cookie;
|
||||
#ifndef HAVE_IOPS_RENAME_USERNS
|
||||
zuserns_t *user_ns = NULL;
|
||||
zuserns_t *user_ns = kcred->user_ns;
|
||||
#endif
|
||||
|
||||
crhold(cr);
|
||||
@@ -557,7 +569,7 @@ zpl_symlink(struct inode *dir, struct dentry *dentry, const char *name)
|
||||
int error;
|
||||
fstrans_cookie_t cookie;
|
||||
#ifndef HAVE_IOPS_SYMLINK_USERNS
|
||||
zuserns_t *user_ns = NULL;
|
||||
zuserns_t *user_ns = kcred->user_ns;
|
||||
#endif
|
||||
|
||||
crhold(cr);
|
||||
|
||||
Reference in New Issue
Block a user