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 5531C213E6F; Thu, 12 Dec 2024 17:32:24 +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=1734024744; cv=none; b=VxEWvIeHEC7ZCJNkfZE8ijUB0EU1vO8uSsev/EezqkjaVQZ1tIAv2iC/5XQEu6lrxjdJcWah0AMhqRP6+llAgCl/zh0J94hXO4qm7C08U77VaQSRq8hr/6bYfuuAR9Cvuxl1xDN6QQxbLBOju4dvo7883itUORvw2yau8Fd5+KY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734024744; c=relaxed/simple; bh=3ZA3wF3Tw+14hA9D9IIk1Z1w8xpuEbrQTCCFMzyIVXI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YfS0pUovZwJ2meaDKvXVGAEFsklsDh9uOFCc9AACK/zAnt5KmMfaY1iCQ2r7z42tDJ4KLiyIGuqXMRXjNhqiYeTBQyrn5BhaFifQmFzOH90pXpCoEPTGmh4nj0HjX/a2F0WwuIikuGGuoIf9b3gM2op2AfpFX0kVlFgCvwQydJ8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=lM48wPyM; 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="lM48wPyM" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C9654C4CECE; Thu, 12 Dec 2024 17:32:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1734024744; bh=3ZA3wF3Tw+14hA9D9IIk1Z1w8xpuEbrQTCCFMzyIVXI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lM48wPyMYwUBWNCtWs6wiUOToRT87qFxywyxNJCxAdGrJ0+CxNTPkTFo/OnaeE/GK 4Nx0sYjJUqpkB6GX9VdJXvJ02sv5OCNLUOGew5JmCcTh/rHHRnSmXX4YxULUrpfICl H2AxFZrvpeFXsUu/Dz/tvEQkF+Dwxkzft6mOvteI= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Ignat Korchagin , Miquel Raynal , Kuniyuki Iwashima , Eric Dumazet , Jakub Kicinski , Sasha Levin Subject: [PATCH 5.10 397/459] net: ieee802154: do not leave a dangling sk pointer in ieee802154_create() Date: Thu, 12 Dec 2024 16:02:15 +0100 Message-ID: <20241212144309.445689059@linuxfoundation.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241212144253.511169641@linuxfoundation.org> References: <20241212144253.511169641@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 5.10-stable review patch. If anyone has any objections, please let me know. ------------------ From: Ignat Korchagin [ Upstream commit b4fcd63f6ef79c73cafae8cf4a114def5fc3d80d ] sock_init_data() attaches the allocated sk object to the provided sock object. If ieee802154_create() fails later, the allocated sk object is freed, but the dangling pointer remains in the provided sock object, which may allow use-after-free. Clear the sk pointer in the sock object on error. Signed-off-by: Ignat Korchagin Reviewed-by: Miquel Raynal Reviewed-by: Kuniyuki Iwashima Reviewed-by: Eric Dumazet Link: https://patch.msgid.link/20241014153808.51894-6-ignat@cloudflare.com Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- net/ieee802154/socket.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/net/ieee802154/socket.c b/net/ieee802154/socket.c index d4c275e56d825..c8b9efc92b45a 100644 --- a/net/ieee802154/socket.c +++ b/net/ieee802154/socket.c @@ -1047,19 +1047,21 @@ static int ieee802154_create(struct net *net, struct socket *sock, if (sk->sk_prot->hash) { rc = sk->sk_prot->hash(sk); - if (rc) { - sk_common_release(sk); - goto out; - } + if (rc) + goto out_sk_release; } if (sk->sk_prot->init) { rc = sk->sk_prot->init(sk); if (rc) - sk_common_release(sk); + goto out_sk_release; } out: return rc; +out_sk_release: + sk_common_release(sk); + sock->sk = NULL; + goto out; } static const struct net_proto_family ieee802154_family_ops = { -- 2.43.0