Skip to content

[sanitizer_common] Fix edge case for stack mapping parsing #98381

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 2 commits into from
Jul 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,19 @@ void GetThreadStackTopAndBottom(bool at_initialization, uptr *stack_top,
stacksize = kMaxThreadStackSize;
*stack_top = segment.end;
*stack_bottom = segment.end - stacksize;

uptr maxAddr = GetMaxUserVirtualAddress();
// Edge case: the stack mapping on some systems may be off-by-one e.g.,
// fffffffdf000-1000000000000 rw-p 00000000 00:00 0 [stack]
// instead of:
// fffffffdf000- ffffffffffff
// The out-of-range stack_top can result in an invalid shadow address
// calculation, since those usually assume the parameters are in range.
if (*stack_top == maxAddr + 1)
*stack_top = maxAddr;
else
CHECK_LE(*stack_top, maxAddr);

return;
}
uptr stacksize = 0;
Expand Down
Loading