llvm-project/compiler-rt/test
Dan Liew 861b69faee [Darwin] Fix symbolization for recent simulator runtimes.
Summary:
Due to sandbox restrictions in the recent versions of the simulator runtime the
atos program is no longer able to access the task port of a parent process
without additional help.

This patch fixes this by registering a task port for the parent process
before spawning atos and also tells atos to look for this by setting
a special environment variable.

This patch is based on an Apple internal fix (rdar://problem/43693565) that
unfortunately contained a bug (rdar://problem/58789439) because it used
setenv() to set the special environment variable. This is not safe because in
certain circumstances this can trigger a call to realloc() which can fail
during symbolization leading to deadlock. A test case is included that captures
this problem.

The approach used to set the necessary environment variable is as
follows:

1. Calling `putenv()` early during process init (but late enough that
malloc/realloc works) to set a dummy value for the environment variable.

2. Just before `atos` is spawned the storage for the environment
variable is modified to contain the correct PID.

A flaw with this approach is that if the application messes with the
atos environment variable (i.e. unsets it or changes it) between the
time its set and the time we need it then symbolization will fail. We
will ignore this issue for now but a `DCHECK()` is included in the patch
that documents this assumption but doesn't check it at runtime to avoid
calling `getenv()`.

The issue reported in rdar://problem/58789439 manifested as a deadlock
during symbolization in the following situation:

1. Before TSan detects an issue something outside of the runtime calls
setenv() that sets a new environment variable that wasn't previously
set. This triggers a call to malloc() to allocate a new environment
array. This uses TSan's normal user-facing allocator. LibC stores this
pointer for future use later.

2. TSan detects an issue and tries to launch the symbolizer. When we are in the
symbolizer we switch to a different (internal allocator) and then we call
setenv() to set a new environment variable. When this happen setenv() sees
that it needs to make the environment array larger and calls realloc() on the
existing enviroment array because it remembers that it previously allocated
memory for it. Calling realloc() fails here because it is being called on a
pointer its never seen before.

The included test case closely reproduces the originally reported
problem but it doesn't replicate the `((kBlockMagic)) ==
((((u64*)addr)[0])` assertion failure exactly. This is due to the way
TSan's normal allocator allocates the environment array the first time
it is allocated. In the test program addr[0] accesses an inaccessible
page and raises SIGBUS. If TSan's SIGBUS signal handler is active, the
signal is caught and symbolication is attempted again which results in
deadlock.

In the originally reported problem the pointer is successfully derefenced but
then the assert fails due to the provided pointer not coming from the active
allocator. When the assert fails TSan tries to symbolicate the stacktrace while
already being in the middle of symbolication which results in deadlock.

rdar://problem/58789439

Reviewers: kubamracek, yln

Subscribers: jfb, #sanitizers, llvm-commits

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D78179
2020-04-17 15:08:14 -07:00
..
BlocksRuntime Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
asan [ASan] Fix issue where system log buffer was not cleared after reporting an issue. 2020-03-26 10:56:17 -07:00
builtins [compiler-rt] [builtins] Fix logb / logbl tests 2020-02-20 10:16:03 +00:00
cfi [cfi][test] cross-dso/stats.cpp: don't assume the order of static constructors 2020-01-08 15:50:51 -08:00
crt Fix include guard and properly order __deregister_frame_info. 2019-11-12 14:54:41 -08:00
dfsan Fix DataFlowSanitizer implementation of strchr() so that strchr(..., '\0') returns a pointer to '\0'. 2020-04-15 13:08:47 -07:00
fuzzer [libFuzzer] Fix denominator in the "inputs have DFT" log line. 2020-02-19 11:05:14 -08:00
gwp_asan [GWP-ASan] Crash Handler API. 2020-02-05 15:39:17 -08:00
hwasan [compiler-rt] libhwasan interceptor ABI intercept longjmp/setjmp 2019-10-30 14:04:40 +00:00
interception [compiler-rt] Rename lit.*.cfg.* -> lit.*.cfg.py.* 2019-06-27 20:56:04 +00:00
lsan [compiler-rt] [test] Disable ASLR on LSAN+ASAN tests on NetBSD 2019-12-18 17:21:14 +01:00
msan [MSan] Enable for SystemZ 2020-04-16 12:15:01 +02:00
profile Fix simultaneous .gcda creation 2020-04-01 10:29:50 +09:00
safestack compiler-rt: Remove .cc from all lit config files 2019-08-05 19:25:35 +00:00
sanitizer_common [Darwin] Fix a bug where the symbolizer would examine the wrong process. 2020-04-13 13:36:29 -07:00
scudo [Scudo] [GWP-ASan] Add GWP-ASan to Scudo Standalone. 2019-12-13 09:09:41 -08:00
shadowcallstack compiler-rt: Remove .cc from all lit config files 2019-08-05 19:25:35 +00:00
tsan [Darwin] Fix symbolization for recent simulator runtimes. 2020-04-17 15:08:14 -07:00
ubsan [UBSan] Fix vptr checks on arm64e 2020-04-16 16:09:05 -07:00
ubsan_minimal [UBSan][clang][compiler-rt] Applying non-zero offset to nullptr is undefined behaviour 2019-10-10 09:25:02 +00:00
xray [compiler-rt] [test] Disable MPROTECT for XRay tests on NetBSD 2019-12-20 22:08:01 +01:00
.clang-format [compiler-rt] Use "ColumnLimit: 0" instead of "clang-format off" in tests 2018-12-01 01:24:29 +00:00
CMakeLists.txt [compiler-rt] Disable fuzzer large.test when LLVM_ENABLE_EXPENSIVE_CHECKS=ON 2019-12-03 14:37:37 -08:00
lit.common.cfg.py Only add `darwin_log_cmd` lit shell test feature when the log can be queried. 2020-03-27 11:24:50 -07:00
lit.common.configured.in Revert abb00753 "build: reduce CMake handling for zlib" (PR44780) 2020-03-03 11:03:09 +01:00