diff options
Diffstat (limited to 'kernel')
| -rw-r--r-- | kernel/groups.c | 4 | ||||
| -rw-r--r-- | kernel/user_namespace.c | 14 |
2 files changed, 17 insertions, 1 deletions
diff --git a/kernel/groups.c b/kernel/groups.c index 02d8a251c476..664411f171b5 100644 --- a/kernel/groups.c +++ b/kernel/groups.c | |||
| @@ -6,6 +6,7 @@ | |||
| 6 | #include <linux/slab.h> | 6 | #include <linux/slab.h> |
| 7 | #include <linux/security.h> | 7 | #include <linux/security.h> |
| 8 | #include <linux/syscalls.h> | 8 | #include <linux/syscalls.h> |
| 9 | #include <linux/user_namespace.h> | ||
| 9 | #include <asm/uaccess.h> | 10 | #include <asm/uaccess.h> |
| 10 | 11 | ||
| 11 | /* init to 2 - one for init_task, one to ensure it is never freed */ | 12 | /* init to 2 - one for init_task, one to ensure it is never freed */ |
| @@ -217,7 +218,8 @@ bool may_setgroups(void) | |||
| 217 | { | 218 | { |
| 218 | struct user_namespace *user_ns = current_user_ns(); | 219 | struct user_namespace *user_ns = current_user_ns(); |
| 219 | 220 | ||
| 220 | return ns_capable(user_ns, CAP_SETGID); | 221 | return ns_capable(user_ns, CAP_SETGID) && |
| 222 | userns_may_setgroups(user_ns); | ||
| 221 | } | 223 | } |
| 222 | 224 | ||
| 223 | /* | 225 | /* |
diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c index b99c862a2e3f..27c8dab48c07 100644 --- a/kernel/user_namespace.c +++ b/kernel/user_namespace.c | |||
| @@ -843,6 +843,20 @@ static bool new_idmap_permitted(const struct file *file, | |||
| 843 | return false; | 843 | return false; |
| 844 | } | 844 | } |
| 845 | 845 | ||
| 846 | bool userns_may_setgroups(const struct user_namespace *ns) | ||
| 847 | { | ||
| 848 | bool allowed; | ||
| 849 | |||
| 850 | mutex_lock(&id_map_mutex); | ||
| 851 | /* It is not safe to use setgroups until a gid mapping in | ||
| 852 | * the user namespace has been established. | ||
| 853 | */ | ||
| 854 | allowed = ns->gid_map.nr_extents != 0; | ||
| 855 | mutex_unlock(&id_map_mutex); | ||
| 856 | |||
| 857 | return allowed; | ||
| 858 | } | ||
| 859 | |||
| 846 | static void *userns_get(struct task_struct *task) | 860 | static void *userns_get(struct task_struct *task) |
| 847 | { | 861 | { |
| 848 | struct user_namespace *user_ns; | 862 | struct user_namespace *user_ns; |
