Reland: [GWP-ASan] Add recoverable mode.
authorMitch Phillips <31459023+hctim@users.noreply.github.com>
Fri, 13 Jan 2023 00:01:06 +0000 (16:01 -0800)
committerMitch Phillips <31459023+hctim@users.noreply.github.com>
Tue, 17 Jan 2023 18:21:01 +0000 (10:21 -0800)
commit35b5499d7259ac3e5c648a711678290695703a87
treee1abe3c07f6d19cd1d41dac9d174c4e3d9581a7c
parent9c84d20fa69006adcbbaf424f3ef674298045f78
Reland: [GWP-ASan] Add recoverable mode.

The GWP-ASan recoverable mode allows a process to continue to function
after a GWP-ASan error is detected. The error will continue to be
dumped, but GWP-ASan now has APIs that a signal handler (like the
example optional crash handler) can call in order to allow the
continuation of a process.

When an error occurs with an allocation, the slot used for that
allocation will be permanently disabled. This means that free() of that
pointer is a no-op, and use-after-frees will succeed (writing and
reading the data present in the page).

For heap-buffer-overflow/underflow, the guard page is marked as accessible
and buffer-overflows will succeed (writing and reading the data present
in the now-accessible guard page). This does impact adjacent
allocations, buffer-underflow and buffer-overflows from adjacent
allocations will no longer touch an inaccessible guard page. This could
be improved in future by having two guard pages between each adjacent
allocation, but that's out of scope of this patch.

Each allocation only ever has a single error report generated. It's
whatever came first between invalid-free, double-free, use-after-free or
heap-buffer-overflow, but only one.

Reviewed By: eugenis, fmayer

Differential Revision: https://reviews.llvm.org/D140173
17 files changed:
compiler-rt/lib/gwp_asan/common.cpp
compiler-rt/lib/gwp_asan/common.h
compiler-rt/lib/gwp_asan/crash_handler.cpp
compiler-rt/lib/gwp_asan/crash_handler.h
compiler-rt/lib/gwp_asan/guarded_pool_allocator.cpp
compiler-rt/lib/gwp_asan/guarded_pool_allocator.h
compiler-rt/lib/gwp_asan/optional/segv_handler.h
compiler-rt/lib/gwp_asan/optional/segv_handler_fuchsia.cpp
compiler-rt/lib/gwp_asan/optional/segv_handler_posix.cpp
compiler-rt/lib/gwp_asan/options.inc
compiler-rt/lib/gwp_asan/tests/CMakeLists.txt
compiler-rt/lib/gwp_asan/tests/backtrace.cpp
compiler-rt/lib/gwp_asan/tests/crash_handler_api.cpp
compiler-rt/lib/gwp_asan/tests/harness.cpp
compiler-rt/lib/gwp_asan/tests/harness.h
compiler-rt/lib/gwp_asan/tests/recoverable.cpp [new file with mode: 0644]
compiler-rt/lib/scudo/standalone/combined.h