From d326c811170f304ffcf6d4362996cf4317b3f0f2 Mon Sep 17 00:00:00 2001 From: Evgeniy Stepanov Date: Fri, 11 Apr 2014 12:04:29 +0000 Subject: [PATCH] [msan] mprotect() more memory to detect user code outside of application range. llvm-svn: 206028 --- compiler-rt/lib/msan/msan.cc | 5 ++--- compiler-rt/lib/msan/msan_linux.cc | 6 ++++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/compiler-rt/lib/msan/msan.cc b/compiler-rt/lib/msan/msan.cc index 7f15f4a722b7..f5d6bf45798c 100644 --- a/compiler-rt/lib/msan/msan.cc +++ b/compiler-rt/lib/msan/msan.cc @@ -299,9 +299,8 @@ void __msan_init() { __msan_clear_on_return(); if (__msan_get_track_origins()) VPrintf(1, "msan_track_origins\n"); - if (!InitShadow(/* prot1 */ false, /* prot2 */ true, /* map_shadow */ true, - __msan_get_track_origins())) { - // FIXME: prot1 = false is only required when running under DR. + if (!InitShadow(/* prot1 */ !msan_running_under_dr, /* prot2 */ true, + /* map_shadow */ true, __msan_get_track_origins())) { Printf("FATAL: MemorySanitizer can not mmap the shadow memory.\n"); Printf("FATAL: Make sure to compile with -fPIE and to link with -pie.\n"); Printf("FATAL: Disabling ASLR is known to cause this error.\n"); diff --git a/compiler-rt/lib/msan/msan_linux.cc b/compiler-rt/lib/msan/msan_linux.cc index 9a40279293de..2582ee27ab82 100644 --- a/compiler-rt/lib/msan/msan_linux.cc +++ b/compiler-rt/lib/msan/msan_linux.cc @@ -39,7 +39,7 @@ static const uptr kMemBeg = 0x600000000000; static const uptr kMemEnd = 0x7fffffffffff; static const uptr kShadowBeg = MEM_TO_SHADOW(kMemBeg); static const uptr kShadowEnd = MEM_TO_SHADOW(kMemEnd); -static const uptr kBad1Beg = 0x100000000; // 4G +static const uptr kBad1Beg = 0; static const uptr kBad1End = kShadowBeg - 1; static const uptr kBad2Beg = kShadowEnd + 1; static const uptr kBad2End = kMemBeg - 1; @@ -61,7 +61,9 @@ bool InitShadow(bool prot1, bool prot2, bool map_shadow, bool init_origins) { VPrintf(1, "Bad1 : %p %p\n", kBad1Beg, kBad1End); if (!MemoryRangeIsAvailable(kShadowBeg, - init_origins ? kOriginsEnd : kShadowEnd)) { + init_origins ? kOriginsEnd : kShadowEnd) || + (prot1 && !MemoryRangeIsAvailable(kBad1Beg, kBad1End)) || + (prot2 && !MemoryRangeIsAvailable(kBad2Beg, kBad2End))) { Printf("FATAL: Shadow memory range is not available.\n"); return false; }