diff options
author | J. Bruce Fields <bfields@citi.umich.edu> | 2010-04-24 15:35:43 -0400 |
---|---|---|
committer | J. Bruce Fields <bfields@citi.umich.edu> | 2010-05-03 08:32:31 -0400 |
commit | 26c0c75e69265961e891ed80b38fb62a548ab371 (patch) | |
tree | 1ecbc767a1b2ad3e8f25d88e918076806d8c2eb1 /fs/nfsd | |
parent | e0c8233622cbd49d171bc57b60e725f2fb748750 (diff) |
nfsd4: fix unlikely race in session replay case
In the replay case, the
renew_client(session->se_client);
happens after we've droppped the sessionid_lock, and without holding a
reference on the session; so there's nothing preventing the session
being freed before we get here.
Thanks to Benny Halevy for catching a bug in an earlier version of this
patch.
Signed-off-by: J. Bruce Fields <bfields@citi.umich.edu>
Acked-by: Benny Halevy <bhalevy@panasas.com>
Diffstat (limited to 'fs/nfsd')
-rw-r--r-- | fs/nfsd/nfs4proc.c | 1 | ||||
-rw-r--r-- | fs/nfsd/nfs4state.c | 7 | ||||
-rw-r--r-- | fs/nfsd/nfs4xdr.c | 10 |
3 files changed, 10 insertions, 8 deletions
diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c index e147dbcb7ef7..61282f8405b5 100644 --- a/fs/nfsd/nfs4proc.c +++ b/fs/nfsd/nfs4proc.c | |||
@@ -1027,6 +1027,7 @@ nfsd4_proc_compound(struct svc_rqst *rqstp, | |||
1027 | resp->rqstp = rqstp; | 1027 | resp->rqstp = rqstp; |
1028 | resp->cstate.minorversion = args->minorversion; | 1028 | resp->cstate.minorversion = args->minorversion; |
1029 | resp->cstate.replay_owner = NULL; | 1029 | resp->cstate.replay_owner = NULL; |
1030 | resp->cstate.session = NULL; | ||
1030 | fh_init(&resp->cstate.current_fh, NFS4_FHSIZE); | 1031 | fh_init(&resp->cstate.current_fh, NFS4_FHSIZE); |
1031 | fh_init(&resp->cstate.save_fh, NFS4_FHSIZE); | 1032 | fh_init(&resp->cstate.save_fh, NFS4_FHSIZE); |
1032 | /* Use the deferral mechanism only for NFSv4.0 compounds */ | 1033 | /* Use the deferral mechanism only for NFSv4.0 compounds */ |
diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index bba9fff49cfe..737315c61e7e 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c | |||
@@ -1443,11 +1443,10 @@ nfsd4_sequence(struct svc_rqst *rqstp, | |||
1443 | cstate->slot = slot; | 1443 | cstate->slot = slot; |
1444 | cstate->session = session; | 1444 | cstate->session = session; |
1445 | 1445 | ||
1446 | /* Hold a session reference until done processing the compound: | ||
1447 | * nfsd4_put_session called only if the cstate slot is set. | ||
1448 | */ | ||
1449 | nfsd4_get_session(session); | ||
1450 | out: | 1446 | out: |
1447 | /* Hold a session reference until done processing the compound. */ | ||
1448 | if (cstate->session) | ||
1449 | nfsd4_get_session(cstate->session); | ||
1451 | spin_unlock(&sessionid_lock); | 1450 | spin_unlock(&sessionid_lock); |
1452 | /* Renew the clientid on success and on replay */ | 1451 | /* Renew the clientid on success and on replay */ |
1453 | if (cstate->session) { | 1452 | if (cstate->session) { |
diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c index fb27b1db007b..05bc5bd63c95 100644 --- a/fs/nfsd/nfs4xdr.c +++ b/fs/nfsd/nfs4xdr.c | |||
@@ -3306,10 +3306,12 @@ nfs4svc_encode_compoundres(struct svc_rqst *rqstp, __be32 *p, struct nfsd4_compo | |||
3306 | iov = &rqstp->rq_res.head[0]; | 3306 | iov = &rqstp->rq_res.head[0]; |
3307 | iov->iov_len = ((char*)resp->p) - (char*)iov->iov_base; | 3307 | iov->iov_len = ((char*)resp->p) - (char*)iov->iov_base; |
3308 | BUG_ON(iov->iov_len > PAGE_SIZE); | 3308 | BUG_ON(iov->iov_len > PAGE_SIZE); |
3309 | if (nfsd4_has_session(cs) && cs->status != nfserr_replay_cache) { | 3309 | if (nfsd4_has_session(cs)) { |
3310 | nfsd4_store_cache_entry(resp); | 3310 | if (cs->status != nfserr_replay_cache) { |
3311 | dprintk("%s: SET SLOT STATE TO AVAILABLE\n", __func__); | 3311 | nfsd4_store_cache_entry(resp); |
3312 | resp->cstate.slot->sl_inuse = false; | 3312 | dprintk("%s: SET SLOT STATE TO AVAILABLE\n", __func__); |
3313 | resp->cstate.slot->sl_inuse = false; | ||
3314 | } | ||
3313 | nfsd4_put_session(resp->cstate.session); | 3315 | nfsd4_put_session(resp->cstate.session); |
3314 | } | 3316 | } |
3315 | return 1; | 3317 | return 1; |