fs: port vfs{g,u}id helpers to mnt_idmap
JIRA: https://issues.redhat.com/browse/RHEL-33888 Status: Linus Conflicts: Dropped hunks for ksmbd because the source is not present in the CentOS Stream source tree. commit 4d7ca4090184c153f8ccb1a68ca5cf136dac108b Author: Christian Brauner <brauner@kernel.org> Date: Fri Jan 13 12:49:32 2023 +0100 fs: port vfs{g,u}id helpers to mnt_idmap Convert to struct mnt_idmap. Last cycle we merged the necessary infrastructure in 256c8aed2b42 ("fs: introduce dedicated idmap type for mounts"). This is just the conversion to struct mnt_idmap. Currently we still pass around the plain namespace that was attached to a mount. This is in general pretty convenient but it makes it easy to conflate namespaces that are relevant on the filesystem with namespaces that are relevent on the mount level. Especially for non-vfs developers without detailed knowledge in this area this can be a potential source for bugs. Once the conversion to struct mnt_idmap is done all helpers down to the really low-level helpers will take a struct mnt_idmap argument instead of two namespace arguments. This way it becomes impossible to conflate the two eliminating the possibility of any bugs. All of the vfs and all filesystems only operate on struct mnt_idmap. Acked-by: Dave Chinner <dchinner@redhat.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Christian Brauner (Microsoft) <brauner@kernel.org> Signed-off-by: Ian Kent <ikent@redhat.com>
This commit is contained in:
parent
4f34d24b81
commit
252894f3c0
|
@ -379,7 +379,6 @@ EXPORT_SYMBOL(may_setattr);
|
|||
int notify_change(struct mnt_idmap *idmap, struct dentry *dentry,
|
||||
struct iattr *attr, struct inode **delegated_inode)
|
||||
{
|
||||
struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
|
||||
struct inode *inode = dentry->d_inode;
|
||||
umode_t mode = inode->i_mode;
|
||||
int error;
|
||||
|
@ -453,11 +452,11 @@ int notify_change(struct mnt_idmap *idmap, struct dentry *dentry,
|
|||
* namespace of the superblock.
|
||||
*/
|
||||
if (ia_valid & ATTR_UID &&
|
||||
!vfsuid_has_fsmapping(mnt_userns, inode->i_sb->s_user_ns,
|
||||
!vfsuid_has_fsmapping(idmap, inode->i_sb->s_user_ns,
|
||||
attr->ia_vfsuid))
|
||||
return -EOVERFLOW;
|
||||
if (ia_valid & ATTR_GID &&
|
||||
!vfsgid_has_fsmapping(mnt_userns, inode->i_sb->s_user_ns,
|
||||
!vfsgid_has_fsmapping(idmap, inode->i_sb->s_user_ns,
|
||||
attr->ia_vfsgid))
|
||||
return -EOVERFLOW;
|
||||
|
||||
|
|
|
@ -472,7 +472,6 @@ static int fat_allow_set_time(struct mnt_idmap *idmap,
|
|||
int fat_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
|
||||
struct iattr *attr)
|
||||
{
|
||||
struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
|
||||
struct msdos_sb_info *sbi = MSDOS_SB(dentry->d_sb);
|
||||
struct inode *inode = d_inode(dentry);
|
||||
unsigned int ia_valid;
|
||||
|
@ -511,10 +510,10 @@ int fat_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
|
|||
}
|
||||
|
||||
if (((attr->ia_valid & ATTR_UID) &&
|
||||
(!uid_eq(from_vfsuid(mnt_userns, i_user_ns(inode), attr->ia_vfsuid),
|
||||
(!uid_eq(from_vfsuid(idmap, i_user_ns(inode), attr->ia_vfsuid),
|
||||
sbi->options.fs_uid))) ||
|
||||
((attr->ia_valid & ATTR_GID) &&
|
||||
(!gid_eq(from_vfsgid(mnt_userns, i_user_ns(inode), attr->ia_vfsgid),
|
||||
(!gid_eq(from_vfsgid(idmap, i_user_ns(inode), attr->ia_vfsgid),
|
||||
sbi->options.fs_gid))) ||
|
||||
((attr->ia_valid & ATTR_MODE) &&
|
||||
(attr->ia_mode & ~FAT_VALID_MODE)))
|
||||
|
|
|
@ -717,7 +717,7 @@ static inline bool setattr_vfsgid(struct iattr *attr, kgid_t kgid)
|
|||
int chown_common(const struct path *path, uid_t user, gid_t group)
|
||||
{
|
||||
struct mnt_idmap *idmap;
|
||||
struct user_namespace *mnt_userns, *fs_userns;
|
||||
struct user_namespace *fs_userns;
|
||||
struct inode *inode = path->dentry->d_inode;
|
||||
struct inode *delegated_inode = NULL;
|
||||
int error;
|
||||
|
@ -729,7 +729,6 @@ int chown_common(const struct path *path, uid_t user, gid_t group)
|
|||
gid = make_kgid(current_user_ns(), group);
|
||||
|
||||
idmap = mnt_idmap(path->mnt);
|
||||
mnt_userns = mnt_idmap_owner(idmap);
|
||||
fs_userns = i_user_ns(inode);
|
||||
|
||||
retry_deleg:
|
||||
|
@ -747,8 +746,8 @@ retry_deleg:
|
|||
/* Continue to send actual fs values, not the mount values. */
|
||||
error = security_path_chown(
|
||||
path,
|
||||
from_vfsuid(mnt_userns, fs_userns, newattrs.ia_vfsuid),
|
||||
from_vfsgid(mnt_userns, fs_userns, newattrs.ia_vfsgid));
|
||||
from_vfsuid(idmap, fs_userns, newattrs.ia_vfsuid),
|
||||
from_vfsgid(idmap, fs_userns, newattrs.ia_vfsgid));
|
||||
if (!error)
|
||||
error = notify_change(idmap, path->dentry, &newattrs,
|
||||
&delegated_inode);
|
||||
|
|
|
@ -352,7 +352,7 @@ static const char *ovl_get_link(struct dentry *dentry,
|
|||
* alter the POSIX ACLs for the underlying filesystem.
|
||||
*/
|
||||
static void ovl_idmap_posix_acl(const struct inode *realinode,
|
||||
struct user_namespace *mnt_userns,
|
||||
struct mnt_idmap *idmap,
|
||||
struct posix_acl *acl)
|
||||
{
|
||||
struct user_namespace *fs_userns = i_user_ns(realinode);
|
||||
|
@ -364,11 +364,11 @@ static void ovl_idmap_posix_acl(const struct inode *realinode,
|
|||
struct posix_acl_entry *e = &acl->a_entries[i];
|
||||
switch (e->e_tag) {
|
||||
case ACL_USER:
|
||||
vfsuid = make_vfsuid(mnt_userns, fs_userns, e->e_uid);
|
||||
vfsuid = make_vfsuid(idmap, fs_userns, e->e_uid);
|
||||
e->e_uid = vfsuid_into_kuid(vfsuid);
|
||||
break;
|
||||
case ACL_GROUP:
|
||||
vfsgid = make_vfsgid(mnt_userns, fs_userns, e->e_gid);
|
||||
vfsgid = make_vfsgid(idmap, fs_userns, e->e_gid);
|
||||
e->e_gid = vfsgid_into_kgid(vfsgid);
|
||||
break;
|
||||
}
|
||||
|
@ -403,12 +403,10 @@ struct posix_acl *ovl_get_acl_path(const struct path *path,
|
|||
const char *acl_name, bool noperm)
|
||||
{
|
||||
struct posix_acl *real_acl, *clone;
|
||||
struct user_namespace *mnt_userns;
|
||||
struct mnt_idmap *idmap;
|
||||
struct inode *realinode = d_inode(path->dentry);
|
||||
|
||||
idmap = mnt_idmap(path->mnt);
|
||||
mnt_userns = mnt_idmap_owner(idmap);
|
||||
|
||||
if (noperm)
|
||||
real_acl = get_inode_acl(realinode, posix_acl_type(acl_name));
|
||||
|
@ -431,7 +429,7 @@ struct posix_acl *ovl_get_acl_path(const struct path *path,
|
|||
if (!clone)
|
||||
return ERR_PTR(-ENOMEM);
|
||||
|
||||
ovl_idmap_posix_acl(realinode, mnt_userns, clone);
|
||||
ovl_idmap_posix_acl(realinode, idmap, clone);
|
||||
return clone;
|
||||
}
|
||||
|
||||
|
|
|
@ -379,7 +379,6 @@ posix_acl_permission(struct mnt_idmap *idmap, struct inode *inode,
|
|||
{
|
||||
const struct posix_acl_entry *pa, *pe, *mask_obj;
|
||||
struct user_namespace *fs_userns = i_user_ns(inode);
|
||||
struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
|
||||
int found = 0;
|
||||
vfsuid_t vfsuid;
|
||||
vfsgid_t vfsgid;
|
||||
|
@ -395,7 +394,7 @@ posix_acl_permission(struct mnt_idmap *idmap, struct inode *inode,
|
|||
goto check_perm;
|
||||
break;
|
||||
case ACL_USER:
|
||||
vfsuid = make_vfsuid(mnt_userns, fs_userns,
|
||||
vfsuid = make_vfsuid(idmap, fs_userns,
|
||||
pa->e_uid);
|
||||
if (vfsuid_eq_kuid(vfsuid, current_fsuid()))
|
||||
goto mask;
|
||||
|
@ -409,7 +408,7 @@ posix_acl_permission(struct mnt_idmap *idmap, struct inode *inode,
|
|||
}
|
||||
break;
|
||||
case ACL_GROUP:
|
||||
vfsgid = make_vfsgid(mnt_userns, fs_userns,
|
||||
vfsgid = make_vfsgid(idmap, fs_userns,
|
||||
pa->e_gid);
|
||||
if (vfsgid_in_group_p(vfsgid)) {
|
||||
found = 1;
|
||||
|
@ -896,7 +895,6 @@ static ssize_t vfs_posix_acl_to_xattr(struct mnt_idmap *idmap,
|
|||
struct posix_acl_xattr_header *ext_acl = buffer;
|
||||
struct posix_acl_xattr_entry *ext_entry;
|
||||
struct user_namespace *fs_userns, *caller_userns;
|
||||
struct user_namespace *mnt_userns;
|
||||
ssize_t real_size, n;
|
||||
vfsuid_t vfsuid;
|
||||
vfsgid_t vfsgid;
|
||||
|
@ -912,19 +910,18 @@ static ssize_t vfs_posix_acl_to_xattr(struct mnt_idmap *idmap,
|
|||
|
||||
fs_userns = i_user_ns(inode);
|
||||
caller_userns = current_user_ns();
|
||||
mnt_userns = mnt_idmap_owner(idmap);
|
||||
for (n=0; n < acl->a_count; n++, ext_entry++) {
|
||||
const struct posix_acl_entry *acl_e = &acl->a_entries[n];
|
||||
ext_entry->e_tag = cpu_to_le16(acl_e->e_tag);
|
||||
ext_entry->e_perm = cpu_to_le16(acl_e->e_perm);
|
||||
switch(acl_e->e_tag) {
|
||||
case ACL_USER:
|
||||
vfsuid = make_vfsuid(mnt_userns, fs_userns, acl_e->e_uid);
|
||||
vfsuid = make_vfsuid(idmap, fs_userns, acl_e->e_uid);
|
||||
ext_entry->e_id = cpu_to_le32(from_kuid(
|
||||
caller_userns, vfsuid_into_kuid(vfsuid)));
|
||||
break;
|
||||
case ACL_GROUP:
|
||||
vfsgid = make_vfsgid(mnt_userns, fs_userns, acl_e->e_gid);
|
||||
vfsgid = make_vfsgid(idmap, fs_userns, acl_e->e_gid);
|
||||
ext_entry->e_id = cpu_to_le32(from_kgid(
|
||||
caller_userns, vfsgid_into_kgid(vfsgid)));
|
||||
break;
|
||||
|
@ -1049,18 +1046,16 @@ static int vfs_set_acl_idmapped_mnt(struct mnt_idmap *idmap,
|
|||
struct user_namespace *fs_userns,
|
||||
struct posix_acl *acl)
|
||||
{
|
||||
struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
|
||||
|
||||
for (int n = 0; n < acl->a_count; n++) {
|
||||
struct posix_acl_entry *acl_e = &acl->a_entries[n];
|
||||
|
||||
switch (acl_e->e_tag) {
|
||||
case ACL_USER:
|
||||
acl_e->e_uid = from_vfsuid(mnt_userns, fs_userns,
|
||||
acl_e->e_uid = from_vfsuid(idmap, fs_userns,
|
||||
VFSUIDT_INIT(acl_e->e_uid));
|
||||
break;
|
||||
case ACL_GROUP:
|
||||
acl_e->e_gid = from_vfsgid(mnt_userns, fs_userns,
|
||||
acl_e->e_gid = from_vfsgid(idmap, fs_userns,
|
||||
VFSGIDT_INIT(acl_e->e_gid));
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -2094,7 +2094,6 @@ EXPORT_SYMBOL(__dquot_transfer);
|
|||
int dquot_transfer(struct mnt_idmap *idmap, struct inode *inode,
|
||||
struct iattr *iattr)
|
||||
{
|
||||
struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
|
||||
struct dquot *transfer_to[MAXQUOTAS] = {};
|
||||
struct dquot *dquot;
|
||||
struct super_block *sb = inode->i_sb;
|
||||
|
@ -2104,7 +2103,7 @@ int dquot_transfer(struct mnt_idmap *idmap, struct inode *inode,
|
|||
return 0;
|
||||
|
||||
if (i_uid_needs_update(idmap, iattr, inode)) {
|
||||
kuid_t kuid = from_vfsuid(mnt_userns, i_user_ns(inode),
|
||||
kuid_t kuid = from_vfsuid(idmap, i_user_ns(inode),
|
||||
iattr->ia_vfsuid);
|
||||
|
||||
dquot = dqget(sb, make_kqid_uid(kuid));
|
||||
|
@ -2118,7 +2117,7 @@ int dquot_transfer(struct mnt_idmap *idmap, struct inode *inode,
|
|||
transfer_to[USRQUOTA] = dquot;
|
||||
}
|
||||
if (i_gid_needs_update(idmap, iattr, inode)) {
|
||||
kgid_t kgid = from_vfsgid(mnt_userns, i_user_ns(inode),
|
||||
kgid_t kgid = from_vfsgid(idmap, i_user_ns(inode),
|
||||
iattr->ia_vfsgid);
|
||||
|
||||
dquot = dqget(sb, make_kqid_gid(kgid));
|
||||
|
|
|
@ -663,7 +663,6 @@ xfs_setattr_nonsize(
|
|||
kgid_t gid = GLOBAL_ROOT_GID;
|
||||
struct xfs_dquot *udqp = NULL, *gdqp = NULL;
|
||||
struct xfs_dquot *old_udqp = NULL, *old_gdqp = NULL;
|
||||
struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
|
||||
|
||||
ASSERT((mask & ATTR_SIZE) == 0);
|
||||
|
||||
|
@ -679,14 +678,14 @@ xfs_setattr_nonsize(
|
|||
uint qflags = 0;
|
||||
|
||||
if ((mask & ATTR_UID) && XFS_IS_UQUOTA_ON(mp)) {
|
||||
uid = from_vfsuid(mnt_userns, i_user_ns(inode),
|
||||
uid = from_vfsuid(idmap, i_user_ns(inode),
|
||||
iattr->ia_vfsuid);
|
||||
qflags |= XFS_QMOPT_UQUOTA;
|
||||
} else {
|
||||
uid = inode->i_uid;
|
||||
}
|
||||
if ((mask & ATTR_GID) && XFS_IS_GQUOTA_ON(mp)) {
|
||||
gid = from_vfsgid(mnt_userns, i_user_ns(inode),
|
||||
gid = from_vfsgid(idmap, i_user_ns(inode),
|
||||
iattr->ia_vfsgid);
|
||||
qflags |= XFS_QMOPT_GQUOTA;
|
||||
} else {
|
||||
|
|
|
@ -1722,8 +1722,7 @@ static inline void i_gid_write(struct inode *inode, gid_t gid)
|
|||
static inline vfsuid_t i_uid_into_vfsuid(struct mnt_idmap *idmap,
|
||||
const struct inode *inode)
|
||||
{
|
||||
struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
|
||||
return make_vfsuid(mnt_userns, i_user_ns(inode), inode->i_uid);
|
||||
return make_vfsuid(idmap, i_user_ns(inode), inode->i_uid);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1759,10 +1758,8 @@ static inline void i_uid_update(struct mnt_idmap *idmap,
|
|||
const struct iattr *attr,
|
||||
struct inode *inode)
|
||||
{
|
||||
struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
|
||||
|
||||
if (attr->ia_valid & ATTR_UID)
|
||||
inode->i_uid = from_vfsuid(mnt_userns, i_user_ns(inode),
|
||||
inode->i_uid = from_vfsuid(idmap, i_user_ns(inode),
|
||||
attr->ia_vfsuid);
|
||||
}
|
||||
|
||||
|
@ -1777,8 +1774,7 @@ static inline void i_uid_update(struct mnt_idmap *idmap,
|
|||
static inline vfsgid_t i_gid_into_vfsgid(struct mnt_idmap *idmap,
|
||||
const struct inode *inode)
|
||||
{
|
||||
struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
|
||||
return make_vfsgid(mnt_userns, i_user_ns(inode), inode->i_gid);
|
||||
return make_vfsgid(idmap, i_user_ns(inode), inode->i_gid);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1814,10 +1810,8 @@ static inline void i_gid_update(struct mnt_idmap *idmap,
|
|||
const struct iattr *attr,
|
||||
struct inode *inode)
|
||||
{
|
||||
struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
|
||||
|
||||
if (attr->ia_valid & ATTR_GID)
|
||||
inode->i_gid = from_vfsgid(mnt_userns, i_user_ns(inode),
|
||||
inode->i_gid = from_vfsgid(idmap, i_user_ns(inode),
|
||||
attr->ia_vfsgid);
|
||||
}
|
||||
|
||||
|
|
|
@ -190,7 +190,7 @@ static inline bool no_idmapping(const struct user_namespace *mnt_userns,
|
|||
|
||||
/**
|
||||
* make_vfsuid - map a filesystem kuid into a mnt_userns
|
||||
* @mnt_userns: the mount's idmapping
|
||||
* @idmap: the mount's idmapping
|
||||
* @fs_userns: the filesystem's idmapping
|
||||
* @kuid : kuid to be mapped
|
||||
*
|
||||
|
@ -209,11 +209,12 @@ static inline bool no_idmapping(const struct user_namespace *mnt_userns,
|
|||
* returned.
|
||||
*/
|
||||
|
||||
static inline vfsuid_t make_vfsuid(struct user_namespace *mnt_userns,
|
||||
static inline vfsuid_t make_vfsuid(struct mnt_idmap *idmap,
|
||||
struct user_namespace *fs_userns,
|
||||
kuid_t kuid)
|
||||
{
|
||||
uid_t uid;
|
||||
struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
|
||||
|
||||
if (no_idmapping(mnt_userns, fs_userns))
|
||||
return VFSUIDT_INIT(kuid);
|
||||
|
@ -228,7 +229,7 @@ static inline vfsuid_t make_vfsuid(struct user_namespace *mnt_userns,
|
|||
|
||||
/**
|
||||
* make_vfsgid - map a filesystem kgid into a mnt_userns
|
||||
* @mnt_userns: the mount's idmapping
|
||||
* @idmap: the mount's idmapping
|
||||
* @fs_userns: the filesystem's idmapping
|
||||
* @kgid : kgid to be mapped
|
||||
*
|
||||
|
@ -247,11 +248,12 @@ static inline vfsuid_t make_vfsuid(struct user_namespace *mnt_userns,
|
|||
* returned.
|
||||
*/
|
||||
|
||||
static inline vfsgid_t make_vfsgid(struct user_namespace *mnt_userns,
|
||||
static inline vfsgid_t make_vfsgid(struct mnt_idmap *idmap,
|
||||
struct user_namespace *fs_userns,
|
||||
kgid_t kgid)
|
||||
{
|
||||
gid_t gid;
|
||||
struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
|
||||
|
||||
if (no_idmapping(mnt_userns, fs_userns))
|
||||
return VFSGIDT_INIT(kgid);
|
||||
|
@ -266,7 +268,7 @@ static inline vfsgid_t make_vfsgid(struct user_namespace *mnt_userns,
|
|||
|
||||
/**
|
||||
* from_vfsuid - map a vfsuid into the filesystem idmapping
|
||||
* @mnt_userns: the mount's idmapping
|
||||
* @idmap: the mount's idmapping
|
||||
* @fs_userns: the filesystem's idmapping
|
||||
* @vfsuid : vfsuid to be mapped
|
||||
*
|
||||
|
@ -275,11 +277,12 @@ static inline vfsgid_t make_vfsgid(struct user_namespace *mnt_userns,
|
|||
*
|
||||
* Return: @vfsuid mapped into the filesystem idmapping
|
||||
*/
|
||||
static inline kuid_t from_vfsuid(struct user_namespace *mnt_userns,
|
||||
static inline kuid_t from_vfsuid(struct mnt_idmap *idmap,
|
||||
struct user_namespace *fs_userns,
|
||||
vfsuid_t vfsuid)
|
||||
{
|
||||
uid_t uid;
|
||||
struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
|
||||
|
||||
if (no_idmapping(mnt_userns, fs_userns))
|
||||
return AS_KUIDT(vfsuid);
|
||||
|
@ -293,7 +296,7 @@ static inline kuid_t from_vfsuid(struct user_namespace *mnt_userns,
|
|||
|
||||
/**
|
||||
* vfsuid_has_fsmapping - check whether a vfsuid maps into the filesystem
|
||||
* @mnt_userns: the mount's idmapping
|
||||
* @idmap: the mount's idmapping
|
||||
* @fs_userns: the filesystem's idmapping
|
||||
* @vfsuid: vfsuid to be mapped
|
||||
*
|
||||
|
@ -303,11 +306,11 @@ static inline kuid_t from_vfsuid(struct user_namespace *mnt_userns,
|
|||
*
|
||||
* Return: true if @vfsuid has a mapping in the filesystem, false if not.
|
||||
*/
|
||||
static inline bool vfsuid_has_fsmapping(struct user_namespace *mnt_userns,
|
||||
static inline bool vfsuid_has_fsmapping(struct mnt_idmap *idmap,
|
||||
struct user_namespace *fs_userns,
|
||||
vfsuid_t vfsuid)
|
||||
{
|
||||
return uid_valid(from_vfsuid(mnt_userns, fs_userns, vfsuid));
|
||||
return uid_valid(from_vfsuid(idmap, fs_userns, vfsuid));
|
||||
}
|
||||
|
||||
static inline bool vfsuid_has_mapping(struct user_namespace *userns,
|
||||
|
@ -331,7 +334,7 @@ static inline kuid_t vfsuid_into_kuid(vfsuid_t vfsuid)
|
|||
|
||||
/**
|
||||
* from_vfsgid - map a vfsgid into the filesystem idmapping
|
||||
* @mnt_userns: the mount's idmapping
|
||||
* @idmap: the mount's idmapping
|
||||
* @fs_userns: the filesystem's idmapping
|
||||
* @vfsgid : vfsgid to be mapped
|
||||
*
|
||||
|
@ -340,11 +343,12 @@ static inline kuid_t vfsuid_into_kuid(vfsuid_t vfsuid)
|
|||
*
|
||||
* Return: @vfsgid mapped into the filesystem idmapping
|
||||
*/
|
||||
static inline kgid_t from_vfsgid(struct user_namespace *mnt_userns,
|
||||
static inline kgid_t from_vfsgid(struct mnt_idmap *idmap,
|
||||
struct user_namespace *fs_userns,
|
||||
vfsgid_t vfsgid)
|
||||
{
|
||||
gid_t gid;
|
||||
struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
|
||||
|
||||
if (no_idmapping(mnt_userns, fs_userns))
|
||||
return AS_KGIDT(vfsgid);
|
||||
|
@ -358,7 +362,7 @@ static inline kgid_t from_vfsgid(struct user_namespace *mnt_userns,
|
|||
|
||||
/**
|
||||
* vfsgid_has_fsmapping - check whether a vfsgid maps into the filesystem
|
||||
* @mnt_userns: the mount's idmapping
|
||||
* @idmap: the mount's idmapping
|
||||
* @fs_userns: the filesystem's idmapping
|
||||
* @vfsgid: vfsgid to be mapped
|
||||
*
|
||||
|
@ -368,11 +372,11 @@ static inline kgid_t from_vfsgid(struct user_namespace *mnt_userns,
|
|||
*
|
||||
* Return: true if @vfsgid has a mapping in the filesystem, false if not.
|
||||
*/
|
||||
static inline bool vfsgid_has_fsmapping(struct user_namespace *mnt_userns,
|
||||
static inline bool vfsgid_has_fsmapping(struct mnt_idmap *idmap,
|
||||
struct user_namespace *fs_userns,
|
||||
vfsgid_t vfsgid)
|
||||
{
|
||||
return gid_valid(from_vfsgid(mnt_userns, fs_userns, vfsgid));
|
||||
return gid_valid(from_vfsgid(idmap, fs_userns, vfsgid));
|
||||
}
|
||||
|
||||
static inline bool vfsgid_has_mapping(struct user_namespace *userns,
|
||||
|
@ -410,9 +414,7 @@ static inline kgid_t vfsgid_into_kgid(vfsgid_t vfsgid)
|
|||
static inline kuid_t mapped_fsuid(struct mnt_idmap *idmap,
|
||||
struct user_namespace *fs_userns)
|
||||
{
|
||||
struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
|
||||
return from_vfsuid(mnt_userns, fs_userns,
|
||||
VFSUIDT_INIT(current_fsuid()));
|
||||
return from_vfsuid(idmap, fs_userns, VFSUIDT_INIT(current_fsuid()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -431,9 +433,7 @@ static inline kuid_t mapped_fsuid(struct mnt_idmap *idmap,
|
|||
static inline kgid_t mapped_fsgid(struct mnt_idmap *idmap,
|
||||
struct user_namespace *fs_userns)
|
||||
{
|
||||
struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
|
||||
return from_vfsgid(mnt_userns, fs_userns,
|
||||
VFSGIDT_INIT(current_fsgid()));
|
||||
return from_vfsgid(idmap, fs_userns, VFSGIDT_INIT(current_fsgid()));
|
||||
}
|
||||
|
||||
#endif /* _LINUX_MNT_IDMAPPING_H */
|
||||
|
|
|
@ -391,7 +391,6 @@ int cap_inode_getsecurity(struct mnt_idmap *idmap,
|
|||
struct vfs_ns_cap_data *nscap = NULL;
|
||||
struct dentry *dentry;
|
||||
struct user_namespace *fs_ns;
|
||||
struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
|
||||
|
||||
if (strcmp(name, "capability") != 0)
|
||||
return -EOPNOTSUPP;
|
||||
|
@ -421,7 +420,7 @@ int cap_inode_getsecurity(struct mnt_idmap *idmap,
|
|||
kroot = make_kuid(fs_ns, root);
|
||||
|
||||
/* If this is an idmapped mount shift the kuid. */
|
||||
vfsroot = make_vfsuid(mnt_userns, fs_ns, kroot);
|
||||
vfsroot = make_vfsuid(idmap, fs_ns, kroot);
|
||||
|
||||
/* If the root kuid maps to a valid uid in current ns, then return
|
||||
* this as a nscap. */
|
||||
|
@ -537,7 +536,6 @@ int cap_convert_nscap(struct mnt_idmap *idmap, struct dentry *dentry,
|
|||
struct inode *inode = d_backing_inode(dentry);
|
||||
struct user_namespace *task_ns = current_user_ns(),
|
||||
*fs_ns = inode->i_sb->s_user_ns;
|
||||
struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
|
||||
kuid_t rootid;
|
||||
vfsuid_t vfsrootid;
|
||||
size_t newsize;
|
||||
|
@ -557,7 +555,7 @@ int cap_convert_nscap(struct mnt_idmap *idmap, struct dentry *dentry,
|
|||
if (!vfsuid_valid(vfsrootid))
|
||||
return -EINVAL;
|
||||
|
||||
rootid = from_vfsuid(mnt_userns, fs_ns, vfsrootid);
|
||||
rootid = from_vfsuid(idmap, fs_ns, vfsrootid);
|
||||
if (!uid_valid(rootid))
|
||||
return -EINVAL;
|
||||
|
||||
|
@ -653,7 +651,6 @@ int get_vfs_caps_from_disk(struct mnt_idmap *idmap,
|
|||
kuid_t rootkuid;
|
||||
vfsuid_t rootvfsuid;
|
||||
struct user_namespace *fs_ns;
|
||||
struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
|
||||
|
||||
memset(cpu_caps, 0, sizeof(struct cpu_vfs_cap_data));
|
||||
|
||||
|
@ -698,7 +695,7 @@ int get_vfs_caps_from_disk(struct mnt_idmap *idmap,
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
rootvfsuid = make_vfsuid(mnt_userns, fs_ns, rootkuid);
|
||||
rootvfsuid = make_vfsuid(idmap, fs_ns, rootkuid);
|
||||
if (!vfsuid_valid(rootvfsuid))
|
||||
return -ENODATA;
|
||||
|
||||
|
|
Loading…
Reference in New Issue