]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
CIFS: Fix credit calculations in compound mid callback
authorPavel Shilovsky <pshilov@microsoft.com>
Wed, 23 Jan 2019 00:50:21 +0000 (16:50 -0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 20 Feb 2019 09:29:08 +0000 (10:29 +0100)
[ Upstream commit 3d3003fce8e837acc4e3960fe3cbabebc356dcb5 ]

The current code doesn't do proper accounting for credits
in SMB1 case: it adds one credit per response only if we get
a complete response while it needs to return it unconditionally.
Fix this and also include malformed responses for SMB2+ into
accounting for credits because such responses have Credit
Granted field, thus nothing prevents to get a proper credit
value from them.

Signed-off-by: Pavel Shilovsky <pshilov@microsoft.com>
Reviewed-by: Ronnie Sahlberg <lsahlber@redhat.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/cifs/smb2ops.c
fs/cifs/transport.c

index d7dd7d38fad61f8b0cb84eb1ac9e44f467dd2e7e..aa71e620f3cd82aebf778fdbfcf68137467fa24b 100644 (file)
@@ -154,7 +154,11 @@ smb2_get_credits(struct mid_q_entry *mid)
 {
        struct smb2_sync_hdr *shdr = (struct smb2_sync_hdr *)mid->resp_buf;
 
-       return le16_to_cpu(shdr->CreditRequest);
+       if (mid->mid_state == MID_RESPONSE_RECEIVED
+           || mid->mid_state == MID_RESPONSE_MALFORMED)
+               return le16_to_cpu(shdr->CreditRequest);
+
+       return 0;
 }
 
 static int
index 0dab276eced84a3b899052dbde457751ab9b4793..6f937e826910064f69285e065252de7ac8a74d72 100644 (file)
@@ -784,17 +784,8 @@ static void
 cifs_compound_callback(struct mid_q_entry *mid)
 {
        struct TCP_Server_Info *server = mid->server;
-       unsigned int optype = mid->optype;
-       unsigned int credits_received = 0;
 
-       if (mid->mid_state == MID_RESPONSE_RECEIVED) {
-               if (mid->resp_buf)
-                       credits_received = server->ops->get_credits(mid);
-               else
-                       cifs_dbg(FYI, "Bad state for cancelled MID\n");
-       }
-
-       add_credits(server, credits_received, optype);
+       add_credits(server, server->ops->get_credits(mid), mid->optype);
 }
 
 static void