Skip to contentSkip to conversation

fix NGROUPS hard limit (resend)

PATCH In review Timothy Hockin 1 participant 1 message Oct 22, 2002

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 2/4 fix NGROUPS hard limit (resend)

# This is a BitKeeper generated patch for the following project:
# Project Name: Linux kernel tree
# This patch format is intended for GNU patch command version 2.5 or higher. # This patch includes the following deltas:
# ChangeSet 1.809 -> 1.810
# include/linux/init_task.h 1.19 -> 1.20
# include/linux/sched.h 1.108 -> 1.109
# kernel/fork.c 1.87 -> 1.88
# kernel/sys.c 1.30 -> 1.31
# include/asm-i386/param.h 1.2 -> 1.3

#	      kernel/uid16.c	1.2     -> 1.3    
#	     fs/proc/array.c	1.31    -> 1.32   
#	       kernel/exit.c	1.72    -> 1.73   

# include/linux/limits.h 1.3 -> 1.4
#
# The following is the BitKeeper ChangeSet Log
# --------------------------------------------
# 02/10/21 [email protected] 1.810
# Remove the limit of 32 groups. We now have a per-task, dynamic array of # groups, which is kept sorted and refcounted.
#
# This ChangeSet incorporates all the core functionality. but does not fixup

# all the incorrect usages of groups.  That is in a seperate ChangeSet.
# --------------------------------------------
#
diff -Nru a/fs/proc/array.c b/fs/proc/array.c
--- a/fs/proc/array.c	Mon Oct 21 17:14:36 2002
+++ b/fs/proc/array.c	Mon Oct 21 17:14:36 2002
@@ -171,7 +171,7 @@
 		p->files ? p->files->max_fds : 0);
 	task_unlock(p);

- for (g = 0; g < p->ngroups; g++)
+ for (g = 0; g < min(p->ngroups, OLD_NGROUPS); g++)
buffer += sprintf(buffer, "%d ", p->groups[g]);

buffer += sprintf(buffer, "\n");

include/asm-i386/param.h +0 -4
diff -Nru a/include/asm-i386/param.h b/include/asm-i386/param.h
@@ -13,10 +13,6 @@
 
 #define EXEC_PAGESIZE	4096
 
-#ifndef NGROUPS
-#define NGROUPS		32
-#endif
-
 #ifndef NOGROUP
 #define NOGROUP		(-1)
 #endif
include/linux/init_task.h +1 -0
diff -Nru a/include/linux/init_task.h b/include/linux/init_task.h
@@ -80,6 +80,7 @@
 	.real_timer	= {						\
 		.function	= it_real_fn				\
 	},								\
+	.ngroups	= 0,						\
 	.cap_effective	= CAP_INIT_EFF_SET,				\
 	.cap_inheritable = CAP_INIT_INH_SET,				\
 	.cap_permitted	= CAP_FULL_SET,					\
include/linux/limits.h +2 -1
diff -Nru a/include/linux/limits.h b/include/linux/limits.h
@@ -3,7 +3,6 @@
 
 #define NR_OPEN	        1024
 
-#define NGROUPS_MAX       32	/* supplemental group IDs are available */
 #define ARG_MAX       131072	/* # bytes of args + environ for exec() */
 #define CHILD_MAX        999    /* no limit :-) */
 #define OPEN_MAX         256	/* # open files a process may have */
@@ -18,5 +17,7 @@
 #define XATTR_LIST_MAX 65536	/* size of extended attribute namelist (64k) */
 
 #define RTSIG_MAX	  32
+
+#define OLD_NGROUPS       32	/* old limit of supplemental group IDs */
 
 #endif
include/linux/sched.h +2 -1
diff -Nru a/include/linux/sched.h b/include/linux/sched.h
@@ -343,7 +343,8 @@
 	uid_t uid,euid,suid,fsuid;
 	gid_t gid,egid,sgid,fsgid;
 	int ngroups;
-	gid_t	groups[NGROUPS];
+	gid_t *groups;
+	atomic_t *groups_refcount;
 	kernel_cap_t   cap_effective, cap_inheritable, cap_permitted;
 	int keep_capabilities:1;
 	struct user_struct *user;
kernel/exit.c +6 -0
diff -Nru a/kernel/exit.c b/kernel/exit.c
@@ -7,6 +7,7 @@
 #include <linux/config.h>
 #include <linux/mm.h>
 #include <linux/slab.h>
+#include <linux/vmalloc.h>
 #include <linux/interrupt.h>
 #include <linux/smp_lock.h>
 #include <linux/module.h>
@@ -65,6 +66,11 @@
  
 	if (p != current)
 		wait_task_inactive(p);
+
+	if (p->ngroups && atomic_dec_and_test(p->groups_refcount)) {
+		vfree(p->groups_refcount);
+		vfree(p->groups);
+	}
 
 	atomic_dec(&p->user->processes);
 	security_ops->task_free_security(p);
kernel/fork.c +4 -0
diff -Nru a/kernel/fork.c b/kernel/fork.c
@@ -810,6 +810,10 @@
 	 */
 	clear_tsk_thread_flag(p, TIF_SYSCALL_TRACE);
 
+	/* increment the groups ref count */
+	if (p->ngroups)
+		atomic_inc(p->groups_refcount);
+
 	/* Our parent execution domain becomes current domain
 	   These must match for thread signalling to apply */
 	   
kernel/sys.c +68 -20

119 lines not on this page · raw message

kernel/uid16.c +48 -15

103 lines not on this page · raw message