-
Notifications
You must be signed in to change notification settings - Fork 14.7k
[asan] Fix misalignment of variables in fake stack frames #152819
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 26 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
45198b2
[asan] Fix misalignment of variables in fake stack frames
thurstond fdfcc01
Update SizeRequiredForFlags
thurstond 0b69b3b
Proof of alignment invariant in GetFrame()
thurstond fe98da4
GetFrame() wording
thurstond 58e1841
Punctuation
thurstond 222c89f
Wording
thurstond ccb538f
Fix claim
thurstond 48bf1aa
Comment on near-optimality
thurstond bbecef4
Wording
thurstond 0e5b514
Simplify alignment step to FakeStack::Create() only
thurstond 570f8cf
Revert test
thurstond d4441e4
Update FakeStack comment
thurstond 7b314b5
Remove duplicated comment
thurstond 6cef8c5
Update comment
thurstond 46e7c1e
Formatting
thurstond 07ee0bb
Add alignment check to test
thurstond 8282b9b
clang-format
thurstond a378876
More logging
thurstond a1859f0
Fix edge case of frame with small variables that need heavy alignment
thurstond d8dab9f
Reword comment
thurstond 8529f76
Partly revert aligned local stack size change, to maximize protection
thurstond 8df0f39
Statically assert that FakeStack as a whole is aligned
thurstond cc040e1
Drive-by fix: remove deprecated comment
thurstond e19176e
Add note that most modern compilers have sizeof(type) >= alignof(type)
thurstond 4df767d
Revert ASan instrumentation change
thurstond 6ccb151
Update commentary on min stack size and GetFrame 4K alignment
thurstond d31eea6
Merge remote-tracking branch 'upstream/main' into asan_align_fake_stack
thurstond 44b8a3c
Use kMaxStackFrameSize and remove local true_start.
thurstond 96845f2
Replace other usages of 1 << kMaxStackFrameSizeLog
thurstond File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,17 +55,32 @@ FakeStack *FakeStack::Create(uptr stack_size_log) { | |
if (stack_size_log > kMaxStackSizeLog) | ||
stack_size_log = kMaxStackSizeLog; | ||
uptr size = RequiredSize(stack_size_log); | ||
uptr padded_size = size + (1 << kMaxStackFrameSizeLog); | ||
void *true_res = reinterpret_cast<void *>( | ||
flags()->uar_noreserve ? MmapNoReserveOrDie(padded_size, "FakeStack") | ||
: MmapOrDie(padded_size, "FakeStack")); | ||
// GetFrame() requires the property that | ||
// (res + kFlagsOffset + SizeRequiredForFlags(stack_size_log)) is aligned to | ||
// (1 << kMaxStackFrameSizeLog). | ||
// We didn't use MmapAlignedOrDieOnFatalError, because it requires that the | ||
// *size* is a power of 2, which is an overly strong condition. | ||
static_assert(alignof(FakeStack) <= (1 << kMaxStackFrameSizeLog)); | ||
FakeStack *res = reinterpret_cast<FakeStack *>( | ||
flags()->uar_noreserve ? MmapNoReserveOrDie(size, "FakeStack") | ||
: MmapOrDie(size, "FakeStack")); | ||
RoundUpTo( | ||
(uptr)true_res + kFlagsOffset + SizeRequiredForFlags(stack_size_log), | ||
1 << kMaxStackFrameSizeLog) - | ||
kFlagsOffset - SizeRequiredForFlags(stack_size_log)); | ||
res->true_start = true_res; | ||
res->stack_size_log_ = stack_size_log; | ||
u8 *p = reinterpret_cast<u8 *>(res); | ||
VReport(1, | ||
"T%d: FakeStack created: %p -- %p stack_size_log: %zd; " | ||
"mmapped %zdK, noreserve=%d \n", | ||
"mmapped %zdK, noreserve=%d, true_start: %p, start of first frame: " | ||
"0x%zx\n", | ||
GetCurrentTidOrInvalid(), (void *)p, | ||
(void *)(p + FakeStack::RequiredSize(stack_size_log)), stack_size_log, | ||
size >> 10, flags()->uar_noreserve); | ||
size >> 10, flags()->uar_noreserve, res->true_start, | ||
res->GetFrame(stack_size_log, /*class_id*/ 0, /*pos*/ 0)); | ||
return res; | ||
} | ||
|
||
|
@@ -79,8 +94,11 @@ void FakeStack::Destroy(int tid) { | |
Report("T%d: FakeStack destroyed: %s\n", tid, str.data()); | ||
} | ||
uptr size = RequiredSize(stack_size_log_); | ||
FlushUnneededASanShadowMemory(reinterpret_cast<uptr>(this), size); | ||
UnmapOrDie(this, size); | ||
uptr padded_size = size + (1 << kMaxStackFrameSizeLog); | ||
void *true_start = this->true_start; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed |
||
FlushUnneededASanShadowMemory(reinterpret_cast<uptr>(true_start), | ||
padded_size); | ||
UnmapOrDie(true_start, padded_size); | ||
} | ||
|
||
void FakeStack::PoisonAll(u8 magic) { | ||
|
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this would be a bit easier to read if we had
and then used this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a static const