@@ -416,7 +416,7 @@ find_timestamp(struct cifs_ses *ses)
416
416
}
417
417
418
418
static int calc_ntlmv2_hash (struct cifs_ses * ses , char * ntlmv2_hash ,
419
- const struct nls_table * nls_cp )
419
+ const struct nls_table * nls_cp , struct shash_desc * hmacmd5 )
420
420
{
421
421
int rc = 0 ;
422
422
int len ;
@@ -425,34 +425,26 @@ static int calc_ntlmv2_hash(struct cifs_ses *ses, char *ntlmv2_hash,
425
425
wchar_t * domain ;
426
426
wchar_t * server ;
427
427
428
- if (!ses -> server -> secmech .hmacmd5 ) {
429
- cifs_dbg (VFS , "%s: can't generate ntlmv2 hash\n" , __func__ );
430
- return -1 ;
431
- }
432
-
433
428
/* calculate md4 hash of password */
434
429
E_md4hash (ses -> password , nt_hash , nls_cp );
435
430
436
- rc = crypto_shash_setkey (ses -> server -> secmech .hmacmd5 -> tfm , nt_hash ,
437
- CIFS_NTHASH_SIZE );
431
+ rc = crypto_shash_setkey (hmacmd5 -> tfm , nt_hash , CIFS_NTHASH_SIZE );
438
432
if (rc ) {
439
- cifs_dbg (VFS , "%s: Could not set NT Hash as a key\n" , __func__ );
433
+ cifs_dbg (VFS , "%s: Could not set NT hash as a key, rc=%d \n" , __func__ , rc );
440
434
return rc ;
441
435
}
442
436
443
- rc = crypto_shash_init (ses -> server -> secmech . hmacmd5 );
437
+ rc = crypto_shash_init (hmacmd5 );
444
438
if (rc ) {
445
- cifs_dbg (VFS , "%s: Could not init hmacmd5 \n" , __func__ );
439
+ cifs_dbg (VFS , "%s: Could not init HMAC-MD5, rc=%d \n" , __func__ , rc );
446
440
return rc ;
447
441
}
448
442
449
443
/* convert ses->user_name to unicode */
450
444
len = ses -> user_name ? strlen (ses -> user_name ) : 0 ;
451
445
user = kmalloc (2 + (len * 2 ), GFP_KERNEL );
452
- if (user == NULL ) {
453
- rc = - ENOMEM ;
454
- return rc ;
455
- }
446
+ if (user == NULL )
447
+ return - ENOMEM ;
456
448
457
449
if (len ) {
458
450
len = cifs_strtoUTF16 (user , ses -> user_name , len , nls_cp );
@@ -461,11 +453,10 @@ static int calc_ntlmv2_hash(struct cifs_ses *ses, char *ntlmv2_hash,
461
453
* (u16 * )user = 0 ;
462
454
}
463
455
464
- rc = crypto_shash_update (ses -> server -> secmech .hmacmd5 ,
465
- (char * )user , 2 * len );
456
+ rc = crypto_shash_update (hmacmd5 , (char * )user , 2 * len );
466
457
kfree (user );
467
458
if (rc ) {
468
- cifs_dbg (VFS , "%s: Could not update with user\n" , __func__ );
459
+ cifs_dbg (VFS , "%s: Could not update with user, rc=%d \n" , __func__ , rc );
469
460
return rc ;
470
461
}
471
462
@@ -474,53 +465,43 @@ static int calc_ntlmv2_hash(struct cifs_ses *ses, char *ntlmv2_hash,
474
465
len = strlen (ses -> domainName );
475
466
476
467
domain = kmalloc (2 + (len * 2 ), GFP_KERNEL );
477
- if (domain == NULL ) {
478
- rc = - ENOMEM ;
479
- return rc ;
480
- }
468
+ if (domain == NULL )
469
+ return - ENOMEM ;
470
+
481
471
len = cifs_strtoUTF16 ((__le16 * )domain , ses -> domainName , len ,
482
472
nls_cp );
483
- rc =
484
- crypto_shash_update (ses -> server -> secmech .hmacmd5 ,
485
- (char * )domain , 2 * len );
473
+ rc = crypto_shash_update (hmacmd5 , (char * )domain , 2 * len );
486
474
kfree (domain );
487
475
if (rc ) {
488
- cifs_dbg (VFS , "%s: Could not update with domain\n" ,
489
- __func__ );
476
+ cifs_dbg (VFS , "%s: Could not update with domain, rc=%d\n" , __func__ , rc );
490
477
return rc ;
491
478
}
492
479
} else {
493
480
/* We use ses->ip_addr if no domain name available */
494
481
len = strlen (ses -> ip_addr );
495
482
496
483
server = kmalloc (2 + (len * 2 ), GFP_KERNEL );
497
- if (server == NULL ) {
498
- rc = - ENOMEM ;
499
- return rc ;
500
- }
501
- len = cifs_strtoUTF16 ((__le16 * )server , ses -> ip_addr , len ,
502
- nls_cp );
503
- rc =
504
- crypto_shash_update (ses -> server -> secmech .hmacmd5 ,
505
- (char * )server , 2 * len );
484
+ if (server == NULL )
485
+ return - ENOMEM ;
486
+
487
+ len = cifs_strtoUTF16 ((__le16 * )server , ses -> ip_addr , len , nls_cp );
488
+ rc = crypto_shash_update (hmacmd5 , (char * )server , 2 * len );
506
489
kfree (server );
507
490
if (rc ) {
508
- cifs_dbg (VFS , "%s: Could not update with server\n" ,
509
- __func__ );
491
+ cifs_dbg (VFS , "%s: Could not update with server, rc=%d\n" , __func__ , rc );
510
492
return rc ;
511
493
}
512
494
}
513
495
514
- rc = crypto_shash_final (ses -> server -> secmech .hmacmd5 ,
515
- ntlmv2_hash );
496
+ rc = crypto_shash_final (hmacmd5 , ntlmv2_hash );
516
497
if (rc )
517
- cifs_dbg (VFS , "%s: Could not generate md5 hash\n" , __func__ );
498
+ cifs_dbg (VFS , "%s: Could not generate MD5 hash, rc=%d \n" , __func__ , rc );
518
499
519
500
return rc ;
520
501
}
521
502
522
503
static int
523
- CalcNTLMv2_response (const struct cifs_ses * ses , char * ntlmv2_hash )
504
+ CalcNTLMv2_response (const struct cifs_ses * ses , char * ntlmv2_hash , struct shash_desc * hmacmd5 )
524
505
{
525
506
int rc ;
526
507
struct ntlmv2_resp * ntlmv2 = (struct ntlmv2_resp * )
@@ -531,50 +512,41 @@ CalcNTLMv2_response(const struct cifs_ses *ses, char *ntlmv2_hash)
531
512
hash_len = ses -> auth_key .len - (CIFS_SESS_KEY_SIZE +
532
513
offsetof(struct ntlmv2_resp , challenge .key [0 ]));
533
514
534
- if (!ses -> server -> secmech .hmacmd5 ) {
535
- cifs_dbg (VFS , "%s: can't generate ntlmv2 hash\n" , __func__ );
536
- return -1 ;
537
- }
538
-
539
- rc = crypto_shash_setkey (ses -> server -> secmech .hmacmd5 -> tfm ,
540
- ntlmv2_hash , CIFS_HMAC_MD5_HASH_SIZE );
515
+ rc = crypto_shash_setkey (hmacmd5 -> tfm , ntlmv2_hash , CIFS_HMAC_MD5_HASH_SIZE );
541
516
if (rc ) {
542
- cifs_dbg (VFS , "%s: Could not set NTLMV2 Hash as a key\n" ,
543
- __func__ );
517
+ cifs_dbg (VFS , "%s: Could not set NTLMv2 hash as a key, rc=%d\n" , __func__ , rc );
544
518
return rc ;
545
519
}
546
520
547
- rc = crypto_shash_init (ses -> server -> secmech . hmacmd5 );
521
+ rc = crypto_shash_init (hmacmd5 );
548
522
if (rc ) {
549
- cifs_dbg (VFS , "%s: Could not init hmacmd5 \n" , __func__ );
523
+ cifs_dbg (VFS , "%s: Could not init HMAC-MD5, rc=%d \n" , __func__ , rc );
550
524
return rc ;
551
525
}
552
526
553
527
if (ses -> server -> negflavor == CIFS_NEGFLAVOR_EXTENDED )
554
- memcpy (ntlmv2 -> challenge .key ,
555
- ses -> ntlmssp -> cryptkey , CIFS_SERVER_CHALLENGE_SIZE );
528
+ memcpy (ntlmv2 -> challenge .key , ses -> ntlmssp -> cryptkey , CIFS_SERVER_CHALLENGE_SIZE );
556
529
else
557
- memcpy (ntlmv2 -> challenge .key ,
558
- ses -> server -> cryptkey , CIFS_SERVER_CHALLENGE_SIZE );
559
- rc = crypto_shash_update (ses -> server -> secmech .hmacmd5 ,
560
- ntlmv2 -> challenge .key , hash_len );
530
+ memcpy (ntlmv2 -> challenge .key , ses -> server -> cryptkey , CIFS_SERVER_CHALLENGE_SIZE );
531
+
532
+ rc = crypto_shash_update (hmacmd5 , ntlmv2 -> challenge .key , hash_len );
561
533
if (rc ) {
562
- cifs_dbg (VFS , "%s: Could not update with response\n" , __func__ );
534
+ cifs_dbg (VFS , "%s: Could not update with response, rc=%d \n" , __func__ , rc );
563
535
return rc ;
564
536
}
565
537
566
538
/* Note that the MD5 digest over writes anon.challenge_key.key */
567
- rc = crypto_shash_final (ses -> server -> secmech .hmacmd5 ,
568
- ntlmv2 -> ntlmv2_hash );
539
+ rc = crypto_shash_final (hmacmd5 , ntlmv2 -> ntlmv2_hash );
569
540
if (rc )
570
- cifs_dbg (VFS , "%s: Could not generate md5 hash\n" , __func__ );
541
+ cifs_dbg (VFS , "%s: Could not generate MD5 hash, rc=%d \n" , __func__ , rc );
571
542
572
543
return rc ;
573
544
}
574
545
575
546
int
576
547
setup_ntlmv2_rsp (struct cifs_ses * ses , const struct nls_table * nls_cp )
577
548
{
549
+ struct shash_desc * hmacmd5 = NULL ;
578
550
int rc ;
579
551
int baselen ;
580
552
unsigned int tilen ;
@@ -640,55 +612,51 @@ setup_ntlmv2_rsp(struct cifs_ses *ses, const struct nls_table *nls_cp)
640
612
641
613
cifs_server_lock (ses -> server );
642
614
643
- rc = cifs_alloc_hash ("hmac(md5)" , & ses -> server -> secmech . hmacmd5 );
615
+ rc = cifs_alloc_hash ("hmac(md5)" , & hmacmd5 );
644
616
if (rc ) {
617
+ cifs_dbg (VFS , "Could not allocate HMAC-MD5, rc=%d\n" , rc );
645
618
goto unlock ;
646
619
}
647
620
648
621
/* calculate ntlmv2_hash */
649
- rc = calc_ntlmv2_hash (ses , ntlmv2_hash , nls_cp );
622
+ rc = calc_ntlmv2_hash (ses , ntlmv2_hash , nls_cp , hmacmd5 );
650
623
if (rc ) {
651
- cifs_dbg (VFS , "Could not get v2 hash rc %d\n" , rc );
624
+ cifs_dbg (VFS , "Could not get NTLMv2 hash, rc= %d\n" , rc );
652
625
goto unlock ;
653
626
}
654
627
655
628
/* calculate first part of the client response (CR1) */
656
- rc = CalcNTLMv2_response (ses , ntlmv2_hash );
629
+ rc = CalcNTLMv2_response (ses , ntlmv2_hash , hmacmd5 );
657
630
if (rc ) {
658
- cifs_dbg (VFS , "Could not calculate CR1 rc: %d\n" , rc );
631
+ cifs_dbg (VFS , "Could not calculate CR1, rc= %d\n" , rc );
659
632
goto unlock ;
660
633
}
661
634
662
635
/* now calculate the session key for NTLMv2 */
663
- rc = crypto_shash_setkey (ses -> server -> secmech .hmacmd5 -> tfm ,
664
- ntlmv2_hash , CIFS_HMAC_MD5_HASH_SIZE );
636
+ rc = crypto_shash_setkey (hmacmd5 -> tfm , ntlmv2_hash , CIFS_HMAC_MD5_HASH_SIZE );
665
637
if (rc ) {
666
- cifs_dbg (VFS , "%s: Could not set NTLMV2 Hash as a key\n" ,
667
- __func__ );
638
+ cifs_dbg (VFS , "%s: Could not set NTLMv2 hash as a key, rc=%d\n" , __func__ , rc );
668
639
goto unlock ;
669
640
}
670
641
671
- rc = crypto_shash_init (ses -> server -> secmech . hmacmd5 );
642
+ rc = crypto_shash_init (hmacmd5 );
672
643
if (rc ) {
673
- cifs_dbg (VFS , "%s: Could not init hmacmd5 \n" , __func__ );
644
+ cifs_dbg (VFS , "%s: Could not init HMAC-MD5, rc=%d \n" , __func__ , rc );
674
645
goto unlock ;
675
646
}
676
647
677
- rc = crypto_shash_update (ses -> server -> secmech .hmacmd5 ,
678
- ntlmv2 -> ntlmv2_hash ,
679
- CIFS_HMAC_MD5_HASH_SIZE );
648
+ rc = crypto_shash_update (hmacmd5 , ntlmv2 -> ntlmv2_hash , CIFS_HMAC_MD5_HASH_SIZE );
680
649
if (rc ) {
681
- cifs_dbg (VFS , "%s: Could not update with response\n" , __func__ );
650
+ cifs_dbg (VFS , "%s: Could not update with response, rc=%d \n" , __func__ , rc );
682
651
goto unlock ;
683
652
}
684
653
685
- rc = crypto_shash_final (ses -> server -> secmech .hmacmd5 ,
686
- ses -> auth_key .response );
654
+ rc = crypto_shash_final (hmacmd5 , ses -> auth_key .response );
687
655
if (rc )
688
- cifs_dbg (VFS , "%s: Could not generate md5 hash\n" , __func__ );
689
-
656
+ cifs_dbg (VFS , "%s: Could not generate MD5 hash, rc=%d\n" , __func__ , rc );
690
657
unlock :
691
658
cifs_server_unlock (ses -> server );
659
+ cifs_free_hash (& hmacmd5 );
692
660
setup_ntlmv2_rsp_ret :
693
661
kfree_sensitive (tiblob );
694
662
@@ -733,7 +701,6 @@ cifs_crypto_secmech_release(struct TCP_Server_Info *server)
733
701
cifs_free_hash (& server -> secmech .hmacsha256 );
734
702
cifs_free_hash (& server -> secmech .md5 );
735
703
cifs_free_hash (& server -> secmech .sha512 );
736
- cifs_free_hash (& server -> secmech .hmacmd5 );
737
704
738
705
if (!SERVER_IS_CHAN (server )) {
739
706
if (server -> secmech .enc ) {
0 commit comments