Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1383450 > unrolled thread

Re: [PATCH] Bluetooth: vhci: Fix race at creating hci device

Started byMarcel Holtmann <marcel@holtmann.org>
First post2016-04-20 16:40 +0200
Last post2016-04-20 17:00 +0200
Articles 2 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: [PATCH] Bluetooth: vhci: Fix race at creating hci device Marcel Holtmann <marcel@holtmann.org> - 2016-04-20 16:40 +0200
    Re: [PATCH] Bluetooth: vhci: Fix race at creating hci device Takashi Iwai <tiwai@suse.de> - 2016-04-20 17:00 +0200

#1383450 — Re: [PATCH] Bluetooth: vhci: Fix race at creating hci device

FromMarcel Holtmann <marcel@holtmann.org>
Date2016-04-20 16:40 +0200
SubjectRe: [PATCH] Bluetooth: vhci: Fix race at creating hci device
Message-ID<rq1sn-VS-29@gated-at.bofh.it>
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: <stable@vger.kernel.org>
> Signed-off-by: Takashi Iwai <tiwai@suse.de>
> ---
> 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.

Regards

Marcel

[toc] | [next] | [standalone]


#1383471

FromTakashi Iwai <tiwai@suse.de>
Date2016-04-20 17:00 +0200
Message-ID<rq1LJ-13P-21@gated-at.bofh.it>
In reply to#1383450
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: <stable@vger.kernel.org>
> > Signed-off-by: Takashi Iwai <tiwai@suse.de>
> > ---
> > 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

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web