Skip to contentSkip to conversation

cifs: Support NTLM2 session security during NTLMSSP authentication [try #3]

PATCH In review [email protected] 2 participants 4 messages Dec 9, 2010 – Dec 10, 2010 3 messages not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cifs: Support NTLM2 session security during NTLMSSP authentication [try #3]

From: Shirish Pargaonkar <[email protected]>

Indicate to the server a capability of NTLM2 session security (NTLM2 Key) during ntlmssp protocol exchange in one of the bits of the flags field. If server supports this capability, send NTLM2 key even if signing is not required on the server.

If the server requires signing, the session keys exchanged for NTLMv2 and NTLM2 session security in auth packet of the nlmssp exchange are same.

Send the same flags in authenticate message (type 3) that client sent in negotiate message (type 1).

---
 fs/cifs/sess.c |   13 +++++++------
 1 files changed, 7 insertions(+), 6 deletions(-)
fs/cifs/sess.c +7 -6
index 7b01d3f..ea39f3f 100644
@@ -437,7 +437,7 @@ static void build_ntlmssp_negotiate_blob(unsigned char *pbuffer,
 	/* BB is NTLMV2 session security format easier to use here? */
 	flags = NTLMSSP_NEGOTIATE_56 |	NTLMSSP_REQUEST_TARGET |
 		NTLMSSP_NEGOTIATE_128 | NTLMSSP_NEGOTIATE_UNICODE |
-		NTLMSSP_NEGOTIATE_NTLM;
+		NTLMSSP_NEGOTIATE_NTLM | NTLMSSP_NEGOTIATE_EXTENDED_SEC;
 	if (ses->server->secMode &
 			(SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED)) {
 		flags |= NTLMSSP_NEGOTIATE_SIGN;
@@ -446,7 +446,7 @@ static void build_ntlmssp_negotiate_blob(unsigned char *pbuffer,
 				NTLMSSP_NEGOTIATE_EXTENDED_SEC;
 	}
 
-	sec_blob->NegotiateFlags |= cpu_to_le32(flags);
+	sec_blob->NegotiateFlags = cpu_to_le32(flags);
 
 	sec_blob->WorkstationName.BufferOffset = 0;
 	sec_blob->WorkstationName.Length = 0;
@@ -477,7 +477,7 @@ static int build_ntlmssp_auth_blob(unsigned char *pbuffer,
 	flags = NTLMSSP_NEGOTIATE_56 |
 		NTLMSSP_REQUEST_TARGET | NTLMSSP_NEGOTIATE_TARGET_INFO |
 		NTLMSSP_NEGOTIATE_128 | NTLMSSP_NEGOTIATE_UNICODE |
-		NTLMSSP_NEGOTIATE_NTLM;
+		NTLMSSP_NEGOTIATE_NTLM | NTLMSSP_NEGOTIATE_EXTENDED_SEC;
 	if (ses->server->secMode &
 	   (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED))
 		flags |= NTLMSSP_NEGOTIATE_SIGN;
@@ -485,7 +485,7 @@ static int build_ntlmssp_auth_blob(unsigned char *pbuffer,
 		flags |= NTLMSSP_NEGOTIATE_ALWAYS_SIGN;
 
 	tmp = pbuffer + sizeof(AUTHENTICATE_MESSAGE);
-	sec_blob->NegotiateFlags |= cpu_to_le32(flags);
+	sec_blob->NegotiateFlags = cpu_to_le32(flags);
 
 	sec_blob->LmChallengeResponse.BufferOffset =
 				cpu_to_le32(sizeof(AUTHENTICATE_MESSAGE));
@@ -544,8 +544,9 @@ static int build_ntlmssp_auth_blob(unsigned char *pbuffer,
 	sec_blob->WorkstationName.MaximumLength = 0;
 	tmp += 2;
 
-	if ((ses->ntlmssp->server_flags & NTLMSSP_NEGOTIATE_KEY_XCH) &&
-			!calc_seckey(ses)) {
+	if (((ses->ntlmssp->server_flags & NTLMSSP_NEGOTIATE_KEY_XCH) ||
+		(ses->ntlmssp->server_flags & NTLMSSP_NEGOTIATE_EXTENDED_SEC))
+			&& !calc_seckey(ses)) {
 		memcpy(tmp, ses->ntlmssp->ciphertext, CIFS_CPHTXT_SIZE);
 		sec_blob->SessionKey.BufferOffset = cpu_to_le32(tmp - pbuffer);
 		sec_blob->SessionKey.Length = cpu_to_le16(CIFS_CPHTXT_SIZE);
Signature · 1 line
1.6.0.2

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

#2 lore raw
Quoted 35 lines · On Thu, 9 Dec 2010 11:58:11 -0600 shirishpargaonkar-Re5JQEeQqe8AvxtiuMwx3w@pub…

From: Shirish Pargaonkar <[email protected]>

Indicate to the server a capability of NTLM2 session security (NTLM2 Key) during ntlmssp protocol exchange in one of the bits of the flags field. If server supports this capability, send NTLM2 key even if signing is not required on the server.

If the server requires signing, the session keys exchanged for NTLMv2 and NTLM2 session security in auth packet of the nlmssp exchange are same.

Send the same flags in authenticate message (type 3) that client sent in negotiate message (type 1).

---
 fs/cifs/sess.c |   13 +++++++------
 1 files changed, 7 insertions(+), 6 deletions(-)
fs/cifs/sess.c +1 -1
index 7b01d3f..ea39f3f 100644
@@ -437,7 +437,7 @@ static void build_ntlmssp_negotiate_blob(unsigned char *pbuffer,
 	/* BB is NTLMV2 session security format easier to use here? */
 	flags = NTLMSSP_NEGOTIATE_56 |	NTLMSSP_REQUEST_TARGET |
 		NTLMSSP_NEGOTIATE_128 | NTLMSSP_NEGOTIATE_UNICODE |
-		NTLMSSP_NEGOTIATE_NTLM;
+		NTLMSSP_NEGOTIATE_NTLM | NTLMSSP_NEGOTIATE_EXTENDED_SEC;
 	if (ses->server->secMode &
 			(SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED)) {
 		flags |= NTLMSSP_NEGOTIATE_SIGN;

fs/cifs/sess.c static void build_ntlmssp_negotiate_blob(unsigned char *pbuffer, · line 450

Quoted 6 lines
fs/cifs/sess.c +1 -1
@@ -446,7 +446,7 @@ static void build_ntlmssp_negotiate_blob(unsigned char *pbuffer,
 				NTLMSSP_NEGOTIATE_EXTENDED_SEC;
 	}
 
-	sec_blob->NegotiateFlags |= cpu_to_le32(flags);
+	sec_blob->NegotiateFlags = cpu_to_le32(flags);
 

Your earlier emails about seeing the POISON_INUSE value in this struct worry me a bit. Maybe we ought to zero out the sec_blob before use?

These aren't exactly hot codepaths so we can afford to do a little defensive coding here. Ditto for this buffer in the other phases of NTLMSSP negotiation too.

Thoughts?

Quoted 32 lines
fs/cifs/sess.c +5 -4
 	sec_blob->WorkstationName.BufferOffset = 0;
 	sec_blob->WorkstationName.Length = 0;
@@ -477,7 +477,7 @@ static int build_ntlmssp_auth_blob(unsigned char *pbuffer,
 	flags = NTLMSSP_NEGOTIATE_56 |
 		NTLMSSP_REQUEST_TARGET | NTLMSSP_NEGOTIATE_TARGET_INFO |
 		NTLMSSP_NEGOTIATE_128 | NTLMSSP_NEGOTIATE_UNICODE |
-		NTLMSSP_NEGOTIATE_NTLM;
+		NTLMSSP_NEGOTIATE_NTLM | NTLMSSP_NEGOTIATE_EXTENDED_SEC;
 	if (ses->server->secMode &
 	   (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED))
 		flags |= NTLMSSP_NEGOTIATE_SIGN;
@@ -485,7 +485,7 @@ static int build_ntlmssp_auth_blob(unsigned char *pbuffer,
 		flags |= NTLMSSP_NEGOTIATE_ALWAYS_SIGN;
 
 	tmp = pbuffer + sizeof(AUTHENTICATE_MESSAGE);
-	sec_blob->NegotiateFlags |= cpu_to_le32(flags);
+	sec_blob->NegotiateFlags = cpu_to_le32(flags);
 
 	sec_blob->LmChallengeResponse.BufferOffset =
 				cpu_to_le32(sizeof(AUTHENTICATE_MESSAGE));
@@ -544,8 +544,9 @@ static int build_ntlmssp_auth_blob(unsigned char *pbuffer,
 	sec_blob->WorkstationName.MaximumLength = 0;
 	tmp += 2;
 
-	if ((ses->ntlmssp->server_flags & NTLMSSP_NEGOTIATE_KEY_XCH) &&
-			!calc_seckey(ses)) {
+	if (((ses->ntlmssp->server_flags & NTLMSSP_NEGOTIATE_KEY_XCH) ||
+		(ses->ntlmssp->server_flags & NTLMSSP_NEGOTIATE_EXTENDED_SEC))
+			&& !calc_seckey(ses)) {
 		memcpy(tmp, ses->ntlmssp->ciphertext, CIFS_CPHTXT_SIZE);
 		sec_blob->SessionKey.BufferOffset = cpu_to_le32(tmp - pbuffer);
 		sec_blob->SessionKey.Length = cpu_to_le16(CIFS_CPHTXT_SIZE);
Signature · 1 line
Jeff Layton <[email protected]>

A message that is not in the archive (sent off-list or not yet received): 20101209162709.57cc5019-9yPaYZwiELC+kQycOl6kW4xkIHaj4LzF@public.gmane.org

#4 lore raw
Quoted 78 lines · Jeff Layton
Quoted 35 lines · On Thu,  9 Dec 2010 11:58:11 -0600 shirishpargaonkar-Re5JQEeQqe8AvxtiuMwx3w@pub…

From: Shirish Pargaonkar <[email protected]>

Indicate to the server a capability of NTLM2 session security (NTLM2 Key) during ntlmssp protocol exchange in one of the bits of the flags field. If server supports this capability, send NTLM2 key even if signing is not required on the server.

If the server requires signing, the session keys exchanged for NTLMv2 and NTLM2 session security in auth packet of the nlmssp exchange are same.

Send the same flags in authenticate message (type 3) that client sent in negotiate message (type 1).

---
 fs/cifs/sess.c |   13 +++++++------

 1 files changed, 7 insertions(+), 6 deletions(-)
fs/cifs/sess.c +0 -0
index 7b01d3f..ea39f3f 100644
@@ -437,7 +437,7 @@ static void build_ntlmssp_negotiate_blob(unsigned char *pbuffer,
       /* BB is NTLMV2 session security format easier to use here? */

      flags = NTLMSSP_NEGOTIATE_56 |  NTLMSSP_REQUEST_TARGET | NTLMSSP_NEGOTIATE_128 | NTLMSSP_NEGOTIATE_UNICODE |
-             NTLMSSP_NEGOTIATE_NTLM;
+             NTLMSSP_NEGOTIATE_NTLM | NTLMSSP_NEGOTIATE_EXTENDED_SEC; if (ses->server->secMode &
                      (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED)) { flags |= NTLMSSP_NEGOTIATE_SIGN;

fs/cifs/sess.c static void build_ntlmssp_negotiate_blob(unsigned char *pbuffer, · line 450

Quoted 6 lines
fs/cifs/sess.c +1 -1
@@ -446,7 +446,7 @@ static void build_ntlmssp_negotiate_blob(unsigned char *pbuffer,
                               NTLMSSP_NEGOTIATE_EXTENDED_SEC;
       }
 
-     sec_blob->NegotiateFlags |= cpu_to_le32(flags);
+     sec_blob->NegotiateFlags = cpu_to_le32(flags);
 

Your earlier emails about seeing the POISON_INUSE value in this struct worry me a bit. Maybe we ought to zero out the sec_blob before use?

These aren't exactly hot codepaths so we can afford to do a little defensive coding here. Ditto for this buffer in the other phases of NTLMSSP negotiation too.

Thoughts?

Quoted 24 lines
fs/cifs/sess.c +0 -0
       sec_blob->WorkstationName.BufferOffset = 0;
       sec_blob->WorkstationName.Length = 0;
@@ -477,7 +477,7 @@ static int build_ntlmssp_auth_blob(unsigned char *pbuffer,

      flags = NTLMSSP_NEGOTIATE_56 |
              NTLMSSP_REQUEST_TARGET | NTLMSSP_NEGOTIATE_TARGET_INFO | NTLMSSP_NEGOTIATE_128 | NTLMSSP_NEGOTIATE_UNICODE |
-             NTLMSSP_NEGOTIATE_NTLM;
+             NTLMSSP_NEGOTIATE_NTLM | NTLMSSP_NEGOTIATE_EXTENDED_SEC; if (ses->server->secMode &
         (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED)) flags |= NTLMSSP_NEGOTIATE_SIGN;

fs/cifs/sess.c +1 -1
@@ -485,7 +485,7 @@ static int build_ntlmssp_auth_blob(unsigned char *pbuffer,
               flags |= NTLMSSP_NEGOTIATE_ALWAYS_SIGN;
 
       tmp = pbuffer + sizeof(AUTHENTICATE_MESSAGE);
-     sec_blob->NegotiateFlags |= cpu_to_le32(flags);
+     sec_blob->NegotiateFlags = cpu_to_le32(flags);
 

      sec_blob->LmChallengeResponse.BufferOffset = cpu_to_le32(sizeof(AUTHENTICATE_MESSAGE));

fs/cifs/sess.c +0 -0
@@ -544,8 +544,9 @@ static int build_ntlmssp_auth_blob(unsigned char *pbuffer,
       sec_blob->WorkstationName.MaximumLength = 0;
       tmp += 2;
 
Quoted 14 lines

fs/cifs/sess.c static int build_ntlmssp_auth_blob(unsigned char *pbuffer, · line 552

Quoted 8 lines
fs/cifs/sess.c +3 -2
-     if ((ses->ntlmssp->server_flags & NTLMSSP_NEGOTIATE_KEY_XCH) &&
-                     !calc_seckey(ses)) {
+     if (((ses->ntlmssp->server_flags & NTLMSSP_NEGOTIATE_KEY_XCH) ||
+             (ses->ntlmssp->server_flags & NTLMSSP_NEGOTIATE_EXTENDED_SEC))
+                     && !calc_seckey(ses)) {
               memcpy(tmp, ses->ntlmssp->ciphertext, CIFS_CPHTXT_SIZE);
               sec_blob->SessionKey.BufferOffset = cpu_to_le32(tmp - pbuffer);
               sec_blob->SessionKey.Length = cpu_to_le16(CIFS_CPHTXT_SIZE);

--
Jeff Layton <[email protected]>

Yes. I think that would be safe thing to do. I will look into wireshark trace again
just to see what other fields contained POISON_INUSE besides flags field when either of the requests (type 1 and type 3 of ntlmssp exchange) were sent (such as session key) and resubmit this patch as well. This code gets called may be once per smb connection so it does not get exercised often, as you stated.

Regards,

Shirish

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

#6 lore raw
Quoted 94 lines · On Fri, 10 Dec 2010 07:07:23 -0600 Shirish Pargaonkar…
Quoted 78 lines · Jeff Layton
Quoted 35 lines · On Thu,  9 Dec 2010 11:58:11 -0600 shirishpargaonkar-Re5JQEeQqe8AvxtiuMwx3w@pub…

From: Shirish Pargaonkar <[email protected]>

Indicate to the server a capability of NTLM2 session security (NTLM2 Key) during ntlmssp protocol exchange in one of the bits of the flags field. If server supports this capability, send NTLM2 key even if signing is not required on the server.

If the server requires signing, the session keys exchanged for NTLMv2 and NTLM2 session security in auth packet of the nlmssp exchange are same.

Send the same flags in authenticate message (type 3) that client sent in negotiate message (type 1).

---
 fs/cifs/sess.c |   13 +++++++------

 1 files changed, 7 insertions(+), 6 deletions(-)
fs/cifs/sess.c +0 -0
index 7b01d3f..ea39f3f 100644
@@ -437,7 +437,7 @@ static void build_ntlmssp_negotiate_blob(unsigned char *pbuffer,
       /* BB is NTLMV2 session security format easier to use here? */

      flags = NTLMSSP_NEGOTIATE_56 |  NTLMSSP_REQUEST_TARGET | NTLMSSP_NEGOTIATE_128 | NTLMSSP_NEGOTIATE_UNICODE |
-             NTLMSSP_NEGOTIATE_NTLM;
+             NTLMSSP_NEGOTIATE_NTLM | NTLMSSP_NEGOTIATE_EXTENDED_SEC; if (ses->server->secMode &
                      (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED)) { flags |= NTLMSSP_NEGOTIATE_SIGN;

fs/cifs/sess.c static void build_ntlmssp_negotiate_blob(unsigned char *pbuffer, · line 450

Quoted 6 lines
fs/cifs/sess.c +1 -1
@@ -446,7 +446,7 @@ static void build_ntlmssp_negotiate_blob(unsigned char *pbuffer,
                               NTLMSSP_NEGOTIATE_EXTENDED_SEC;
       }
 
-     sec_blob->NegotiateFlags |= cpu_to_le32(flags);
+     sec_blob->NegotiateFlags = cpu_to_le32(flags);
 

Your earlier emails about seeing the POISON_INUSE value in this struct worry me a bit. Maybe we ought to zero out the sec_blob before use?

These aren't exactly hot codepaths so we can afford to do a little defensive coding here. Ditto for this buffer in the other phases of NTLMSSP negotiation too.

Thoughts?

Quoted 24 lines
fs/cifs/sess.c +0 -0
       sec_blob->WorkstationName.BufferOffset = 0;
       sec_blob->WorkstationName.Length = 0;
@@ -477,7 +477,7 @@ static int build_ntlmssp_auth_blob(unsigned char *pbuffer,

      flags = NTLMSSP_NEGOTIATE_56 |
              NTLMSSP_REQUEST_TARGET | NTLMSSP_NEGOTIATE_TARGET_INFO | NTLMSSP_NEGOTIATE_128 | NTLMSSP_NEGOTIATE_UNICODE |
-             NTLMSSP_NEGOTIATE_NTLM;
+             NTLMSSP_NEGOTIATE_NTLM | NTLMSSP_NEGOTIATE_EXTENDED_SEC; if (ses->server->secMode &
         (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED)) flags |= NTLMSSP_NEGOTIATE_SIGN;

fs/cifs/sess.c +1 -1
@@ -485,7 +485,7 @@ static int build_ntlmssp_auth_blob(unsigned char *pbuffer,
               flags |= NTLMSSP_NEGOTIATE_ALWAYS_SIGN;
 
       tmp = pbuffer + sizeof(AUTHENTICATE_MESSAGE);
-     sec_blob->NegotiateFlags |= cpu_to_le32(flags);
+     sec_blob->NegotiateFlags = cpu_to_le32(flags);
 

      sec_blob->LmChallengeResponse.BufferOffset = cpu_to_le32(sizeof(AUTHENTICATE_MESSAGE));

fs/cifs/sess.c +0 -0
@@ -544,8 +544,9 @@ static int build_ntlmssp_auth_blob(unsigned char *pbuffer,
       sec_blob->WorkstationName.MaximumLength = 0;
       tmp += 2;
 
Quoted 14 lines

fs/cifs/sess.c static int build_ntlmssp_auth_blob(unsigned char *pbuffer, · line 552

Quoted 8 lines
fs/cifs/sess.c +3 -2
-     if ((ses->ntlmssp->server_flags & NTLMSSP_NEGOTIATE_KEY_XCH) &&
-                     !calc_seckey(ses)) {
+     if (((ses->ntlmssp->server_flags & NTLMSSP_NEGOTIATE_KEY_XCH) ||
+             (ses->ntlmssp->server_flags & NTLMSSP_NEGOTIATE_EXTENDED_SEC))
+                     && !calc_seckey(ses)) {
               memcpy(tmp, ses->ntlmssp->ciphertext, CIFS_CPHTXT_SIZE);
               sec_blob->SessionKey.BufferOffset = cpu_to_le32(tmp - pbuffer);
               sec_blob->SessionKey.Length = cpu_to_le16(CIFS_CPHTXT_SIZE);

--
Jeff Layton <[email protected]>

Quoted 8 lines

Yes. I think that would be safe thing to do. I will look into wireshark trace again
just to see what other fields contained POISON_INUSE besides flags field when either of the requests (type 1 and type 3 of ntlmssp exchange) were sent (such as session key) and resubmit this patch as well. This code gets called may be once per smb connection so it does not get exercised often, as you stated.

We have to consider that wherever you see POISON_INUSE, it could just as easily be leftover data from earlier use of the page. We really need to take great care not to stick unintialized data out on the wire. There's no telling what it might contain.

It may even be best to just to memset all buffers to zero in smb_init and small_smb_init. Those functions look like they do part of the buffer now, but it seems a little dangerous to leave the rest unset.

Signature · 1 line
Jeff Layton <[email protected]>