1 From c7c999cb18da88a881e10e07f0724ad0bfaff770 Mon Sep 17 00:00:00 2001
2 From: Takashi Iwai <tiwai@suse.de>
3 Date: Thu, 14 Apr 2016 17:32:19 +0200
4 Subject: Bluetooth: vhci: Fix race at creating hci device
6 From: Takashi Iwai <tiwai@suse.de>
8 commit c7c999cb18da88a881e10e07f0724ad0bfaff770 upstream.
10 hci_vhci driver creates a hci device object dynamically upon each
11 HCI_VENDOR_PKT write. Although it checks the already created object
12 and returns an error, it's still racy and may build multiple hci_dev
13 objects concurrently when parallel writes are performed, as the device
14 tracks only a single hci_dev object.
16 This patch introduces a mutex to protect against the concurrent device
19 Signed-off-by: Takashi Iwai <tiwai@suse.de>
20 Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
21 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
24 drivers/bluetooth/hci_vhci.c | 23 +++++++++++++++++------
25 1 file changed, 17 insertions(+), 6 deletions(-)
27 --- a/drivers/bluetooth/hci_vhci.c
28 +++ b/drivers/bluetooth/hci_vhci.c
29 @@ -50,6 +50,7 @@ struct vhci_data {
30 wait_queue_head_t read_wait;
31 struct sk_buff_head readq;
33 + struct mutex open_mutex;
34 struct delayed_work open_timeout;
37 @@ -87,12 +88,15 @@ static int vhci_send_frame(struct hci_de
41 -static int vhci_create_device(struct vhci_data *data, __u8 opcode)
42 +static int __vhci_create_device(struct vhci_data *data, __u8 opcode)
51 /* bits 0-1 are dev_type (BR/EDR or AMP) */
52 dev_type = opcode & 0x03;
54 @@ -151,6 +155,17 @@ static int vhci_create_device(struct vhc
58 +static int vhci_create_device(struct vhci_data *data, __u8 opcode)
62 + mutex_lock(&data->open_mutex);
63 + err = __vhci_create_device(data, opcode);
64 + mutex_unlock(&data->open_mutex);
69 static inline ssize_t vhci_get_user(struct vhci_data *data,
70 struct iov_iter *from)
72 @@ -191,11 +206,6 @@ static inline ssize_t vhci_get_user(stru
74 cancel_delayed_work_sync(&data->open_timeout);
81 opcode = *((__u8 *) skb->data);
84 @@ -320,6 +330,7 @@ static int vhci_open(struct inode *inode
85 skb_queue_head_init(&data->readq);
86 init_waitqueue_head(&data->read_wait);
88 + mutex_init(&data->open_mutex);
89 INIT_DELAYED_WORK(&data->open_timeout, vhci_open_timeout);
91 file->private_data = data;