This repository has been archived by the owner on Mar 24, 2022. It is now read-only.
Fix incorrect globals/sigstack allocation layout #401
Merged
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.
Most of this patch is actually to fix up the tests that were erroneously succeeding because of this bug. The core of the fix is here in
mmap.rs
:This was causing the signal stack to begin one page after the start of the globals section, regardless of how big the globals are. This mostly wasn't causing problems because the default globals size is a page, and we were still adding in a page for the guard, meaning the segments didn't actually overlap with default
Limits
. However, the guard page for the signal stack was missing, and configurations with larger globals sizes could end up overlapping the signal stack, potentially allowing guests to observe residual signal stack values.The lack of a signal stack guard page was also making it so that tests running in debug mode would succeed, even though the signal handler was overflowing its stack into the globals page. To make those tests pass with the correct memory layout, the signal stack size is now configurable and set higher by default on debug builds (
cfg(debug_assertions)
). On release mode, the stack use is fine as the problematic series of stack allocations get optimized into some straightforward copies, so we continue to use SIGSTKSZ as a default in that configuration.Finally, I added a test that tries to write to the sigstack guard page, improved the "is this a fatal fault address?" method, and made sure that all tests run correctly in release mode.