Page MenuHomeFreeBSD

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

Authored by olce on Oct 4 2024, 8:07 AM.
Tags
None
Referenced Files
Unknown Object (File)
Sat, Nov 2, 10:34 PM
Unknown Object (File)
Mon, Oct 28, 8:38 PM
Unknown Object (File)
Fri, Oct 25, 9:00 PM
Unknown Object (File)
Wed, Oct 9, 3:00 PM
Unknown Object (File)
Oct 5 2024, 4:35 PM
Subscribers

Details

Summary

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'.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 60262
Build 57146: arc lint + arc unit

Event Timeline

olce requested review of this revision.Oct 4 2024, 8:07 AM

You are too kind to the foot-shooters ;)

This revision is now accepted and ready to land.Mon, Oct 28, 5:33 PM

You are too kind to the foot-shooters ;)

Yeah, I don't expect anyone to ever use a value close to INT_MAX, which in any case would probably cause memory problems in some places (e.g., NFS). But it didn't cost much to add that extra if.

The real value of this commit, IMO, is the existing comment's expansion about why ngroups_max cannot be smaller than NGROUPS_MAX with a reference to the standard.

olce retitled this revision from cred: 'kern.ngroups' tunable: Avoid total number of groups overflow to cred: 'kern.ngroups' tunable: Limit it to avoid internal overflows.
olce edited the summary of this revision. (Show Details)

Be stricter for the maximal value of kern.ngroups (see the updated commit message and inline comments).

This revision now requires review to proceed.Wed, Oct 30, 5:49 PM
This revision was not accepted when it landed; it landed in state Needs Review.Sat, Nov 2, 8:39 PM
This revision was automatically updated to reflect the committed changes.