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 BE4DC3A4526; Wed, 20 May 2026 17:25:14 +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=1779297915; cv=none; b=SMIziOjoG0qLoxsEkMjq5kXdZ6b0BhASaKZXiNqudEVhuHM/sxG0B6sF6XhdlixRZjmtNhfBOEABEIIQ1WBTNZHZ3oanNxW+28CfpGGfy1A1Xsy10wOOOrVBlHLb1hdUifTCQU4/dkCAYFQCrAjqrFLtOYd9SxbYKSUfochZqYQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779297915; c=relaxed/simple; bh=FmFjrUEEKtO4rl0okwaCyPw8TZJ6N1zRCrVNCc5WlQU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DTorzEGPQXeodDFRJ0Cg7a7BoA/vmwUJRSua75mc/ShhaqINf/qHY1J87xMeNYmytgF0fLV8BdB8b6o3a/cDWS3TPOGWj6kB4/UUOTIO5qrhbxdqF+aTxq5D3ekz3B39OvDF5MVr/V4LevZ2QA4DtRW4uR8pnoUED/1qAJ1r2rM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=aom/7B22; 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="aom/7B22" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 30F711F000E9; Wed, 20 May 2026 17:25:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1779297914; bh=7N6dUfFqA8mYGcH96vdm3a35phy+ZuWk7bYvb8i6OwA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=aom/7B22AXu8gOinpfVH+JaNJIOJEt14Sk0Xqtv9QFY8rTty+fH5pXYdzOgq1svXg s6ejEgCuafI5CvSW5kZP/4dUcpkPP7IibdcZ1P3umR3qAtIttXyWmk57TlbUfLXRZi ZxDWEIqhtLJeKr+pe7Wsi7g1CrBMD3DPKGf7dkeI= 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.18 175/957] Bluetooth: hci_ldisc: Clear HCI_UART_PROTO_INIT on error Date: Wed, 20 May 2026 18:10:58 +0200 Message-ID: <20260520162138.348949688@linuxfoundation.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260520162134.554764788@linuxfoundation.org> References: <20260520162134.554764788@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.18-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 2b28515de92c4..5455990ab211e 100644 --- a/drivers/bluetooth/hci_ldisc.c +++ b/drivers/bluetooth/hci_ldisc.c @@ -692,6 +692,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