10b57cec5SDimitry Andric//===-- options.inc ---------------------------------------------*- C++ -*-===// 20b57cec5SDimitry Andric// 30b57cec5SDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 40b57cec5SDimitry Andric// See https://llvm.org/LICENSE.txt for license information. 50b57cec5SDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 60b57cec5SDimitry Andric// 70b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 80b57cec5SDimitry Andric 90b57cec5SDimitry Andric#ifndef GWP_ASAN_OPTION 100b57cec5SDimitry Andric#error "Define GWP_ASAN_OPTION prior to including this file!" 110b57cec5SDimitry Andric#endif 120b57cec5SDimitry Andric 13*e8d8bef9SDimitry Andric#ifndef GWP_ASAN_DEFAULT_ENABLED 14*e8d8bef9SDimitry Andric#define GWP_ASAN_DEFAULT_ENABLED true 15*e8d8bef9SDimitry Andric#endif 16*e8d8bef9SDimitry Andric 17*e8d8bef9SDimitry Andric#ifndef GWP_ASAN_STRINGIFY 18*e8d8bef9SDimitry Andric#define GWP_ASAN_STRINGIFY(S) GWP_ASAN_STRINGIFY_(S) 19*e8d8bef9SDimitry Andric#define GWP_ASAN_STRINGIFY_(S) #S 20*e8d8bef9SDimitry Andric#endif 21*e8d8bef9SDimitry Andric 22*e8d8bef9SDimitry AndricGWP_ASAN_OPTION(bool, Enabled, GWP_ASAN_DEFAULT_ENABLED, 23*e8d8bef9SDimitry Andric "Is GWP-ASan enabled? Defaults to " GWP_ASAN_STRINGIFY( 24*e8d8bef9SDimitry Andric GWP_ASAN_DEFAULT_ENABLED) ".") 250b57cec5SDimitry Andric 260b57cec5SDimitry AndricGWP_ASAN_OPTION( 270b57cec5SDimitry Andric bool, PerfectlyRightAlign, false, 280b57cec5SDimitry Andric "When allocations are right-aligned, should we perfectly align them up to " 290b57cec5SDimitry Andric "the page boundary? By default (false), we round up allocation size to the " 300b57cec5SDimitry Andric "nearest power of two (1, 2, 4, 8, 16) up to a maximum of 16-byte " 315ffd83dbSDimitry Andric "alignment for performance reasons. For Bionic, we use 8-byte alignment by " 325ffd83dbSDimitry Andric "default. Setting this to true can find single byte buffer-overflows for " 335ffd83dbSDimitry Andric "multibyte allocations at the cost of performance, and may be incompatible " 345ffd83dbSDimitry Andric "with some architectures.") 350b57cec5SDimitry Andric 3668d75effSDimitry AndricGWP_ASAN_OPTION(int, MaxSimultaneousAllocations, 16, 3768d75effSDimitry Andric "Number of simultaneously-guarded allocations available in the " 3868d75effSDimitry Andric "pool. Defaults to 16.") 390b57cec5SDimitry Andric 400b57cec5SDimitry AndricGWP_ASAN_OPTION(int, SampleRate, 5000, 410b57cec5SDimitry Andric "The probability (1 / SampleRate) that an allocation is " 420b57cec5SDimitry Andric "selected for GWP-ASan sampling. Default is 5000. Sample rates " 43*e8d8bef9SDimitry Andric "up to (2^30 - 1) are supported.") 440b57cec5SDimitry Andric 455ffd83dbSDimitry Andric// Developer note - This option is not actually processed by GWP-ASan itself. It 465ffd83dbSDimitry Andric// is included here so that a user can specify whether they want signal handlers 475ffd83dbSDimitry Andric// or not. The supporting allocator should inspect this value to see whether 485ffd83dbSDimitry Andric// signal handlers need to be installed, and then use 495ffd83dbSDimitry Andric// crash_handler::installSignalHandlers() in order to install the handlers. Note 505ffd83dbSDimitry Andric// that in order to support signal handlers, you will need to link against the 515ffd83dbSDimitry Andric// optional crash_handler component. 520b57cec5SDimitry AndricGWP_ASAN_OPTION( 530b57cec5SDimitry Andric bool, InstallSignalHandlers, true, 540b57cec5SDimitry Andric "Install GWP-ASan signal handlers for SIGSEGV during dynamic loading. This " 550b57cec5SDimitry Andric "allows better error reports by providing stack traces for allocation and " 560b57cec5SDimitry Andric "deallocation when reporting a memory error. GWP-ASan's signal handler " 570b57cec5SDimitry Andric "will forward the signal to any previously-installed handler, and user " 580b57cec5SDimitry Andric "programs that install further signal handlers should make sure they do " 590b57cec5SDimitry Andric "the same. Note, if the previously installed SIGSEGV handler is SIG_IGN, " 600b57cec5SDimitry Andric "we terminate the process after dumping the error report.") 615ffd83dbSDimitry Andric 625ffd83dbSDimitry AndricGWP_ASAN_OPTION(bool, InstallForkHandlers, true, 635ffd83dbSDimitry Andric "Install GWP-ASan atfork handlers to acquire internal locks " 645ffd83dbSDimitry Andric "before fork and release them after.") 65*e8d8bef9SDimitry Andric 66*e8d8bef9SDimitry AndricGWP_ASAN_OPTION(bool, help, false, "Print a summary of the available options.") 67*e8d8bef9SDimitry Andric 68*e8d8bef9SDimitry Andric// ============================================================================= 69*e8d8bef9SDimitry Andric// ==== WARNING 70*e8d8bef9SDimitry Andric// ============================================================================= 71*e8d8bef9SDimitry Andric// If you are adding flags to GWP-ASan, please note that GWP-ASan flag strings 72*e8d8bef9SDimitry Andric// may be parsed by trusted system components (on Android, GWP-ASan flag strings 73*e8d8bef9SDimitry Andric// are parsed by libc during the dynamic loader). This means that GWP-ASan 74*e8d8bef9SDimitry Andric// should never feature flags like log paths on disk, because this can lead to 75*e8d8bef9SDimitry Andric// arbitrary file write and thus privilege escalation. For an example, see the 76*e8d8bef9SDimitry Andric// setuid ASan log_path exploits: https://www.exploit-db.com/exploits/46241. 77*e8d8bef9SDimitry Andric// 78*e8d8bef9SDimitry Andric// Please place all new flags above this warning, so that the warning always 79*e8d8bef9SDimitry Andric// stays at the bottom. 80