From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8CEBF15C82 for ; Mon, 5 Dec 2022 19:16:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0E847C433C1; Mon, 5 Dec 2022 19:16:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1670267785; bh=TTLKCTjwzvs7rQuRr3TR35ulCgjGduDOd6s2hnL8VPM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zvdZBmsEBCrh6FsKSyz4iM4j2moH4Hka78gRbE8+jYUKyy2ujbNJWHEWADtpNwH5K PhmY+zbovXimOUUPzmo3TI8vJk1LByIaYXGy6ZtI1acYZwZ76PtiW8yqlqhrGn5sYP PRgFL60D7rL802OanVxINALIsCO3iOOVLLWYJ8Dg= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Wang Hai , Al Viro , "David S. Miller" , Sasha Levin Subject: [PATCH 4.14 51/77] net/9p: Fix a potential socket leak in p9_socket_open Date: Mon, 5 Dec 2022 20:09:42 +0100 Message-Id: <20221205190802.678687079@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221205190800.868551051@linuxfoundation.org> References: <20221205190800.868551051@linuxfoundation.org> User-Agent: quilt/0.67 Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Wang Hai [ Upstream commit dcc14cfd7debe11b825cb077e75d91d2575b4cb8 ] Both p9_fd_create_tcp() and p9_fd_create_unix() will call p9_socket_open(). If the creation of p9_trans_fd fails, p9_fd_create_tcp() and p9_fd_create_unix() will return an error directly instead of releasing the cscoket, which will result in a socket leak. This patch adds sock_release() to fix the leak issue. Fixes: 6b18662e239a ("9p connect fixes") Signed-off-by: Wang Hai ACKed-by: Al Viro Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/9p/trans_fd.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c index da7fcf9d14a9..cdf60ffca240 100644 --- a/net/9p/trans_fd.c +++ b/net/9p/trans_fd.c @@ -865,8 +865,10 @@ static int p9_socket_open(struct p9_client *client, struct socket *csocket) struct file *file; p = kzalloc(sizeof(struct p9_trans_fd), GFP_KERNEL); - if (!p) + if (!p) { + sock_release(csocket); return -ENOMEM; + } csocket->sk->sk_allocation = GFP_NOIO; file = sock_alloc_file(csocket, 0, NULL); -- 2.35.1