diff options
author | Abseil Team <absl-team@google.com> | 2023-01-23 09:10:24 -0800 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2023-01-23 09:11:40 -0800 |
commit | 96355f50aa468b2ffc04589ea2b8573619ab205c (patch) | |
tree | 420336629ffde6819f546362353423bcf9bd2323 /absl/debugging | |
parent | 7e8d8018f621e94182876535320718542a4c5f09 (diff) |
absl: harden stack bounds check
Ensure that we know both real low and high stack bounds
when relying on the stack bounds check.
PiperOrigin-RevId: 504003431
Change-Id: I8f6e6b75f5edff233d3cf80285f81b53f9080a0f
Diffstat (limited to 'absl/debugging')
-rw-r--r-- | absl/debugging/internal/stacktrace_x86-inl.inc | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/absl/debugging/internal/stacktrace_x86-inl.inc b/absl/debugging/internal/stacktrace_x86-inl.inc index ada2628d..7b26464e 100644 --- a/absl/debugging/internal/stacktrace_x86-inl.inc +++ b/absl/debugging/internal/stacktrace_x86-inl.inc @@ -267,12 +267,20 @@ static void **NextStackFrame(void **old_fp, const void *uc, // guessed frame pointers incorrectly and now risk a paging fault // dereferencing a wrong frame pointer. Or maybe not because large frames // are possible as well. The main stack is assumed to be readable, - // so we assume the large frame is legit if we know the stack bounds and are - // within the stack. - if (new_fp_u - old_fp_u > kMaxFrameBytes && - (stack_high == kUnknownStackEnd || - !(stack_low < new_fp_u && new_fp_u <= stack_high))) { - return nullptr; + // so we assume the large frame is legit if we know the real stack bounds + // and are within the stack. + if (new_fp_u - old_fp_u > kMaxFrameBytes) { + if (stack_high < kUnknownStackEnd && + static_cast<size_t>(getpagesize()) < stack_low) { + // Stack bounds are known. + if (!(stack_low < new_fp_u && new_fp_u <= stack_high)) { + // new_fp_u is not within the known stack. + return nullptr; + } + } else { + // Stack bounds are unknown, prefer truncated stack to possible crash. + return nullptr; + } } if (stack_low < old_fp_u && old_fp_u <= stack_high) { // Old BP was in the expected stack region... |