summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2016-04-14 18:32:19 +0300
committerBen Hutchings <ben@decadent.org.uk>2016-08-23 00:37:50 +0300
commit418429fdabbba3d1e195e7e35fa631c38581f967 (patch)
tree8ce8d16722426cae2bb3704bc2ef6b3ec8ff1b6b /drivers
parent35d7cfb3d3c5873e8e2e9de8f85642b8393cb3f1 (diff)
downloadlinux-418429fdabbba3d1e195e7e35fa631c38581f967.tar.xz
Bluetooth: vhci: Fix race at creating hci device
commit c7c999cb18da88a881e10e07f0724ad0bfaff770 upstream. hci_vhci driver creates a hci device object dynamically upon each HCI_VENDOR_PKT write. Although it checks the already created object and returns an error, it's still racy and may build multiple hci_dev objects concurrently when parallel writes are performed, as the device tracks only a single hci_dev object. This patch introduces a mutex to protect against the concurrent device creations. Signed-off-by: Takashi Iwai <tiwai@suse.de> Signed-off-by: Marcel Holtmann <marcel@holtmann.org> [bwh: Backported to 3.16: adjust context] Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/bluetooth/hci_vhci.c23
1 files changed, 17 insertions, 6 deletions
diff --git a/drivers/bluetooth/hci_vhci.c b/drivers/bluetooth/hci_vhci.c
index 877b6c363d05..e26eb6b606e1 100644
--- a/drivers/bluetooth/hci_vhci.c
+++ b/drivers/bluetooth/hci_vhci.c
@@ -50,6 +50,7 @@ struct vhci_data {
wait_queue_head_t read_wait;
struct sk_buff_head readq;
+ struct mutex open_mutex;
struct delayed_work open_timeout;
};
@@ -95,11 +96,14 @@ static int vhci_send_frame(struct hci_dev *hdev, struct sk_buff *skb)
return 0;
}
-static int vhci_create_device(struct vhci_data *data, __u8 dev_type)
+static int __vhci_create_device(struct vhci_data *data, __u8 dev_type)
{
struct hci_dev *hdev;
struct sk_buff *skb;
+ if (data->hdev)
+ return -EBADFD;
+
skb = bt_skb_alloc(4, GFP_KERNEL);
if (!skb)
return -ENOMEM;
@@ -140,6 +144,17 @@ static int vhci_create_device(struct vhci_data *data, __u8 dev_type)
return 0;
}
+static int vhci_create_device(struct vhci_data *data, __u8 opcode)
+{
+ int err;
+
+ mutex_lock(&data->open_mutex);
+ err = __vhci_create_device(data, opcode);
+ mutex_unlock(&data->open_mutex);
+
+ return err;
+}
+
static inline ssize_t vhci_get_user(struct vhci_data *data,
const struct iovec *iov,
unsigned long count)
@@ -185,11 +200,6 @@ static inline ssize_t vhci_get_user(struct vhci_data *data,
case HCI_VENDOR_PKT:
cancel_delayed_work_sync(&data->open_timeout);
- if (data->hdev) {
- kfree_skb(skb);
- return -EBADFD;
- }
-
dev_type = *((__u8 *) skb->data);
skb_pull(skb, 1);
@@ -318,6 +328,7 @@ static int vhci_open(struct inode *inode, struct file *file)
skb_queue_head_init(&data->readq);
init_waitqueue_head(&data->read_wait);
+ mutex_init(&data->open_mutex);
INIT_DELAYED_WORK(&data->open_timeout, vhci_open_timeout);
file->private_data = data;