public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Use of usb_find_interface in open is racy
@ 2009-11-17 21:06 Russ Dill
  2009-11-18 10:41 ` Jiri Kosina
  0 siblings, 1 reply; 12+ messages in thread
From: Russ Dill @ 2009-11-17 21:06 UTC (permalink / raw)
  To: linux-kernel

Many usb drivers that create character devices use "struct
usb_class_driver", a set of fops, and a usb_find_interface in their
open call. A prime example is drivers/usb/usb-skeleton.c. A race
occurs when userspace receives a hotplug event for the addition for
the interface and then opens the associated device file before the
device is added to the driver's klist_devices.

The usb core senses a new usb device (usb_new_device) and calls
device_add. This eventually gets down to really_probe and the
usb-skeleton probe function, skel_probe. skel_probe calls
usb_register_dev() which registers the associated character device for
skel_class. The hotplug events for the class device get emitted.

User space receives the hotplug event for the class device, makes the
device node and notifies another program that opens the device node.
The program opens the device node which calls into usb_open and then
skel_open. skel_open calls usb_find_interface. usb_find_interfaces
searches the klist_devices of skel_driver, finds no device associated
with the minor number and returns NULL. skel_open returns -ENODEV.

Control returns to really_probe and really_probe calls driver_bound
which adds the device to the list of devices associated with
skel_driver (klist_devices).

I'm not sure what the right way to solve this is. A call to
wait_for_device_probe() in the skel_open call before calling
usb_find_interface fixes the problem, but it is a rather large hammer.

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2009-11-18 18:19 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-11-17 21:06 Use of usb_find_interface in open is racy Russ Dill
2009-11-18 10:41 ` Jiri Kosina
2009-11-18 14:27   ` Oliver Neukum
2009-11-18 15:35     ` Alan Stern
2009-11-18 16:58       ` Russ Dill
2009-11-18 16:51     ` Russ Dill
2009-11-18 15:31   ` Alan Stern
2009-11-18 15:39     ` Greg KH
2009-11-18 17:01       ` Russ Dill
2009-11-18 18:02       ` [PATCH] Close usb_find_interface race Russ Dill
2009-11-18 18:16         ` Greg KH
2009-11-18 16:57     ` Use of usb_find_interface in open is racy Russ Dill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox