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 BCB8636CE19; Wed, 20 May 2026 18:04:21 +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=1779300262; cv=none; b=IkFs8Od3gGo0arJYXeKMOchr10tmpPWbn7lZXBxkiyM4AxfgZgbIxORAF4lVkXd1fOJAj9p6hIgV5Syx/0ldlilTUzdzGnipex/YTxP7pK5p0JsRFWnGQ88IWItF7kVsIM12zqbfK9cZ7Jz3E713nUwNkzrBNK/GhY9sXb4iR5g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779300262; c=relaxed/simple; bh=dMZGoeSRBbMDChr1LK97/5ftlyFVXWHafTA5nvKG61k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MoDwmXQGu1VewtqtR2rYny/IQd+5+uPpsjfQIknCc5qaL47cprhzXJW9jjZCrRDYffy8uBW84KenME+cxrEwBsD0YKId7nAz7Du1/9ElMHZfTtKnspsIE96eJlqh11REILKNOPtWkudklTgO78ijQQQdvAO9v7/uZXCdEXgHSfc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=qmP4QpeN; 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="qmP4QpeN" Received: by smtp.kernel.org (Postfix) with ESMTPSA id F1ABA1F000E9; Wed, 20 May 2026 18:04:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1779300261; bh=onvH6+CiPa2IoEBA7A14j3JWjRJ/Pvj11gzBtN1ge3A=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=qmP4QpeNU9GHnGtrYl3KmgWEahyHUZLnkE0itJmaaXxKVraKF9y5gDlNjm44+8Ayf UAKZ5xnaATPvz3R9iKY58P8vdUYGVUMQIVunFvSZQA0GXB7hTJI9e1GWhncWE3gyiy SAQtzhXuWgPzKLHIKrrLVGGM4m++nuXHwui1WzTk= 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.12 107/666] Bluetooth: hci_ldisc: Clear HCI_UART_PROTO_INIT on error Date: Wed, 20 May 2026 18:15:18 +0200 Message-ID: <20260520162113.540865845@linuxfoundation.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260520162111.222830634@linuxfoundation.org> References: <20260520162111.222830634@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.12-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 436ee77d4bf2f..0d06b83816d1c 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