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