nfsd4: fix bare destroy_session null dereference
[safe/jmp/linux-2.6] / fs / nfsd / nfs4state.c
index 4300d9f..835d6ce 100644 (file)
@@ -34,6 +34,7 @@
 
 #include <linux/file.h>
 #include <linux/smp_lock.h>
+#include <linux/slab.h>
 #include <linux/namei.h>
 #include <linux/swap.h>
 #include <linux/sunrpc/svcauth_gss.h>
@@ -1343,6 +1344,21 @@ out:
        return status;
 }
 
+static bool nfsd4_last_compound_op(struct svc_rqst *rqstp)
+{
+       struct nfsd4_compoundres *resp = rqstp->rq_resp;
+       struct nfsd4_compoundargs *argp = rqstp->rq_argp;
+
+       return argp->opcnt == resp->opcnt;
+}
+
+static bool nfsd4_compound_in_session(struct nfsd4_session *session, struct nfs4_sessionid *sid)
+{
+       if (!session)
+               return 0;
+       return !memcmp(sid, &session->se_sessionid, sizeof(*sid));
+}
+
 __be32
 nfsd4_destroy_session(struct svc_rqst *r,
                      struct nfsd4_compound_state *cstate,
@@ -1358,6 +1374,10 @@ nfsd4_destroy_session(struct svc_rqst *r,
         * - Do we need to clear any callback info from previous session?
         */
 
+       if (nfsd4_compound_in_session(cstate->session, &sessionid->sessionid)) {
+               if (!nfsd4_last_compound_op(r))
+                       return nfserr_not_only_op;
+       }
        dump_sessionid(__func__, &sessionid->sessionid);
        spin_lock(&sessionid_lock);
        ses = find_in_sessionid_hashtbl(&sessionid->sessionid);
@@ -1430,11 +1450,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) {