Skip to content

Commit 720769d

Browse files
authored
[tsan] Lazily call 'personality' to minimize sandbox violations (#79334)
My previous patch, "Re-exec TSan with no ASLR if memory layout is incompatible on Linux (#78351)" (0784b1e) hoisted the 'personality' call, to share the code between Android and non-Android Linux. Unfortunately, this eager call to 'personality' may trigger sandbox violations on non-Android Linux. This patch fixes the issue by only calling 'personality' on non-Android Linux if the memory mapping is incompatible. This may still cause a sandbox violation, but only if it was going to abort anyway due to an incompatible memory mapping. (The behavior on Android Linux is unchanged by this patch or the previous patch.)
1 parent 0b0cce8 commit 720769d

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

compiler-rt/lib/tsan/rtl/tsan_platform_linux.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,12 +244,12 @@ static void ReExecIfNeeded() {
244244
}
245245

246246
# if SANITIZER_LINUX
247+
# if SANITIZER_ANDROID && (defined(__aarch64__) || defined(__x86_64__))
247248
// ASLR personality check.
248249
int old_personality = personality(0xffffffff);
249250
bool aslr_on =
250251
(old_personality != -1) && ((old_personality & ADDR_NO_RANDOMIZE) == 0);
251252

252-
# if SANITIZER_ANDROID && (defined(__aarch64__) || defined(__x86_64__))
253253
// After patch "arm64: mm: support ARCH_MMAP_RND_BITS." is introduced in
254254
// linux kernel, the random gap between stack and mapped area is increased
255255
// from 128M to 36G on 39-bit aarch64. As it is almost impossible to cover
@@ -267,6 +267,14 @@ static void ReExecIfNeeded() {
267267
if (reexec) {
268268
// Don't check the address space since we're going to re-exec anyway.
269269
} else if (!CheckAndProtect(false, false, false)) {
270+
// ASLR personality check.
271+
// N.B. 'personality' is sometimes forbidden by sandboxes, so we only call
272+
// this as a last resort (when the memory mapping is incompatible and TSan
273+
// would fail anyway).
274+
int old_personality = personality(0xffffffff);
275+
bool aslr_on =
276+
(old_personality != -1) && ((old_personality & ADDR_NO_RANDOMIZE) == 0);
277+
270278
if (aslr_on) {
271279
// Disable ASLR if the memory layout was incompatible.
272280
// Alternatively, we could just keep re-execing until we get lucky

0 commit comments

Comments
 (0)