Module Name: src Committed By: martin Date: Sat Aug 24 16:21:11 UTC 2024
Modified Files: src/sbin/fsirand [netbsd-9]: fsirand.8 src/usr.sbin/mountd [netbsd-9]: exports.5 mountd.8 Log Message: Pull up following revision(s) (requested by riastradh in ticket #1882): usr.sbin/mountd/exports.5: revision 1.33 usr.sbin/mountd/exports.5: revision 1.34 sbin/fsirand/fsirand.8: revision 1.11 usr.sbin/mountd/exports.5: revision 1.35 usr.sbin/mountd/exports.5: revision 1.36 usr.sbin/mountd/mountd.8: revision 1.43 usr.sbin/mountd/exports.5: revision 1.37 usr.sbin/mountd/exports.5: revision 1.38 exports(5), mountd(8): First pass at clarifying export semantics. The exports(5) man page is full of walls of turgid prose that should be itemized lists with syntax templates, and I'm itching to rewrite it, but let's get the security-relevant warnings out of the way first. PR misc/58063 exports(5): Revert warning about `-ro' on read/write file systems. Looks like the nfs server does enforce that after all, in spite of the rather oblique commentary in the BUGS section about export options being tied to local mount point options with which they must be noncontradictory. And there's no reason in principle it shouldn't enforce this -- it just need to block various file system _operations_, rather than the subtree issue where the criteria for evaluating whether operations are allowed on particular _file handles_ are too painful to contemplate. PR misc/58063 exports(5): Substantially rewrite for clarity. Hope this is an improvement over the turgid paragraphs all about first/second/third cases of everything. PR misc/58063 exports(5): improve mark up fsirand(8): Fix security claims. PR misc/58063 pick some nits exports(5): Tiny punctuation fix in man page. To generate a diff of this commit: cvs rdiff -u -r1.10 -r1.10.16.1 src/sbin/fsirand/fsirand.8 cvs rdiff -u -r1.32 -r1.32.30.1 src/usr.sbin/mountd/exports.5 cvs rdiff -u -r1.38 -r1.38.16.1 src/usr.sbin/mountd/mountd.8 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sbin/fsirand/fsirand.8 diff -u src/sbin/fsirand/fsirand.8:1.10 src/sbin/fsirand/fsirand.8:1.10.16.1 --- src/sbin/fsirand/fsirand.8:1.10 Sun Sep 11 21:22:18 2016 +++ src/sbin/fsirand/fsirand.8 Sat Aug 24 16:21:11 2024 @@ -1,4 +1,4 @@ -.\" $NetBSD: fsirand.8,v 1.10 2016/09/11 21:22:18 sevan Exp $ +.\" $NetBSD: fsirand.8,v 1.10.16.1 2024/08/24 16:21:11 martin Exp $ .\" .\" Copyright (c) 1997 The NetBSD Foundation, Inc. .\" All rights reserved. @@ -43,8 +43,17 @@ .Nm writes random inode generation numbers for all the inodes on device .Ar special . -These random numbers make the NFS filehandles less predictable, increasing -security of exported filesystems. +These random numbers make the NFS filehandles less predictable, which +was once thought to increase security of exported file systems. +.Pp +.Nm +is no longer relevant because +.Xr newfs 8 +has randomized inode generation numbers on all new file systems since +.Nx 2.0 , +and in any case, exporting a file system to NFS clients allows them to +traverse the entire file system, so making filehandles less predictable +does not prevent clients from finding them anyway. .Pp .Nm should be run on a clean and unmounted filesystem. Index: src/usr.sbin/mountd/exports.5 diff -u src/usr.sbin/mountd/exports.5:1.32 src/usr.sbin/mountd/exports.5:1.32.30.1 --- src/usr.sbin/mountd/exports.5:1.32 Thu Mar 28 22:54:25 2013 +++ src/usr.sbin/mountd/exports.5 Sat Aug 24 16:21:10 2024 @@ -1,4 +1,4 @@ -.\" $NetBSD: exports.5,v 1.32 2013/03/28 22:54:25 njoly Exp $ +.\" $NetBSD: exports.5,v 1.32.30.1 2024/08/24 16:21:10 martin Exp $ .\" .\" Copyright (c) 1989, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,118 +29,159 @@ .\" .\" @(#)exports.5 8.3 (Berkeley) 3/29/95 .\" -.Dd October 8, 2006 +.Dd March 27, 2024 .Dt EXPORTS 5 .Os .Sh NAME .Nm exports -.Nd define remote mount points for +.Nd exported filesystem mount points for .Tn NFS mount requests -.Sh SYNOPSIS -.Nm exports .Sh DESCRIPTION The -.Nm exports -file specifies remote mount points for the +.Nm +file on an .Tn NFS -mount protocol per the +server lists filesystems to be exported to .Tn NFS -server specification; see -.%T "Network File System Protocol Specification RFC 1094, Appendix A" -and -.%T "NFS: Network File System Version 3 Specification, Appendix I" . +clients. +It is read and applied by +.Xr mountd 8 +on start and on +.Dv SIGHUP . +.Pp +Each entry in +.Nm +is a line with a list of directories followed by a list of hosts, +netgroups, and options, separated by spaces or tabs: +.Pp +.D1 Li / Ns Ar dir Li ... Oo Ar host | Ar netgroup | Fl Ar option Oc Li ... +.Pp +All directories in a single line must live in the same filesystem, +which is exported to the hosts and netgroups listed, according to the +options specified. +Exported directories must not have pathname components that are +symbolic links, +.Ql \&. , +or +.Ql \&.. . .Pp -Each line in the file -(other than comment lines that begin with a -.Sq # ) -specifies the mount point(s) and export flags within one local server -filesystem for one or more hosts. -A host may be specified only once for each local filesystem on the -server and there may be only one default entry for each server -filesystem that applies to all other hosts. -The latter exports the filesystem to the -.Dq world -and should -be used only when the filesystem contains public information. +.Bf -symbolic +Warning: +Exporting a directory exposes the +.Em entire +contents of the filesystem that the directory lives in to +.Tn NFS +clients. +.Ef +This happens even if an exported directory is not the root directory of +a filesystem on the server. +.Tn NFS +clients are only prevented from access to files and directories on +filesystems that are +.Em not +exported at all. .Pp -If you have modified the -.Pa /etc/exports -file, send the mountd a SIGHUP to make it re-read the -.Pa /etc/exports -file: -.Dq kill -HUP `cat /var/run/mountd.pid` . +.Bf -symbolic +Warning: +Access control is only by network address. +.Ef +.Tn NFS +servers with any non-public data should be exposed only to restricted +or firewalled networks with ingress filtering. +There is no authentication or encryption to make it safe for +restricting access on the open internet. +.Pp +Blank lines are ignored. +Text beginning with +.Ql # +until the end of line is ignored as a comment. +Each line ending with +.Ql \e +has the next line appended, without the +.Ql \e , +as a continuation line. +Characters can be escaped with +.Ql \e . +.Pp +All directories, which begin with +.Ql / , +must come before any hosts, netgroups, or options on a line. +Options begin with +.Ql - . +All other items on an export line are interpreted either as netgroups +.Po see +.Xr netgroup 5 +.Pc +or as hosts, which can be either names, as in example.com, or numbers, +as in 192.0.2.123 or 2001:db8:1234:abcd::42. +Sets of hosts in a contiguous network range can be specified with the +.Fl network +option. .Pp -In a mount entry, -the first field(s) specify the directory path(s) within a server filesystem -that can be mounted on by the corresponding client(s). -There are two forms of this specification. -The first is to list all mount points as absolute -directory paths separated by whitespace. -The second is to specify the pathname of the root of the filesystem -followed by the -.Fl alldirs -flag; -this form allows the host(s) to mount at any point within the filesystem, +The same filesystem may be exported on multiple lines with different +options to different sets of hosts, as long as it is exported at most +once to each host, netgroup, or network. +.Pp +Export lines with no hosts, netgroups, or +.Fl network +options are exported to +.Em any +hosts on the network, with no access control. +.Pp +Supported export options: +.Bl -tag -width Fl +.It Fl alldirs +Allow mount requests from clients at any point within the filesystem, including regular files. -Note that the +Only the root directory of the filesystem should be specified on the +line. +.Pp +Note that omitting the .Fl alldirs option should not be used as a security measure to make clients mount only those subdirectories that they should have access to. A client can still access the whole filesystem via individual RPCs if it wanted to, even if just one subdirectory has been mounted. -The pathnames must not have any symbolic links in them and should not have -any -.Dq \&. -or -.Dq .. -components. -Mount points for a filesystem may appear on multiple lines each with -different sets of hosts and export options. -.Pp -The second component of a line specifies how the filesystem is to be -exported to the host set. -The option flags specify whether the filesystem -is exported read-only or read-write and how the client uid is mapped to -user credentials on the server. -.Pp -Export options are specified as follows: -.Pp .Sm off -.Fl maproot No = Ar user +.It Fl maproot Li = Ar user .Sm on The credential of the specified user is used for remote access by root. The credential includes all the groups to which the user is a member -on the local machine (see -.Xr id 1 ) . +on the local machine +.Po see +.Xr id 1 +.Pc . The user may be specified by name or number. -.Pp .Sm off -.Fl maproot No = Ar user : group1 : group2 : ... +.It Fl maproot Li = Ar user\^ Li \&: Ar group1\^ Li \&: group2\^ Li \&: Ar ... .Sm on The colon separated list is used to specify the precise credential to be used for remote access by root. The elements of the list may be either names or numbers. -Note that user: should be used to distinguish a credential containing -no groups from a complete credential for that user. -.Pp -.Sm off -.Fl mapall No = Ar user -.Sm on -or +Note that +.Sq Ar user\^ Ns Li \&: +(with the trailing colon) +should be used to distinguish a credential containing no groups from a +complete credential for that user. .Sm off -.Fl mapall No = Ar user : group1 : group2 : ... +.It Fl mapall Li = Ar user +.It Fl mapall Li = Ar user\^ Li \&: Ar group1\^ Li \&: Ar group2\^ Li \&: Ar ... .Sm on -specifies a mapping for all client uids (including root) +Mapping for all client uids (including root) using the same semantics as .Fl maproot . +.It Fl r Ar user +.It Fl r Ar user\^ Ns Li \&: Ns Ar group1\^ Ns Li \&: Ns Ar group2\^ Ns Li \&: Ns Ar ... +Synonym for +.Fl maproot , +for compatibility with older export file formats. .Pp -The option -.Fl r -is a synonym for -.Fl maproot -in an effort to be backward compatible with older export file formats. +.Em Note : +Not a synonym for the read-only option +.Fl ro . +.El .Pp In the absence of .Fl maproot @@ -157,66 +198,76 @@ If a option is given, all users (including root) will be mapped to that credential in place of their own. -.Pp -The -.Fl kerb -option specifies that the Kerberos authentication server should be +.Bl -tag -width Fl +.It Fl kerb +Specifies that the Kerberos authentication server should be used to authenticate and map client credentials. -This option is currently not implemented. -.Pp -The -.Fl ro -option specifies that the filesystem should be exported read-only -(default read/write). -The option -.Fl o -is a synonym for +.Sy This option is currently not implemented. +.It Fl ro +Export filesystem read-only. +Clients will be forbidden to change or write to anything in the +filesystem +.Po +except for named pipes, sockets, and device nodes, where +write semantics is client-side anyway +.Pc . +.It Fl o +Synonym for .Fl ro -in an effort to be backward compatible with older export file formats. -.Pp -The -.Fl noresvport -option specifies that NFS RPC calls for the filesystem do not have to come -from reserved ports. +for compatibility with older export file formats. +.It Fl noresvport +Allow NFS RPC calls for the filesystem to come from non-reserved +ports. Normally, clients are required to use reserved ports for operations. Using this option decreases the security of your system. -.Pp -The -.Fl noresvmnt -option specifies that mount RPC requests for the filesystem do not have -to come from reserved ports. +.\" XXX ^ Not really... +.It Fl noresvmnt +Allow mount RPC requests for the filesystem to come from non-reserved +ports. Normally, clients are required to use reserved ports for mount requests. Using this option decreases the security of your system. +.\" XXX ^ Not really... +.It Fl webnfs +(WebNFS) +Enables WebNFS export, equivalent to combining +.Fl public , +.Fl mapall=nobody , +and +.Fl ro . +.It Fl public +(WebNFS) +Enables WebNFS export strictly according to the spec, +RFC 2054 and RFC 2055. +This implies: +.Bl -bullet -compact +.It +read/write access to all files in the filesystem +.It +not requiring reserved ports +.Pq Fl noresvport , Fl noresvmnt +.It +not remapping uids +.El .Pp -WebNFS exports strictly according to the spec (RFC 2054 and RFC 2055) can -be done with the +.Bf -symbolic +Warning: .Fl public -flag. -However, this flag in itself allows r/w access to all files in -the filesystem, not requiring reserved ports and not remapping uids. -It is only provided to conform to the spec, and should normally +is only provided to conform to the spec, and should normally not be used. +.Ef For a WebNFS export, use the .Fl webnfs -flag, which implies -.Fl public , -.Sm off -.Fl mapall No = Ar nobody -.Sm on -and -.Fl ro . -.Pp -A -.Sm off -.Fl index No = Ar file -.Sm on -option can be used to specify a file whose handle will be returned if -a directory is looked up using the public filehandle (WebNFS). +flag. +.It Fl index Ns Li = Ns Ar file +(WebNFS) +File whose handle will be returned if +a directory is looked up using the public filehandle. This is to mimic the behavior of URLs. If no .Fl index option is specified, a directory filehandle will be returned as usual. +.Pp The .Fl index option only makes sense in combination with the @@ -224,70 +275,75 @@ option only makes sense in combination w or .Fl webnfs flags. +.El .Pp .Bf -symbolic Warning: exporting a filesystem both using WebNFS and read/write in the normal way to other hosts should be avoided in an environment that is vulnerable to IP spoofing. .Ef +.\" XXX Isn't this an issue for _all_ read/write exports, not just +.\" WebNFS ones? WebNFS enables any client to get filehandles to the exported filesystem. Using IP spoofing, a client could then pretend to be a host to which the same filesystem was exported read/write, and use the handle to gain access to that filesystem. +.Bl -tag -width Fl +.Sm off +.It Fl network Li = Ar netname Op Li / Ar prefixlength +.Sm on +Export the filesystem to all hosts in the specified network. .Pp -The third component of a line specifies the host set to which the line applies. -If no host set is specified, the filesystem is exported to everyone. -The set may be specified in three ways. -The first way is to list the host name(s) separated by white space. -(Standard internet -.Dq dot -addresses may be used in place of names.) -The second way is to specify a -.Dq netgroup -as defined in the netgroup file (see -.Xr netgroup 5 ) . -A netgroup that contains an item that does have a host entry -is treated like an error. -The third way is to specify an internet subnetwork using a network and -network mask that is defined as the set of all hosts with addresses within -the subnetwork. -This latter approach requires less overhead within the +This approach to identifying hosts requires less overhead within the kernel and is recommended for cases where the export line refers to a large number of clients within an administrative subnet. .Pp -The first two cases are specified by simply listing the name(s) separated -by whitespace. -All names are checked to see if they are -.Dq netgroup -names first and are assumed to be hostnames otherwise. -Using the full domain specification for a hostname can normally -circumvent the problem of a host that has the same name as a netgroup. -The third case is specified by the flag -.Sm off -.Fl network No = Ar netname Op No / Ar prefixlength -.Sm on -and optionally -.Sm off -.Fl mask No = Ar netmask . -.Sm on -The netmask may be specified either by attaching a -.Ar prefixlength -to the -.Fl network -option, or by using a separate +The netmask may be specified either by +.Ar prefixlength , +or +.Pq for IPv4 networks only +by using a separate .Fl mask option. If the mask is not specified, it will default to the mask for that network -class (A, B or C; see -.Xr inet 4 ) . +class +.Po +A, B or C; see +.Xr inet 4 +.Pc . .Pp -Scoped IPv6 address must carry scope identifier as documented in +Scoped IPv6 address must carry a scope identifier as documented in .Xr inet6 4 . For example, -.Dq fe80::%ne2/10 -is used to specify fe80::/10 on ne2 interface. +.Ql fe80::%ne2/10 +is used to specify +.Ql fe80::/10 +on +.Ql ne2 +interface. +.Sm off +.It Fl mask No = Ar netmask +.Sm on +(IPv4-only) +Netmask for +.Fl network +options with no +.Ar prefixlength . +.El +.Sh FILES +.Bl -tag -width Pa -compact +.It Pa /etc/exports +The default remote mount-point file. +.El +.Pp +If you have modified the +.Pa /etc/exports +file, send the mountd process a +.Dv SIGHUP +to make it re-read it: .Pp -For example: +.Dl "kill -HUP $(cat /var/run/mountd.pid)" +.Sh EXAMPLES .Bd -literal -offset indent /usr /usr/local -maproot=0:10 friends /usr -maproot=daemon grumpy.cis.uoguelph.ca 131.104.48.16 @@ -306,69 +362,97 @@ and .Pa /u2 are local filesystem mount points, the above example specifies the following: -.Pa /usr +.Bl -tag -width ".Pa /usr" +.It Pa /usr is exported to hosts -.Em friends -where friends is specified in the netgroup file -with users mapped to their remote credentials and +.Ql friends +where +.Ql friends +is specified in the +.Xr netgroup 5 +file with users mapped to their remote credentials and root mapped to uid 0 and group 10. It is exported read-write and the hosts in -.Dq friends +.Ql friends can mount either .Pa /usr or .Pa /usr/local . -It is exported to -.Em 131.104.48.16 +.Pp +It is also exported to +.Ql 131.104.48.16 and -.Em grumpy.cis.uoguelph.ca +.Ql grumpy.cis.uoguelph.ca with users mapped to their remote credentials and root mapped to the user and groups associated with -.Dq daemon ; -it is exported to the rest of the world as read-only with -all users mapped to the user and groups associated with -.Dq nobody . +.Ql daemon . .Pp -.Pa /u +It is also exported to the rest of the world as read-only with +all users mapped to the user and groups associated with +.Ql nobody . +.It Pa /u is exported to all hosts on the subnetwork -.Em 131.104.48 +.Ql 131.104.48 with root mapped to the uid for -.Dq bin +.Ql bin and with no group access. -.Pp -.Pa /u2 +.It Pa /u2 is exported to the hosts in -.Dq friends +.Ql friends with root mapped to uid and groups associated with -.Dq root ; +.Ql root ; it is exported to all hosts on network -.Dq cis-net +.Ql cis-net allowing mounts at any -directory within /u2 and mapping all uids to credentials for the principal +directory within +.Pa /u2 +and mapping all uids to credentials for the principal that is authenticated by a Kerberos ticket. -.Pp -.Pa /a -is exported to the network 192.168.0.0, with a netmask of 255.255.255.0. -However, the netmask length in the entry for /a is not specified through -a -mask option, but through the /prefix notation. -.Pp +.Pq Sy Kerberos not implemented. +.It Pa /a +is exported to the network +.Ql 192.168.0.0 , +with a netmask of +.Ql 255.255.255.0 . +However, the netmask in the entry for .Pa /a -is also exported to the IPv6 network 3ffe:1ce1:1:fe80:: address, using -the upper 64 bits as the prefix. +is not specified through a +.Fl mask +option, but through the +.Li / Ns Ar prefixlen +notation. +.It Pa /a +is also exported to the IPv6 network +.Ql 3ffe:1ce1:1:fe80:: +address, using the upper 64 bits as the prefix. Note that, unlike with IPv4 network addresses, the specified network address must be complete, and not just contain the upper bits. -With IPv6 addresses, the -mask option must not -be used. -.Sh FILES -.Bl -tag -width /etc/exports -compact -.It Pa /etc/exports -The default remote mount-point file. +With IPv6 addresses, the +.Fl mask +option must not be used. .El .Sh SEE ALSO .Xr netgroup 5 , .Xr mountd 8 , .Xr nfsd 8 , .Xr showmount 8 +.Rs +.%T NFS: Network File System Protocol Specification +.%R RFC 1094 +.%I IETF Network Working Group +.%O Appendix A +.%U https://datatracker.ietf.org/doc/html/rfc1094#appendix-A.1 +.Re +.Rs +.%A B. Callaghan +.%A B. Pawlowski +.%A P. Staubach +.%T NFS Version 3 Protocol Specification +.%R RFC 1813 +.%I IETF Network Working Group +.%O Appendix I +.%U https://datatracker.ietf.org/doc/html/rfc1813#section-5.0 +.Re .Sh CAVEATS Don't re-export NFS-mounted filesystems unless you are sure of the implications. @@ -377,10 +461,26 @@ systems being exported, e.g. when timest Re-exporting should work to some extent and can even be useful in some cases, but don't expect it works as well as with local file systems. +.Pp +Filesystems that provide a namespace for a subtree of another +filesystem such as nullfs +.Pq Xr mount_null 8 +and umapfs +.Pq Xr mount_umap 8 +.Em do not +restrict +.Tn NFS +clients to that namespace, so they cannot be used to securely limit +.Tn NFS +clients to a subtree of a filesystem. +If you want to export one subtree and prevent access to other subtrees, +the exported subtree must be on its own filesystem on the server. .Sh BUGS The export options are tied to the local mount points in the kernel and must be non-contradictory for any exported subdirectory of the local server mount point. +.\" XXX Explain what `contradictory' means here and give some positive +.\" and negative examples. It is recommended that all exported directories within the same server filesystem be specified on adjacent lines going down the tree. You cannot specify a hostname that is also the name of a netgroup. Index: src/usr.sbin/mountd/mountd.8 diff -u src/usr.sbin/mountd/mountd.8:1.38 src/usr.sbin/mountd/mountd.8:1.38.16.1 --- src/usr.sbin/mountd/mountd.8:1.38 Sat Dec 24 08:26:57 2016 +++ src/usr.sbin/mountd/mountd.8 Sat Aug 24 16:21:10 2024 @@ -1,4 +1,4 @@ -.\" $NetBSD: mountd.8,v 1.38 2016/12/24 08:26:57 abhinav Exp $ +.\" $NetBSD: mountd.8,v 1.38.16.1 2024/08/24 16:21:10 martin Exp $ .\" .\" Copyright (c) 1989, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -48,8 +48,14 @@ mount requests is the server for .Tn NFS mount requests from other client machines. +.Pp .Nm -listens for service requests at the port indicated in the +makes all filesystems listed in +.Xr exports 5 +available to +.Tn NFS +clients, and then listens for mount service requests at the port +indicated in the .Tn NFS server specification; see .%T "Network File System Protocol Specification" ,