Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 4 Nov 2014 11:01:30 +0100
From:      Mateusz Guzik <mjguzik@gmail.com>
To:        Tiwei Bie <btw@mail.ustc.edu.cn>
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: [PATCH] Finish the task 'Embedd group table into struct ucred'
Message-ID:  <20141104100130.GC4032@dft-labs.eu>
In-Reply-To: <1415094686-39302-1-git-send-email-btw@mail.ustc.edu.cn>
References:  <1415094686-39302-1-git-send-email-btw@mail.ustc.edu.cn>

next in thread | previous in thread | raw e-mail | index | archive | help
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>



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20141104100130.GC4032>