Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp6259016imu; Mon, 21 Jan 2019 06:00:52 -0800 (PST) X-Google-Smtp-Source: ALg8bN6LaikQFqRPVK+6SZ2g2YeOy3u2O1KN1apkhhdccsQMAYnMKZcepqK+gUnparYFQ6i0xWuo X-Received: by 2002:a17:902:28c1:: with SMTP id f59mr30325816plb.37.1548079252037; Mon, 21 Jan 2019 06:00:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548079252; cv=none; d=google.com; s=arc-20160816; b=A8d4mm6zxbCRhmRNhv7VrZodDJIKRAAPzH88tQCmiKhkWT+0iEBgr2GMYoI9D+xvQX XklfnpF5yS/uZ6qEmcojfWlqK0khwICQHcfYhNnX3V3jvy3zIhMKE9KSafHYdbueOUK5 JC/g+qYsa3e4PxRurkeJ3rk8KjD3iTraQt1Ae0/80OxRRyes50TkbwL2uQcxuGxekw9S 46WABHQ8NmqnNxSgNFOdy1s1SP/WUY/bd64ao9EQHwB+5vrtSN1Grq1I9eMUDsTWPmWV i9nQbjIpONfhr/3NOnAzw2rMj7IlXYaCpchtL9gh5p1+a4ncIPc5Lyu2qgbkI4o52Iu2 0+nA== 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=1aGrSf1LvIwSvs/aubmcDkfa6y0U7Rb0HrHTnOHjhTs=; b=mlQma3GvsaD9PKycuaM8VcQ66QQzSq3M7J5zhJhc0BBNygHxuMyeQ6hBp1vHFFSoaN 2nqS+4MxHCz6rD/NzO/kTzbH6haE9YLo59DeTGxNbBKydrJcty9XV3LDkhleQltgakcC DoA+Oq3XuFO6lsUPYs1NTg+t8XAn2LIsS8U0+2zsZmwI8zZeB19DUZz9E7JUxPB/Vs9V RHa80Y+d2fsF+PUx9/l1bKqP/4rmK8d7IqAftT+GsLRhlm0JlfWSsVRovDhnpDV0vgIa Nw66tUWzAiTjlnWLSzcCqtdxlRXMTQlY8uVRYQyvbQVhwnJ8iwRfV0Y5VK5Tip35b6mv X0oA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=dCAIdsvX; 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 ay4si13255090plb.235.2019.01.21.06.00.36; Mon, 21 Jan 2019 06:00:52 -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=dCAIdsvX; 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 S1731846AbfAUN6o (ORCPT + 99 others); Mon, 21 Jan 2019 08:58:44 -0500 Received: from mail.kernel.org ([198.145.29.99]:44304 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732034AbfAUN6l (ORCPT ); Mon, 21 Jan 2019 08:58:41 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (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 1F9392084C; Mon, 21 Jan 2019 13:58:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1548079120; bh=QFFMolJ+NWaG/RDlKxDhyUelDAGwAR0RY0xG9wzTEHE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dCAIdsvXKkszwtKDLM5NtoJnbw976n6sZQRqnS0MvGzVViw+16p20GYbYgRv4sJoi ga1WABpe0ivWy5zhkSs1tpqjNAfuQfqAVPdSHjk7FJea7jP9Za2rzJipQFHVVmOF/6 nkUAtlRVbIXJhhOLUaTsKy8CNbnZC5/6cZMoJDbo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Varun Prakash , "Martin K. Petersen" , Sasha Levin Subject: [PATCH 4.19 16/99] scsi: target: iscsi: cxgbit: fix csk leak Date: Mon, 21 Jan 2019 14:48:08 +0100 Message-Id: <20190121134914.534395149@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190121134913.924726465@linuxfoundation.org> References: <20190121134913.924726465@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore 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. ------------------ [ Upstream commit 801df68d617e3cb831f531c99fa6003620e6b343 ] csk leak can happen if a new TCP connection gets established after cxgbit_accept_np() returns, to fix this leak free remaining csk in cxgbit_free_np(). Signed-off-by: Varun Prakash Signed-off-by: Martin K. Petersen Signed-off-by: Sasha Levin --- drivers/target/iscsi/cxgbit/cxgbit_cm.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/drivers/target/iscsi/cxgbit/cxgbit_cm.c b/drivers/target/iscsi/cxgbit/cxgbit_cm.c index 8de16016b6de..71888b979ab5 100644 --- a/drivers/target/iscsi/cxgbit/cxgbit_cm.c +++ b/drivers/target/iscsi/cxgbit/cxgbit_cm.c @@ -598,9 +598,12 @@ static void cxgbit_free_cdev_np(struct cxgbit_np *cnp) mutex_unlock(&cdev_list_lock); } +static void __cxgbit_free_conn(struct cxgbit_sock *csk); + void cxgbit_free_np(struct iscsi_np *np) { struct cxgbit_np *cnp = np->np_context; + struct cxgbit_sock *csk, *tmp; cnp->com.state = CSK_STATE_DEAD; if (cnp->com.cdev) @@ -608,6 +611,13 @@ void cxgbit_free_np(struct iscsi_np *np) else cxgbit_free_all_np(cnp); + spin_lock_bh(&cnp->np_accept_lock); + list_for_each_entry_safe(csk, tmp, &cnp->np_accept_list, accept_node) { + list_del_init(&csk->accept_node); + __cxgbit_free_conn(csk); + } + spin_unlock_bh(&cnp->np_accept_lock); + np->np_context = NULL; cxgbit_put_cnp(cnp); } @@ -705,9 +715,9 @@ void cxgbit_abort_conn(struct cxgbit_sock *csk) csk->tid, 600, __func__); } -void cxgbit_free_conn(struct iscsi_conn *conn) +static void __cxgbit_free_conn(struct cxgbit_sock *csk) { - struct cxgbit_sock *csk = conn->context; + struct iscsi_conn *conn = csk->conn; bool release = false; pr_debug("%s: state %d\n", @@ -716,7 +726,7 @@ void cxgbit_free_conn(struct iscsi_conn *conn) spin_lock_bh(&csk->lock); switch (csk->com.state) { case CSK_STATE_ESTABLISHED: - if (conn->conn_state == TARG_CONN_STATE_IN_LOGOUT) { + if (conn && (conn->conn_state == TARG_CONN_STATE_IN_LOGOUT)) { csk->com.state = CSK_STATE_CLOSING; cxgbit_send_halfclose(csk); } else { @@ -741,6 +751,11 @@ void cxgbit_free_conn(struct iscsi_conn *conn) cxgbit_put_csk(csk); } +void cxgbit_free_conn(struct iscsi_conn *conn) +{ + __cxgbit_free_conn(conn->context); +} + static void cxgbit_set_emss(struct cxgbit_sock *csk, u16 opt) { csk->emss = csk->com.cdev->lldi.mtus[TCPOPT_MSS_G(opt)] - @@ -803,6 +818,7 @@ void _cxgbit_free_csk(struct kref *kref) spin_unlock_bh(&cdev->cskq.lock); cxgbit_free_skb(csk); + cxgbit_put_cnp(csk->cnp); cxgbit_put_cdev(cdev); kfree(csk); @@ -1351,6 +1367,7 @@ cxgbit_pass_accept_req(struct cxgbit_device *cdev, struct sk_buff *skb) goto rel_skb; } + cxgbit_get_cnp(cnp); cxgbit_get_cdev(cdev); spin_lock(&cdev->cskq.lock); -- 2.19.1