* [patch 3/3] hci_usb.h: fix hard-to-trigger race
@ 2008-04-18 20:46 akpm
2008-04-18 21:10 ` Marcel Holtmann
0 siblings, 1 reply; 8+ messages in thread
From: akpm @ 2008-04-18 20:46 UTC (permalink / raw)
To: marcel; +Cc: hidave.darkstar, linux-bluetooth, netdev, akpm, pavel, pavel
From: Pavel Machek <pavel@ucw.cz>
If someone tries to _urb_unlink while _urb_queue_head is running, he'll see
_urb->queue == NULL and fail to do any locking. Prevent that from happening
by strategically placed barriers.
Signed-off-by: Pavel Machek <pavel@suse.cz>
Cc: Marcel Holtmann <marcel@holtmann.org>
Cc: Dave Young <hidave.darkstar@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---
drivers/bluetooth/hci_usb.h | 21 +++++++++++++--------
1 file changed, 13 insertions(+), 8 deletions(-)
diff -puN drivers/bluetooth/hci_usb.h~hci_usbh-fix-hard-to-trigger-race drivers/bluetooth/hci_usb.h
--- a/drivers/bluetooth/hci_usb.h~hci_usbh-fix-hard-to-trigger-race
+++ a/drivers/bluetooth/hci_usb.h
@@ -70,7 +70,8 @@ static inline void _urb_queue_head(struc
{
unsigned long flags;
spin_lock_irqsave(&q->lock, flags);
- list_add(&_urb->list, &q->head); _urb->queue = q;
+ /* _urb_unlink needs to know which spinlock to use, thus mb(). */
+ _urb->queue = q; mb(); list_add(&_urb->list, &q->head);
spin_unlock_irqrestore(&q->lock, flags);
}
@@ -78,19 +79,23 @@ static inline void _urb_queue_tail(struc
{
unsigned long flags;
spin_lock_irqsave(&q->lock, flags);
- list_add_tail(&_urb->list, &q->head); _urb->queue = q;
+ /* _urb_unlink needs to know which spinlock to use, thus mb(). */
+ _urb->queue = q; mb(); list_add_tail(&_urb->list, &q->head);
spin_unlock_irqrestore(&q->lock, flags);
}
static inline void _urb_unlink(struct _urb *_urb)
{
- struct _urb_queue *q = _urb->queue;
+ struct _urb_queue *q;
unsigned long flags;
- if (q) {
- spin_lock_irqsave(&q->lock, flags);
- list_del(&_urb->list); _urb->queue = NULL;
- spin_unlock_irqrestore(&q->lock, flags);
- }
+
+ mb();
+ q = _urb->queue;
+ /* If q is NULL, it will die at easy-to-debug NULL pointer dereference.
+ No need to BUG(). */
+ spin_lock_irqsave(&q->lock, flags);
+ list_del(&_urb->list); _urb->queue = NULL;
+ spin_unlock_irqrestore(&q->lock, flags);
}
struct hci_usb {
_
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [patch 3/3] hci_usb.h: fix hard-to-trigger race 2008-04-18 20:46 [patch 3/3] hci_usb.h: fix hard-to-trigger race akpm @ 2008-04-18 21:10 ` Marcel Holtmann [not found] ` <55DEC459-2D49-4366-88CC-21E9CA6783DC-kz+m5ild9QBg9hUCZPvPmw@public.gmane.org> 0 siblings, 1 reply; 8+ messages in thread From: Marcel Holtmann @ 2008-04-18 21:10 UTC (permalink / raw) To: akpm; +Cc: hidave.darkstar, linux-bluetooth, netdev, pavel, pavel Hi Andrew, > From: Pavel Machek <pavel@ucw.cz> > > If someone tries to _urb_unlink while _urb_queue_head is running, > he'll see > _urb->queue == NULL and fail to do any locking. Prevent that from > happening > by strategically placed barriers. let me repeat this, the hci_usb driver is not worth fixing. Doing our own URB handling is a bad idea. The btusb driver should fix all of this. Only exception is that it is missing all the quirks, but that was me being lazy. Regards Marcel ^ permalink raw reply [flat|nested] 8+ messages in thread
[parent not found: <55DEC459-2D49-4366-88CC-21E9CA6783DC-kz+m5ild9QBg9hUCZPvPmw@public.gmane.org>]
* Re: [patch 3/3] hci_usb.h: fix hard-to-trigger race [not found] ` <55DEC459-2D49-4366-88CC-21E9CA6783DC-kz+m5ild9QBg9hUCZPvPmw@public.gmane.org> @ 2008-04-18 21:21 ` Andrew Morton [not found] ` <20080418142153.4e0eb83b.akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org> 2008-04-19 1:25 ` Marcel Holtmann 0 siblings, 2 replies; 8+ messages in thread From: Andrew Morton @ 2008-04-18 21:21 UTC (permalink / raw) To: Marcel Holtmann Cc: hidave.darkstar-Re5JQEeQqe8AvxtiuMwx3w, linux-bluetooth-u79uwXL29TY76Z2rM5mHXA, netdev-u79uwXL29TY76Z2rM5mHXA, pavel-+ZI9xUNit7I, pavel-AlSwsSmVLrQ On Fri, 18 Apr 2008 23:10:12 +0200 Marcel Holtmann <marcel-kz+m5ild9QBg9hUCZPvPmw@public.gmane.org> wrote: > Hi Andrew, > > > From: Pavel Machek <pavel-+ZI9xUNit7I@public.gmane.org> > > > > If someone tries to _urb_unlink while _urb_queue_head is running, > > he'll see > > _urb->queue == NULL and fail to do any locking. Prevent that from > > happening > > by strategically placed barriers. > > let me repeat this, the hci_usb driver is not worth fixing. Doing our > own URB handling is a bad idea. The btusb driver should fix all of > this. Only exception is that it is missing all the quirks, but that > was me being lazy. > ok... But as long as the old code is buildable and installable, we should fix bugs in it? ^ permalink raw reply [flat|nested] 8+ messages in thread
[parent not found: <20080418142153.4e0eb83b.akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org>]
* Re: [patch 3/3] hci_usb.h: fix hard-to-trigger race [not found] ` <20080418142153.4e0eb83b.akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org> @ 2008-04-18 22:41 ` David Miller 0 siblings, 0 replies; 8+ messages in thread From: David Miller @ 2008-04-18 22:41 UTC (permalink / raw) To: akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b Cc: marcel-kz+m5ild9QBg9hUCZPvPmw, hidave.darkstar-Re5JQEeQqe8AvxtiuMwx3w, linux-bluetooth-u79uwXL29TY76Z2rM5mHXA, netdev-u79uwXL29TY76Z2rM5mHXA, pavel-+ZI9xUNit7I, pavel-AlSwsSmVLrQ From: Andrew Morton <akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org> Date: Fri, 18 Apr 2008 14:21:53 -0700 > On Fri, 18 Apr 2008 23:10:12 +0200 > Marcel Holtmann <marcel-kz+m5ild9QBg9hUCZPvPmw@public.gmane.org> wrote: > > > Hi Andrew, > > > > > From: Pavel Machek <pavel-+ZI9xUNit7I@public.gmane.org> > > > > > > If someone tries to _urb_unlink while _urb_queue_head is running, > > > he'll see > > > _urb->queue == NULL and fail to do any locking. Prevent that from > > > happening > > > by strategically placed barriers. > > > > let me repeat this, the hci_usb driver is not worth fixing. Doing our > > own URB handling is a bad idea. The btusb driver should fix all of > > this. Only exception is that it is missing all the quirks, but that > > was me being lazy. > > > > ok... But as long as the old code is buildable and installable, we should > fix bugs in it? Yep. ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [patch 3/3] hci_usb.h: fix hard-to-trigger race 2008-04-18 21:21 ` Andrew Morton [not found] ` <20080418142153.4e0eb83b.akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org> @ 2008-04-19 1:25 ` Marcel Holtmann 2008-04-19 16:49 ` [patch] document hci_usb as broken Pavel Machek 1 sibling, 1 reply; 8+ messages in thread From: Marcel Holtmann @ 2008-04-19 1:25 UTC (permalink / raw) To: Andrew Morton; +Cc: hidave.darkstar, linux-bluetooth, netdev, pavel, pavel Hi Andrew, >>> If someone tries to _urb_unlink while _urb_queue_head is running, >>> he'll see >>> _urb->queue == NULL and fail to do any locking. Prevent that from >>> happening >>> by strategically placed barriers. >> >> let me repeat this, the hci_usb driver is not worth fixing. Doing our >> own URB handling is a bad idea. The btusb driver should fix all of >> this. Only exception is that it is missing all the quirks, but that >> was me being lazy. >> > > ok... But as long as the old code is buildable and installable, we > should > fix bugs in it? I am okay with it and happy to accept any fixes, but to be quite honest, that this driver still works is in some cases pure luck. Doing the URB handling by ourself is really simply plain work. No excuses here and parts of it is my fault. I know that. Hence I started a new implementation from scratch. Regards Marcel ^ permalink raw reply [flat|nested] 8+ messages in thread
* [patch] document hci_usb as broken 2008-04-19 1:25 ` Marcel Holtmann @ 2008-04-19 16:49 ` Pavel Machek 2008-04-19 17:40 ` Marcel Holtmann 0 siblings, 1 reply; 8+ messages in thread From: Pavel Machek @ 2008-04-19 16:49 UTC (permalink / raw) To: Marcel Holtmann; +Cc: Andrew Morton, hidave.darkstar, linux-bluetooth, netdev Hi! >> ok... But as long as the old code is buildable and installable, we should >> fix bugs in it? > > I am okay with it and happy to accept any fixes, but to be quite honest, > that this driver still works is in some cases pure luck. Doing the URB > handling by ourself is really simply plain work. No excuses here and parts > of it is my fault. I know that. Hence I started a new implementation from > scratch. Ok, so I guess this is good idea... (I'd prefer previous race patch to still be applied; but driver is broken even with that fix...) I thought about adding && BROKEN to Kconfig... --- hci_usb is fatally broken, document it as such. Signed-off-by: Pavel Machek <pavel@suse.cz> diff --git a/drivers/bluetooth/Kconfig b/drivers/bluetooth/Kconfig index 075598e..20d9279 100644 --- a/drivers/bluetooth/Kconfig +++ b/drivers/bluetooth/Kconfig @@ -3,13 +3,16 @@ menu "Bluetooth device drivers" depends on BT config BT_HCIUSB - tristate "HCI USB driver" + tristate "HCI USB driver (dangerous, use alternate driver below)" depends on USB help Bluetooth HCI USB driver. This driver is required if you want to use Bluetooth devices with USB interface. + Unfortunately, locking in this driver is fatally broken; it will + corrupt memory on surprise disconnect and during resume. + Say Y here to compile support for Bluetooth USB devices into the kernel or say M to compile it as module (hci_usb). diff --git a/drivers/bluetooth/hci_usb.c b/drivers/bluetooth/hci_usb.c index 192522e..6cc96b4 100644 --- a/drivers/bluetooth/hci_usb.c +++ b/drivers/bluetooth/hci_usb.c @@ -1,8 +1,22 @@ -/* +/* + + This driver has fatally broken locking. + + DO NOT USE. + + See btusb.c for cleaner / shorter / actually working driver. + + + + + + + + + HCI USB driver for Linux Bluetooth protocol stack (BlueZ) Copyright (C) 2000-2001 Qualcomm Incorporated Written 2000,2001 by Maxim Krasnyansky <maxk@qualcomm.com> - Copyright (C) 2003 Maxim Krasnyansky <maxk@qualcomm.com> This program is free software; you can redistribute it and/or modify -- (english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [patch] document hci_usb as broken 2008-04-19 16:49 ` [patch] document hci_usb as broken Pavel Machek @ 2008-04-19 17:40 ` Marcel Holtmann 2008-04-19 17:57 ` Pavel Machek 0 siblings, 1 reply; 8+ messages in thread From: Marcel Holtmann @ 2008-04-19 17:40 UTC (permalink / raw) To: Pavel Machek; +Cc: Andrew Morton, hidave.darkstar, linux-bluetooth, netdev Hi Pavel, >>> ok... But as long as the old code is buildable and installable, >>> we should >>> fix bugs in it? >> >> I am okay with it and happy to accept any fixes, but to be quite >> honest, >> that this driver still works is in some cases pure luck. Doing the >> URB >> handling by ourself is really simply plain work. No excuses here >> and parts >> of it is my fault. I know that. Hence I started a new >> implementation from >> scratch. > > Ok, so I guess this is good idea... (I'd prefer previous race patch to > still be applied; but driver is broken even with that fix...) > > I thought about adding && BROKEN to Kconfig... > > --- > > hci_usb is fatally broken, document it as such. > > Signed-off-by: Pavel Machek <pavel@suse.cz> > > diff --git a/drivers/bluetooth/Kconfig b/drivers/bluetooth/Kconfig > index 075598e..20d9279 100644 > --- a/drivers/bluetooth/Kconfig > +++ b/drivers/bluetooth/Kconfig > @@ -3,13 +3,16 @@ menu "Bluetooth device drivers" > depends on BT > > config BT_HCIUSB > - tristate "HCI USB driver" > + tristate "HCI USB driver (dangerous, use alternate driver below)" > depends on USB > help > Bluetooth HCI USB driver. > This driver is required if you want to use Bluetooth devices with > USB interface. > > + Unfortunately, locking in this driver is fatally broken; it will > + corrupt memory on surprise disconnect and during resume. > + > Say Y here to compile support for Bluetooth USB devices into the > kernel or say M to compile it as module (hci_usb). this would be fine with me. Acked-by: Marcel Holtmann <marcel@holtmann.org > > diff --git a/drivers/bluetooth/hci_usb.c b/drivers/bluetooth/hci_usb.c > index 192522e..6cc96b4 100644 > --- a/drivers/bluetooth/hci_usb.c > +++ b/drivers/bluetooth/hci_usb.c > @@ -1,8 +1,22 @@ > -/* > +/* > + > + This driver has fatally broken locking. > + > + DO NOT USE. > + > + See btusb.c for cleaner / shorter / actually working driver. NAK to this hunk. Not needed. The Kconfig help is enough. Regards Marcel ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [patch] document hci_usb as broken 2008-04-19 17:40 ` Marcel Holtmann @ 2008-04-19 17:57 ` Pavel Machek 0 siblings, 0 replies; 8+ messages in thread From: Pavel Machek @ 2008-04-19 17:57 UTC (permalink / raw) To: Marcel Holtmann; +Cc: Andrew Morton, hidave.darkstar, linux-bluetooth, netdev Hi! >> index 075598e..20d9279 100644 >> --- a/drivers/bluetooth/Kconfig >> +++ b/drivers/bluetooth/Kconfig >> @@ -3,13 +3,16 @@ menu "Bluetooth device drivers" >> depends on BT >> >> config BT_HCIUSB >> - tristate "HCI USB driver" >> + tristate "HCI USB driver (dangerous, use alternate driver below)" >> depends on USB >> help >> Bluetooth HCI USB driver. >> This driver is required if you want to use Bluetooth devices with >> USB interface. >> >> + Unfortunately, locking in this driver is fatally broken; it will >> + corrupt memory on surprise disconnect and during resume. >> + >> Say Y here to compile support for Bluetooth USB devices into the >> kernel or say M to compile it as module (hci_usb). > > this would be fine with me. Acked-by: Marcel Holtmann <marcel@holtmann.org> > >> diff --git a/drivers/bluetooth/hci_usb.c b/drivers/bluetooth/hci_usb.c >> index 192522e..6cc96b4 100644 >> --- a/drivers/bluetooth/hci_usb.c >> +++ b/drivers/bluetooth/hci_usb.c >> @@ -1,8 +1,22 @@ >> -/* >> +/* >> + >> + This driver has fatally broken locking. >> + >> + DO NOT USE. >> + >> + See btusb.c for cleaner / shorter / actually working driver. > > NAK to this hunk. Not needed. The Kconfig help is enough. Developers trying to debug hci_usb problems will nor see the help text, since they probably have it enabled in their .config already and will not be asked again... Pavel -- (english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2008-04-19 17:56 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-04-18 20:46 [patch 3/3] hci_usb.h: fix hard-to-trigger race akpm
2008-04-18 21:10 ` Marcel Holtmann
[not found] ` <55DEC459-2D49-4366-88CC-21E9CA6783DC-kz+m5ild9QBg9hUCZPvPmw@public.gmane.org>
2008-04-18 21:21 ` Andrew Morton
[not found] ` <20080418142153.4e0eb83b.akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org>
2008-04-18 22:41 ` David Miller
2008-04-19 1:25 ` Marcel Holtmann
2008-04-19 16:49 ` [patch] document hci_usb as broken Pavel Machek
2008-04-19 17:40 ` Marcel Holtmann
2008-04-19 17:57 ` Pavel Machek
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).