xref: /freebsd/contrib/llvm-project/compiler-rt/lib/gwp_asan/options.inc (revision 77013d11e6483b970af25e13c9b892075742f7e5)
1//===-- options.inc ---------------------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef GWP_ASAN_OPTION
10#error "Define GWP_ASAN_OPTION prior to including this file!"
11#endif
12
13#ifndef GWP_ASAN_DEFAULT_ENABLED
14#define GWP_ASAN_DEFAULT_ENABLED true
15#endif
16
17#ifndef GWP_ASAN_STRINGIFY
18#define GWP_ASAN_STRINGIFY(S) GWP_ASAN_STRINGIFY_(S)
19#define GWP_ASAN_STRINGIFY_(S) #S
20#endif
21
22GWP_ASAN_OPTION(bool, Enabled, GWP_ASAN_DEFAULT_ENABLED,
23                "Is GWP-ASan enabled? Defaults to " GWP_ASAN_STRINGIFY(
24                    GWP_ASAN_DEFAULT_ENABLED) ".")
25
26GWP_ASAN_OPTION(
27    bool, PerfectlyRightAlign, false,
28    "When allocations are right-aligned, should we perfectly align them up to "
29    "the page boundary? By default (false), we round up allocation size to the "
30    "nearest power of two (1, 2, 4, 8, 16) up to a maximum of 16-byte "
31    "alignment for performance reasons. For Bionic, we use 8-byte alignment by "
32    "default. Setting this to true can find single byte buffer-overflows for "
33    "multibyte allocations at the cost of performance, and may be incompatible "
34    "with some architectures.")
35
36GWP_ASAN_OPTION(int, MaxSimultaneousAllocations, 16,
37                "Number of simultaneously-guarded allocations available in the "
38                "pool. Defaults to 16.")
39
40GWP_ASAN_OPTION(int, SampleRate, 5000,
41                "The probability (1 / SampleRate) that an allocation is "
42                "selected for GWP-ASan sampling. Default is 5000. Sample rates "
43                "up to (2^30 - 1) are supported.")
44
45// Developer note - This option is not actually processed by GWP-ASan itself. It
46// is included here so that a user can specify whether they want signal handlers
47// or not. The supporting allocator should inspect this value to see whether
48// signal handlers need to be installed, and then use
49// crash_handler::installSignalHandlers() in order to install the handlers. Note
50// that in order to support signal handlers, you will need to link against the
51// optional crash_handler component.
52GWP_ASAN_OPTION(
53    bool, InstallSignalHandlers, true,
54    "Install GWP-ASan signal handlers for SIGSEGV during dynamic loading. This "
55    "allows better error reports by providing stack traces for allocation and "
56    "deallocation when reporting a memory error. GWP-ASan's signal handler "
57    "will forward the signal to any previously-installed handler, and user "
58    "programs that install further signal handlers should make sure they do "
59    "the same. Note, if the previously installed SIGSEGV handler is SIG_IGN, "
60    "we terminate the process after dumping the error report.")
61
62GWP_ASAN_OPTION(bool, InstallForkHandlers, true,
63                "Install GWP-ASan atfork handlers to acquire internal locks "
64                "before fork and release them after.")
65
66GWP_ASAN_OPTION(bool, help, false, "Print a summary of the available options.")
67
68// =============================================================================
69// ==== WARNING
70// =============================================================================
71// If you are adding flags to GWP-ASan, please note that GWP-ASan flag strings
72// may be parsed by trusted system components (on Android, GWP-ASan flag strings
73// are parsed by libc during the dynamic loader). This means that GWP-ASan
74// should never feature flags like log paths on disk, because this can lead to
75// arbitrary file write and thus privilege escalation. For an example, see the
76// setuid ASan log_path exploits: https://www.exploit-db.com/exploits/46241.
77//
78// Please place all new flags above this warning, so that the warning always
79// stays at the bottom.
80