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 B21D715C82 for ; Mon, 5 Dec 2022 19:13:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 339D3C433B5; Mon, 5 Dec 2022 19:13:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1670267590; bh=HR9ThG2rHLHc6JV1l1KcLUxKX9fVsctANgy8HrOzd6U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZGQp+ElptQBU143pB9yWlQtvxqqBXA7PbQ/FxTIeTPra5AICxlamrru2ldxA8wcZB h+6q6fJtwNSbWipnhfU8tCWihuejaJ51Ii+qRKhXPpUDYtFNMO2fhYVQNv9d8+De+t /6wwTb3pyxHcuDX+PzIbuO3fv63QzKxErxk3WcMI= 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.9 41/62] net/9p: Fix a potential socket leak in p9_socket_open Date: Mon, 5 Dec 2022 20:09:38 +0100 Message-Id: <20221205190759.645291647@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221205190758.073114639@linuxfoundation.org> References: <20221205190758.073114639@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 e70e843ee48f..7e484f5b140c 100644 --- a/net/9p/trans_fd.c +++ b/net/9p/trans_fd.c @@ -851,8 +851,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