Repository navigation
Conversation
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 <256263590+Alyx-ML@users.noreply.github.com>
…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 <256263590+Alyx-ML@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of the #2755 split. Draft until it has a run on a Mac (the last Evidence line says which).
Summary
Evidence
A host harness builds the real old and new function text under ASan and UBSan:
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.
spi-hid-apple): passed, Apple build and KUnit.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)