On Fri, Nov 15, 2019 at 04:13:58PM +0100, Andrey Konovalov wrote: > On Fri, Nov 15, 2019 at 4:06 PM Greg Kroah-Hartman > <gregkh@xxxxxxxxxxxxxxxxxxx> wrote: > > > > On Fri, Nov 15, 2019 at 03:25:38PM +0100, Andrey Konovalov wrote: > > > Hi Greg and Alan, > > > > > > For USB fuzzing it would be nice to be able to export usb_device_id > > > structs from the kernel to facilitate the fuzzer with generating USB > > > descriptors that match to actual drivers. The same is required for > > > hid_device_id structs, since those are matched separately by the > > > usbhid driver (are there other cases like this?). > > > > > > Currently I have a hacky patch [1] that walks all drivers for USB and > > > HID buses and then prints all device ids for those drivers into the > > > kernel log. Those are manually parsed and built into the fuzzer [2] > > > and then used to generate USB descriptors [3]. > > > > The kernel will spit out all device ids of all USB devices when found if > > you have CONFIG_USB_ANNOUNCE_NEW_DEVICES enabled, if you want to parse > > the log. > > > > Otherwise, just walk usbfs or sysfs and get the ids there. If you use > > libusb you can do this with just a few lines of code, or worst case, > > just implement the same thing on your own (like lsusb used to do). > > Heck, just copy what lsusb does, or again worst case, parse the output > > of it. > > > > There's also 'lsusb.py' as part of usbutils that shows how to do this > > from within python in userspace, and if you really want it, we also > > export the whole raw usb descriptor is in sysfs as well, if you want to > > not trust how the kernel parses it. > > > > hope this helps, > > Either I misunderstand you or you misunderstood me. I don't want to > see IDs of devices that are connected. I want to see all of the IDs > for all of the devices that might be connected and bound to some > driver at some point in the future. Essentially I want to all IDs that > are passed to MODULE_DEVICE_TABLE(usb, ...) and > MODULE_DEVICE_TABLE(hid, ...). Is it possible to obtain those via > usbfs/sysfs? Ah, no, that information is not directly there in sysfs, sorry. But it is in the modules themselves, look at the output of 'modinfo' at the "alias:" lines for "usb:" entries. That is what modprobe uses to find out what module to load when a USB device is reported by the system. Same thing goes for any type of device bus. hope this helps, greg k-h