HomeFreeBSD

setcred(): Remove an optimization for when cr_groups[0] was the egid

Description

setcred(): Remove an optimization for when cr_groups[0] was the egid

Because setcred() has (always) treated the effective GID separately from
the supplementary groups, when cr_groups[0] was storing the effective
GID, it internally needed to build an array containing both the
effective GID and the specified supplementary groups to eventually call
crsetgroups_internal().

As kern_setcred() was only used to actually implement
user_setcred()/sys_setcred(), which need to allocate a buffer to copy in
the userland groups array into, some optimization was put in place where
these would allocate an array with one more element than
'wc_supp_groups', copyin() the latter into the subarray starting at
index 1 and pass the pointer to the whole array to kern_setcred() in
'preallocated_groups'. This would allow kern_setcred() not to have to
allocate memory again to make room for the additional effective GID.

Since commit be1f7435ef21 ("kern: start tracking cr_gid outside of
cr_groups[]"), crsetgroups_internal() only takes supplementary groups,
so this machinery has become obsolete. It was not removed as part of
that commit, but just minimally amended to simplify the changes and
lower the risks. Finally remove it.

Reviewed by: kevans
MFC after: 2 weeks
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D53772

Details

Provenance
olceAuthored on Fri, Nov 14, 6:22 PM
Reviewer
kevans
Differential Revision
D53772: setcred(): Remove an optimization for when cr_groups[0] was the egid
Parents
rGb92b1b475830: mdo(1): Avoid calling getgroups() in some unnecessary cases
Branches
Unknown
Tags
Unknown