[PATCH] Finish the task 'Embedd group table into struct ucred'
Mateusz Guzik
mjguzik at gmail.com
Tue Nov 4 10:01:37 UTC 2014
On Tue, Nov 04, 2014 at 05:51:26PM +0800, Tiwei Bie wrote:
> diff --git a/sys/kern/kern_prot.c b/sys/kern/kern_prot.c
> index 9b2bcd8..76d2cfc 100644
> --- a/sys/kern/kern_prot.c
> +++ b/sys/kern/kern_prot.c
> @@ -1864,7 +1864,8 @@ crfree(struct ucred *cr)
> #ifdef MAC
> mac_cred_destroy(cr);
> #endif
> - free(cr->cr_groups, M_CRED);
> + if (cr->cr_groups != cr->cr_smallgroups)
> + free(cr->cr_groups, M_CRED);
> free(cr, M_CRED);
> }
> }
> @@ -1976,6 +1977,12 @@ crextend(struct ucred *cr, int n)
> if (n <= cr->cr_agroups)
> return;
>
> + if (n <= XU_NGROUPS) {
> + cr->cr_groups = cr->cr_smallgroups;
> + cr->cr_agroups = XU_NGROUPS;
> + return;
> + }
> +
This should be initialized in crget, which should no longer call this
function.
> /*
> * We extend by 2 each time since we're using a power of two
> * allocator until we need enough groups to fill a page.
> @@ -1997,7 +2004,7 @@ crextend(struct ucred *cr, int n)
> cnt = roundup2(n, PAGE_SIZE / sizeof(gid_t));
>
> /* Free the old array. */
> - if (cr->cr_groups)
> + if (cr->cr_groups && cr->cr_groups != cr->cr_smallgroups)
> free(cr->cr_groups, M_CRED);
It is no longer possible for cr_groups to be NULL.
>
> cr->cr_groups = malloc(cnt * sizeof(gid_t), M_CRED, M_WAITOK | M_ZERO);
> diff --git a/sys/sys/ucred.h b/sys/sys/ucred.h
> index 81e4520..a6531c4 100644
> --- a/sys/sys/ucred.h
> +++ b/sys/sys/ucred.h
> @@ -37,6 +37,8 @@
>
> struct loginclass;
>
> +#define XU_NGROUPS 16
> +
> /*
> * Credentials.
> *
> @@ -64,13 +66,12 @@ struct ucred {
> struct auditinfo_addr cr_audit; /* Audit properties. */
> gid_t *cr_groups; /* groups */
> int cr_agroups; /* Available groups */
> + gid_t cr_smallgroups[XU_NGROUPS]; /* storage for small groups */
> };
> #define NOCRED ((struct ucred *)0) /* no credential available */
> #define FSCRED ((struct ucred *)-1) /* filesystem credential */
> #endif /* _KERNEL || _WANT_UCRED */
>
> -#define XU_NGROUPS 16
> -
> /*
> * Flags for cr_flags.
> */
> --
> 2.1.0
>
> [1] https://wiki.freebsd.org/JuniorJobs#Embedd_group_table_into_struct_ucred
>
> Tiwei Bie
>
--
Mateusz Guzik <mjguzik gmail.com>
More information about the freebsd-hackers
mailing list