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 7F8F22210E3; Thu, 12 Dec 2024 16:33:07 +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=1734021187; cv=none; b=CO2lgml8vbwmiorw+XAmYMu3H+hzm6wdzND7uHXaeAr7Q+dxEb8wsFMPLc8hL1erJmkDuKpDKzsKFZoQJKuNk4XZAmTOR09q+hnUgIyK5ijkHPSi2BZAzyrWI5VQhXUtklKxFPq6sm7NWdNgyzKgrY/phYY7cRVbpP9RTJwrIxE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734021187; c=relaxed/simple; bh=Ug3yRK1MhqMWv6hv8g8olYhyuUprGIBFCTihBeSR6WY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ByqLqpl9HphEzRAqAsD1il2eGQsgCYEFD/QEJxpx1GrkoBqAsZtBOhu3Kx/Z08QR6Sw47LHsMms7ffFvkEcbqBxu8hKF/qbWbjc487yEkNhDfG5suOf2jLMzWchBo/1o89b9qbKLuV+Ds/8EnTCmFPvaMpms+ucqXfF6GOnA2b0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=WLy9Q+VT; 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="WLy9Q+VT" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C442EC4CECE; Thu, 12 Dec 2024 16:33:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1734021187; bh=Ug3yRK1MhqMWv6hv8g8olYhyuUprGIBFCTihBeSR6WY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WLy9Q+VT5ThfL66Jw9JctAUyU0ARoRhNZR3IfVc6LOsh/cUFZJYdGI3S5RRL+E3wm EGkItCD5M9htQOr3ZMB8KZ9/ubuq1LMAT1eS2wls8Eo1tGgatSMSM7AeUVqLxno0v4 r/caYXRwllFg7sXioYKgcO0syhq7KKu/blbcSjwE= 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.1 669/772] Bluetooth: RFCOMM: avoid leaving dangling sk pointer in rfcomm_sock_alloc() Date: Thu, 12 Dec 2024 16:00:14 +0100 Message-ID: <20241212144417.556961672@linuxfoundation.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241212144349.797589255@linuxfoundation.org> References: <20241212144349.797589255@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.1-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 4fae82fedccaf..1cf6543bdec55 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