@@ -326,13 +326,9 @@ int smb2_set_rsp_credits(struct ksmbd_work *work)
326
326
if (hdr -> Command == SMB2_NEGOTIATE )
327
327
aux_max = 1 ;
328
328
else
329
- aux_max = conn -> vals -> max_credits - credit_charge ;
329
+ aux_max = conn -> vals -> max_credits - conn -> total_credits ;
330
330
credits_granted = min_t (unsigned short , credits_requested , aux_max );
331
331
332
- if (conn -> vals -> max_credits - conn -> total_credits < credits_granted )
333
- credits_granted = conn -> vals -> max_credits -
334
- conn -> total_credits ;
335
-
336
332
conn -> total_credits += credits_granted ;
337
333
work -> credits_granted += credits_granted ;
338
334
@@ -849,13 +845,14 @@ static void assemble_neg_contexts(struct ksmbd_conn *conn,
849
845
850
846
static __le32 decode_preauth_ctxt (struct ksmbd_conn * conn ,
851
847
struct smb2_preauth_neg_context * pneg_ctxt ,
852
- int len_of_ctxts )
848
+ int ctxt_len )
853
849
{
854
850
/*
855
851
* sizeof(smb2_preauth_neg_context) assumes SMB311_SALT_SIZE Salt,
856
852
* which may not be present. Only check for used HashAlgorithms[1].
857
853
*/
858
- if (len_of_ctxts < MIN_PREAUTH_CTXT_DATA_LEN )
854
+ if (ctxt_len <
855
+ sizeof (struct smb2_neg_context ) + MIN_PREAUTH_CTXT_DATA_LEN )
859
856
return STATUS_INVALID_PARAMETER ;
860
857
861
858
if (pneg_ctxt -> HashAlgorithms != SMB2_PREAUTH_INTEGRITY_SHA512 )
@@ -867,15 +864,23 @@ static __le32 decode_preauth_ctxt(struct ksmbd_conn *conn,
867
864
868
865
static void decode_encrypt_ctxt (struct ksmbd_conn * conn ,
869
866
struct smb2_encryption_neg_context * pneg_ctxt ,
870
- int len_of_ctxts )
867
+ int ctxt_len )
871
868
{
872
- int cph_cnt = le16_to_cpu (pneg_ctxt -> CipherCount );
873
- int i , cphs_size = cph_cnt * sizeof (__le16 );
869
+ int cph_cnt ;
870
+ int i , cphs_size ;
871
+
872
+ if (sizeof (struct smb2_encryption_neg_context ) > ctxt_len ) {
873
+ pr_err ("Invalid SMB2_ENCRYPTION_CAPABILITIES context size\n" );
874
+ return ;
875
+ }
874
876
875
877
conn -> cipher_type = 0 ;
876
878
879
+ cph_cnt = le16_to_cpu (pneg_ctxt -> CipherCount );
880
+ cphs_size = cph_cnt * sizeof (__le16 );
881
+
877
882
if (sizeof (struct smb2_encryption_neg_context ) + cphs_size >
878
- len_of_ctxts ) {
883
+ ctxt_len ) {
879
884
pr_err ("Invalid cipher count(%d)\n" , cph_cnt );
880
885
return ;
881
886
}
@@ -923,15 +928,22 @@ static void decode_compress_ctxt(struct ksmbd_conn *conn,
923
928
924
929
static void decode_sign_cap_ctxt (struct ksmbd_conn * conn ,
925
930
struct smb2_signing_capabilities * pneg_ctxt ,
926
- int len_of_ctxts )
931
+ int ctxt_len )
927
932
{
928
- int sign_algo_cnt = le16_to_cpu (pneg_ctxt -> SigningAlgorithmCount );
929
- int i , sign_alos_size = sign_algo_cnt * sizeof (__le16 );
933
+ int sign_algo_cnt ;
934
+ int i , sign_alos_size ;
935
+
936
+ if (sizeof (struct smb2_signing_capabilities ) > ctxt_len ) {
937
+ pr_err ("Invalid SMB2_SIGNING_CAPABILITIES context length\n" );
938
+ return ;
939
+ }
930
940
931
941
conn -> signing_negotiated = false;
942
+ sign_algo_cnt = le16_to_cpu (pneg_ctxt -> SigningAlgorithmCount );
943
+ sign_alos_size = sign_algo_cnt * sizeof (__le16 );
932
944
933
945
if (sizeof (struct smb2_signing_capabilities ) + sign_alos_size >
934
- len_of_ctxts ) {
946
+ ctxt_len ) {
935
947
pr_err ("Invalid signing algorithm count(%d)\n" , sign_algo_cnt );
936
948
return ;
937
949
}
@@ -969,18 +981,16 @@ static __le32 deassemble_neg_contexts(struct ksmbd_conn *conn,
969
981
len_of_ctxts = len_of_smb - offset ;
970
982
971
983
while (i ++ < neg_ctxt_cnt ) {
972
- int clen ;
973
-
974
- /* check that offset is not beyond end of SMB */
975
- if (len_of_ctxts == 0 )
976
- break ;
984
+ int clen , ctxt_len ;
977
985
978
986
if (len_of_ctxts < sizeof (struct smb2_neg_context ))
979
987
break ;
980
988
981
989
pctx = (struct smb2_neg_context * )((char * )pctx + offset );
982
990
clen = le16_to_cpu (pctx -> DataLength );
983
- if (clen + sizeof (struct smb2_neg_context ) > len_of_ctxts )
991
+ ctxt_len = clen + sizeof (struct smb2_neg_context );
992
+
993
+ if (ctxt_len > len_of_ctxts )
984
994
break ;
985
995
986
996
if (pctx -> ContextType == SMB2_PREAUTH_INTEGRITY_CAPABILITIES ) {
@@ -991,7 +1001,7 @@ static __le32 deassemble_neg_contexts(struct ksmbd_conn *conn,
991
1001
992
1002
status = decode_preauth_ctxt (conn ,
993
1003
(struct smb2_preauth_neg_context * )pctx ,
994
- len_of_ctxts );
1004
+ ctxt_len );
995
1005
if (status != STATUS_SUCCESS )
996
1006
break ;
997
1007
} else if (pctx -> ContextType == SMB2_ENCRYPTION_CAPABILITIES ) {
@@ -1002,7 +1012,7 @@ static __le32 deassemble_neg_contexts(struct ksmbd_conn *conn,
1002
1012
1003
1013
decode_encrypt_ctxt (conn ,
1004
1014
(struct smb2_encryption_neg_context * )pctx ,
1005
- len_of_ctxts );
1015
+ ctxt_len );
1006
1016
} else if (pctx -> ContextType == SMB2_COMPRESSION_CAPABILITIES ) {
1007
1017
ksmbd_debug (SMB ,
1008
1018
"deassemble SMB2_COMPRESSION_CAPABILITIES context\n" );
@@ -1021,9 +1031,10 @@ static __le32 deassemble_neg_contexts(struct ksmbd_conn *conn,
1021
1031
} else if (pctx -> ContextType == SMB2_SIGNING_CAPABILITIES ) {
1022
1032
ksmbd_debug (SMB ,
1023
1033
"deassemble SMB2_SIGNING_CAPABILITIES context\n" );
1034
+
1024
1035
decode_sign_cap_ctxt (conn ,
1025
1036
(struct smb2_signing_capabilities * )pctx ,
1026
- len_of_ctxts );
1037
+ ctxt_len );
1027
1038
}
1028
1039
1029
1040
/* offsets must be 8 byte aligned */
@@ -1057,16 +1068,16 @@ int smb2_handle_negotiate(struct ksmbd_work *work)
1057
1068
return rc ;
1058
1069
}
1059
1070
1060
- if (req -> DialectCount == 0 ) {
1061
- pr_err ("malformed packet\n" );
1071
+ smb2_buf_len = get_rfc1002_len (work -> request_buf );
1072
+ smb2_neg_size = offsetof(struct smb2_negotiate_req , Dialects );
1073
+ if (smb2_neg_size > smb2_buf_len ) {
1062
1074
rsp -> hdr .Status = STATUS_INVALID_PARAMETER ;
1063
1075
rc = - EINVAL ;
1064
1076
goto err_out ;
1065
1077
}
1066
1078
1067
- smb2_buf_len = get_rfc1002_len (work -> request_buf );
1068
- smb2_neg_size = offsetof(struct smb2_negotiate_req , Dialects );
1069
- if (smb2_neg_size > smb2_buf_len ) {
1079
+ if (req -> DialectCount == 0 ) {
1080
+ pr_err ("malformed packet\n" );
1070
1081
rsp -> hdr .Status = STATUS_INVALID_PARAMETER ;
1071
1082
rc = - EINVAL ;
1072
1083
goto err_out ;
@@ -4358,21 +4369,6 @@ static int get_file_basic_info(struct smb2_query_info_rsp *rsp,
4358
4369
return 0 ;
4359
4370
}
4360
4371
4361
- static unsigned long long get_allocation_size (struct inode * inode ,
4362
- struct kstat * stat )
4363
- {
4364
- unsigned long long alloc_size = 0 ;
4365
-
4366
- if (!S_ISDIR (stat -> mode )) {
4367
- if ((inode -> i_blocks << 9 ) <= stat -> size )
4368
- alloc_size = stat -> size ;
4369
- else
4370
- alloc_size = inode -> i_blocks << 9 ;
4371
- }
4372
-
4373
- return alloc_size ;
4374
- }
4375
-
4376
4372
static void get_file_standard_info (struct smb2_query_info_rsp * rsp ,
4377
4373
struct ksmbd_file * fp , void * rsp_org )
4378
4374
{
@@ -4387,7 +4383,7 @@ static void get_file_standard_info(struct smb2_query_info_rsp *rsp,
4387
4383
sinfo = (struct smb2_file_standard_info * )rsp -> Buffer ;
4388
4384
delete_pending = ksmbd_inode_pending_delete (fp );
4389
4385
4390
- sinfo -> AllocationSize = cpu_to_le64 (get_allocation_size ( inode , & stat ) );
4386
+ sinfo -> AllocationSize = cpu_to_le64 (inode -> i_blocks << 9 );
4391
4387
sinfo -> EndOfFile = S_ISDIR (stat .mode ) ? 0 : cpu_to_le64 (stat .size );
4392
4388
sinfo -> NumberOfLinks = cpu_to_le32 (get_nlink (& stat ) - delete_pending );
4393
4389
sinfo -> DeletePending = delete_pending ;
@@ -4452,7 +4448,7 @@ static int get_file_all_info(struct ksmbd_work *work,
4452
4448
file_info -> Attributes = fp -> f_ci -> m_fattr ;
4453
4449
file_info -> Pad1 = 0 ;
4454
4450
file_info -> AllocationSize =
4455
- cpu_to_le64 (get_allocation_size ( inode , & stat ) );
4451
+ cpu_to_le64 (inode -> i_blocks << 9 );
4456
4452
file_info -> EndOfFile = S_ISDIR (stat .mode ) ? 0 : cpu_to_le64 (stat .size );
4457
4453
file_info -> NumberOfLinks =
4458
4454
cpu_to_le32 (get_nlink (& stat ) - delete_pending );
@@ -4641,7 +4637,7 @@ static int get_file_network_open_info(struct smb2_query_info_rsp *rsp,
4641
4637
file_info -> ChangeTime = cpu_to_le64 (time );
4642
4638
file_info -> Attributes = fp -> f_ci -> m_fattr ;
4643
4639
file_info -> AllocationSize =
4644
- cpu_to_le64 (get_allocation_size ( inode , & stat ) );
4640
+ cpu_to_le64 (inode -> i_blocks << 9 );
4645
4641
file_info -> EndOfFile = S_ISDIR (stat .mode ) ? 0 : cpu_to_le64 (stat .size );
4646
4642
file_info -> Reserved = cpu_to_le32 (0 );
4647
4643
rsp -> OutputBufferLength =
@@ -5506,7 +5502,7 @@ static int smb2_create_link(struct ksmbd_work *work,
5506
5502
{
5507
5503
char * link_name = NULL , * target_name = NULL , * pathname = NULL ;
5508
5504
struct path path ;
5509
- bool file_present = true ;
5505
+ bool file_present = false ;
5510
5506
int rc ;
5511
5507
5512
5508
if (buf_len < (u64 )sizeof (struct smb2_file_link_info ) +
@@ -5539,8 +5535,8 @@ static int smb2_create_link(struct ksmbd_work *work,
5539
5535
if (rc ) {
5540
5536
if (rc != - ENOENT )
5541
5537
goto out ;
5542
- file_present = false;
5543
- }
5538
+ } else
5539
+ file_present = true;
5544
5540
5545
5541
if (file_info -> ReplaceIfExists ) {
5546
5542
if (file_present ) {
0 commit comments