From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 71C863A5426; Wed, 20 May 2026 18:33:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779301987; cv=none; b=oxp/DAXKP9myDRCMhYib7w2OV2z0hCrSKsW4tOdeC1TdjOrqF7UeojjKGtb5Cv3BsmZ5waORA8F3tfMeVPBKHK9o+0OUSfuOfOhY+T3E9Aseg2vXpUq9OwpP0zMR+Hj+fJwMe48YKRolcz9cIVNXhZ5NZInPK/TnSrXk5C4LsfY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779301987; c=relaxed/simple; bh=E7XIDsfsBIW6kRr7xznp7blg46uNvK/jIVy8tQa9cko=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Aj5eBWWkNfuqbIB68M3AzWTTnCCKuONwT0QBLkaSIIXYj0MuXvXZXZy/U0DCLPKQopbB9wAS/LcTsDOSOQ2yIAgqwS9lL2mpiWzNnCL3SgGBhk+uG8a3bz7Mu5vGbXz8Axk9LWem3WD0CDhcjF7tC1SbKueEX3efDcTLZqqNeyU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=MW7SI+qd; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="MW7SI+qd" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CAB361F000E9; Wed, 20 May 2026 18:33:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1779301985; bh=8axdLrB+9EFsqSapBvHaQD5xOatW1jdH01AH+91kl8k=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=MW7SI+qdF03xKvPzrGujqhrblNT6eJC65p1BndSbSQjqkpbn+6WqryODI6lLn+roz oVv2ZRlXvkyhrk+o3/UiRTsvX0rdO2BuLRFrrRJPZSElWWR7TBBLiSwleVnL6plFFd q3ktz9E8GXEWpk+sUW5caDbZPs+n56q1CsUmymrk= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Jonathan Rissanen , Luiz Augusto von Dentz , Sasha Levin Subject: [PATCH 6.6 078/508] Bluetooth: hci_ldisc: Clear HCI_UART_PROTO_INIT on error Date: Wed, 20 May 2026 18:18:21 +0200 Message-ID: <20260520162100.300397564@linuxfoundation.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260520162058.573354582@linuxfoundation.org> References: <20260520162058.573354582@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jonathan Rissanen [ Upstream commit 68d39ea5e0adc9ecaea1ce8abd842ec972eb8718 ] When hci_register_dev() fails in hci_uart_register_dev() HCI_UART_PROTO_INIT is not cleared before calling hu->proto->close(hu) and setting hu->hdev to NULL. This means incoming UART data will reach the protocol-specific recv handler in hci_uart_tty_receive() after resources are freed. Clear HCI_UART_PROTO_INIT with a write lock before calling hu->proto->close() and setting hu->hdev to NULL. The write lock ensures all active readers have completed and no new reader can enter the protocol recv path before resources are freed. This allows the protocol-specific recv functions to remove the "HCI_UART_REGISTERED" guard without risking a null pointer dereference if hci_register_dev() fails. Fixes: 5df5dafc171b ("Bluetooth: hci_uart: Fix another race during initialization") Signed-off-by: Jonathan Rissanen Signed-off-by: Luiz Augusto von Dentz Signed-off-by: Sasha Levin --- drivers/bluetooth/hci_ldisc.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/bluetooth/hci_ldisc.c b/drivers/bluetooth/hci_ldisc.c index e38f3c4458c90..85baba91aaa97 100644 --- a/drivers/bluetooth/hci_ldisc.c +++ b/drivers/bluetooth/hci_ldisc.c @@ -689,6 +689,9 @@ static int hci_uart_register_dev(struct hci_uart *hu) if (hci_register_dev(hdev) < 0) { BT_ERR("Can't register HCI device"); + percpu_down_write(&hu->proto_lock); + clear_bit(HCI_UART_PROTO_INIT, &hu->flags); + percpu_up_write(&hu->proto_lock); hu->proto->close(hu); hu->hdev = NULL; hci_free_dev(hdev); -- 2.53.0