Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp173930imd; Wed, 31 Oct 2018 16:48:41 -0700 (PDT) X-Google-Smtp-Source: AJdET5e09aaO80IAZE/qd0Pc7EaJ06roLRBXdz9RX1jNDJ1qqNiCW73vPc4dGPtDnb1ozNCUxTaa X-Received: by 2002:a63:b30f:: with SMTP id i15mr5079739pgf.240.1541029721806; Wed, 31 Oct 2018 16:48:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541029721; cv=none; d=google.com; s=arc-20160816; b=likq7a5wTjma8/7Lgf0F1JuNdNqeSzP0g050LPZziigpfRv/ZVHwHurgX1sVORzVov DMkfAjeOJjtxj1P/0JJZz3mrZO+pjGlMS91FhqrhLGirg1rNddgT+6mWTWZcO+TlsqhJ C1PlTyh7y0pallxOQhIU9IJUlXZBsKAL56WTrB+MVndPzBRzkehIjHi9S8mbY4xK+Eex uoODVUxrbu3zl/mdlVOUdkG9VbUUCuiKIxOc9DlDmlK17kQ1HGW26mq3t3XrbOv61F7F uwglmZ6526VUNTKPEDT+y44WRl/pN2cQ6ff1PetezEMgZy7JkK4xUD3KlLvjeM+NQSyR J/dQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=F0s29k1w9i0IJEYWTUITHIBQT/p3TDmAYdpHsU0G8U4=; b=B7Bh2dWVJRW3lRD5vRyHk3H3U6NZJwF0o6vDD5CFgzDIbUloCkI1i5UkL9vOY1vchr Xc7gZjDeiIAJVNw/z7KJMGm3LaliLjrjxkl4k9DJSYGiLyuWePS9pwPSLN5bfT3d/GBw ffNJdaQeu9sj15WSa1S/WpoebqTEKP0uxlaEzLjMmM/GshDp5ttnAkvSxyWEEfRsci3S 4WedhskrUgxUbtKxDGB+RD4OqrU0YMSnFyJntSSiTzacxWU/VWxYtWgd4lHc+xZ+p4k8 z8O7roxmJExydaOyfHbnO//xdrG3zxk6Mw3zhl2amDxOjbely6+osIH1RDS5/4NcPdIM vNbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Udd6uvwj; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s144-v6si18202496pfc.149.2018.10.31.16.48.27; Wed, 31 Oct 2018 16:48:41 -0700 (PDT) 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=Udd6uvwj; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728661AbeKAIHL (ORCPT + 99 others); Thu, 1 Nov 2018 04:07:11 -0400 Received: from mail.kernel.org ([198.145.29.99]:54688 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728646AbeKAIHK (ORCPT ); Thu, 1 Nov 2018 04:07:10 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 4121620664; Wed, 31 Oct 2018 23:06:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541027219; bh=wr2K4d3ejnl+MunT9gDCKKo+1pwJpXM5250ZUzNYomA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Udd6uvwj412rFGLTdDMBeTcP3nzuu0jX5w8fAldmbpNKtfO5g0rOHrTjXip+Fll++ UnP12UGRBgfGe8VAXi6FSLVOqJVtkxF/lQDp84Ov9Pov2Irmrxpr4luwCLObKlXXxS QPnXCzsGGJdQQn8VileX45BEpQljw5YITbghMaC8= From: Sasha Levin To: stable@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Ronnie Sahlberg , Steve French , Sasha Levin Subject: [PATCH AUTOSEL 4.19 085/146] cifs: fix a credits leak for compund commands Date: Wed, 31 Oct 2018 19:04:40 -0400 Message-Id: <20181031230541.28822-85-sashal@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181031230541.28822-1-sashal@kernel.org> References: <20181031230541.28822-1-sashal@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- fs/cifs/transport.c | 57 +++++++++++++++++++++++++++++---------------- 1 file changed, 37 insertions(+), 20 deletions(-) diff --git a/fs/cifs/transport.c b/fs/cifs/transport.c index b48f43963da6..333729cf46cd 100644 --- a/fs/cifs/transport.c +++ b/fs/cifs/transport.c @@ -786,7 +786,7 @@ compound_send_recv(const unsigned int xid, struct cifs_ses *ses, 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 xid, struct cifs_ses *ses, 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 xid, struct cifs_ses *ses, } 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 xid, struct cifs_ses *ses, 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 -- 2.17.1