nfsd4: fix bare destroy_session null dereference
[safe/jmp/linux-2.6] / fs / nfsd / nfs4state.c
index bba9fff..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>
@@ -1351,6 +1352,13 @@ static bool nfsd4_last_compound_op(struct svc_rqst *rqstp)
        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,
@@ -1366,8 +1374,7 @@ nfsd4_destroy_session(struct svc_rqst *r,
         * - Do we need to clear any callback info from previous session?
         */
 
-       if (!memcmp(&sessionid->sessionid, &cstate->session->se_sessionid,
-                                       sizeof(struct nfs4_sessionid))) {
+       if (nfsd4_compound_in_session(cstate->session, &sessionid->sessionid)) {
                if (!nfsd4_last_compound_op(r))
                        return nfserr_not_only_op;
        }
@@ -1443,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) {