Skip to content

Commit 00fcd1c

Browse files
ebiedermgregkh
authored andcommitted
groups: Consolidate the setgroups permission checks
commit 7ff4d90 upstream. Today there are 3 instances of setgroups and due to an oversight their permission checking has diverged. Add a common function so that they may all share the same permission checking code. This corrects the current oversight in the current permission checks and adds a helper to avoid this in the future. A user namespace security fix will update this new helper, shortly. Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 5f20ade commit 00fcd1c

4 files changed

Lines changed: 11 additions & 3 deletions

File tree

‎arch/s390/kernel/compat_linux.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ asmlinkage long sys32_setgroups16(int gidsetsize, u16 __user *grouplist)
245245
struct group_info *group_info;
246246
int retval;
247247

248-
if (!capable(CAP_SETGID))
248+
if (!may_setgroups())
249249
return -EPERM;
250250
if ((unsigned)gidsetsize > NGROUPS_MAX)
251251
return -EINVAL;

‎include/linux/cred.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ extern void groups_free(struct group_info *);
6868
extern int set_current_groups(struct group_info *);
6969
extern int set_groups(struct cred *, struct group_info *);
7070
extern int groups_search(const struct group_info *, kgid_t);
71+
extern bool may_setgroups(void);
7172

7273
/* access the groups "array" with this macro */
7374
#define GROUP_AT(gi, i) \

‎kernel/groups.c‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,13 @@ SYSCALL_DEFINE2(getgroups, int, gidsetsize, gid_t __user *, grouplist)
223223
return i;
224224
}
225225

226+
bool may_setgroups(void)
227+
{
228+
struct user_namespace *user_ns = current_user_ns();
229+
230+
return ns_capable(user_ns, CAP_SETGID);
231+
}
232+
226233
/*
227234
* SMP: Our groups are copy-on-write. We can set them safely
228235
* without another task interfering.
@@ -233,7 +240,7 @@ SYSCALL_DEFINE2(setgroups, int, gidsetsize, gid_t __user *, grouplist)
233240
struct group_info *group_info;
234241
int retval;
235242

236-
if (!ns_capable(current_user_ns(), CAP_SETGID))
243+
if (!may_setgroups())
237244
return -EPERM;
238245
if ((unsigned)gidsetsize > NGROUPS_MAX)
239246
return -EINVAL;

‎kernel/uid16.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ SYSCALL_DEFINE2(setgroups16, int, gidsetsize, old_gid_t __user *, grouplist)
176176
struct group_info *group_info;
177177
int retval;
178178

179-
if (!ns_capable(current_user_ns(), CAP_SETGID))
179+
if (!may_setgroups())
180180
return -EPERM;
181181
if ((unsigned)gidsetsize > NGROUPS_MAX)
182182
return -EINVAL;

0 commit comments

Comments
 (0)