Skip to content

Commit b589f5d

Browse files
namjaejeonsmfrench
authored andcommitted
ksmbd: limits exceeding the maximum allowable outstanding requests
If the client ignores the CreditResponse received from the server and continues to send the request, ksmbd limits the requests if it exceeds smb2 max credits. Signed-off-by: Namjae Jeon <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent 914d7e5 commit b589f5d

File tree

4 files changed

+13
-1
lines changed

4 files changed

+13
-1
lines changed

fs/ksmbd/connection.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ struct ksmbd_conn *ksmbd_conn_alloc(void)
6262
atomic_set(&conn->req_running, 0);
6363
atomic_set(&conn->r_count, 0);
6464
conn->total_credits = 1;
65+
conn->outstanding_credits = 1;
6566

6667
init_waitqueue_head(&conn->req_running_q);
6768
INIT_LIST_HEAD(&conn->conns_list);

fs/ksmbd/connection.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ struct ksmbd_conn {
6161
atomic_t req_running;
6262
/* References which are made for this Server object*/
6363
atomic_t r_count;
64-
unsigned short total_credits;
64+
unsigned int total_credits;
65+
unsigned int outstanding_credits;
6566
spinlock_t credits_lock;
6667
wait_queue_head_t req_running_q;
6768
/* Lock to protect requests list*/

fs/ksmbd/smb2misc.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,16 @@ static int smb2_validate_credit_charge(struct ksmbd_conn *conn,
337337
credit_charge, conn->total_credits);
338338
ret = 1;
339339
}
340+
341+
if ((u64)conn->outstanding_credits + credit_charge > conn->vals->max_credits) {
342+
ksmbd_debug(SMB, "Limits exceeding the maximum allowable outstanding requests, given : %u, pending : %u\n",
343+
credit_charge, conn->outstanding_credits);
344+
ret = 1;
345+
} else
346+
conn->outstanding_credits += credit_charge;
347+
340348
spin_unlock(&conn->credits_lock);
349+
341350
return ret;
342351
}
343352

fs/ksmbd/smb2pdu.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ int smb2_set_rsp_credits(struct ksmbd_work *work)
322322
}
323323

324324
conn->total_credits -= credit_charge;
325+
conn->outstanding_credits -= credit_charge;
325326
credits_requested = max_t(unsigned short,
326327
le16_to_cpu(req_hdr->CreditRequest), 1);
327328

0 commit comments

Comments
 (0)