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 2F148213E6B; Thu, 12 Dec 2024 15:45:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734018322; cv=none; b=gis3YrifWiDnn5N1LGWSjTQ8jj9H0ZeZi8ut3e0RUqOL53TxxeNq0z1ySLSk/xr+NMNhDwb1C4Ovg0dYnA+Xf2m0LQxteoFa6++6+Gdg+v4x1DC3ZHQZKr565MhlkHQboMDB3tMmY3U7djfXe63djDLK0irTDQrL8gXjuwgcw70= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734018322; c=relaxed/simple; bh=HRwdxwZ5uvDZSejCasHED5k3Bj0RYG+C4Xg6yb2KNeU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uJ4Z2a4d23PdFIfeTeFd3/+yiyF0OKcmctgKlGFyWMlwGW8WfugvrknVnY/D7l6LSvrDtvR3Ss0w9uo+3qSkw4cRdZXaenqOEpH5pcdzZgZjFAjl3x2QqCZWQDAGCcc5NyrSQvAz0uV7+zUekLDFcR3NYCh4Z4xioVYj6grntJo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=j49oioOv; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="j49oioOv" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 95D13C4CECE; Thu, 12 Dec 2024 15:45:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1734018322; bh=HRwdxwZ5uvDZSejCasHED5k3Bj0RYG+C4Xg6yb2KNeU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=j49oioOvidaGR0TuBNHvGQe9B5WpIQOJDFGIvp0YyI3Q419t81UwVf6FJOK/Q9H7o YLk9oVVlXDPZHkTEGwcjeQoEc9I5psI6aB1afqK4tDA9/XkV5YOLwl3EEF/urcDYkB ihvjGeYD5z7SGoB50W7OQXDryx5jBjZBXc2oVBCI= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Ignat Korchagin , Kuniyuki Iwashima , Eric Dumazet , Jakub Kicinski , Sasha Levin Subject: [PATCH 6.6 230/356] net: inet6: do not leave a dangling sk pointer in inet6_create() Date: Thu, 12 Dec 2024 15:59:09 +0100 Message-ID: <20241212144253.707647006@linuxfoundation.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241212144244.601729511@linuxfoundation.org> References: <20241212144244.601729511@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Ignat Korchagin [ Upstream commit 9df99c395d0f55fb444ef39f4d6f194ca437d884 ] sock_init_data() attaches the allocated sk pointer to the provided sock object. If inet6_create() fails later, the sk object is released, but the sock object retains the dangling sk pointer, which may cause use-after-free later. Clear the sock sk pointer on error. Signed-off-by: Ignat Korchagin Reviewed-by: Kuniyuki Iwashima Reviewed-by: Eric Dumazet Link: https://patch.msgid.link/20241014153808.51894-8-ignat@cloudflare.com Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- net/ipv6/af_inet6.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c index 99843eb4d49b9..102ce1748b599 100644 --- a/net/ipv6/af_inet6.c +++ b/net/ipv6/af_inet6.c @@ -250,31 +250,29 @@ static int inet6_create(struct net *net, struct socket *sock, int protocol, */ inet->inet_sport = htons(inet->inet_num); err = sk->sk_prot->hash(sk); - if (err) { - sk_common_release(sk); - goto out; - } + if (err) + goto out_sk_release; } if (sk->sk_prot->init) { err = sk->sk_prot->init(sk); - if (err) { - sk_common_release(sk); - goto out; - } + if (err) + goto out_sk_release; } if (!kern) { err = BPF_CGROUP_RUN_PROG_INET_SOCK(sk); - if (err) { - sk_common_release(sk); - goto out; - } + if (err) + goto out_sk_release; } out: return err; out_rcu_unlock: rcu_read_unlock(); goto out; +out_sk_release: + sk_common_release(sk); + sock->sk = NULL; + goto out; } static int __inet6_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len, -- 2.43.0