USB Raw Gadget, a module for the Kernel that allows emulating USB devices

USB Raw Gadget

Already on some occasions here in the blog we have talked about the work done by Andrey Konovalov (a Google developer) in Linux, from his work in the timely detection of failures in the USB drivers of the Linux Kernel and also in Wifi devices.

Now he is currently working on the development of a new module for the Linux Kernel which he has named as "USB Raw Gadget" which describes as a utility that allows emulating USB devices in user space.

Besides that mentions that an application is being considered for the inclusion of this module in the main Linux kernel. Google Raw Gadget is already being used by Google to simplify fuzzy testing of the USB kernel stack with the syzkaller toolkit.

Initially I was using GadgetFS (along with the Dummy HCD / UDC module) to emulate USB devices for fuzzing, but then it was switched to a custom written interface.

The incentive for implementing a different interface was to provide direct and somewhat raw access to the USB Gadget layer for user space, where each USB request is passed to user space for a response.

About USB Raw Gadget

The module takes care of adding a new interface programming to the kernel subsystem called "USB Gadget" and which is being developed as an alternative to GadgetFS.

The creation of a new API is due to the need for direct and low-level access to the Gadget USB subsystem from user space, allowing all possible USB requests to be processed (GadgetFS processes some requests on its own, without transferring it to user space).

USB Raw Gadget is controlled via the / dev / raw-gadget device by analogy with / dev / gadget in GadgetFS, but an ioctl () based interface, instead of a pseudo-FS, is used for the interaction.

In addition to direct processing of all USB requests by a process in user space, the new interface also has the ability to return any data in response to a USB request (GadgetFS checks the correctness of USB descriptors and filters out certain responses, which interferes with error detection during the USB stack clearing test).

USB Raw Gadget also allows you to select a specific UDC device (USB device driver) and a driver to connect, while GadgetFS connects to the first available UDC device.

For different UDCs, predictable endpoint names are mapped to different types of separate communication channels within a single device.

Finally, if you want to know more about it, you can check the details, as well as the log of the changes made in USB Raw Gadget In the following link.

How to install the Raw Gadget USB module in Linux?

For those who are interested in being able to test this module on their system, they can do so by following the instructions detailed here.

For Dummy HCD / UDC (a module that configures virtual USB devices and host controllers that are connected to each other within the kernel). We must open a terminal and in it we are going to type the following command:

svn checkout https://github.com/xairy/raw-gadget/trunk/dummy_hcd

With this we are going to obtain the folder with the modules which we are going to compile by executing the following command in the terminal:

cd dummy_hcd

make

And we proceed to install them with:

./insmod.sh

If we want to update the module, we do it with:

./update.sh

Now for those who want to install the kernel module. In a terminal we are going to obtain the necessary files for this by executing the following command:

svn checkout https://github.com/xairy/raw-gadget/trunk/raw_gadget

With this we are going to obtain the folder with the modules which we are going to compile by executing the following command in the terminal:

cd dummy_hcd

make

And we proceed to install them with:

./insmod.sh

If we want to update the module, we do it with:

./update.sh

You can check the work in the following link. 


Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: AB Internet Networks 2008 SL
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.