Commit Graph

414 Commits

Author SHA1 Message Date
Rick Macklem
648a208ef3 nfsd: Fix NFSv3 Readdir/ReaddirPlus reply for large i-node numbers
If the i-node number (d_fileno) for a file on the server did
not fit in 32bits, it would be truncated to the low order 32bits
for the NFSv3 Readdir and ReaddirPlus RPC replies.
This is no longer correct, given that ino_t is now 64bits.

This patch fixes this by sending the full 64bits of d_fileno
on the wire in the NFSv3 Readdir/ReaddirPlus RPC reply.

PR:	271174
Reported by:	bmueller@panasas.com
Tested by:	bmueller@panasas.com
MFC after:	2 weeks
2023-05-05 15:43:55 -07:00
Rick Macklem
ff2f1f691c nfsd: Add support for the SP4_MACH_CRED case in ExchangeID
Commit f4179ad46f added support for operation bitmaps for
NFSv4.1/4.2.  This commit uses those to implement the SP4_MACH_CRED
case for the NFSv4.1/4.2 ExchangeID operation since the Linux
NFSv4.1/4.2 client is now using this for Kerberized mounts.
The Linux Kerberized NFSv4.1/4.2 mounts currently work without
support for this because Linux will fall back to SP4_NONE,
but there is no guarantee this fallback will work forever.

This commit only affects Kerberized NFSv4.1/4.2 mounts from
Linux at this time.

MFC after:	3 months
2023-04-07 12:49:23 -07:00
Rick Macklem
695d87bae1 nfscl: Make coverity happy
Coverity does not like code that checks a function's
return value sometimes.  Add "(void)" in front of the
function when the return value does not matter to try
and make it happy.

A recent commit deleted "(void)"s in front of nfsm_fhtom().
This commit puts them back in.

Reported by:	emaste
MFC after:	3 months
2023-03-28 17:08:45 -07:00
Rick Macklem
896516e54a nfscl: Add a new NFSv4.1/4.2 mount option for Kerberized mounts
Without this patch, a Kerberized NFSv4.1/4.2 mount must provide
a Kerberos credential for the client at mount time.  This credential
is typically referred to as a "machine credential".  It can be
created one of two ways:
- The user (usually root) has a valid TGT at the time the mount
  is done and this becomes the machine credential.
  There are two problems with this.
  1 - The user doing the mount must have a valid TGT for a user
      principal at mount time.  As such, the mount cannot be put
      in fstab(5) or similar.
  2 - When the TGT expires, the mount breaks.
- The client machine has a service principal in its default keytab
  file and this service principal (typically called a host-based
  initiator credential) is used as the machine credential.
  There are problems with this approach as well:
  1 - There is a certain amount of administrative overhead creating
      the service principal for the NFS client, creating a keytab
      entry for this principal and then copying the keytab entry
      into the client's default keytab file via some secure means.
  2 - The NFS client must have a fixed, well known, DNS name, since
      that FQDN is in the service principal name as the instance.

This patch uses a feature of NFSv4.1/4.2 called SP4_NONE, which
allows the state maintenance operations to be performed by any
authentication mechanism, to do these operations via AUTH_SYS
instead of RPCSEC_GSS (Kerberos).  As such, neither of the above
mechanisms is needed.

It is hoped that this option will encourage adoption of Kerberized
NFS mounts using TLS, to provide a more secure NFS mount.

This new NFSv4.1/4.2 mount option, called "syskrb5" must be used
with "sec=krb5[ip]" to avoid the need for either of the above
Kerberos setups to be done by the client.

Note that all file access/modification operations still require
users on the NFS client to have a valid TGT recognized by the
NFSv4.1/4.2 server.  As such, this option allows, at most, a
malicious client to do some sort of DOS attack.

Although not required, use of "tls" with this new option is
encouraged, since it provides on-the-wire encryption plus,
optionally, client identity verification via a X.509
certificate provided to the server during TLS handshake.
Alternately, "sec=krb5p" does provide on-the-wire
encryption of file data.

A mount_nfs(8) man page update will be done in a separate commit.

Discussed on:	freebsd-current@
MFC after:	3 months
2023-03-16 15:55:36 -07:00
Rick Macklem
a90b47abcb nfs_fha_new: Fix nfs_fha_new so that sysctls work in prisons
The sysctls were in "struct fha_params", making it impractical
to vnet them.  This patch moves the sysctls out of "struct fha_params"
and vnet's them, so that they are available in vnet prisons
running nfsd(8).  It also avoids the IS_DEFAULT_VNET() macros
in the VNET_SYSINIT() function.

Reviewed by:	glebius
MFC after:	3 months
Differential Revision:	https://reviews.freebsd.org/D38748
2023-03-01 15:25:35 -08:00
Rick Macklem
10dff9da97 nfsd: Return ENXIO instead of EPERM when nfsd(8) already running
The nfsd(8) daemon generates an error message that does not
indicate that the nfsd daemon is already running when the nfssvc(2)
syscall fails for the NFSSVC_STABLERESTART.  Also, the check for
running nfsd(8) in a vnet prison will return EPERM when it fails.

This patch replaces EPERM with ENXIO so that the nfsd(8) daemon
can generate more reasonable failure messages.  The nfsd(8) daemon
will be patched in a future commit.

MFC after:	3 months
2023-02-22 13:19:07 -08:00
Rick Macklem
88175af8b7 vfs_export: Add mnt_exjail to control exports done in prisons
If there are multiple instances of mountd(8) (in different
prisons), there will be confusion if they manipulate the
exports of the same file system.  This patch adds mnt_exjail
to "struct mount" so that the credentials (and, therefore,
the prison) that did the exports for that file system can
be recorded.  If another prison has already exported the
file system, vfs_export() will fail with an error.
If mnt_exjail == NULL, the file system has not been exported.
mnt_exjail is checked by the NFS server, so that exports done
from within a different prison will not be used.

The patch also implements vfs_exjail_destroy(), which is
called from prison_cleanup() to release all the mnt_exjail
credential references, so that the prison can be removed.
Mainly to avoid doing a scan of the mountlist for the case
where there were no exports done from within the prison,
a count of how many file systems have been exported from
within the prison is kept in pr_exportcnt.

Reviewed by:	markj
Discussed with:	jamie
Differential Revision:	https://reviews.freebsd.org/D38371
MFC after:	3 months
2023-02-21 13:00:42 -08:00
Rick Macklem
ef6fcc5e2b nfsd: Add VNET_SYSUNINIT() macros for vnet cleanup
Commit ed03776ca7 enabled the vnet front end macros.
As such, for kernels built with the VIMAGE option will malloc
data and initialize locks on a per-vnet basis, typically
via a VNET_SYSINIT().

This patch adds VNET_SYSUNINIT() macros to do the frees
of the per-vnet malloc'd data and destroys of per-vnet
locks.  It also removes the mtx_lock/mtx_unlock calls
from nfsrvd_cleancache(), since they are not needed.

Discussed with:	bz, jamie
MFC after:	3 months
2023-02-20 13:11:22 -08:00
Rick Macklem
ed03776ca7 nfsd: Enable the NFSD_VNET vnet front end macros
Several commits have added front end macros for the vnet
macros to the NFS server, krpc and kgssapi.  These macros
are now null, but this patch changes them to front end
the vnet macros.

With this commit, many global variables in the code become
vnet'd, so that nfsd(8), nfsuserd(8), rpc.tlsservd(8) and
gssd(8) can run in a vnet prison, once enabled.
To run the NFS server in a vnet prison still requires a
couple of patches (in D37741 and D38371) that allow mountd(8)
to export file systems from within a vnet prison.  Once
these are committed to main, a small patch to kern_jail.c
allowing "allow.nfsd" without VNET_NFSD defined will allow
the NFS server to run in a vnet prison.

One area that still needs to be settled is cleanup when a
prison is removed.  Without this, everything should work
except there will be a leak of malloc'd data and mutex locks
when a vnet prison is removed.

MFC after:	3 months
2023-02-18 14:59:36 -08:00
Rick Macklem
cd406ac94d nfsd: Add NFSD_VNET() macros to nfs_fha_new.c
Although it is not 100% obvious if the affinity threads
lists need to be vnet'd when nfsd runs in a prison, I
think it is necessary for the unusual case where the
same file system is exported in multiple prisons.
For this case, the affinity code might try to assign
the RPC to a svc thread that runs in a different prison.
Also, it makes sense to vnet them, since there are
separate svc threads for each prison running nfsd(8).

This patch adds the macros for vnet'ng to nfs_fha_new.c.
The macros are still null, so the only semantics change
is malloc'ng the fha_param structure.

MFC after:	3 months
2023-02-18 07:45:38 -08:00
Rick Macklem
b99c419587 nfsd: Get rid of useless "pool" field in nfs_fha_new.c
Since svcpool_create() is now called from an initialization function,
the pool field of fha_params is always non-NULL, so just get
rid of it and the useless check for it being NULL.

MFC after:	3 months
2023-02-17 07:34:40 -08:00
Rick Macklem
b039ca0776 nfsd: Wrap nfsstatsv1_p in the NFSD_VNET() macro
Commit 7344856e3a6d added a lot of macros that will front end
vnet macros so that nfsd(8) can run in vnet prison.
The nfsstatsv1_p variable got missed.  This patch wraps all
uses of nfsstatsv1_p with the NFSD_VNET() macro.
The NFSD_VNET() macro is still a null macro.

MFC after:	3 months
2023-02-15 17:39:07 -08:00
Rick Macklem
9d329bbc9a nfsd: Continue adding macros so nfsd can run in a vnet prison
Commit 7344856e3a6d added a lot of macros that will front end
vnet macros so that nfsd(8) can run in vnet prison.
This patch adds some more of them and also a lot of uses of
nfsstatsv1_p instead of nfsstatsv1. nfsstatsv1_p points to
nfsstatsv1 for prison0, but will point to a malloc'd structure
for other prisons.

It also puts nfsstatsv1_p in nfscommon.ko instead of nfsd.ko.

MFC after:	3 months
2023-02-13 15:07:17 -08:00
Rick Macklem
fcfdb76e12 nfsd: Fix initialization broken by 7344856e3a6d
Oops, although the vneting macros do not do anything yet,
commit 7344856e3a6d did change where things are initialized
and one of the initialization functions was not being called
early enough.  This patch moves nfsrvd_init(0) to the
function called via (VNET_)SYSINIT() to fix this.

Reported by:	olivier
MFC after:	3 months
2023-02-12 09:16:56 -08:00
Rick Macklem
4d68605f31 nfsd: Delete nfsrv_prison_cleanup() until vneting enabled
Oops, although the vneting macros do not do anything yet,
commit 7344856e3a6d enabled the prison cleanup function, that
would get called and crash the system when a jail was terminated.

This patch gets rid of nfsrv_prison_cleanup() for now.
It can go in when the vnet macros are enabled as
front ends to the vnet macros.

MFC after:	3 months
2023-02-11 18:27:59 -08:00
Rick Macklem
7e44856e3a nfsd: Prepare the NFS server code to run in a vnet prison
This patch defines null macros that can be used to apply
the vnet macros for global variables and SYSCTL flags.
It also applies these macros to many of the global variables
and some of the SYSCTLs.  Since the macros do nothing, these
changes should not result in semantics changes, although the
changes are large in number.

The patch does change several global variables that were
arrays or structures to pointers to same.  For these variables,
modified initialization and cleanup code malloc's and free's
the arrays/structures.  This was done so that the vnet footprint
would be about 300bytes when the macros are defined as vnet macros,
allowing nfsd.ko to load dynamically.

I believe the comments in D37519 have been addressed, although
it has never been reviewed, due in part to the large size of the patch.
This is the first of a series of patches that will put D37519 in main.

Once everything is in main, the macros will be defined as front
end macros to the vnet ones.

MFC after:	3 months
Differential Revision:	https://reviews.freebsd.org/D37519
2023-02-11 15:51:19 -08:00
Rick Macklem
5fd0916cdb nfsd: Add a KASSERT in nfsvno_open
Commit ded5f2954e defined done_namei to indicate that
nd_repstat was set after a successful nfsvno_namei(),
so that a cleanup needs to be done in nfsvno_open().
This only happens when nfsvno_namei() is done with CREATE.

This patch adds a KASSERT() to check for that.

PR:	268971
2023-02-11 07:14:08 -08:00
Rick Macklem
3e230e0cc4 nfsd: Fix handling of the error case for nfsvno_open some more
Commit ded5f2954e defined done_namei to indicate that
nd_repstat was set after a successful nfsvno_namei(),
so that a cleanup needs to be done in nfsvno_open().
However, it missed the case where a call to
nfsrv_opencheck() in nfsvno_open() sets nd_repstat non-zero.

This would cause panics due to a dangling locked vnode
when nfsrv_opencheck() set nd_repstat, such as during grace
just after a server boot.

This patch fixes the problem.

PR:	268971
2023-02-10 19:34:57 -08:00
Rick Macklem
ded5f2954e nfsd: Fix handling of the error case for nfsvno_open
Using done_namei instead of ni_startdir did not
fix the crashes reported in the PR. Upon looking
more closely at the code, the only case where the
code near the end of nfsvno_open() needs to be
executed is when nfsvno_namei() has succeeded,
but a subsequent error was detected.

This patch uses done_namei to indicate this case.

Also, nfsvno_relpathbuf() should only be called for
this case and not whenever nfsvno_open() is called
with nd_repstat != 0. A bug was introduced here when
the HASBUF flag was deleted.

Reviewed by:	mjg
PR:	268971
Tested by:	ish@amail.plala.or.jp
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D38430
2023-02-08 13:08:51 -08:00
Elliott Mitchell
aa41036eb7 nfsserver: purge EOL release compatibility
Remove now-obsolete FreeBSD 4.x and earlier ifdef.

Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/603
Differential Revision: https://reviews.freebsd.org/D35560
2023-02-04 09:10:30 -07:00
Rick Macklem
5a0050e68a nfsserver: Fix handling of SP4_NONE
For NFSv4.1/4.2, when the client specifies SP4_NONE for
state protection in the ExchangeID operation arguments,
the server MUST allow the state management operations for
any user credentials.  (I misread the RFC and thought that
SP4_NONE meant "at the server's discression" and not MUST
be allowed.)

This means that the "sec=XXX" field of the "V4:" exports(5)
line only applies to NFSv4.0.

This patch fixes the server to always allow state management
operations for SP4_NONE, which is the only state management
option currently supported. (I have patches that add support
for SP4_MACH_CRED to the server. These will be in a future commit.)

In practice, this bug does not seem to have caused
interoperability problems.

MFC after:	2 weeks
2023-01-15 14:07:40 -08:00
Rick Macklem
dcfa3ee44d nfsserver: Fix vrele() panic in nfsvno_open()
Commit 65127e982b removed a check for ni_startdir != NULL.
This allowed the vrele(ndp->ni_dvp) to be called with
a NULL argument.

This patch adds a new boolean argument to nfsvno_open()
that can be checked instead of ni_startdir, since mjg@ requested
that ni_startdir not be used. (Discussed in PR#268828.)

PR:	268828
Reviewed by:	mjg
Differential Revision:	https://reviews.freebsd.org/D38032
2023-01-12 16:48:53 -08:00
Rick Macklem
6fd6a0e342 nfsd: Handle file systems without a VOP_VPTOFH()
Unlike NFSv3, the NFSv4 server follows mount points
within the file system tree below the NFSv4 root directory.
If there is a file system mounted within this subtree
that returns EOPNOTSUPP for VOP_VPTOFH(), the NFSv4 server
would return an error for the mount point entry.
This resulted in an "I/O error" report from the Linux NFSv4
client.  It also put an error code in the Readdir reply
that is not defined in the NFSv4 RFCs.

For the FreeBSD NFSv4 client, the entry with the error would
be ignored, which I think is reasonable behaviour for a
mounted file system that can never be exported.

This patch changes the NFSv4 server behaviour to ignore the
mount point entry and not send it in the Readdir reply.
It also changes the behaviour of Lookup for the entry so
that it replies ENOENT for the mount point directory, so
that it is consistent with no entry in the Readdir reply.

With these two changes, the Linux client behaviour is the
same as the FreeBSD client behaviour.  It also avoids
putting an unknown error on the wire to the client.

MFC after:	1 week
2022-12-23 15:17:34 -08:00
Mateusz Guzik
65127e982b nfs: stop using SAVESTART
Only the name is wanted which is already always provided.

Reviewed by:	rmacklem
Tested by:	pho, rmacklem
Differential Revision:	https://reviews.freebsd.org/D34470
2022-12-19 08:09:00 +00:00
Gordon Bergling
bf31248287 nfs: Fix common typos in source code comments
- s/attrbute/attribute/

MFC after:	3 days
2022-11-08 14:58:32 +01:00
Rick Macklem
ae7816576e nfsd: Make the pNFS server update Change for Setxattr/Rmxattr
When the NFS server does the Setxattr or Rmxattr operation,
the Change attribute (va_filerev) needs to be updated.

Without this patch, that was not happening for the
pNFS server configuration.  This patch does a Setattr
against the DS file to make the Change attribute
change.

This bug was discovered during a recent IETF NFSv4 testing
event, where the Change attribute wasn't changed in the
operation reply.

MFC after:	1 month
2022-10-18 15:47:07 -07:00
Cy Schubert
8cee2ebac5 Revert "unbound: Vendor import 1.17.0"
This reverts commit 64d318ea98, reversing
changes made to 8063dc0320.

Revert a mismerge which reversed 8063dc0320.
2022-10-16 13:42:15 -07:00
Cy Schubert
64d318ea98 unbound: Vendor import 1.17.0
Added ACL per interface, proxy protocol and bug fixes.

Announcement:   https://nlnetlabs.nl/news/2022/Oct/13/unbound-1.17.0-released/

Merge commit '643f9a0581e8aac7eb790ced1164748939829826' into new_merge
2022-10-16 13:32:55 -07:00
Rick Macklem
8063dc0320 nfsd: Make Setxattr/Removexattr NFSv4.2 ops IO_SYNC
When the NFS server does Setxattr or Removexattr, the
operations must be done IO_SYNC. If a server
crashes/reboots immediately after replying it must
have the extended attribute changes.

Since UFS does extended attributes asynchronously
by default and there is no "ioflag" argument in
the VOP calls, follow the VOP calls with VOP_FSYNC(),
to ensure the operation has been done synchronously.

This was found by inspection while investigating a
bug discovered during a recent IETF NFSv4 testing
event, where the Change attribute wasn't changed
in the operation reply.

This bug will take further work for ZFS and the
pNFS server configuration, but is now fixed for
a non-pNFS UFS exported file system.

MFC after:	1 month
2022-10-16 13:27:32 -07:00
Mateusz Guzik
a75d1ddd74 vfs: introduce V_PCATCH to stop abusing PCATCH 2022-09-17 15:41:37 +00:00
Mateusz Guzik
5b5b7e2ca2 vfs: always retain path buffer after lookup
This removes some of the complexity needed to maintain HASBUF and
allows for removing injecting SAVENAME by filesystems.

Reviewed by:	kib (previous version)
Differential Revision:	https://reviews.freebsd.org/D36542
2022-09-17 09:10:38 +00:00
Rick Macklem
b875d4f5dd nfsd: Update console message for no session found
The NFSv4.1/4.2 server generates a console message that indicates
that there is no session. I was until recently perplexed w.r.t. how
this could occur. It turns out that the common cause is multiple NFS
clients with the same /etc/hostid.

The host uuid is used by the FreeBSD NFSv4.1/4.2 client as a unique
identifier for the client. If multiple clients use the same host uuid,
this indicates to the NFSv4.1/4.2 server that they are the same client
and confusion occurs.

This trivial patch modifies the console message to suggest that the
client's /etc/hostid needs to be checked for uniqueness.

Reviewed by:	asomers
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D36377
2022-08-27 18:31:20 -07:00
Konstantin Belousov
c6d31b8306 AST: rework
Make most AST handlers dynamically registered.  This allows to have
subsystem-specific handler source located in the subsystem files,
instead of making subr_trap.c aware of it.  For instance, signal
delivery code on return to userspace is now moved to kern_sig.c.

Also, it allows to have some handlers designated as the cleanup (kclear)
type, which are called both at AST and on thread/process exit.  For
instance, ast(), exit1(), and NFS server no longer need to be aware
about UFS softdep processing.

The dynamic registration also allows third-party modules to register AST
handlers if needed.  There is one caveat with loadable modules: the
code does not make any effort to ensure that the module is not unloaded
before all threads processed through AST handler in it.  In fact, this
is already present behavior for hwpmc.ko and ufs.ko.  I do not think it
is worth the efforts and the runtime overhead to try to fix it.

Reviewed by:	markj
Tested by:	emaste (arm64), pho
Discussed with:	jhb
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D35888
2022-08-02 21:11:09 +03:00
Rick Macklem
088ba4356a nfsd: Fix CreateSession for an established ClientID
I mis-read the RFC w.r.t. handling of the sequenceid
when a CreateSession is done after the initial one
that confirms the ClientID.  Fortunately this does
not affect most extant NFSv4.1/4.2 clients, since
they only acquire a single session for TCP for a
ClientID (Solaris might be an exception?).

This patch fixes the server to handle this case,
where the RFC requires the sequenceid be incremented
for each CreateSession and is required to reply to
a retried CreateSession with a cached reply.
It adds a field to nfsclient called lc_prevsess,
which caches the sessionid, which is the only field
in a CreateSession reply that will change for a
retry, to implement this reply cache.

The recent commits up to d4a11b3e3b that mark
session slots bad when "intr" and/or "soft" mounts
are used by the client needs this server patch.
Without this patch, the client will do a full
recovery, including a new ClientID, losing all
byte range locks.  However, prior to the recent
client commits, the client would hang when all
session slots were bad, so even without this
patch it is not a regression.

PR: 260011
MFC after:	2 weeks
2022-07-13 16:28:56 -07:00
Rick Macklem
40ada74ee1 nfscl: Add optional support for slots marked bad
This patch adds support for session slots marked bad
to nfsv4_sequencelookup().  An additional boolean
argument indicates if the check for slots marked bad
should be done.

The "cred" argument added to nfscl_reqstart() by
commit 326bcf9394 is now passed into nfsv4_setquence()
so that it can optionally set the boolean argument
for nfsv4_sequencelookup().  When optionally enabled,
nfsv4_setsequence() will do a DestroySession when all
slots are marked bad.

Since the code that marks slots bad is not yet committed,
this patch should not result in a semantics change.

PR: 260011
MFC after:	2 weeks
2022-07-09 14:43:16 -07:00
Rick Macklem
2b766d5e5a nfscl: Change the cred argument to non-NULL for pNFS proxies
Commit 326bcf9394 added a "cred" argument to nfscl_reqstart().
For the pNFS proxy calls on the server, the argument
should be "cred" instead of NULL.
This patch fixes this.

Since the argument is not yet used, this patch
should not result in a semantics change.

PR: 260011
MFC after:	2 weeks
2022-07-08 17:27:23 -07:00
Rick Macklem
326bcf9394 nfscl: Add a cred argument to nfscl_reqstart()
To deal with broken session slots caused by the use of the
"soft" and/or "intr" mount options, nfsv4_sequencelookup()
will be modified to track the potentially broken session
slots.  Then, when all session slots are potentially
broken, do a DeleteSession operation, so that the NFSv4
server will reply NFSERR_BADSESSION to uses of the session.
These changes will be done in future commits.  However,
to do the DeleteSession RPC, a "cred" argument is needed
for nfscl_reqstart().  This patch adds this argument,
which is unused at this time.  If the argument is NULL,
it indicates that DeleteSession should not be done
(usually because the RPC does not use sessions).

This patch should not cause any semantics change.

PR: 260011
MFC after:	2 weeks
2022-07-08 16:58:06 -07:00
Rick Macklem
5d3fe02c5a nfsd: Clean up the code by not using the vnode_vtype() macro
The vnode_vtype() macro was used to make the code compatible
with Mac OSX, for the Mac OSX port.
For FreeBSD, this macro just obscured the code, so
avoid using it to clean up the code.

This commit should not result in a semantics change.
2022-06-22 13:20:32 -07:00
Rick Macklem
0586a12904 nfscl: Clean up the code by removing vfs_flags() macro
The vfs_flags() macro was used to make the code compatible
with Mac OSX, for the Mac OSX port.
For FreeBSD, this macro just obscured the code, so
remove it to clean up the code.

This commit should not result in a semantics change.
2022-06-20 13:23:04 -07:00
Rick Macklem
f32bf50d43 nfsd: Fix handling of Open/Create for the pNFS server
When the MDS of a pNFS service receives an Open/Create
and the file already exists, it must do a Setattr of
size == 0.  Without this patch, this was eroneously
done via a VOP_SETAATR() call, which would set the
length of the MDS file to 0 (which is already is,
since all data lives on the DSs).

This patch fixes the problem by doing a nfsvno_setattr()
instead of VOP_SETATTR(), which knows to do a proxied
Setattr on the DSs.

For a non-pNFS server, the change has no effect, since
nfsvno_setattr() only does a VOP_SETATTR() for that case.

This was found during a recent IETF NFSv4 testing event.

MFC after:	2 weeks
2022-05-04 13:52:33 -07:00
Rick Macklem
271f6d52a6 nfsd: Fix session slot freeing for NFSv4.1/4.2
Without this patch the NFSv4.1/4.2 server erroneously
always frees session slot zero for callbacks.  This only
affects 4.1/4.2 mounts if the server has delegations
enabled or is a pNFS configuration.  Even for those
cases, the effect is mainly to only use slot 0 for
callbacks, serializing all of them.  There is a slight
chance that callbacks will fail if the client performs
them in a different order than received on the TCP
connection.

If this bug affects your server, you will see console
messages like:
  newnfs_request: Bad session slot

This patch fixes the problem.  Found during a recent
IETF NFSv4 testing event.

PR:	263728
MFC after:	2 weeks
2022-05-02 12:47:43 -07:00
Rick Macklem
47d75c29f5 nfsd: Add a sanity check to SecinfoNoname for file type
Robert Morris reported that, for the case of SecinfoNoname
with the Parent option, providing a non-directory could
cause a crash.

This patch adds a sanity check for v_type == VDIR for
this case, to avoid the crash.

Reported by:	rtm@lcs.mit.edu
PR:	260300
MFC after:	2 weeks
2022-05-01 13:41:31 -07:00
Mateusz Guzik
0134bbe56f vfs: prefix lookup and relookup with vfs_
Reviewed by:	imp, mckusick
Differential Revision:		https://reviews.freebsd.org/D34530
2022-03-13 14:44:39 +00:00
Rick Macklem
3fc3fe9091 nfsd: Do not exempt NFSv3 Fsinfo from the TLS check
The Fsinfo RPC is exempt from the check for
Kerberized NFS being required, as recommended
by RFC2623.  However, there is no reason to
exempt Fsinfo from the requirement to use TLS.

This patch fixes the code so that the exemption
only applies to Kerberized NFS and not
NFS-over-TLS.

This only affects NFS-over-TLS for an NFSv3
mount when it is required, but the client does
not do so.

MFC after:	1 month
2022-03-09 16:52:42 -08:00
Rick Macklem
17a56f3fab nfsd: Reply NFSERR_SEQMISORDERED for bogus seqid argument
The ESXi NFSv4.1 client bogusly sends the wrong value
for the csa_sequence argument for a Create_session operation.
RFC8881 requires this value to be the same as the sequence
reply from the ExchangeID operation most recently done for
the client ID.

Without this patch, the server replies NFSERR_STALECLIENTID,
which is the correct response for an NFSv4.0 SetClientIDConfirm
but is not the correct error for NFSv4.1/4.2, which is
specified as NFSERR_SEQMISORDERED in RFC8881.
This patch fixes this.

This change does not fix the issue reported in the PR, where
the ESXi client loops, attempting ExchangeID/Create_session
repeatedly.

Reported by:	asomers
Tested by:	asomers
PR:	261291
MFC after:	1 week
2022-02-09 15:17:50 -08:00
Rick Macklem
e2fe58d61b nfsd: Allow file owners to perform Open(Delegate_cur)
Commit b0b7d978b6 changed the NFSv4 server's default
behaviour to check the file's mode or ACL for permission to
open the file, to be Linux and Solaris compatible.
However, it turns out that Linux makes an exception for
the case of Claim_delegate_cur(_fh).

When a NFSv4 client is returning a delegation, it must
acquire Opens against the server to replace the ones
done locally in the client.  The client does this via
an Open operation with Claim_delegate_cur(_fh).  If
this operation fails, due to a change to the file's
mode or ACL after the delegation was issued, the
client does not have any way to retain the open.

As such, the Linux client allows the file's owner
to perform an Open with Claim_delegate_cur(_fh)
no matter what the mode or ACL allows.

This patch makes the FreeBSD server allow this case,
to be Linux compatible.

This patch only affects the case where delegations
are enabled, which is not the default.

MFC after:	2 weeks
2022-02-02 14:10:16 -08:00
Rick Macklem
a91a57846b nfsd: Do not accept audit/alarm ACEs for the NFSv4 server
The UFS and ZFS file systems only support Allow/Deny ACEs
in the NFSv4 ACLs.  This patch does not allow the server
to parse Audit/Alarm ACEs.  The NFSv4 client is still
allowed to pase Audit/Alarm ACEs, since non-FreeBSD NFSv4
servers may use them.

This patch should not have a significant effect, since the
UFS and ZFS file systems will not handle these ACEs anyhow.
It simply serves as an additional "safety belt" for the
NFSv4 server.

MFC after:	2 weeks
2022-01-11 09:40:07 -08:00
Rick Macklem
5da9b3b011 Revert "nfscommon: Add arguments for support of the dacl attribute"
This reverts commit 0fa074b53e.

I now see that the implementation of the "dacl" operation
requires that the NFSv4 server to "automatic inheritance"
and I do not plan on doing this.  As such, this patch is
harmless, but unneeded.
2022-01-11 08:30:50 -08:00
Alexander Motin
3455c738ac nfsd: Reduce callouts rate.
Before this callouts were scheduled twice a seconds even if nfsd was
never used.  This reduces the rate to ~1Hz and only after nfsd first
started.

MFC after:	2 weeks
2022-01-09 13:14:23 -05:00
Rick Macklem
0fa074b53e nfscommon: Add arguments for support of the dacl attribute
NFSv4.1/4.2 has an alternative to the acl attribute, called
dacl, that includes support for the ACL_ENTRY_INHERITED flag,
called NFSV4ACE_INHERITED in NFSv4.

This patch adds a dacl argument to nfsrv_buildacl(),
nfsrv_dissectacl() and nfsrv_dissectace(), so that they
will handle NFSV4ACE_INHERITED when dacl == true.

Since these functions are always called with dacl == false
for this patch, semantics should not have changed.
A future patch will add support for dacl.

MFC after:	2 weeks
2021-12-26 16:43:46 -08:00