]> asedeno.scripts.mit.edu Git - linux.git/commit
Bluetooth: hci_ldisc: Use rwlocking to avoid closing proto races
authorDean Jenkins <Dean_Jenkins@mentor.com>
Fri, 5 May 2017 15:27:06 +0000 (16:27 +0100)
committerMarcel Holtmann <marcel@holtmann.org>
Thu, 18 May 2017 11:52:50 +0000 (13:52 +0200)
commitdec2c92880cc5435381d50e3045ef018a762a917
tree3312e3a68788b6dd49d292dafdc38ae11b6ae1ee
parentb56c7b2548a428d37b56951f419122ef4c75cc1b
Bluetooth: hci_ldisc: Use rwlocking to avoid closing proto races

When HCI_UART_PROTO_READY is in the set state, the Data Link protocol
layer (proto) is bound to the HCI UART driver. This state allows the
registered proto function pointers to be used by the HCI UART driver.

When unbinding (closing) the Data Link protocol layer, the proto
function pointers much be prevented from being used immediately before
running the proto close function pointer. Otherwise, there is a risk
that a proto non-close function pointer is used during or after the
proto close function pointer is used. The consequences are likely to
be a kernel crash because the proto close function pointer will free
resources used in the Data Link protocol layer.

Therefore, add a reader writer lock (rwlock) solution to prevent the
close proto function pointer from running by using write_lock_irqsave()
whilst the other proto function pointers are protected using
read_lock(). This means HCI_UART_PROTO_READY can safely be cleared
in the knowledge that no proto function pointers are running.

When flag HCI_UART_PROTO_READY is put into the clear state,
proto close function pointer can safely be run. Note
flag HCI_UART_PROTO_SET being in the set state prevents the proto
open function pointer from being run so there is no race condition
between proto open and close function pointers.

Signed-off-by: Dean Jenkins <Dean_Jenkins@mentor.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
drivers/bluetooth/hci_ldisc.c
drivers/bluetooth/hci_uart.h