What the review read and ran
An appendix to the milestone.
The crate
partsfoundry/universal_serial_bus at 4612f6b5e5ef739fa1ad6f14b3ca182cca0d1fd5, version 0.1.0,
publish = false. Read: Cargo.toml, README.md, CHANGELOG.md, docs/stranger-test.md and
every module under src/ (descriptor, request, boot_keyboard and verification), and the
two fuzz targets by name.
The commands
Run on a Linux x86_64 host, an Intel Xeon Platinum 8160, in an exported copy of the repository.
cargo testpasses: 31 unit tests and 2 doctests.cargo build --lib --target x86_64-unknown-nonepasses.cargo +1.85 buildpasses, the declared minimum Rust version.RUSTDOCFLAGS="-D missing_docs" cargo doc --no-depspasses.cargo clippy --all-targetsprints no warning.cargo package --list --allow-dirtylistsCODEOWNERS,_typos.toml,deny.toml,rustfmt.toml,docs/stranger-test.mdand fivefalsifications/*.patchfiles besidesrc/(P1-4).grep -c 'kani::proof' src/verification.rsprints 5.grep -n '# Errors' src/*.rsprints nothing (P1-2).
The benchmark
A scratch binary depending on this crate by path and on nusb =0.2.9, built with
cargo run --release under rustc 1.100.0. Each figure is the best of seven runs of ten million
calls, after a warm-up of one million, with inputs and outputs passed through
std::hint::black_box.
- The configuration, 94 bytes: the header (three interfaces) and interface 0 as mass storage with two bulk endpoints. Interface 1 is a vendor interface with a 5-byte class descriptor and alternate settings 0 and 1, one interrupt endpoint each. Interface 2 is a boot keyboard with its 9-byte HID descriptor and endpoint 0x84, 8 bytes, interval 10. Both walks return interface 2, endpoint 0x84, 8 bytes, which the bench asserts before timing.
- The
nusbwalk:ConfigurationDescriptor::new, theninterface_alt_settings()filtered to alternate setting 0 and the class triple (3, 1, 1), thenendpoints()to the first interruptINendpoint of at least 8 bytes. - The reports: modifiers 0x02 and keys 0x04, 0x05, 0x06, then modifiers 0x20 and keys 0x05, 0x07, 0x08, 0x09; seven events, which both versions count before timing.
- The Linux port: the modifier loop and the six-slot loop of
usb_kbd_irqindrivers/hid/usbhid/usbkbd.c, written over two byte arrays for timing only and not kept.
| what | ns per call |
|---|---|
find_boot_keyboard |
41.6 |
nusb 0.2.9 walk |
75.5 |
two BootReport::parse and changes |
40.4 |
| the Linux loop, ported | 19.0 |
The comparators read
Each .crate from crates.io at the version in the prior-art table, unpacked and read.
crab-usb0.12.1: a host stack with xHCI, EHCI and DWC2 back ends behind async device and interface types. It needsalloc, takes 17 dependencies with one more optional, gets its descriptor types fromusb-if, and has no HID or keyboard layer. ItsHostErrorimplementscore::error::Errorthroughthiserror.nusb0.2.9,src/descriptors.rs:Descriptor,DescriptorIter, and viewsDeviceDescriptor,ConfigurationDescriptor,InterfaceDescriptorandEndpointDescriptorover borrowed bytes, with every field of each descriptor as a method.DescriptorIterstops at a length below 2 or past the buffer, logging a warning. The module uses std.usbh0.1.0: a no_std host stack over aHostBustrait, with a boot keyboard driver insrc/driver/kbd.rs. It casts itsInputReportfrom the slice withunsafe,pressed_keysiterates the nonzero slots, and nothing computes releases or checks for a phantom report. Its descriptor parser usesnom.usb-host0.1.3: theUSBHost,EndpointandDrivertraits,repr(C)descriptor structs and a typedRequestType; no configuration walk.usb-device0.3.2: the device side'sDescriptorWriter, which writes the descriptors this crate reads.usbd-hid0.10.2: the device side'sKeyboardReport, withmodifier,reserved,ledsandkeycodes: [u8; 6], the layoutBootReportreads.keycode1.0.0:KeyMaptables from usage ids to scan codes and aKeyboardStatethat builds reports.rusb,usb,usb-if,usbd-human-interface-device,hidreportandhut: measured, not read.
The systems outside Rust
- OpenBSD, from the GitHub mirror at commit
c31f732c3135f73ec492f4793614fbe158ae4b4b, whose files carry their own revisions:sys/dev/usb/ukbd.c1.91,sys/dev/hid/hidkbd.c1.15 andsys/dev/usb/usb_subr.c1.169.hidkbd_decodeignores a report whose first slot is 0x01, then emits modifier changes, releases and presses in that order, the orderchangesfollows; it adds a key twice when the new report lists it twice.usbd_find_idescwalks towTotalLengthand stops at a length of 0. - Linux v6.18:
drivers/hid/usbhid/usbkbd.c, whoseusb_kbd_irqreports the eight modifiers, then for each slot a release and a press, skipping a slot that holds 0 to 3. Its probe takes an interface with exactly one interruptINendpoint. Anddrivers/usb/core/config.c, whoseusb_parse_configurationlogs a descriptor longer than what remains or shorter than 2 and skips the rest of the configuration.
OpenBSD's files are under BSD licenses and Linux's under the GPL; the review read them for behavior only and copied no text.
What was not run
- Kani: the harness count is from source.
- The fuzz targets.
- Any comparator's tests; the bench built
nusbonly as its dependency.