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)
Tue, Oct 14, 10:48 AM
Unknown Object (File)
Tue, Oct 7, 9:31 AM
Unknown Object (File)
Tue, Oct 7, 4:19 AM
Unknown Object (File)
Mon, Oct 6, 8:05 AM
Unknown Object (File)
Sat, Sep 20, 6:21 PM
Unknown Object (File)
Sep 10 2025, 5:04 AM
Unknown Object (File)
Sep 8 2025, 1:26 PM
Unknown Object (File)
Aug 20 2025, 5:54 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