Fix LinuxUserland::read_maps to handle large /proc/self/maps output - #1407
Open
dywongcloud wants to merge 2 commits into
Open
dywongcloud wants to merge 2 commits into
dywongcloud wants to merge 2 commits into
Conversation
read_maps() read /proc/self/maps into a fixed 8 KiB stack buffer and asserted the read fit, panicking with "buffer too small" once the process had enough mappings to exceed that size. This was hit in CI as a timing-dependent race: the broker starting worker threads while read_maps() was capturing the process's mappings could push the file past 8 KiB. Replace the fixed-size read with an EOF-driven loop into a growable buffer, backing off gracefully (keeping whatever was read so far) if growing the buffer fails, consistent with this function's existing best-effort contract (it already returns nothing if the file can't be opened, and mappings created during/after the read are still not guaranteed to be captured). Parsing now works directly off the raw bytes instead of requiring the whole file to be valid UTF-8, since a mapped file's pathname field isn't guaranteed to be one. Adds a regression test that creates thousands of small mappings to push /proc/self/maps past the old 8 KiB limit and calls read_maps() directly, verifying it no longer panics. Fixes microsoft#1328
Contributor
Author
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.
As described in [issue #1328](#1328),
read_maps()could panic when/proc/self/mapsexceeded its fixed 8 KiB buffer, sometimes triggered by worker threads starting during the read.Read into a growable buffer until EOF, retaining partial data if allocation fails. Parse the raw bytes so non-UTF-8 pathnames do not prevent parsing. Add a regression test with thousands of mappings that exceed the old limit.