Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3485109imu; Sun, 11 Nov 2018 16:09:54 -0800 (PST) X-Google-Smtp-Source: AJdET5erBGLgdVjCNq93Aeyh7zJcnI40h9A3V8PtSU9vFaxmnGm6i56XSDUkZgjVk//dirXgcy1l X-Received: by 2002:a17:902:c5:: with SMTP id a63-v6mr17906681pla.201.1541981394374; Sun, 11 Nov 2018 16:09:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541981394; cv=none; d=google.com; s=arc-20160816; b=t+X4wsXQKCIbappwTTSu4t0slsH4flNpD0OLGcqjDs/ytF9QtOwd210NkL9OsjNmxH ns7tdNcgm97ErDSJeeiyLAH/mF5ro9wBjjQaXzhivrxzuQ1ERyqVPPSF8JYMUQJpRlnm Kp5dSV/1O7MLD9mofh0wj3cPLgt6ED7YMZNLuyaMM2tVLoq1KUR6rlfkwv4mbOSzpeg5 FSrCIHEU2Sm/lcOt7CqrAVR35gFZFdd0bRp3ENj88FkVhjsXkOJQLkiZkMDCmHcIYa07 2XPhRWR6tkKneNK5K3zFWmQqRVontDrQom9ldsBQEK+TRQv9VBxA31hayplLtis8+Kmv yxbg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=s8mKXz+3Kp50WwcyoZYJIatd8pC70g1ns3vjI6kFJO4=; b=LbwfQ1BreM9p+vRErTGfP1PetRzTo0LO0uo0B1AAaAPDJFDBeJXqZcegTyTJnLb57w lsu8Vg2oPW96Wh6ctksclB5q8deTIyl1Lj2QawIPZi/ixe/gin9xbosmPXj80IO278Lv eXiX239WQfunGFjXtlz34f9myTJMl8UtalDt7l5s/HdPEn9TVgrya/thm/zioDjCr4pr 2jEl41ykFx9T67nLv4f8/ZAdLECQyfKnu7bHuc6aLVLzpb5HVPW7boLYGesboAa36gCb 0A8UaF/F+xl7WMBcaMrxt4+jkG0ZNKNKuWanbk0dufWDiVMAoitXN7uMS3IaU/UUzwd9 UKPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ZGMpuj7j; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w13-v6si13552207pgj.229.2018.11.11.16.09.39; Sun, 11 Nov 2018 16:09:54 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ZGMpuj7j; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731490AbeKLIRc (ORCPT + 99 others); Mon, 12 Nov 2018 03:17:32 -0500 Received: from mail.kernel.org ([198.145.29.99]:60278 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731159AbeKLIRc (ORCPT ); Mon, 12 Nov 2018 03:17:32 -0500 Received: from localhost (unknown [206.108.79.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A0E4C21707; Sun, 11 Nov 2018 22:27:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541975256; bh=Zzgy0UV74fkKKeeHYCw6tGKVg9Emy2iOw58hTB/Xgw8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZGMpuj7jukVJoQxhUgGLE/88ce3WJAM6U8VWUXJoDV04lsM+xtwXj+191rPcWD1aC 7B9gSnZ3hVnZaCyW7tqdDl+Ras8C7uU22mYjcvA0i8o9AB5kHku9ZGX6kAiEsCNy2U o50H6uQMjFSI3NUm3/7KkzlIsVkn5seCBmGMba+c= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ronnie Sahlberg , Steve French , Sasha Levin Subject: [PATCH 4.19 130/361] cifs: fix a credits leak for compund commands Date: Sun, 11 Nov 2018 14:17:57 -0800 Message-Id: <20181111221638.508291509@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181111221619.915519183@linuxfoundation.org> References: <20181111221619.915519183@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Ronnie Sahlberg [ Upstream commit cb5c2e63948451d38c977685fffc06e23beb4517 ] When processing the mids for compounds we would only add credits based on the last successful mid in the compound which would leak credits and eventually triggering a re-connect. Fix this by splitting the mid processing part into two loops instead of one where the first loop just waits for all mids and then counts how many credits we were granted for the whole compound. Signed-off-by: Ronnie Sahlberg Signed-off-by: Steve French Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- fs/cifs/transport.c | 57 +++++++++++++++++++++++++++++++++------------------- 1 file changed, 37 insertions(+), 20 deletions(-) --- a/fs/cifs/transport.c +++ b/fs/cifs/transport.c @@ -786,7 +786,7 @@ compound_send_recv(const unsigned int xi int i, j, rc = 0; int timeout, optype; struct mid_q_entry *midQ[MAX_COMPOUND]; - unsigned int credits = 1; + unsigned int credits = 0; char *buf; timeout = flags & CIFS_TIMEOUT_MASK; @@ -851,17 +851,20 @@ compound_send_recv(const unsigned int xi mutex_unlock(&ses->server->srv_mutex); - for (i = 0; i < num_rqst; i++) { - if (rc < 0) - goto out; + if (rc < 0) + goto out; - if ((ses->status == CifsNew) || (optype & CIFS_NEG_OP)) - smb311_update_preauth_hash(ses, rqst[i].rq_iov, - rqst[i].rq_nvec); + /* + * Compounding is never used during session establish. + */ + if ((ses->status == CifsNew) || (optype & CIFS_NEG_OP)) + smb311_update_preauth_hash(ses, rqst[0].rq_iov, + rqst[0].rq_nvec); - if (timeout == CIFS_ASYNC_OP) - goto out; + if (timeout == CIFS_ASYNC_OP) + goto out; + for (i = 0; i < num_rqst; i++) { rc = wait_for_response(ses->server, midQ[i]); if (rc != 0) { cifs_dbg(FYI, "Cancelling wait for mid %llu\n", @@ -877,10 +880,21 @@ compound_send_recv(const unsigned int xi } spin_unlock(&GlobalMid_Lock); } + } + + for (i = 0; i < num_rqst; i++) + if (midQ[i]->resp_buf) + credits += ses->server->ops->get_credits(midQ[i]); + if (!credits) + credits = 1; + + for (i = 0; i < num_rqst; i++) { + if (rc < 0) + goto out; rc = cifs_sync_mid_result(midQ[i], ses->server); if (rc != 0) { - add_credits(ses->server, 1, optype); + add_credits(ses->server, credits, optype); return rc; } @@ -901,23 +915,26 @@ compound_send_recv(const unsigned int xi else resp_buf_type[i] = CIFS_SMALL_BUFFER; - if ((ses->status == CifsNew) || (optype & CIFS_NEG_OP)) { - struct kvec iov = { - .iov_base = resp_iov[i].iov_base, - .iov_len = resp_iov[i].iov_len - }; - smb311_update_preauth_hash(ses, &iov, 1); - } - - credits = ses->server->ops->get_credits(midQ[i]); - rc = ses->server->ops->check_receive(midQ[i], ses->server, flags & CIFS_LOG_ERROR); /* mark it so buf will not be freed by cifs_delete_mid */ if ((flags & CIFS_NO_RESP) == 0) midQ[i]->resp_buf = NULL; + + } + + /* + * Compounding is never used during session establish. + */ + if ((ses->status == CifsNew) || (optype & CIFS_NEG_OP)) { + struct kvec iov = { + .iov_base = resp_iov[0].iov_base, + .iov_len = resp_iov[0].iov_len + }; + smb311_update_preauth_hash(ses, &iov, 1); } + out: /* * This will dequeue all mids. After this it is important that the