Skip to content

Commit 5f98ca9

Browse files
shirishpargaonkarSteve French
authored andcommitted
cifs NTLMv2/NTLMSSP Change variable name mac_key to session key to reflect the key it holds
Change name of variable mac_key to session key. The reason mac_key was changed to session key is, this structure does not hold message authentication code, it holds the session key (for ntlmv2, ntlmv1 etc.). mac is generated as a signature in cifs_calc* functions. Signed-off-by: Shirish Pargaonkar <shirishpargaonkar@gmail.com> Signed-off-by: Steve French <sfrench@us.ibm.com>
1 parent aa91c7e commit 5f98ca9

File tree

5 files changed

+23
-23
lines changed

5 files changed

+23
-23
lines changed

fs/cifs/cifsencrypt.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ extern void SMBencrypt(unsigned char *passwd, const unsigned char *c8,
4242
unsigned char *p24);
4343

4444
static int cifs_calculate_signature(const struct smb_hdr *cifs_pdu,
45-
const struct mac_key *key, char *signature)
45+
const struct session_key *key, char *signature)
4646
{
4747
struct MD5Context context;
4848

@@ -78,7 +78,7 @@ int cifs_sign_smb(struct smb_hdr *cifs_pdu, struct TCP_Server_Info *server,
7878
server->sequence_number++;
7979
spin_unlock(&GlobalMid_Lock);
8080

81-
rc = cifs_calculate_signature(cifs_pdu, &server->mac_signing_key,
81+
rc = cifs_calculate_signature(cifs_pdu, &server->session_key,
8282
smb_signature);
8383
if (rc)
8484
memset(cifs_pdu->Signature.SecuritySignature, 0, 8);
@@ -89,7 +89,7 @@ int cifs_sign_smb(struct smb_hdr *cifs_pdu, struct TCP_Server_Info *server,
8989
}
9090

9191
static int cifs_calc_signature2(const struct kvec *iov, int n_vec,
92-
const struct mac_key *key, char *signature)
92+
const struct session_key *key, char *signature)
9393
{
9494
struct MD5Context context;
9595
int i;
@@ -145,7 +145,7 @@ int cifs_sign_smb2(struct kvec *iov, int n_vec, struct TCP_Server_Info *server,
145145
server->sequence_number++;
146146
spin_unlock(&GlobalMid_Lock);
147147

148-
rc = cifs_calc_signature2(iov, n_vec, &server->mac_signing_key,
148+
rc = cifs_calc_signature2(iov, n_vec, &server->session_key,
149149
smb_signature);
150150
if (rc)
151151
memset(cifs_pdu->Signature.SecuritySignature, 0, 8);
@@ -156,14 +156,14 @@ int cifs_sign_smb2(struct kvec *iov, int n_vec, struct TCP_Server_Info *server,
156156
}
157157

158158
int cifs_verify_signature(struct smb_hdr *cifs_pdu,
159-
const struct mac_key *mac_key,
159+
const struct session_key *session_key,
160160
__u32 expected_sequence_number)
161161
{
162162
unsigned int rc;
163163
char server_response_sig[8];
164164
char what_we_think_sig_should_be[20];
165165

166-
if ((cifs_pdu == NULL) || (mac_key == NULL))
166+
if (cifs_pdu == NULL || session_key == NULL)
167167
return -EINVAL;
168168

169169
if (cifs_pdu->Command == SMB_COM_NEGOTIATE)
@@ -192,7 +192,7 @@ int cifs_verify_signature(struct smb_hdr *cifs_pdu,
192192
cpu_to_le32(expected_sequence_number);
193193
cifs_pdu->Signature.Sequence.Reserved = 0;
194194

195-
rc = cifs_calculate_signature(cifs_pdu, mac_key,
195+
rc = cifs_calculate_signature(cifs_pdu, session_key,
196196
what_we_think_sig_should_be);
197197

198198
if (rc)
@@ -209,7 +209,7 @@ int cifs_verify_signature(struct smb_hdr *cifs_pdu,
209209
}
210210

211211
/* 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,
212+
int cifs_calculate_session_key(struct session_key *key, const char *rn,
213213
const char *password)
214214
{
215215
char temp_key[16];
@@ -347,11 +347,11 @@ void setup_ntlmv2_rsp(struct cifsSesInfo *ses, char *resp_buf,
347347
/* now calculate the MAC key for NTLMv2 */
348348
hmac_md5_init_limK_to_64(ses->server->ntlmv2_hash, 16, &context);
349349
hmac_md5_update(resp_buf, 16, &context);
350-
hmac_md5_final(ses->server->mac_signing_key.data.ntlmv2.key, &context);
350+
hmac_md5_final(ses->server->session_key.data.ntlmv2.key, &context);
351351

352-
memcpy(&ses->server->mac_signing_key.data.ntlmv2.resp, resp_buf,
352+
memcpy(&ses->server->session_key.data.ntlmv2.resp, resp_buf,
353353
sizeof(struct ntlmv2_resp));
354-
ses->server->mac_signing_key.len = 16 + sizeof(struct ntlmv2_resp);
354+
ses->server->session_key.len = 16 + sizeof(struct ntlmv2_resp);
355355
}
356356

357357
void CalcNTLMv2_response(const struct cifsSesInfo *ses,

fs/cifs/cifsglob.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ enum protocolEnum {
9797
/* Netbios frames protocol not supported at this time */
9898
};
9999

100-
struct mac_key {
100+
struct session_key {
101101
unsigned int len;
102102
union {
103103
char ntlm[CIFS_SESS_KEY_SIZE + 16];
@@ -182,7 +182,7 @@ struct TCP_Server_Info {
182182
/* 16th byte of RFC1001 workstation name is always null */
183183
char workstation_RFC1001_name[RFC1001_NAME_LEN_WITH_NULL];
184184
__u32 sequence_number; /* needed for CIFS PDU signature */
185-
struct mac_key mac_signing_key;
185+
struct session_key session_key;
186186
char ntlmv2_hash[16];
187187
unsigned long lstrp; /* when we got last response from this server */
188188
u16 dialect; /* dialect index that server chose */

fs/cifs/cifsproto.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,9 +363,9 @@ extern int cifs_sign_smb(struct smb_hdr *, struct TCP_Server_Info *, __u32 *);
363363
extern int cifs_sign_smb2(struct kvec *iov, int n_vec, struct TCP_Server_Info *,
364364
__u32 *);
365365
extern int cifs_verify_signature(struct smb_hdr *,
366-
const struct mac_key *mac_key,
366+
const struct session_key *session_key,
367367
__u32 expected_sequence_number);
368-
extern int cifs_calculate_mac_key(struct mac_key *key, const char *rn,
368+
extern int cifs_calculate_session_key(struct session_key *key, const char *rn,
369369
const char *pass);
370370
extern void CalcNTLMv2_response(const struct cifsSesInfo *, char *);
371371
extern void setup_ntlmv2_rsp(struct cifsSesInfo *, char *,

fs/cifs/sess.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ static int build_ntlmssp_auth_blob(unsigned char *pbuffer,
480480
/* calculate session key, BB what about adding similar ntlmv2 path? */
481481
SMBNTencrypt(ses->password, ses->server->cryptKey, ntlm_session_key);
482482
if (first)
483-
cifs_calculate_mac_key(&ses->server->mac_signing_key,
483+
cifs_calculate_session_key(&ses->server->session_key,
484484
ntlm_session_key, ses->password);
485485

486486
memcpy(tmp, ntlm_session_key, CIFS_SESS_KEY_SIZE);
@@ -690,7 +690,7 @@ CIFS_SessSetup(unsigned int xid, struct cifsSesInfo *ses,
690690

691691
if (first_time) /* should this be moved into common code
692692
with similar ntlmv2 path? */
693-
cifs_calculate_mac_key(&ses->server->mac_signing_key,
693+
cifs_calculate_session_key(&ses->server->session_key,
694694
ntlm_session_key, ses->password);
695695
/* copy session key */
696696

@@ -765,15 +765,15 @@ CIFS_SessSetup(unsigned int xid, struct cifsSesInfo *ses,
765765
}
766766
/* bail out if key is too long */
767767
if (msg->sesskey_len >
768-
sizeof(ses->server->mac_signing_key.data.krb5)) {
768+
sizeof(ses->server->session_key.data.krb5)) {
769769
cERROR(1, "Kerberos signing key too long (%u bytes)",
770770
msg->sesskey_len);
771771
rc = -EOVERFLOW;
772772
goto ssetup_exit;
773773
}
774774
if (first_time) {
775-
ses->server->mac_signing_key.len = msg->sesskey_len;
776-
memcpy(ses->server->mac_signing_key.data.krb5,
775+
ses->server->session_key.len = msg->sesskey_len;
776+
memcpy(ses->server->session_key.data.krb5,
777777
msg->data, msg->sesskey_len);
778778
}
779779
pSMB->req.hdr.Flags2 |= SMBFLG2_EXT_SEC;

fs/cifs/transport.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ SendReceive2(const unsigned int xid, struct cifsSesInfo *ses,
543543
(ses->server->secMode & (SECMODE_SIGN_REQUIRED |
544544
SECMODE_SIGN_ENABLED))) {
545545
rc = cifs_verify_signature(midQ->resp_buf,
546-
&ses->server->mac_signing_key,
546+
&ses->server->session_key,
547547
midQ->sequence_number+1);
548548
if (rc) {
549549
cERROR(1, "Unexpected SMB signature");
@@ -731,7 +731,7 @@ SendReceive(const unsigned int xid, struct cifsSesInfo *ses,
731731
(ses->server->secMode & (SECMODE_SIGN_REQUIRED |
732732
SECMODE_SIGN_ENABLED))) {
733733
rc = cifs_verify_signature(out_buf,
734-
&ses->server->mac_signing_key,
734+
&ses->server->session_key,
735735
midQ->sequence_number+1);
736736
if (rc) {
737737
cERROR(1, "Unexpected SMB signature");
@@ -981,7 +981,7 @@ SendReceiveBlockingLock(const unsigned int xid, struct cifsTconInfo *tcon,
981981
(ses->server->secMode & (SECMODE_SIGN_REQUIRED |
982982
SECMODE_SIGN_ENABLED))) {
983983
rc = cifs_verify_signature(out_buf,
984-
&ses->server->mac_signing_key,
984+
&ses->server->session_key,
985985
midQ->sequence_number+1);
986986
if (rc) {
987987
cERROR(1, "Unexpected SMB signature");

0 commit comments

Comments
 (0)