HomeFreeBSD

cred: 'kern.ngroups' tunable: Limit it to avoid internal overflows

Description

cred: 'kern.ngroups' tunable: Limit it to avoid internal overflows

As the comment introduced with the tunable said (but the code didn't
do), make sure that 'ngroups_max' can't be INT_MAX, as this would cause
overflow in the usual 'ngroups_max + 1' computations (as we store the
effective GID and supplementary groups' IDs in the same array, and
'ngroups_max' only applies to supplementary groups).

Further, we limit the maximum number of groups somewhat arbitrarily to
~17M so as to avoid overflow when computing the size in bytes of the
groups set's backing array and to avoid obvious configuration errors.
We really don't think that more than ~17M groups will ever be needed (if
I'm proven wrong one day, please drop me a note about your use case).

While here, document more precisely why NGROUPS_MAX needs to be the
minimum value for 'ngroups_max'.

Reviewed by: mhorne (older version)
Approved by: markj (mentor)
MFC after: 3 days
Differential Revision: https://reviews.freebsd.org/D46913

Details

Provenance
olceAuthored on Oct 1 2024, 5:00 PM
Reviewer
mhorne
Differential Revision
D46913: cred: 'kern.ngroups' tunable: Limit it to avoid internal overflows
Parents
rGabd39811cd7e: cred: kern_setgroups(): Internally use int as number of groups' type
Branches
Unknown
Tags
Unknown