Skip to content

Commit

Permalink
userns: Rename id_map_mutex to userns_state_mutex
Browse files Browse the repository at this point in the history
Generalize id_map_mutex so it can be used for more state of a user namespace.

Cc: [email protected]
Reviewed-by: Andy Lutomirski <[email protected]>
Signed-off-by: "Eric W. Biederman" <[email protected]>
  • Loading branch information
ebiederm committed Dec 9, 2014
1 parent f95d791 commit f0d62ae
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions kernel/user_namespace.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <linux/fs_struct.h>

static struct kmem_cache *user_ns_cachep __read_mostly;
static DEFINE_MUTEX(userns_state_mutex);

static bool new_idmap_permitted(const struct file *file,
struct user_namespace *ns, int cap_setid,
Expand Down Expand Up @@ -583,9 +584,6 @@ static bool mappings_overlap(struct uid_gid_map *new_map,
return false;
}


static DEFINE_MUTEX(id_map_mutex);

static ssize_t map_write(struct file *file, const char __user *buf,
size_t count, loff_t *ppos,
int cap_setid,
Expand All @@ -602,7 +600,7 @@ static ssize_t map_write(struct file *file, const char __user *buf,
ssize_t ret = -EINVAL;

/*
* The id_map_mutex serializes all writes to any given map.
* The userns_state_mutex serializes all writes to any given map.
*
* Any map is only ever written once.
*
Expand All @@ -620,7 +618,7 @@ static ssize_t map_write(struct file *file, const char __user *buf,
* order and smp_rmb() is guaranteed that we don't have crazy
* architectures returning stale data.
*/
mutex_lock(&id_map_mutex);
mutex_lock(&userns_state_mutex);

ret = -EPERM;
/* Only allow one successful write to the map */
Expand Down Expand Up @@ -750,7 +748,7 @@ static ssize_t map_write(struct file *file, const char __user *buf,
*ppos = count;
ret = count;
out:
mutex_unlock(&id_map_mutex);
mutex_unlock(&userns_state_mutex);
if (page)
free_page(page);
return ret;
Expand Down Expand Up @@ -845,12 +843,12 @@ bool userns_may_setgroups(const struct user_namespace *ns)
{
bool allowed;

mutex_lock(&id_map_mutex);
mutex_lock(&userns_state_mutex);
/* It is not safe to use setgroups until a gid mapping in
* the user namespace has been established.
*/
allowed = ns->gid_map.nr_extents != 0;
mutex_unlock(&id_map_mutex);
mutex_unlock(&userns_state_mutex);

return allowed;
}
Expand Down

0 comments on commit f0d62ae

Please sign in to comment.