Skip to content

Commit 914d7e5

Browse files
namjaejeonsmfrench
authored andcommitted
ksmbd: move credit charge deduction under processing request
Moves the credit charge deduction from total_credits under the processing a request. When repeating smb2 lock request and other command request, there will be a problem that ->total_credits does not decrease. Signed-off-by: Namjae Jeon <linkinjeon@kernel.org> Signed-off-by: Steve French <stfrench@microsoft.com>
1 parent 004443b commit 914d7e5

2 files changed

Lines changed: 12 additions & 11 deletions

File tree

fs/ksmbd/smb2misc.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ static int smb2_validate_credit_charge(struct ksmbd_conn *conn,
289289
unsigned int req_len = 0, expect_resp_len = 0, calc_credit_num, max_len;
290290
unsigned short credit_charge = le16_to_cpu(hdr->CreditCharge);
291291
void *__hdr = hdr;
292-
int ret;
292+
int ret = 0;
293293

294294
switch (hdr->Command) {
295295
case SMB2_QUERY_INFO:
@@ -332,10 +332,7 @@ static int smb2_validate_credit_charge(struct ksmbd_conn *conn,
332332
}
333333

334334
spin_lock(&conn->credits_lock);
335-
if (credit_charge <= conn->total_credits) {
336-
conn->total_credits -= credit_charge;
337-
ret = 0;
338-
} else {
335+
if (credit_charge > conn->total_credits) {
339336
ksmbd_debug(SMB, "Insufficient credits granted, given: %u, granted: %u\n",
340337
credit_charge, conn->total_credits);
341338
ret = 1;

fs/ksmbd/smb2pdu.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -299,9 +299,8 @@ int smb2_set_rsp_credits(struct ksmbd_work *work)
299299
struct smb2_hdr *req_hdr = ksmbd_req_buf_next(work);
300300
struct smb2_hdr *hdr = ksmbd_resp_buf_next(work);
301301
struct ksmbd_conn *conn = work->conn;
302-
unsigned short credits_requested;
302+
unsigned short credits_requested, aux_max;
303303
unsigned short credit_charge, credits_granted = 0;
304-
unsigned short aux_max, aux_credits;
305304

306305
if (work->send_no_response)
307306
return 0;
@@ -316,6 +315,13 @@ int smb2_set_rsp_credits(struct ksmbd_work *work)
316315

317316
credit_charge = max_t(unsigned short,
318317
le16_to_cpu(req_hdr->CreditCharge), 1);
318+
if (credit_charge > conn->total_credits) {
319+
ksmbd_debug(SMB, "Insufficient credits granted, given: %u, granted: %u\n",
320+
credit_charge, conn->total_credits);
321+
return -EINVAL;
322+
}
323+
324+
conn->total_credits -= credit_charge;
319325
credits_requested = max_t(unsigned short,
320326
le16_to_cpu(req_hdr->CreditRequest), 1);
321327

@@ -325,13 +331,11 @@ int smb2_set_rsp_credits(struct ksmbd_work *work)
325331
* TODO: Need to adjuct CreditRequest value according to
326332
* current cpu load
327333
*/
328-
aux_credits = credits_requested - 1;
329334
if (hdr->Command == SMB2_NEGOTIATE)
330-
aux_max = 0;
335+
aux_max = 1;
331336
else
332337
aux_max = conn->vals->max_credits - credit_charge;
333-
aux_credits = min_t(unsigned short, aux_credits, aux_max);
334-
credits_granted = credit_charge + aux_credits;
338+
credits_granted = min_t(unsigned short, credits_requested, aux_max);
335339

336340
if (conn->vals->max_credits - conn->total_credits < credits_granted)
337341
credits_granted = conn->vals->max_credits -

0 commit comments

Comments
 (0)