fix(hidpp): bounds-check raw report dispatch lambdas#551
Open
jelmerdehen wants to merge 1 commit into
Open
Conversation
Filter lambdas in hidpp::Device and hidpp10::ReceiverMonitor indexed the raw byte buffer at Offset::Type, ::DeviceIndex, and ::SubID without checking that the buffer was large enough. A short hidraw read (possible from a malicious or buggy device, or partial reads under load) would cause an out-of-bounds access on std::vector::operator[]. Reject reports shorter than the offsets we read.
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.
Summary
The filter lambdas in
hidpp::Device::_setupReportsAndInitandhidpp10::ReceiverMonitor::_ready/waitForDeviceindex the raw byte buffer atOffset::Type,Offset::DeviceIndex, andOffset::SubIDwithout checking that the buffer is large enough:return (report[Offset::Type] == Report::Type::Short || ...) && (report[Offset::DeviceIndex] == index);reportis the rawstd::vector<uint8_t>returned byread(hidraw_fd)and may be shorter than 2 bytes (a buggy or malicious device, or a partial read).std::vector::operator[]does no bounds checking, so this is undefined behaviour.Fix
Add a
report.size() <= Offset::DeviceIndex(orOffset::SubID) guard at the top of each filter lambda.Test plan