In xdr_authunix_parms(), prevent accidental or malicious DoS by refusing
to receive a number of groups that is higher than 'ngroups_max' (maximum
number of supplementary groups) + 1 (accounting for the effective GID).
The 'cr_groups' field of 'struct xucred' can only contain up to
XU_NGROUPS including the effective GID. Just keep accepting more groups
than that, dropping the extra ones on the floor (as before).
For consistency, in the XDR_INLINE variant in _svcauth_unix(), make sure
to accept more groups than XU_NGROUPS (if less than the above-mentioned
limit).
xdr_authunix_parms() would try to fill up cr_groups[] with as many
groups as received with the only limit being 'ngroups_max' + 1, while by
default and in practice that limit is much greater than XU_NGROUPS which
represents the storage really allocated.
In the XDR_INLINE version, fix multiple OOB accesses possibilities when
answers are too short (in general, or with respect to their particular
content), which the previously existing check would reject too late to
prevent the OOB accesses.
As defense-in-depth, because 'cr_groups' is sized by XU_NGROUPS, check
for that limit instead of NGRPS. Fortunately, these constants are
currently equal so there was no practical harm. As NGRPS, which is
local, doesn't seem to serve any other purpose (like a protocol
limitation), just remove it.
While here, fix some style.
Fixes: dfdcada31e79 ("Add the new kernel-mode NFS Lock Manager.")
Sponsored by: The FreeBSD Foundation