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 0CDD715C83 for ; Mon, 5 Dec 2022 19:25:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 83848C433C1; Mon, 5 Dec 2022 19:25:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1670268306; bh=/yEZWT9cyjBbpupMJ8pXa9Z4pppWixJQy4hL7oceQHQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ffjZWKVCXgh8lioLGFZxBC7MHgeKTD6gMpBSvPrnvtOOUNeVFVJcwFEwvF52W1kaN PIQ6j3vipdQPAqXrUvUYo/NQ3dZPICAn784TptTqu4/clDFSZuNpeEr0gfJhPB9aJT HO/Fuf7wm3OA8H5Dz8VJymHvh+owiVT4zSfj+Yg8= 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 6.0 053/124] net/9p: Fix a potential socket leak in p9_socket_open Date: Mon, 5 Dec 2022 20:09:19 +0100 Message-Id: <20221205190809.938649269@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221205190808.422385173@linuxfoundation.org> References: <20221205190808.422385173@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 8487321c1fc7..3e056fb043bb 100644 --- a/net/9p/trans_fd.c +++ b/net/9p/trans_fd.c @@ -862,8 +862,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