aboutsummaryrefslogtreecommitdiff
path: root/usr.sbin/mountd
Commit message (Collapse)AuthorAgeFilesLines
* Update man page for new TLS export options.Rick Macklem2020-11-201-4/+58
| | | | | | | | | | | | | | NFS over TLS uses three new export options, added by r364979. This patch updates the exports.5 man page for these new options. Once assigned by IETF, "NNNN" will be replaced with the RFC number. This is a content change. Reviewed by: gbe Differential Revision: https://review.freebsd.org/D26241 Notes: svn path=/head/; revision=367912
* Update man page for -R option added by r376026.Rick Macklem2020-10-241-2/+13
| | | | | | | | | | | This is a content change. Reviewed by: bcr MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D26746 Notes: svn path=/head/; revision=367027
* Add "-R" option to tell mountd to not register with rpcbind.Rick Macklem2020-10-241-141/+184
| | | | | | | | | | | | | | | | | | | | rpcbind is now considered a security risk for some sites. Since an NFSv4 only NFS server does not need rpcbind, it makes sense to have an option that implements this. This patch adds a "-R" option that disables the Mount protocol (not used by NFSv4) and does not register with rpcbind. Changes are required to /etc/rc.d/mountd and /etc/rc.d/nfsd. Those will be in a separate commit. Reviewed by: freqlabs, asomers MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D26746 Notes: svn path=/head/; revision=367026
* Modify mountd.c so that it does not always malloc 4K for the map credentials.Rick Macklem2020-10-101-16/+44
| | | | | | | | | | | | | | | | | | | 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. Reviewed by: kib, freqlabs Differential Revision: https://reviews.freebsd.org/D26521 Notes: svn path=/head/; revision=366595
* Fix a few mandoc issuesGordon Bergling2020-10-091-13/+17
| | | | | | | | | | | - no blank before trailing delimiter - whitespace at end of input line - sections out of conventional order - normalizing date format - AUTHORS section without An macro Notes: svn path=/head/; revision=366572
* Add support for the NFS over TLS exports to mountd.Rick Macklem2020-08-301-0/+7
| | | | | | | | | | | Three new export flags are added to mountd that will restrict exported file system mounts to use TLS. Without these flags, TLS is allowed, but not required. The exports(5) man page will be updated in a future commit. Notes: svn path=/head/; revision=364979
* Correct a type-mismatch between xdr_long and the variable "bad".Brooks Davis2020-07-221-1/+2
| | | | | | | | | | | | | | | | | Way back in r28911 (August 1997, CVS rev 1.22) we imported a NetBSD information leak fix via OpenBSD. Unfortunatly we failed to track the followup commit that fixed the type of the error code. Apply the change from int to long now. Reviewed by: emaste Found by: CHERI Obtained from: CheriBSD MFC after: 3 days Sponsored by: DARPA Differential Revision: https://reviews.freebsd.org/D25779 Notes: svn path=/head/; revision=363439
* Avoid reading one byte before the path buffer.Brooks Davis2020-07-221-2/+2
| | | | | | | | | | | | | | | | | | | This happens when there's only one component (e.g. "/foo"). This (mostly-harmless) bug has been present since June 1990 when it was commited to mountd.c SCCS version 5.9. Note: the bug is on the second changed line, the first line is changed for visual consistency. Reviewed by: cem, emaste, mckusick, rmacklem Found with: CHERI Obtained from: CheriBSD MFC after: 1 week Sponsored by: DARPA Differential Revision: https://reviews.freebsd.org/D25759 Notes: svn path=/head/; revision=363435
* Make use of the UID_NOBODY and GID_NOGROUP definitions in sys/conf.h.Rick Macklem2020-06-161-4/+5
| | | | | | | | | | | r362214 exposed UID_NOBODY and GID_NOGROUP to userspace, so use them instead of the numbers. Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D25281 Notes: svn path=/head/; revision=362215
* Modify mountd to use the new struct export_args committed by r362158.Rick Macklem2020-06-141-59/+79
| | | | | | | | | | | | | | | | | r362158 modified struct export_args for make the ex_flags field 64bits and also changed the anonymous credentials to allow more than 16 groups. This patch fixes mountd.c to use the new structure. It does allocate larger exportlist and grouplist structures now. That will be fixed in a future commit. The only visible change will be that the credentials provided for the -maproot and -mapall exports options can now have more than 16 groups. Reviewed by: kib, freqlabs Relnotes: yes Differential Revision: https://reviews.freebsd.org/D25088 Notes: svn path=/head/; revision=362163
* Fix a bug where XU_NGROUPS + 1 groups might be copied.Rick Macklem2020-06-091-0/+2
| | | | | | | | | | | | | | r361780 fixed the code so that it would only remove the duplicate when it actually existed. However, that might have resulted in XU_NGROUPS + 1 groups being copied, running off the end of the array. This patch fixes the problem. Spotted during code inspection for other mountd changes. MFC after: 2 weeks Notes: svn path=/head/; revision=361956
* Fix mountd so that it will not lose SIGHUPs that indicate "reload exports".Rick Macklem2020-06-061-6/+46
| | | | | | | | | | | | | | | | | | | | | | | Without this patch, if a SIGHUP is handled while the process is executing get_exportlist(), that SIGHUP is essentially ignored because the got_sighup variable is reset to 0 after get_exportlist(). This results in the exports file(s) not being reloaded until another SIGHUP signal is sent to mountd. This patch fixes this by resetting got_sighup to zero before the get_exportlist() call while SIGHUP is blocked. It also defines a delay time of 250msec before doing another exports reload if there are RPC request(s) to process. This prevents repeated exports reloads from delaying handling of RPC requests significantly. PR: 246597 Reported by: patrykkotlowski@gmail.com Tested by: patrykkotlowski@gmail.com Reviewed by: markj MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D25127 Notes: svn path=/head/; revision=361854
* Fix mountd to handle getgrouplist() not returning groups[0] == groups[1].Rick Macklem2020-06-041-3/+9
| | | | | | | | | | | | | | | | | | Prior to r174547, getgrouplist(3) always returned a groups list with element 0 and 1 set to the basegid argument, so long as ngroups was > 1. Post-r174547 this is not the case. r328304 disabled the deduplication that removed the duplicate, but the duplicate still does not occur unless the group for a user in the password database is also entered in the group database. This patch fixes mountd so that it handles the case where a user specified with the -maproot or -mapall exports option has a getgrouplist(3) groups list where groups[0] != groups[1]. Found while testing another mountd patch. MFC after: 2 weeks Notes: svn path=/head/; revision=361780
* Deduplicate fsid comparisonsRyan Moeller2020-05-211-10/+5
| | | | | | | | | | | | | | | | Comparing fsid_t objects requires internal knowledge of the fsid structure and yet this is duplicated across a number of places in the code. Simplify by creating a fsidcmp function (macro). Reviewed by: mjg, rmacklem Approved by: mav (mentor) MFC after: 1 week Sponsored by: iXsystems, Inc. Differential Revision: https://reviews.freebsd.org/D24749 Notes: svn path=/head/; revision=361313
* Add a reference to the NFSv3 RFC.Mark Johnston2019-08-081-2/+2
| | | | | | | | | PR: 239721 Submitted by: Gordon Bergling <gbergling@gmail.com> MFC after: 3 days Notes: svn path=/head/; revision=350780
* Fix strsep_quote() on strings without quotes.Alexander Motin2019-06-251-1/+1
| | | | | | | | | | | | | | | | For strings without quotes and escapes dstptr and srcptr are equal, so zeroing *dstptr before checking *srcptr is not a good idea. In practice it means that in -maproot=65534:65533 everything after the colon is lost. The problem was there since r293305, but before r346976 it was covered by improper strsep_quote() usage. PR: 238725 MFC after: 3 days Sponsored by: iXsystems, Inc. Notes: svn path=/head/; revision=349376
* r348590 had mention of "-I" in a comment that no longer applied to the patch.Rick Macklem2019-06-031-1/+1
| | | | | | | | | | Take "-I" out of the comment line, since the patch no longer uses the "-I" option. MFC after: 1 month Notes: svn path=/head/; revision=348591
* Modify mountd so that it incrementally updates the kernel exports upon a reload.Rick Macklem2019-06-032-70/+499
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Without this patch, mountd would delete/load all exports from the exports file(s) when it receives a SIGHUP. This works fine for small exports file(s), but can take several seconds to do when there are large numbers (10000+) of exported file systems. Most of this time is spent doing the system calls that delete/export each of these file systems. When the "-S" option has been specified (the default these days), the nfsd threads are suspended for several seconds while the reload is done. This patch changes mountd so that it only does system calls for file systems where the exports have been changed/added/deleted as compared to the exports done for the previous load/reload of the exports file(s). Basically, when SIGHUP is posted to mountd, it saves the exportlist structures from the previous load and creates a new set of structures from the current exports file(s). Then it compares the current with the previous and only does system calls for cases that have been changed/added/deleted. The nfsd threads do not need to be suspended until the comparison step is being done. This results in a suspension period of milliseconds for a server with 10000+ exported file systems. There is some code using a LOGDEBUG() macro that allow runtime debugging output via syslog(LOG_DEBUG,...) that can be enabled by creating a file called /var/log/mountd.debug. This code is expected to be replaced with code that uses dtrace by cy@ in the near future, once issues w.r.t. dtrace in stable/12 have been resolved. The patch should not change the usage of the exports file(s), but improves the performance of reloading large exports file(s) where there are only a small number of changes done to the file(s). Tested by: pen@lysator.liu.se PR: 237860 Reviewed by: kib MFC after: 1 month Relnotes: yes Differential Revision: https://reviews.freebsd.org/D20487 Notes: svn path=/head/; revision=348590
* Replace a single linked list with a hash table of lists.Rick Macklem2019-05-311-21/+49
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | mountd.c uses a single linked list of "struct exportlist" structures, where there is one of these for each exported file system on the NFS server. This list gets long if there are a large number of file systems exported and the list must be searched for each line in the exports file(s) when SIGHUP causes the exports file(s) to be reloaded. A simple benchmark that traverses SLIST() elements and compares two 32bit fields in the structure for equal (which is what the search is) appears to take a couple of nsec. So, for a server with 72000 exported file systems, this can take about 5sec during reload of the exports file(s). By replacing the single linked list with a hash table with a target of 10 elements per list, the time should be reduced to less than 1msec. Peter Errikson (who has a server with 72000+ exported file systems) ran a test program using 5 hashes to see how they worked. fnv_32_buf(fsid,..., 0) fnv_32_buf(fsid,..., FNV1_32_INIT) hash32_buf(fsid,..., 0) hash32_buf(fsid,..., HASHINIT) - plus simply using the low order bits of fsid.val[0]. The first three behaved about equally well, with the first one being slightly better than the others. It has an average variation of about 4.5% about the target list length and that is what this patch uses. Peter Errikson also tested this hash table version and found that the performance wasn't measurably improved by a larger hash table, so a load factor of 10 appears adequate. Tested by: pen@lysator.liu.se (with other patches) PR: 237860 MFC after: 1 month Notes: svn path=/head/; revision=348452
* Complete LOCAL_PEERCRED support. Cache pid of the remote process in theDmitry Chagin2019-05-301-1/+1
| | | | | | | | | | | | struct xucred. Do not bump XUCRED_VERSION as struct layout is not changed. PR: 215202 Reviewed by: tijl MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D20415 Notes: svn path=/head/; revision=348419
* Replace global list for grouplist with list(s) for each exportlist element.Rick Macklem2019-05-141-13/+10
| | | | | | | | | | | | | | | | | | | | | | | In mountd.c, the grouplist structures are linked into a single global linked list headed by "grphead". The only use of this linked list is to free all list elements when the exportlist elements are also all being free'd at the time the exports are being reloaded. This patch replaces this one global linked list head with a list head in each exportlist structure, where the grouplist elements for that exported file system are linked. The only change is that now the grouplist elements are free'd with the associated exportlist element as they are free'd instead of all grouplist elements being free'd after the exportlist elements are free'd. This change should have no effect in practice. This is being done, since a future patch that will add a "-I" option for incrementally updating the exports in the kernel needs to know which grouplist elements are associated with each exported file system and having them linked into a list headed by the exportlist element does that. MFC after: 1 month Notes: svn path=/head/; revision=347583
* Factor code into two new functions in preparation for a future commit.Rick Macklem2019-05-111-64/+84
| | | | | | | | | | | | | | | | | Factor code into two functions. read_exportfile() a functon which reads the exports file(s) and calls get_exportlist_one() to process each of them. delete_export() a function which deletes the exports in the kernel for a file system. The contents of these functions is just the same code as was used to do the operations, moved into separate functions. As such, there is no semantic change. This is being done in preparation for a future commit that will add an option to do incremental changes of kernel exports upon receiving SIGHUP. MFC after: 1 month Notes: svn path=/head/; revision=347498
* Factor out some exportlist list operations into separate functions.Rick Macklem2019-05-101-13/+38
| | | | | | | | | | | | | | | | | | | This patch moves the code that removes and frees all exportlist elements out into a separate function called free_exports(). It does the same for the insertion of a new exportlist entry into a list. It also adds a second argument to ex_search() for the list to use. None of these changes have any semantic effect. They are being done to prepare the code for future patches that convert the single linked list for the exportlist to a hash table of lists and a patch that will do incremental changes of exports in the kernel. And it fixes the argument for SLIST_HEAD_INITIALIZER() to be a pointer, which doesn't really matter, since SLIST_HEAD_INITIALIZER() doesn't use the argument. MFC after: 1 month Notes: svn path=/head/; revision=347476
* Respect quotes and escapes when splitting exports fields.Alexander Motin2019-04-301-11/+20
| | | | | | | | | | Without this r293305 was still unable to handle names with spaces. MFC after: 1 week Sponsored by: iXsystems, Inc. Notes: svn path=/head/; revision=346976
* Bump .Dd for today's edit.Martin Cracauer2019-02-111-1/+1
| | | | | | | Thank you Enji Cooper Notes: svn path=/head/; revision=344015
* Clarify NFSv4 /etc/exports semantics, with working example.Martin Cracauer2019-02-111-0/+34
| | | | | | | The existing wording has been confusing users for years. Notes: svn path=/head/; revision=344013
* Reduce number of DNS queries in mountd.Sean Eric Fagan2018-12-061-2/+7
| | | | | | | | | | | | | | | | As reported by a FreeNAS user (see https://redmine.ixsystems.com/issues/55728), mountd does more calls to getnameinfo() than it needs to; this changes it to only call it for the RPC calls it needs the name information for. Reported by: Dave Flowers Reviewed by: imp, mav Approved by: mav (mentor) MFC after: 2 weeks Sponsored by: iXsystems Inc Differential Revision: https://reviews.freebsd.org/D18430 Notes: svn path=/head/; revision=341641
* mountd has no way to configure the listen queue depth; rather than add a newSean Eric Fagan2018-11-141-1/+5
| | | | | | | | | | | | option, we pass -1 down to listen, which causes it to use the kern.ipc.soacceptqueue sysctl. Approved by: mav MFC after: 2 weeks Sponsored by: iXsystems Inc Notes: svn path=/head/; revision=340442
* mountd: fix a crash when getgrouplist reports too many groupsAndriy Gapon2018-04-161-1/+4
| | | | | | | | | | | | | Previously the code only warned about the condition and then happily proceeded to use the too large value resulting in the array out-of-bounds access. Obtained from: Panzura (Chuanbo Zheng) MFC after: 10 days Sponsored by: Panzura Notes: svn path=/head/; revision=332559
* mountd: Return proper errno values in a few error pathsRavi Pokala2018-02-211-4/+16
| | | | | | | | | | | | | | | | When attempting to mount a non-directory which exists, return ENOTDIR instead of ENOENT. If stat() or statfs() failed, don't pass part of the invalid (struct statfs) to ex_search(). In that same case, preserve the value of "bad" rather than overwriting with EACCES. Submitted by: Bruce Leverett (Panasas) Reviewed by: rmacklem MFC after: 1 week Sponsored by: Panasas Differential Revision: https://reviews.freebsd.org/D14438 Notes: svn path=/head/; revision=329682
* mountd(8): Produce vaguely meaningful error messagesConrad Meyer2018-02-081-24/+28
| | | | | | | Sponsored by: Dell EMC Isilon Notes: svn path=/head/; revision=329009
* General further adoption of SPDX licensing ID tags.Pedro F. Giffuni2017-11-202-2/+6
| | | | | | | | | | | | | | | | | Mainly focus on files that use BSD 3-Clause license. The Software Package Data Exchange (SPDX) group provides a specification to make it easier for automated tools to detect and summarize well known opensource licenses. We are gradually adopting the specification, noting that the tags are considered only advisory and do not, in any way, superceed or replace the license texts. Special thanks to Wind River for providing access to "The Duke of Highlander" tool: an older (2014) run over FreeBSD tree was useful as a starting point. Notes: svn path=/head/; revision=326025
* DIRDEPS_BUILD: Update dependencies.Bryan Drewery2017-10-311-1/+0
| | | | | | | Sponsored by: Dell EMC Isilon Notes: svn path=/head/; revision=325188
* mountd: Convert mountlist to SLISTEmmanuel Vadot2017-10-041-33/+16
| | | | | | | | | | | | Use SLIST from sys/queue.h instead of homebrew linked list for mountlist. Reviewed by: bapt, rmacklem MFC after: 1 week Sponsored by: Gandi.net Differential Revision: https://reviews.freebsd.org/D12504 Notes: svn path=/head/; revision=324258
* mountd: Convert exportlist to SLISTEmmanuel Vadot2017-10-041-29/+13
| | | | | | | | | | | | Use SLIST from sys/queue.h instead of homebrew linked list for the exportlist. Reviewed by: bapt, rmacklem MFC after: 1 week Sponsored by: Gandi.net Differential Revision: https://reviews.freebsd.org/D12502 Notes: svn path=/head/; revision=324257
* mountd: Avoid memory leak by freeing dp_dirpEmmanuel Vadot2017-09-261-1/+2
| | | | | | | | | | | | Introduced in r324007, the data alloced by strdup was never free'ed. While here, remove cast to caddr_t when freeing dp. Reported by: bde MFC after: 1 week X MFC With: r324007 Notes: svn path=/head/; revision=324014
* mountd: Remove unneeded castEmmanuel Vadot2017-09-261-1/+1
| | | | | | | | | Reported by: kib MFC after: 1 week X MFC With: r324007 Notes: svn path=/head/; revision=324012
* mountd: Replace malloc+strcpy to strdupEmmanuel Vadot2017-09-261-9/+7
| | | | | | | | | | Reviewed by: bapt MFC after: 1 week Sponsored by: Gandi.net Differential Revision: https://reviews.freebsd.org/D12503 Notes: svn path=/head/; revision=324007
* Update the exports.5 man page to reflect the change in default uid/gidRick Macklem2017-05-201-3/+3
| | | | | | | | | made by r318262. This is a content change. Notes: svn path=/head/; revision=318589
* Change the default uid/gid values for nobody/nogroup to 65534/65533.Rick Macklem2017-05-141-4/+4
| | | | | | | | | | | | | | | | | The default values found in /etc/passwd and /etc/group are 65534, 65533. In mountd.c, the defaults were -2, which was 65534 back when uid_t was 16bits. Without this patch, a file created by root on an NFS exported volume without the "-root=" export option will end up owned by uid 4**32 - 2. When discussed on freebsd-current@, it seemed that users preferred the values being changed to 65534/65533. I have not added code to acquire these values from the databases, since the mountd daemon might get "stuck" during startup waiting for a non-responsive password database server. Discussed on: freebsd-current Notes: svn path=/head/; revision=318262
* usr.sbin: normalize paths using SRCTOP-relative paths or :H when possibleEnji Cooper2017-03-041-1/+1
| | | | | | | | | | This simplifies make logic/output MFC after: 1 month Sponsored by: Dell EMC Isilon Notes: svn path=/head/; revision=314659
* Renumber copyright clause 4Warner Losh2017-02-285-5/+5
| | | | | | | | | | | | Renumber cluase 4 to 3, per what everybody else did when BSD granted them permission to remove clause 3. My insistance on keeping the same numbering for legal reasons is too pedantic, so give up on that point. Submitted by: Jan Schaumann <jschauma@stevens.edu> Pull Request: https://github.com/freebsd/freebsd/pull/96 Notes: svn path=/head/; revision=314436
* Fix the man page to reflect the change done by r307890 to mountd.cRick Macklem2016-10-251-2/+2
| | | | | | | | | | | | so that the "-n" option uses the sysctl for the new NFS server. This is a content change. PR: 213450 Submitted by: rs@bytecamp.net MFC after: 2 weeks Notes: svn path=/head/; revision=307891
* mountd(8) was erroneously setting the sysctl for the old NFS serverRick Macklem2016-10-251-1/+1
| | | | | | | | | | | | | | | | | | when the new/default NFS server was running, for the "-n" option. This patch fixes the problem for head and stable/11. For stable/10 the patch will need to be modified when MFC'd, since the stable/10 mountd.c handles both old and new NFS servers. Since the new NFS server uses vfs.nfsd.nfs_privport == 0 by default, there wouldn't have been many users affected by the code not setting it to 0 when the "-n" option was specified. PR: 213450 Submitted by: rs@bytecamp.net MFC after: 2 weeks Notes: svn path=/head/; revision=307890
* Use MIN macro from sys/param.h.Marcelo Araujo2016-05-021-1/+1
| | | | | | | MFC after: 2 weeks. Notes: svn path=/head/; revision=298912
* Cleanup unnecessary semicolons from utilities we all love.Pedro F. Giffuni2016-04-151-3/+3
| | | | Notes: svn path=/head/; revision=298089
* Allow /etc/exports to contain usernames/groups with spaces in them.Josh Paetzel2016-01-072-1/+72
| | | | | | | | | | | | | | If you are getting your users/groups from a directory service such as LDAP or AD it's possible for those usernames or groupnames to contain spaces. Submitted by: Sean E. Fagan Reviewed by: rmacklem MFC after: 1 week Sponsored by: iXsystems Notes: svn path=/head/; revision=293305
* Fix type mismatches for malloc(3) and Co.Ulrich Spörlein2015-12-291-1/+1
| | | | | | | | | | | | This is rather pedantic, as for most architectures it holds that sizeof(type *) == sizeof(type **) Found by: clang static analyzer Reviewed by: ed Differential Revision: https://reviews.freebsd.org/D4722 Notes: svn path=/head/; revision=292864
* Staticize some stuff in mountd(8); no functional changes.Edward Tomasz Napierala2015-07-041-126/+128
| | | | | | | | MFC after: 1 month Sponsored by: The FreeBSD Foundation Notes: svn path=/head/; revision=285128
* Add META_MODE support.Simon J. Gerraty2015-06-131-0/+22
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | Off by default, build behaves normally. WITH_META_MODE we get auto objdir creation, the ability to start build from anywhere in the tree. Still need to add real targets under targets/ to build packages. Differential Revision: D2796 Reviewed by: brooks imp Notes: svn path=/head/; revision=284345