Reapply all revisions mentioned in LOCAL_PATCHES.

(cherry picked from commit 21bb1625bd)
This commit is contained in:
Martin Liska 2019-11-07 10:34:14 +01:00
parent 0b997f6e07
commit b040b1ce1f
13 changed files with 57 additions and 30 deletions

View File

@ -154,23 +154,6 @@ static void CheckODRViolationViaIndicator(const Global *g) {
} }
} }
// Check ODR violation for given global G by checking if it's already poisoned.
// We use this method in case compiler doesn't use private aliases for global
// variables.
static void CheckODRViolationViaPoisoning(const Global *g) {
if (__asan_region_is_poisoned(g->beg, g->size_with_redzone)) {
// This check may not be enough: if the first global is much larger
// the entire redzone of the second global may be within the first global.
for (ListOfGlobals *l = list_of_all_globals; l; l = l->next) {
if (g->beg == l->g->beg &&
(flags()->detect_odr_violation >= 2 || g->size != l->g->size) &&
!IsODRViolationSuppressed(g->name))
ReportODRViolation(g, FindRegistrationSite(g),
l->g, FindRegistrationSite(l->g));
}
}
}
// Clang provides two different ways for global variables protection: // Clang provides two different ways for global variables protection:
// it can poison the global itself or its private alias. In former // it can poison the global itself or its private alias. In former
// case we may poison same symbol multiple times, that can help us to // case we may poison same symbol multiple times, that can help us to
@ -216,8 +199,6 @@ static void RegisterGlobal(const Global *g) {
// where two globals with the same name are defined in different modules. // where two globals with the same name are defined in different modules.
if (UseODRIndicator(g)) if (UseODRIndicator(g))
CheckODRViolationViaIndicator(g); CheckODRViolationViaIndicator(g);
else
CheckODRViolationViaPoisoning(g);
} }
if (CanPoisonMemory()) if (CanPoisonMemory())
PoisonRedZones(*g); PoisonRedZones(*g);

View File

@ -81,7 +81,12 @@ void InitializePlatformInterceptors();
#if ASAN_HAS_EXCEPTIONS && !SANITIZER_WINDOWS && !SANITIZER_SOLARIS && \ #if ASAN_HAS_EXCEPTIONS && !SANITIZER_WINDOWS && !SANITIZER_SOLARIS && \
!SANITIZER_NETBSD !SANITIZER_NETBSD
# define ASAN_INTERCEPT___CXA_THROW 1 # define ASAN_INTERCEPT___CXA_THROW 1
# define ASAN_INTERCEPT___CXA_RETHROW_PRIMARY_EXCEPTION 1 # if ! defined(ASAN_HAS_CXA_RETHROW_PRIMARY_EXCEPTION) \
|| ASAN_HAS_CXA_RETHROW_PRIMARY_EXCEPTION
# define ASAN_INTERCEPT___CXA_RETHROW_PRIMARY_EXCEPTION 1
# else
# define ASAN_INTERCEPT___CXA_RETHROW_PRIMARY_EXCEPTION 0
# endif
# if defined(_GLIBCXX_SJLJ_EXCEPTIONS) || (SANITIZER_IOS && defined(__arm__)) # if defined(_GLIBCXX_SJLJ_EXCEPTIONS) || (SANITIZER_IOS && defined(__arm__))
# define ASAN_INTERCEPT__UNWIND_SJLJ_RAISEEXCEPTION 1 # define ASAN_INTERCEPT__UNWIND_SJLJ_RAISEEXCEPTION 1
# else # else

View File

@ -178,7 +178,7 @@ static const u64 kAArch64_ShadowOffset64 = 1ULL << 36;
static const u64 kRiscv64_ShadowOffset64 = 0x20000000; static const u64 kRiscv64_ShadowOffset64 = 0x20000000;
static const u64 kMIPS32_ShadowOffset32 = 0x0aaa0000; static const u64 kMIPS32_ShadowOffset32 = 0x0aaa0000;
static const u64 kMIPS64_ShadowOffset64 = 1ULL << 37; static const u64 kMIPS64_ShadowOffset64 = 1ULL << 37;
static const u64 kPPC64_ShadowOffset64 = 1ULL << 44; static const u64 kPPC64_ShadowOffset64 = 1ULL << 41;
static const u64 kSystemZ_ShadowOffset64 = 1ULL << 52; static const u64 kSystemZ_ShadowOffset64 = 1ULL << 52;
static const u64 kSPARC64_ShadowOffset64 = 1ULL << 43; // 0x80000000000 static const u64 kSPARC64_ShadowOffset64 = 1ULL << 43; // 0x80000000000
static const u64 kFreeBSD_ShadowOffset32 = 1ULL << 30; // 0x40000000 static const u64 kFreeBSD_ShadowOffset32 = 1ULL << 30; // 0x40000000

View File

@ -730,9 +730,13 @@ u32 GetNumberOfCPUs() {
#elif SANITIZER_SOLARIS #elif SANITIZER_SOLARIS
return sysconf(_SC_NPROCESSORS_ONLN); return sysconf(_SC_NPROCESSORS_ONLN);
#else #else
#if defined(CPU_COUNT)
cpu_set_t CPUs; cpu_set_t CPUs;
CHECK_EQ(sched_getaffinity(0, sizeof(cpu_set_t), &CPUs), 0); CHECK_EQ(sched_getaffinity(0, sizeof(cpu_set_t), &CPUs), 0);
return CPU_COUNT(&CPUs); return CPU_COUNT(&CPUs);
#else
return 1;
#endif
#endif #endif
} }

View File

@ -37,7 +37,7 @@
extern char **environ; extern char **environ;
#endif #endif
#if defined(__has_include) && __has_include(<os/trace.h>) #if defined(__has_include) && __has_include(<os/trace.h>) && defined(__BLOCKS__)
#define SANITIZER_OS_TRACE 1 #define SANITIZER_OS_TRACE 1
#include <os/trace.h> #include <os/trace.h>
#else #else

View File

@ -26,9 +26,12 @@
// With old kernels (and even new kernels on powerpc) asm/stat.h uses types that // With old kernels (and even new kernels on powerpc) asm/stat.h uses types that
// are not defined anywhere in userspace headers. Fake them. This seems to work // are not defined anywhere in userspace headers. Fake them. This seems to work
// fine with newer headers, too. // fine with newer headers, too. Beware that with <sys/stat.h>, struct stat
// takes the form of struct stat64 on 32-bit platforms if _FILE_OFFSET_BITS=64.
// Also, for some platforms (e.g. mips) there are additional members in the
// <sys/stat.h> struct stat:s.
#include <linux/posix_types.h> #include <linux/posix_types.h>
#if defined(__x86_64__) || defined(__mips__) #if defined(__x86_64__)
#include <sys/stat.h> #include <sys/stat.h>
#else #else
#define ino_t __kernel_ino_t #define ino_t __kernel_ino_t

View File

@ -83,7 +83,7 @@ const unsigned struct_kernel_stat64_sz = 104;
#elif defined(__mips__) #elif defined(__mips__)
const unsigned struct_kernel_stat_sz = SANITIZER_ANDROID const unsigned struct_kernel_stat_sz = SANITIZER_ANDROID
? FIRST_32_SECOND_64(104, 128) ? FIRST_32_SECOND_64(104, 128)
: FIRST_32_SECOND_64(160, 216); : FIRST_32_SECOND_64(144, 216);
const unsigned struct_kernel_stat64_sz = 104; const unsigned struct_kernel_stat64_sz = 104;
#elif defined(__s390__) && !defined(__s390x__) #elif defined(__s390__) && !defined(__s390x__)
const unsigned struct_kernel_stat_sz = 64; const unsigned struct_kernel_stat_sz = 64;

View File

@ -84,8 +84,8 @@ static inline uhwptr *GetCanonicFrame(uptr bp,
// Nope, this does not look right either. This means the frame after next does // Nope, this does not look right either. This means the frame after next does
// not have a valid frame pointer, but we can still extract the caller PC. // not have a valid frame pointer, but we can still extract the caller PC.
// Unfortunately, there is no way to decide between GCC and LLVM frame // Unfortunately, there is no way to decide between GCC and LLVM frame
// layouts. Assume LLVM. // layouts. Assume GCC.
return bp_prev; return bp_prev - 1;
#else #else
return (uhwptr*)bp; return (uhwptr*)bp;
#endif #endif
@ -108,14 +108,21 @@ void BufferedStackTrace::UnwindFast(uptr pc, uptr bp, uptr stack_top,
IsAligned((uptr)frame, sizeof(*frame)) && IsAligned((uptr)frame, sizeof(*frame)) &&
size < max_depth) { size < max_depth) {
#ifdef __powerpc__ #ifdef __powerpc__
// PowerPC ABIs specify that the return address is saved at offset // PowerPC ABIs specify that the return address is saved on the
// 16 of the *caller's* stack frame. Thus we must dereference the // *caller's* stack frame. Thus we must dereference the back chain
// back chain to find the caller frame before extracting it. // to find the caller frame before extracting it.
uhwptr *caller_frame = (uhwptr*)frame[0]; uhwptr *caller_frame = (uhwptr*)frame[0];
if (!IsValidFrame((uptr)caller_frame, stack_top, bottom) || if (!IsValidFrame((uptr)caller_frame, stack_top, bottom) ||
!IsAligned((uptr)caller_frame, sizeof(uhwptr))) !IsAligned((uptr)caller_frame, sizeof(uhwptr)))
break; break;
// For most ABIs the offset where the return address is saved is two
// register sizes. The exception is the SVR4 ABI, which uses an
// offset of only one register size.
#ifdef _CALL_SYSV
uhwptr pc1 = caller_frame[1];
#else
uhwptr pc1 = caller_frame[2]; uhwptr pc1 = caller_frame[2];
#endif
#elif defined(__s390__) #elif defined(__s390__)
uhwptr pc1 = frame[14]; uhwptr pc1 = frame[14];
#elif defined(__riscv) #elif defined(__riscv)

View File

@ -1,5 +1,6 @@
#include "tsan_ppc_regs.h" #include "tsan_ppc_regs.h"
.machine altivec
.section .text .section .text
.hidden __tsan_setjmp .hidden __tsan_setjmp
.globl _setjmp .globl _setjmp

View File

@ -50,6 +50,7 @@ void InitializeFlags() {
{ {
CommonFlags cf; CommonFlags cf;
cf.CopyFrom(*common_flags()); cf.CopyFrom(*common_flags());
cf.print_summary = false;
cf.external_symbolizer_path = GetFlag("UBSAN_SYMBOLIZER_PATH"); cf.external_symbolizer_path = GetFlag("UBSAN_SYMBOLIZER_PATH");
OverrideCommonFlags(cf); OverrideCommonFlags(cf);
} }

View File

@ -894,6 +894,21 @@ void __ubsan_handle_cfi_bad_type(CFICheckFailData *Data, ValueHandle Vtable,
} // namespace __ubsan } // namespace __ubsan
void __ubsan::__ubsan_handle_cfi_bad_icall(CFIBadIcallData *CallData,
ValueHandle Function) {
GET_REPORT_OPTIONS(false);
CFICheckFailData Data = {CFITCK_ICall, CallData->Loc, CallData->Type};
handleCFIBadIcall(&Data, Function, Opts);
}
void __ubsan::__ubsan_handle_cfi_bad_icall_abort(CFIBadIcallData *CallData,
ValueHandle Function) {
GET_REPORT_OPTIONS(true);
CFICheckFailData Data = {CFITCK_ICall, CallData->Loc, CallData->Type};
handleCFIBadIcall(&Data, Function, Opts);
Die();
}
void __ubsan::__ubsan_handle_cfi_check_fail(CFICheckFailData *Data, void __ubsan::__ubsan_handle_cfi_check_fail(CFICheckFailData *Data,
ValueHandle Value, ValueHandle Value,
uptr ValidVtable) { uptr ValidVtable) {

View File

@ -215,12 +215,20 @@ enum CFITypeCheckKind : unsigned char {
CFITCK_VMFCall, CFITCK_VMFCall,
}; };
struct CFIBadIcallData {
SourceLocation Loc;
const TypeDescriptor &Type;
};
struct CFICheckFailData { struct CFICheckFailData {
CFITypeCheckKind CheckKind; CFITypeCheckKind CheckKind;
SourceLocation Loc; SourceLocation Loc;
const TypeDescriptor &Type; const TypeDescriptor &Type;
}; };
/// \brief Handle control flow integrity failure for indirect function calls.
RECOVERABLE(cfi_bad_icall, CFIBadIcallData *Data, ValueHandle Function)
/// \brief Handle control flow integrity failures. /// \brief Handle control flow integrity failures.
RECOVERABLE(cfi_check_fail, CFICheckFailData *Data, ValueHandle Function, RECOVERABLE(cfi_check_fail, CFICheckFailData *Data, ValueHandle Function,
uptr VtableIsValid) uptr VtableIsValid)

View File

@ -12,6 +12,7 @@
#ifndef UBSAN_PLATFORM_H #ifndef UBSAN_PLATFORM_H
#define UBSAN_PLATFORM_H #define UBSAN_PLATFORM_H
#ifndef CAN_SANITIZE_UB
// Other platforms should be easy to add, and probably work as-is. // Other platforms should be easy to add, and probably work as-is.
#if defined(__linux__) || defined(__FreeBSD__) || defined(__APPLE__) || \ #if defined(__linux__) || defined(__FreeBSD__) || defined(__APPLE__) || \
defined(__NetBSD__) || defined(__OpenBSD__) || \ defined(__NetBSD__) || defined(__OpenBSD__) || \
@ -21,5 +22,6 @@
#else #else
# define CAN_SANITIZE_UB 0 # define CAN_SANITIZE_UB 0
#endif #endif
#endif //CAN_SANITIZE_UB
#endif #endif