ksmbd: limits exceeding the maximum allowable outstanding requests
authorNamjae Jeon <linkinjeon@kernel.org>
Fri, 31 Dec 2021 00:26:25 +0000 (09:26 +0900)
committerSteve French <stfrench@microsoft.com>
Mon, 10 Jan 2022 18:44:19 +0000 (12:44 -0600)
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>
fs/ksmbd/connection.c
fs/ksmbd/connection.h
fs/ksmbd/smb2misc.c
fs/ksmbd/smb2pdu.c

index 83a94d0bb480faff2ec27aecad7c83642e42b30d..d1d0105be5b1d67e3406c3b6e5c6387fda9dedfa 100644 (file)
@@ -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);
index 42ffb6d9c5d80d386f7d30ad616657c303e3ee52..7e0730a262da705b61db6b94753085c803a1a9db 100644 (file)
@@ -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*/
index fedcb753c7af51fb733acdced352cea01ed3cec4..4a9460153b595eb05af79c1d0792afb16741b7f1 100644 (file)
@@ -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;
 }
 
index 706191f5e475a38e6bcd8e6e4025921dbe0ed40d..867ed982f7297359c6ff4b9bfcb962051f3ed346 100644 (file)
@@ -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);