Skip to content

Commit 92d4abd

Browse files
arkqVudentz
authored andcommitted
Bluetooth: vhci: Fix race when opening vhci device
When the vhci device is opened in the two-step way, i.e.: open device then write a vendor packet with requested controller type, the device shall respond with a vendor packet which includes HCI index of created interface. When the virtual HCI is created, the host sends a reset request to the controller. This request is processed by the vhci_send_frame() function. However, this request is send by a different thread, so it might happen that this HCI request will be received before the vendor response is queued in the read queue. This results in the HCI vendor response and HCI reset request inversion in the read queue which leads to improper behavior of btvirt: > dmesg [1754256.640122] Bluetooth: MGMT ver 1.22 [1754263.023806] Bluetooth: MGMT ver 1.22 [1754265.043775] Bluetooth: hci1: Opcode 0x c03 failed: -110 In order to synchronize vhci two-step open/setup process with virtual HCI initialization, this patch adds internal lock when queuing data in the vhci_send_frame() function. Signed-off-by: Arkadiusz Bokowy <[email protected]> Signed-off-by: Luiz Augusto von Dentz <[email protected]>
1 parent a950a59 commit 92d4abd

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

drivers/bluetooth/hci_vhci.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,10 @@ static int vhci_send_frame(struct hci_dev *hdev, struct sk_buff *skb)
7474
struct vhci_data *data = hci_get_drvdata(hdev);
7575

7676
memcpy(skb_push(skb, 1), &hci_skb_pkt_type(skb), 1);
77+
78+
mutex_lock(&data->open_mutex);
7779
skb_queue_tail(&data->readq, skb);
80+
mutex_unlock(&data->open_mutex);
7881

7982
wake_up_interruptible(&data->read_wait);
8083
return 0;

0 commit comments

Comments
 (0)