Skip to content

HID: spi-hid-apple: bound reassembled reports and refuse a descriptor without a buffer - #2986

Closed
Alyx-ML wants to merge 2 commits into
aurora-silicon:mainfrom
Alyx-ML:aurora/spi-hid-bounds
Closed

Alyx-ML wants to merge 2 commits into
aurora-silicon:mainfrom
Alyx-ML:aurora/spi-hid-bounds

Conversation

@Alyx-ML

@Alyx-ML Alyx-ML commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Part of the #2755 split. Draft until it has a run on a Mac (the last Evidence line says which).

Summary

 spihid_assemble_message()
+  announced size > the 2 KiB report buffer -> drop the report
+  a packet that would write past the buffer -> drop it
+  a later packet with a different total -> drop the partial report
 spihid_process_iface_hid_report_desc()
+  interface with no hid_desc buffer (interface 0) -> refuse, no NULL write

Evidence

A host harness builds the real old and new function text under ASan and UBSan:

  • Before: a 20,000-byte report causes a heap-buffer-overflow, 246 bytes past the 2 KiB buffer.
  • After: reports of 247, 500, 1000, 2047 and 2048 bytes arrive unchanged. Reports of 2049 and
    20,000 bytes, a stray packet at offset 60,000 and a partial report whose total changes are
    dropped, and a good report still arrives afterwards.
  • The descriptor fix was checked by reading: probe only asks for interfaces 1 and up.
  • Build and KUnit (spi-hid-apple): passed, Apple build and KUnit.
  • Needed before merging: typing and trackpad use on an M1 or M2 MacBook.

Merge Danger

Door: two-way

Blast Radius: internal keyboard and trackpad

A wrong bound would drop a valid report. The bound is the report buffer the driver already has.

Assisted-by: LLM (Claude:Opus 5.5)

spihid_assemble_message() joins multi-packet input reports in rep->buf,
a SPIHID_MAX_INPUT_REPORT_SIZE (2 KiB) devm_kmalloc() buffer. The first
packet's header sets the total size, and the only check was that offset,
length and remain fit in a u16. A first packet announcing a report of up
to 64 KiB was accepted, and each later packet was copied to rep->buf +
offset, so the packets after the first 2 KiB wrote past the buffer, and
the finished report was then read back at its full length.

Drop a report whose announced size does not fit the buffer, and any
packet that would write past it, with a rate-limited warning. Also drop
the partial report when a later packet disagrees about the total size,
so its bytes are not joined to a different report.

Verified with a host harness built from the real old and new function
text under ASan and UBSan. The old code hits a heap-buffer-overflow (a
246-byte write just past the 2 KiB buffer) on a 20,000-byte report. The
new code delivers 247, 500, 1000, 2047 and 2048-byte reports unchanged,
drops 2049 and 20,000-byte reports, a stray packet at offset 60,000 and
a first packet with remain 65,289, drops a partial report whose total
changes, and still delivers a good report afterwards. The kernel object
was not built here, and no keyboard or trackpad hardware was used.

Signed-off-by: Alyx-ML <[email protected]>
…ut a buffer

Only the keyboard, trackpad and aux interfaces get a descriptor buffer
at probe; the management interface's hid_desc stays NULL. A HID report
descriptor message addressed to interface 0 is still accepted by
spihid_process_iface_hid_report_desc(), which copies it through that
NULL pointer.

Refuse a descriptor for an interface that has no buffer. Probe only asks
for descriptors of interfaces 1 and up, so a working device is not
affected.

Checked by reading the probe and message paths. Not built or run on
hardware.

Signed-off-by: Alyx-ML <[email protected]>
@RyanTheTide

Copy link
Copy Markdown
Contributor

@Alyx-ML checking open drafts today. To come out of draft, this still needs:

  • It conflicts with main. Merge main in or rebase (no force push needed: a merge commit is fine).
  • About 47% of the lines it adds are already on main. Drop what has landed so the diff shows only what is new.
  • Then a test run at the final head on a Mac with the hardware it touches, and mark it ready for review.

If it's no longer needed, say so here and we'll close it. Otherwise it stays open as a draft until these are done.

@Alyx-ML

Alyx-ML commented Nov 27, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for checking. This is no longer needed. e2ec946 on main bounds reassembly by the
buffer size and ignores a descriptor for an interface without a buffer, with KUnit cases. The
only part left here was resetting the partial report on a mismatched fragment, which changes no
copy, so it is not worth a PR.

Please close it.

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide

Copy link
Copy Markdown
Contributor

Closing as you asked in #2986 (comment). The commits you list are all on main (checked each one). Thanks. The branch stays.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants