Skip to content

Commit f4b69c3

Browse files
Jonathan Rissanengregkh
authored andcommitted
Bluetooth: hci_ldisc: Clear HCI_UART_PROTO_INIT on error
[ Upstream commit 68d39ea ] 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: 5df5daf ("Bluetooth: hci_uart: Fix another race during initialization") Signed-off-by: Jonathan Rissanen <jonathan.rissanen@axis.com> Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 7a148da commit f4b69c3

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

drivers/bluetooth/hci_ldisc.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,9 @@ static int hci_uart_register_dev(struct hci_uart *hu)
692692

693693
if (hci_register_dev(hdev) < 0) {
694694
BT_ERR("Can't register HCI device");
695+
percpu_down_write(&hu->proto_lock);
696+
clear_bit(HCI_UART_PROTO_INIT, &hu->flags);
697+
percpu_up_write(&hu->proto_lock);
695698
hu->proto->close(hu);
696699
hu->hdev = NULL;
697700
hci_free_dev(hdev);

0 commit comments

Comments
 (0)