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