Skip to content

Commit e365b94

Browse files
Kefeng Wanggregkh
Kefeng Wang
authored andcommitted
Bluetooth: hci_ldisc: Postpone HCI_UART_PROTO_READY bit set in hci_uart_set_proto()
commit 56897b2 upstream. task A: task B: hci_uart_set_proto flush_to_ldisc - p->open(hu) -> h5_open //alloc h5 - receive_buf - set_bit HCI_UART_PROTO_READY - tty_port_default_receive_buf - hci_uart_register_dev - tty_ldisc_receive_buf - hci_uart_tty_receive - test_bit HCI_UART_PROTO_READY - h5_recv - clear_bit HCI_UART_PROTO_READY while() { - p->open(hu) -> h5_close //free h5 - h5_rx_3wire_hdr - h5_reset() //use-after-free } It could use ioctl to set hci uart proto, but there is a use-after-free issue when hci_uart_register_dev() fail in hci_uart_set_proto(), see stack above, fix this by setting HCI_UART_PROTO_READY bit only when hci_uart_register_dev() return success. Reported-by: [email protected] Signed-off-by: Kefeng Wang <[email protected]> Reviewed-by: Jeremy Cline <[email protected]> Signed-off-by: Marcel Holtmann <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent f67202f commit e365b94

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

drivers/bluetooth/hci_ldisc.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -696,14 +696,13 @@ static int hci_uart_set_proto(struct hci_uart *hu, int id)
696696
return -EPROTONOSUPPORT;
697697

698698
hu->proto = p;
699-
set_bit(HCI_UART_PROTO_READY, &hu->flags);
700699

701700
err = hci_uart_register_dev(hu);
702701
if (err) {
703-
clear_bit(HCI_UART_PROTO_READY, &hu->flags);
704702
return err;
705703
}
706704

705+
set_bit(HCI_UART_PROTO_READY, &hu->flags);
707706
return 0;
708707
}
709708

0 commit comments

Comments
 (0)