Ticket #125 (new enhancement)

Opened 5 years ago

Last modified 4 years ago

libusb_kernel_driver_active() and _detach() are racy

Reported by: stuge Owned by:
Milestone: Component: libusb-1.1
Keywords: Cc:
Blocked By: Blocks:

Description

If the functionality is to be kept in the next API then let's do something that isn't racy.

Change History

comment:1 Changed 5 years ago by xiaofan

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

Alan Stern thinks that this is not possible to fix without changing the Linux kernel usbfs driver.

His view is quoted here.
"I don't think so. At the very least, it would be necessary to change
the USBDEVFS_DISCONNECT ioctl to make it avoid doing anything if the
current driver is usbfs. A better approach would be to allow the user
to specify a driver name, and have USBDEVFS_DISCONNECT do nothing if
the current driver isn't the one specified."

comment:3 in reply to: ↑ 2 Changed 4 years ago by hansdegoede

Hi,

Replying to hjelmn:

Does Hans's commit found @ https://github.com/hjelmn/libusb-darwin/commit/774cfa0405fe646436eab3b846ece171d1ab8eae fix the race?

No that does not fix it I'm afraid. Alan is correct in stating that fixing this race needs a kernel change. Which is why I've written a kernel patch to allow to do these things in a race free manner, see:
http://permalink.gmane.org/gmane.linux.usb.general/69725

This patch is upstream now, but libusb still needs to be modified to use it. This requires adding a new API for this, as the old API is inherently racy.

I've this on my todo list. I hope to be able to work on this soonish.

Regards,

Hans

Note: See TracTickets for help on using tickets.