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 665A7217656; Thu, 12 Dec 2024 17:08:19 +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=1734023302; cv=none; b=lBKRQWgApOhx9wIqAeZxRgeoJ3kPN1Fsnf6dWH5g0NJKip5r2YZ846agsx5ZmFURiTcqNQwCVp0T6UJaKRzGC1RfstikwMv71nF40B8ia7Thr9l5/jIm4vp7BBclql6iyycXETRp4TQo4orRaj73lL2vbam0KAue+KwBerUxUCU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734023302; c=relaxed/simple; bh=EDuDeSDH/Gnaxj/w/KIac3WqqyvWfpbFmvEJ5P8th7o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WdJPcfjnepFnQpR8zBEnXea/dwZktqPPDmU20xV8wt8+sXiT8O7TZ3VAIW/VnE3S8xWRUPUq0FVxt7emFo9FUpxReRPcocWqXX2/4lDpJ2V+C0ahv4sBcKK6g8PSv5K/zjbNItUizuosSzbfdPLGnivLg96v0+4jYxfN91tK4uA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=r2tjmg6L; 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="r2tjmg6L" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 86FC8C4CED3; Thu, 12 Dec 2024 17:08:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1734023298; bh=EDuDeSDH/Gnaxj/w/KIac3WqqyvWfpbFmvEJ5P8th7o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=r2tjmg6L8CdkWsxadGhSRCW6RnhlxtHBcYTaIqK40EBgRDKqffHtLd7cDSwHppSpY Uvw04S2E9YLW9KJ8s31SnOHTHDER95vQdBWvW3/8k5BtBA3KSLS5tNdvK9mI2ZANpd K1cvY9vWyNL5Efrrzq/088z4OoQK6j3ll0O9FG+E= 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.15 489/565] net: ieee802154: do not leave a dangling sk pointer in ieee802154_create() Date: Thu, 12 Dec 2024 16:01:24 +0100 Message-ID: <20241212144331.090573840@linuxfoundation.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241212144311.432886635@linuxfoundation.org> References: <20241212144311.432886635@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.15-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 586a6c4adf246..d7fa862b81ef5 100644 --- a/net/ieee802154/socket.c +++ b/net/ieee802154/socket.c @@ -1046,19 +1046,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