Commit 8af7f144 authored by Eric W. Biederman's avatar Eric W. Biederman Committed by Jiri Slaby

userns: Rename id_map_mutex to userns_state_mutex

commit f0d62aec upstream.

Generalize id_map_mutex so it can be used for more state of a user namespace.
Reviewed-by: default avatarAndy Lutomirski <luto@amacapital.net>
Signed-off-by: default avatar"Eric W. Biederman" <ebiederm@xmission.com>
Signed-off-by: default avatarJiri Slaby <jslaby@suse.cz>
parent 42eec84f
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include <linux/fs_struct.h> #include <linux/fs_struct.h>
static struct kmem_cache *user_ns_cachep __read_mostly; static struct kmem_cache *user_ns_cachep __read_mostly;
static DEFINE_MUTEX(userns_state_mutex);
static bool new_idmap_permitted(const struct file *file, static bool new_idmap_permitted(const struct file *file,
struct user_namespace *ns, int cap_setid, struct user_namespace *ns, int cap_setid,
...@@ -575,9 +576,6 @@ static bool mappings_overlap(struct uid_gid_map *new_map, struct uid_gid_extent ...@@ -575,9 +576,6 @@ static bool mappings_overlap(struct uid_gid_map *new_map, struct uid_gid_extent
return false; return false;
} }
static DEFINE_MUTEX(id_map_mutex);
static ssize_t map_write(struct file *file, const char __user *buf, static ssize_t map_write(struct file *file, const char __user *buf,
size_t count, loff_t *ppos, size_t count, loff_t *ppos,
int cap_setid, int cap_setid,
...@@ -594,7 +592,7 @@ static ssize_t map_write(struct file *file, const char __user *buf, ...@@ -594,7 +592,7 @@ static ssize_t map_write(struct file *file, const char __user *buf,
ssize_t ret = -EINVAL; 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. * Any map is only ever written once.
* *
...@@ -612,7 +610,7 @@ static ssize_t map_write(struct file *file, const char __user *buf, ...@@ -612,7 +610,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 * order and smp_rmb() is guaranteed that we don't have crazy
* architectures returning stale data. * architectures returning stale data.
*/ */
mutex_lock(&id_map_mutex); mutex_lock(&userns_state_mutex);
ret = -EPERM; ret = -EPERM;
/* Only allow one successful write to the map */ /* Only allow one successful write to the map */
...@@ -739,7 +737,7 @@ static ssize_t map_write(struct file *file, const char __user *buf, ...@@ -739,7 +737,7 @@ static ssize_t map_write(struct file *file, const char __user *buf,
*ppos = count; *ppos = count;
ret = count; ret = count;
out: out:
mutex_unlock(&id_map_mutex); mutex_unlock(&userns_state_mutex);
if (page) if (page)
free_page(page); free_page(page);
return ret; return ret;
...@@ -831,12 +829,12 @@ bool userns_may_setgroups(const struct user_namespace *ns) ...@@ -831,12 +829,12 @@ bool userns_may_setgroups(const struct user_namespace *ns)
{ {
bool allowed; bool allowed;
mutex_lock(&id_map_mutex); mutex_lock(&userns_state_mutex);
/* It is not safe to use setgroups until a gid mapping in /* It is not safe to use setgroups until a gid mapping in
* the user namespace has been established. * the user namespace has been established.
*/ */
allowed = ns->gid_map.nr_extents != 0; allowed = ns->gid_map.nr_extents != 0;
mutex_unlock(&id_map_mutex); mutex_unlock(&userns_state_mutex);
return allowed; return allowed;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment