* [PATCH] Driver core: fix race in __device_release_driver
@ 2007-11-16 16:57 Alan Stern
2007-11-16 17:04 ` David Woodhouse
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Alan Stern @ 2007-11-16 16:57 UTC (permalink / raw)
To: Greg KH, David Woodhouse; +Cc: USB development list, Kernel development list
This patch (as1013) was suggested by David Woodhouse; it fixes a race
in the driver core. If a device is unregistered at the same time as
its driver is unloaded, the driver's code pages may be unmapped while
the remove method is still running. The calls to get_driver() and
put_driver() were intended to prevent this, but they don't work if the
driver's module count has already dropped to 0.
Instead, the patch keeps the device on the driver's list until after
the remove method has returned. This forces the necessary
synchronization to occur.
Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
CC: David Woodhouse <dwmw2@infradead.org>
---
This should be considered for 2.6.24.
Index: usb-2.6/drivers/base/dd.c
===================================================================
--- usb-2.6.orig/drivers/base/dd.c
+++ usb-2.6/drivers/base/dd.c
@@ -289,11 +289,10 @@ static void __device_release_driver(stru
{
struct device_driver * drv;
- drv = get_driver(dev->driver);
+ drv = dev->driver;
if (drv) {
driver_sysfs_remove(dev);
sysfs_remove_link(&dev->kobj, "driver");
- klist_remove(&dev->knode_driver);
if (dev->bus)
blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
@@ -306,7 +305,7 @@ static void __device_release_driver(stru
drv->remove(dev);
devres_release_all(dev);
dev->driver = NULL;
- put_driver(drv);
+ klist_remove(&dev->knode_driver);
}
}
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH] Driver core: fix race in __device_release_driver
2007-11-16 16:57 [PATCH] Driver core: fix race in __device_release_driver Alan Stern
@ 2007-11-16 17:04 ` David Woodhouse
2007-11-16 20:37 ` Greg KH
2007-11-27 7:14 ` patch driver-core-fix-race-in-__device_release_driver.patch added to gregkh-2.6 tree gregkh
2 siblings, 0 replies; 7+ messages in thread
From: David Woodhouse @ 2007-11-16 17:04 UTC (permalink / raw)
To: Alan Stern; +Cc: Greg KH, USB development list, Kernel development list
On Fri, 2007-11-16 at 11:57 -0500, Alan Stern wrote:
> This patch (as1013) was suggested by David Woodhouse; it fixes a race
> in the driver core. If a device is unregistered at the same time as
> its driver is unloaded, the driver's code pages may be unmapped while
> the remove method is still running. The calls to get_driver() and
> put_driver() were intended to prevent this, but they don't work if the
> driver's module count has already dropped to 0.
>
> Instead, the patch keeps the device on the driver's list until after
> the remove method has returned. This forces the necessary
> synchronization to occur.
>
> Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
> CC: David Woodhouse <dwmw2@infradead.org>
Since we're submitting it rather than just using it to explain the
problem, I suppose I should add:
Signed-off-by: David Woodhouse <dwmw2@infradead.org>
> ---
>
> This should be considered for 2.6.24.
>
>
> Index: usb-2.6/drivers/base/dd.c
> ===================================================================
> --- usb-2.6.orig/drivers/base/dd.c
> +++ usb-2.6/drivers/base/dd.c
> @@ -289,11 +289,10 @@ static void __device_release_driver(stru
> {
> struct device_driver * drv;
>
> - drv = get_driver(dev->driver);
> + drv = dev->driver;
> if (drv) {
> driver_sysfs_remove(dev);
> sysfs_remove_link(&dev->kobj, "driver");
> - klist_remove(&dev->knode_driver);
>
> if (dev->bus)
> blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
> @@ -306,7 +305,7 @@ static void __device_release_driver(stru
> drv->remove(dev);
> devres_release_all(dev);
> dev->driver = NULL;
> - put_driver(drv);
> + klist_remove(&dev->knode_driver);
> }
> }
>
>
--
dwmw2
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH] Driver core: fix race in __device_release_driver
2007-11-16 16:57 [PATCH] Driver core: fix race in __device_release_driver Alan Stern
2007-11-16 17:04 ` David Woodhouse
@ 2007-11-16 20:37 ` Greg KH
2007-11-16 20:45 ` David Woodhouse
2007-11-16 20:48 ` Alan Stern
2007-11-27 7:14 ` patch driver-core-fix-race-in-__device_release_driver.patch added to gregkh-2.6 tree gregkh
2 siblings, 2 replies; 7+ messages in thread
From: Greg KH @ 2007-11-16 20:37 UTC (permalink / raw)
To: Alan Stern; +Cc: David Woodhouse, USB development list, Kernel development list
On Fri, Nov 16, 2007 at 11:57:28AM -0500, Alan Stern wrote:
> This patch (as1013) was suggested by David Woodhouse; it fixes a race
> in the driver core. If a device is unregistered at the same time as
> its driver is unloaded, the driver's code pages may be unmapped while
> the remove method is still running. The calls to get_driver() and
> put_driver() were intended to prevent this, but they don't work if the
> driver's module count has already dropped to 0.
>
> Instead, the patch keeps the device on the driver's list until after
> the remove method has returned. This forces the necessary
> synchronization to occur.
Is this something that you all feel is worth getting in for 2.6.24?
Does it fix a regression that just showed up, or is just a bugfix for
something that people finally realized has always been there?
Can it wait for 2.6.25 to get some more testing in -mm?
thanks,
greg k-h
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] Driver core: fix race in __device_release_driver
2007-11-16 20:37 ` Greg KH
@ 2007-11-16 20:45 ` David Woodhouse
2007-11-16 20:56 ` Greg KH
2007-11-16 20:48 ` Alan Stern
1 sibling, 1 reply; 7+ messages in thread
From: David Woodhouse @ 2007-11-16 20:45 UTC (permalink / raw)
To: Greg KH; +Cc: Alan Stern, USB development list, Kernel development list
On Fri, 2007-11-16 at 12:37 -0800, Greg KH wrote:
> Is this something that you all feel is worth getting in for 2.6.24?
> Does it fix a regression that just showed up, or is just a bugfix for
> something that people finally realized has always been there?
The latter. We just happen to kick the wireless device in the head by
toggling its out-of-band reset signal when we unload the driver, which
causes us to trigger this "unlikely" race with almost 100% reliability.
But it's always been there, AFAICT.
> Can it wait for 2.6.25 to get some more testing in -mm?
Yeah, I think so.
--
dwmw2
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] Driver core: fix race in __device_release_driver
2007-11-16 20:45 ` David Woodhouse
@ 2007-11-16 20:56 ` Greg KH
0 siblings, 0 replies; 7+ messages in thread
From: Greg KH @ 2007-11-16 20:56 UTC (permalink / raw)
To: David Woodhouse; +Cc: Alan Stern, USB development list, Kernel development list
On Fri, Nov 16, 2007 at 03:45:55PM -0500, David Woodhouse wrote:
> On Fri, 2007-11-16 at 12:37 -0800, Greg KH wrote:
> > Is this something that you all feel is worth getting in for 2.6.24?
> > Does it fix a regression that just showed up, or is just a bugfix for
> > something that people finally realized has always been there?
>
> The latter. We just happen to kick the wireless device in the head by
> toggling its out-of-band reset signal when we unload the driver, which
> causes us to trigger this "unlikely" race with almost 100% reliability.
> But it's always been there, AFAICT.
>
> > Can it wait for 2.6.25 to get some more testing in -mm?
>
> Yeah, I think so.
Thanks for letting me know, I'll add it to the proper place in my queue.
greg k-h
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] Driver core: fix race in __device_release_driver
2007-11-16 20:37 ` Greg KH
2007-11-16 20:45 ` David Woodhouse
@ 2007-11-16 20:48 ` Alan Stern
1 sibling, 0 replies; 7+ messages in thread
From: Alan Stern @ 2007-11-16 20:48 UTC (permalink / raw)
To: Greg KH; +Cc: David Woodhouse, USB development list, Kernel development list
On Fri, 16 Nov 2007, Greg KH wrote:
> On Fri, Nov 16, 2007 at 11:57:28AM -0500, Alan Stern wrote:
> > This patch (as1013) was suggested by David Woodhouse; it fixes a race
> > in the driver core. If a device is unregistered at the same time as
> > its driver is unloaded, the driver's code pages may be unmapped while
> > the remove method is still running. The calls to get_driver() and
> > put_driver() were intended to prevent this, but they don't work if the
> > driver's module count has already dropped to 0.
> >
> > Instead, the patch keeps the device on the driver's list until after
> > the remove method has returned. This forces the necessary
> > synchronization to occur.
>
> Is this something that you all feel is worth getting in for 2.6.24?
> Does it fix a regression that just showed up, or is just a bugfix for
> something that people finally realized has always been there?
>
> Can it wait for 2.6.25 to get some more testing in -mm?
Considering how few people have been affected by it, I'm willing to
let it wait for 2.6.25. David Woodhouse may feel differently.
Alan Stern
^ permalink raw reply [flat|nested] 7+ messages in thread
* patch driver-core-fix-race-in-__device_release_driver.patch added to gregkh-2.6 tree
2007-11-16 16:57 [PATCH] Driver core: fix race in __device_release_driver Alan Stern
2007-11-16 17:04 ` David Woodhouse
2007-11-16 20:37 ` Greg KH
@ 2007-11-27 7:14 ` gregkh
2 siblings, 0 replies; 7+ messages in thread
From: gregkh @ 2007-11-27 7:14 UTC (permalink / raw)
To: stern, dwmw2, greg, gregkh, linux-kernel, linux-usb-devel
This is a note to let you know that I've just added the patch titled
Subject: Driver core: fix race in __device_release_driver
to my gregkh-2.6 tree. Its filename is
driver-core-fix-race-in-__device_release_driver.patch
This tree can be found at
http://www.kernel.org/pub/linux/kernel/people/gregkh/gregkh-2.6/patches/
>From stern@rowland.harvard.edu Mon Nov 26 22:49:20 2007
From: Alan Stern <stern@rowland.harvard.edu>
Date: Fri, 16 Nov 2007 11:57:28 -0500 (EST)
Subject: Driver core: fix race in __device_release_driver
To: Greg KH <greg@kroah.com>, David Woodhouse <dwmw2@infradead.org>
Cc: USB development list <linux-usb-devel@lists.sourceforge.net>, Kernel development list <linux-kernel@vger.kernel.org>
Message-ID: <Pine.LNX.4.44L0.0711161151340.3268-100000@iolanthe.rowland.org>
This patch (as1013) was suggested by David Woodhouse; it fixes a race
in the driver core. If a device is unregistered at the same time as
its driver is unloaded, the driver's code pages may be unmapped while
the remove method is still running. The calls to get_driver() and
put_driver() were intended to prevent this, but they don't work if the
driver's module count has already dropped to 0.
Instead, the patch keeps the device on the driver's list until after
the remove method has returned. This forces the necessary
synchronization to occur.
Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: David Woodhouse <dwmw2@infradead.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
drivers/base/dd.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
--- a/drivers/base/dd.c
+++ b/drivers/base/dd.c
@@ -289,11 +289,10 @@ static void __device_release_driver(stru
{
struct device_driver * drv;
- drv = get_driver(dev->driver);
+ drv = dev->driver;
if (drv) {
driver_sysfs_remove(dev);
sysfs_remove_link(&dev->kobj, "driver");
- klist_remove(&dev->knode_driver);
if (dev->bus)
blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
@@ -306,7 +305,7 @@ static void __device_release_driver(stru
drv->remove(dev);
devres_release_all(dev);
dev->driver = NULL;
- put_driver(drv);
+ klist_remove(&dev->knode_driver);
}
}
Patches currently in gregkh-2.6 which might be from stern@rowland.harvard.edu are
driver/pm-acquire-device-locks-prior-to-suspending.patch
driver/create-sys-...-power-when-config_pm-is-set.patch
driver/driver-core-fix-race-in-__device_release_driver.patch
usb/usb-add-support-for-an-older-firmware-revision-for-the-nikon-d200.patch
usb/usb-fix-priority-mistakes-in-drivers-usb-core-hub.c.patch
usb/usb-fix-signr-comment-in-usbdevice_fs.h.patch
usb/usb-mailing-lists-have-changed.patch
usb/usb-power-management-documenation-update.patch
usb/usb-hcd-avoid-duplicate-local_irq_disable.patch
usb/usb-usb-mon-mon_bin.c-cleanups.patch
usb/usb-keep-track-of-whether-interface-sysfs-files-exist.patch
usb/usb-uevent-environment-key-fix.patch
usb/usb-autosuspend-for-cdc-acm.patch
usb/usb-fix-up-ehci-startup-synchronization.patch
usb/usb-usb-storage-new-lockable-subclass-0x07.patch
usb/usb-don-t-change-hc-power-state-for-a-freeze.patch
usb/usb-dummy_hcd-don-t-register-drivers-on-the-platform-bus.patch
usb/usb-force-handover-port-to-companion-when-hub_port_connect_change-fails.patch
usb/usb-make-ksuspend_usbd-thread-non-freezable.patch
usb/usb-usb-storage-unusual_devs-entry-for-jetflash-ts1gjf2a.patch
usb/usb-storage-always-set-the-allow_restart-flag.patch
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2007-11-27 7:14 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-11-16 16:57 [PATCH] Driver core: fix race in __device_release_driver Alan Stern
2007-11-16 17:04 ` David Woodhouse
2007-11-16 20:37 ` Greg KH
2007-11-16 20:45 ` David Woodhouse
2007-11-16 20:56 ` Greg KH
2007-11-16 20:48 ` Alan Stern
2007-11-27 7:14 ` patch driver-core-fix-race-in-__device_release_driver.patch added to gregkh-2.6 tree gregkh
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®