Page MenuHomeFreeBSD

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

Authored by rmacklem on Sep 22 2020, 2:25 AM.
Tags
None
Referenced Files
Unknown Object (File)
Fri, Apr 12, 2:35 AM
Unknown Object (File)
Thu, Apr 11, 5:48 PM
Unknown Object (File)
Thu, Apr 11, 9:15 AM
Unknown Object (File)
Fri, Mar 29, 4:51 AM
Unknown Object (File)
Fri, Mar 29, 12:39 AM
Unknown Object (File)
Fri, Mar 22, 9:14 PM
Unknown Object (File)
Fri, Mar 22, 9:13 PM
Unknown Object (File)
Fri, Mar 22, 9:13 PM
Subscribers

Details

Summary

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

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

kib added inline comments.
usr.sbin/mountd/mountd.c
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.
usr.sbin/mountd/mountd.c
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.Oct 4 2020, 10:42 PM
This revision is now accepted and ready to land.Oct 5 2020, 2:00 AM