From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932458AbcDTOzn (ORCPT ); Wed, 20 Apr 2016 10:55:43 -0400 Received: from mx2.suse.de ([195.135.220.15]:45374 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932168AbcDTOzk (ORCPT ); Wed, 20 Apr 2016 10:55:40 -0400 Date: Wed, 20 Apr 2016 16:55:36 +0200 Message-ID: From: Takashi Iwai To: Marcel Holtmann Cc: Linux Bluetooth , "Gustavo F. Padovan" , Johan Hedberg , Jiri Slaby , linux-kernel@vger.kernel.org Subject: Re: [PATCH] Bluetooth: vhci: Fix race at creating hci device In-Reply-To: <4C452D10-6A16-47B1-9DF2-E1B8D162F5B7@holtmann.org> References: <1460647939-15637-1-git-send-email-tiwai@suse.de> <4C452D10-6A16-47B1-9DF2-E1B8D162F5B7@holtmann.org> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI/1.14.6 (Maruoka) FLIM/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL/10.8 Emacs/24.5 (x86_64-suse-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 20 Apr 2016 16:32:24 +0200, Marcel Holtmann wrote: > > Hi Takashi, > > > 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. > > > > Cc: > > Signed-off-by: Takashi Iwai > > --- > > drivers/bluetooth/hci_vhci.c | 22 ++++++++++++++++------ > > 1 file changed, 16 insertions(+), 6 deletions(-) > > > > diff --git a/drivers/bluetooth/hci_vhci.c b/drivers/bluetooth/hci_vhci.c > > index f67ea1c090cb..39230f30f544 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; > > }; > > > > @@ -87,7 +88,7 @@ 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 opcode) > > +static int __vhci_create_device(struct vhci_data *data, __u8 opcode) > > { > > struct hci_dev *hdev; > > struct sk_buff *skb; > > @@ -151,6 +152,19 @@ static int vhci_create_device(struct vhci_data *data, __u8 opcode) > > return 0; > > } > > > > +static int vhci_create_device(struct vhci_data *data, __u8 opcode) > > +{ > > + int err; > > + > > + mutex_lock(&data->open_mutex); > > + if (data->hdev) > > + err = -EBADFD; > > I moved this check into __vhci_create_device after applying your patch to bluetooth-next tree. I think that is a lot cleaner and no need for you to respin it. OK, thanks! Takashi