fs/cifs: correctly to anonymous authentication via NTLMSSP
authorStefan Metzmacher <metze@samba.org>
Tue, 3 May 2016 08:52:30 +0000 (10:52 +0200)
committerBen Hutchings <ben@decadent.org.uk>
Mon, 22 Aug 2016 21:37:11 +0000 (22:37 +0100)
commit cfda35d98298131bf38fbad3ce4cd5ecb3cf18db upstream.

See [MS-NLMP] 3.2.5.1.2 Server Receives an AUTHENTICATE_MESSAGE from the Client:

   ...
   Set NullSession to FALSE
   If (AUTHENTICATE_MESSAGE.UserNameLen == 0 AND
      AUTHENTICATE_MESSAGE.NtChallengeResponse.Length == 0 AND
      (AUTHENTICATE_MESSAGE.LmChallengeResponse == Z(1)
       OR
       AUTHENTICATE_MESSAGE.LmChallengeResponse.Length == 0))
       -- Special case: client requested anonymous authentication
       Set NullSession to TRUE
   ...

Only server which map unknown users to guest will allow
access using a non-null NTChallengeResponse.

For Samba it's the "map to guest = bad user" option.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=11913

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Signed-off-by: Steve French <smfrench@gmail.com>
[bwh: Backported to 3.2: keep using cERROR()]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
fs/cifs/sess.c

index d362626..e8bc77d 100644 (file)
@@ -480,19 +480,27 @@ static int build_ntlmssp_auth_blob(unsigned char *pbuffer,
        sec_blob->LmChallengeResponse.MaximumLength = 0;
 
        sec_blob->NtChallengeResponse.BufferOffset = cpu_to_le32(tmp - pbuffer);
-       rc = setup_ntlmv2_rsp(ses, nls_cp);
-       if (rc) {
-               cERROR(1, "Error %d during NTLMSSP authentication", rc);
-               goto setup_ntlmv2_ret;
-       }
-       memcpy(tmp, ses->auth_key.response + CIFS_SESS_KEY_SIZE,
-                       ses->auth_key.len - CIFS_SESS_KEY_SIZE);
-       tmp += ses->auth_key.len - CIFS_SESS_KEY_SIZE;
+       if (ses->user_name != NULL) {
+               rc = setup_ntlmv2_rsp(ses, nls_cp);
+               if (rc) {
+                       cERROR(1, "Error %d during NTLMSSP authentication", rc);
+                       goto setup_ntlmv2_ret;
+               }
+               memcpy(tmp, ses->auth_key.response + CIFS_SESS_KEY_SIZE,
+                               ses->auth_key.len - CIFS_SESS_KEY_SIZE);
+               tmp += ses->auth_key.len - CIFS_SESS_KEY_SIZE;
 
-       sec_blob->NtChallengeResponse.Length =
-                       cpu_to_le16(ses->auth_key.len - CIFS_SESS_KEY_SIZE);
-       sec_blob->NtChallengeResponse.MaximumLength =
-                       cpu_to_le16(ses->auth_key.len - CIFS_SESS_KEY_SIZE);
+               sec_blob->NtChallengeResponse.Length =
+                               cpu_to_le16(ses->auth_key.len - CIFS_SESS_KEY_SIZE);
+               sec_blob->NtChallengeResponse.MaximumLength =
+                               cpu_to_le16(ses->auth_key.len - CIFS_SESS_KEY_SIZE);
+       } else {
+               /*
+                * don't send an NT Response for anonymous access
+                */
+               sec_blob->NtChallengeResponse.Length = 0;
+               sec_blob->NtChallengeResponse.MaximumLength = 0;
+       }
 
        if (ses->domainName == NULL) {
                sec_blob->DomainName.BufferOffset = cpu_to_le32(tmp - pbuffer);