diff --git a/sys/kern/kern_prot.c b/sys/kern/kern_prot.c --- a/sys/kern/kern_prot.c +++ b/sys/kern/kern_prot.c @@ -811,7 +811,7 @@ int sys_setgroups(struct thread *td, struct setgroups_args *uap) { - gid_t smallgroups[XU_NGROUPS]; + gid_t smallgroups[CRED_SMALLGROUPS_NB]; gid_t *groups; int gidsetsize, error; @@ -819,7 +819,7 @@ if (gidsetsize > ngroups_max + 1 || gidsetsize < 0) return (EINVAL); - if (gidsetsize > XU_NGROUPS) + if (gidsetsize > CRED_SMALLGROUPS_NB) groups = malloc(gidsetsize * sizeof(gid_t), M_TEMP, M_WAITOK); else groups = smallgroups; @@ -828,7 +828,7 @@ if (error == 0) error = kern_setgroups(td, gidsetsize, groups); - if (gidsetsize > XU_NGROUPS) + if (gidsetsize > CRED_SMALLGROUPS_NB) free(groups, M_TEMP); return (error); } diff --git a/sys/sys/ucred.h b/sys/sys/ucred.h --- a/sys/sys/ucred.h +++ b/sys/sys/ucred.h @@ -42,6 +42,14 @@ #define XU_NGROUPS 16 +#if defined(_KERNEL) || defined(_WANT_UCRED) +/* + * Number of groups inlined in 'struct ucred'. It must stay reasonably low as + * it is also used by some functions to allocate an array of this size on the + * stack. + */ +#define CRED_SMALLGROUPS_NB 16 + /* * Credentials. * @@ -55,7 +63,6 @@ * * See "Credential management" comment in kern_prot.c for more information. */ -#if defined(_KERNEL) || defined(_WANT_UCRED) struct ucred { struct mtx cr_mtx; long cr_ref; /* (c) reference count */ @@ -78,7 +85,8 @@ struct label *cr_label; /* MAC label */ gid_t *cr_groups; /* groups */ int cr_agroups; /* Available groups */ - gid_t cr_smallgroups[XU_NGROUPS]; /* storage for small groups */ + /* storage for small groups */ + gid_t cr_smallgroups[CRED_SMALLGROUPS_NB]; }; #define NOCRED ((struct ucred *)0) /* no credential available */ #define FSCRED ((struct ucred *)-1) /* filesystem credential */