Skip to contentSkip to conversation

cifs: Send a logoff request before removing a smb session

PATCH Superseded [email protected] 3 participants 5 messages Oct 4, 2013 – Oct 7, 2013 2 messages not in the archive

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cifs: Send a logoff request before removing a smb session

From: Shirish Pargaonkar <[email protected]>

Send a smb session logoff request before removing smb session off of the list. On a signed smb session, remvoing a session off of the list before sending a logoff request results in server returning an error for lack of smb signature.

If a server returns an error to a logoff request, log and error and keep the session on the list.

---
 fs/cifs/connect.c       | 32 +++++++++++++++++++++++++++-----
 fs/cifs/smb2transport.c | 10 ++++++++--
 fs/cifs/transport.c     | 11 +++++++++--
 3 files changed, 44 insertions(+), 9 deletions(-)
fs/cifs/connect.c +27 -5
index a279ffc..ab3cc8d 100644
@@ -2242,6 +2242,8 @@ cifs_find_smb_ses(struct TCP_Server_Info *server, struct smb_vol *vol)
 
 	spin_lock(&cifs_tcp_ses_lock);
 	list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) {
+		if (ses->status == CifsExiting)
+			continue;
 		if (!match_session(ses, vol))
 			continue;
 		++ses->ses_count;
@@ -2255,24 +2257,44 @@ cifs_find_smb_ses(struct TCP_Server_Info *server, struct smb_vol *vol)
 static void
 cifs_put_smb_ses(struct cifs_ses *ses)
 {
-	unsigned int xid;
+	unsigned int rc, xid;
 	struct TCP_Server_Info *server = ses->server;
 
 	cifs_dbg(FYI, "%s: ses_count=%d\n", __func__, ses->ses_count);
+
 	spin_lock(&cifs_tcp_ses_lock);
+	if (ses->status == CifsExiting) {
+		spin_unlock(&cifs_tcp_ses_lock);
+		return;
+	}
 	if (--ses->ses_count > 0) {
 		spin_unlock(&cifs_tcp_ses_lock);
 		return;
 	}
-
-	list_del_init(&ses->smb_ses_list);
+	if (ses->status == CifsGood)
+		ses->status = CifsExiting;
 	spin_unlock(&cifs_tcp_ses_lock);
 
-	if (ses->status == CifsGood && server->ops->logoff) {
+	if (ses->status == CifsExiting && server->ops->logoff) {
 		xid = get_xid();
-		server->ops->logoff(xid, ses);
+		rc = server->ops->logoff(xid, ses);
 		_free_xid(xid);
+
+		if (rc) {
+			cifs_dbg(VFS, "%s: Session Logoff failure rc=%d\n",
+				__func__, rc);
+			spin_lock(&cifs_tcp_ses_lock);
+			++ses->ses_count;
+			ses->status = CifsGood;
+			spin_unlock(&cifs_tcp_ses_lock);
+			return;
+		}
 	}
+
+	spin_lock(&cifs_tcp_ses_lock);
+	list_del_init(&ses->smb_ses_list);
+	spin_unlock(&cifs_tcp_ses_lock);
+
 	sesInfoFree(ses);
 	cifs_put_tcp_session(server);
 }
fs/cifs/smb2transport.c +8 -2
index 340abca..ee1963b 100644
@@ -516,13 +516,19 @@ smb2_get_mid_entry(struct cifs_ses *ses, struct smb2_hdr *buf,
 		return -EAGAIN;
 	}
 
-	if (ses->status != CifsGood) {
-		/* check if SMB2 session is bad because we are setting it up */
+	if (ses->status == CifsNew) {
 		if ((buf->Command != SMB2_SESSION_SETUP) &&
 		    (buf->Command != SMB2_NEGOTIATE))
 			return -EAGAIN;
 		/* else ok - we are setting up session */
 	}
+
+	if (ses->status == CifsExiting) {
+		if (buf->Command != SMB2_LOGOFF)
+			return -EAGAIN;
+		/* else ok - we are shutting down the session */
+	}
+
 	*mid = smb2_mid_entry_alloc(buf, ses->server);
 	if (*mid == NULL)
 		return -ENOMEM;
fs/cifs/transport.c +9 -2
index 800b938..ebb46e3 100644
@@ -431,13 +431,20 @@ static int allocate_mid(struct cifs_ses *ses, struct smb_hdr *in_buf,
 		return -EAGAIN;
 	}
 
-	if (ses->status != CifsGood) {
-		/* check if SMB session is bad because we are setting it up */
+	if (ses->status == CifsNew) {
 		if ((in_buf->Command != SMB_COM_SESSION_SETUP_ANDX) &&
 			(in_buf->Command != SMB_COM_NEGOTIATE))
 			return -EAGAIN;
 		/* else ok - we are setting up session */
 	}
+
+	if (ses->status == CifsExiting) {
+		/* check if SMB session is bad because we are setting it up */
+		if (in_buf->Command != SMB_COM_LOGOFF_ANDX)
+			return -EAGAIN;
+		/* else ok - we are shutting down session */
+	}
+
 	*ppmidQ = AllocMidQEntry(in_buf, ses->server);
 	if (*ppmidQ == NULL)
 		return -ENOMEM;
Signature · 1 line
1.8.1.2

A message that is not in the archive (sent off-list or not yet received): 1380913583-5506-1-git-send-email-shirishpargaonkar-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

#2 lore raw

Anyone else tested or reviewed this ...

Quoted 138 lines · On Fri, Oct 4, 2013 at 2:06 PM, <shirishpargaonkar-Re5JQEeQqe8AvxtiuMwx3w@publ…

From: Shirish Pargaonkar <[email protected]>

Send a smb session logoff request before removing smb session off of the list. On a signed smb session, remvoing a session off of the list before sending a logoff request results in server returning an error for lack of smb signature.

If a server returns an error to a logoff request, log and error and keep the session on the list.

---
 fs/cifs/connect.c       | 32 +++++++++++++++++++++++++++-----
 fs/cifs/smb2transport.c | 10 ++++++++--
 fs/cifs/transport.c     | 11 +++++++++--
 3 files changed, 44 insertions(+), 9 deletions(-)
fs/cifs/connect.c +27 -5
index a279ffc..ab3cc8d 100644
@@ -2242,6 +2242,8 @@ cifs_find_smb_ses(struct TCP_Server_Info *server, struct smb_vol *vol)
 
        spin_lock(&cifs_tcp_ses_lock);
        list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) {
+               if (ses->status == CifsExiting)
+                       continue;
                if (!match_session(ses, vol))
                        continue;
                ++ses->ses_count;
@@ -2255,24 +2257,44 @@ cifs_find_smb_ses(struct TCP_Server_Info *server, struct smb_vol *vol)
 static void
 cifs_put_smb_ses(struct cifs_ses *ses)
 {
-       unsigned int xid;
+       unsigned int rc, xid;
        struct TCP_Server_Info *server = ses->server;
 
        cifs_dbg(FYI, "%s: ses_count=%d\n", __func__, ses->ses_count);
+
        spin_lock(&cifs_tcp_ses_lock);
+       if (ses->status == CifsExiting) {
+               spin_unlock(&cifs_tcp_ses_lock);
+               return;
+       }
        if (--ses->ses_count > 0) {
                spin_unlock(&cifs_tcp_ses_lock);
                return;
        }
-
-       list_del_init(&ses->smb_ses_list);
+       if (ses->status == CifsGood)
+               ses->status = CifsExiting;
        spin_unlock(&cifs_tcp_ses_lock);
 
-       if (ses->status == CifsGood && server->ops->logoff) {
+       if (ses->status == CifsExiting && server->ops->logoff) {
                xid = get_xid();
-               server->ops->logoff(xid, ses);
+               rc = server->ops->logoff(xid, ses);
                _free_xid(xid);
+
+               if (rc) {
+                       cifs_dbg(VFS, "%s: Session Logoff failure rc=%d\n",
+                               __func__, rc);
+                       spin_lock(&cifs_tcp_ses_lock);
+                       ++ses->ses_count;
+                       ses->status = CifsGood;
+                       spin_unlock(&cifs_tcp_ses_lock);
+                       return;
+               }
        }
+
+       spin_lock(&cifs_tcp_ses_lock);
+       list_del_init(&ses->smb_ses_list);
+       spin_unlock(&cifs_tcp_ses_lock);
+
        sesInfoFree(ses);
        cifs_put_tcp_session(server);
 }
fs/cifs/smb2transport.c +8 -2
index 340abca..ee1963b 100644
@@ -516,13 +516,19 @@ smb2_get_mid_entry(struct cifs_ses *ses, struct smb2_hdr *buf,
                return -EAGAIN;
        }
 
-       if (ses->status != CifsGood) {
-               /* check if SMB2 session is bad because we are setting it up */
+       if (ses->status == CifsNew) {
                if ((buf->Command != SMB2_SESSION_SETUP) &&
                    (buf->Command != SMB2_NEGOTIATE))
                        return -EAGAIN;
                /* else ok - we are setting up session */
        }
+
+       if (ses->status == CifsExiting) {
+               if (buf->Command != SMB2_LOGOFF)
+                       return -EAGAIN;
+               /* else ok - we are shutting down the session */
+       }
+
        *mid = smb2_mid_entry_alloc(buf, ses->server);
        if (*mid == NULL)
                return -ENOMEM;
fs/cifs/transport.c +9 -3
index 800b938..ebb46e3 100644
@@ -431,13 +431,20 @@ static int allocate_mid(struct cifs_ses *ses, struct smb_hdr *in_buf,
                return -EAGAIN;
        }
 
-       if (ses->status != CifsGood) {
-               /* check if SMB session is bad because we are setting it up */
+       if (ses->status == CifsNew) {
                if ((in_buf->Command != SMB_COM_SESSION_SETUP_ANDX) &&
                        (in_buf->Command != SMB_COM_NEGOTIATE))
                        return -EAGAIN;
                /* else ok - we are setting up session */
        }
+
+       if (ses->status == CifsExiting) {
+               /* check if SMB session is bad because we are setting it up */
+               if (in_buf->Command != SMB_COM_LOGOFF_ANDX)
+                       return -EAGAIN;
+               /* else ok - we are shutting down session */
+       }
+
        *ppmidQ = AllocMidQEntry(in_buf, ses->server);
        if (*ppmidQ == NULL)
                return -ENOMEM;
--

1.8.1.2

Signature · 3 lines
Thanks,

Steve
#3 lore raw
In reply to a message not in the archive

Presumably this is needed when you mount multiuser to the same server.
Can you describe the problem reproduction scenario?

Quoted 138 lines · On Fri, Oct 4, 2013 at 2:06 PM, <shirishpargaonkar-Re5JQEeQqe8AvxtiuMwx3w@publ…

From: Shirish Pargaonkar <[email protected]>

Send a smb session logoff request before removing smb session off of the list. On a signed smb session, remvoing a session off of the list before sending a logoff request results in server returning an error for lack of smb signature.

If a server returns an error to a logoff request, log and error and keep the session on the list.

---
 fs/cifs/connect.c       | 32 +++++++++++++++++++++++++++-----
 fs/cifs/smb2transport.c | 10 ++++++++--
 fs/cifs/transport.c     | 11 +++++++++--
 3 files changed, 44 insertions(+), 9 deletions(-)
fs/cifs/connect.c +27 -5
index a279ffc..ab3cc8d 100644
@@ -2242,6 +2242,8 @@ cifs_find_smb_ses(struct TCP_Server_Info *server, struct smb_vol *vol)
 
        spin_lock(&cifs_tcp_ses_lock);
        list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) {
+               if (ses->status == CifsExiting)
+                       continue;
                if (!match_session(ses, vol))
                        continue;
                ++ses->ses_count;
@@ -2255,24 +2257,44 @@ cifs_find_smb_ses(struct TCP_Server_Info *server, struct smb_vol *vol)
 static void
 cifs_put_smb_ses(struct cifs_ses *ses)
 {
-       unsigned int xid;
+       unsigned int rc, xid;
        struct TCP_Server_Info *server = ses->server;
 
        cifs_dbg(FYI, "%s: ses_count=%d\n", __func__, ses->ses_count);
+
        spin_lock(&cifs_tcp_ses_lock);
+       if (ses->status == CifsExiting) {
+               spin_unlock(&cifs_tcp_ses_lock);
+               return;
+       }
        if (--ses->ses_count > 0) {
                spin_unlock(&cifs_tcp_ses_lock);
                return;
        }
-
-       list_del_init(&ses->smb_ses_list);
+       if (ses->status == CifsGood)
+               ses->status = CifsExiting;
        spin_unlock(&cifs_tcp_ses_lock);
 
-       if (ses->status == CifsGood && server->ops->logoff) {
+       if (ses->status == CifsExiting && server->ops->logoff) {
                xid = get_xid();
-               server->ops->logoff(xid, ses);
+               rc = server->ops->logoff(xid, ses);
                _free_xid(xid);
+
+               if (rc) {
+                       cifs_dbg(VFS, "%s: Session Logoff failure rc=%d\n",
+                               __func__, rc);
+                       spin_lock(&cifs_tcp_ses_lock);
+                       ++ses->ses_count;
+                       ses->status = CifsGood;
+                       spin_unlock(&cifs_tcp_ses_lock);
+                       return;
+               }
        }
+
+       spin_lock(&cifs_tcp_ses_lock);
+       list_del_init(&ses->smb_ses_list);
+       spin_unlock(&cifs_tcp_ses_lock);
+
        sesInfoFree(ses);
        cifs_put_tcp_session(server);
 }
fs/cifs/smb2transport.c +8 -2
index 340abca..ee1963b 100644
@@ -516,13 +516,19 @@ smb2_get_mid_entry(struct cifs_ses *ses, struct smb2_hdr *buf,
                return -EAGAIN;
        }
 
-       if (ses->status != CifsGood) {
-               /* check if SMB2 session is bad because we are setting it up */
+       if (ses->status == CifsNew) {
                if ((buf->Command != SMB2_SESSION_SETUP) &&
                    (buf->Command != SMB2_NEGOTIATE))
                        return -EAGAIN;
                /* else ok - we are setting up session */
        }
+
+       if (ses->status == CifsExiting) {
+               if (buf->Command != SMB2_LOGOFF)
+                       return -EAGAIN;
+               /* else ok - we are shutting down the session */
+       }
+
        *mid = smb2_mid_entry_alloc(buf, ses->server);
        if (*mid == NULL)
                return -ENOMEM;
fs/cifs/transport.c +9 -3
index 800b938..ebb46e3 100644
@@ -431,13 +431,20 @@ static int allocate_mid(struct cifs_ses *ses, struct smb_hdr *in_buf,
                return -EAGAIN;
        }
 
-       if (ses->status != CifsGood) {
-               /* check if SMB session is bad because we are setting it up */
+       if (ses->status == CifsNew) {
                if ((in_buf->Command != SMB_COM_SESSION_SETUP_ANDX) &&
                        (in_buf->Command != SMB_COM_NEGOTIATE))
                        return -EAGAIN;
                /* else ok - we are setting up session */
        }
+
+       if (ses->status == CifsExiting) {
+               /* check if SMB session is bad because we are setting it up */
+               if (in_buf->Command != SMB_COM_LOGOFF_ANDX)
+                       return -EAGAIN;
+               /* else ok - we are shutting down session */
+       }
+
        *ppmidQ = AllocMidQEntry(in_buf, ses->server);
        if (*ppmidQ == NULL)
                return -ENOMEM;
--

1.8.1.2

Signature · 3 lines
Thanks,

Steve

A message that is not in the archive (sent off-list or not yet received): CAH2r5mtFn59CBNYjy7zTyvWBMMaEWtT8ruO8LNrwAshje6TBqg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#5 lore raw

Simplest scenario is when you mount a share with signing enabled.

Right now, when you send a logoff e.g. during unmount, server will send an error in response becuase there is no signature in the request since the session has been removed off of the list before sending the request.

That error logged can raise flag which need not be.
I am not sure what a client is supposed to do when server returns an error in session logoff except send another request, so session remains on the list.

Regards,

Shirish

Quoted 149 lines · Steve French

Presumably this is needed when you mount multiuser to the same server.
Can you describe the problem reproduction scenario?

Quoted 136 lines · On Fri, Oct 4, 2013 at 2:06 PM, <shirishpargaonkar-Re5JQEeQqe8AvxtiuMwx3w@publ…

From: Shirish Pargaonkar <[email protected]>

Send a smb session logoff request before removing smb session off of the list. On a signed smb session, remvoing a session off of the list before sending a logoff request results in server returning an error for lack of smb signature.

If a server returns an error to a logoff request, log and error and keep the session on the list.

---
 fs/cifs/connect.c       | 32 +++++++++++++++++++++++++++-----
 fs/cifs/smb2transport.c | 10 ++++++++--
 fs/cifs/transport.c     | 11 +++++++++--
 3 files changed, 44 insertions(+), 9 deletions(-)
fs/cifs/connect.c +27 -5
index a279ffc..ab3cc8d 100644
@@ -2242,6 +2242,8 @@ cifs_find_smb_ses(struct TCP_Server_Info *server, struct smb_vol *vol)
 
        spin_lock(&cifs_tcp_ses_lock);
        list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) {
+               if (ses->status == CifsExiting)
+                       continue;
                if (!match_session(ses, vol))
                        continue;
                ++ses->ses_count;
@@ -2255,24 +2257,44 @@ cifs_find_smb_ses(struct TCP_Server_Info *server, struct smb_vol *vol)
 static void
 cifs_put_smb_ses(struct cifs_ses *ses)
 {
-       unsigned int xid;
+       unsigned int rc, xid;
        struct TCP_Server_Info *server = ses->server;
 
        cifs_dbg(FYI, "%s: ses_count=%d\n", __func__, ses->ses_count);
+
        spin_lock(&cifs_tcp_ses_lock);
+       if (ses->status == CifsExiting) {
+               spin_unlock(&cifs_tcp_ses_lock);
+               return;
+       }
        if (--ses->ses_count > 0) {
                spin_unlock(&cifs_tcp_ses_lock);
                return;
        }
-
-       list_del_init(&ses->smb_ses_list);
+       if (ses->status == CifsGood)
+               ses->status = CifsExiting;
        spin_unlock(&cifs_tcp_ses_lock);
 
-       if (ses->status == CifsGood && server->ops->logoff) {
+       if (ses->status == CifsExiting && server->ops->logoff) {
                xid = get_xid();
-               server->ops->logoff(xid, ses);
+               rc = server->ops->logoff(xid, ses);
                _free_xid(xid);
+
+               if (rc) {
+                       cifs_dbg(VFS, "%s: Session Logoff failure rc=%d\n",
+                               __func__, rc);
+                       spin_lock(&cifs_tcp_ses_lock);
+                       ++ses->ses_count;
+                       ses->status = CifsGood;
+                       spin_unlock(&cifs_tcp_ses_lock);
+                       return;
+               }
        }
+
+       spin_lock(&cifs_tcp_ses_lock);
+       list_del_init(&ses->smb_ses_list);
+       spin_unlock(&cifs_tcp_ses_lock);
+
        sesInfoFree(ses);
        cifs_put_tcp_session(server);
 }
fs/cifs/smb2transport.c +8 -2
index 340abca..ee1963b 100644
@@ -516,13 +516,19 @@ smb2_get_mid_entry(struct cifs_ses *ses, struct smb2_hdr *buf,
                return -EAGAIN;
        }
 
-       if (ses->status != CifsGood) {
-               /* check if SMB2 session is bad because we are setting it up */
+       if (ses->status == CifsNew) {
                if ((buf->Command != SMB2_SESSION_SETUP) &&
                    (buf->Command != SMB2_NEGOTIATE))
                        return -EAGAIN;
                /* else ok - we are setting up session */
        }
+
+       if (ses->status == CifsExiting) {
+               if (buf->Command != SMB2_LOGOFF)
+                       return -EAGAIN;
+               /* else ok - we are shutting down the session */
+       }
+
        *mid = smb2_mid_entry_alloc(buf, ses->server);
        if (*mid == NULL)
                return -ENOMEM;
fs/cifs/transport.c +9 -3
index 800b938..ebb46e3 100644
@@ -431,13 +431,20 @@ static int allocate_mid(struct cifs_ses *ses, struct smb_hdr *in_buf,
                return -EAGAIN;
        }
 
-       if (ses->status != CifsGood) {
-               /* check if SMB session is bad because we are setting it up */
+       if (ses->status == CifsNew) {
                if ((in_buf->Command != SMB_COM_SESSION_SETUP_ANDX) &&
                        (in_buf->Command != SMB_COM_NEGOTIATE))
                        return -EAGAIN;
                /* else ok - we are setting up session */
        }
+
+       if (ses->status == CifsExiting) {
+               /* check if SMB session is bad because we are setting it up */
+               if (in_buf->Command != SMB_COM_LOGOFF_ANDX)
+                       return -EAGAIN;
+               /* else ok - we are shutting down session */
+       }
+
        *ppmidQ = AllocMidQEntry(in_buf, ses->server);
        if (*ppmidQ == NULL)
                return -ENOMEM;
--
Quoted 2 lines

1.8.1.2

--
Thanks,

Steve

#6 lore raw
In reply to a message not in the archive
Quoted 63 lines · On Fri, 4 Oct 2013 14:06:23 -0500 shirishpargaonkar-Re5JQEeQqe8AvxtiuMwx3w@pub…

From: Shirish Pargaonkar <[email protected]>

Send a smb session logoff request before removing smb session off of the list. On a signed smb session, remvoing a session off of the list before sending a logoff request results in server returning an error for lack of smb signature.

If a server returns an error to a logoff request, log and error and keep the session on the list.

---
 fs/cifs/connect.c       | 32 +++++++++++++++++++++++++++-----
 fs/cifs/smb2transport.c | 10 ++++++++--
 fs/cifs/transport.c     | 11 +++++++++--
 3 files changed, 44 insertions(+), 9 deletions(-)
fs/cifs/connect.c +12 -5
index a279ffc..ab3cc8d 100644
@@ -2242,6 +2242,8 @@ cifs_find_smb_ses(struct TCP_Server_Info *server, struct smb_vol *vol)
 
 	spin_lock(&cifs_tcp_ses_lock);
 	list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) {
+		if (ses->status == CifsExiting)
+			continue;
 		if (!match_session(ses, vol))
 			continue;
 		++ses->ses_count;
@@ -2255,24 +2257,44 @@ cifs_find_smb_ses(struct TCP_Server_Info *server, struct smb_vol *vol)
 static void
 cifs_put_smb_ses(struct cifs_ses *ses)
 {
-	unsigned int xid;
+	unsigned int rc, xid;
 	struct TCP_Server_Info *server = ses->server;
 
 	cifs_dbg(FYI, "%s: ses_count=%d\n", __func__, ses->ses_count);
+
 	spin_lock(&cifs_tcp_ses_lock);
+	if (ses->status == CifsExiting) {
+		spin_unlock(&cifs_tcp_ses_lock);
+		return;
+	}
 	if (--ses->ses_count > 0) {
 		spin_unlock(&cifs_tcp_ses_lock);
 		return;
 	}
-
-	list_del_init(&ses->smb_ses_list);
+	if (ses->status == CifsGood)
+		ses->status = CifsExiting;
 	spin_unlock(&cifs_tcp_ses_lock);
 
-	if (ses->status == CifsGood && server->ops->logoff) {
+	if (ses->status == CifsExiting && server->ops->logoff) {
 		xid = get_xid();
-		server->ops->logoff(xid, ses);
+		rc = server->ops->logoff(xid, ses);
 		_free_xid(xid);

fs/cifs/connect.c cifs_find_smb_ses(struct TCP_Server_Info *server, struct smb_vol *vol) · line 2291

Quoted 10 lines
fs/cifs/connect.c +10 -0
+
+		if (rc) {
+			cifs_dbg(VFS, "%s: Session Logoff failure rc=%d\n",
+				__func__, rc);
+			spin_lock(&cifs_tcp_ses_lock);
+			++ses->ses_count;
+			ses->status = CifsGood;
+			spin_unlock(&cifs_tcp_ses_lock);
+			return;
+		}

This looks wrong.

With this patch, if ->logoff returns an error we'll end up just leaking this reference. What's going to eventually clean it up?

Quoted 62 lines
fs/cifs/connect.c +5 -0
 	}
+
+	spin_lock(&cifs_tcp_ses_lock);
+	list_del_init(&ses->smb_ses_list);
+	spin_unlock(&cifs_tcp_ses_lock);
+
 	sesInfoFree(ses);
 	cifs_put_tcp_session(server);
 }
fs/cifs/smb2transport.c +8 -2
index 340abca..ee1963b 100644
@@ -516,13 +516,19 @@ smb2_get_mid_entry(struct cifs_ses *ses, struct smb2_hdr *buf,
 		return -EAGAIN;
 	}
 
-	if (ses->status != CifsGood) {
-		/* check if SMB2 session is bad because we are setting it up */
+	if (ses->status == CifsNew) {
 		if ((buf->Command != SMB2_SESSION_SETUP) &&
 		    (buf->Command != SMB2_NEGOTIATE))
 			return -EAGAIN;
 		/* else ok - we are setting up session */
 	}
+
+	if (ses->status == CifsExiting) {
+		if (buf->Command != SMB2_LOGOFF)
+			return -EAGAIN;
+		/* else ok - we are shutting down the session */
+	}
+
 	*mid = smb2_mid_entry_alloc(buf, ses->server);
 	if (*mid == NULL)
 		return -ENOMEM;
fs/cifs/transport.c +9 -2
index 800b938..ebb46e3 100644
@@ -431,13 +431,20 @@ static int allocate_mid(struct cifs_ses *ses, struct smb_hdr *in_buf,
 		return -EAGAIN;
 	}
 
-	if (ses->status != CifsGood) {
-		/* check if SMB session is bad because we are setting it up */
+	if (ses->status == CifsNew) {
 		if ((in_buf->Command != SMB_COM_SESSION_SETUP_ANDX) &&
 			(in_buf->Command != SMB_COM_NEGOTIATE))
 			return -EAGAIN;
 		/* else ok - we are setting up session */
 	}
+
+	if (ses->status == CifsExiting) {
+		/* check if SMB session is bad because we are setting it up */
+		if (in_buf->Command != SMB_COM_LOGOFF_ANDX)
+			return -EAGAIN;
+		/* else ok - we are shutting down session */
+	}
+
 	*ppmidQ = AllocMidQEntry(in_buf, ses->server);
 	if (*ppmidQ == NULL)
 		return -ENOMEM;
Signature · 1 line
Jeff Layton <[email protected]>