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 388EF41A8F; Sat, 30 May 2026 18:37:28 +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=1780166249; cv=none; b=g35Q28XNwQ9E09ylsBHSi8tsZTs98soDSnArLue7/RHVrMW7mQvckpeWxs/SKwYsXoZ9w4jSyxN/IkKEKimIfs0m1laTwJrJRgLtG1wfUvLt9fdy+T06cK86DIzrpAdpAJIVSJ//mnY9dIQbP9TKg6Gk4cBchndIGbiuhwFJvew= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780166249; c=relaxed/simple; bh=zGHmjQ6/jYbpWU4XJ0N7b0OR3V539bRMUKJ7NgusHnQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DZg4H9if6Yh3HRXjoZgP2Rr+lOreD5SW6imM2rqtlypzc8hS78SOR31BVp1RfTCScf7fQVvSJrDBOF6Au15cgJUIb72n/KVBFvs2NdIwFqyUmHrXk6V/VI/5m5C1Od2bC99m0J0PiVnTXIRVLrWeKEzR4aQTUI5/lm4e2FUmRR4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=CHdr0kei; 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="CHdr0kei" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7A3F51F00898; Sat, 30 May 2026 18:37:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1780166248; bh=YUrrkJrSQ/CYOdIAS8FlkjedtnbYPJxR9gTb2sOGJ4M=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=CHdr0keiJPx8v4BpnCdh42X4pfvkNzz/pT1dkQCUkTClQPrCxmacPfC2gemooY3Hr ApERRxRkB01gYtIh+wAM7Wja9hdX0+TkUdQI2GJQbUr4V5rb8ZgJbSkFn3Gl+1K1WH 1L0Ii9b9XsuyD4/i3U6/hd6RuIzm4oyx6+N5cfqY= 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 5.10 316/589] Bluetooth: hci_ldisc: Clear HCI_UART_PROTO_INIT on error Date: Sat, 30 May 2026 18:03:17 +0200 Message-ID: <20260530160233.243542239@linuxfoundation.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260530160224.570625122@linuxfoundation.org> References: <20260530160224.570625122@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 5.10-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 436d82a7f5871..b1e036bb682f8 100644 --- a/drivers/bluetooth/hci_ldisc.c +++ b/drivers/bluetooth/hci_ldisc.c @@ -691,6 +691,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