Skip to content

Commit

Permalink
ksmbd: limits exceeding the maximum allowable outstanding requests
Browse files Browse the repository at this point in the history
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 <linkinjeon@kernel.org>
Signed-off-by: Steve French <stfrench@microsoft.com>
  • Loading branch information
Namjae Jeon authored and Steve French committed Jan 10, 2022
1 parent 914d7e5 commit b589f5d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions fs/ksmbd/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ struct ksmbd_conn *ksmbd_conn_alloc(void)
atomic_set(&conn->req_running, 0);
atomic_set(&conn->r_count, 0);
conn->total_credits = 1;
conn->outstanding_credits = 1;

init_waitqueue_head(&conn->req_running_q);
INIT_LIST_HEAD(&conn->conns_list);
Expand Down
3 changes: 2 additions & 1 deletion fs/ksmbd/connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ struct ksmbd_conn {
atomic_t req_running;
/* References which are made for this Server object*/
atomic_t r_count;
unsigned short total_credits;
unsigned int total_credits;
unsigned int outstanding_credits;
spinlock_t credits_lock;
wait_queue_head_t req_running_q;
/* Lock to protect requests list*/
Expand Down
9 changes: 9 additions & 0 deletions fs/ksmbd/smb2misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,16 @@ static int smb2_validate_credit_charge(struct ksmbd_conn *conn,
credit_charge, conn->total_credits);
ret = 1;
}

if ((u64)conn->outstanding_credits + credit_charge > conn->vals->max_credits) {
ksmbd_debug(SMB, "Limits exceeding the maximum allowable outstanding requests, given : %u, pending : %u\n",
credit_charge, conn->outstanding_credits);
ret = 1;
} else
conn->outstanding_credits += credit_charge;

spin_unlock(&conn->credits_lock);

return ret;
}

Expand Down
1 change: 1 addition & 0 deletions fs/ksmbd/smb2pdu.c
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ int smb2_set_rsp_credits(struct ksmbd_work *work)
}

conn->total_credits -= credit_charge;
conn->outstanding_credits -= credit_charge;
credits_requested = max_t(unsigned short,
le16_to_cpu(req_hdr->CreditRequest), 1);

Expand Down

0 comments on commit b589f5d

Please sign in to comment.