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 954082AF0E; Thu, 12 Dec 2024 15:19:18 +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=1734016760; cv=none; b=m8CXB8s46ygjTkpHGEsNeJM4M+y23nxhFKuIade9K3hDOPhqtQRpX2l2Z2ctBerGo1P0sSOP4f/HdhbZMLYYM+ktEep/0b+CGLoOq7Q8ZmWtxCxivq5yq7MnFioIAmtb2xULMjK0OMQ+QwfnoRfU5fV5IYlMN601O9Q8KTNS+u8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734016760; c=relaxed/simple; bh=NgUBWttAfEiAN1jCTwjSEL3WVjuWtvN71X0OeFoNG/Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HWrqx63hr46tKyzidl/mmiIvnfvP2FU3ifIbjrhqXWMr5k1lCQIOuBNRL38QObg48tdQzf6+Or4oPLkdERhyTyj2Nf359h14UET32kdP3z6biO9sO/wua0berCygsf3xLPWNBQSKGSkE0u7JFGi6DtbolUU4Z3USt4PDhMfWrsk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=BU3oMGXx; 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="BU3oMGXx" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B4B10C4CECE; Thu, 12 Dec 2024 15:19:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1734016758; bh=NgUBWttAfEiAN1jCTwjSEL3WVjuWtvN71X0OeFoNG/Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BU3oMGXx3dOactmTYsRaGjv4t0Netktzn7LYzjV6HMAbdcr5HYPkG4srIyqbxRxQU DZAneP3qGDJ/P/B1mVkdqTKPMt3W2kL1iJmGChfVzey60hu8ejqlTGu7MZZ+ZyTV4X JM24nPjnl1MUgJpa5byHfMSS0Q+cTj9JJmcb8bks= 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.12 289/466] Bluetooth: RFCOMM: avoid leaving dangling sk pointer in rfcomm_sock_alloc() Date: Thu, 12 Dec 2024 15:57:38 +0100 Message-ID: <20241212144318.204130042@linuxfoundation.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241212144306.641051666@linuxfoundation.org> References: <20241212144306.641051666@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.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Ignat Korchagin [ Upstream commit 3945c799f12b8d1f49a3b48369ca494d981ac465 ] bt_sock_alloc() attaches allocated sk object to the provided sock object. If rfcomm_dlc_alloc() fails, we release the sk object, but leave the dangling pointer in the sock object, which may cause use-after-free. Fix this by swapping calls to bt_sock_alloc() and rfcomm_dlc_alloc(). Signed-off-by: Ignat Korchagin Reviewed-by: Kuniyuki Iwashima Reviewed-by: Eric Dumazet Link: https://patch.msgid.link/20241014153808.51894-4-ignat@cloudflare.com Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- net/bluetooth/rfcomm/sock.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c index 8af1bf518321f..40766f8119ed9 100644 --- a/net/bluetooth/rfcomm/sock.c +++ b/net/bluetooth/rfcomm/sock.c @@ -274,13 +274,13 @@ static struct sock *rfcomm_sock_alloc(struct net *net, struct socket *sock, struct rfcomm_dlc *d; struct sock *sk; - sk = bt_sock_alloc(net, sock, &rfcomm_proto, proto, prio, kern); - if (!sk) + d = rfcomm_dlc_alloc(prio); + if (!d) return NULL; - d = rfcomm_dlc_alloc(prio); - if (!d) { - sk_free(sk); + sk = bt_sock_alloc(net, sock, &rfcomm_proto, proto, prio, kern); + if (!sk) { + rfcomm_dlc_free(d); return NULL; } -- 2.43.0