PATCH - NGROUPS 2.6.2rc2 + fixups
Subsystems (11)
Linus, Andrew,
Attached is a patch to remove the NGROUPS limit (again). I've fixed up the issues that people have pointed out this week. It incorporates a fixed limit which can be easily changed in a user wanted even more groups.
This patch is against linux-2.6.2rc2. If it is OK, I can make it bitkeeper accessible.
What think?
Signature · 4 lines
Tim Hockin Sun Microsystems, Linux Software Engineering [email protected] All opinions are my own, not Sun's
===== include/linux/sched.h 1.178 vs edited =====
include/linux/sched.h +28 -2
@@ -329,6 +329,33 @@struct io_context ;/* See blkdev.h */ void exit_io_context (void ); +#define NGROUPS_SMALL 32 +#define NGROUPS_PER_BLOCK ((int)(EXEC_PAGESIZE / sizeof(gid_t))) +struct group_info { +int ngroups; +atomic_t usage; +gid_t small_block[NGROUPS_SMALL ]; +int nblocks; +gid_t *blocks[0 ]; +}; + +#define get_group_info (group_info) do { \ + atomic_inc(&(group_info)->usage); \ +} while (0) + +#define put_group_info (group_info) do { \ + if (atomic_dec_and_test(&(group_info)->usage)) \ + groups_free(group_info); \ +} while (0) + +struct group_info *groups_alloc (int gidsetsize); +void groups_free (struct group_info *group_info); +int set_current_groups (struct group_info *group_info); +/* access the groups "array" with this macro */ +#define GROUP_AT (gi, i) \ + ((gi)->blocks[(i)/NGROUPS_PER_BLOCK][(i)%NGROUPS_PER_BLOCK]) + +struct task_struct {volatile long state;/* -1 unrunnable, 0 runnable, >0 stopped */ struct thread_info *thread_info;
@@ -403,8 +430,7 @@/* process credentials */ uid_t uid,euid,suid,fsuid;gid_t gid,egid,sgid,fsgid; -int ngroups; -gid_t groups[NGROUPS ]; +struct group_info *group_info;kernel_cap_t cap_effective, cap_inheritable, cap_permitted; int keep_capabilities:1;struct user_struct *user;
===== include/linux/init_task.h 1.27 vs edited =====
include/linux/init_task.h +3 -0
@@ -56,6 +56,8 @@ .siglock = SPIN_LOCK_UNLOCKED, \ } +extern struct group_info init_groups; +/* * INIT_TASK is used to set up the first task table, touch at * your own risk!. Base=0, limit=0x1fffff (=2MB)
@@ -87,6 +89,7 @@ .real_timer = { \ .function = it_real_fn \ }, \ + .group_info = &init_groups, \ .cap_effective = CAP_INIT_EFF_SET, \ .cap_inheritable = CAP_INIT_INH_SET, \ .cap_permitted = CAP_FULL_SET, \
===== include/linux/limits.h 1.3 vs edited =====
include/linux/limits.h +1 -1
@@ -3,7 +3,7 @@#define NR_OPEN 1024 -#define NGROUPS_MAX 32/* supplemental group IDs are available */ +#define NGROUPS_MAX 65536/* 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 */
===== kernel/sys.c 1.69 vs edited =====
kernel/sys.c +201 -35
281 lines not on this page · raw message
===== kernel/fork.c 1.154 vs edited =====
kernel/fork.c +3 -0
@@ -86,6 +86,7 @@security_task_free (tsk);free_uid (tsk->user); +put_group_info (tsk->group_info);free_task (tsk); }
@@ -878,6 +879,7 @@atomic_inc (&p->user->__count);atomic_inc (&p->user->processes); +get_group_info (p->group_info);/* * If multiple threads are within copy_process(), then this check
@@ -1084,6 +1086,7 @@ bad_fork_cleanup_put_domain:module_put (p->thread_info->exec_domain->module); bad_fork_cleanup_count: +put_group_info (p->group_info);atomic_dec (&p->user->processes);free_uid (p->user); bad_fork_free:
===== kernel/uid16.c 1.5 vs edited =====
kernel/uid16.c +74 -23
119 lines not on this page · raw message
===== fs/proc/array.c 1.55 vs edited =====
fs/proc/array.c +4 -2
@@ -176,8 +176,10 @@ p->files ? p->files->max_fds : 0);task_unlock (p); -for (g =0 ; g < p->ngroups; g++) - buffer +=sprintf (buffer,"%d " , p->groups[g]); +get_group_info (p->group_info); +for (g =0 ; g <min (p->group_info->ngroups,NGROUPS_SMALL ); g++) + buffer +=sprintf (buffer,"%d " ,GROUP_AT (p->group_info,g)); +put_group_info (p->group_info); buffer +=sprintf (buffer,"\n" );return buffer;
===== include/linux/sunrpc/auth.h 1.9 vs edited =====
include/linux/sunrpc/auth.h +1 -2
@@ -28,8 +28,7 @@struct auth_cred {uid_t uid;gid_t gid; -int ngroups; -gid_t *groups; +struct group_info *group_info; };/*
===== include/linux/sunrpc/svcauth.h 1.9 vs edited =====
include/linux/sunrpc/svcauth.h +2 -1
@@ -16,10 +16,11 @@#include <linux/sunrpc/cache.h> #include <linux/hash.h> +#define SVC_CRED_NGROUPS 32struct svc_cred {uid_t cr_uid;gid_t cr_gid; -gid_t cr_groups[NGROUPS ]; +gid_t cr_groups[SVC_CRED_NGROUPS ]; };struct svc_rqst ;/* forward decl */
===== net/sunrpc/auth.c 1.12 vs edited =====
net/sunrpc/auth.c +21 -14
@@ -246,34 +246,41 @@struct rpc_cred *rpcauth_lookupcred (struct rpc_auth *auth,int taskflags) { -struct auth_cred acred = { - .uid = current->fsuid, - .gid = current->fsgid, - .ngroups = current->ngroups, - .groups = current->groups, - }; +struct auth_cred acred; +struct rpc_cred *ret; + +get_group_info (current->group_info); + acred.uid = current->fsuid; + acred.gid = current->fsgid; + acred.group_info = current->group_info; +dprintk ("RPC: looking up %s cred\n" , auth->au_ops->au_name); -return rpcauth_lookup_credcache (auth, &acred, taskflags); + ret =rpcauth_lookup_credcache (auth, &acred, taskflags); +put_group_info (current->group_info); +return ret; }struct rpc_cred *rpcauth_bindcred (struct rpc_task *task) {struct rpc_auth *auth = task->tk_auth; -struct auth_cred acred = { - .uid = current->fsuid, - .gid = current->fsgid, - .ngroups = current->ngroups, - .groups = current->groups, - }; +struct auth_cred acred; +struct rpc_cred *ret; + +get_group_info (current->group_info); + acred.uid = current->fsuid; + acred.gid = current->fsgid; + acred.group_info = current->group_info;dprintk ("RPC: %4d looking up %s cred\n" , task->tk_pid, task->tk_auth->au_ops->au_name); task->tk_msg.rpc_cred =rpcauth_lookup_credcache (auth, &acred, task->tk_flags);if (task->tk_msg.rpc_cred ==0 ) task->tk_status = -ENOMEM ; -return task->tk_msg.rpc_cred; + ret = task->tk_msg.rpc_cred; +put_group_info (current->group_info); +return ret; }void
===== net/sunrpc/auth_unix.c 1.11 vs edited =====
net/sunrpc/auth_unix.c +4 -4
@@ -82,7 +82,7 @@ cred->uc_gid = cred->uc_pgid =0 ; cred->uc_gids[0 ] =NOGROUP ; }else { -int groups = acred->ngroups; +int groups = acred->group_info->ngroups;if (groups >NFS_NGROUPS ) groups =NFS_NGROUPS ;
@@ -91,7 +91,7 @@ cred->uc_puid = current->uid; cred->uc_pgid = current->gid;for (i =0 ; i < groups; i++) - cred->uc_gids[i] = (gid_t ) acred->groups[i]; + cred->uc_gids[i] =GROUP_AT (acred->group_info, i);if (i <NFS_NGROUPS ) cred->uc_gids[i] =NOGROUP ; }
@@ -126,11 +126,11 @@ || cred->uc_pgid != current->gid)return 0 ; - groups = acred->ngroups; + groups = acred->group_info->ngroups;if (groups >NFS_NGROUPS ) groups =NFS_NGROUPS ;for (i =0 ; i < groups ; i++) -if (cred->uc_gids[i] != (gid_t ) acred->groups[i]) +if (cred->uc_gids[i] !=GROUP_AT (acred->group_info, i))return 0 ;return 1 ; }
===== net/sunrpc/svcauth_unix.c 1.20 vs edited =====
net/sunrpc/svcauth_unix.c +2 -2
@@ -434,11 +434,11 @@if (slen >16 || (len -= (slen +2 )*4 ) <0 ) goto badcred;for (i =0 ; i < slen; i++) -if (i <NGROUPS ) +if (i <SVC_CRED_NGROUPS ) cred->cr_groups[i] =ntohl (svc_getu32 (argv));else svc_getu32 (argv); -if (i <NGROUPS ) +if (i <SVC_CRED_NGROUPS ) cred->cr_groups[i] =NOGROUP ;if (svc_getu32 (argv) !=RPC_AUTH_NULL ||svc_getu32 (argv) !=0 ) {
===== fs/nfsd/auth.c 1.2 vs edited =====
fs/nfsd/auth.c +7 -4
@@ -10,12 +10,15 @@#include <linux/sunrpc/svcauth.h> #include <linux/nfsd/nfsd.h> +extern asmlinkage long sys_setgroups (int gidsetsize,gid_t *grouplist); +#define CAP_NFSD_MASK (CAP_FS_MASK|CAP_TO_MASK(CAP_SYS_RESOURCE))void nfsd_setuser (struct svc_rqst *rqstp,struct svc_export *exp) {struct svc_cred *cred = &rqstp->rq_cred;int i; +gid_t groups[SVC_CRED_NGROUPS ];if (exp->ex_flags &NFSEXP_ALLSQUASH ) { cred->cr_uid = exp->ex_anon_uid;
@@ -26,7 +29,7 @@ cred->cr_uid = exp->ex_anon_uid;if (!cred->cr_gid) cred->cr_gid = exp->ex_anon_gid; -for (i =0 ; i <NGROUPS ; i++) +for (i =0 ; i <SVC_CRED_NGROUPS ; i++)if (!cred->cr_groups[i]) cred->cr_groups[i] = exp->ex_anon_gid; }
@@ -39,13 +42,13 @@ current->fsgid = cred->cr_gid; else current->fsgid = exp->ex_anon_gid; -for (i =0 ; i <NGROUPS ; i++) { +for (i =0 ; i <SVC_CRED_NGROUPS ; i++) {gid_t group = cred->cr_groups[i];if (group == (gid_t )NOGROUP )break ; - current->groups[i] = group; + groups[i] = group; } - current->ngroups = i; +sys_setgroups (i, groups);if ((cred->cr_uid)) {cap_t (current->cap_effective) &= ~CAP_NFSD_MASK ;
===== fs/nfsd/nfs4state.c 1.21 vs edited =====
fs/nfsd/nfs4state.c +1 -1
@@ -244,7 +244,7 @@ target->cr_uid = source->cr_uid; target->cr_gid = source->cr_gid; -for (i =0 ; i <NGROUPS ; i++) +for (i =0 ; i <SVC_CRED_NGROUPS ; i++) target->cr_groups[i] = source->cr_groups[i]; }
===== include/linux/security.h 1.28 vs edited =====
include/linux/security.h +6 -7
@@ -554,9 +554,8 @@* Return 0 if permission is granted. * @task_setgroups: * Check permission before setting the supplementary group set of the -* current process to @grouplist. -* @gidsetsize contains the number of elements in @grouplist. -* @grouplist contains the array of gids. +* current process. +* @group_info contains the new group information. * Return 0 if permission is granted. * @task_setnice: * Check permission before setting the nice value of @p to @nice.
@@ -1116,7 +1115,7 @@int (*task_setpgid) (struct task_struct * p,pid_t pgid);int (*task_getpgid) (struct task_struct * p);int (*task_getsid) (struct task_struct * p); -int (*task_setgroups) (int gidsetsize,gid_t * grouplist); +int (*task_setgroups) (struct group_info *group_info);int (*task_setnice) (struct task_struct * p,int nice);int (*task_setrlimit) (unsigned int resource,struct rlimit * new_rlim); int (*task_setscheduler) (struct task_struct * p, int policy,
@@ -1670,9 +1669,9 @@return security_ops->task_getsid (p); } -static inline int security_task_setgroups (int gidsetsize,gid_t *grouplist) +static inline int security_task_setgroups (struct group_info *group_info) { -return security_ops->task_setgroups (gidsetsize, grouplist); +return security_ops->task_setgroups (group_info); }static inline int security_task_setnice (struct task_struct *p,int nice)
@@ -2299,7 +2298,7 @@return 0 ; } -static inline int security_task_setgroups (int gidsetsize,gid_t *grouplist) +static inline int security_task_setgroups (struct group_info *group_info) {return 0 ; }
===== security/dummy.c 1.30 vs edited =====
security/dummy.c +1 -1
@@ -539,7 +539,7 @@return 0 ; } -static int dummy_task_setgroups (int gidsetsize,gid_t * grouplist) +static int dummy_task_setgroups (struct group_info *group_info) {return 0 ; }
===== security/selinux/hooks.c 1.20 vs edited =====
security/selinux/hooks.c +1 -1
@@ -2265,7 +2265,7 @@return task_has_perm (current, p,PROCESS__GETSESSION ); } -static int selinux_task_setgroups (int gidsetsize,gid_t *grouplist) +static int selinux_task_setgroups (struct group_info *group_info) {/* See the comment for setuid above. */ return 0 ;
===== arch/ia64/ia32/sys_ia32.c 1.87 vs edited =====
arch/ia64/ia32/sys_ia32.c +81 -27
125 lines not on this page · raw message
===== arch/mips/kernel/sysirix.c 1.18 vs edited =====
arch/mips/kernel/sysirix.c +1 -1
@@ -368,7 +368,7 @@ retval =HZ ; goto out;case 4 : - retval =NGROUPS ; + retval =NGROUPS_MAX ; goto out;case 5 : retval =NR_OPEN ;
===== arch/s390/kernel/compat_linux.c 1.10 vs edited =====
arch/s390/kernel/compat_linux.c +72 -18
112 lines not on this page · raw message
===== arch/sparc64/kernel/sys_sparc32.c 1.86 vs edited =====
arch/sparc64/kernel/sys_sparc32.c +72 -18
112 lines not on this page · raw message
===== include/asm-alpha/param.h 1.2 vs edited =====
include/asm-alpha/param.h +0 -4
@@ -19,10 +19,6 @@#define EXEC_PAGESIZE 8192 -#ifndef NGROUPS -#define NGROUPS 32 -#endif -#ifndef NOGROUP #define NOGROUP (-1)#endif
===== include/asm-arm/param.h 1.5 vs edited =====
include/asm-arm/param.h +0 -4
@@ -26,10 +26,6 @@#define EXEC_PAGESIZE 4096 -#ifndef NGROUPS -#define NGROUPS 32 -#endif -#ifndef NOGROUP #define NOGROUP (-1)#endif
===== include/asm-arm26/param.h 1.1 vs edited =====
include/asm-arm26/param.h +0 -4
@@ -22,10 +22,6 @@# define HZ 100#endif -#ifndef NGROUPS -#define NGROUPS 32 -#endif -#ifndef NOGROUP #define NOGROUP (-1)#endif
===== include/asm-cris/param.h 1.2 vs edited =====
include/asm-cris/param.h +0 -4
@@ -14,10 +14,6 @@#define EXEC_PAGESIZE 8192 -#ifndef NGROUPS -#define NGROUPS 32 -#endif -#ifndef NOGROUP #define NOGROUP (-1)#endif
===== include/asm-h8300/param.h 1.1 vs edited =====
include/asm-h8300/param.h +0 -4
@@ -14,10 +14,6 @@#define EXEC_PAGESIZE 4096 -#ifndef NGROUPS -#define NGROUPS 32 -#endif -#ifndef NOGROUP #define NOGROUP (-1)#endif
===== include/asm-i386/param.h 1.2 vs edited =====
include/asm-i386/param.h +0 -4
@@ -13,10 +13,6 @@#define EXEC_PAGESIZE 4096 -#ifndef NGROUPS -#define NGROUPS 32 -#endif -#ifndef NOGROUP #define NOGROUP (-1)#endif
===== include/asm-ia64/param.h 1.5 vs edited =====
include/asm-ia64/param.h +0 -4
@@ -12,10 +12,6 @@#define EXEC_PAGESIZE 65536 -#ifndef NGROUPS -# define NGROUPS 32 -#endif -#ifndef NOGROUP # define NOGROUP (-1)#endif
===== include/asm-m68k/param.h 1.2 vs edited =====
include/asm-m68k/param.h +0 -4
@@ -13,10 +13,6 @@#define EXEC_PAGESIZE 8192 -#ifndef NGROUPS -#define NGROUPS 32 -#endif -#ifndef NOGROUP #define NOGROUP (-1)#endif
===== include/asm-m68knommu/param.h 1.1 vs edited =====
include/asm-m68knommu/param.h +0 -4
@@ -44,10 +44,6 @@#define EXEC_PAGESIZE 4096 -#ifndef NGROUPS -#define NGROUPS 32 -#endif -#ifndef NOGROUP #define NOGROUP (-1)#endif
===== include/asm-mips/param.h 1.3 vs edited =====
include/asm-mips/param.h +0 -4
@@ -33,10 +33,6 @@#define EXEC_PAGESIZE 4096 -#ifndef NGROUPS -#define NGROUPS 32 -#endif -#ifndef NOGROUP #define NOGROUP (-1)#endif
===== include/asm-parisc/param.h 1.3 vs edited =====
include/asm-parisc/param.h +0 -4
@@ -18,10 +18,6 @@#define EXEC_PAGESIZE 4096 -#ifndef NGROUPS -#define NGROUPS 32 -#endif -#ifndef NOGROUP #define NOGROUP (-1)#endif
===== include/asm-ppc/param.h 1.6 vs edited =====
include/asm-ppc/param.h +0 -4
@@ -13,10 +13,6 @@#define EXEC_PAGESIZE 4096 -#ifndef NGROUPS -#define NGROUPS 32 -#endif -#ifndef NOGROUP #define NOGROUP (-1)#endif
===== include/asm-ppc64/param.h 1.2 vs edited =====
include/asm-ppc64/param.h +0 -4
@@ -20,10 +20,6 @@#define EXEC_PAGESIZE 4096 -#ifndef NGROUPS -#define NGROUPS 32 -#endif -#ifndef NOGROUP #define NOGROUP (-1)#endif
===== include/asm-s390/param.h 1.3 vs edited =====
include/asm-s390/param.h +0 -4
@@ -21,10 +21,6 @@#define EXEC_PAGESIZE 4096 -#ifndef NGROUPS -#define NGROUPS 32 -#endif -#ifndef NOGROUP #define NOGROUP (-1)#endif
===== include/asm-sh/param.h 1.2 vs edited =====
include/asm-sh/param.h +0 -4
@@ -17,10 +17,6 @@#define EXEC_PAGESIZE 4096 -#ifndef NGROUPS -#define NGROUPS 32 -#endif -#ifndef NOGROUP #define NOGROUP (-1)#endif
===== include/asm-sparc/param.h 1.2 vs edited =====
include/asm-sparc/param.h +0 -4
@@ -14,10 +14,6 @@#define EXEC_PAGESIZE 8192/* Thanks for sun4's we carry baggage... */ -#ifndef NGROUPS -#define NGROUPS 32 -#endif -#ifndef NOGROUP #define NOGROUP (-1)#endif
===== include/asm-sparc64/param.h 1.2 vs edited =====
include/asm-sparc64/param.h +0 -4
@@ -14,10 +14,6 @@#define EXEC_PAGESIZE 8192/* Thanks for sun4's we carry baggage... */ -#ifndef NGROUPS -#define NGROUPS 32 -#endif -#ifndef NOGROUP #define NOGROUP (-1)#endif
===== include/asm-um/param.h 1.1 vs edited =====
include/asm-um/param.h +0 -4
@@ -3,10 +3,6 @@#define EXEC_PAGESIZE 4096 -#ifndef NGROUPS -#define NGROUPS 32 -#endif -#ifndef NOGROUP #define NOGROUP (-1)#endif
===== include/asm-v850/param.h 1.1 vs edited =====
include/asm-v850/param.h +0 -4
@@ -18,10 +18,6 @@#define EXEC_PAGESIZE 4096 -#ifndef NGROUPS -#define NGROUPS 32 -#endif -#ifndef NOGROUP #define NOGROUP (-1)#endif
===== include/asm-x86_64/param.h 1.3 vs edited =====
include/asm-x86_64/param.h +0 -4
@@ -13,10 +13,6 @@#define EXEC_PAGESIZE 4096 -#ifndef NGROUPS -#define NGROUPS 32 -#endif -#ifndef NOGROUP #define NOGROUP (-1)#endif
Quoted 2 lines · Tim Hockin
What think?
I still don't understand the complexity.
Why the list of pages? Is there really any valid use for this that could overflow a simple "kmalloc()"? How many groups do people really really need?
I just find it wrong to go from 32 to millions. And a few thousand can trivially be handled by a normal "kmalloc()".
Basically, I find overdesign physically nauseating. This is less so than the original stuff, but I'm still finding myself asking "Why?".
Linus
In message <[email protected]> you write:
Quoted 11 lines · Tim Hockin
Quoted 2 lines
What think?
I still don't understand the complexity.
Why the list of pages? Is there really any valid use for this that could overflow a simple "
kmalloc()"? How many groups do people really really need?
I was happy with kmalloc, and no sorting. Simple patch. Tim complained that he had some wierd-ass users who hit kmalloc limits w/ fragmentation. I added about 10 lines of code to fall back to vmalloc for that very rare case, and you scotched that.
ie. Don't blame Tim: you led us here 8(
Rusty.
--
Anyone who quotes me in their sig is an idiot. -- Rusty Russell.
Hi,
anything new about this patch?
I'd like to see this problem solved too, also because of a samba, mad integration with the need of > 256 groups per user.
regards
Stefan
Signature · 6 lines
-------------------------------------------------------------------- Stefan Völkel [email protected] Millenux GmbH mobile: +49.170.79177.17 Lilienthalstraße 2 phone: +49.711.88770.300 70825 Stuttgart-Korntal fax: +49.711.88770.349 -= linux without limits -=- http://linux.zSeries.org/ =-
Quoted 6 lines · Stefan Voelkel
Hi,
anything new about this patch?
I'd like to see this problem solved too, also because of a samba, mad integration with the need of > 256 groups per user.
Has anyone else seen a limit of 16 groups with nss-ldap?
Quoted 13 lines · Rusty Russell
In message <[email protected]> you write:
Quoted 11 lines · Tim Hockin
Quoted 2 lines
What think?
I still don't understand the complexity.
Why the list of pages? Is there really any valid use for this that could overflow a simple "
kmalloc()"? How many groups do people really really need?
Quoted 8 lines
I was happy with kmalloc, and no sorting. Simple patch. Tim complained that he had some wierd-ass users who hit kmalloc limits w/ fragmentation. I added about 10 lines of code to fall back to vmalloc for that very rare case, and you scotched that.
ie. Don't blame Tim: you led us here 8(
Rusty.
So what was the conclusion? It would be nice to get this resolved and merged in finally..
-- Pasi Kärkkäinen
^
. .
Linux
/ - \
Choice.of.the
.Next.Generation.