nfsd4: fix unlikely race in session replay case
authorJ. Bruce Fields <bfields@citi.umich.edu>
Sat, 24 Apr 2010 19:35:43 +0000 (15:35 -0400)
committerJ. Bruce Fields <bfields@citi.umich.edu>
Mon, 3 May 2010 12:32:31 +0000 (08:32 -0400)
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>
fs/nfsd/nfs4proc.c
fs/nfsd/nfs4state.c
fs/nfsd/nfs4xdr.c

index e147dbcb7ef71a43ab2a6bfbd380e72e4bafc162..61282f8405b5da8a8216636fdc6e5a0bf47de00c 100644 (file)
@@ -1027,6 +1027,7 @@ nfsd4_proc_compound(struct svc_rqst *rqstp,
        resp->rqstp = rqstp;
        resp->cstate.minorversion = args->minorversion;
        resp->cstate.replay_owner = NULL;
+       resp->cstate.session = NULL;
        fh_init(&resp->cstate.current_fh, NFS4_FHSIZE);
        fh_init(&resp->cstate.save_fh, NFS4_FHSIZE);
        /* Use the deferral mechanism only for NFSv4.0 compounds */
index bba9fff49cfea532ceb03841ffb281b25c7c4e09..737315c61e7e0b77a6d18e605e0e0b006d869a18 100644 (file)
@@ -1443,11 +1443,10 @@ nfsd4_sequence(struct svc_rqst *rqstp,
        cstate->slot = slot;
        cstate->session = session;
 
-       /* Hold a session reference until done processing the compound:
-        * nfsd4_put_session called only if the cstate slot is set.
-        */
-       nfsd4_get_session(session);
 out:
+       /* Hold a session reference until done processing the compound. */
+       if (cstate->session)
+               nfsd4_get_session(cstate->session);
        spin_unlock(&sessionid_lock);
        /* Renew the clientid on success and on replay */
        if (cstate->session) {
index fb27b1db007be8f7904a5b3275dcde376ea86adb..05bc5bd63c954a86b6984dedd7889dfb505bed48 100644 (file)
@@ -3306,10 +3306,12 @@ nfs4svc_encode_compoundres(struct svc_rqst *rqstp, __be32 *p, struct nfsd4_compo
                iov = &rqstp->rq_res.head[0];
        iov->iov_len = ((char*)resp->p) - (char*)iov->iov_base;
        BUG_ON(iov->iov_len > PAGE_SIZE);
-       if (nfsd4_has_session(cs) && cs->status != nfserr_replay_cache) {
-               nfsd4_store_cache_entry(resp);
-               dprintk("%s: SET SLOT STATE TO AVAILABLE\n", __func__);
-               resp->cstate.slot->sl_inuse = false;
+       if (nfsd4_has_session(cs)) {
+               if (cs->status != nfserr_replay_cache) {
+                       nfsd4_store_cache_entry(resp);
+                       dprintk("%s: SET SLOT STATE TO AVAILABLE\n", __func__);
+                       resp->cstate.slot->sl_inuse = false;
+               }
                nfsd4_put_session(resp->cstate.session);
        }
        return 1;