Skip to content

Commit f0d62ae

Browse files
committed
userns: Rename id_map_mutex to userns_state_mutex
Generalize id_map_mutex so it can be used for more state of a user namespace. Cc: stable@vger.kernel.org Reviewed-by: Andy Lutomirski <luto@amacapital.net> Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
1 parent f95d791 commit f0d62ae

1 file changed

Lines changed: 6 additions & 8 deletions

File tree

‎kernel/user_namespace.c‎

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <linux/fs_struct.h>
2525

2626
static struct kmem_cache *user_ns_cachep __read_mostly;
27+
static DEFINE_MUTEX(userns_state_mutex);
2728

2829
static bool new_idmap_permitted(const struct file *file,
2930
struct user_namespace *ns, int cap_setid,
@@ -583,9 +584,6 @@ static bool mappings_overlap(struct uid_gid_map *new_map,
583584
return false;
584585
}
585586

586-
587-
static DEFINE_MUTEX(id_map_mutex);
588-
589587
static ssize_t map_write(struct file *file, const char __user *buf,
590588
size_t count, loff_t *ppos,
591589
int cap_setid,
@@ -602,7 +600,7 @@ static ssize_t map_write(struct file *file, const char __user *buf,
602600
ssize_t ret = -EINVAL;
603601

604602
/*
605-
* The id_map_mutex serializes all writes to any given map.
603+
* The userns_state_mutex serializes all writes to any given map.
606604
*
607605
* Any map is only ever written once.
608606
*
@@ -620,7 +618,7 @@ static ssize_t map_write(struct file *file, const char __user *buf,
620618
* order and smp_rmb() is guaranteed that we don't have crazy
621619
* architectures returning stale data.
622620
*/
623-
mutex_lock(&id_map_mutex);
621+
mutex_lock(&userns_state_mutex);
624622

625623
ret = -EPERM;
626624
/* Only allow one successful write to the map */
@@ -750,7 +748,7 @@ static ssize_t map_write(struct file *file, const char __user *buf,
750748
*ppos = count;
751749
ret = count;
752750
out:
753-
mutex_unlock(&id_map_mutex);
751+
mutex_unlock(&userns_state_mutex);
754752
if (page)
755753
free_page(page);
756754
return ret;
@@ -845,12 +843,12 @@ bool userns_may_setgroups(const struct user_namespace *ns)
845843
{
846844
bool allowed;
847845

848-
mutex_lock(&id_map_mutex);
846+
mutex_lock(&userns_state_mutex);
849847
/* It is not safe to use setgroups until a gid mapping in
850848
* the user namespace has been established.
851849
*/
852850
allowed = ns->gid_map.nr_extents != 0;
853-
mutex_unlock(&id_map_mutex);
851+
mutex_unlock(&userns_state_mutex);
854852

855853
return allowed;
856854
}

0 commit comments

Comments
 (0)