linux-stable/fs/nfsd
NeilBrown b7d2eee1f5 nfsd: fix RELEASE_LOCKOWNER
commit edcf972515 upstream.

The test on so_count in nfsd4_release_lockowner() is nonsense and
harmful.  Revert to using check_for_locks(), changing that to not sleep.

First: harmful.
As is documented in the kdoc comment for nfsd4_release_lockowner(), the
test on so_count can transiently return a false positive resulting in a
return of NFS4ERR_LOCKS_HELD when in fact no locks are held.  This is
clearly a protocol violation and with the Linux NFS client it can cause
incorrect behaviour.

If RELEASE_LOCKOWNER is sent while some other thread is still
processing a LOCK request which failed because, at the time that request
was received, the given owner held a conflicting lock, then the nfsd
thread processing that LOCK request can hold a reference (conflock) to
the lock owner that causes nfsd4_release_lockowner() to return an
incorrect error.

The Linux NFS client ignores that NFS4ERR_LOCKS_HELD error because it
never sends NFS4_RELEASE_LOCKOWNER without first releasing any locks, so
it knows that the error is impossible.  It assumes the lock owner was in
fact released so it feels free to use the same lock owner identifier in
some later locking request.

When it does reuse a lock owner identifier for which a previous RELEASE
failed, it will naturally use a lock_seqid of zero.  However the server,
which didn't release the lock owner, will expect a larger lock_seqid and
so will respond with NFS4ERR_BAD_SEQID.

So clearly it is harmful to allow a false positive, which testing
so_count allows.

The test is nonsense because ... well... it doesn't mean anything.

so_count is the sum of three different counts.
1/ the set of states listed on so_stateids
2/ the set of active vfs locks owned by any of those states
3/ various transient counts such as for conflicting locks.

When it is tested against '2' it is clear that one of these is the
transient reference obtained by find_lockowner_str_locked().  It is not
clear what the other one is expected to be.

In practice, the count is often 2 because there is precisely one state
on so_stateids.  If there were more, this would fail.

In my testing I see two circumstances when RELEASE_LOCKOWNER is called.
In one case, CLOSE is called before RELEASE_LOCKOWNER.  That results in
all the lock states being removed, and so the lockowner being discarded
(it is removed when there are no more references which usually happens
when the lock state is discarded).  When nfsd4_release_lockowner() finds
that the lock owner doesn't exist, it returns success.

The other case shows an so_count of '2' and precisely one state listed
in so_stateid.  It appears that the Linux client uses a separate lock
owner for each file resulting in one lock state per lock owner, so this
test on '2' is safe.  For another client it might not be safe.

So this patch changes check_for_locks() to use the (newish)
find_any_file_locked() so that it doesn't take a reference on the
nfs4_file and so never calls nfsd_file_put(), and so never sleeps.  With
this check is it safe to restore the use of check_for_locks() rather
than testing so_count against the mysterious '2'.

Fixes: ce3c4ad7f4 ("NFSD: Fix possible sleep during nfsd4_release_lockowner()")
Signed-off-by: NeilBrown <neilb@suse.de>
Reviewed-by: Jeff Layton <jlayton@kernel.org>
Cc: stable@vger.kernel.org # v6.2+
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2024-01-31 16:19:06 -08:00
..
acl.h NFSD: add posix ACLs to struct nfsd_attrs 2022-08-04 10:28:03 -04:00
auth.c cred: get rid of CONFIG_DEBUG_CREDENTIALS 2023-12-20 17:01:51 +01:00
auth.h
blocklayout.c nfsd: call op_release, even when op_func returns an error 2023-03-31 17:29:49 -04:00
blocklayoutxdr.c NFSD: da_addr_body field missing in some GETDEVICEINFO replies 2023-08-29 17:45:22 -04:00
blocklayoutxdr.h
cache.h NFSD: Fix checksum mismatches in the duplicate reply cache 2023-12-03 07:33:02 +01:00
current_stateid.h
export.c nfsd: remove redundant assignments to variable len 2023-06-21 15:05:32 -04:00
export.h NFSD: Handle new xprtsec= export option 2023-04-27 18:49:24 -04:00
filecache.c nfsd: Handle EOPENSTALE correctly in the filecache 2023-11-20 11:58:52 +01:00
filecache.h NFSD: Convert filecache to rhltable 2023-04-26 09:04:59 -04:00
flexfilelayout.c nfsd: move nfserrno() to vfs.c 2022-11-28 12:54:44 -05:00
flexfilelayoutxdr.c NFSD: da_addr_body field missing in some GETDEVICEINFO replies 2023-08-29 17:45:22 -04:00
flexfilelayoutxdr.h
idmap.h
Kconfig NFS & NFSD: Update GSS dependencies 2023-03-10 09:38:47 -05:00
lockd.c
Makefile nfsd: allow disabling NFSv2 at compile time 2022-11-28 12:54:45 -05:00
netns.h File locking changes for v6.3 2023-02-20 11:10:38 -08:00
nfs2acl.c NFSD 6.3 Release Notes 2023-02-22 14:21:40 -08:00
nfs3acl.c NFSD 6.3 Release Notes 2023-02-22 14:21:40 -08:00
nfs3proc.c nfsd: handle failure to collect pre/post-op attrs more sanely 2023-08-29 17:45:22 -04:00
nfs3xdr.c NFSD: Ensure that xdr_write_pages updates rq_next_page 2023-06-05 09:01:44 -04:00
nfs4acl.c nfsd: inherit required unset default acls from effective set 2023-08-29 17:45:22 -04:00
nfs4callback.c NFSD: callback request does not use correct credential for AUTH_SYS 2023-04-04 09:55:27 -04:00
nfs4idmap.c SUNRPC: return proper error from get_expiry() 2023-04-26 09:05:00 -04:00
nfs4layouts.c nfsd: fix race to check ls_layouts 2023-02-20 09:20:56 -05:00
nfs4proc.c nfsd: fix change_info in NFSv4 RENAME replies 2023-09-09 13:24:52 -04:00
nfs4recover.c fs: port vfs_*() helpers to struct mnt_idmap 2023-01-18 17:51:45 +01:00
nfs4state.c nfsd: fix RELEASE_LOCKOWNER 2024-01-31 16:19:06 -08:00
nfs4xdr.c NFSD: Fix zero NFSv4 READ results when RQ_SPLICE_OK is not set 2023-09-28 10:34:28 -04:00
nfscache.c NFSD: Fix checksum mismatches in the duplicate reply cache 2023-12-03 07:33:02 +01:00
nfsctl.c nfsd: drop the nfsd_put helper 2024-01-15 18:57:06 +01:00
nfsd.h nfsd: drop the nfsd_put helper 2024-01-15 18:57:06 +01:00
nfsfh.c nfsd: handle failure to collect pre/post-op attrs more sanely 2023-08-29 17:45:22 -04:00
nfsfh.h nfsd: handle failure to collect pre/post-op attrs more sanely 2023-08-29 17:45:22 -04:00
nfsproc.c NFSD: Hoist rq_vec preparation into nfsd_read() 2023-06-11 16:37:45 -04:00
nfssvc.c nfsd: call nfsd_last_thread() before final nfsd_put() 2024-01-01 12:42:42 +00:00
nfsxdr.c NFSD: Ensure that xdr_write_pages updates rq_next_page 2023-06-05 09:01:44 -04:00
pnfs.h
state.h NFSD: handle GETATTR conflict with write delegation 2023-08-29 17:45:22 -04:00
stats.c NFSD: handle GETATTR conflict with write delegation 2023-08-29 17:45:22 -04:00
stats.h NFSD: handle GETATTR conflict with write delegation 2023-08-29 17:45:22 -04:00
trace.c
trace.h NFSD: Rename struct svc_cacherep 2023-08-29 17:45:22 -04:00
vfs.c cred: get rid of CONFIG_DEBUG_CREDENTIALS 2023-12-20 17:01:51 +01:00
vfs.h nfsd: Handle EOPENSTALE correctly in the filecache 2023-11-20 11:58:52 +01:00
xdr.h NFSD: prevent underflow in nfssvc_decode_writeargs() 2022-03-15 09:35:56 -04:00
xdr3.h SUNRPC: Change return value type of .pc_encode 2021-10-13 11:34:49 -04:00
xdr4.h nfsd: remove unsafe BUG_ON from set_change_info 2023-08-29 17:45:22 -04:00
xdr4cb.h NFSD: add support for sending CB_RECALL_ANY 2022-12-10 11:01:12 -05:00