diff options
author | Chuck Lever <chuck.lever@oracle.com> | 2016-08-11 10:37:30 -0400 |
---|---|---|
committer | J. Bruce Fields <bfields@redhat.com> | 2016-08-11 15:08:39 -0400 |
commit | 42691398be08bd1fe99326911a0aa31f2c041d53 (patch) | |
tree | 1a0674b92269c6ed774b755189764f84c4687061 | |
parent | 502aa0a5be633e6558574ebcf63b65afdfbfcd7a (diff) |
nfsd: Fix race between FREE_STATEID and LOCK
When running LTP's nfslock01 test, the Linux client can send a LOCK
and a FREE_STATEID request at the same time. The outcome is:
Frame 324 R OPEN stateid [2,O]
Frame 115004 C LOCK lockowner_is_new stateid [2,O] offset 672000 len 64
Frame 115008 R LOCK stateid [1,L]
Frame 115012 C WRITE stateid [0,L] offset 672000 len 64
Frame 115016 R WRITE NFS4_OK
Frame 115019 C LOCKU stateid [1,L] offset 672000 len 64
Frame 115022 R LOCKU NFS4_OK
Frame 115025 C FREE_STATEID stateid [2,L]
Frame 115026 C LOCK lockowner_is_new stateid [2,O] offset 672128 len 64
Frame 115029 R FREE_STATEID NFS4_OK
Frame 115030 R LOCK stateid [3,L]
Frame 115034 C WRITE stateid [0,L] offset 672128 len 64
Frame 115038 R WRITE NFS4ERR_BAD_STATEID
In other words, the server returns stateid L in a successful LOCK
reply, but it has already released it. Subsequent uses of stateid L
fail.
To address this, protect the generation check in nfsd4_free_stateid
with the st_mutex. This should guarantee that only one of two
outcomes occurs: either LOCK returns a fresh valid stateid, or
FREE_STATEID returns NFS4ERR_LOCKS_HELD.
Reported-by: Alexey Kodanev <alexey.kodanev@oracle.com>
Fix-suggested-by: Jeff Layton <jlayton@redhat.com>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
Tested-by: Alexey Kodanev <alexey.kodanev@oracle.com>
Cc: stable@vger.kernel.org
Signed-off-by: J. Bruce Fields <bfields@redhat.com>
-rw-r--r-- | fs/nfsd/nfs4state.c | 40 |
1 files changed, 28 insertions, 12 deletions
diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index 8410ca275db1..0edc1822f144 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c | |||
@@ -4903,6 +4903,32 @@ nfsd4_test_stateid(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, | |||
4903 | return nfs_ok; | 4903 | return nfs_ok; |
4904 | } | 4904 | } |
4905 | 4905 | ||
4906 | static __be32 | ||
4907 | nfsd4_free_lock_stateid(stateid_t *stateid, struct nfs4_stid *s) | ||
4908 | { | ||
4909 | struct nfs4_ol_stateid *stp = openlockstateid(s); | ||
4910 | __be32 ret; | ||
4911 | |||
4912 | mutex_lock(&stp->st_mutex); | ||
4913 | |||
4914 | ret = check_stateid_generation(stateid, &s->sc_stateid, 1); | ||
4915 | if (ret) | ||
4916 | goto out; | ||
4917 | |||
4918 | ret = nfserr_locks_held; | ||
4919 | if (check_for_locks(stp->st_stid.sc_file, | ||
4920 | lockowner(stp->st_stateowner))) | ||
4921 | goto out; | ||
4922 | |||
4923 | release_lock_stateid(stp); | ||
4924 | ret = nfs_ok; | ||
4925 | |||
4926 | out: | ||
4927 | mutex_unlock(&stp->st_mutex); | ||
4928 | nfs4_put_stid(s); | ||
4929 | return ret; | ||
4930 | } | ||
4931 | |||
4906 | __be32 | 4932 | __be32 |
4907 | nfsd4_free_stateid(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, | 4933 | nfsd4_free_stateid(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, |
4908 | struct nfsd4_free_stateid *free_stateid) | 4934 | struct nfsd4_free_stateid *free_stateid) |
@@ -4910,7 +4936,6 @@ nfsd4_free_stateid(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, | |||
4910 | stateid_t *stateid = &free_stateid->fr_stateid; | 4936 | stateid_t *stateid = &free_stateid->fr_stateid; |
4911 | struct nfs4_stid *s; | 4937 | struct nfs4_stid *s; |
4912 | struct nfs4_delegation *dp; | 4938 | struct nfs4_delegation *dp; |
4913 | struct nfs4_ol_stateid *stp; | ||
4914 | struct nfs4_client *cl = cstate->session->se_client; | 4939 | struct nfs4_client *cl = cstate->session->se_client; |
4915 | __be32 ret = nfserr_bad_stateid; | 4940 | __be32 ret = nfserr_bad_stateid; |
4916 | 4941 | ||
@@ -4929,18 +4954,9 @@ nfsd4_free_stateid(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, | |||
4929 | ret = nfserr_locks_held; | 4954 | ret = nfserr_locks_held; |
4930 | break; | 4955 | break; |
4931 | case NFS4_LOCK_STID: | 4956 | case NFS4_LOCK_STID: |
4932 | ret = check_stateid_generation(stateid, &s->sc_stateid, 1); | 4957 | atomic_inc(&s->sc_count); |
4933 | if (ret) | ||
4934 | break; | ||
4935 | stp = openlockstateid(s); | ||
4936 | ret = nfserr_locks_held; | ||
4937 | if (check_for_locks(stp->st_stid.sc_file, | ||
4938 | lockowner(stp->st_stateowner))) | ||
4939 | break; | ||
4940 | WARN_ON(!unhash_lock_stateid(stp)); | ||
4941 | spin_unlock(&cl->cl_lock); | 4958 | spin_unlock(&cl->cl_lock); |
4942 | nfs4_put_stid(s); | 4959 | ret = nfsd4_free_lock_stateid(stateid, s); |
4943 | ret = nfs_ok; | ||
4944 | goto out; | 4960 | goto out; |
4945 | case NFS4_REVOKED_DELEG_STID: | 4961 | case NFS4_REVOKED_DELEG_STID: |
4946 | dp = delegstateid(s); | 4962 | dp = delegstateid(s); |