Skip to content

Commit 37657da

Browse files
committed
userns: Allow setting a userns mapping to your current uid.
Acked-by: Serge Hallyn <[email protected]> Signed-off-by: "Eric W. Biederman" <[email protected]>
1 parent 7fa294c commit 37657da

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

kernel/user_namespace.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,21 @@ ssize_t proc_projid_map_write(struct file *file, const char __user *buf, size_t
709709
static bool new_idmap_permitted(struct user_namespace *ns, int cap_setid,
710710
struct uid_gid_map *new_map)
711711
{
712+
/* Allow mapping to your own filesystem ids */
713+
if ((new_map->nr_extents == 1) && (new_map->extent[0].count == 1)) {
714+
u32 id = new_map->extent[0].lower_first;
715+
if (cap_setid == CAP_SETUID) {
716+
kuid_t uid = make_kuid(ns->parent, id);
717+
if (uid_eq(uid, current_fsuid()))
718+
return true;
719+
}
720+
else if (cap_setid == CAP_SETGID) {
721+
kgid_t gid = make_kgid(ns->parent, id);
722+
if (gid_eq(gid, current_fsgid()))
723+
return true;
724+
}
725+
}
726+
712727
/* Allow anyone to set a mapping that doesn't require privilege */
713728
if (!cap_valid(cap_setid))
714729
return true;

0 commit comments

Comments
 (0)