40
40
#include "smb2status.h"
41
41
#include "smb2glob.h"
42
42
43
- static int
44
- smb2_crypto_shash_allocate (struct TCP_Server_Info * server )
45
- {
46
- return cifs_alloc_hash ("hmac(sha256)" ,
47
- & server -> secmech .hmacsha256 ,
48
- & server -> secmech .sdeschmacsha256 );
49
- }
50
-
51
43
static int
52
44
smb3_crypto_shash_allocate (struct TCP_Server_Info * server )
53
45
{
@@ -219,7 +211,8 @@ smb2_find_smb_tcon(struct TCP_Server_Info *server, __u64 ses_id, __u32 tid)
219
211
}
220
212
221
213
int
222
- smb2_calc_signature (struct smb_rqst * rqst , struct TCP_Server_Info * server )
214
+ smb2_calc_signature (struct smb_rqst * rqst , struct TCP_Server_Info * server ,
215
+ bool allocate_crypto )
223
216
{
224
217
int rc ;
225
218
unsigned char smb2_signature [SMB2_HMACSHA256_SIZE ];
@@ -228,6 +221,8 @@ smb2_calc_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server)
228
221
struct smb2_sync_hdr * shdr = (struct smb2_sync_hdr * )iov [0 ].iov_base ;
229
222
struct cifs_ses * ses ;
230
223
struct shash_desc * shash ;
224
+ struct crypto_shash * hash ;
225
+ struct sdesc * sdesc = NULL ;
231
226
struct smb_rqst drqst ;
232
227
233
228
ses = smb2_find_smb_ses (server , shdr -> SessionId );
@@ -239,24 +234,32 @@ smb2_calc_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server)
239
234
memset (smb2_signature , 0x0 , SMB2_HMACSHA256_SIZE );
240
235
memset (shdr -> Signature , 0x0 , SMB2_SIGNATURE_SIZE );
241
236
242
- rc = smb2_crypto_shash_allocate (server );
243
- if (rc ) {
244
- cifs_server_dbg (VFS , "%s: sha256 alloc failed\n" , __func__ );
245
- return rc ;
237
+ if (allocate_crypto ) {
238
+ rc = cifs_alloc_hash ("hmac(sha256)" , & hash , & sdesc );
239
+ if (rc ) {
240
+ cifs_server_dbg (VFS ,
241
+ "%s: sha256 alloc failed\n" , __func__ );
242
+ return rc ;
243
+ }
244
+ shash = & sdesc -> shash ;
245
+ } else {
246
+ hash = server -> secmech .hmacsha256 ;
247
+ shash = & server -> secmech .sdeschmacsha256 -> shash ;
246
248
}
247
249
248
- rc = crypto_shash_setkey (server -> secmech . hmacsha256 ,
249
- ses -> auth_key . response , SMB2_NTLMV2_SESSKEY_SIZE );
250
+ rc = crypto_shash_setkey (hash , ses -> auth_key . response ,
251
+ SMB2_NTLMV2_SESSKEY_SIZE );
250
252
if (rc ) {
251
- cifs_server_dbg (VFS , "%s: Could not update with response\n" , __func__ );
252
- return rc ;
253
+ cifs_server_dbg (VFS ,
254
+ "%s: Could not update with response\n" ,
255
+ __func__ );
256
+ goto out ;
253
257
}
254
258
255
- shash = & server -> secmech .sdeschmacsha256 -> shash ;
256
259
rc = crypto_shash_init (shash );
257
260
if (rc ) {
258
261
cifs_server_dbg (VFS , "%s: Could not init sha256" , __func__ );
259
- return rc ;
262
+ goto out ;
260
263
}
261
264
262
265
/*
@@ -271,9 +274,10 @@ smb2_calc_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server)
271
274
rc = crypto_shash_update (shash , iov [0 ].iov_base ,
272
275
iov [0 ].iov_len );
273
276
if (rc ) {
274
- cifs_server_dbg (VFS , "%s: Could not update with payload\n" ,
275
- __func__ );
276
- return rc ;
277
+ cifs_server_dbg (VFS ,
278
+ "%s: Could not update with payload\n" ,
279
+ __func__ );
280
+ goto out ;
277
281
}
278
282
drqst .rq_iov ++ ;
279
283
drqst .rq_nvec -- ;
@@ -283,6 +287,9 @@ smb2_calc_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server)
283
287
if (!rc )
284
288
memcpy (shdr -> Signature , sigptr , SMB2_SIGNATURE_SIZE );
285
289
290
+ out :
291
+ if (allocate_crypto )
292
+ cifs_free_hash (& hash , & sdesc );
286
293
return rc ;
287
294
}
288
295
@@ -504,29 +511,42 @@ generate_smb311signingkey(struct cifs_ses *ses)
504
511
}
505
512
506
513
int
507
- smb3_calc_signature (struct smb_rqst * rqst , struct TCP_Server_Info * server )
514
+ smb3_calc_signature (struct smb_rqst * rqst , struct TCP_Server_Info * server ,
515
+ bool allocate_crypto )
508
516
{
509
517
int rc ;
510
518
unsigned char smb3_signature [SMB2_CMACAES_SIZE ];
511
519
unsigned char * sigptr = smb3_signature ;
512
520
struct kvec * iov = rqst -> rq_iov ;
513
521
struct smb2_sync_hdr * shdr = (struct smb2_sync_hdr * )iov [0 ].iov_base ;
514
- struct shash_desc * shash = & server -> secmech .sdesccmacaes -> shash ;
522
+ struct shash_desc * shash ;
523
+ struct crypto_shash * hash ;
524
+ struct sdesc * sdesc = NULL ;
515
525
struct smb_rqst drqst ;
516
526
u8 key [SMB3_SIGN_KEY_SIZE ];
517
527
518
528
rc = smb2_get_sign_key (shdr -> SessionId , server , key );
519
529
if (rc )
520
530
return 0 ;
521
531
532
+ if (allocate_crypto ) {
533
+ rc = cifs_alloc_hash ("cmac(aes)" , & hash , & sdesc );
534
+ if (rc )
535
+ return rc ;
536
+
537
+ shash = & sdesc -> shash ;
538
+ } else {
539
+ hash = server -> secmech .cmacaes ;
540
+ shash = & server -> secmech .sdesccmacaes -> shash ;
541
+ }
542
+
522
543
memset (smb3_signature , 0x0 , SMB2_CMACAES_SIZE );
523
544
memset (shdr -> Signature , 0x0 , SMB2_SIGNATURE_SIZE );
524
545
525
- rc = crypto_shash_setkey (server -> secmech .cmacaes ,
526
- key , SMB2_CMACAES_SIZE );
546
+ rc = crypto_shash_setkey (hash , key , SMB2_CMACAES_SIZE );
527
547
if (rc ) {
528
548
cifs_server_dbg (VFS , "%s: Could not set key for cmac aes\n" , __func__ );
529
- return rc ;
549
+ goto out ;
530
550
}
531
551
532
552
/*
@@ -537,7 +557,7 @@ smb3_calc_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server)
537
557
rc = crypto_shash_init (shash );
538
558
if (rc ) {
539
559
cifs_server_dbg (VFS , "%s: Could not init cmac aes\n" , __func__ );
540
- return rc ;
560
+ goto out ;
541
561
}
542
562
543
563
/*
@@ -554,7 +574,7 @@ smb3_calc_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server)
554
574
if (rc ) {
555
575
cifs_server_dbg (VFS , "%s: Could not update with payload\n" ,
556
576
__func__ );
557
- return rc ;
577
+ goto out ;
558
578
}
559
579
drqst .rq_iov ++ ;
560
580
drqst .rq_nvec -- ;
@@ -564,6 +584,9 @@ smb3_calc_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server)
564
584
if (!rc )
565
585
memcpy (shdr -> Signature , sigptr , SMB2_SIGNATURE_SIZE );
566
586
587
+ out :
588
+ if (allocate_crypto )
589
+ cifs_free_hash (& hash , & sdesc );
567
590
return rc ;
568
591
}
569
592
@@ -593,7 +616,7 @@ smb2_sign_rqst(struct smb_rqst *rqst, struct TCP_Server_Info *server)
593
616
return 0 ;
594
617
}
595
618
596
- rc = server -> ops -> calc_signature (rqst , server );
619
+ rc = server -> ops -> calc_signature (rqst , server , false );
597
620
598
621
return rc ;
599
622
}
@@ -631,9 +654,7 @@ smb2_verify_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server)
631
654
632
655
memset (shdr -> Signature , 0 , SMB2_SIGNATURE_SIZE );
633
656
634
- mutex_lock (& server -> srv_mutex );
635
- rc = server -> ops -> calc_signature (rqst , server );
636
- mutex_unlock (& server -> srv_mutex );
657
+ rc = server -> ops -> calc_signature (rqst , server , true);
637
658
638
659
if (rc )
639
660
return rc ;
0 commit comments