Subject: Re: crcmp(), once again
To: None <tech-kern@NetBSD.org, fvdl@NetBSD.org>
From: Roland Illig <rillig@NetBSD.org>
List: tech-kern
Date: 11/18/2005 08:38:39
Tom Spindler wrote:
>>	I spent a minute or two reading that code when I found when crcmp()
>>is used, and decided I didn't have the time to actually understand
>>what it is doing and WHY it checks if one credential is the same as
>>some other one, or WHERE those credentials come from.
> 
> 
> The relevant change shows up in 1.195 of src/sys/kern/vfs_subr.c:
> 
> from the commit message:
> 
> date: 2003/05/16 14:01:56;  author: christos;  state: Exp;  lines: +74 -27
> Fix a variety of kernel panics related to unchecked export data:
> [...]
> 3. we only know about inet4 and inet6, so make sure that the corresponding
>    data is valid before using it.
> 
> and the code itself:
> 
> +check:
>                 if (enp->netc_exflags != argp->ex_flags ||
> -                   enp->netc_anon.cr_uid != argp->ex_anon.cr_uid ||
> -                   enp->netc_anon.cr_gid != argp->ex_anon.cr_gid ||
> -                   enp->netc_anon.cr_ngroups !=
> -                                       (uint32_t) argp->ex_anon.cr_ngroups ||
> -                   memcmp(&enp->netc_anon.cr_groups, &argp->ex_anon.cr_groups,
> -                       enp->netc_anon.cr_ngroups))
> +           crcmp(&enp->netc_anon, &argp->ex_anon) != 0)

This is when crcmp() was born. The code itself has been buggy since 1997:

----
RCS file: /cvsroot/src/sys/kern/vfs_subr.c,v
revision 1.72
date: 1997/07/20 23:31:32;  author: fvdl;
Allow multiple export requests for a filesystem, host pair if the flags 
and anon cred are the same. Should probably be handled better in the 
mountd, but this will do for now. Fixes PR 469, submitted Sept 1994 by
a certain "Jason R. Thorpe".. ;-)
----

Maybe that code should have gotten some documentation back it 1997?

Roland