Fix out-of-bounds write and lack of null-termination in /proc/cpuinfo…#408
Open
mhansen wants to merge 2 commits into
Open
Fix out-of-bounds write and lack of null-termination in /proc/cpuinfo…#408mhansen wants to merge 2 commits into
mhansen wants to merge 2 commits into
Conversation
Added a reproduction test case `repro_cpuinfo` which uses a mock filesystem with an overly long 'Hardware' value to trigger the issue. The test is added to the CMake build (guarded for ARM). Marked the test as WILL_FAIL in CMake because the bug is not yet fixed in this commit. TAG=agy CONV=54bab573-9944-4cb7-9b45-7b056f7d9c47
… parser The parser for 'Hardware' and 'Revision' fields in src/arm/linux/cpuinfo.c had logic errors when handling values with length equal to or greater than the maximum buffer size. 1. If value_length == LIMIT, it would write '\0' at index LIMIT, which is out of bounds (buffer size is LIMIT). 2. If value_length > LIMIT, it would truncate to LIMIT, skip writing the null terminator, and copy LIMIT bytes, leaving the buffer non-null-terminated. Fixed by checking if value_length >= LIMIT, truncating to LIMIT - 1 if so, and always writing the null terminator at the end of the (potentially truncated) copied value. Removed the WILL_FAIL property from the repro test in CMakeLists.txt as the test now passes. TAG=agy CONV=54bab573-9944-4cb7-9b45-7b056f7d9c47
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.
… parser
The parser for 'Hardware' and 'Revision' fields in src/arm/linux/cpuinfo.c had logic errors when handling values with length equal to or greater than the maximum buffer size.
Fixed by checking if value_length >= LIMIT, truncating to LIMIT - 1 if so, and always writing the null terminator at the end of the (potentially truncated) copied value.
Fixes #407