lsusb: return on short bLength in the class-specific descriptor dispatchers
The audio/video/MIDI/DFU class-specific descriptor dump entry points all
share a "warn but fall through" pattern on a too-short bLength:
if (buf[1] != USB_DT_CS_INTERFACE)
printf(" Warning: Invalid descriptor\n");
else if (buf[0] < 3)
printf(" Warning: Descriptor too short\n");
... desc_dump(dev, table, buf + 3, buf[0] - 3, indent);
so a bLength of 2 underflows buf[0]-3 to UINT_MAX as the buf_len handed
to desc_dump() (or dump_bytes() in the unknown-subtype tails), defeating
every per-field bounds check in the engine. The "else" makes it worse:
the caller's switch on bDescriptorType falls CS_DEVICE through to
CS_INTERFACE, so a buf[1]==0x21 takes the "Invalid descriptor" arm and
skips the length check entirely.
Make every dispatcher's short-descriptor check independent of the type
check and return after the warning. Covers dump_audiocontrol_interface,
dump_audiostreaming_interface, dump_audiostreaming_endpoint (which had
no length check at all), dump_midistreaming_interface/_endpoint,
dump_videocontrol_interface, dump_videocontrol_interrupt_endpoint,
dump_videostreaming_interface, dump_dfu_interface, and
dump_comm_descriptor (which opened with switch(buf[2]) before any length
check at all, so a 2-byte CDC descriptor read the subtype byte one past
libusb's extra[] allocation).
Assisted-by: gkh_clanker_t1000
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This is a collection of USB tools for use on Linux and BSD systems to query what type of USB devices are connected to the system. This is to be run on a USB host (i.e. a machine you plug USB devices into), not on a USB device (i.e. a device you plug into a USB host.)
Note, usbutils depends on libusb and libudev, be sure that libraries are properly installed first.
To work with the “raw” repo, after cloning it just do:
./autogen.sh
which will build everything and place the binaries into the build/ subdirectory.
usbutils uses meson to build, so if you wish to just build by hand you can do:
meson setup build cd build/ meson compile
The source for usbutils can be found in many places, depending on the git hosting site you prefer. Here are the primary locations, in order of preference by the maintainer:
https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usbutils.git/ https://git.sr.ht/~gregkh/usbutils https://github.com/gregkh/usbutils
If you have patches or suggestions, you can submit them either via email to the maintainer or to the linux-usb mailing list or via a pull request.
Please note that commits must include a Signed-off-by trailer, indicating that you comply with the Developer Certificate of Origin v1.1.
In addition, when adding new files or contributing to existing ones, ensure that the SPDX tags SPDX-FileCopyrightText and SPDX-License-Identifier are available and are kept up-to date. You can learn more and do that via reuse-tool.