locks: print unsigned ino in /proc/locks
[GitHub/LineageOS/android_kernel_samsung_universal7580.git] / kernel / groups.c
index 6b2588dd04ff20fb89995394f9c530a2613fbb83..c1d384bb25fbd6e662f0050e42afde804c07ccae 100644 (file)
@@ -6,6 +6,7 @@
 #include <linux/slab.h>
 #include <linux/security.h>
 #include <linux/syscalls.h>
+#include <linux/user_namespace.h>
 #include <asm/uaccess.h>
 
 /* init to 2 - one for init_task, one to ensure it is never freed */
@@ -153,6 +154,18 @@ int groups_search(const struct group_info *group_info, kgid_t grp)
        return 0;
 }
 
+ /**
+ * set_groups_sorted - Change a group subscription in a set of credentials
+ * @new: The newly prepared set of credentials to alter
+ * @group_info: The group list to install; must be sorted
+ */
+static void set_groups_sorted(struct cred *new, struct group_info *group_info)
+{
+       put_group_info(new->group_info);
+       get_group_info(group_info);
+       new->group_info = group_info;
+}
+
 /**
  * set_groups - Change a group subscription in a set of credentials
  * @new: The newly prepared set of credentials to alter
@@ -163,10 +176,8 @@ int groups_search(const struct group_info *group_info, kgid_t grp)
  */
 int set_groups(struct cred *new, struct group_info *group_info)
 {
-       put_group_info(new->group_info);
        groups_sort(group_info);
-       get_group_info(group_info);
-       new->group_info = group_info;
+       set_groups_sorted(new, group_info);
        return 0;
 }
 
@@ -223,6 +234,14 @@ out:
        return i;
 }
 
+bool may_setgroups(void)
+{
+       struct user_namespace *user_ns = current_user_ns();
+
+       return ns_capable(user_ns, CAP_SETGID) &&
+               userns_may_setgroups(user_ns);
+}
+
 /*
  *     SMP: Our groups are copy-on-write. We can set them safely
  *     without another task interfering.
@@ -233,7 +252,7 @@ SYSCALL_DEFINE2(setgroups, int, gidsetsize, gid_t __user *, grouplist)
        struct group_info *group_info;
        int retval;
 
-       if (!nsown_capable(CAP_SETGID))
+       if (!may_setgroups())
                return -EPERM;
        if ((unsigned)gidsetsize > NGROUPS_MAX)
                return -EINVAL;