Reapply all revisions mentioned in LOCAL_PATCHES.
authorMartin Liska <mliska@suse.cz>
Tue, 5 Nov 2019 13:55:27 +0000 (14:55 +0100)
committerMartin Liska <marxin@gcc.gnu.org>
Tue, 5 Nov 2019 13:55:27 +0000 (13:55 +0000)
2019-11-05  Martin Liska  <mliska@suse.cz>

* asan/asan_globals.cpp (CheckODRViolationViaIndicator): Reapply from
LOCAL_PATCHES.
(CheckODRViolationViaPoisoning): Likewise.
(RegisterGlobal): Likewise.
* asan/asan_interceptors.h (ASAN_INTERCEPT___CXA_RETHROW_PRIMARY_EXCEPTION): Likewise.
(defined): Likewise.
* asan/asan_mapping.h: Likewise.
* sanitizer_common/sanitizer_linux_libcdep.cpp (defined): Likewise.
* sanitizer_common/sanitizer_mac.cpp (defined): Likewise.
* sanitizer_common/sanitizer_platform_limits_linux.cpp (defined): Likewise.
* sanitizer_common/sanitizer_platform_limits_posix.h: Likewise.
* sanitizer_common/sanitizer_stacktrace.cpp (GetCanonicFrame): Likewise.
* tsan/tsan_rtl_ppc64.S: Likewise.
* ubsan/ubsan_handlers.cpp (__ubsan::__ubsan_handle_cfi_bad_icall): Likewise.
(__ubsan::__ubsan_handle_cfi_bad_icall_abort): Likewise.
* ubsan/ubsan_handlers.h (struct CFIBadIcallData): Likewise.
(struct CFICheckFailData): Likewise.
(RECOVERABLE): Likewise.
* ubsan/ubsan_platform.h: Likewise.

From-SVN: r277836

13 files changed:
libsanitizer/ChangeLog
libsanitizer/asan/asan_globals.cpp
libsanitizer/asan/asan_interceptors.h
libsanitizer/asan/asan_mapping.h
libsanitizer/sanitizer_common/sanitizer_linux_libcdep.cpp
libsanitizer/sanitizer_common/sanitizer_mac.cpp
libsanitizer/sanitizer_common/sanitizer_platform_limits_linux.cpp
libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.h
libsanitizer/sanitizer_common/sanitizer_stacktrace.cpp
libsanitizer/tsan/tsan_rtl_ppc64.S
libsanitizer/ubsan/ubsan_handlers.cpp
libsanitizer/ubsan/ubsan_handlers.h
libsanitizer/ubsan/ubsan_platform.h

index 7dee22c19bd88f52892f9e83fea42d5e472942a9..5f4124f291963675942cdfc10213d791835aea98 100644 (file)
@@ -1,3 +1,25 @@
+2019-11-05  Martin Liska  <mliska@suse.cz>
+
+       * asan/asan_globals.cpp (CheckODRViolationViaIndicator): Reapply from
+       LOCAL_PATCHES.
+       (CheckODRViolationViaPoisoning): Likewise.
+       (RegisterGlobal): Likewise.
+       * asan/asan_interceptors.h (ASAN_INTERCEPT___CXA_RETHROW_PRIMARY_EXCEPTION): Likewise.
+       (defined): Likewise.
+       * asan/asan_mapping.h: Likewise.
+       * sanitizer_common/sanitizer_linux_libcdep.cpp (defined): Likewise.
+       * sanitizer_common/sanitizer_mac.cpp (defined): Likewise.
+       * sanitizer_common/sanitizer_platform_limits_linux.cpp (defined): Likewise.
+       * sanitizer_common/sanitizer_platform_limits_posix.h: Likewise.
+       * sanitizer_common/sanitizer_stacktrace.cpp (GetCanonicFrame): Likewise.
+       * tsan/tsan_rtl_ppc64.S: Likewise.
+       * ubsan/ubsan_handlers.cpp (__ubsan::__ubsan_handle_cfi_bad_icall): Likewise.
+       (__ubsan::__ubsan_handle_cfi_bad_icall_abort): Likewise.
+       * ubsan/ubsan_handlers.h (struct CFIBadIcallData): Likewise.
+       (struct CFICheckFailData): Likewise.
+       (RECOVERABLE): Likewise.
+       * ubsan/ubsan_platform.h: Likewise.
+
 2019-11-05  Martin Liska  <mliska@suse.cz>
 
        * tsan/Makefile.am: Rename tsan_interceptors.cpp to
index 9d7dbc6f264cea7b80a71a91da37cfa0cfbbd0db..e045c31cd1c38ec4258a1857ced145934b2aa90c 100644 (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:
 // 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
@@ -216,8 +199,6 @@ static void RegisterGlobal(const Global *g) {
     // where two globals with the same name are defined in different modules.
     if (UseODRIndicator(g))
       CheckODRViolationViaIndicator(g);
-    else
-      CheckODRViolationViaPoisoning(g);
   }
   if (CanPoisonMemory())
     PoisonRedZones(*g);
index 344a64bd83d330553bca41f066b004092b6632df..b7a85fedbdfd4d69a1abf0d5cb0a4ced2d183079 100644 (file)
@@ -80,7 +80,12 @@ void InitializePlatformInterceptors();
 #if ASAN_HAS_EXCEPTIONS && !SANITIZER_WINDOWS && !SANITIZER_SOLARIS && \
     !SANITIZER_NETBSD
 # 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__))
 #  define ASAN_INTERCEPT__UNWIND_SJLJ_RAISEEXCEPTION 1
 # else
index 41fb49ee46d460774a487c638b2c58531b8ac8d0..09be904270cedbb1bed9736dd3a616463180c83b 100644 (file)
@@ -163,7 +163,7 @@ static const u64 kDefaultShort64bitShadowOffset =
 static const u64 kAArch64_ShadowOffset64 = 1ULL << 36;
 static const u64 kMIPS32_ShadowOffset32 = 0x0aaa0000;
 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 kSPARC64_ShadowOffset64 = 1ULL << 43;  // 0x80000000000
 static const u64 kFreeBSD_ShadowOffset32 = 1ULL << 30;  // 0x40000000
index cd503718205a18807445b65c126296005d3ecd77..e09d568d8024863f7d97861cb2d9e246740083a5 100644 (file)
@@ -698,9 +698,13 @@ u32 GetNumberOfCPUs() {
 #elif SANITIZER_SOLARIS
   return sysconf(_SC_NPROCESSORS_ONLN);
 #else
+#if defined(CPU_COUNT)
   cpu_set_t CPUs;
   CHECK_EQ(sched_getaffinity(0, sizeof(cpu_set_t), &CPUs), 0);
   return CPU_COUNT(&CPUs);
+#else
+  return 1;
+#endif
 #endif
 }
 
index ea4bd02aa92e4580bcf4f1c49a540722d70af9b7..b971ad058e9f6d8cf78defe7eb130f6b9cf66273 100644 (file)
@@ -37,7 +37,7 @@
 extern char **environ;
 #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
 #include <os/trace.h>
 #else
index 842bc789f4793117134a82a7fe18a8cc60dbf5ce..7c1a21d6ccb322a9e4016ea5decc6b4b68937865 100644 (file)
 
 // 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
-// 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>
-#if defined(__x86_64__) ||  defined(__mips__)
+#if defined(__x86_64__)
 #include <sys/stat.h>
 #else
 #define ino_t __kernel_ino_t
index db2c4f07b3ae4f91f3549f4e695a8304e89369d8..738bc3fd721689b5f84eab01c0355e2be3e56c52 100644 (file)
@@ -82,7 +82,7 @@ const unsigned struct_kernel_stat64_sz = 104;
 #elif defined(__mips__)
 const unsigned struct_kernel_stat_sz = SANITIZER_ANDROID
                                            ? 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;
 #elif defined(__s390__) && !defined(__s390x__)
 const unsigned struct_kernel_stat_sz = 64;
index ef14fb704eed394acf0be36505eaae5f952fa6d2..ce75cbe5d265094329e3f770e5f0ed19b9a455f4 100644 (file)
@@ -60,8 +60,8 @@ static inline uhwptr *GetCanonicFrame(uptr bp,
   // 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.
   // Unfortunately, there is no way to decide between GCC and LLVM frame
-  // layouts. Assume LLVM.
-  return bp_prev;
+  // layouts. Assume GCC.
+  return bp_prev - 1;
 #else
   return (uhwptr*)bp;
 #endif
@@ -84,14 +84,21 @@ void BufferedStackTrace::UnwindFast(uptr pc, uptr bp, uptr stack_top,
          IsAligned((uptr)frame, sizeof(*frame)) &&
          size < max_depth) {
 #ifdef __powerpc__
-    // PowerPC ABIs specify that the return address is saved at offset
-    // 16 of the *caller's* stack frame.  Thus we must dereference the
-    // back chain to find the caller frame before extracting it.
+    // PowerPC ABIs specify that the return address is saved on the
+    // *caller's* stack frame.  Thus we must dereference the back chain
+    // to find the caller frame before extracting it.
     uhwptr *caller_frame = (uhwptr*)frame[0];
     if (!IsValidFrame((uptr)caller_frame, stack_top, bottom) ||
         !IsAligned((uptr)caller_frame, sizeof(uhwptr)))
       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];
+#endif
 #elif defined(__s390__)
     uhwptr pc1 = frame[14];
 #else
index 8285e21aa1ec7a797dfcf4840ee5a7851106b497..9e533a71a9c477ecae59f09ab431b2664554d998 100644 (file)
@@ -1,5 +1,6 @@
 #include "tsan_ppc_regs.h"
 
+        .machine altivec
         .section .text
         .hidden __tsan_setjmp
         .globl _setjmp
index 3f9da75a12a8d34386977ba9e959eda2af27f298..0ddbb50c26cc3da00980867be7811ab5e3f41a1b 100644 (file)
@@ -819,6 +819,21 @@ void __ubsan_handle_cfi_bad_type(CFICheckFailData *Data, ValueHandle Vtable,
 
 }  // 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,
                                             ValueHandle Value,
                                             uptr ValidVtable) {
index 22ca96422381c104798588f64c5ae370f3ef2f07..eba1cf918fc34796fdaaf0d458984e197758e43c 100644 (file)
@@ -207,12 +207,20 @@ enum CFITypeCheckKind : unsigned char {
   CFITCK_VMFCall,
 };
 
+struct CFIBadIcallData {
+  SourceLocation Loc;
+  const TypeDescriptor &Type;
+};
+
 struct CFICheckFailData {
   CFITypeCheckKind CheckKind;
   SourceLocation Loc;
   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.
 RECOVERABLE(cfi_check_fail, CFICheckFailData *Data, ValueHandle Function,
             uptr VtableIsValid)
index 71d7fb18c9b3a5e94039e3843113050f31fa1c9f..58aabbe67b5c25e0b47b03a848182691de2252a7 100644 (file)
@@ -12,6 +12,7 @@
 #ifndef UBSAN_PLATFORM_H
 #define UBSAN_PLATFORM_H
 
+#ifndef CAN_SANITIZE_UB
 // Other platforms should be easy to add, and probably work as-is.
 #if defined(__linux__) || defined(__FreeBSD__) || defined(__APPLE__) ||        \
     defined(__NetBSD__) || defined(__OpenBSD__) || \
@@ -21,5 +22,6 @@
 #else
 # define CAN_SANITIZE_UB 0
 #endif
+#endif //CAN_SANITIZE_UB
 
 #endif