Skip to content

Commit 3ce3d88

Browse files
authored
[asan] Re-exec without ASLR if needed on 64-bit Linux (#132682)
This generalizes #131975 to non-32-bit Linux (i.e., 64-bit Linux). This works around an edge case in 64-bit Linux, whereby the memory layout is incompatible if the stack size is unlimited AND ASLR entropy is 31+ bits (see google/sanitizers#856 (comment)). More generally, this "re-exec without ASLR if layout is incompatible" is a hammer that can work around most shadow mapping issues, without incurring the overhead of using a dynamic shadow.
1 parent 567b0f8 commit 3ce3d88

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

compiler-rt/lib/asan/asan_shadow_setup.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,14 @@ void InitializeShadowMemory() {
109109
ProtectGap(kShadowGap2Beg, kShadowGap2End - kShadowGap2Beg + 1);
110110
ProtectGap(kShadowGap3Beg, kShadowGap3End - kShadowGap3Beg + 1);
111111
} else {
112-
// The shadow mappings can shadow the entire user address space. However,
113-
// on 32-bit systems, the maximum ASLR entropy (currently up to 16-bits
114-
// == 256MB) is a significant chunk of the address space; reclaiming it by
115-
// disabling ASLR might allow chonky binaries to run.
116-
if (sizeof(uptr) == 32)
117-
TryReExecWithoutASLR();
112+
// ASan's mappings can usually shadow the entire address space, even with
113+
// maximum ASLR entropy. However:
114+
// - On 32-bit systems, the maximum ASLR entropy (currently up to 16-bits
115+
// == 256MB) is a significant chunk of the address space; reclaiming it
116+
// by disabling ASLR might allow chonky binaries to run.
117+
// - On 64-bit systems, some settings (e.g., for Linux, unlimited stack
118+
// size plus 31+ bits of entropy) can lead to an incompatible layout.
119+
TryReExecWithoutASLR();
118120

119121
Report(
120122
"Shadow memory range interleaves with an existing memory mapping. "

0 commit comments

Comments
 (0)