Page MenuHomeFreeBSD

fix mountd.c so that it does not allocate 4K for credential groups unless a large groups list is needed

Authored by rmacklem on Sep 22 2020, 2:25 AM.



r362163 upgraded mountd so that it could handle MAX_NGROUPS
groups for the anonymous user credentials (the ones provided by
-maproot and -mapall exports options).
The problem is that this resulted in every export structure growing by
about 4Kbytes, because the cr_groups field went from 16->MAX_NGROUPS.

This patch fixes this by only including a small 32 element cr_groups in the
structure and then malloc()'ng cr_groups when a larger one is needed.
The value of SMALLNGROUPS is arbitrarily set to 32, assuming most users
used by -maproot or -mapall will be in <= 32 groups.

Test Plan

Tested by doing an export entry with -maproot=ricktst,
when ricktst was in > SMALLNGROUPS groups.
For the test, syslog() calls were added to ensure the
malloc()s and free()s of the large cr_groups list
happened at the correct times.

Diff Detail

rS FreeBSD src repository
Automatic diff as part of commit; lint not applicable.
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

kib added inline comments.
1831 ↗(On Diff #77339)

I find a test like anon.cr_groups != anon.cr_smallgrps more clean, instead of relying on the size comparision.

This revision is now accepted and ready to land.Sep 22 2020, 5:27 PM
freqlabs added inline comments.
3483 ↗(On Diff #77339)

I take it this will not be in the committed version?

3528 ↗(On Diff #77339)

How about using memcpy here, too?

Updated with changes as suggested by kib@ and freqlabs@.

This revision now requires review to proceed.Sun, Oct 4, 10:42 PM
This revision is now accepted and ready to land.Mon, Oct 5, 2:00 AM