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 AA72322331C; Thu, 12 Dec 2024 17:50:33 +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=1734025833; cv=none; b=H67GAGy6MUQwEIcUKh/ZuIHnEqakFvcSapsxsey4ZeekiV57QpgVcBhwKA18S01aaBaeuGMHRxVqkOA/vzQKaTd+BbJuxnTuIZB/pmRhRIHUs5JaOrLHQczz6mo69lX2dTTIb4rOIHPvPSzEo0IoZn4MTUexxJ/Rk7bWe8fkCek= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734025833; c=relaxed/simple; bh=C8Q7jys1u5c3PIjo98RyE+w3/+ZeRS7HYxl4BesxKtg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VKobDSaRVQVuKihYPQOllRfkl6M8FDXClykIswFm01a6hzP8s3Q0CF3Rev6H5yBa9rGxDE8vz9WcoDXVLyMAwaUwMh8DKjcF5ltkPfKUnaKXjNITuqrG2YKE6Gk3bK4HycgWQ4K46ybHgdYt8QC8ps6+nEfyvInSO6F/rW9D3xQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=KfNPQnXB; 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="KfNPQnXB" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 323A5C4CECE; Thu, 12 Dec 2024 17:50:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1734025833; bh=C8Q7jys1u5c3PIjo98RyE+w3/+ZeRS7HYxl4BesxKtg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KfNPQnXBY6LujzbVBwatcCdA+TcZmU2BoTfQHXozofKxlxqYnPGGNefLgYjRTejeL wT7Af3RogW+gFmThLG7P1tVWHu3FHbo7EI5tg+KwyF1lYeGCsBZH8Sbpy+3XUUilMR R+HCQbfWadF8eAVxXOX/w+KRQZ/DQn4M4aj6A45U= 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 5.4 275/321] Bluetooth: L2CAP: do not leave dangling sk pointer on error in l2cap_sock_create() Date: Thu, 12 Dec 2024 16:03:13 +0100 Message-ID: <20241212144240.844119742@linuxfoundation.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241212144229.291682835@linuxfoundation.org> References: <20241212144229.291682835@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.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Ignat Korchagin [ Upstream commit 7c4f78cdb8e7501e9f92d291a7d956591bf73be9 ] bt_sock_alloc() allocates the sk object and attaches it to the provided sock object. On error l2cap_sock_alloc() frees the sk object, but the dangling pointer is still attached to the sock object, which may create use-after-free in other code. Signed-off-by: Ignat Korchagin Reviewed-by: Kuniyuki Iwashima Reviewed-by: Eric Dumazet Link: https://patch.msgid.link/20241014153808.51894-3-ignat@cloudflare.com Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- net/bluetooth/l2cap_sock.c | 1 + 1 file changed, 1 insertion(+) diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c index 9eea2af9a8e1c..6ec6f6a06521d 100644 --- a/net/bluetooth/l2cap_sock.c +++ b/net/bluetooth/l2cap_sock.c @@ -1678,6 +1678,7 @@ static struct sock *l2cap_sock_alloc(struct net *net, struct socket *sock, chan = l2cap_chan_create(); if (!chan) { sk_free(sk); + sock->sk = NULL; return NULL; } -- 2.43.0