]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/4.6.1/bluetooth-vhci-fix-race-at-creating-hci-device.patch
4.9-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 4.6.1 / bluetooth-vhci-fix-race-at-creating-hci-device.patch
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
5
6 From: Takashi Iwai <tiwai@suse.de>
7
8 commit c7c999cb18da88a881e10e07f0724ad0bfaff770 upstream.
9
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.
15
16 This patch introduces a mutex to protect against the concurrent device
17 creations.
18
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>
22
23 ---
24 drivers/bluetooth/hci_vhci.c | 23 +++++++++++++++++------
25 1 file changed, 17 insertions(+), 6 deletions(-)
26
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;
32
33 + struct mutex open_mutex;
34 struct delayed_work open_timeout;
35 };
36
37 @@ -87,12 +88,15 @@ static int vhci_send_frame(struct hci_de
38 return 0;
39 }
40
41 -static int vhci_create_device(struct vhci_data *data, __u8 opcode)
42 +static int __vhci_create_device(struct vhci_data *data, __u8 opcode)
43 {
44 struct hci_dev *hdev;
45 struct sk_buff *skb;
46 __u8 dev_type;
47
48 + if (data->hdev)
49 + return -EBADFD;
50 +
51 /* bits 0-1 are dev_type (BR/EDR or AMP) */
52 dev_type = opcode & 0x03;
53
54 @@ -151,6 +155,17 @@ static int vhci_create_device(struct vhc
55 return 0;
56 }
57
58 +static int vhci_create_device(struct vhci_data *data, __u8 opcode)
59 +{
60 + int err;
61 +
62 + mutex_lock(&data->open_mutex);
63 + err = __vhci_create_device(data, opcode);
64 + mutex_unlock(&data->open_mutex);
65 +
66 + return err;
67 +}
68 +
69 static inline ssize_t vhci_get_user(struct vhci_data *data,
70 struct iov_iter *from)
71 {
72 @@ -191,11 +206,6 @@ static inline ssize_t vhci_get_user(stru
73 case HCI_VENDOR_PKT:
74 cancel_delayed_work_sync(&data->open_timeout);
75
76 - if (data->hdev) {
77 - kfree_skb(skb);
78 - return -EBADFD;
79 - }
80 -
81 opcode = *((__u8 *) skb->data);
82 skb_pull(skb, 1);
83
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);
87
88 + mutex_init(&data->open_mutex);
89 INIT_DELAYED_WORK(&data->open_timeout, vhci_open_timeout);
90
91 file->private_data = data;