audit 0.21.0: MSC and MTP follow-ups

Open
#4,526 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
12/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Active
Tech stack
c
Domain
embedded-iot

Research direction

Read mtp_device.c around lines 185, 468 and 585 to trace how an armed OUT receive survives a Cancel, then mtp_device.c:332,680 with mtp_device.h:88 for the Data-IN early-response path. For item 3, start at msc_device.c:408 and src/device/usbd.c:1640, checking whether usbd_open_edpt_pair() validates descriptor length bounds before the MPS pre-read. Done means a diagnosed contract (toggle-preserving partial-OUT drain, IN cancellation, descriptor size checks) confirmed by raw host or HIL runs, since only source tracing has happened so far.

Written by the indexing model from the issue text.

Description

follow-up Prio 📌

Deferred defects found in the repository audit of 0.21.0..ad7c83db8 (batch class-msc-mtp). Each was validated against the source at ad7c83db8 and judged real but too large, or too hardware-dependent, for the audit PR's contained fixes.

1. Cancel changes to COMMAND while a partially filled OUT receive remains armed. Its next completion can contain old data followed by the next command.
  • Where: mtp_device.c:185,468,585
  • Verdict: valid causal path; stated timing not reproduced; introduced: New COMMAND transition/live-read reuse; baseline Cancel was also incomplete; severity: medium
  • Hardware/spec dependence: M host-cancel sequence checked; DCD partial-receive/abort behavior lacks variant records
  • Overlap: #3961 covers IN, not this OUT case; #4495/#4107 early rejection are different triggers. No full coverage
  • Remaining work and verification: Needs a toggle-preserving partial-OUT retirement/drain design, not an unconditional fallback abort. Existing raw test cancels after a complete 512-byte write, missing the partial-buffer trigger.
2. Early response from an unfinished Data-IN callback is transmitted as the next data packet, without cancellation handling.
  • Where: mtp_device.c:332,680; mtp_device.h:88
  • Verdict: valid; introduced: Mechanism older; permissive API documentation new; severity: medium
  • Hardware/spec dependence: M pp.31,36 checked: phase termination and device cancellation
  • Overlap: #4040 and PR #4517 address Data-OUT only; partial overlap, not full coverage
  • Remaining work and verification: Extend the early-answer contract deliberately to unfinished IN, preventing response submission before cancellation/phase completion. Test a GetObject callback that answers after the first full chunk; raw host/HIL validation required.
3. New MPS pre-read follows application descriptor lengths without bounds/type validation.
  • Where: msc_device.c:408; src/device/usbd.c:1640
  • Verdict: valid malformed-descriptor hardening; claimed valid-config regression not established; introduced: New pre-read; unsafe descriptor-walk foundation older; severity: low
  • Hardware/spec dependence: Bounds defect is source-level; descriptor legality needs USB lookup
  • Overlap: #4387 related field-read scope; PR #4517 fixes the common helper only and does not protect this pre-read
  • Remaining work and verification: Extend device descriptor hardening with minimum-size and remaining-span checks before either endpoint is inspected/opened. bLength != 7 alone is not proof of invalidity; usbd_open_edpt_pair() itself does not validate length bounds.
Adjudication notes: class-msc-mtp

Claims still needing read-doc:

  • S08-06/C08-01, F2: For each affected DCD, does abort retire DMA/FIFO ownership and partial OUT state without changing the current toggle, and can a completion remain queued afterward? The nRF52840 DTOGGLE register and applicable errata cited by the earlier reviewer need an actual claim record; its citations alone are not one.
  • S08-01/S08-07: Which abort/reset/clear-halt operations preserve an armed receive, and what ISR ordering guarantees make a core generation scheme safe? No all-variant equivalence was established.
  • S08-04/S08-05/S08-15, only if revived: DMA/cache ownership for eliminating writes; permitted bulk MPS values for mask substitution; and per-HCD transfer-length/packet-boundary requirements for moving chunking.
  • F10: USB descriptor minimum sizes, extended-length handling, and class endpoint ordering requirements before defining the accepted descriptor set.

Unverified: no unit suite, build, fuzz execution, or hardware run occurred. F5 arithmetic was executed; other defect triggers were traced in source. No additional independently established runtime defect beyond N08-01 was found in the inspected changes. The checkout remains clean, and no files were changed.

Dominant language
C
Stars
7.3k
Forks
1.6k
Avg merge
1d 19h
Merged PRs (30d)
67

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from hathach/tinyusb

All issues in hathach/tinyusb

Similar issues

More C issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.