linux/fs/nfsd
Jeff Layton 0b3a551fa5 nfsd: fix handling of cached open files in nfsd4_open codepath
Commit fb70bf124b ("NFSD: Instantiate a struct file when creating a
regular NFSv4 file") added the ability to cache an open fd over a
compound. There are a couple of problems with the way this currently
works:

It's racy, as a newly-created nfsd_file can end up with its PENDING bit
cleared while the nf is hashed, and the nf_file pointer is still zeroed
out. Other tasks can find it in this state and they expect to see a
valid nf_file, and can oops if nf_file is NULL.

Also, there is no guarantee that we'll end up creating a new nfsd_file
if one is already in the hash. If an extant entry is in the hash with a
valid nf_file, nfs4_get_vfs_file will clobber its nf_file pointer with
the value of op_file and the old nf_file will leak.

Fix both issues by making a new nfsd_file_acquirei_opened variant that
takes an optional file pointer. If one is present when this is called,
we'll take a new reference to it instead of trying to open the file. If
the nfsd_file already has a valid nf_file, we'll just ignore the
optional file and pass the nfsd_file back as-is.

Also rework the tracepoints a bit to allow for an "opened" variant and
don't try to avoid counting acquisitions in the case where we already
have a cached open file.

Fixes: fb70bf124b ("NFSD: Instantiate a struct file when creating a regular NFSv4 file")
Cc: Trond Myklebust <trondmy@hammerspace.com>
Reported-by: Stanislav Saner <ssaner@redhat.com>
Reported-and-Tested-by: Ruben Vestergaard <rubenv@drcmr.dk>
Reported-and-Tested-by: Torkil Svensgaard <torkil@drcmr.dk>
Signed-off-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
2023-01-06 13:17:06 -05:00
..
acl.h NFSD: add posix ACLs to struct nfsd_attrs 2022-08-04 10:28:03 -04:00
auth.c nfsd: auth: Fix gid sorting when rootsquash enabled 2018-01-22 20:13:07 -08:00
auth.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
blocklayout.c nfsd: move nfserrno() to vfs.c 2022-11-28 12:54:44 -05:00
blocklayoutxdr.c nfsd: move nfserrno() to vfs.c 2022-11-28 12:54:44 -05:00
blocklayoutxdr.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
cache.h nfsd: use DEFINE_SHOW_ATTRIBUTE to define nfsd_reply_cache_stats_fops 2022-09-26 14:02:50 -04:00
current_stateid.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
export.c fs: add is_idmapped_mnt() helper 2021-12-03 18:44:06 +01:00
export.h nfsd: move nfserrno() to vfs.c 2022-11-28 12:54:44 -05:00
fault_inject.c nfsd: no need to check return value of debugfs_create functions 2019-07-03 16:57:17 +02:00
filecache.c nfsd: fix handling of cached open files in nfsd4_open codepath 2023-01-06 13:17:06 -05:00
filecache.h nfsd: fix handling of cached open files in nfsd4_open codepath 2023-01-06 13:17:06 -05:00
flexfilelayout.c nfsd: move nfserrno() to vfs.c 2022-11-28 12:54:44 -05:00
flexfilelayoutxdr.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
flexfilelayoutxdr.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
idmap.h
Kconfig nfsd: allow disabling NFSv2 at compile time 2022-11-28 12:54:45 -05:00
lockd.c NFSD: simplify struct nfsfh 2021-10-02 15:51:10 -04:00
Makefile nfsd: allow disabling NFSv2 at compile time 2022-11-28 12:54:45 -05:00
netns.h NFSD: add shrinker to reap courtesy clients on low memory condition 2022-09-26 14:02:41 -04:00
nfs2acl.c NFSD: Finish converting the NFSv2 GETACL result encoder 2022-11-28 12:54:44 -05:00
nfs3acl.c NFSD: Finish converting the NFSv3 GETACL result encoder 2022-11-28 12:54:44 -05:00
nfs3proc.c NFSD: Add an NFSD_FILE_GC flag to enable nfsd_file garbage collection 2022-11-28 12:54:45 -05:00
nfs3xdr.c NFSD: Clean up WRITE arg decoders 2022-09-26 14:02:47 -04:00
nfs4acl.c NFSD: add posix ACLs to struct nfsd_attrs 2022-08-04 10:28:03 -04:00
nfs4callback.c nfsd: under NFSv4.1, fix double svc_xprt_put on rpc_create failure 2022-12-12 09:18:44 -05:00
nfs4idmap.c nfsd: move nfserrno() to vfs.c 2022-11-28 12:54:44 -05:00
nfs4layouts.c NFSD: Add tracepoints to report NFSv4 callback completions 2022-09-26 14:02:32 -04:00
nfs4proc.c NFSD: fix use-after-free in __nfs42_ssc_open() 2022-12-14 10:11:54 -05:00
nfs4recover.c struct file-related stuff 2022-10-06 17:13:18 -07:00
nfs4state.c nfsd: fix handling of cached open files in nfsd4_open codepath 2023-01-06 13:17:06 -05:00
nfs4xdr.c nfsd: fix handling of readdir in v4root vs. mount upcall timeout 2023-01-02 10:45:31 -05:00
nfscache.c nfsd: use DEFINE_SHOW_ATTRIBUTE to define nfsd_reply_cache_stats_fops 2022-09-26 14:02:50 -04:00
nfsctl.c nfsd: allow disabling NFSv2 at compile time 2022-11-28 12:54:45 -05:00
nfsd.h nfsd: allow disabling NFSv2 at compile time 2022-11-28 12:54:45 -05:00
nfsfh.c nfsd: ensure we always call fh_verify_error tracepoint 2022-10-13 12:12:37 -04:00
nfsfh.h NFSD: Use const pointers as parameters to fh_ helpers 2022-11-28 12:54:46 -05:00
nfsproc.c NFSD: Use only RQ_DROPME to signal the need to drop a reply 2022-12-10 11:01:13 -05:00
nfssvc.c nfsd: shut down the NFSv4 state objects before the filecache 2022-12-22 10:12:56 -05:00
nfsxdr.c NFSD: Clean up WRITE arg decoders 2022-09-26 14:02:47 -04:00
pnfs.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
state.h NFSD: add delegation reaper to react to low memory condition 2022-12-10 11:01:12 -05:00
stats.c nfsd: use DEFINE_PROC_SHOW_ATTRIBUTE to define nfsd_proc_ops 2022-09-26 14:02:49 -04:00
stats.h nfsd: make nfsd_stats.th_cnt atomic_t 2021-12-13 13:42:51 -05:00
trace.c NFSD: Add SPDX header for fs/nfsd/trace.c 2020-11-30 13:00:24 -05:00
trace.h nfsd: fix handling of cached open files in nfsd4_open codepath 2023-01-06 13:17:06 -05:00
vfs.c NFSD: Add an NFSD_FILE_GC flag to enable nfsd_file garbage collection 2022-11-28 12:54:45 -05:00
vfs.h NFSD: Pass the target nfsd_file to nfsd_commit() 2022-11-28 12:54:45 -05:00
xdr3.h SUNRPC: Change return value type of .pc_encode 2021-10-13 11:34:49 -04:00
xdr4.h NFSD: add support for sending CB_RECALL_ANY 2022-12-10 11:01:12 -05:00
xdr4cb.h NFSD: add support for sending CB_RECALL_ANY 2022-12-10 11:01:12 -05:00
xdr.h NFSD: prevent underflow in nfssvc_decode_writeargs() 2022-03-15 09:35:56 -04:00