On Tue, Aug 23, 2016 at 3:02 PM, Jay Aurabind wrote: > On 23 August 2016 at 16:40, Tormod Volden wrote: >> It usually shouldn't try to retrieve descriptor strings from other >> devices than the ones targeted. The device descriptor (retrieved and >> cached by the OS) is usually enough to filter out the right devices >> (e.g. filtering on vid/pid). How are the devices filtered in your >> program? > > Here is the code which creates the error: > > all_devices = usb.core.find(find_all=True) > > if not all_devices: > logging.debug("No device connected") > return [] > > boards = [] > > # iterate on all devices found > for board in all_devices: > interface_number = -1 > try: > # The product string is read over USB when accessed. > # This can cause an exception to be thrown if the device > # is malfunctioning. > product = board.product > > This is how pyusb is used. The program doesn't go beyond the last line > shown above, if run as normal user. See full source github[1].
There is a grave mismatch between comment and code here: # find all devices matching the vid/pid specified all_devices = usb.core.find(find_all=True) There is nothing in the code that filters on vid/pid. usb.core.find(find_all=True) will return all devices the OS know of. Then the code goes on to request the product string from all these devices... It can be expected that this goes wrong on devices for which the user has no permissions. > > [1]:https://github.com/mbedmicro/pyOCD/blob/master/pyOCD/pyDAPAccess/interface/pyusb_backend.py#L88 > >> >>>> Some devices can be released from the kernel, and then be available >>>> for you to manipulate it through the device node (and thus via e.g >>>> libusb and pyusb). See for instance the libusb_detach_kernel_driver() >>>> function in libusb. However, in most cases people use libusb and pyusb >>>> to access devices that have no kernel driver. >>> >>> In that case, even the root should not be able to write to those >>> devices, since its exclusively managed by kernel. Then how come I get >>> no errors when I run pyocd with root permissions ? >> >> You won't be able to claim any of its interfaces, but I suppose some >> control transfers are still allowed. The pyocd code actually goes on to detach any kernel driver (line 111). This might succeed if it is run by root (or user with sufficient permissions). Tormod ------------------------------------------------------------------------------ _______________________________________________ pyusb-users mailing list pyusb-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/pyusb-users