blob: 5f1730aa3d775944db483725dbce937c0b2ae456 [file] [log] [blame]
Matthew Dentonbb0b03e2021-07-22 16:18:131// 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
5#ifndef BASE_STACK_CANARY_LINUX_H_
6#define BASE_STACK_CANARY_LINUX_H_
7
8#include "base/base_export.h"
Matthew Dentonbb0b03e2021-07-22 16:18:139
10namespace 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.
21void 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.
28void BASE_EXPORT SetStackSmashingEmitsDebugMessage();
29
30} // namespace base
31
32#endif // BASE_STACK_CANARY_LINUX_H_