@@ -8424,13 +8424,13 @@ void smb3_preauth_hash_rsp(struct ksmbd_work *work)
8424
8424
}
8425
8425
}
8426
8426
8427
- static void fill_transform_hdr (struct smb2_transform_hdr * tr_hdr , char * old_buf ,
8428
- __le16 cipher_type )
8427
+ static void fill_transform_hdr (void * tr_buf , char * old_buf , __le16 cipher_type )
8429
8428
{
8430
- struct smb2_hdr * hdr = (struct smb2_hdr * )old_buf ;
8429
+ struct smb2_transform_hdr * tr_hdr = tr_buf + 4 ;
8430
+ struct smb2_hdr * hdr = smb2_get_msg (old_buf );
8431
8431
unsigned int orig_len = get_rfc1002_len (old_buf );
8432
8432
8433
- memset (tr_hdr , 0 , sizeof (struct smb2_transform_hdr ));
8433
+ memset (tr_buf , 0 , sizeof (struct smb2_transform_hdr ) + 4 );
8434
8434
tr_hdr -> ProtocolId = SMB2_TRANSFORM_PROTO_NUM ;
8435
8435
tr_hdr -> OriginalMessageSize = cpu_to_le32 (orig_len );
8436
8436
tr_hdr -> Flags = cpu_to_le16 (0x01 );
@@ -8440,30 +8440,29 @@ static void fill_transform_hdr(struct smb2_transform_hdr *tr_hdr, char *old_buf,
8440
8440
else
8441
8441
get_random_bytes (& tr_hdr -> Nonce , SMB3_AES_CCM_NONCE );
8442
8442
memcpy (& tr_hdr -> SessionId , & hdr -> SessionId , 8 );
8443
- inc_rfc1001_len (tr_hdr , sizeof (struct smb2_transform_hdr ) - 4 );
8444
- inc_rfc1001_len (tr_hdr , orig_len );
8443
+ inc_rfc1001_len (tr_buf , sizeof (struct smb2_transform_hdr ));
8444
+ inc_rfc1001_len (tr_buf , orig_len );
8445
8445
}
8446
8446
8447
8447
int smb3_encrypt_resp (struct ksmbd_work * work )
8448
8448
{
8449
8449
char * buf = work -> response_buf ;
8450
- struct smb2_transform_hdr * tr_hdr ;
8451
8450
struct kvec iov [3 ];
8452
8451
int rc = - ENOMEM ;
8453
8452
int buf_size = 0 , rq_nvec = 2 + (work -> aux_payload_sz ? 1 : 0 );
8454
8453
8455
8454
if (ARRAY_SIZE (iov ) < rq_nvec )
8456
8455
return - ENOMEM ;
8457
8456
8458
- tr_hdr = kzalloc (sizeof (struct smb2_transform_hdr ), GFP_KERNEL );
8459
- if (!tr_hdr )
8457
+ work -> tr_buf = kzalloc (sizeof (struct smb2_transform_hdr ) + 4 , GFP_KERNEL );
8458
+ if (!work -> tr_buf )
8460
8459
return rc ;
8461
8460
8462
8461
/* fill transform header */
8463
- fill_transform_hdr (tr_hdr , buf , work -> conn -> cipher_type );
8462
+ fill_transform_hdr (work -> tr_buf , buf , work -> conn -> cipher_type );
8464
8463
8465
- iov [0 ].iov_base = tr_hdr ;
8466
- iov [0 ].iov_len = sizeof (struct smb2_transform_hdr );
8464
+ iov [0 ].iov_base = work -> tr_buf ;
8465
+ iov [0 ].iov_len = sizeof (struct smb2_transform_hdr ) + 4 ;
8467
8466
buf_size += iov [0 ].iov_len - 4 ;
8468
8467
8469
8468
iov [1 ].iov_base = buf + 4 ;
@@ -8483,15 +8482,14 @@ int smb3_encrypt_resp(struct ksmbd_work *work)
8483
8482
return rc ;
8484
8483
8485
8484
memmove (buf , iov [1 ].iov_base , iov [1 ].iov_len );
8486
- tr_hdr -> smb2_buf_length = cpu_to_be32 (buf_size );
8487
- work -> tr_buf = tr_hdr ;
8485
+ * (__be32 * )work -> tr_buf = cpu_to_be32 (buf_size );
8488
8486
8489
8487
return rc ;
8490
8488
}
8491
8489
8492
8490
bool smb3_is_transform_hdr (void * buf )
8493
8491
{
8494
- struct smb2_transform_hdr * trhdr = buf ;
8492
+ struct smb2_transform_hdr * trhdr = smb2_get_msg ( buf ) ;
8495
8493
8496
8494
return trhdr -> ProtocolId == SMB2_TRANSFORM_PROTO_NUM ;
8497
8495
}
@@ -8503,9 +8501,8 @@ int smb3_decrypt_req(struct ksmbd_work *work)
8503
8501
char * buf = work -> request_buf ;
8504
8502
unsigned int pdu_length = get_rfc1002_len (buf );
8505
8503
struct kvec iov [2 ];
8506
- int buf_data_size = pdu_length + 4 -
8507
- sizeof (struct smb2_transform_hdr );
8508
- struct smb2_transform_hdr * tr_hdr = (struct smb2_transform_hdr * )buf ;
8504
+ int buf_data_size = pdu_length - sizeof (struct smb2_transform_hdr );
8505
+ struct smb2_transform_hdr * tr_hdr = smb2_get_msg (buf );
8509
8506
int rc = 0 ;
8510
8507
8511
8508
if (buf_data_size < sizeof (struct smb2_hdr )) {
@@ -8527,8 +8524,8 @@ int smb3_decrypt_req(struct ksmbd_work *work)
8527
8524
}
8528
8525
8529
8526
iov [0 ].iov_base = buf ;
8530
- iov [0 ].iov_len = sizeof (struct smb2_transform_hdr );
8531
- iov [1 ].iov_base = buf + sizeof (struct smb2_transform_hdr );
8527
+ iov [0 ].iov_len = sizeof (struct smb2_transform_hdr ) + 4 ;
8528
+ iov [1 ].iov_base = buf + sizeof (struct smb2_transform_hdr ) + 4 ;
8532
8529
iov [1 ].iov_len = buf_data_size ;
8533
8530
rc = ksmbd_crypt_message (conn , iov , 2 , 0 );
8534
8531
if (rc )
0 commit comments