stack_canary_linux.h 1.3 KB

1234567891011121314151617181920212223242526272829303132
  1. // Copyright 2021 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef BASE_STACK_CANARY_LINUX_H_
  5. #define BASE_STACK_CANARY_LINUX_H_
  6. #include "base/base_export.h"
  7. namespace base {
  8. // This resets the reference stack canary to a new random value, which is
  9. // useful when forking so multiple processes don't have the same canary (which
  10. // makes it easy to brute force). All functions called from here on out will
  11. // use the new stack canary. However, functions that are on the call stack at
  12. // the time of calling this function are now unsafe to return from unless they
  13. // have the no_stack_protector attribute.
  14. //
  15. // On ARM we require the process to be single-threaded, as this function needs
  16. // to edit a read-only page containing the canary.
  17. void BASE_EXPORT ResetStackCanaryIfPossible();
  18. // After this is called, any canary mismatch is considered to be due to a
  19. // change in the reference canary (see ResetStackCanaryIfPossible()) rather
  20. // than a stack corruption. Instead of immediately crashing, emit a useful
  21. // debug message that explains how to avoid the crash.
  22. // Has no effect is non-debug builds.
  23. void BASE_EXPORT SetStackSmashingEmitsDebugMessage();
  24. } // namespace base
  25. #endif // BASE_STACK_CANARY_LINUX_H_