Bluetooth: hci_ldisc: Initialize hci_dev before open()
authorJeremy Cline <jcline@redhat.com>
Wed, 6 Feb 2019 17:54:16 +0000 (12:54 -0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 27 Mar 2019 05:13:53 +0000 (14:13 +0900)
commit6ea83d9338c181de28ca60cbf221b0a4b94c4fd9
treec2d5bb82214f5e232faa28ba190b2c9e3da7b9ca
parent3df00eb895f8ea16ccbfb6db49dc905f99ac9d17
Bluetooth: hci_ldisc: Initialize hci_dev before open()

commit 32a7b4cbe93b0a0ef7e63d31ca69ce54736c4412 upstream.

The hci_dev struct hdev is referenced in work queues and timers started
by open() in some protocols. This creates a race between the
initialization function and the work or timer which can result hdev
being dereferenced while it is still null.

The syzbot report contains a reliable reproducer which causes a null
pointer dereference of hdev in hci_uart_write_work() by making the
memory allocation for hdev fail.

To fix this, ensure hdev is valid from before calling a protocol's
open() until after calling a protocol's close().

Reported-by: syzbot+257790c15bcdef6fe00c@syzkaller.appspotmail.com
Signed-off-by: Jeremy Cline <jcline@redhat.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/bluetooth/hci_ldisc.c