diff mbox series

[bionic:linux-azure-4.15,1/2] CIFS: Only send SMB2_NEGOTIATE command on new TCP connections

Message ID 20201026143443.2526723-2-marcelo.cerri@canonical.com
State New
Headers show
Series LP:#1882268 - [linux-azure] Request for two CIFS commits in 16.04 | expand

Commit Message

Marcelo Henrique Cerri Oct. 26, 2020, 2:34 p.m. UTC
From: Pavel Shilovsky <piastryyy@gmail.com>

BugLink: https://bugs.launchpad.net/bugs/1882268

Do not allow commands other than SMB2_NEGOTIATE to be sent over
recently established TCP connections. Return -EAGAIN to let upper
layers handle it properly.

Signed-off-by: Pavel Shilovsky <pshilov@microsoft.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
(cherry picked from commit 2084ed57167c3e39f99ac2bb19f19e85321d2169)
Signed-off-by: Marcelo Henrique Cerri <marcelo.cerri@canonical.com>
---
 fs/cifs/smb2transport.c | 8 ++++++++
 1 file changed, 8 insertions(+)
diff mbox series

Patch

diff --git a/fs/cifs/smb2transport.c b/fs/cifs/smb2transport.c
index a41fc4a63a59..dd601cd34025 100644
--- a/fs/cifs/smb2transport.c
+++ b/fs/cifs/smb2transport.c
@@ -579,6 +579,10 @@  smb2_get_mid_entry(struct cifs_ses *ses, struct smb2_sync_hdr *shdr,
 		return -EAGAIN;
 	}
 
+	if (ses->server->tcpStatus == CifsNeedNegotiate &&
+	   shdr->Command != SMB2_NEGOTIATE)
+		return -EAGAIN;
+
 	if (ses->status == CifsNew) {
 		if ((shdr->Command != SMB2_SESSION_SETUP) &&
 		    (shdr->Command != SMB2_NEGOTIATE))
@@ -658,6 +662,10 @@  smb2_setup_async_request(struct TCP_Server_Info *server, struct smb_rqst *rqst)
 			(struct smb2_sync_hdr *)rqst->rq_iov[1].iov_base;
 	struct mid_q_entry *mid;
 
+	if (server->tcpStatus == CifsNeedNegotiate &&
+	   shdr->Command != SMB2_NEGOTIATE)
+		return ERR_PTR(-EAGAIN);
+
 	smb2_seq_num_into_buf(server, shdr);
 
 	mid = smb2_mid_entry_alloc(shdr, server);