@@ -45,39 +45,38 @@ extern void SMBencrypt(unsigned char *passwd, const unsigned char *c8,
45
45
static int cifs_calculate_signature (const struct smb_hdr * cifs_pdu ,
46
46
struct TCP_Server_Info * server , char * signature )
47
47
{
48
- int rc = 0 ;
49
- struct {
50
- struct shash_desc shash ;
51
- char ctx [crypto_shash_descsize (server -> ntlmssp .md5 )];
52
- } sdesc ;
48
+ int rc ;
53
49
54
50
if (cifs_pdu == NULL || server == NULL || signature == NULL )
55
51
return - EINVAL ;
56
52
57
- sdesc .shash .tfm = server -> ntlmssp .md5 ;
58
- sdesc .shash .flags = 0x0 ;
53
+ if (!server -> ntlmssp .sdescmd5 ) {
54
+ cERROR (1 ,
55
+ "cifs_calculate_signature: can't generate signature\n" );
56
+ return -1 ;
57
+ }
59
58
60
- rc = crypto_shash_init (& sdesc . shash );
59
+ rc = crypto_shash_init (& server -> ntlmssp . sdescmd5 -> shash );
61
60
if (rc ) {
62
- cERROR (1 , "could not initialize master crypto API hmacmd5 \n" );
61
+ cERROR (1 , "cifs_calculate_signature: oould not init md5 \n" );
63
62
return rc ;
64
63
}
65
64
66
65
if (server -> secType == RawNTLMSSP )
67
- crypto_shash_update (& sdesc . shash ,
66
+ crypto_shash_update (& server -> ntlmssp . sdescmd5 -> shash ,
68
67
server -> session_key .data .ntlmv2 .key ,
69
68
CIFS_NTLMV2_SESSKEY_SIZE );
70
69
else
71
- crypto_shash_update (& sdesc . shash ,
70
+ crypto_shash_update (& server -> ntlmssp . sdescmd5 -> shash ,
72
71
(char * )& server -> session_key .data ,
73
72
server -> session_key .len );
74
73
75
- crypto_shash_update (& sdesc . shash ,
74
+ crypto_shash_update (& server -> ntlmssp . sdescmd5 -> shash ,
76
75
cifs_pdu -> Protocol , cifs_pdu -> smb_buf_length );
77
76
78
- rc = crypto_shash_final (& sdesc . shash , signature );
77
+ rc = crypto_shash_final (& server -> ntlmssp . sdescmd5 -> shash , signature );
79
78
80
- return 0 ;
79
+ return rc ;
81
80
}
82
81
83
82
@@ -115,55 +114,53 @@ static int cifs_calc_signature2(const struct kvec *iov, int n_vec,
115
114
struct TCP_Server_Info * server , char * signature )
116
115
{
117
116
int i ;
118
- int rc = 0 ;
119
- struct {
120
- struct shash_desc shash ;
121
- char ctx [crypto_shash_descsize (server -> ntlmssp .md5 )];
122
- } sdesc ;
117
+ int rc ;
123
118
124
119
if (iov == NULL || server == NULL || signature == NULL )
125
120
return - EINVAL ;
126
121
127
- sdesc .shash .tfm = server -> ntlmssp .md5 ;
128
- sdesc .shash .flags = 0x0 ;
122
+ if (!server -> ntlmssp .sdescmd5 ) {
123
+ cERROR (1 , "cifs_calc_signature2: can't generate signature\n" );
124
+ return -1 ;
125
+ }
129
126
130
- rc = crypto_shash_init (& sdesc . shash );
127
+ rc = crypto_shash_init (& server -> ntlmssp . sdescmd5 -> shash );
131
128
if (rc ) {
132
- cERROR (1 , "could not initialize master crypto API hmacmd5 \n" );
129
+ cERROR (1 , "cifs_calc_signature2: oould not init md5 \n" );
133
130
return rc ;
134
131
}
135
132
136
133
if (server -> secType == RawNTLMSSP )
137
- crypto_shash_update (& sdesc . shash ,
134
+ crypto_shash_update (& server -> ntlmssp . sdescmd5 -> shash ,
138
135
server -> session_key .data .ntlmv2 .key ,
139
136
CIFS_NTLMV2_SESSKEY_SIZE );
140
137
else
141
- crypto_shash_update (& sdesc . shash ,
138
+ crypto_shash_update (& server -> ntlmssp . sdescmd5 -> shash ,
142
139
(char * )& server -> session_key .data ,
143
140
server -> session_key .len );
144
141
145
142
for (i = 0 ; i < n_vec ; i ++ ) {
146
143
if (iov [i ].iov_len == 0 )
147
144
continue ;
148
145
if (iov [i ].iov_base == NULL ) {
149
- cERROR (1 , "null iovec entry" );
146
+ cERROR (1 , "cifs_calc_signature2: null iovec entry" );
150
147
return - EIO ;
151
148
}
152
149
/* The first entry includes a length field (which does not get
153
150
signed that occupies the first 4 bytes before the header */
154
151
if (i == 0 ) {
155
152
if (iov [0 ].iov_len <= 8 ) /* cmd field at offset 9 */
156
153
break ; /* nothing to sign or corrupt header */
157
- crypto_shash_update (& sdesc . shash ,
154
+ crypto_shash_update (& server -> ntlmssp . sdescmd5 -> shash ,
158
155
iov [i ].iov_base + 4 , iov [i ].iov_len - 4 );
159
156
} else
160
- crypto_shash_update (& sdesc . shash ,
157
+ crypto_shash_update (& server -> ntlmssp . sdescmd5 -> shash ,
161
158
iov [i ].iov_base , iov [i ].iov_len );
162
159
}
163
160
164
- rc = crypto_shash_final (& sdesc . shash , signature );
161
+ rc = crypto_shash_final (& server -> ntlmssp . sdescmd5 -> shash , signature );
165
162
166
- return 0 ;
163
+ return rc ;
167
164
}
168
165
169
166
int cifs_sign_smb2 (struct kvec * iov , int n_vec , struct TCP_Server_Info * server ,
@@ -313,76 +310,89 @@ static int calc_ntlmv2_hash(struct cifsSesInfo *ses,
313
310
wchar_t * user ;
314
311
wchar_t * domain ;
315
312
wchar_t * server ;
316
- struct {
317
- struct shash_desc shash ;
318
- char ctx [crypto_shash_descsize (ses -> server -> ntlmssp .hmacmd5 )];
319
- } sdesc ;
313
+
314
+ if (!ses -> server -> ntlmssp .sdeschmacmd5 ) {
315
+ cERROR (1 , "calc_ntlmv2_hash: can't generate ntlmv2 hash\n" );
316
+ return -1 ;
317
+ }
320
318
321
319
/* calculate md4 hash of password */
322
320
E_md4hash (ses -> password , nt_hash );
323
321
324
- sdesc .shash .tfm = ses -> server -> ntlmssp .hmacmd5 ;
325
- sdesc .shash .flags = 0x0 ;
326
-
327
322
crypto_shash_setkey (ses -> server -> ntlmssp .hmacmd5 , nt_hash ,
328
323
CIFS_NTHASH_SIZE );
329
324
330
- rc = crypto_shash_init (& sdesc . shash );
325
+ rc = crypto_shash_init (& ses -> server -> ntlmssp . sdeschmacmd5 -> shash );
331
326
if (rc ) {
332
- cERROR (1 , "could not initialize master crypto API hmacmd5\n" );
327
+ cERROR (1 , "calc_ntlmv2_hash: could not init hmacmd5\n" );
333
328
return rc ;
334
329
}
335
330
336
331
/* convert ses->userName to unicode and uppercase */
337
332
len = strlen (ses -> userName );
338
333
user = kmalloc (2 + (len * 2 ), GFP_KERNEL );
339
- if (user == NULL )
334
+ if (user == NULL ) {
335
+ cERROR (1 , "calc_ntlmv2_hash: user mem alloc failure\n" );
336
+ rc = - ENOMEM ;
340
337
goto calc_exit_2 ;
338
+ }
341
339
len = cifs_strtoUCS ((__le16 * )user , ses -> userName , len , nls_cp );
342
340
UniStrupr (user );
343
341
344
- crypto_shash_update (& sdesc .shash , (char * )user , 2 * len );
342
+ crypto_shash_update (& ses -> server -> ntlmssp .sdeschmacmd5 -> shash ,
343
+ (char * )user , 2 * len );
345
344
346
345
/* convert ses->domainName to unicode and uppercase */
347
346
if (ses -> domainName ) {
348
347
len = strlen (ses -> domainName );
349
348
350
349
domain = kmalloc (2 + (len * 2 ), GFP_KERNEL );
351
- if (domain == NULL )
350
+ if (domain == NULL ) {
351
+ cERROR (1 , "calc_ntlmv2_hash: domain mem alloc failure" );
352
+ rc = - ENOMEM ;
352
353
goto calc_exit_1 ;
354
+ }
353
355
len = cifs_strtoUCS ((__le16 * )domain , ses -> domainName , len ,
354
356
nls_cp );
355
357
/* the following line was removed since it didn't work well
356
358
with lower cased domain name that passed as an option.
357
359
Maybe converting the domain name earlier makes sense */
358
360
/* UniStrupr(domain); */
359
361
360
- crypto_shash_update (& sdesc .shash , (char * )domain , 2 * len );
362
+ crypto_shash_update (& ses -> server -> ntlmssp .sdeschmacmd5 -> shash ,
363
+ (char * )domain , 2 * len );
361
364
362
365
kfree (domain );
363
366
} else if (ses -> serverName ) {
364
367
len = strlen (ses -> serverName );
365
368
366
369
server = kmalloc (2 + (len * 2 ), GFP_KERNEL );
367
- if (server == NULL )
370
+ if (server == NULL ) {
371
+ cERROR (1 , "calc_ntlmv2_hash: server mem alloc failure" );
372
+ rc = - ENOMEM ;
368
373
goto calc_exit_1 ;
374
+ }
369
375
len = cifs_strtoUCS ((__le16 * )server , ses -> serverName , len ,
370
376
nls_cp );
371
377
/* the following line was removed since it didn't work well
372
378
with lower cased domain name that passed as an option.
373
379
Maybe converting the domain name earlier makes sense */
374
380
/* UniStrupr(domain); */
375
381
376
- crypto_shash_update (& sdesc .shash , (char * )server , 2 * len );
382
+ crypto_shash_update (& ses -> server -> ntlmssp .sdeschmacmd5 -> shash ,
383
+ (char * )server , 2 * len );
377
384
378
385
kfree (server );
379
386
}
387
+
388
+ rc = crypto_shash_final (& ses -> server -> ntlmssp .sdeschmacmd5 -> shash ,
389
+ ses -> server -> ntlmv2_hash );
390
+
380
391
calc_exit_1 :
381
392
kfree (user );
382
393
calc_exit_2 :
383
394
/* BB FIXME what about bytes 24 through 40 of the signing key?
384
395
compare with the NTLM example */
385
- rc = crypto_shash_final (& sdesc .shash , ses -> server -> ntlmv2_hash );
386
396
387
397
return rc ;
388
398
}
@@ -442,34 +452,33 @@ CalcNTLMv2_response(const struct TCP_Server_Info *server,
442
452
char * v2_session_response )
443
453
{
444
454
int rc ;
445
- struct {
446
- struct shash_desc shash ;
447
- char ctx [crypto_shash_descsize (server -> ntlmssp .hmacmd5 )];
448
- } sdesc ;
449
455
450
- sdesc .shash .tfm = server -> ntlmssp .hmacmd5 ;
451
- sdesc .shash .flags = 0x0 ;
456
+ if (!server -> ntlmssp .sdeschmacmd5 ) {
457
+ cERROR (1 , "calc_ntlmv2_hash: can't generate ntlmv2 hash\n" );
458
+ return -1 ;
459
+ }
452
460
453
461
crypto_shash_setkey (server -> ntlmssp .hmacmd5 , server -> ntlmv2_hash ,
454
462
CIFS_HMAC_MD5_HASH_SIZE );
455
463
456
- rc = crypto_shash_init (& sdesc . shash );
464
+ rc = crypto_shash_init (& server -> ntlmssp . sdeschmacmd5 -> shash );
457
465
if (rc ) {
458
- cERROR (1 , "could not initialize master crypto API hmacmd5\n " );
466
+ cERROR (1 , "CalcNTLMv2_response: could not init hmacmd5" );
459
467
return rc ;
460
468
}
461
469
462
470
memcpy (v2_session_response + CIFS_SERVER_CHALLENGE_SIZE ,
463
471
server -> cryptKey , CIFS_SERVER_CHALLENGE_SIZE );
464
- crypto_shash_update (& sdesc . shash ,
472
+ crypto_shash_update (& server -> ntlmssp . sdeschmacmd5 -> shash ,
465
473
v2_session_response + CIFS_SERVER_CHALLENGE_SIZE ,
466
474
sizeof (struct ntlmv2_resp ) - CIFS_SERVER_CHALLENGE_SIZE );
467
475
468
476
if (server -> tilen )
469
- crypto_shash_update (& sdesc . shash ,
477
+ crypto_shash_update (& server -> ntlmssp . sdeschmacmd5 -> shash ,
470
478
server -> tiblob , server -> tilen );
471
479
472
- rc = crypto_shash_final (& sdesc .shash , v2_session_response );
480
+ rc = crypto_shash_final (& server -> ntlmssp .sdeschmacmd5 -> shash ,
481
+ v2_session_response );
473
482
474
483
return rc ;
475
484
}
@@ -480,10 +489,6 @@ setup_ntlmv2_rsp(struct cifsSesInfo *ses, char *resp_buf,
480
489
{
481
490
int rc = 0 ;
482
491
struct ntlmv2_resp * buf = (struct ntlmv2_resp * )resp_buf ;
483
- struct {
484
- struct shash_desc shash ;
485
- char ctx [crypto_shash_descsize (ses -> server -> ntlmssp .hmacmd5 )];
486
- } sdesc ;
487
492
488
493
buf -> blob_signature = cpu_to_le32 (0x00000101 );
489
494
buf -> reserved = 0 ;
@@ -511,21 +516,24 @@ setup_ntlmv2_rsp(struct cifsSesInfo *ses, char *resp_buf,
511
516
return rc ;
512
517
}
513
518
519
+ if (!ses -> server -> ntlmssp .sdeschmacmd5 ) {
520
+ cERROR (1 , "calc_ntlmv2_hash: can't generate ntlmv2 hash\n" );
521
+ return -1 ;
522
+ }
523
+
514
524
crypto_shash_setkey (ses -> server -> ntlmssp .hmacmd5 ,
515
525
ses -> server -> ntlmv2_hash , CIFS_HMAC_MD5_HASH_SIZE );
516
526
517
- sdesc .shash .tfm = ses -> server -> ntlmssp .hmacmd5 ;
518
- sdesc .shash .flags = 0x0 ;
519
-
520
- rc = crypto_shash_init (& sdesc .shash );
527
+ rc = crypto_shash_init (& ses -> server -> ntlmssp .sdeschmacmd5 -> shash );
521
528
if (rc ) {
522
- cERROR (1 , "could not initialize master crypto API hmacmd5\n" );
529
+ cERROR (1 , "setup_ntlmv2_rsp: could not init hmacmd5\n" );
523
530
return rc ;
524
531
}
525
532
526
- crypto_shash_update (& sdesc .shash , resp_buf , CIFS_HMAC_MD5_HASH_SIZE );
533
+ crypto_shash_update (& ses -> server -> ntlmssp .sdeschmacmd5 -> shash ,
534
+ resp_buf , CIFS_HMAC_MD5_HASH_SIZE );
527
535
528
- rc = crypto_shash_final (& sdesc . shash ,
536
+ rc = crypto_shash_final (& ses -> server -> ntlmssp . sdeschmacmd5 -> shash ,
529
537
ses -> server -> session_key .data .ntlmv2 .key );
530
538
531
539
memcpy (& ses -> server -> session_key .data .ntlmv2 .resp , resp_buf ,
@@ -578,24 +586,65 @@ cifs_crypto_shash_release(struct TCP_Server_Info *server)
578
586
579
587
if (server -> ntlmssp .hmacmd5 )
580
588
crypto_free_shash (server -> ntlmssp .hmacmd5 );
589
+
590
+ kfree (server -> ntlmssp .sdeschmacmd5 );
591
+
592
+ kfree (server -> ntlmssp .sdescmd5 );
581
593
}
582
594
583
595
int
584
596
cifs_crypto_shash_allocate (struct TCP_Server_Info * server )
585
597
{
598
+ int rc ;
599
+ unsigned int size ;
600
+
586
601
server -> ntlmssp .hmacmd5 = crypto_alloc_shash ("hmac(md5)" , 0 , 0 );
587
602
if (!server -> ntlmssp .hmacmd5 ||
588
603
IS_ERR (server -> ntlmssp .hmacmd5 )) {
589
- cERROR (1 , "could not allocate master crypto API hmacmd5\n" );
604
+ cERROR (1 , "could not allocate crypto hmacmd5\n" );
590
605
return 1 ;
591
606
}
592
607
593
608
server -> ntlmssp .md5 = crypto_alloc_shash ("md5" , 0 , 0 );
594
609
if (!server -> ntlmssp .md5 || IS_ERR (server -> ntlmssp .md5 )) {
595
- crypto_free_shash ( server -> ntlmssp . hmacmd5 );
596
- cERROR ( 1 , "could not allocate master crypto API md5\n" ) ;
597
- return 1 ;
610
+ cERROR ( 1 , "could not allocate crypto md5\n" );
611
+ rc = 1 ;
612
+ goto cifs_crypto_shash_allocate_ret1 ;
598
613
}
599
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
+
600
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 ;
601
650
}
0 commit comments