Hi,

On 07/28/2012 06:33 PM, Peter Stuge wrote:
> Hans de Goede wrote:
>> This patch fixes libusb_detach_kernel_driver to only detach "real"
>> kernel drivers and not the special usbfs driver
>
> Ignoring the race for now?

Yes, the race is mostly theoretical thing, where as one libusb app
stealing the device from another is very much a real issue, it is for example
the root cause of:
https://bugzilla.redhat.com/show_bug.cgi?id=820205

> What's the situation of kernel support to
> make the operations race free?

Quoting from:
http://marc.info/?l=libusb-devel&m=128655552910330&w=2

"I agree that it makes sense for libusb to be aware of a device's current 
driver before trying to detach it. It might also be desirable to avoid ever 
detaching the usbfs driver -- however this is a matter to be settled by the 
designers and users of libusb. It should not be enforced by the kernel.

Certainly libusb-0.1's ability to report the name of the current driver 
shouldn't be given up in libusb-1.0. That's a backward step.

Alan Stern"

So Alan believes, and I agree, that the policy of handling the detaching
of usbfs in a special way is a userspace decision. Note that we've 2
racy things here btw:

1) Testing if a driver is bound and then doing a detach

This can be fixed (in apps) by simply doing the unbind always and ignore the
ERROR_NOT_FOUND return

2) Testing if the driver is usbfs, and if it is not then unbind the kernel
driver (which my patch does / adds).

This is racy too and cannot simply be fixed. The only solution I can come
up with is adding a "USBDEVFS_NO_USBFS_DISCONNECT" flag with a value of
0x80000000 which can be or-ed together with the interface number passed
to the USBDEVFS_DISCONNECT ioctl to make it not unbind the usbfs driver
in a non racy way. Combined with a new capability flag for this (I assume
you've seen my capability patches).

I must say I find this kind of ugly though, if people think this is a good
idea, I'll try to push it upstream, but I believe the race window is so small,
it is not really an issue.

Regards,

Hans

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
libusbx-devel mailing list
libusbx-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libusbx-devel

Reply via email to