Skip to content

Commit

Permalink
fs: tweak fsuidgid_has_mapping()
Browse files Browse the repository at this point in the history
If the caller's fs{g,u}id aren't mapped in the mount's idmapping we can
return early and skip the check whether the mapped fs{g,u}id also have a
mapping in the filesystem's idmapping. If the fs{g,u}id aren't mapped in
the mount's idmapping they consequently can't be mapped in the
filesystem's idmapping. So there's no point in checking that.

Link: https://lore.kernel.org/r/[email protected] (v1)
Link: https://lore.kernel.org/r/[email protected] (v2)
Link: https://lore.kernel.org/r/[email protected]
Cc: Seth Forshee <[email protected]>
Cc: Christoph Hellwig <[email protected]>
Cc: Al Viro <[email protected]>
CC: [email protected]
Reviewed-by: Amir Goldstein <[email protected]>
Reviewed-by: Seth Forshee <[email protected]>
Signed-off-by: Christian Brauner <[email protected]>
  • Loading branch information
Christian Brauner authored and Jaegeuk Kim committed Dec 20, 2022
1 parent 1845197 commit 47ab4bf
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions include/linux/fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -1697,10 +1697,18 @@ static inline void inode_fsgid_set(struct inode *inode,
static inline bool fsuidgid_has_mapping(struct super_block *sb,
struct user_namespace *mnt_userns)
{
struct user_namespace *s_user_ns = sb->s_user_ns;
struct user_namespace *fs_userns = sb->s_user_ns;
kuid_t kuid;
kgid_t kgid;

return kuid_has_mapping(s_user_ns, mapped_fsuid(mnt_userns)) &&
kgid_has_mapping(s_user_ns, mapped_fsgid(mnt_userns));
kuid = mapped_fsuid(mnt_userns);
if (!uid_valid(kuid))
return false;
kgid = mapped_fsgid(mnt_userns);
if (!gid_valid(kgid))
return false;
return kuid_has_mapping(fs_userns, kuid) &&
kgid_has_mapping(fs_userns, kgid);
}

extern struct timespec64 current_time(struct inode *inode);
Expand Down

0 comments on commit 47ab4bf

Please sign in to comment.