mirror of
https://github.com/utmapp/libusb.git
synced 2026-12-01 07:43:16 -10:00
fix/reenumerate-2
When one process has two contexts to libusb, it may trigger a reenumeration while the other context accesses `*dpriv->device`. Adding a mutex to access `device` can be costly because it is used in every function. Instead, we maintain an invariant: the `darwin_cached_device` must be valid at all times. In particular, this means the fields `device` and `service` must not be stale or we will have a use after free triggerable through a race condition. Previously, in `darwin_devices_detached` during reenumeration, it was possible for `old_device->device` to be freed. We now defer this free to `darwin_get_cached_device` after a new `device` is written. Note that the order is important because we do not have locks, so we must free the old device after writing the new one. The same point applies to `service` which we take care to free after the new `service` is written. A caveat here is that even if we do not crash it is still possible for one context to be using an outdated `device` and `service` leading to an error return. This should be acceptable because it would be a similar situation to the device being detached during an API call.
libusb
libusb is a library for USB device access from Linux, macOS, Windows, OpenBSD/NetBSD, Haiku, Solaris userspace, and WebAssembly via WebUSB. It is written in C (Haiku backend in C++) and licensed under the GNU Lesser General Public License version 2.1 or, at your option, any later version (see COPYING).
libusb is abstracted internally in such a way that it can hopefully be ported to other operating systems. Please see the PORTING file for more information.
libusb homepage: https://libusb.info/
Developers will wish to consult the API documentation: http://api.libusb.info
Use the mailing list for questions, comments, etc: http://mailing-list.libusb.info
- Hans de Goede [email protected]
- Xiaofan Chen [email protected]
- Ludovic Rousseau [email protected]
- Nathan Hjelm [email protected]
- Chris Dickens [email protected]
(Please use the mailing list rather than mailing developers directly)
Description
A cross-platform library to access USB devices
6.1 MiB
0 Stars
1 Watchers
0 Forks
Languages
C
94%
C++
3%
M4
1.3%
Makefile
1.1%
Shell
0.6%