diff options
| -rw-r--r-- | fs/cifs/Kconfig | 2 | ||||
| -rw-r--r-- | fs/cifs/asn1.c | 6 | ||||
| -rw-r--r-- | fs/cifs/cifs_unicode.h | 18 | ||||
| -rw-r--r-- | fs/cifs/cifs_uniupr.h | 16 | ||||
| -rw-r--r-- | fs/cifs/cifsencrypt.c | 475 | ||||
| -rw-r--r-- | fs/cifs/cifsglob.h | 25 | ||||
| -rw-r--r-- | fs/cifs/cifspdu.h | 7 | ||||
| -rw-r--r-- | fs/cifs/cifsproto.h | 12 | ||||
| -rw-r--r-- | fs/cifs/cifssmb.c | 13 | ||||
| -rw-r--r-- | fs/cifs/connect.c | 17 | ||||
| -rw-r--r-- | fs/cifs/dir.c | 157 | ||||
| -rw-r--r-- | fs/cifs/file.c | 3 | ||||
| -rw-r--r-- | fs/cifs/ntlmssp.h | 13 | ||||
| -rw-r--r-- | fs/cifs/sess.c | 131 | ||||
| -rw-r--r-- | fs/cifs/transport.c | 6 |
15 files changed, 622 insertions, 279 deletions
diff --git a/fs/cifs/Kconfig b/fs/cifs/Kconfig index 917b7d449bb2..0da1debd499d 100644 --- a/fs/cifs/Kconfig +++ b/fs/cifs/Kconfig | |||
| @@ -2,6 +2,8 @@ config CIFS | |||
| 2 | tristate "CIFS support (advanced network filesystem, SMBFS successor)" | 2 | tristate "CIFS support (advanced network filesystem, SMBFS successor)" |
| 3 | depends on INET | 3 | depends on INET |
| 4 | select NLS | 4 | select NLS |
| 5 | select CRYPTO_MD5 | ||
| 6 | select CRYPTO_ARC4 | ||
| 5 | help | 7 | help |
| 6 | This is the client VFS module for the Common Internet File System | 8 | This is the client VFS module for the Common Internet File System |
| 7 | (CIFS) protocol which is the successor to the Server Message Block | 9 | (CIFS) protocol which is the successor to the Server Message Block |
diff --git a/fs/cifs/asn1.c b/fs/cifs/asn1.c index cfd1ce34e0bc..21f0fbd86989 100644 --- a/fs/cifs/asn1.c +++ b/fs/cifs/asn1.c | |||
| @@ -597,13 +597,13 @@ decode_negTokenInit(unsigned char *security_blob, int length, | |||
| 597 | if (compare_oid(oid, oidlen, MSKRB5_OID, | 597 | if (compare_oid(oid, oidlen, MSKRB5_OID, |
| 598 | MSKRB5_OID_LEN)) | 598 | MSKRB5_OID_LEN)) |
| 599 | server->sec_mskerberos = true; | 599 | server->sec_mskerberos = true; |
| 600 | else if (compare_oid(oid, oidlen, KRB5U2U_OID, | 600 | if (compare_oid(oid, oidlen, KRB5U2U_OID, |
| 601 | KRB5U2U_OID_LEN)) | 601 | KRB5U2U_OID_LEN)) |
| 602 | server->sec_kerberosu2u = true; | 602 | server->sec_kerberosu2u = true; |
| 603 | else if (compare_oid(oid, oidlen, KRB5_OID, | 603 | if (compare_oid(oid, oidlen, KRB5_OID, |
| 604 | KRB5_OID_LEN)) | 604 | KRB5_OID_LEN)) |
| 605 | server->sec_kerberos = true; | 605 | server->sec_kerberos = true; |
| 606 | else if (compare_oid(oid, oidlen, NTLMSSP_OID, | 606 | if (compare_oid(oid, oidlen, NTLMSSP_OID, |
| 607 | NTLMSSP_OID_LEN)) | 607 | NTLMSSP_OID_LEN)) |
| 608 | server->sec_ntlmssp = true; | 608 | server->sec_ntlmssp = true; |
| 609 | 609 | ||
diff --git a/fs/cifs/cifs_unicode.h b/fs/cifs/cifs_unicode.h index 650638275a6f..7fe6b52df507 100644 --- a/fs/cifs/cifs_unicode.h +++ b/fs/cifs/cifs_unicode.h | |||
| @@ -30,6 +30,8 @@ | |||
| 30 | * This is a compressed table of upper and lower case conversion. | 30 | * This is a compressed table of upper and lower case conversion. |
| 31 | * | 31 | * |
| 32 | */ | 32 | */ |
| 33 | #ifndef _CIFS_UNICODE_H | ||
| 34 | #define _CIFS_UNICODE_H | ||
| 33 | 35 | ||
| 34 | #include <asm/byteorder.h> | 36 | #include <asm/byteorder.h> |
| 35 | #include <linux/types.h> | 37 | #include <linux/types.h> |
| @@ -67,8 +69,8 @@ extern const struct UniCaseRange CifsUniUpperRange[]; | |||
| 67 | #endif /* UNIUPR_NOUPPER */ | 69 | #endif /* UNIUPR_NOUPPER */ |
| 68 | 70 | ||
| 69 | #ifndef UNIUPR_NOLOWER | 71 | #ifndef UNIUPR_NOLOWER |
| 70 | extern signed char UniLowerTable[512]; | 72 | extern signed char CifsUniLowerTable[512]; |
| 71 | extern struct UniCaseRange UniLowerRange[]; | 73 | extern const struct UniCaseRange CifsUniLowerRange[]; |
| 72 | #endif /* UNIUPR_NOLOWER */ | 74 | #endif /* UNIUPR_NOLOWER */ |
| 73 | 75 | ||
| 74 | #ifdef __KERNEL__ | 76 | #ifdef __KERNEL__ |
| @@ -337,15 +339,15 @@ UniStrupr(register wchar_t *upin) | |||
| 337 | * UniTolower: Convert a unicode character to lower case | 339 | * UniTolower: Convert a unicode character to lower case |
| 338 | */ | 340 | */ |
| 339 | static inline wchar_t | 341 | static inline wchar_t |
| 340 | UniTolower(wchar_t uc) | 342 | UniTolower(register wchar_t uc) |
| 341 | { | 343 | { |
| 342 | register struct UniCaseRange *rp; | 344 | register const struct UniCaseRange *rp; |
| 343 | 345 | ||
| 344 | if (uc < sizeof(UniLowerTable)) { | 346 | if (uc < sizeof(CifsUniLowerTable)) { |
| 345 | /* Latin characters */ | 347 | /* Latin characters */ |
| 346 | return uc + UniLowerTable[uc]; /* Use base tables */ | 348 | return uc + CifsUniLowerTable[uc]; /* Use base tables */ |
| 347 | } else { | 349 | } else { |
| 348 | rp = UniLowerRange; /* Use range tables */ | 350 | rp = CifsUniLowerRange; /* Use range tables */ |
| 349 | while (rp->start) { | 351 | while (rp->start) { |
| 350 | if (uc < rp->start) /* Before start of range */ | 352 | if (uc < rp->start) /* Before start of range */ |
| 351 | return uc; /* Uppercase = input */ | 353 | return uc; /* Uppercase = input */ |
| @@ -374,3 +376,5 @@ UniStrlwr(register wchar_t *upin) | |||
| 374 | } | 376 | } |
| 375 | 377 | ||
| 376 | #endif | 378 | #endif |
| 379 | |||
| 380 | #endif /* _CIFS_UNICODE_H */ | ||
diff --git a/fs/cifs/cifs_uniupr.h b/fs/cifs/cifs_uniupr.h index 18a9d978e519..0ac7c5a8633a 100644 --- a/fs/cifs/cifs_uniupr.h +++ b/fs/cifs/cifs_uniupr.h | |||
| @@ -140,7 +140,7 @@ const struct UniCaseRange CifsUniUpperRange[] = { | |||
| 140 | /* | 140 | /* |
| 141 | * Latin lower case | 141 | * Latin lower case |
| 142 | */ | 142 | */ |
| 143 | static signed char CifsUniLowerTable[512] = { | 143 | signed char CifsUniLowerTable[512] = { |
| 144 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 000-00f */ | 144 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 000-00f */ |
| 145 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 010-01f */ | 145 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 010-01f */ |
| 146 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 020-02f */ | 146 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 020-02f */ |
| @@ -242,12 +242,12 @@ static signed char UniCaseRangeLff20[27] = { | |||
| 242 | /* | 242 | /* |
| 243 | * Lower Case Range | 243 | * Lower Case Range |
| 244 | */ | 244 | */ |
| 245 | static const struct UniCaseRange CifsUniLowerRange[] = { | 245 | const struct UniCaseRange CifsUniLowerRange[] = { |
| 246 | 0x0380, 0x03ab, UniCaseRangeL0380, | 246 | {0x0380, 0x03ab, UniCaseRangeL0380}, |
| 247 | 0x0400, 0x042f, UniCaseRangeL0400, | 247 | {0x0400, 0x042f, UniCaseRangeL0400}, |
| 248 | 0x0490, 0x04cb, UniCaseRangeL0490, | 248 | {0x0490, 0x04cb, UniCaseRangeL0490}, |
| 249 | 0x1e00, 0x1ff7, UniCaseRangeL1e00, | 249 | {0x1e00, 0x1ff7, UniCaseRangeL1e00}, |
| 250 | 0xff20, 0xff3a, UniCaseRangeLff20, | 250 | {0xff20, 0xff3a, UniCaseRangeLff20}, |
| 251 | 0, 0, 0 | 251 | {0} |
| 252 | }; | 252 | }; |
| 253 | #endif | 253 | #endif |
diff --git a/fs/cifs/cifsencrypt.c b/fs/cifs/cifsencrypt.c index 847628dfdc44..709f2296bdb4 100644 --- a/fs/cifs/cifsencrypt.c +++ b/fs/cifs/cifsencrypt.c | |||
| @@ -27,6 +27,7 @@ | |||
| 27 | #include "md5.h" | 27 | #include "md5.h" |
| 28 | #include "cifs_unicode.h" | 28 | #include "cifs_unicode.h" |
| 29 | #include "cifsproto.h" | 29 | #include "cifsproto.h" |
| 30 | #include "ntlmssp.h" | ||
| 30 | #include <linux/ctype.h> | 31 | #include <linux/ctype.h> |
| 31 | #include <linux/random.h> | 32 | #include <linux/random.h> |
| 32 | 33 | ||
| @@ -42,21 +43,43 @@ extern void SMBencrypt(unsigned char *passwd, const unsigned char *c8, | |||
| 42 | unsigned char *p24); | 43 | unsigned char *p24); |
| 43 | 44 | ||
| 44 | static int cifs_calculate_signature(const struct smb_hdr *cifs_pdu, | 45 | static int cifs_calculate_signature(const struct smb_hdr *cifs_pdu, |
| 45 | const struct mac_key *key, char *signature) | 46 | struct TCP_Server_Info *server, char *signature) |
| 46 | { | 47 | { |
| 47 | struct MD5Context context; | 48 | int rc; |
| 48 | 49 | ||
| 49 | if ((cifs_pdu == NULL) || (signature == NULL) || (key == NULL)) | 50 | if (cifs_pdu == NULL || server == NULL || signature == NULL) |
| 50 | return -EINVAL; | 51 | return -EINVAL; |
| 51 | 52 | ||
| 52 | cifs_MD5_init(&context); | 53 | if (!server->ntlmssp.sdescmd5) { |
| 53 | cifs_MD5_update(&context, (char *)&key->data, key->len); | 54 | cERROR(1, |
| 54 | cifs_MD5_update(&context, cifs_pdu->Protocol, cifs_pdu->smb_buf_length); | 55 | "cifs_calculate_signature: can't generate signature\n"); |
| 56 | return -1; | ||
| 57 | } | ||
| 55 | 58 | ||
| 56 | cifs_MD5_final(signature, &context); | 59 | rc = crypto_shash_init(&server->ntlmssp.sdescmd5->shash); |
| 57 | return 0; | 60 | if (rc) { |
| 61 | cERROR(1, "cifs_calculate_signature: oould not init md5\n"); | ||
| 62 | return rc; | ||
| 63 | } | ||
| 64 | |||
| 65 | if (server->secType == RawNTLMSSP) | ||
| 66 | crypto_shash_update(&server->ntlmssp.sdescmd5->shash, | ||
| 67 | server->session_key.data.ntlmv2.key, | ||
| 68 | CIFS_NTLMV2_SESSKEY_SIZE); | ||
| 69 | else | ||
| 70 | crypto_shash_update(&server->ntlmssp.sdescmd5->shash, | ||
| 71 | (char *)&server->session_key.data, | ||
| 72 | server->session_key.len); | ||
| 73 | |||
| 74 | crypto_shash_update(&server->ntlmssp.sdescmd5->shash, | ||
| 75 | cifs_pdu->Protocol, cifs_pdu->smb_buf_length); | ||
| 76 | |||
| 77 | rc = crypto_shash_final(&server->ntlmssp.sdescmd5->shash, signature); | ||
| 78 | |||
| 79 | return rc; | ||
| 58 | } | 80 | } |
| 59 | 81 | ||
| 82 | |||
| 60 | int cifs_sign_smb(struct smb_hdr *cifs_pdu, struct TCP_Server_Info *server, | 83 | int cifs_sign_smb(struct smb_hdr *cifs_pdu, struct TCP_Server_Info *server, |
| 61 | __u32 *pexpected_response_sequence_number) | 84 | __u32 *pexpected_response_sequence_number) |
| 62 | { | 85 | { |
| @@ -78,8 +101,7 @@ int cifs_sign_smb(struct smb_hdr *cifs_pdu, struct TCP_Server_Info *server, | |||
| 78 | server->sequence_number++; | 101 | server->sequence_number++; |
| 79 | spin_unlock(&GlobalMid_Lock); | 102 | spin_unlock(&GlobalMid_Lock); |
| 80 | 103 | ||
| 81 | rc = cifs_calculate_signature(cifs_pdu, &server->mac_signing_key, | 104 | rc = cifs_calculate_signature(cifs_pdu, server, smb_signature); |
| 82 | smb_signature); | ||
| 83 | if (rc) | 105 | if (rc) |
| 84 | memset(cifs_pdu->Signature.SecuritySignature, 0, 8); | 106 | memset(cifs_pdu->Signature.SecuritySignature, 0, 8); |
| 85 | else | 107 | else |
| @@ -89,21 +111,39 @@ int cifs_sign_smb(struct smb_hdr *cifs_pdu, struct TCP_Server_Info *server, | |||
| 89 | } | 111 | } |
| 90 | 112 | ||
| 91 | static int cifs_calc_signature2(const struct kvec *iov, int n_vec, | 113 | static int cifs_calc_signature2(const struct kvec *iov, int n_vec, |
| 92 | const struct mac_key *key, char *signature) | 114 | struct TCP_Server_Info *server, char *signature) |
| 93 | { | 115 | { |
| 94 | struct MD5Context context; | ||
| 95 | int i; | 116 | int i; |
| 117 | int rc; | ||
| 96 | 118 | ||
| 97 | if ((iov == NULL) || (signature == NULL) || (key == NULL)) | 119 | if (iov == NULL || server == NULL || signature == NULL) |
| 98 | return -EINVAL; | 120 | return -EINVAL; |
| 99 | 121 | ||
| 100 | cifs_MD5_init(&context); | 122 | if (!server->ntlmssp.sdescmd5) { |
| 101 | cifs_MD5_update(&context, (char *)&key->data, key->len); | 123 | cERROR(1, "cifs_calc_signature2: can't generate signature\n"); |
| 124 | return -1; | ||
| 125 | } | ||
| 126 | |||
| 127 | rc = crypto_shash_init(&server->ntlmssp.sdescmd5->shash); | ||
| 128 | if (rc) { | ||
| 129 | cERROR(1, "cifs_calc_signature2: oould not init md5\n"); | ||
| 130 | return rc; | ||
| 131 | } | ||
| 132 | |||
| 133 | if (server->secType == RawNTLMSSP) | ||
| 134 | crypto_shash_update(&server->ntlmssp.sdescmd5->shash, | ||
| 135 | server->session_key.data.ntlmv2.key, | ||
| 136 | CIFS_NTLMV2_SESSKEY_SIZE); | ||
| 137 | else | ||
| 138 | crypto_shash_update(&server->ntlmssp.sdescmd5->shash, | ||
| 139 | (char *)&server->session_key.data, | ||
| 140 | server->session_key.len); | ||
| 141 | |||
| 102 | for (i = 0; i < n_vec; i++) { | 142 | for (i = 0; i < n_vec; i++) { |
| 103 | if (iov[i].iov_len == 0) | 143 | if (iov[i].iov_len == 0) |
| 104 | continue; | 144 | continue; |
| 105 | if (iov[i].iov_base == NULL) { | 145 | if (iov[i].iov_base == NULL) { |
| 106 | cERROR(1, "null iovec entry"); | 146 | cERROR(1, "cifs_calc_signature2: null iovec entry"); |
| 107 | return -EIO; | 147 | return -EIO; |
| 108 | } | 148 | } |
| 109 | /* The first entry includes a length field (which does not get | 149 | /* The first entry includes a length field (which does not get |
| @@ -111,18 +151,18 @@ static int cifs_calc_signature2(const struct kvec *iov, int n_vec, | |||
| 111 | if (i == 0) { | 151 | if (i == 0) { |
| 112 | if (iov[0].iov_len <= 8) /* cmd field at offset 9 */ | 152 | if (iov[0].iov_len <= 8) /* cmd field at offset 9 */ |
| 113 | break; /* nothing to sign or corrupt header */ | 153 | break; /* nothing to sign or corrupt header */ |
| 114 | cifs_MD5_update(&context, iov[0].iov_base+4, | 154 | crypto_shash_update(&server->ntlmssp.sdescmd5->shash, |
| 115 | iov[0].iov_len-4); | 155 | iov[i].iov_base + 4, iov[i].iov_len - 4); |
| 116 | } else | 156 | } else |
| 117 | cifs_MD5_update(&context, iov[i].iov_base, iov[i].iov_len); | 157 | crypto_shash_update(&server->ntlmssp.sdescmd5->shash, |
| 158 | iov[i].iov_base, iov[i].iov_len); | ||
| 118 | } | 159 | } |
| 119 | 160 | ||
| 120 | cifs_MD5_final(signature, &context); | 161 | rc = crypto_shash_final(&server->ntlmssp.sdescmd5->shash, signature); |
| 121 | 162 | ||
| 122 | return 0; | 163 | return rc; |
| 123 | } | 164 | } |
| 124 | 165 | ||
| 125 | |||
| 126 | int cifs_sign_smb2(struct kvec *iov, int n_vec, struct TCP_Server_Info *server, | 166 | int cifs_sign_smb2(struct kvec *iov, int n_vec, struct TCP_Server_Info *server, |
| 127 | __u32 *pexpected_response_sequence_number) | 167 | __u32 *pexpected_response_sequence_number) |
| 128 | { | 168 | { |
| @@ -145,8 +185,7 @@ int cifs_sign_smb2(struct kvec *iov, int n_vec, struct TCP_Server_Info *server, | |||
| 145 | server->sequence_number++; | 185 | server->sequence_number++; |
| 146 | spin_unlock(&GlobalMid_Lock); | 186 | spin_unlock(&GlobalMid_Lock); |
| 147 | 187 | ||
| 148 | rc = cifs_calc_signature2(iov, n_vec, &server->mac_signing_key, | 188 | rc = cifs_calc_signature2(iov, n_vec, server, smb_signature); |
| 149 | smb_signature); | ||
| 150 | if (rc) | 189 | if (rc) |
| 151 | memset(cifs_pdu->Signature.SecuritySignature, 0, 8); | 190 | memset(cifs_pdu->Signature.SecuritySignature, 0, 8); |
| 152 | else | 191 | else |
| @@ -156,14 +195,14 @@ int cifs_sign_smb2(struct kvec *iov, int n_vec, struct TCP_Server_Info *server, | |||
| 156 | } | 195 | } |
| 157 | 196 | ||
| 158 | int cifs_verify_signature(struct smb_hdr *cifs_pdu, | 197 | int cifs_verify_signature(struct smb_hdr *cifs_pdu, |
| 159 | const struct mac_key *mac_key, | 198 | struct TCP_Server_Info *server, |
| 160 | __u32 expected_sequence_number) | 199 | __u32 expected_sequence_number) |
| 161 | { | 200 | { |
| 162 | unsigned int rc; | 201 | int rc; |
| 163 | char server_response_sig[8]; | 202 | char server_response_sig[8]; |
| 164 | char what_we_think_sig_should_be[20]; | 203 | char what_we_think_sig_should_be[20]; |
| 165 | 204 | ||
| 166 | if ((cifs_pdu == NULL) || (mac_key == NULL)) | 205 | if (cifs_pdu == NULL || server == NULL) |
| 167 | return -EINVAL; | 206 | return -EINVAL; |
| 168 | 207 | ||
| 169 | if (cifs_pdu->Command == SMB_COM_NEGOTIATE) | 208 | if (cifs_pdu->Command == SMB_COM_NEGOTIATE) |
| @@ -192,7 +231,7 @@ int cifs_verify_signature(struct smb_hdr *cifs_pdu, | |||
| 192 | cpu_to_le32(expected_sequence_number); | 231 | cpu_to_le32(expected_sequence_number); |
| 193 | cifs_pdu->Signature.Sequence.Reserved = 0; | 232 | cifs_pdu->Signature.Sequence.Reserved = 0; |
| 194 | 233 | ||
| 195 | rc = cifs_calculate_signature(cifs_pdu, mac_key, | 234 | rc = cifs_calculate_signature(cifs_pdu, server, |
| 196 | what_we_think_sig_should_be); | 235 | what_we_think_sig_should_be); |
| 197 | 236 | ||
| 198 | if (rc) | 237 | if (rc) |
| @@ -209,7 +248,7 @@ int cifs_verify_signature(struct smb_hdr *cifs_pdu, | |||
| 209 | } | 248 | } |
| 210 | 249 | ||
| 211 | /* We fill in key by putting in 40 byte array which was allocated by caller */ | 250 | /* We fill in key by putting in 40 byte array which was allocated by caller */ |
| 212 | int cifs_calculate_mac_key(struct mac_key *key, const char *rn, | 251 | int cifs_calculate_session_key(struct session_key *key, const char *rn, |
| 213 | const char *password) | 252 | const char *password) |
| 214 | { | 253 | { |
| 215 | char temp_key[16]; | 254 | char temp_key[16]; |
| @@ -223,63 +262,6 @@ int cifs_calculate_mac_key(struct mac_key *key, const char *rn, | |||
| 223 | return 0; | 262 | return 0; |
| 224 | } | 263 | } |
| 225 | 264 | ||
| 226 | int CalcNTLMv2_partial_mac_key(struct cifsSesInfo *ses, | ||
| 227 | const struct nls_table *nls_info) | ||
| 228 | { | ||
| 229 | char temp_hash[16]; | ||
| 230 | struct HMACMD5Context ctx; | ||
| 231 | char *ucase_buf; | ||
| 232 | __le16 *unicode_buf; | ||
| 233 | unsigned int i, user_name_len, dom_name_len; | ||
| 234 | |||
| 235 | if (ses == NULL) | ||
| 236 | return -EINVAL; | ||
| 237 | |||
| 238 | E_md4hash(ses->password, temp_hash); | ||
| 239 | |||
| 240 | hmac_md5_init_limK_to_64(temp_hash, 16, &ctx); | ||
| 241 | user_name_len = strlen(ses->userName); | ||
| 242 | if (user_name_len > MAX_USERNAME_SIZE) | ||
| 243 | return -EINVAL; | ||
| 244 | if (ses->domainName == NULL) | ||
| 245 | return -EINVAL; /* BB should we use CIFS_LINUX_DOM */ | ||
| 246 | dom_name_len = strlen(ses->domainName); | ||
| 247 | if (dom_name_len > MAX_USERNAME_SIZE) | ||
| 248 | return -EINVAL; | ||
| 249 | |||
| 250 | ucase_buf = kmalloc((MAX_USERNAME_SIZE+1), GFP_KERNEL); | ||
| 251 | if (ucase_buf == NULL) | ||
| 252 | return -ENOMEM; | ||
| 253 | unicode_buf = kmalloc((MAX_USERNAME_SIZE+1)*4, GFP_KERNEL); | ||
| 254 | if (unicode_buf == NULL) { | ||
| 255 | kfree(ucase_buf); | ||
| 256 | return -ENOMEM; | ||
| 257 | } | ||
| 258 | |||
| 259 | for (i = 0; i < user_name_len; i++) | ||
| 260 | ucase_buf[i] = nls_info->charset2upper[(int)ses->userName[i]]; | ||
| 261 | ucase_buf[i] = 0; | ||
| 262 | user_name_len = cifs_strtoUCS(unicode_buf, ucase_buf, | ||
| 263 | MAX_USERNAME_SIZE*2, nls_info); | ||
| 264 | unicode_buf[user_name_len] = 0; | ||
| 265 | user_name_len++; | ||
| 266 | |||
| 267 | for (i = 0; i < dom_name_len; i++) | ||
| 268 | ucase_buf[i] = nls_info->charset2upper[(int)ses->domainName[i]]; | ||
| 269 | ucase_buf[i] = 0; | ||
| 270 | dom_name_len = cifs_strtoUCS(unicode_buf+user_name_len, ucase_buf, | ||
| 271 | MAX_USERNAME_SIZE*2, nls_info); | ||
| 272 | |||
| 273 | unicode_buf[user_name_len + dom_name_len] = 0; | ||
| 274 | hmac_md5_update((const unsigned char *) unicode_buf, | ||
| 275 | (user_name_len+dom_name_len)*2, &ctx); | ||
| 276 | |||
| 277 | hmac_md5_final(ses->server->ntlmv2_hash, &ctx); | ||
| 278 | kfree(ucase_buf); | ||
| 279 | kfree(unicode_buf); | ||
| 280 | return 0; | ||
| 281 | } | ||
| 282 | |||
| 283 | #ifdef CONFIG_CIFS_WEAK_PW_HASH | 265 | #ifdef CONFIG_CIFS_WEAK_PW_HASH |
| 284 | void calc_lanman_hash(const char *password, const char *cryptkey, bool encrypt, | 266 | void calc_lanman_hash(const char *password, const char *cryptkey, bool encrypt, |
| 285 | char *lnm_session_key) | 267 | char *lnm_session_key) |
| @@ -324,38 +306,52 @@ static int calc_ntlmv2_hash(struct cifsSesInfo *ses, | |||
| 324 | { | 306 | { |
| 325 | int rc = 0; | 307 | int rc = 0; |
| 326 | int len; | 308 | int len; |
| 327 | char nt_hash[16]; | 309 | char nt_hash[CIFS_NTHASH_SIZE]; |
| 328 | struct HMACMD5Context *pctxt; | ||
| 329 | wchar_t *user; | 310 | wchar_t *user; |
| 330 | wchar_t *domain; | 311 | wchar_t *domain; |
| 312 | wchar_t *server; | ||
| 331 | 313 | ||
| 332 | pctxt = kmalloc(sizeof(struct HMACMD5Context), GFP_KERNEL); | 314 | if (!ses->server->ntlmssp.sdeschmacmd5) { |
| 333 | 315 | cERROR(1, "calc_ntlmv2_hash: can't generate ntlmv2 hash\n"); | |
| 334 | if (pctxt == NULL) | 316 | return -1; |
| 335 | return -ENOMEM; | 317 | } |
| 336 | 318 | ||
| 337 | /* calculate md4 hash of password */ | 319 | /* calculate md4 hash of password */ |
| 338 | E_md4hash(ses->password, nt_hash); | 320 | E_md4hash(ses->password, nt_hash); |
| 339 | 321 | ||
| 340 | /* convert Domainname to unicode and uppercase */ | 322 | crypto_shash_setkey(ses->server->ntlmssp.hmacmd5, nt_hash, |
| 341 | hmac_md5_init_limK_to_64(nt_hash, 16, pctxt); | 323 | CIFS_NTHASH_SIZE); |
| 324 | |||
| 325 | rc = crypto_shash_init(&ses->server->ntlmssp.sdeschmacmd5->shash); | ||
| 326 | if (rc) { | ||
| 327 | cERROR(1, "calc_ntlmv2_hash: could not init hmacmd5\n"); | ||
| 328 | return rc; | ||
| 329 | } | ||
| 342 | 330 | ||
| 343 | /* convert ses->userName to unicode and uppercase */ | 331 | /* convert ses->userName to unicode and uppercase */ |
| 344 | len = strlen(ses->userName); | 332 | len = strlen(ses->userName); |
| 345 | user = kmalloc(2 + (len * 2), GFP_KERNEL); | 333 | user = kmalloc(2 + (len * 2), GFP_KERNEL); |
| 346 | if (user == NULL) | 334 | if (user == NULL) { |
| 335 | cERROR(1, "calc_ntlmv2_hash: user mem alloc failure\n"); | ||
| 336 | rc = -ENOMEM; | ||
| 347 | goto calc_exit_2; | 337 | goto calc_exit_2; |
| 338 | } | ||
| 348 | len = cifs_strtoUCS((__le16 *)user, ses->userName, len, nls_cp); | 339 | len = cifs_strtoUCS((__le16 *)user, ses->userName, len, nls_cp); |
| 349 | UniStrupr(user); | 340 | UniStrupr(user); |
| 350 | hmac_md5_update((char *)user, 2*len, pctxt); | 341 | |
| 342 | crypto_shash_update(&ses->server->ntlmssp.sdeschmacmd5->shash, | ||
| 343 | (char *)user, 2 * len); | ||
| 351 | 344 | ||
| 352 | /* convert ses->domainName to unicode and uppercase */ | 345 | /* convert ses->domainName to unicode and uppercase */ |
| 353 | if (ses->domainName) { | 346 | if (ses->domainName) { |
| 354 | len = strlen(ses->domainName); | 347 | len = strlen(ses->domainName); |
| 355 | 348 | ||
| 356 | domain = kmalloc(2 + (len * 2), GFP_KERNEL); | 349 | domain = kmalloc(2 + (len * 2), GFP_KERNEL); |
| 357 | if (domain == NULL) | 350 | if (domain == NULL) { |
| 351 | cERROR(1, "calc_ntlmv2_hash: domain mem alloc failure"); | ||
| 352 | rc = -ENOMEM; | ||
| 358 | goto calc_exit_1; | 353 | goto calc_exit_1; |
| 354 | } | ||
| 359 | len = cifs_strtoUCS((__le16 *)domain, ses->domainName, len, | 355 | len = cifs_strtoUCS((__le16 *)domain, ses->domainName, len, |
| 360 | nls_cp); | 356 | nls_cp); |
| 361 | /* the following line was removed since it didn't work well | 357 | /* the following line was removed since it didn't work well |
| @@ -363,65 +359,292 @@ static int calc_ntlmv2_hash(struct cifsSesInfo *ses, | |||
| 363 | Maybe converting the domain name earlier makes sense */ | 359 | Maybe converting the domain name earlier makes sense */ |
| 364 | /* UniStrupr(domain); */ | 360 | /* UniStrupr(domain); */ |
| 365 | 361 | ||
| 366 | hmac_md5_update((char *)domain, 2*len, pctxt); | 362 | crypto_shash_update(&ses->server->ntlmssp.sdeschmacmd5->shash, |
| 363 | (char *)domain, 2 * len); | ||
| 367 | 364 | ||
| 368 | kfree(domain); | 365 | kfree(domain); |
| 366 | } else if (ses->serverName) { | ||
| 367 | len = strlen(ses->serverName); | ||
| 368 | |||
| 369 | server = kmalloc(2 + (len * 2), GFP_KERNEL); | ||
| 370 | if (server == NULL) { | ||
| 371 | cERROR(1, "calc_ntlmv2_hash: server mem alloc failure"); | ||
| 372 | rc = -ENOMEM; | ||
| 373 | goto calc_exit_1; | ||
| 374 | } | ||
| 375 | len = cifs_strtoUCS((__le16 *)server, ses->serverName, len, | ||
| 376 | nls_cp); | ||
| 377 | /* the following line was removed since it didn't work well | ||
| 378 | with lower cased domain name that passed as an option. | ||
| 379 | Maybe converting the domain name earlier makes sense */ | ||
| 380 | /* UniStrupr(domain); */ | ||
| 381 | |||
| 382 | crypto_shash_update(&ses->server->ntlmssp.sdeschmacmd5->shash, | ||
| 383 | (char *)server, 2 * len); | ||
| 384 | |||
| 385 | kfree(server); | ||
| 369 | } | 386 | } |
| 387 | |||
| 388 | rc = crypto_shash_final(&ses->server->ntlmssp.sdeschmacmd5->shash, | ||
| 389 | ses->server->ntlmv2_hash); | ||
| 390 | |||
| 370 | calc_exit_1: | 391 | calc_exit_1: |
| 371 | kfree(user); | 392 | kfree(user); |
| 372 | calc_exit_2: | 393 | calc_exit_2: |
| 373 | /* BB FIXME what about bytes 24 through 40 of the signing key? | 394 | /* BB FIXME what about bytes 24 through 40 of the signing key? |
| 374 | compare with the NTLM example */ | 395 | compare with the NTLM example */ |
| 375 | hmac_md5_final(ses->server->ntlmv2_hash, pctxt); | ||
| 376 | 396 | ||
| 377 | kfree(pctxt); | ||
| 378 | return rc; | 397 | return rc; |
| 379 | } | 398 | } |
| 380 | 399 | ||
| 381 | void setup_ntlmv2_rsp(struct cifsSesInfo *ses, char *resp_buf, | 400 | static int |
| 382 | const struct nls_table *nls_cp) | 401 | find_domain_name(struct cifsSesInfo *ses) |
| 402 | { | ||
| 403 | int rc = 0; | ||
| 404 | unsigned int attrsize; | ||
| 405 | unsigned int type; | ||
| 406 | unsigned char *blobptr; | ||
| 407 | struct ntlmssp2_name *attrptr; | ||
| 408 | |||
| 409 | if (ses->server->tiblob) { | ||
| 410 | blobptr = ses->server->tiblob; | ||
| 411 | attrptr = (struct ntlmssp2_name *) blobptr; | ||
| 412 | |||
| 413 | while ((type = attrptr->type) != 0) { | ||
| 414 | blobptr += 2; /* advance attr type */ | ||
| 415 | attrsize = attrptr->length; | ||
| 416 | blobptr += 2; /* advance attr size */ | ||
| 417 | if (type == NTLMSSP_AV_NB_DOMAIN_NAME) { | ||
| 418 | if (!ses->domainName) { | ||
| 419 | ses->domainName = | ||
| 420 | kmalloc(attrptr->length + 1, | ||
| 421 | GFP_KERNEL); | ||
| 422 | if (!ses->domainName) | ||
| 423 | return -ENOMEM; | ||
| 424 | cifs_from_ucs2(ses->domainName, | ||
| 425 | (__le16 *)blobptr, | ||
| 426 | attrptr->length, | ||
| 427 | attrptr->length, | ||
| 428 | load_nls_default(), false); | ||
| 429 | } | ||
| 430 | } | ||
| 431 | blobptr += attrsize; /* advance attr value */ | ||
| 432 | attrptr = (struct ntlmssp2_name *) blobptr; | ||
| 433 | } | ||
| 434 | } else { | ||
| 435 | ses->server->tilen = 2 * sizeof(struct ntlmssp2_name); | ||
| 436 | ses->server->tiblob = kmalloc(ses->server->tilen, GFP_KERNEL); | ||
| 437 | if (!ses->server->tiblob) { | ||
| 438 | ses->server->tilen = 0; | ||
| 439 | cERROR(1, "Challenge target info allocation failure"); | ||
| 440 | return -ENOMEM; | ||
| 441 | } | ||
| 442 | memset(ses->server->tiblob, 0x0, ses->server->tilen); | ||
| 443 | attrptr = (struct ntlmssp2_name *) ses->server->tiblob; | ||
| 444 | attrptr->type = cpu_to_le16(NTLMSSP_DOMAIN_TYPE); | ||
| 445 | } | ||
| 446 | |||
| 447 | return rc; | ||
| 448 | } | ||
| 449 | |||
| 450 | static int | ||
| 451 | CalcNTLMv2_response(const struct TCP_Server_Info *server, | ||
| 452 | char *v2_session_response) | ||
| 383 | { | 453 | { |
| 384 | int rc; | 454 | int rc; |
| 455 | |||
| 456 | if (!server->ntlmssp.sdeschmacmd5) { | ||
| 457 | cERROR(1, "calc_ntlmv2_hash: can't generate ntlmv2 hash\n"); | ||
| 458 | return -1; | ||
| 459 | } | ||
| 460 | |||
| 461 | crypto_shash_setkey(server->ntlmssp.hmacmd5, server->ntlmv2_hash, | ||
| 462 | CIFS_HMAC_MD5_HASH_SIZE); | ||
| 463 | |||
| 464 | rc = crypto_shash_init(&server->ntlmssp.sdeschmacmd5->shash); | ||
| 465 | if (rc) { | ||
| 466 | cERROR(1, "CalcNTLMv2_response: could not init hmacmd5"); | ||
| 467 | return rc; | ||
| 468 | } | ||
| 469 | |||
| 470 | memcpy(v2_session_response + CIFS_SERVER_CHALLENGE_SIZE, | ||
| 471 | server->cryptKey, CIFS_SERVER_CHALLENGE_SIZE); | ||
| 472 | crypto_shash_update(&server->ntlmssp.sdeschmacmd5->shash, | ||
| 473 | v2_session_response + CIFS_SERVER_CHALLENGE_SIZE, | ||
| 474 | sizeof(struct ntlmv2_resp) - CIFS_SERVER_CHALLENGE_SIZE); | ||
| 475 | |||
| 476 | if (server->tilen) | ||
| 477 | crypto_shash_update(&server->ntlmssp.sdeschmacmd5->shash, | ||
| 478 | server->tiblob, server->tilen); | ||
| 479 | |||
| 480 | rc = crypto_shash_final(&server->ntlmssp.sdeschmacmd5->shash, | ||
| 481 | v2_session_response); | ||
| 482 | |||
| 483 | return rc; | ||
| 484 | } | ||
| 485 | |||
| 486 | int | ||
| 487 | setup_ntlmv2_rsp(struct cifsSesInfo *ses, char *resp_buf, | ||
| 488 | const struct nls_table *nls_cp) | ||
| 489 | { | ||
| 490 | int rc = 0; | ||
| 385 | struct ntlmv2_resp *buf = (struct ntlmv2_resp *)resp_buf; | 491 | struct ntlmv2_resp *buf = (struct ntlmv2_resp *)resp_buf; |
| 386 | struct HMACMD5Context context; | ||
| 387 | 492 | ||
| 388 | buf->blob_signature = cpu_to_le32(0x00000101); | 493 | buf->blob_signature = cpu_to_le32(0x00000101); |
| 389 | buf->reserved = 0; | 494 | buf->reserved = 0; |
| 390 | buf->time = cpu_to_le64(cifs_UnixTimeToNT(CURRENT_TIME)); | 495 | buf->time = cpu_to_le64(cifs_UnixTimeToNT(CURRENT_TIME)); |
| 391 | get_random_bytes(&buf->client_chal, sizeof(buf->client_chal)); | 496 | get_random_bytes(&buf->client_chal, sizeof(buf->client_chal)); |
| 392 | buf->reserved2 = 0; | 497 | buf->reserved2 = 0; |
| 393 | buf->names[0].type = cpu_to_le16(NTLMSSP_DOMAIN_TYPE); | 498 | |
| 394 | buf->names[0].length = 0; | 499 | if (!ses->domainName) { |
| 395 | buf->names[1].type = 0; | 500 | rc = find_domain_name(ses); |
| 396 | buf->names[1].length = 0; | 501 | if (rc) { |
| 502 | cERROR(1, "could not get domain/server name rc %d", rc); | ||
| 503 | return rc; | ||
| 504 | } | ||
| 505 | } | ||
| 397 | 506 | ||
| 398 | /* calculate buf->ntlmv2_hash */ | 507 | /* calculate buf->ntlmv2_hash */ |
| 399 | rc = calc_ntlmv2_hash(ses, nls_cp); | 508 | rc = calc_ntlmv2_hash(ses, nls_cp); |
| 400 | if (rc) | 509 | if (rc) { |
| 401 | cERROR(1, "could not get v2 hash rc %d", rc); | 510 | cERROR(1, "could not get v2 hash rc %d", rc); |
| 402 | CalcNTLMv2_response(ses, resp_buf); | 511 | return rc; |
| 512 | } | ||
| 513 | rc = CalcNTLMv2_response(ses->server, resp_buf); | ||
| 514 | if (rc) { | ||
| 515 | cERROR(1, "could not get v2 hash rc %d", rc); | ||
| 516 | return rc; | ||
| 517 | } | ||
| 403 | 518 | ||
| 404 | /* now calculate the MAC key for NTLMv2 */ | 519 | if (!ses->server->ntlmssp.sdeschmacmd5) { |
| 405 | hmac_md5_init_limK_to_64(ses->server->ntlmv2_hash, 16, &context); | 520 | cERROR(1, "calc_ntlmv2_hash: can't generate ntlmv2 hash\n"); |
| 406 | hmac_md5_update(resp_buf, 16, &context); | 521 | return -1; |
| 407 | hmac_md5_final(ses->server->mac_signing_key.data.ntlmv2.key, &context); | 522 | } |
| 408 | 523 | ||
| 409 | memcpy(&ses->server->mac_signing_key.data.ntlmv2.resp, resp_buf, | 524 | crypto_shash_setkey(ses->server->ntlmssp.hmacmd5, |
| 410 | sizeof(struct ntlmv2_resp)); | 525 | ses->server->ntlmv2_hash, CIFS_HMAC_MD5_HASH_SIZE); |
| 411 | ses->server->mac_signing_key.len = 16 + sizeof(struct ntlmv2_resp); | 526 | |
| 527 | rc = crypto_shash_init(&ses->server->ntlmssp.sdeschmacmd5->shash); | ||
| 528 | if (rc) { | ||
| 529 | cERROR(1, "setup_ntlmv2_rsp: could not init hmacmd5\n"); | ||
| 530 | return rc; | ||
| 531 | } | ||
| 532 | |||
| 533 | crypto_shash_update(&ses->server->ntlmssp.sdeschmacmd5->shash, | ||
| 534 | resp_buf, CIFS_HMAC_MD5_HASH_SIZE); | ||
| 535 | |||
| 536 | rc = crypto_shash_final(&ses->server->ntlmssp.sdeschmacmd5->shash, | ||
| 537 | ses->server->session_key.data.ntlmv2.key); | ||
| 538 | |||
| 539 | memcpy(&ses->server->session_key.data.ntlmv2.resp, resp_buf, | ||
| 540 | sizeof(struct ntlmv2_resp)); | ||
| 541 | ses->server->session_key.len = 16 + sizeof(struct ntlmv2_resp); | ||
| 542 | |||
| 543 | return rc; | ||
| 412 | } | 544 | } |
| 413 | 545 | ||
| 414 | void CalcNTLMv2_response(const struct cifsSesInfo *ses, | 546 | int |
| 415 | char *v2_session_response) | 547 | calc_seckey(struct TCP_Server_Info *server) |
| 416 | { | 548 | { |
| 417 | struct HMACMD5Context context; | 549 | int rc; |
| 418 | /* rest of v2 struct already generated */ | 550 | unsigned char sec_key[CIFS_NTLMV2_SESSKEY_SIZE]; |
| 419 | memcpy(v2_session_response + 8, ses->server->cryptKey, 8); | 551 | struct crypto_blkcipher *tfm_arc4; |
| 420 | hmac_md5_init_limK_to_64(ses->server->ntlmv2_hash, 16, &context); | 552 | struct scatterlist sgin, sgout; |
| 553 | struct blkcipher_desc desc; | ||
| 554 | |||
| 555 | get_random_bytes(sec_key, CIFS_NTLMV2_SESSKEY_SIZE); | ||
| 556 | |||
| 557 | tfm_arc4 = crypto_alloc_blkcipher("ecb(arc4)", | ||
| 558 | 0, CRYPTO_ALG_ASYNC); | ||
| 559 | if (!tfm_arc4 || IS_ERR(tfm_arc4)) { | ||
| 560 | cERROR(1, "could not allocate " "master crypto API arc4\n"); | ||
| 561 | return 1; | ||
| 562 | } | ||
| 563 | |||
| 564 | desc.tfm = tfm_arc4; | ||
| 565 | |||
| 566 | crypto_blkcipher_setkey(tfm_arc4, | ||
| 567 | server->session_key.data.ntlmv2.key, CIFS_CPHTXT_SIZE); | ||
| 568 | sg_init_one(&sgin, sec_key, CIFS_CPHTXT_SIZE); | ||
| 569 | sg_init_one(&sgout, server->ntlmssp.ciphertext, CIFS_CPHTXT_SIZE); | ||
| 570 | rc = crypto_blkcipher_encrypt(&desc, &sgout, &sgin, CIFS_CPHTXT_SIZE); | ||
| 421 | 571 | ||
| 422 | hmac_md5_update(v2_session_response+8, | 572 | if (!rc) |
| 423 | sizeof(struct ntlmv2_resp) - 8, &context); | 573 | memcpy(server->session_key.data.ntlmv2.key, |
| 574 | sec_key, CIFS_NTLMV2_SESSKEY_SIZE); | ||
| 575 | |||
| 576 | crypto_free_blkcipher(tfm_arc4); | ||
| 577 | |||
| 578 | return 0; | ||
| 579 | } | ||
| 424 | 580 | ||
| 425 | hmac_md5_final(v2_session_response, &context); | 581 | void |
| 426 | /* cifs_dump_mem("v2_sess_rsp: ", v2_session_response, 32); */ | 582 | cifs_crypto_shash_release(struct TCP_Server_Info *server) |
| 583 | { | ||
| 584 | if (server->ntlmssp.md5) | ||
| 585 | crypto_free_shash(server->ntlmssp.md5); | ||
| 586 | |||
| 587 | if (server->ntlmssp.hmacmd5) | ||
| 588 | crypto_free_shash(server->ntlmssp.hmacmd5); | ||
| 589 | |||
| 590 | kfree(server->ntlmssp.sdeschmacmd5); | ||
| 591 | |||
| 592 | kfree(server->ntlmssp.sdescmd5); | ||
| 593 | } | ||
| 594 | |||
| 595 | int | ||
| 596 | cifs_crypto_shash_allocate(struct TCP_Server_Info *server) | ||
| 597 | { | ||
| 598 | int rc; | ||
| 599 | unsigned int size; | ||
| 600 | |||
| 601 | server->ntlmssp.hmacmd5 = crypto_alloc_shash("hmac(md5)", 0, 0); | ||
| 602 | if (!server->ntlmssp.hmacmd5 || | ||
| 603 | IS_ERR(server->ntlmssp.hmacmd5)) { | ||
| 604 | cERROR(1, "could not allocate crypto hmacmd5\n"); | ||
| 605 | return 1; | ||
| 606 | } | ||
| 607 | |||
| 608 | server->ntlmssp.md5 = crypto_alloc_shash("md5", 0, 0); | ||
| 609 | if (!server->ntlmssp.md5 || IS_ERR(server->ntlmssp.md5)) { | ||
| 610 | cERROR(1, "could not allocate crypto md5\n"); | ||
| 611 | rc = 1; | ||
| 612 | goto cifs_crypto_shash_allocate_ret1; | ||
| 613 | } | ||
| 614 | |||
| 615 | size = sizeof(struct shash_desc) + | ||
| 616 | crypto_shash_descsize(server->ntlmssp.hmacmd5); | ||
| 617 | server->ntlmssp.sdeschmacmd5 = kmalloc(size, GFP_KERNEL); | ||
| 618 | if (!server->ntlmssp.sdeschmacmd5) { | ||
| 619 | cERROR(1, "cifs_crypto_shash_allocate: can't alloc hmacmd5\n"); | ||
| 620 | rc = -ENOMEM; | ||
| 621 | goto cifs_crypto_shash_allocate_ret2; | ||
| 622 | } | ||
| 623 | server->ntlmssp.sdeschmacmd5->shash.tfm = server->ntlmssp.hmacmd5; | ||
| 624 | server->ntlmssp.sdeschmacmd5->shash.flags = 0x0; | ||
| 625 | |||
| 626 | |||
| 627 | size = sizeof(struct shash_desc) + | ||
| 628 | crypto_shash_descsize(server->ntlmssp.md5); | ||
| 629 | server->ntlmssp.sdescmd5 = kmalloc(size, GFP_KERNEL); | ||
| 630 | if (!server->ntlmssp.sdescmd5) { | ||
| 631 | cERROR(1, "cifs_crypto_shash_allocate: can't alloc md5\n"); | ||
| 632 | rc = -ENOMEM; | ||
| 633 | goto cifs_crypto_shash_allocate_ret3; | ||
| 634 | } | ||
| 635 | server->ntlmssp.sdescmd5->shash.tfm = server->ntlmssp.md5; | ||
| 636 | server->ntlmssp.sdescmd5->shash.flags = 0x0; | ||
| 637 | |||
| 638 | return 0; | ||
| 639 | |||
| 640 | cifs_crypto_shash_allocate_ret3: | ||
| 641 | kfree(server->ntlmssp.sdeschmacmd5); | ||
| 642 | |||
| 643 | cifs_crypto_shash_allocate_ret2: | ||
| 644 | crypto_free_shash(server->ntlmssp.md5); | ||
| 645 | |||
| 646 | cifs_crypto_shash_allocate_ret1: | ||
| 647 | crypto_free_shash(server->ntlmssp.hmacmd5); | ||
| 648 | |||
| 649 | return rc; | ||
| 427 | } | 650 | } |
diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h index 0cdfb8c32ac6..c9d0cfc086eb 100644 --- a/fs/cifs/cifsglob.h +++ b/fs/cifs/cifsglob.h | |||
| @@ -25,6 +25,9 @@ | |||
| 25 | #include <linux/workqueue.h> | 25 | #include <linux/workqueue.h> |
| 26 | #include "cifs_fs_sb.h" | 26 | #include "cifs_fs_sb.h" |
| 27 | #include "cifsacl.h" | 27 | #include "cifsacl.h" |
| 28 | #include <crypto/internal/hash.h> | ||
| 29 | #include <linux/scatterlist.h> | ||
| 30 | |||
| 28 | /* | 31 | /* |
| 29 | * The sizes of various internal tables and strings | 32 | * The sizes of various internal tables and strings |
| 30 | */ | 33 | */ |
| @@ -97,7 +100,7 @@ enum protocolEnum { | |||
| 97 | /* Netbios frames protocol not supported at this time */ | 100 | /* Netbios frames protocol not supported at this time */ |
| 98 | }; | 101 | }; |
| 99 | 102 | ||
| 100 | struct mac_key { | 103 | struct session_key { |
| 101 | unsigned int len; | 104 | unsigned int len; |
| 102 | union { | 105 | union { |
| 103 | char ntlm[CIFS_SESS_KEY_SIZE + 16]; | 106 | char ntlm[CIFS_SESS_KEY_SIZE + 16]; |
| @@ -120,6 +123,21 @@ struct cifs_cred { | |||
| 120 | struct cifs_ace *aces; | 123 | struct cifs_ace *aces; |
| 121 | }; | 124 | }; |
| 122 | 125 | ||
| 126 | struct sdesc { | ||
| 127 | struct shash_desc shash; | ||
| 128 | char ctx[]; | ||
| 129 | }; | ||
| 130 | |||
| 131 | struct ntlmssp_auth { | ||
| 132 | __u32 client_flags; | ||
| 133 | __u32 server_flags; | ||
| 134 | unsigned char ciphertext[CIFS_CPHTXT_SIZE]; | ||
| 135 | struct crypto_shash *hmacmd5; | ||
| 136 | struct crypto_shash *md5; | ||
| 137 | struct sdesc *sdeschmacmd5; | ||
| 138 | struct sdesc *sdescmd5; | ||
| 139 | }; | ||
| 140 | |||
| 123 | /* | 141 | /* |
| 124 | ***************************************************************** | 142 | ***************************************************************** |
| 125 | * Except the CIFS PDUs themselves all the | 143 | * Except the CIFS PDUs themselves all the |
| @@ -182,11 +200,14 @@ struct TCP_Server_Info { | |||
| 182 | /* 16th byte of RFC1001 workstation name is always null */ | 200 | /* 16th byte of RFC1001 workstation name is always null */ |
| 183 | char workstation_RFC1001_name[RFC1001_NAME_LEN_WITH_NULL]; | 201 | char workstation_RFC1001_name[RFC1001_NAME_LEN_WITH_NULL]; |
| 184 | __u32 sequence_number; /* needed for CIFS PDU signature */ | 202 | __u32 sequence_number; /* needed for CIFS PDU signature */ |
| 185 | struct mac_key mac_signing_key; | 203 | struct session_key session_key; |
| 186 | char ntlmv2_hash[16]; | 204 | char ntlmv2_hash[16]; |
| 187 | unsigned long lstrp; /* when we got last response from this server */ | 205 | unsigned long lstrp; /* when we got last response from this server */ |
| 188 | u16 dialect; /* dialect index that server chose */ | 206 | u16 dialect; /* dialect index that server chose */ |
| 189 | /* extended security flavors that server supports */ | 207 | /* extended security flavors that server supports */ |
| 208 | unsigned int tilen; /* length of the target info blob */ | ||
| 209 | unsigned char *tiblob; /* target info blob in challenge response */ | ||
| 210 | struct ntlmssp_auth ntlmssp; /* various keys, ciphers, flags */ | ||
| 190 | bool sec_kerberos; /* supports plain Kerberos */ | 211 | bool sec_kerberos; /* supports plain Kerberos */ |
| 191 | bool sec_mskerberos; /* supports legacy MS Kerberos */ | 212 | bool sec_mskerberos; /* supports legacy MS Kerberos */ |
| 192 | bool sec_kerberosu2u; /* supports U2U Kerberos */ | 213 | bool sec_kerberosu2u; /* supports U2U Kerberos */ |
diff --git a/fs/cifs/cifspdu.h b/fs/cifs/cifspdu.h index 14d036d8db11..320e0fd0ba7b 100644 --- a/fs/cifs/cifspdu.h +++ b/fs/cifs/cifspdu.h | |||
| @@ -134,6 +134,12 @@ | |||
| 134 | * Size of the session key (crypto key encrypted with the password | 134 | * Size of the session key (crypto key encrypted with the password |
| 135 | */ | 135 | */ |
| 136 | #define CIFS_SESS_KEY_SIZE (24) | 136 | #define CIFS_SESS_KEY_SIZE (24) |
| 137 | #define CIFS_CLIENT_CHALLENGE_SIZE (8) | ||
| 138 | #define CIFS_SERVER_CHALLENGE_SIZE (8) | ||
| 139 | #define CIFS_HMAC_MD5_HASH_SIZE (16) | ||
| 140 | #define CIFS_CPHTXT_SIZE (16) | ||
| 141 | #define CIFS_NTLMV2_SESSKEY_SIZE (16) | ||
| 142 | #define CIFS_NTHASH_SIZE (16) | ||
| 137 | 143 | ||
| 138 | /* | 144 | /* |
| 139 | * Maximum user name length | 145 | * Maximum user name length |
| @@ -663,7 +669,6 @@ struct ntlmv2_resp { | |||
| 663 | __le64 time; | 669 | __le64 time; |
| 664 | __u64 client_chal; /* random */ | 670 | __u64 client_chal; /* random */ |
| 665 | __u32 reserved2; | 671 | __u32 reserved2; |
| 666 | struct ntlmssp2_name names[2]; | ||
| 667 | /* array of name entries could follow ending in minimum 4 byte struct */ | 672 | /* array of name entries could follow ending in minimum 4 byte struct */ |
| 668 | } __attribute__((packed)); | 673 | } __attribute__((packed)); |
| 669 | 674 | ||
diff --git a/fs/cifs/cifsproto.h b/fs/cifs/cifsproto.h index 1f5450814087..1378d9133844 100644 --- a/fs/cifs/cifsproto.h +++ b/fs/cifs/cifsproto.h | |||
| @@ -361,15 +361,15 @@ extern int cifs_sign_smb(struct smb_hdr *, struct TCP_Server_Info *, __u32 *); | |||
| 361 | extern int cifs_sign_smb2(struct kvec *iov, int n_vec, struct TCP_Server_Info *, | 361 | extern int cifs_sign_smb2(struct kvec *iov, int n_vec, struct TCP_Server_Info *, |
| 362 | __u32 *); | 362 | __u32 *); |
| 363 | extern int cifs_verify_signature(struct smb_hdr *, | 363 | extern int cifs_verify_signature(struct smb_hdr *, |
| 364 | const struct mac_key *mac_key, | 364 | struct TCP_Server_Info *server, |
| 365 | __u32 expected_sequence_number); | 365 | __u32 expected_sequence_number); |
| 366 | extern int cifs_calculate_mac_key(struct mac_key *key, const char *rn, | 366 | extern int cifs_calculate_session_key(struct session_key *key, const char *rn, |
| 367 | const char *pass); | 367 | const char *pass); |
| 368 | extern int CalcNTLMv2_partial_mac_key(struct cifsSesInfo *, | 368 | extern int setup_ntlmv2_rsp(struct cifsSesInfo *, char *, |
| 369 | const struct nls_table *); | ||
| 370 | extern void CalcNTLMv2_response(const struct cifsSesInfo *, char *); | ||
| 371 | extern void setup_ntlmv2_rsp(struct cifsSesInfo *, char *, | ||
| 372 | const struct nls_table *); | 369 | const struct nls_table *); |
| 370 | extern int cifs_crypto_shash_allocate(struct TCP_Server_Info *); | ||
| 371 | extern void cifs_crypto_shash_release(struct TCP_Server_Info *); | ||
| 372 | extern int calc_seckey(struct TCP_Server_Info *); | ||
| 373 | #ifdef CONFIG_CIFS_WEAK_PW_HASH | 373 | #ifdef CONFIG_CIFS_WEAK_PW_HASH |
| 374 | extern void calc_lanman_hash(const char *password, const char *cryptkey, | 374 | extern void calc_lanman_hash(const char *password, const char *cryptkey, |
| 375 | bool encrypt, char *lnm_session_key); | 375 | bool encrypt, char *lnm_session_key); |
diff --git a/fs/cifs/cifssmb.c b/fs/cifs/cifssmb.c index c65c3419dd37..4bda920d1f75 100644 --- a/fs/cifs/cifssmb.c +++ b/fs/cifs/cifssmb.c | |||
| @@ -604,11 +604,14 @@ CIFSSMBNegotiate(unsigned int xid, struct cifsSesInfo *ses) | |||
| 604 | else | 604 | else |
| 605 | rc = -EINVAL; | 605 | rc = -EINVAL; |
| 606 | 606 | ||
| 607 | if (server->sec_kerberos || server->sec_mskerberos) | 607 | if (server->secType == Kerberos) { |
| 608 | server->secType = Kerberos; | 608 | if (!server->sec_kerberos && |
| 609 | else if (server->sec_ntlmssp) | 609 | !server->sec_mskerberos) |
| 610 | server->secType = RawNTLMSSP; | 610 | rc = -EOPNOTSUPP; |
| 611 | else | 611 | } else if (server->secType == RawNTLMSSP) { |
| 612 | if (!server->sec_ntlmssp) | ||
| 613 | rc = -EOPNOTSUPP; | ||
| 614 | } else | ||
| 612 | rc = -EOPNOTSUPP; | 615 | rc = -EOPNOTSUPP; |
| 613 | } | 616 | } |
| 614 | } else | 617 | } else |
diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c index 95c2ea67edfb..ec0ea4a43bdb 100644 --- a/fs/cifs/connect.c +++ b/fs/cifs/connect.c | |||
| @@ -1673,7 +1673,9 @@ cifs_find_smb_ses(struct TCP_Server_Info *server, struct smb_vol *vol) | |||
| 1673 | MAX_USERNAME_SIZE)) | 1673 | MAX_USERNAME_SIZE)) |
| 1674 | continue; | 1674 | continue; |
| 1675 | if (strlen(vol->username) != 0 && | 1675 | if (strlen(vol->username) != 0 && |
| 1676 | strncmp(ses->password, vol->password, | 1676 | ses->password != NULL && |
| 1677 | strncmp(ses->password, | ||
| 1678 | vol->password ? vol->password : "", | ||
| 1677 | MAX_PASSWORD_SIZE)) | 1679 | MAX_PASSWORD_SIZE)) |
| 1678 | continue; | 1680 | continue; |
| 1679 | } | 1681 | } |
| @@ -1706,6 +1708,7 @@ cifs_put_smb_ses(struct cifsSesInfo *ses) | |||
| 1706 | CIFSSMBLogoff(xid, ses); | 1708 | CIFSSMBLogoff(xid, ses); |
| 1707 | _FreeXid(xid); | 1709 | _FreeXid(xid); |
| 1708 | } | 1710 | } |
| 1711 | cifs_crypto_shash_release(server); | ||
| 1709 | sesInfoFree(ses); | 1712 | sesInfoFree(ses); |
| 1710 | cifs_put_tcp_session(server); | 1713 | cifs_put_tcp_session(server); |
| 1711 | } | 1714 | } |
| @@ -1785,13 +1788,23 @@ cifs_get_smb_ses(struct TCP_Server_Info *server, struct smb_vol *volume_info) | |||
| 1785 | ses->linux_uid = volume_info->linux_uid; | 1788 | ses->linux_uid = volume_info->linux_uid; |
| 1786 | ses->overrideSecFlg = volume_info->secFlg; | 1789 | ses->overrideSecFlg = volume_info->secFlg; |
| 1787 | 1790 | ||
| 1791 | rc = cifs_crypto_shash_allocate(server); | ||
| 1792 | if (rc) { | ||
| 1793 | cERROR(1, "could not setup hash structures rc %d", rc); | ||
| 1794 | goto get_ses_fail; | ||
| 1795 | } | ||
| 1796 | server->tilen = 0; | ||
| 1797 | server->tiblob = NULL; | ||
| 1798 | |||
| 1788 | mutex_lock(&ses->session_mutex); | 1799 | mutex_lock(&ses->session_mutex); |
| 1789 | rc = cifs_negotiate_protocol(xid, ses); | 1800 | rc = cifs_negotiate_protocol(xid, ses); |
| 1790 | if (!rc) | 1801 | if (!rc) |
| 1791 | rc = cifs_setup_session(xid, ses, volume_info->local_nls); | 1802 | rc = cifs_setup_session(xid, ses, volume_info->local_nls); |
| 1792 | mutex_unlock(&ses->session_mutex); | 1803 | mutex_unlock(&ses->session_mutex); |
| 1793 | if (rc) | 1804 | if (rc) { |
| 1805 | cifs_crypto_shash_release(ses->server); | ||
| 1794 | goto get_ses_fail; | 1806 | goto get_ses_fail; |
| 1807 | } | ||
| 1795 | 1808 | ||
| 1796 | /* success, put it on the list */ | 1809 | /* success, put it on the list */ |
| 1797 | write_lock(&cifs_tcp_ses_lock); | 1810 | write_lock(&cifs_tcp_ses_lock); |
diff --git a/fs/cifs/dir.c b/fs/cifs/dir.c index 578d88c5b46e..f9ed0751cc12 100644 --- a/fs/cifs/dir.c +++ b/fs/cifs/dir.c | |||
| @@ -305,8 +305,7 @@ cifs_create(struct inode *inode, struct dentry *direntry, int mode, | |||
| 305 | full_path = build_path_from_dentry(direntry); | 305 | full_path = build_path_from_dentry(direntry); |
| 306 | if (full_path == NULL) { | 306 | if (full_path == NULL) { |
| 307 | rc = -ENOMEM; | 307 | rc = -ENOMEM; |
| 308 | FreeXid(xid); | 308 | goto cifs_create_out; |
| 309 | return rc; | ||
| 310 | } | 309 | } |
| 311 | 310 | ||
| 312 | if (oplockEnabled) | 311 | if (oplockEnabled) |
| @@ -365,9 +364,8 @@ cifs_create(struct inode *inode, struct dentry *direntry, int mode, | |||
| 365 | 364 | ||
| 366 | buf = kmalloc(sizeof(FILE_ALL_INFO), GFP_KERNEL); | 365 | buf = kmalloc(sizeof(FILE_ALL_INFO), GFP_KERNEL); |
| 367 | if (buf == NULL) { | 366 | if (buf == NULL) { |
| 368 | kfree(full_path); | 367 | rc = -ENOMEM; |
| 369 | FreeXid(xid); | 368 | goto cifs_create_out; |
| 370 | return -ENOMEM; | ||
| 371 | } | 369 | } |
| 372 | 370 | ||
| 373 | /* | 371 | /* |
| @@ -496,6 +494,11 @@ int cifs_mknod(struct inode *inode, struct dentry *direntry, int mode, | |||
| 496 | struct cifsTconInfo *pTcon; | 494 | struct cifsTconInfo *pTcon; |
| 497 | char *full_path = NULL; | 495 | char *full_path = NULL; |
| 498 | struct inode *newinode = NULL; | 496 | struct inode *newinode = NULL; |
| 497 | int oplock = 0; | ||
| 498 | u16 fileHandle; | ||
| 499 | FILE_ALL_INFO *buf = NULL; | ||
| 500 | unsigned int bytes_written; | ||
| 501 | struct win_dev *pdev; | ||
| 499 | 502 | ||
| 500 | if (!old_valid_dev(device_number)) | 503 | if (!old_valid_dev(device_number)) |
| 501 | return -EINVAL; | 504 | return -EINVAL; |
| @@ -506,9 +509,12 @@ int cifs_mknod(struct inode *inode, struct dentry *direntry, int mode, | |||
| 506 | pTcon = cifs_sb->tcon; | 509 | pTcon = cifs_sb->tcon; |
| 507 | 510 | ||
| 508 | full_path = build_path_from_dentry(direntry); | 511 | full_path = build_path_from_dentry(direntry); |
| 509 | if (full_path == NULL) | 512 | if (full_path == NULL) { |
| 510 | rc = -ENOMEM; | 513 | rc = -ENOMEM; |
| 511 | else if (pTcon->unix_ext) { | 514 | goto mknod_out; |
| 515 | } | ||
| 516 | |||
| 517 | if (pTcon->unix_ext) { | ||
| 512 | struct cifs_unix_set_info_args args = { | 518 | struct cifs_unix_set_info_args args = { |
| 513 | .mode = mode & ~current_umask(), | 519 | .mode = mode & ~current_umask(), |
| 514 | .ctime = NO_CHANGE_64, | 520 | .ctime = NO_CHANGE_64, |
| @@ -527,87 +533,78 @@ int cifs_mknod(struct inode *inode, struct dentry *direntry, int mode, | |||
| 527 | cifs_sb->local_nls, | 533 | cifs_sb->local_nls, |
| 528 | cifs_sb->mnt_cifs_flags & | 534 | cifs_sb->mnt_cifs_flags & |
| 529 | CIFS_MOUNT_MAP_SPECIAL_CHR); | 535 | CIFS_MOUNT_MAP_SPECIAL_CHR); |
| 536 | if (rc) | ||
| 537 | goto mknod_out; | ||
| 530 | 538 | ||
| 531 | if (!rc) { | 539 | rc = cifs_get_inode_info_unix(&newinode, full_path, |
| 532 | rc = cifs_get_inode_info_unix(&newinode, full_path, | ||
| 533 | inode->i_sb, xid); | 540 | inode->i_sb, xid); |
| 534 | if (pTcon->nocase) | 541 | if (pTcon->nocase) |
| 535 | direntry->d_op = &cifs_ci_dentry_ops; | 542 | direntry->d_op = &cifs_ci_dentry_ops; |
| 536 | else | 543 | else |
| 537 | direntry->d_op = &cifs_dentry_ops; | 544 | direntry->d_op = &cifs_dentry_ops; |
| 538 | if (rc == 0) | ||
| 539 | d_instantiate(direntry, newinode); | ||
| 540 | } | ||
| 541 | } else { | ||
| 542 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL) { | ||
| 543 | int oplock = 0; | ||
| 544 | u16 fileHandle; | ||
| 545 | FILE_ALL_INFO *buf; | ||
| 546 | 545 | ||
| 547 | cFYI(1, "sfu compat create special file"); | 546 | if (rc == 0) |
| 547 | d_instantiate(direntry, newinode); | ||
| 548 | goto mknod_out; | ||
| 549 | } | ||
| 548 | 550 | ||
| 549 | buf = kmalloc(sizeof(FILE_ALL_INFO), GFP_KERNEL); | 551 | if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL)) |
| 550 | if (buf == NULL) { | 552 | goto mknod_out; |
| 551 | kfree(full_path); | ||
| 552 | rc = -ENOMEM; | ||
| 553 | FreeXid(xid); | ||
| 554 | return rc; | ||
| 555 | } | ||
| 556 | 553 | ||
| 557 | rc = CIFSSMBOpen(xid, pTcon, full_path, | 554 | |
| 558 | FILE_CREATE, /* fail if exists */ | 555 | cFYI(1, "sfu compat create special file"); |
| 559 | GENERIC_WRITE /* BB would | 556 | |
| 560 | WRITE_OWNER | WRITE_DAC be better? */, | 557 | buf = kmalloc(sizeof(FILE_ALL_INFO), GFP_KERNEL); |
| 561 | /* Create a file and set the | 558 | if (buf == NULL) { |
| 562 | file attribute to SYSTEM */ | 559 | kfree(full_path); |
| 563 | CREATE_NOT_DIR | CREATE_OPTION_SPECIAL, | 560 | rc = -ENOMEM; |
| 564 | &fileHandle, &oplock, buf, | 561 | FreeXid(xid); |
| 565 | cifs_sb->local_nls, | 562 | return rc; |
| 566 | cifs_sb->mnt_cifs_flags & | ||
| 567 | CIFS_MOUNT_MAP_SPECIAL_CHR); | ||
| 568 | |||
| 569 | /* BB FIXME - add handling for backlevel servers | ||
| 570 | which need legacy open and check for all | ||
| 571 | calls to SMBOpen for fallback to SMBLeagcyOpen */ | ||
| 572 | if (!rc) { | ||
| 573 | /* BB Do not bother to decode buf since no | ||
| 574 | local inode yet to put timestamps in, | ||
| 575 | but we can reuse it safely */ | ||
| 576 | unsigned int bytes_written; | ||
| 577 | struct win_dev *pdev; | ||
| 578 | pdev = (struct win_dev *)buf; | ||
| 579 | if (S_ISCHR(mode)) { | ||
| 580 | memcpy(pdev->type, "IntxCHR", 8); | ||
| 581 | pdev->major = | ||
| 582 | cpu_to_le64(MAJOR(device_number)); | ||
| 583 | pdev->minor = | ||
| 584 | cpu_to_le64(MINOR(device_number)); | ||
| 585 | rc = CIFSSMBWrite(xid, pTcon, | ||
| 586 | fileHandle, | ||
| 587 | sizeof(struct win_dev), | ||
| 588 | 0, &bytes_written, (char *)pdev, | ||
| 589 | NULL, 0); | ||
| 590 | } else if (S_ISBLK(mode)) { | ||
| 591 | memcpy(pdev->type, "IntxBLK", 8); | ||
| 592 | pdev->major = | ||
| 593 | cpu_to_le64(MAJOR(device_number)); | ||
| 594 | pdev->minor = | ||
| 595 | cpu_to_le64(MINOR(device_number)); | ||
| 596 | rc = CIFSSMBWrite(xid, pTcon, | ||
| 597 | fileHandle, | ||
| 598 | sizeof(struct win_dev), | ||
| 599 | 0, &bytes_written, (char *)pdev, | ||
| 600 | NULL, 0); | ||
| 601 | } /* else if(S_ISFIFO */ | ||
| 602 | CIFSSMBClose(xid, pTcon, fileHandle); | ||
| 603 | d_drop(direntry); | ||
| 604 | } | ||
| 605 | kfree(buf); | ||
| 606 | /* add code here to set EAs */ | ||
| 607 | } | ||
| 608 | } | 563 | } |
| 609 | 564 | ||
| 565 | /* FIXME: would WRITE_OWNER | WRITE_DAC be better? */ | ||
| 566 | rc = CIFSSMBOpen(xid, pTcon, full_path, FILE_CREATE, | ||
| 567 | GENERIC_WRITE, CREATE_NOT_DIR | CREATE_OPTION_SPECIAL, | ||
| 568 | &fileHandle, &oplock, buf, cifs_sb->local_nls, | ||
| 569 | cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR); | ||
| 570 | if (rc) | ||
| 571 | goto mknod_out; | ||
| 572 | |||
| 573 | /* BB Do not bother to decode buf since no local inode yet to put | ||
| 574 | * timestamps in, but we can reuse it safely */ | ||
| 575 | |||
| 576 | pdev = (struct win_dev *)buf; | ||
| 577 | if (S_ISCHR(mode)) { | ||
| 578 | memcpy(pdev->type, "IntxCHR", 8); | ||
| 579 | pdev->major = | ||
| 580 | cpu_to_le64(MAJOR(device_number)); | ||
| 581 | pdev->minor = | ||
| 582 | cpu_to_le64(MINOR(device_number)); | ||
| 583 | rc = CIFSSMBWrite(xid, pTcon, | ||
| 584 | fileHandle, | ||
| 585 | sizeof(struct win_dev), | ||
| 586 | 0, &bytes_written, (char *)pdev, | ||
| 587 | NULL, 0); | ||
| 588 | } else if (S_ISBLK(mode)) { | ||
| 589 | memcpy(pdev->type, "IntxBLK", 8); | ||
| 590 | pdev->major = | ||
| 591 | cpu_to_le64(MAJOR(device_number)); | ||
| 592 | pdev->minor = | ||
| 593 | cpu_to_le64(MINOR(device_number)); | ||
| 594 | rc = CIFSSMBWrite(xid, pTcon, | ||
| 595 | fileHandle, | ||
| 596 | sizeof(struct win_dev), | ||
| 597 | 0, &bytes_written, (char *)pdev, | ||
| 598 | NULL, 0); | ||
| 599 | } /* else if (S_ISFIFO) */ | ||
| 600 | CIFSSMBClose(xid, pTcon, fileHandle); | ||
| 601 | d_drop(direntry); | ||
| 602 | |||
| 603 | /* FIXME: add code here to set EAs */ | ||
| 604 | |||
| 605 | mknod_out: | ||
| 610 | kfree(full_path); | 606 | kfree(full_path); |
| 607 | kfree(buf); | ||
| 611 | FreeXid(xid); | 608 | FreeXid(xid); |
| 612 | return rc; | 609 | return rc; |
| 613 | } | 610 | } |
diff --git a/fs/cifs/file.c b/fs/cifs/file.c index db11fdef0e92..de748c652d11 100644 --- a/fs/cifs/file.c +++ b/fs/cifs/file.c | |||
| @@ -242,8 +242,7 @@ int cifs_open(struct inode *inode, struct file *file) | |||
| 242 | full_path = build_path_from_dentry(file->f_path.dentry); | 242 | full_path = build_path_from_dentry(file->f_path.dentry); |
| 243 | if (full_path == NULL) { | 243 | if (full_path == NULL) { |
| 244 | rc = -ENOMEM; | 244 | rc = -ENOMEM; |
| 245 | FreeXid(xid); | 245 | goto out; |
| 246 | return rc; | ||
| 247 | } | 246 | } |
| 248 | 247 | ||
| 249 | cFYI(1, "inode = 0x%p file flags are 0x%x for %s", | 248 | cFYI(1, "inode = 0x%p file flags are 0x%x for %s", |
diff --git a/fs/cifs/ntlmssp.h b/fs/cifs/ntlmssp.h index 49c9a4e75319..1db0f0746a5b 100644 --- a/fs/cifs/ntlmssp.h +++ b/fs/cifs/ntlmssp.h | |||
| @@ -61,6 +61,19 @@ | |||
| 61 | #define NTLMSSP_NEGOTIATE_KEY_XCH 0x40000000 | 61 | #define NTLMSSP_NEGOTIATE_KEY_XCH 0x40000000 |
| 62 | #define NTLMSSP_NEGOTIATE_56 0x80000000 | 62 | #define NTLMSSP_NEGOTIATE_56 0x80000000 |
| 63 | 63 | ||
| 64 | /* Define AV Pair Field IDs */ | ||
| 65 | #define NTLMSSP_AV_EOL 0 | ||
| 66 | #define NTLMSSP_AV_NB_COMPUTER_NAME 1 | ||
| 67 | #define NTLMSSP_AV_NB_DOMAIN_NAME 2 | ||
| 68 | #define NTLMSSP_AV_DNS_COMPUTER_NAME 3 | ||
| 69 | #define NTLMSSP_AV_DNS_DOMAIN_NAME 4 | ||
| 70 | #define NTLMSSP_AV_DNS_TREE_NAME 5 | ||
| 71 | #define NTLMSSP_AV_FLAGS 6 | ||
| 72 | #define NTLMSSP_AV_TIMESTAMP 7 | ||
| 73 | #define NTLMSSP_AV_RESTRICTION 8 | ||
| 74 | #define NTLMSSP_AV_TARGET_NAME 9 | ||
| 75 | #define NTLMSSP_AV_CHANNEL_BINDINGS 10 | ||
| 76 | |||
| 64 | /* Although typedefs are not commonly used for structure definitions */ | 77 | /* Although typedefs are not commonly used for structure definitions */ |
| 65 | /* in the Linux kernel, in this particular case they are useful */ | 78 | /* in the Linux kernel, in this particular case they are useful */ |
| 66 | /* to more closely match the standards document for NTLMSSP from */ | 79 | /* to more closely match the standards document for NTLMSSP from */ |
diff --git a/fs/cifs/sess.c b/fs/cifs/sess.c index 0a57cb7db5dd..4788e16a02cc 100644 --- a/fs/cifs/sess.c +++ b/fs/cifs/sess.c | |||
| @@ -383,6 +383,9 @@ static int decode_ascii_ssetup(char **pbcc_area, int bleft, | |||
| 383 | static int decode_ntlmssp_challenge(char *bcc_ptr, int blob_len, | 383 | static int decode_ntlmssp_challenge(char *bcc_ptr, int blob_len, |
| 384 | struct cifsSesInfo *ses) | 384 | struct cifsSesInfo *ses) |
| 385 | { | 385 | { |
| 386 | unsigned int tioffset; /* challeng message target info area */ | ||
| 387 | unsigned int tilen; /* challeng message target info area length */ | ||
| 388 | |||
| 386 | CHALLENGE_MESSAGE *pblob = (CHALLENGE_MESSAGE *)bcc_ptr; | 389 | CHALLENGE_MESSAGE *pblob = (CHALLENGE_MESSAGE *)bcc_ptr; |
| 387 | 390 | ||
| 388 | if (blob_len < sizeof(CHALLENGE_MESSAGE)) { | 391 | if (blob_len < sizeof(CHALLENGE_MESSAGE)) { |
| @@ -405,6 +408,20 @@ static int decode_ntlmssp_challenge(char *bcc_ptr, int blob_len, | |||
| 405 | /* BB spec says that if AvId field of MsvAvTimestamp is populated then | 408 | /* BB spec says that if AvId field of MsvAvTimestamp is populated then |
| 406 | we must set the MIC field of the AUTHENTICATE_MESSAGE */ | 409 | we must set the MIC field of the AUTHENTICATE_MESSAGE */ |
| 407 | 410 | ||
| 411 | ses->server->ntlmssp.server_flags = le32_to_cpu(pblob->NegotiateFlags); | ||
| 412 | |||
| 413 | tioffset = cpu_to_le16(pblob->TargetInfoArray.BufferOffset); | ||
| 414 | tilen = cpu_to_le16(pblob->TargetInfoArray.Length); | ||
| 415 | ses->server->tilen = tilen; | ||
| 416 | if (tilen) { | ||
| 417 | ses->server->tiblob = kmalloc(tilen, GFP_KERNEL); | ||
| 418 | if (!ses->server->tiblob) { | ||
| 419 | cERROR(1, "Challenge target info allocation failure"); | ||
| 420 | return -ENOMEM; | ||
| 421 | } | ||
| 422 | memcpy(ses->server->tiblob, bcc_ptr + tioffset, tilen); | ||
| 423 | } | ||
| 424 | |||
| 408 | return 0; | 425 | return 0; |
| 409 | } | 426 | } |
| 410 | 427 | ||
| @@ -425,12 +442,13 @@ static void build_ntlmssp_negotiate_blob(unsigned char *pbuffer, | |||
| 425 | /* BB is NTLMV2 session security format easier to use here? */ | 442 | /* BB is NTLMV2 session security format easier to use here? */ |
| 426 | flags = NTLMSSP_NEGOTIATE_56 | NTLMSSP_REQUEST_TARGET | | 443 | flags = NTLMSSP_NEGOTIATE_56 | NTLMSSP_REQUEST_TARGET | |
| 427 | NTLMSSP_NEGOTIATE_128 | NTLMSSP_NEGOTIATE_UNICODE | | 444 | NTLMSSP_NEGOTIATE_128 | NTLMSSP_NEGOTIATE_UNICODE | |
| 428 | NTLMSSP_NEGOTIATE_NT_ONLY | NTLMSSP_NEGOTIATE_NTLM; | 445 | NTLMSSP_NEGOTIATE_NTLM; |
| 429 | if (ses->server->secMode & | 446 | if (ses->server->secMode & |
| 430 | (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED)) | 447 | (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED)) { |
| 431 | flags |= NTLMSSP_NEGOTIATE_SIGN; | 448 | flags |= NTLMSSP_NEGOTIATE_SIGN | |
| 432 | if (ses->server->secMode & SECMODE_SIGN_REQUIRED) | 449 | NTLMSSP_NEGOTIATE_KEY_XCH | |
| 433 | flags |= NTLMSSP_NEGOTIATE_ALWAYS_SIGN; | 450 | NTLMSSP_NEGOTIATE_EXTENDED_SEC; |
| 451 | } | ||
| 434 | 452 | ||
| 435 | sec_blob->NegotiateFlags |= cpu_to_le32(flags); | 453 | sec_blob->NegotiateFlags |= cpu_to_le32(flags); |
| 436 | 454 | ||
| @@ -451,10 +469,12 @@ static int build_ntlmssp_auth_blob(unsigned char *pbuffer, | |||
| 451 | struct cifsSesInfo *ses, | 469 | struct cifsSesInfo *ses, |
| 452 | const struct nls_table *nls_cp, bool first) | 470 | const struct nls_table *nls_cp, bool first) |
| 453 | { | 471 | { |
| 472 | int rc; | ||
| 473 | unsigned int size; | ||
| 454 | AUTHENTICATE_MESSAGE *sec_blob = (AUTHENTICATE_MESSAGE *)pbuffer; | 474 | AUTHENTICATE_MESSAGE *sec_blob = (AUTHENTICATE_MESSAGE *)pbuffer; |
| 455 | __u32 flags; | 475 | __u32 flags; |
| 456 | unsigned char *tmp; | 476 | unsigned char *tmp; |
| 457 | char ntlm_session_key[CIFS_SESS_KEY_SIZE]; | 477 | struct ntlmv2_resp ntlmv2_response = {}; |
| 458 | 478 | ||
| 459 | memcpy(sec_blob->Signature, NTLMSSP_SIGNATURE, 8); | 479 | memcpy(sec_blob->Signature, NTLMSSP_SIGNATURE, 8); |
| 460 | sec_blob->MessageType = NtLmAuthenticate; | 480 | sec_blob->MessageType = NtLmAuthenticate; |
| @@ -477,19 +497,25 @@ static int build_ntlmssp_auth_blob(unsigned char *pbuffer, | |||
| 477 | sec_blob->LmChallengeResponse.Length = 0; | 497 | sec_blob->LmChallengeResponse.Length = 0; |
| 478 | sec_blob->LmChallengeResponse.MaximumLength = 0; | 498 | sec_blob->LmChallengeResponse.MaximumLength = 0; |
| 479 | 499 | ||
| 480 | /* calculate session key, BB what about adding similar ntlmv2 path? */ | ||
| 481 | SMBNTencrypt(ses->password, ses->server->cryptKey, ntlm_session_key); | ||
| 482 | if (first) | ||
| 483 | cifs_calculate_mac_key(&ses->server->mac_signing_key, | ||
| 484 | ntlm_session_key, ses->password); | ||
| 485 | |||
| 486 | memcpy(tmp, ntlm_session_key, CIFS_SESS_KEY_SIZE); | ||
| 487 | sec_blob->NtChallengeResponse.BufferOffset = cpu_to_le32(tmp - pbuffer); | 500 | sec_blob->NtChallengeResponse.BufferOffset = cpu_to_le32(tmp - pbuffer); |
| 488 | sec_blob->NtChallengeResponse.Length = cpu_to_le16(CIFS_SESS_KEY_SIZE); | 501 | rc = setup_ntlmv2_rsp(ses, (char *)&ntlmv2_response, nls_cp); |
| 489 | sec_blob->NtChallengeResponse.MaximumLength = | 502 | if (rc) { |
| 490 | cpu_to_le16(CIFS_SESS_KEY_SIZE); | 503 | cERROR(1, "error rc: %d during ntlmssp ntlmv2 setup", rc); |
| 504 | goto setup_ntlmv2_ret; | ||
| 505 | } | ||
| 506 | size = sizeof(struct ntlmv2_resp); | ||
| 507 | memcpy(tmp, (char *)&ntlmv2_response, size); | ||
| 508 | tmp += size; | ||
| 509 | if (ses->server->tilen > 0) { | ||
| 510 | memcpy(tmp, ses->server->tiblob, ses->server->tilen); | ||
| 511 | tmp += ses->server->tilen; | ||
| 512 | } else | ||
| 513 | ses->server->tilen = 0; | ||
| 491 | 514 | ||
| 492 | tmp += CIFS_SESS_KEY_SIZE; | 515 | sec_blob->NtChallengeResponse.Length = cpu_to_le16(size + |
| 516 | ses->server->tilen); | ||
| 517 | sec_blob->NtChallengeResponse.MaximumLength = | ||
| 518 | cpu_to_le16(size + ses->server->tilen); | ||
| 493 | 519 | ||
| 494 | if (ses->domainName == NULL) { | 520 | if (ses->domainName == NULL) { |
| 495 | sec_blob->DomainName.BufferOffset = cpu_to_le32(tmp - pbuffer); | 521 | sec_blob->DomainName.BufferOffset = cpu_to_le32(tmp - pbuffer); |
| @@ -501,7 +527,6 @@ static int build_ntlmssp_auth_blob(unsigned char *pbuffer, | |||
| 501 | len = cifs_strtoUCS((__le16 *)tmp, ses->domainName, | 527 | len = cifs_strtoUCS((__le16 *)tmp, ses->domainName, |
| 502 | MAX_USERNAME_SIZE, nls_cp); | 528 | MAX_USERNAME_SIZE, nls_cp); |
| 503 | len *= 2; /* unicode is 2 bytes each */ | 529 | len *= 2; /* unicode is 2 bytes each */ |
| 504 | len += 2; /* trailing null */ | ||
| 505 | sec_blob->DomainName.BufferOffset = cpu_to_le32(tmp - pbuffer); | 530 | sec_blob->DomainName.BufferOffset = cpu_to_le32(tmp - pbuffer); |
| 506 | sec_blob->DomainName.Length = cpu_to_le16(len); | 531 | sec_blob->DomainName.Length = cpu_to_le16(len); |
| 507 | sec_blob->DomainName.MaximumLength = cpu_to_le16(len); | 532 | sec_blob->DomainName.MaximumLength = cpu_to_le16(len); |
| @@ -518,7 +543,6 @@ static int build_ntlmssp_auth_blob(unsigned char *pbuffer, | |||
| 518 | len = cifs_strtoUCS((__le16 *)tmp, ses->userName, | 543 | len = cifs_strtoUCS((__le16 *)tmp, ses->userName, |
| 519 | MAX_USERNAME_SIZE, nls_cp); | 544 | MAX_USERNAME_SIZE, nls_cp); |
| 520 | len *= 2; /* unicode is 2 bytes each */ | 545 | len *= 2; /* unicode is 2 bytes each */ |
| 521 | len += 2; /* trailing null */ | ||
| 522 | sec_blob->UserName.BufferOffset = cpu_to_le32(tmp - pbuffer); | 546 | sec_blob->UserName.BufferOffset = cpu_to_le32(tmp - pbuffer); |
| 523 | sec_blob->UserName.Length = cpu_to_le16(len); | 547 | sec_blob->UserName.Length = cpu_to_le16(len); |
| 524 | sec_blob->UserName.MaximumLength = cpu_to_le16(len); | 548 | sec_blob->UserName.MaximumLength = cpu_to_le16(len); |
| @@ -530,9 +554,26 @@ static int build_ntlmssp_auth_blob(unsigned char *pbuffer, | |||
| 530 | sec_blob->WorkstationName.MaximumLength = 0; | 554 | sec_blob->WorkstationName.MaximumLength = 0; |
| 531 | tmp += 2; | 555 | tmp += 2; |
| 532 | 556 | ||
| 533 | sec_blob->SessionKey.BufferOffset = cpu_to_le32(tmp - pbuffer); | 557 | if ((ses->server->ntlmssp.server_flags & NTLMSSP_NEGOTIATE_KEY_XCH) && |
| 534 | sec_blob->SessionKey.Length = 0; | 558 | !calc_seckey(ses->server)) { |
| 535 | sec_blob->SessionKey.MaximumLength = 0; | 559 | memcpy(tmp, ses->server->ntlmssp.ciphertext, CIFS_CPHTXT_SIZE); |
| 560 | sec_blob->SessionKey.BufferOffset = cpu_to_le32(tmp - pbuffer); | ||
| 561 | sec_blob->SessionKey.Length = cpu_to_le16(CIFS_CPHTXT_SIZE); | ||
| 562 | sec_blob->SessionKey.MaximumLength = | ||
| 563 | cpu_to_le16(CIFS_CPHTXT_SIZE); | ||
| 564 | tmp += CIFS_CPHTXT_SIZE; | ||
| 565 | } else { | ||
| 566 | sec_blob->SessionKey.BufferOffset = cpu_to_le32(tmp - pbuffer); | ||
| 567 | sec_blob->SessionKey.Length = 0; | ||
| 568 | sec_blob->SessionKey.MaximumLength = 0; | ||
| 569 | } | ||
| 570 | |||
| 571 | ses->server->sequence_number = 0; | ||
| 572 | |||
| 573 | setup_ntlmv2_ret: | ||
| 574 | if (ses->server->tilen > 0) | ||
| 575 | kfree(ses->server->tiblob); | ||
| 576 | |||
| 536 | return tmp - pbuffer; | 577 | return tmp - pbuffer; |
| 537 | } | 578 | } |
| 538 | 579 | ||
| @@ -546,15 +587,14 @@ static void setup_ntlmssp_neg_req(SESSION_SETUP_ANDX *pSMB, | |||
| 546 | return; | 587 | return; |
| 547 | } | 588 | } |
| 548 | 589 | ||
| 549 | static int setup_ntlmssp_auth_req(SESSION_SETUP_ANDX *pSMB, | 590 | static int setup_ntlmssp_auth_req(char *ntlmsspblob, |
| 550 | struct cifsSesInfo *ses, | 591 | struct cifsSesInfo *ses, |
| 551 | const struct nls_table *nls, bool first_time) | 592 | const struct nls_table *nls, bool first_time) |
| 552 | { | 593 | { |
| 553 | int bloblen; | 594 | int bloblen; |
| 554 | 595 | ||
| 555 | bloblen = build_ntlmssp_auth_blob(&pSMB->req.SecurityBlob[0], ses, nls, | 596 | bloblen = build_ntlmssp_auth_blob(ntlmsspblob, ses, nls, |
| 556 | first_time); | 597 | first_time); |
| 557 | pSMB->req.SecurityBlobLength = cpu_to_le16(bloblen); | ||
| 558 | 598 | ||
| 559 | return bloblen; | 599 | return bloblen; |
| 560 | } | 600 | } |
| @@ -580,6 +620,7 @@ CIFS_SessSetup(unsigned int xid, struct cifsSesInfo *ses, | |||
| 580 | struct key *spnego_key = NULL; | 620 | struct key *spnego_key = NULL; |
| 581 | __le32 phase = NtLmNegotiate; /* NTLMSSP, if needed, is multistage */ | 621 | __le32 phase = NtLmNegotiate; /* NTLMSSP, if needed, is multistage */ |
| 582 | bool first_time; | 622 | bool first_time; |
| 623 | char *ntlmsspblob; | ||
| 583 | 624 | ||
| 584 | if (ses == NULL) | 625 | if (ses == NULL) |
| 585 | return -EINVAL; | 626 | return -EINVAL; |
| @@ -690,7 +731,7 @@ ssetup_ntlmssp_authenticate: | |||
| 690 | 731 | ||
| 691 | if (first_time) /* should this be moved into common code | 732 | if (first_time) /* should this be moved into common code |
| 692 | with similar ntlmv2 path? */ | 733 | with similar ntlmv2 path? */ |
| 693 | cifs_calculate_mac_key(&ses->server->mac_signing_key, | 734 | cifs_calculate_session_key(&ses->server->session_key, |
| 694 | ntlm_session_key, ses->password); | 735 | ntlm_session_key, ses->password); |
| 695 | /* copy session key */ | 736 | /* copy session key */ |
| 696 | 737 | ||
| @@ -729,12 +770,21 @@ ssetup_ntlmssp_authenticate: | |||
| 729 | cpu_to_le16(sizeof(struct ntlmv2_resp)); | 770 | cpu_to_le16(sizeof(struct ntlmv2_resp)); |
| 730 | 771 | ||
| 731 | /* calculate session key */ | 772 | /* calculate session key */ |
| 732 | setup_ntlmv2_rsp(ses, v2_sess_key, nls_cp); | 773 | rc = setup_ntlmv2_rsp(ses, v2_sess_key, nls_cp); |
| 774 | if (rc) { | ||
| 775 | kfree(v2_sess_key); | ||
| 776 | goto ssetup_exit; | ||
| 777 | } | ||
| 733 | /* FIXME: calculate MAC key */ | 778 | /* FIXME: calculate MAC key */ |
| 734 | memcpy(bcc_ptr, (char *)v2_sess_key, | 779 | memcpy(bcc_ptr, (char *)v2_sess_key, |
| 735 | sizeof(struct ntlmv2_resp)); | 780 | sizeof(struct ntlmv2_resp)); |
| 736 | bcc_ptr += sizeof(struct ntlmv2_resp); | 781 | bcc_ptr += sizeof(struct ntlmv2_resp); |
| 737 | kfree(v2_sess_key); | 782 | kfree(v2_sess_key); |
| 783 | if (ses->server->tilen > 0) { | ||
| 784 | memcpy(bcc_ptr, ses->server->tiblob, | ||
| 785 | ses->server->tilen); | ||
| 786 | bcc_ptr += ses->server->tilen; | ||
| 787 | } | ||
| 738 | if (ses->capabilities & CAP_UNICODE) { | 788 | if (ses->capabilities & CAP_UNICODE) { |
| 739 | if (iov[0].iov_len % 2) { | 789 | if (iov[0].iov_len % 2) { |
| 740 | *bcc_ptr = 0; | 790 | *bcc_ptr = 0; |
| @@ -765,15 +815,15 @@ ssetup_ntlmssp_authenticate: | |||
| 765 | } | 815 | } |
| 766 | /* bail out if key is too long */ | 816 | /* bail out if key is too long */ |
| 767 | if (msg->sesskey_len > | 817 | if (msg->sesskey_len > |
| 768 | sizeof(ses->server->mac_signing_key.data.krb5)) { | 818 | sizeof(ses->server->session_key.data.krb5)) { |
| 769 | cERROR(1, "Kerberos signing key too long (%u bytes)", | 819 | cERROR(1, "Kerberos signing key too long (%u bytes)", |
| 770 | msg->sesskey_len); | 820 | msg->sesskey_len); |
| 771 | rc = -EOVERFLOW; | 821 | rc = -EOVERFLOW; |
| 772 | goto ssetup_exit; | 822 | goto ssetup_exit; |
| 773 | } | 823 | } |
| 774 | if (first_time) { | 824 | if (first_time) { |
| 775 | ses->server->mac_signing_key.len = msg->sesskey_len; | 825 | ses->server->session_key.len = msg->sesskey_len; |
| 776 | memcpy(ses->server->mac_signing_key.data.krb5, | 826 | memcpy(ses->server->session_key.data.krb5, |
| 777 | msg->data, msg->sesskey_len); | 827 | msg->data, msg->sesskey_len); |
| 778 | } | 828 | } |
| 779 | pSMB->req.hdr.Flags2 |= SMBFLG2_EXT_SEC; | 829 | pSMB->req.hdr.Flags2 |= SMBFLG2_EXT_SEC; |
| @@ -815,12 +865,26 @@ ssetup_ntlmssp_authenticate: | |||
| 815 | if (phase == NtLmNegotiate) { | 865 | if (phase == NtLmNegotiate) { |
| 816 | setup_ntlmssp_neg_req(pSMB, ses); | 866 | setup_ntlmssp_neg_req(pSMB, ses); |
| 817 | iov[1].iov_len = sizeof(NEGOTIATE_MESSAGE); | 867 | iov[1].iov_len = sizeof(NEGOTIATE_MESSAGE); |
| 868 | iov[1].iov_base = &pSMB->req.SecurityBlob[0]; | ||
| 818 | } else if (phase == NtLmAuthenticate) { | 869 | } else if (phase == NtLmAuthenticate) { |
| 819 | int blob_len; | 870 | int blob_len; |
| 820 | blob_len = setup_ntlmssp_auth_req(pSMB, ses, | 871 | ntlmsspblob = kmalloc(5 * |
| 821 | nls_cp, | 872 | sizeof(struct _AUTHENTICATE_MESSAGE), |
| 822 | first_time); | 873 | GFP_KERNEL); |
| 874 | if (!ntlmsspblob) { | ||
| 875 | cERROR(1, "Can't allocate NTLMSSP"); | ||
| 876 | rc = -ENOMEM; | ||
| 877 | goto ssetup_exit; | ||
| 878 | } | ||
| 879 | |||
| 880 | blob_len = setup_ntlmssp_auth_req(ntlmsspblob, | ||
| 881 | ses, | ||
| 882 | nls_cp, | ||
| 883 | first_time); | ||
| 823 | iov[1].iov_len = blob_len; | 884 | iov[1].iov_len = blob_len; |
| 885 | iov[1].iov_base = ntlmsspblob; | ||
| 886 | pSMB->req.SecurityBlobLength = | ||
| 887 | cpu_to_le16(blob_len); | ||
| 824 | /* Make sure that we tell the server that we | 888 | /* Make sure that we tell the server that we |
| 825 | are using the uid that it just gave us back | 889 | are using the uid that it just gave us back |
| 826 | on the response (challenge) */ | 890 | on the response (challenge) */ |
| @@ -830,7 +894,6 @@ ssetup_ntlmssp_authenticate: | |||
| 830 | rc = -ENOSYS; | 894 | rc = -ENOSYS; |
| 831 | goto ssetup_exit; | 895 | goto ssetup_exit; |
| 832 | } | 896 | } |
| 833 | iov[1].iov_base = &pSMB->req.SecurityBlob[0]; | ||
| 834 | /* unicode strings must be word aligned */ | 897 | /* unicode strings must be word aligned */ |
| 835 | if ((iov[0].iov_len + iov[1].iov_len) % 2) { | 898 | if ((iov[0].iov_len + iov[1].iov_len) % 2) { |
| 836 | *bcc_ptr = 0; | 899 | *bcc_ptr = 0; |
diff --git a/fs/cifs/transport.c b/fs/cifs/transport.c index 82f78c4d6978..e0588cdf4cc5 100644 --- a/fs/cifs/transport.c +++ b/fs/cifs/transport.c | |||
| @@ -543,7 +543,7 @@ SendReceive2(const unsigned int xid, struct cifsSesInfo *ses, | |||
| 543 | (ses->server->secMode & (SECMODE_SIGN_REQUIRED | | 543 | (ses->server->secMode & (SECMODE_SIGN_REQUIRED | |
| 544 | SECMODE_SIGN_ENABLED))) { | 544 | SECMODE_SIGN_ENABLED))) { |
| 545 | rc = cifs_verify_signature(midQ->resp_buf, | 545 | rc = cifs_verify_signature(midQ->resp_buf, |
| 546 | &ses->server->mac_signing_key, | 546 | ses->server, |
| 547 | midQ->sequence_number+1); | 547 | midQ->sequence_number+1); |
| 548 | if (rc) { | 548 | if (rc) { |
| 549 | cERROR(1, "Unexpected SMB signature"); | 549 | cERROR(1, "Unexpected SMB signature"); |
| @@ -731,7 +731,7 @@ SendReceive(const unsigned int xid, struct cifsSesInfo *ses, | |||
| 731 | (ses->server->secMode & (SECMODE_SIGN_REQUIRED | | 731 | (ses->server->secMode & (SECMODE_SIGN_REQUIRED | |
| 732 | SECMODE_SIGN_ENABLED))) { | 732 | SECMODE_SIGN_ENABLED))) { |
| 733 | rc = cifs_verify_signature(out_buf, | 733 | rc = cifs_verify_signature(out_buf, |
| 734 | &ses->server->mac_signing_key, | 734 | ses->server, |
| 735 | midQ->sequence_number+1); | 735 | midQ->sequence_number+1); |
| 736 | if (rc) { | 736 | if (rc) { |
| 737 | cERROR(1, "Unexpected SMB signature"); | 737 | cERROR(1, "Unexpected SMB signature"); |
| @@ -981,7 +981,7 @@ SendReceiveBlockingLock(const unsigned int xid, struct cifsTconInfo *tcon, | |||
| 981 | (ses->server->secMode & (SECMODE_SIGN_REQUIRED | | 981 | (ses->server->secMode & (SECMODE_SIGN_REQUIRED | |
| 982 | SECMODE_SIGN_ENABLED))) { | 982 | SECMODE_SIGN_ENABLED))) { |
| 983 | rc = cifs_verify_signature(out_buf, | 983 | rc = cifs_verify_signature(out_buf, |
| 984 | &ses->server->mac_signing_key, | 984 | ses->server, |
| 985 | midQ->sequence_number+1); | 985 | midQ->sequence_number+1); |
| 986 | if (rc) { | 986 | if (rc) { |
| 987 | cERROR(1, "Unexpected SMB signature"); | 987 | cERROR(1, "Unexpected SMB signature"); |
