[asan] Do not sanitize kernel area on 32-bit targets, patch by Yuri Gribov

llvm-svn: 204897
This commit is contained in:
Kostya Serebryany 2014-03-27 07:36:26 +00:00
parent 4cbd0d9dc2
commit 88d0eac412
4 changed files with 41 additions and 3 deletions

View File

@ -43,13 +43,22 @@
// || `[0x00007fff8000, 0x00008fff6fff]` || LowShadow ||
// || `[0x000000000000, 0x00007fff7fff]` || LowMem ||
//
// Default Linux/i386 mapping:
// Default Linux/i386 mapping on x86_64 machine:
// || `[0x40000000, 0xffffffff]` || HighMem ||
// || `[0x28000000, 0x3fffffff]` || HighShadow ||
// || `[0x24000000, 0x27ffffff]` || ShadowGap ||
// || `[0x20000000, 0x23ffffff]` || LowShadow ||
// || `[0x00000000, 0x1fffffff]` || LowMem ||
//
// Default Linux/i386 mapping on i386 machine
// (addresses starting with 0xc0000000 are reserved
// for kernel and thus not sanitized):
// || `[0x38000000, 0xbfffffff]` || HighMem ||
// || `[0x27000000, 0x37ffffff]` || HighShadow ||
// || `[0x24000000, 0x26ffffff]` || ShadowGap ||
// || `[0x20000000, 0x23ffffff]` || LowShadow ||
// || `[0x00000000, 0x1fffffff]` || LowMem ||
//
// Default Linux/MIPS mapping:
// || `[0x2aaa8000, 0xffffffff]` || HighMem ||
// || `[0x0fffd000, 0x2aaa7fff]` || HighShadow ||

View File

@ -565,6 +565,7 @@ static void AsanInitInternal() {
ReserveShadowMemoryRange(kHighShadowBeg, kHighShadowEnd);
// protect the gap.
ProtectGap(kShadowGapBeg, kShadowGapEnd - kShadowGapBeg + 1);
CHECK_EQ(kShadowGapEnd, kHighShadowBeg - 1);
} else if (kMidMemBeg &&
MemoryRangeIsAvailable(shadow_start, kMidMemBeg - 1) &&
MemoryRangeIsAvailable(kMidMemEnd + 1, kHighShadowEnd)) {

View File

@ -22,6 +22,10 @@
#include <sys/mman.h>
#if SANITIZER_LINUX
#include <sys/utsname.h>
#endif
namespace __sanitizer {
// ------------- sanitizer_common.h
@ -29,6 +33,21 @@ uptr GetMmapGranularity() {
return GetPageSize();
}
#if SANITIZER_WORDSIZE == 32
// Take care of unusable kernel area in top gigabyte
static uptr GetKernelStartAddress() {
#if SANITIZER_LINUX
// 64-bit Linux provides 32-bit apps with full address space
struct utsname uname_info;
return 0 == uname(&uname_info) && !internal_strstr(uname_info.machine, "64")
? 1ULL << 30
: 0;
#else
return 0;
#endif // SANITIZER_LINUX
}
#endif // SANITIZER_WORDSIZE == 32
uptr GetMaxVirtualAddress() {
#if SANITIZER_WORDSIZE == 64
# if defined(__powerpc64__)
@ -44,8 +63,10 @@ uptr GetMaxVirtualAddress() {
return (1ULL << 47) - 1; // 0x00007fffffffffffUL;
# endif
#else // SANITIZER_WORDSIZE == 32
// FIXME: We can probably lower this on Android?
return (1ULL << 32) - 1; // 0xffffffff;
uptr res = (1ULL << 32) - 1; // 0xffffffff;
res -= GetKernelStartAddress();
CHECK_LT(reinterpret_cast<uptr>(&res), res);
return res;
#endif // SANITIZER_WORDSIZE
}

View File

@ -60,8 +60,15 @@ if not os.path.exists(asan_symbolize):
python_exec = get_required_attr(config, "python_executable")
config.substitutions.append( ("%asan_symbolize", python_exec + " " + asan_symbolize + " ") )
# Determine kernel bitness
if config.host_arch.find('64') != -1 and config.android != "TRUE":
kernel_bits = '64'
else:
kernel_bits = '32'
# Define CHECK-%os to check for OS-dependent output.
config.substitutions.append( ('CHECK-%os', ("CHECK-" + config.host_os)))
config.substitutions.append( ('CHECK-%kernel_bits', ("CHECK-kernel-" + kernel_bits + "-bits")))
config.available_features.add("asan-" + config.bits + "-bits")