Skip to content

Commit

Permalink
Revert parts of 938cfeb
Browse files Browse the repository at this point in the history
When read and writing the UID/GID, we always want the value
relative to the root user namespace, the kernel will take care
of remapping this to the user namespace for us.

Calling from_kuid(user_ns, uid) with a unmapped uid will return -1
as that uid is outside of the scope of that namespace, and will result
in the files inside the namespace all being owned by 'nobody' and not
being allowed to call chmod or chown on them.

Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: Allan Jude <[email protected]>
Closes openzfs#12263
  • Loading branch information
allanjude authored and andrewc12 committed Sep 23, 2022
1 parent 04d83c5 commit 0225637
Showing 1 changed file with 0 additions and 16 deletions.
16 changes: 0 additions & 16 deletions include/os/linux/kernel/linux/vfs_compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -296,11 +296,7 @@ static inline struct dentry *file_dentry(const struct file *f)

static inline uid_t zfs_uid_read_impl(struct inode *ip)
{
#ifdef HAVE_SUPER_USER_NS
return (from_kuid(ip->i_sb->s_user_ns, ip->i_uid));
#else
return (from_kuid(kcred->user_ns, ip->i_uid));
#endif
}

static inline uid_t zfs_uid_read(struct inode *ip)
Expand All @@ -310,11 +306,7 @@ static inline uid_t zfs_uid_read(struct inode *ip)

static inline gid_t zfs_gid_read_impl(struct inode *ip)
{
#ifdef HAVE_SUPER_USER_NS
return (from_kgid(ip->i_sb->s_user_ns, ip->i_gid));
#else
return (from_kgid(kcred->user_ns, ip->i_gid));
#endif
}

static inline gid_t zfs_gid_read(struct inode *ip)
Expand All @@ -324,20 +316,12 @@ static inline gid_t zfs_gid_read(struct inode *ip)

static inline void zfs_uid_write(struct inode *ip, uid_t uid)
{
#ifdef HAVE_SUPER_USER_NS
ip->i_uid = make_kuid(ip->i_sb->s_user_ns, uid);
#else
ip->i_uid = make_kuid(kcred->user_ns, uid);
#endif
}

static inline void zfs_gid_write(struct inode *ip, gid_t gid)
{
#ifdef HAVE_SUPER_USER_NS
ip->i_gid = make_kgid(ip->i_sb->s_user_ns, gid);
#else
ip->i_gid = make_kgid(kcred->user_ns, gid);
#endif
}

/*
Expand Down

0 comments on commit 0225637

Please sign in to comment.