Commit cb7dc4da by Martin Liska Committed by Martin Liska

Libsanitizer: merge from trunk

2019-11-07  Martin Liska  <mliska@suse.cz>

	* merge.sh: Update to use llvm-project git repository.
	* all source files: Merge from upstream
	82588e05cc32bb30807e480abd4e689b0dee132a.

From-SVN: r277909
parent 29f3def3
2019-11-07 Martin Liska <mliska@suse.cz>
* merge.sh: Update to use llvm-project git repository.
* all source files: Merge from upstream
82588e05cc32bb30807e480abd4e689b0dee132a.
2019-11-05 Martin Liska <mliska@suse.cz> 2019-11-05 Martin Liska <mliska@suse.cz>
* ubsan/ubsan_flags.cpp (InitializeFlags): Trunk decided to print * ubsan/ubsan_flags.cpp (InitializeFlags): Trunk decided to print
......
375507 82588e05cc32bb30807e480abd4e689b0dee132a
The first line of this file holds the svn revision number of the The first line of this file holds the git revision number of the
last merge done from the master library sources. last merge done from the master library sources.
...@@ -246,6 +246,7 @@ struct Allocator { ...@@ -246,6 +246,7 @@ struct Allocator {
AllocatorCache fallback_allocator_cache; AllocatorCache fallback_allocator_cache;
QuarantineCache fallback_quarantine_cache; QuarantineCache fallback_quarantine_cache;
uptr max_user_defined_malloc_size;
atomic_uint8_t rss_limit_exceeded; atomic_uint8_t rss_limit_exceeded;
// ------------------- Options -------------------------- // ------------------- Options --------------------------
...@@ -280,6 +281,10 @@ struct Allocator { ...@@ -280,6 +281,10 @@ struct Allocator {
SetAllocatorMayReturnNull(options.may_return_null); SetAllocatorMayReturnNull(options.may_return_null);
allocator.InitLinkerInitialized(options.release_to_os_interval_ms); allocator.InitLinkerInitialized(options.release_to_os_interval_ms);
SharedInitCode(options); SharedInitCode(options);
max_user_defined_malloc_size = common_flags()->max_allocation_size_mb
? common_flags()->max_allocation_size_mb
<< 20
: kMaxAllowedMallocSize;
} }
bool RssLimitExceeded() { bool RssLimitExceeded() {
...@@ -394,6 +399,16 @@ struct Allocator { ...@@ -394,6 +399,16 @@ struct Allocator {
return right_chunk; return right_chunk;
} }
bool UpdateAllocationStack(uptr addr, BufferedStackTrace *stack) {
AsanChunk *m = GetAsanChunkByAddr(addr);
if (!m) return false;
if (m->chunk_state != CHUNK_ALLOCATED) return false;
if (m->Beg() != addr) return false;
atomic_store((atomic_uint32_t *)&m->alloc_context_id, StackDepotPut(*stack),
memory_order_relaxed);
return true;
}
// -------------------- Allocation/Deallocation routines --------------- // -------------------- Allocation/Deallocation routines ---------------
void *Allocate(uptr size, uptr alignment, BufferedStackTrace *stack, void *Allocate(uptr size, uptr alignment, BufferedStackTrace *stack,
AllocType alloc_type, bool can_fill) { AllocType alloc_type, bool can_fill) {
...@@ -435,14 +450,16 @@ struct Allocator { ...@@ -435,14 +450,16 @@ struct Allocator {
using_primary_allocator = false; using_primary_allocator = false;
} }
CHECK(IsAligned(needed_size, min_alignment)); CHECK(IsAligned(needed_size, min_alignment));
if (size > kMaxAllowedMallocSize || needed_size > kMaxAllowedMallocSize) { if (size > kMaxAllowedMallocSize || needed_size > kMaxAllowedMallocSize ||
size > max_user_defined_malloc_size) {
if (AllocatorMayReturnNull()) { if (AllocatorMayReturnNull()) {
Report("WARNING: AddressSanitizer failed to allocate 0x%zx bytes\n", Report("WARNING: AddressSanitizer failed to allocate 0x%zx bytes\n",
(void*)size); (void*)size);
return nullptr; return nullptr;
} }
ReportAllocationSizeTooBig(size, needed_size, kMaxAllowedMallocSize, uptr malloc_limit =
stack); Min(kMaxAllowedMallocSize, max_user_defined_malloc_size);
ReportAllocationSizeTooBig(size, needed_size, malloc_limit, stack);
} }
AsanThread *t = GetCurrentThread(); AsanThread *t = GetCurrentThread();
...@@ -1105,6 +1122,11 @@ void __sanitizer_purge_allocator() { ...@@ -1105,6 +1122,11 @@ void __sanitizer_purge_allocator() {
instance.Purge(&stack); instance.Purge(&stack);
} }
int __asan_update_allocation_context(void* addr) {
GET_STACK_TRACE_MALLOC;
return instance.UpdateAllocationStack((uptr)addr, &stack);
}
#if !SANITIZER_SUPPORTS_WEAK_HOOKS #if !SANITIZER_SUPPORTS_WEAK_HOOKS
// Provide default (no-op) implementation of malloc hooks. // Provide default (no-op) implementation of malloc hooks.
SANITIZER_INTERFACE_WEAK_DEF(void, __sanitizer_malloc_hook, SANITIZER_INTERFACE_WEAK_DEF(void, __sanitizer_malloc_hook,
......
...@@ -154,6 +154,23 @@ static void CheckODRViolationViaIndicator(const Global *g) { ...@@ -154,6 +154,23 @@ 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
...@@ -199,6 +216,8 @@ static void RegisterGlobal(const Global *g) { ...@@ -199,6 +216,8 @@ 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);
......
...@@ -80,12 +80,7 @@ void InitializePlatformInterceptors(); ...@@ -80,12 +80,7 @@ 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
# if ! defined(ASAN_HAS_CXA_RETHROW_PRIMARY_EXCEPTION) \ # define ASAN_INTERCEPT___CXA_RETHROW_PRIMARY_EXCEPTION 1
|| 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
......
...@@ -164,6 +164,7 @@ INTERFACE_FUNCTION(__sanitizer_unaligned_load64) ...@@ -164,6 +164,7 @@ INTERFACE_FUNCTION(__sanitizer_unaligned_load64)
INTERFACE_FUNCTION(__sanitizer_unaligned_store16) INTERFACE_FUNCTION(__sanitizer_unaligned_store16)
INTERFACE_FUNCTION(__sanitizer_unaligned_store32) INTERFACE_FUNCTION(__sanitizer_unaligned_store32)
INTERFACE_FUNCTION(__sanitizer_unaligned_store64) INTERFACE_FUNCTION(__sanitizer_unaligned_store64)
INTERFACE_FUNCTION(__asan_update_allocation_context)
INTERFACE_WEAK_FUNCTION(__asan_default_options) INTERFACE_WEAK_FUNCTION(__asan_default_options)
INTERFACE_WEAK_FUNCTION(__asan_default_suppressions) INTERFACE_WEAK_FUNCTION(__asan_default_suppressions)
INTERFACE_WEAK_FUNCTION(__asan_on_error) INTERFACE_WEAK_FUNCTION(__asan_on_error)
...@@ -251,6 +251,9 @@ extern "C" { ...@@ -251,6 +251,9 @@ extern "C" {
const char* __asan_default_suppressions(); const char* __asan_default_suppressions();
SANITIZER_INTERFACE_ATTRIBUTE void __asan_handle_vfork(void *sp); SANITIZER_INTERFACE_ATTRIBUTE void __asan_handle_vfork(void *sp);
SANITIZER_INTERFACE_ATTRIBUTE int __asan_update_allocation_context(
void *addr);
} // extern "C" } // extern "C"
#endif // ASAN_INTERFACE_INTERNAL_H #endif // ASAN_INTERFACE_INTERNAL_H
...@@ -35,11 +35,8 @@ constexpr unsigned long HEAP_REALLOC_IN_PLACE_ONLY = 0x00000010; ...@@ -35,11 +35,8 @@ constexpr unsigned long HEAP_REALLOC_IN_PLACE_ONLY = 0x00000010;
constexpr unsigned long HEAP_ALLOCATE_SUPPORTED_FLAGS = (HEAP_ZERO_MEMORY); constexpr unsigned long HEAP_ALLOCATE_SUPPORTED_FLAGS = (HEAP_ZERO_MEMORY);
constexpr unsigned long HEAP_ALLOCATE_UNSUPPORTED_FLAGS = constexpr unsigned long HEAP_ALLOCATE_UNSUPPORTED_FLAGS =
(~HEAP_ALLOCATE_SUPPORTED_FLAGS); (~HEAP_ALLOCATE_SUPPORTED_FLAGS);
constexpr unsigned long HEAP_FREE_SUPPORTED_FLAGS = (0);
constexpr unsigned long HEAP_FREE_UNSUPPORTED_FLAGS = constexpr unsigned long HEAP_FREE_UNSUPPORTED_FLAGS =
(~HEAP_ALLOCATE_SUPPORTED_FLAGS); (~HEAP_ALLOCATE_SUPPORTED_FLAGS);
constexpr unsigned long HEAP_REALLOC_SUPPORTED_FLAGS =
(HEAP_REALLOC_IN_PLACE_ONLY | HEAP_ZERO_MEMORY);
constexpr unsigned long HEAP_REALLOC_UNSUPPORTED_FLAGS = constexpr unsigned long HEAP_REALLOC_UNSUPPORTED_FLAGS =
(~HEAP_ALLOCATE_SUPPORTED_FLAGS); (~HEAP_ALLOCATE_SUPPORTED_FLAGS);
......
...@@ -163,7 +163,7 @@ static const u64 kDefaultShort64bitShadowOffset = ...@@ -163,7 +163,7 @@ static const u64 kDefaultShort64bitShadowOffset =
static const u64 kAArch64_ShadowOffset64 = 1ULL << 36; static const u64 kAArch64_ShadowOffset64 = 1ULL << 36;
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 << 41; static const u64 kPPC64_ShadowOffset64 = 1ULL << 44;
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
......
...@@ -315,6 +315,10 @@ void *__asan_addr_is_in_fake_stack(void *fake_stack, void *addr, void **beg, ...@@ -315,6 +315,10 @@ void *__asan_addr_is_in_fake_stack(void *fake_stack, void *addr, void **beg,
/// functions like <c>_exit()</c> and <c>execl()</c>. /// functions like <c>_exit()</c> and <c>execl()</c>.
void __asan_handle_no_return(void); void __asan_handle_no_return(void);
/// Update allocation stack trace for the given allocation to the current stack
/// trace. Returns 1 if successfull, 0 if not.
int __asan_update_allocation_context(void* addr);
#ifdef __cplusplus #ifdef __cplusplus
} // extern "C" } // extern "C"
#endif #endif
......
...@@ -36,10 +36,17 @@ static const uptr kMaxAllowedMallocSize = 8UL << 30; ...@@ -36,10 +36,17 @@ static const uptr kMaxAllowedMallocSize = 8UL << 30;
static Allocator allocator; static Allocator allocator;
static uptr max_malloc_size;
void InitializeAllocator() { void InitializeAllocator() {
SetAllocatorMayReturnNull(common_flags()->allocator_may_return_null); SetAllocatorMayReturnNull(common_flags()->allocator_may_return_null);
allocator.InitLinkerInitialized( allocator.InitLinkerInitialized(
common_flags()->allocator_release_to_os_interval_ms); common_flags()->allocator_release_to_os_interval_ms);
if (common_flags()->max_allocation_size_mb)
max_malloc_size = Min(common_flags()->max_allocation_size_mb << 20,
kMaxAllowedMallocSize);
else
max_malloc_size = kMaxAllowedMallocSize;
} }
void AllocatorThreadFinish() { void AllocatorThreadFinish() {
...@@ -72,14 +79,14 @@ static void *ReportAllocationSizeTooBig(uptr size, const StackTrace &stack) { ...@@ -72,14 +79,14 @@ static void *ReportAllocationSizeTooBig(uptr size, const StackTrace &stack) {
Report("WARNING: LeakSanitizer failed to allocate 0x%zx bytes\n", size); Report("WARNING: LeakSanitizer failed to allocate 0x%zx bytes\n", size);
return nullptr; return nullptr;
} }
ReportAllocationSizeTooBig(size, kMaxAllowedMallocSize, &stack); ReportAllocationSizeTooBig(size, max_malloc_size, &stack);
} }
void *Allocate(const StackTrace &stack, uptr size, uptr alignment, void *Allocate(const StackTrace &stack, uptr size, uptr alignment,
bool cleared) { bool cleared) {
if (size == 0) if (size == 0)
size = 1; size = 1;
if (size > kMaxAllowedMallocSize) if (size > max_malloc_size)
return ReportAllocationSizeTooBig(size, stack); return ReportAllocationSizeTooBig(size, stack);
void *p = allocator.Allocate(GetAllocatorCache(), size, alignment); void *p = allocator.Allocate(GetAllocatorCache(), size, alignment);
if (UNLIKELY(!p)) { if (UNLIKELY(!p)) {
...@@ -117,7 +124,7 @@ void Deallocate(void *p) { ...@@ -117,7 +124,7 @@ void Deallocate(void *p) {
void *Reallocate(const StackTrace &stack, void *p, uptr new_size, void *Reallocate(const StackTrace &stack, void *p, uptr new_size,
uptr alignment) { uptr alignment) {
RegisterDeallocation(p); RegisterDeallocation(p);
if (new_size > kMaxAllowedMallocSize) { if (new_size > max_malloc_size) {
allocator.Deallocate(GetAllocatorCache(), p); allocator.Deallocate(GetAllocatorCache(), p);
return ReportAllocationSizeTooBig(new_size, stack); return ReportAllocationSizeTooBig(new_size, stack);
} }
......
...@@ -8,13 +8,12 @@ VCS=${1:-svn} ...@@ -8,13 +8,12 @@ VCS=${1:-svn}
get_upstream() { get_upstream() {
rm -rf upstream rm -rf upstream
#cp -rf orig upstream git clone https://github.com/llvm/llvm-project.git upstream
svn co http://llvm.org/svn/llvm-project/compiler-rt/trunk upstream
} }
get_current_rev() { get_current_rev() {
cd upstream cd upstream
svn info | grep Revision | grep -o '[0-9]*' git rev-parse HEAD
} }
list_files() { list_files() {
...@@ -85,6 +84,6 @@ rm -rf upstream ...@@ -85,6 +84,6 @@ rm -rf upstream
cat << EOF > MERGE cat << EOF > MERGE
$CUR_REV $CUR_REV
The first line of this file holds the svn revision number of the The first line of this file holds the git revision number of the
last merge done from the master library sources. last merge done from the master library sources.
EOF EOF
...@@ -132,6 +132,9 @@ COMMON_FLAG(uptr, soft_rss_limit_mb, 0, ...@@ -132,6 +132,9 @@ COMMON_FLAG(uptr, soft_rss_limit_mb, 0,
" until the RSS goes below the soft limit." " until the RSS goes below the soft limit."
" This limit does not affect memory allocations other than" " This limit does not affect memory allocations other than"
" malloc/new.") " malloc/new.")
COMMON_FLAG(uptr, max_allocation_size_mb, 0,
"If non-zero, malloc/new calls larger than this size will return "
"nullptr (or crash if allocator_may_return_null=false).")
COMMON_FLAG(bool, heap_profile, false, "Experimental heap profiler, asan-only") COMMON_FLAG(bool, heap_profile, false, "Experimental heap profiler, asan-only")
COMMON_FLAG(s32, allocator_release_to_os_interval_ms, COMMON_FLAG(s32, allocator_release_to_os_interval_ms,
((bool)SANITIZER_FUCHSIA || (bool)SANITIZER_WINDOWS) ? -1 : 5000, ((bool)SANITIZER_FUCHSIA || (bool)SANITIZER_WINDOWS) ? -1 : 5000,
......
...@@ -407,7 +407,10 @@ uptr internal_unlink(const char *path) { ...@@ -407,7 +407,10 @@ uptr internal_unlink(const char *path) {
} }
uptr internal_rename(const char *oldpath, const char *newpath) { uptr internal_rename(const char *oldpath, const char *newpath) {
#if SANITIZER_USES_CANONICAL_LINUX_SYSCALLS || SANITIZER_OPENBSD #if defined(__riscv)
return internal_syscall(SYSCALL(renameat2), AT_FDCWD, (uptr)oldpath, AT_FDCWD,
(uptr)newpath, 0);
#elif SANITIZER_USES_CANONICAL_LINUX_SYSCALLS || SANITIZER_OPENBSD
return internal_syscall(SYSCALL(renameat), AT_FDCWD, (uptr)oldpath, AT_FDCWD, return internal_syscall(SYSCALL(renameat), AT_FDCWD, (uptr)oldpath, AT_FDCWD,
(uptr)newpath); (uptr)newpath);
#else #else
...@@ -1972,6 +1975,11 @@ static void GetPcSpBp(void *context, uptr *pc, uptr *sp, uptr *bp) { ...@@ -1972,6 +1975,11 @@ static void GetPcSpBp(void *context, uptr *pc, uptr *sp, uptr *bp) {
# endif # endif
*bp = ucontext->uc_mcontext.gregs[11]; *bp = ucontext->uc_mcontext.gregs[11];
*sp = ucontext->uc_mcontext.gregs[15]; *sp = ucontext->uc_mcontext.gregs[15];
#elif defined(__riscv)
ucontext_t *ucontext = (ucontext_t*)context;
*pc = ucontext->uc_mcontext.__gregs[REG_PC];
*bp = ucontext->uc_mcontext.__gregs[REG_S0];
*sp = ucontext->uc_mcontext.__gregs[REG_SP];
#else #else
# error "Unsupported arch" # error "Unsupported arch"
#endif #endif
......
...@@ -698,13 +698,9 @@ u32 GetNumberOfCPUs() { ...@@ -698,13 +698,9 @@ 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
} }
......
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
extern char **environ; extern char **environ;
#endif #endif
#if defined(__has_include) && __has_include(<os/trace.h>) && defined(__BLOCKS__) #if defined(__has_include) && __has_include(<os/trace.h>)
#define SANITIZER_OS_TRACE 1 #define SANITIZER_OS_TRACE 1
#include <os/trace.h> #include <os/trace.h>
#else #else
......
...@@ -255,11 +255,11 @@ ...@@ -255,11 +255,11 @@
#define SANITIZER_SIGN_EXTENDED_ADDRESSES 0 #define SANITIZER_SIGN_EXTENDED_ADDRESSES 0
#endif #endif
// The AArch64 linux port uses the canonical syscall set as mandated by // The AArch64 and RISC-V linux ports use the canonical syscall set as
// the upstream linux community for all new ports. Other ports may still // mandated by the upstream linux community for all new ports. Other ports
// use legacy syscalls. // may still use legacy syscalls.
#ifndef SANITIZER_USES_CANONICAL_LINUX_SYSCALLS #ifndef SANITIZER_USES_CANONICAL_LINUX_SYSCALLS
# if defined(__aarch64__) && SANITIZER_LINUX # if (defined(__aarch64__) || defined(__riscv)) && SANITIZER_LINUX
# define SANITIZER_USES_CANONICAL_LINUX_SYSCALLS 1 # define SANITIZER_USES_CANONICAL_LINUX_SYSCALLS 1
# else # else
# define SANITIZER_USES_CANONICAL_LINUX_SYSCALLS 0 # define SANITIZER_USES_CANONICAL_LINUX_SYSCALLS 0
......
...@@ -26,12 +26,9 @@ ...@@ -26,12 +26,9 @@
// 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. Beware that with <sys/stat.h>, struct stat // fine with newer headers, too.
// 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__) #if defined(__x86_64__) || defined(__mips__)
#include <sys/stat.h> #include <sys/stat.h>
#else #else
#define ino_t __kernel_ino_t #define ino_t __kernel_ino_t
...@@ -68,7 +65,7 @@ namespace __sanitizer { ...@@ -68,7 +65,7 @@ namespace __sanitizer {
#if !defined(__powerpc64__) && !defined(__x86_64__) && !defined(__aarch64__)\ #if !defined(__powerpc64__) && !defined(__x86_64__) && !defined(__aarch64__)\
&& !defined(__mips__) && !defined(__s390__)\ && !defined(__mips__) && !defined(__s390__)\
&& !defined(__sparc__) && !defined(__sparc__) && !defined(__riscv)
COMPILER_CHECK(struct___old_kernel_stat_sz == sizeof(struct __old_kernel_stat)); COMPILER_CHECK(struct___old_kernel_stat_sz == sizeof(struct __old_kernel_stat));
#endif #endif
......
...@@ -354,7 +354,13 @@ struct __sanitizer_addrinfo { ...@@ -354,7 +354,13 @@ struct __sanitizer_addrinfo {
int ai_family; int ai_family;
int ai_socktype; int ai_socktype;
int ai_protocol; int ai_protocol;
#if defined(__sparc__) && defined(_LP64)
int __ai_pad0;
#endif
unsigned ai_addrlen; unsigned ai_addrlen;
#if defined(__alpha__) || (defined(__i386__) && defined(_LP64))
int __ai_pad0;
#endif
char *ai_canonname; char *ai_canonname;
void *ai_addr; void *ai_addr;
struct __sanitizer_addrinfo *ai_next; struct __sanitizer_addrinfo *ai_next;
......
...@@ -230,7 +230,7 @@ namespace __sanitizer { ...@@ -230,7 +230,7 @@ namespace __sanitizer {
// has been removed from glibc 2.28. // has been removed from glibc 2.28.
#if defined(__aarch64__) || defined(__s390x__) || defined (__mips64) \ #if defined(__aarch64__) || defined(__s390x__) || defined (__mips64) \
|| defined(__powerpc64__) || defined(__arch64__) || defined(__sparcv9) \ || defined(__powerpc64__) || defined(__arch64__) || defined(__sparcv9) \
|| defined(__x86_64__) || defined(__x86_64__) || (defined(__riscv) && __riscv_xlen == 64)
#define SIZEOF_STRUCT_USTAT 32 #define SIZEOF_STRUCT_USTAT 32
#elif defined(__arm__) || defined(__i386__) || defined(__mips__) \ #elif defined(__arm__) || defined(__i386__) || defined(__mips__) \
|| defined(__powerpc__) || defined(__s390__) || defined(__sparc__) || defined(__powerpc__) || defined(__s390__) || defined(__sparc__)
......
...@@ -82,7 +82,7 @@ const unsigned struct_kernel_stat64_sz = 104; ...@@ -82,7 +82,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(144, 216); : FIRST_32_SECOND_64(160, 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;
...@@ -98,6 +98,9 @@ const unsigned struct_kernel_stat64_sz = 144; ...@@ -98,6 +98,9 @@ const unsigned struct_kernel_stat64_sz = 144;
const unsigned struct___old_kernel_stat_sz = 0; const unsigned struct___old_kernel_stat_sz = 0;
const unsigned struct_kernel_stat_sz = 64; const unsigned struct_kernel_stat_sz = 64;
const unsigned struct_kernel_stat64_sz = 104; const unsigned struct_kernel_stat64_sz = 104;
#elif defined(__riscv) && __riscv_xlen == 64
const unsigned struct_kernel_stat_sz = 128;
const unsigned struct_kernel_stat64_sz = 104;
#endif #endif
struct __sanitizer_perf_event_attr { struct __sanitizer_perf_event_attr {
unsigned type; unsigned type;
......
...@@ -60,8 +60,8 @@ static inline uhwptr *GetCanonicFrame(uptr bp, ...@@ -60,8 +60,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 GCC. // layouts. Assume LLVM.
return bp_prev - 1; return bp_prev;
#else #else
return (uhwptr*)bp; return (uhwptr*)bp;
#endif #endif
...@@ -84,21 +84,14 @@ void BufferedStackTrace::UnwindFast(uptr pc, uptr bp, uptr stack_top, ...@@ -84,21 +84,14 @@ 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 on the // PowerPC ABIs specify that the return address is saved at offset
// *caller's* stack frame. Thus we must dereference the back chain // 16 of the *caller's* stack frame. Thus we must dereference the
// to find the caller frame before extracting it. // back chain 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];
#else #else
......
...@@ -42,8 +42,8 @@ ...@@ -42,8 +42,8 @@
// DO NOT EDIT! THIS FILE HAS BEEN GENERATED! // DO NOT EDIT! THIS FILE HAS BEEN GENERATED!
// //
// Generated with: generate_netbsd_syscalls.awk // Generated with: generate_netbsd_syscalls.awk
// Generated date: 2018-10-30 // Generated date: 2019-11-01
// Generated from: syscalls.master,v 1.293 2018/07/31 13:00:13 rjs Exp // Generated from: syscalls.master,v 1.296 2019/09/22 22:59:39 christos Exp
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
...@@ -2433,30 +2433,31 @@ PRE_SYSCALL(uuidgen)(void *store_, long long count_) { /* Nothing to do */ } ...@@ -2433,30 +2433,31 @@ PRE_SYSCALL(uuidgen)(void *store_, long long count_) { /* Nothing to do */ }
POST_SYSCALL(uuidgen)(long long res, void *store_, long long count_) { POST_SYSCALL(uuidgen)(long long res, void *store_, long long count_) {
/* Nothing to do */ /* Nothing to do */
} }
PRE_SYSCALL(getvfsstat)(void *buf_, long long bufsize_, long long flags_) { PRE_SYSCALL(compat_90_getvfsstat)
(void *buf_, long long bufsize_, long long flags_) {
/* Nothing to do */ /* Nothing to do */
} }
POST_SYSCALL(getvfsstat) POST_SYSCALL(compat_90_getvfsstat)
(long long res, void *buf_, long long bufsize_, long long flags_) { (long long res, void *buf_, long long bufsize_, long long flags_) {
/* Nothing to do */ /* Nothing to do */
} }
PRE_SYSCALL(statvfs1)(void *path_, void *buf_, long long flags_) { PRE_SYSCALL(compat_90_statvfs1)(void *path_, void *buf_, long long flags_) {
const char *path = (const char *)path_; const char *path = (const char *)path_;
if (path) { if (path) {
PRE_READ(path, __sanitizer::internal_strlen(path) + 1); PRE_READ(path, __sanitizer::internal_strlen(path) + 1);
} }
} }
POST_SYSCALL(statvfs1) POST_SYSCALL(compat_90_statvfs1)
(long long res, void *path_, void *buf_, long long flags_) { (long long res, void *path_, void *buf_, long long flags_) {
const char *path = (const char *)path_; const char *path = (const char *)path_;
if (path) { if (path) {
POST_READ(path, __sanitizer::internal_strlen(path) + 1); POST_READ(path, __sanitizer::internal_strlen(path) + 1);
} }
} }
PRE_SYSCALL(fstatvfs1)(long long fd_, void *buf_, long long flags_) { PRE_SYSCALL(compat_90_fstatvfs1)(long long fd_, void *buf_, long long flags_) {
/* Nothing to do */ /* Nothing to do */
} }
POST_SYSCALL(fstatvfs1) POST_SYSCALL(compat_90_fstatvfs1)
(long long res, long long fd_, void *buf_, long long flags_) { (long long res, long long fd_, void *buf_, long long flags_) {
/* Nothing to do */ /* Nothing to do */
} }
...@@ -2853,13 +2854,13 @@ PRE_SYSCALL(__fhopen40)(void *fhp_, long long fh_size_, long long flags_) { ...@@ -2853,13 +2854,13 @@ PRE_SYSCALL(__fhopen40)(void *fhp_, long long fh_size_, long long flags_) {
} }
POST_SYSCALL(__fhopen40) POST_SYSCALL(__fhopen40)
(long long res, void *fhp_, long long fh_size_, long long flags_) {} (long long res, void *fhp_, long long fh_size_, long long flags_) {}
PRE_SYSCALL(__fhstatvfs140) PRE_SYSCALL(compat_90_fhstatvfs1)
(void *fhp_, long long fh_size_, void *buf_, long long flags_) { (void *fhp_, long long fh_size_, void *buf_, long long flags_) {
if (fhp_) { if (fhp_) {
PRE_READ(fhp_, fh_size_); PRE_READ(fhp_, fh_size_);
} }
} }
POST_SYSCALL(__fhstatvfs140) POST_SYSCALL(compat_90_fhstatvfs1)
(long long res, void *fhp_, long long fh_size_, void *buf_, long long flags_) {} (long long res, void *fhp_, long long fh_size_, void *buf_, long long flags_) {}
PRE_SYSCALL(compat_50___fhstat40)(void *fhp_, long long fh_size_, void *sb_) { PRE_SYSCALL(compat_50___fhstat40)(void *fhp_, long long fh_size_, void *sb_) {
if (fhp_) { if (fhp_) {
...@@ -3768,6 +3769,41 @@ POST_SYSCALL(clock_getcpuclockid2) ...@@ -3768,6 +3769,41 @@ POST_SYSCALL(clock_getcpuclockid2)
(long long res, long long idtype_, long long id_, void *clock_id_) { (long long res, long long idtype_, long long id_, void *clock_id_) {
/* Nothing to do */ /* Nothing to do */
} }
PRE_SYSCALL(__getvfsstat90)(void *buf_, long long bufsize_, long long flags_) {
/* Nothing to do */
}
POST_SYSCALL(__getvfsstat90)
(long long res, void *buf_, long long bufsize_, long long flags_) {
/* Nothing to do */
}
PRE_SYSCALL(__statvfs190)(void *path_, void *buf_, long long flags_) {
const char *path = (const char *)path_;
if (path) {
PRE_READ(path, __sanitizer::internal_strlen(path) + 1);
}
}
POST_SYSCALL(__statvfs190)
(long long res, void *path_, void *buf_, long long flags_) {
const char *path = (const char *)path_;
if (path) {
POST_READ(path, __sanitizer::internal_strlen(path) + 1);
}
}
PRE_SYSCALL(__fstatvfs190)(long long fd_, void *buf_, long long flags_) {
/* Nothing to do */
}
POST_SYSCALL(__fstatvfs190)
(long long res, long long fd_, void *buf_, long long flags_) {
/* Nothing to do */
}
PRE_SYSCALL(__fhstatvfs190)
(void *fhp_, long long fh_size_, void *buf_, long long flags_) {
if (fhp_) {
PRE_READ(fhp_, fh_size_);
}
}
POST_SYSCALL(__fhstatvfs190)
(long long res, void *fhp_, long long fh_size_, void *buf_, long long flags_) {}
#undef SYS_MAXSYSARGS #undef SYS_MAXSYSARGS
} // extern "C" } // extern "C"
......
...@@ -113,9 +113,16 @@ ScopedGlobalProcessor::~ScopedGlobalProcessor() { ...@@ -113,9 +113,16 @@ ScopedGlobalProcessor::~ScopedGlobalProcessor() {
gp->mtx.Unlock(); gp->mtx.Unlock();
} }
static constexpr uptr kMaxAllowedMallocSize = 1ull << 40;
static uptr max_user_defined_malloc_size;
void InitializeAllocator() { void InitializeAllocator() {
SetAllocatorMayReturnNull(common_flags()->allocator_may_return_null); SetAllocatorMayReturnNull(common_flags()->allocator_may_return_null);
allocator()->Init(common_flags()->allocator_release_to_os_interval_ms); allocator()->Init(common_flags()->allocator_release_to_os_interval_ms);
max_user_defined_malloc_size = common_flags()->max_allocation_size_mb
? common_flags()->max_allocation_size_mb
<< 20
: kMaxAllowedMallocSize;
} }
void InitializeAllocatorLate() { void InitializeAllocatorLate() {
...@@ -150,15 +157,17 @@ static void SignalUnsafeCall(ThreadState *thr, uptr pc) { ...@@ -150,15 +157,17 @@ static void SignalUnsafeCall(ThreadState *thr, uptr pc) {
OutputReport(thr, rep); OutputReport(thr, rep);
} }
static constexpr uptr kMaxAllowedMallocSize = 1ull << 40;
void *user_alloc_internal(ThreadState *thr, uptr pc, uptr sz, uptr align, void *user_alloc_internal(ThreadState *thr, uptr pc, uptr sz, uptr align,
bool signal) { bool signal) {
if (sz >= kMaxAllowedMallocSize || align >= kMaxAllowedMallocSize) { if (sz >= kMaxAllowedMallocSize || align >= kMaxAllowedMallocSize ||
sz > max_user_defined_malloc_size) {
if (AllocatorMayReturnNull()) if (AllocatorMayReturnNull())
return nullptr; return nullptr;
uptr malloc_limit =
Min(kMaxAllowedMallocSize, max_user_defined_malloc_size);
GET_STACK_TRACE_FATAL(thr, pc); GET_STACK_TRACE_FATAL(thr, pc);
ReportAllocationSizeTooBig(sz, kMaxAllowedMallocSize, &stack); ReportAllocationSizeTooBig(sz, malloc_limit, &stack);
} }
void *p = allocator()->Allocate(&thr->proc()->alloc_cache, sz, align); void *p = allocator()->Allocate(&thr->proc()->alloc_cache, sz, align);
if (UNLIKELY(!p)) { if (UNLIKELY(!p)) {
......
#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
......
...@@ -54,7 +54,6 @@ void InitializeFlags() { ...@@ -54,7 +54,6 @@ 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);
} }
......
...@@ -819,21 +819,6 @@ void __ubsan_handle_cfi_bad_type(CFICheckFailData *Data, ValueHandle Vtable, ...@@ -819,21 +819,6 @@ 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) {
......
...@@ -207,20 +207,12 @@ enum CFITypeCheckKind : unsigned char { ...@@ -207,20 +207,12 @@ 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)
......
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
#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__) || \
...@@ -22,6 +21,5 @@ ...@@ -22,6 +21,5 @@
#else #else
# define CAN_SANITIZE_UB 0 # define CAN_SANITIZE_UB 0
#endif #endif
#endif //CAN_SANITIZE_UB
#endif #endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment