@@ -4541,7 +4541,7 @@ smb2_get_enc_key(struct TCP_Server_Info *server, __u64 ses_id, int enc, u8 *key)
4541
4541
*/
4542
4542
static int
4543
4543
crypt_message (struct TCP_Server_Info * server , int num_rqst ,
4544
- struct smb_rqst * rqst , int enc )
4544
+ struct smb_rqst * rqst , int enc , struct crypto_aead * tfm )
4545
4545
{
4546
4546
struct smb2_transform_hdr * tr_hdr =
4547
4547
(struct smb2_transform_hdr * )rqst [0 ].rq_iov [0 ].iov_base ;
@@ -4552,8 +4552,6 @@ crypt_message(struct TCP_Server_Info *server, int num_rqst,
4552
4552
u8 key [SMB3_ENC_DEC_KEY_SIZE ];
4553
4553
struct aead_request * req ;
4554
4554
u8 * iv ;
4555
- DECLARE_CRYPTO_WAIT (wait );
4556
- struct crypto_aead * tfm ;
4557
4555
unsigned int crypt_len = le32_to_cpu (tr_hdr -> OriginalMessageSize );
4558
4556
void * creq ;
4559
4557
@@ -4564,15 +4562,6 @@ crypt_message(struct TCP_Server_Info *server, int num_rqst,
4564
4562
return rc ;
4565
4563
}
4566
4564
4567
- rc = smb3_crypto_aead_allocate (server );
4568
- if (rc ) {
4569
- cifs_server_dbg (VFS , "%s: crypto alloc failed\n" , __func__ );
4570
- return rc ;
4571
- }
4572
-
4573
- tfm = enc ? server -> secmech .ccmaesencrypt :
4574
- server -> secmech .ccmaesdecrypt ;
4575
-
4576
4565
if ((server -> cipher_type == SMB2_ENCRYPTION_AES256_CCM ) ||
4577
4566
(server -> cipher_type == SMB2_ENCRYPTION_AES256_GCM ))
4578
4567
rc = crypto_aead_setkey (tfm , key , SMB3_GCM256_CRYPTKEY_SIZE );
@@ -4611,11 +4600,7 @@ crypt_message(struct TCP_Server_Info *server, int num_rqst,
4611
4600
aead_request_set_crypt (req , sg , sg , crypt_len , iv );
4612
4601
aead_request_set_ad (req , assoc_data_len );
4613
4602
4614
- aead_request_set_callback (req , CRYPTO_TFM_REQ_MAY_BACKLOG ,
4615
- crypto_req_done , & wait );
4616
-
4617
- rc = crypto_wait_req (enc ? crypto_aead_encrypt (req )
4618
- : crypto_aead_decrypt (req ), & wait );
4603
+ rc = enc ? crypto_aead_encrypt (req ) : crypto_aead_decrypt (req );
4619
4604
4620
4605
if (!rc && enc )
4621
4606
memcpy (& tr_hdr -> Signature , sign , SMB2_SIGNATURE_SIZE );
@@ -4704,7 +4689,7 @@ smb3_init_transform_rq(struct TCP_Server_Info *server, int num_rqst,
4704
4689
/* fill the 1st iov with a transform header */
4705
4690
fill_transform_hdr (tr_hdr , orig_len , old_rq , server -> cipher_type );
4706
4691
4707
- rc = crypt_message (server , num_rqst , new_rq , 1 );
4692
+ rc = crypt_message (server , num_rqst , new_rq , 1 , server -> secmech . ccmaesencrypt );
4708
4693
cifs_dbg (FYI , "Encrypt message returned %d\n" , rc );
4709
4694
if (rc )
4710
4695
goto err_free ;
@@ -4730,8 +4715,9 @@ decrypt_raw_data(struct TCP_Server_Info *server, char *buf,
4730
4715
unsigned int npages , unsigned int page_data_size ,
4731
4716
bool is_offloaded )
4732
4717
{
4733
- struct kvec iov [ 2 ] ;
4718
+ struct crypto_aead * tfm ;
4734
4719
struct smb_rqst rqst = {NULL };
4720
+ struct kvec iov [2 ];
4735
4721
int rc ;
4736
4722
4737
4723
iov [0 ].iov_base = buf ;
@@ -4746,9 +4732,31 @@ decrypt_raw_data(struct TCP_Server_Info *server, char *buf,
4746
4732
rqst .rq_pagesz = PAGE_SIZE ;
4747
4733
rqst .rq_tailsz = (page_data_size % PAGE_SIZE ) ? : PAGE_SIZE ;
4748
4734
4749
- rc = crypt_message (server , 1 , & rqst , 0 );
4735
+ if (is_offloaded ) {
4736
+ if ((server -> cipher_type == SMB2_ENCRYPTION_AES128_GCM ) ||
4737
+ (server -> cipher_type == SMB2_ENCRYPTION_AES256_GCM ))
4738
+ tfm = crypto_alloc_aead ("gcm(aes)" , 0 , 0 );
4739
+ else
4740
+ tfm = crypto_alloc_aead ("ccm(aes)" , 0 , 0 );
4741
+ if (IS_ERR (tfm )) {
4742
+ rc = PTR_ERR (tfm );
4743
+ cifs_server_dbg (VFS , "%s: Failed alloc decrypt TFM, rc=%d\n" , __func__ , rc );
4744
+
4745
+ return rc ;
4746
+ }
4747
+ } else {
4748
+ if (unlikely (!server -> secmech .ccmaesdecrypt ))
4749
+ return - EIO ;
4750
+
4751
+ tfm = server -> secmech .ccmaesdecrypt ;
4752
+ }
4753
+
4754
+ rc = crypt_message (server , 1 , & rqst , 0 , tfm );
4750
4755
cifs_dbg (FYI , "Decrypt message returned %d\n" , rc );
4751
4756
4757
+ if (is_offloaded )
4758
+ crypto_free_aead (tfm );
4759
+
4752
4760
if (rc )
4753
4761
return rc ;
4754
4762
0 commit comments