简体   繁体   中英

Can't read usb string descriptor with libusb because of permissions

I just can't do a simple thing as read a string descriptor. Here's the simple code with pyusb wrapper(just for simplicity of code) but the problem remains even with le libsub original library.

import usb.core
import usb.util
devs = usb.core.find(find_all=True)
for dev in devs:
    try:
        print usb.util.get_string(dev, 255, dev.iManufacturer)
    except usb.core.USBError:
        pass

If I execute this without root permissions i get nothing(all loop iteration raise an exception). If I execute with root permissions I get some string descriptor and some exception. In this case I know the exception is normal because the pipe error means the device does not provide any string descriptor.

The question is: how can I get the string descriptors without the root permissions? The command lsusb retrieves all the informations and it does it without the suid bit enabled.

I encountered that problem as well. It seems that pyusb by default opens devices read-write, while lsusb opens them read-only, as can be seen in this $ strace lsusb extract:

...
open("/sys/devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1:1.0/uevent", O_RDONLY|O_CLOEXEC) = 6
...

I solved the problem by making all usb devices world-read/writable, but that's definitely not optimal from a security standpoint (keyloggers, etc)...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM