aboutsummaryrefslogtreecommitdiffstats
path: root/lib/msan
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2019-10-23 17:52:22 +0000
committerDimitry Andric <dim@FreeBSD.org>2019-10-23 17:52:22 +0000
commit3a1720af1d7f43edc5b214cde0be11bfb94d077e (patch)
tree029e0ff2d5e3c0eaf2405fd8e669555fdf5e1297 /lib/msan
parent8f3cadc28cb2bb9e8f9d69eeaaea1f57f2f7b2ab (diff)
downloadsrc-vendor/compiler-rt.tar.gz
src-vendor/compiler-rt.zip
Vendor import of stripped compiler-rt trunk r375505, the last commitvendor/compiler-rt/compiler-rt-trunk-r375505vendor/compiler-rt
before the upstream Subversion repository was made read-only, and the LLVM project migrated to GitHub: https://llvm.org/svn/llvm-project/compiler-rt/trunk@375505
Notes
Notes: svn path=/vendor/compiler-rt/dist/; revision=353944 svn path=/vendor/compiler-rt/compiler-rt-r375505/; revision=353945; tag=vendor/compiler-rt/compiler-rt-trunk-r375505
Diffstat (limited to 'lib/msan')
-rw-r--r--lib/msan/msan.cpp (renamed from lib/msan/msan.cc)10
-rw-r--r--lib/msan/msan.h11
-rw-r--r--lib/msan/msan_allocator.cpp (renamed from lib/msan/msan_allocator.cc)2
-rw-r--r--lib/msan/msan_chained_origin_depot.cpp (renamed from lib/msan/msan_chained_origin_depot.cc)2
-rw-r--r--lib/msan/msan_interceptors.cpp (renamed from lib/msan/msan_interceptors.cc)93
-rw-r--r--lib/msan/msan_linux.cpp (renamed from lib/msan/msan_linux.cc)8
-rw-r--r--lib/msan/msan_new_delete.cpp (renamed from lib/msan/msan_new_delete.cc)4
-rw-r--r--lib/msan/msan_poisoning.cpp (renamed from lib/msan/msan_poisoning.cc)2
-rw-r--r--lib/msan/msan_report.cpp (renamed from lib/msan/msan_report.cc)2
-rw-r--r--lib/msan/msan_thread.cpp (renamed from lib/msan/msan_thread.cc)0
10 files changed, 72 insertions, 62 deletions
diff --git a/lib/msan/msan.cc b/lib/msan/msan.cpp
index c62e5cd4c518..6ea63cb2c48f 100644
--- a/lib/msan/msan.cc
+++ b/lib/msan/msan.cpp
@@ -1,4 +1,4 @@
-//===-- msan.cc -----------------------------------------------------------===//
+//===-- msan.cpp ----------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -130,8 +130,8 @@ static void RegisterMsanFlags(FlagParser *parser, Flags *f) {
#include "msan_flags.inc"
#undef MSAN_FLAG
- FlagHandlerKeepGoing *fh_keep_going = new (FlagParser::Alloc) // NOLINT
- FlagHandlerKeepGoing(&f->halt_on_error);
+ FlagHandlerKeepGoing *fh_keep_going =
+ new (FlagParser::Alloc) FlagHandlerKeepGoing(&f->halt_on_error);
parser->RegisterHandler("keep_going", fh_keep_going,
"deprecated, use halt_on_error");
}
@@ -378,7 +378,7 @@ void __msan_warning_noreturn() {
static void OnStackUnwind(const SignalContext &sig, const void *,
BufferedStackTrace *stack) {
- stack->Unwind(sig.pc, sig.bp, sig.context,
+ stack->Unwind(StackTrace::GetNextInstructionPc(sig.pc), sig.bp, sig.context,
common_flags()->fast_unwind_on_fatal);
}
@@ -403,7 +403,6 @@ void __msan_init() {
AvoidCVE_2016_2143();
CacheBinaryName();
- CheckASLR();
InitializeFlags();
// Install tool-specific callbacks in sanitizer_common.
@@ -412,6 +411,7 @@ void __msan_init() {
__sanitizer_set_report_path(common_flags()->log_path);
InitializeInterceptors();
+ CheckASLR();
InitTlsSize();
InstallDeadlySignalHandlers(MsanOnDeadlySignal);
InstallAtExitHandler(); // Needs __cxa_atexit interceptor.
diff --git a/lib/msan/msan.h b/lib/msan/msan.h
index ac5f67e6ab3d..12aeaa43519a 100644
--- a/lib/msan/msan.h
+++ b/lib/msan/msan.h
@@ -267,7 +267,7 @@ inline bool addr_is_type(uptr addr, MappingDesc::Type mapping_type) {
#define MEM_IS_SHADOW(mem) addr_is_type((uptr)(mem), MappingDesc::SHADOW)
#define MEM_IS_ORIGIN(mem) addr_is_type((uptr)(mem), MappingDesc::ORIGIN)
-// These constants must be kept in sync with the ones in MemorySanitizer.cc.
+// These constants must be kept in sync with the ones in MemorySanitizer.cpp.
const int kMsanParamTlsSize = 800;
const int kMsanRetvalTlsSize = 800;
@@ -346,10 +346,11 @@ const int STACK_TRACE_TAG_POISON = StackTrace::TAG_CUSTOM + 1;
#define GET_STORE_STACK_TRACE \
GET_STORE_STACK_TRACE_PC_BP(StackTrace::GetCurrentPc(), GET_CURRENT_FRAME())
-#define GET_FATAL_STACK_TRACE_PC_BP(pc, bp) \
- BufferedStackTrace stack; \
- if (msan_inited) \
- stack.Unwind(pc, bp, nullptr, common_flags()->fast_unwind_on_fatal)
+#define GET_FATAL_STACK_TRACE_PC_BP(pc, bp) \
+ BufferedStackTrace stack; \
+ if (msan_inited) { \
+ stack.Unwind(pc, bp, nullptr, common_flags()->fast_unwind_on_fatal); \
+ }
#define GET_FATAL_STACK_TRACE_HERE \
GET_FATAL_STACK_TRACE_PC_BP(StackTrace::GetCurrentPc(), GET_CURRENT_FRAME())
diff --git a/lib/msan/msan_allocator.cc b/lib/msan/msan_allocator.cpp
index 1816840012e4..6aa4e2738075 100644
--- a/lib/msan/msan_allocator.cc
+++ b/lib/msan/msan_allocator.cpp
@@ -1,4 +1,4 @@
-//===-- msan_allocator.cc --------------------------- ---------------------===//
+//===-- msan_allocator.cpp -------------------------- ---------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
diff --git a/lib/msan/msan_chained_origin_depot.cc b/lib/msan/msan_chained_origin_depot.cpp
index 6c634252e0b1..d2897481a4b9 100644
--- a/lib/msan/msan_chained_origin_depot.cc
+++ b/lib/msan/msan_chained_origin_depot.cpp
@@ -1,4 +1,4 @@
-//===-- msan_chained_origin_depot.cc -----------------------------------===//
+//===-- msan_chained_origin_depot.cpp ----------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
diff --git a/lib/msan/msan_interceptors.cc b/lib/msan/msan_interceptors.cpp
index b055bb749cb8..1d9d9f7986d7 100644
--- a/lib/msan/msan_interceptors.cc
+++ b/lib/msan/msan_interceptors.cpp
@@ -1,4 +1,4 @@
-//===-- msan_interceptors.cc ----------------------------------------------===//
+//===-- msan_interceptors.cpp ---------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -282,35 +282,35 @@ INTERCEPTOR(void, malloc_stats, void) {
#define MSAN_MAYBE_INTERCEPT_MALLOC_STATS
#endif
-INTERCEPTOR(char *, strcpy, char *dest, const char *src) { // NOLINT
+INTERCEPTOR(char *, strcpy, char *dest, const char *src) {
ENSURE_MSAN_INITED();
GET_STORE_STACK_TRACE;
SIZE_T n = REAL(strlen)(src);
CHECK_UNPOISONED_STRING(src + n, 0);
- char *res = REAL(strcpy)(dest, src); // NOLINT
+ char *res = REAL(strcpy)(dest, src);
CopyShadowAndOrigin(dest, src, n + 1, &stack);
return res;
}
-INTERCEPTOR(char *, strncpy, char *dest, const char *src, SIZE_T n) { // NOLINT
+INTERCEPTOR(char *, strncpy, char *dest, const char *src, SIZE_T n) {
ENSURE_MSAN_INITED();
GET_STORE_STACK_TRACE;
SIZE_T copy_size = REAL(strnlen)(src, n);
if (copy_size < n)
copy_size++; // trailing \0
- char *res = REAL(strncpy)(dest, src, n); // NOLINT
+ char *res = REAL(strncpy)(dest, src, n);
CopyShadowAndOrigin(dest, src, copy_size, &stack);
__msan_unpoison(dest + copy_size, n - copy_size);
return res;
}
#if !SANITIZER_NETBSD
-INTERCEPTOR(char *, stpcpy, char *dest, const char *src) { // NOLINT
+INTERCEPTOR(char *, stpcpy, char *dest, const char *src) {
ENSURE_MSAN_INITED();
GET_STORE_STACK_TRACE;
SIZE_T n = REAL(strlen)(src);
CHECK_UNPOISONED_STRING(src + n, 0);
- char *res = REAL(stpcpy)(dest, src); // NOLINT
+ char *res = REAL(stpcpy)(dest, src);
CopyShadowAndOrigin(dest, src, n + 1, &stack);
return res;
}
@@ -359,25 +359,25 @@ INTERCEPTOR(char *, gcvt, double number, SIZE_T ndigit, char *buf) {
#define MSAN_MAYBE_INTERCEPT_GCVT
#endif
-INTERCEPTOR(char *, strcat, char *dest, const char *src) { // NOLINT
+INTERCEPTOR(char *, strcat, char *dest, const char *src) {
ENSURE_MSAN_INITED();
GET_STORE_STACK_TRACE;
SIZE_T src_size = REAL(strlen)(src);
SIZE_T dest_size = REAL(strlen)(dest);
CHECK_UNPOISONED_STRING(src + src_size, 0);
CHECK_UNPOISONED_STRING(dest + dest_size, 0);
- char *res = REAL(strcat)(dest, src); // NOLINT
+ char *res = REAL(strcat)(dest, src);
CopyShadowAndOrigin(dest + dest_size, src, src_size + 1, &stack);
return res;
}
-INTERCEPTOR(char *, strncat, char *dest, const char *src, SIZE_T n) { // NOLINT
+INTERCEPTOR(char *, strncat, char *dest, const char *src, SIZE_T n) {
ENSURE_MSAN_INITED();
GET_STORE_STACK_TRACE;
SIZE_T dest_size = REAL(strlen)(dest);
SIZE_T copy_size = REAL(strnlen)(src, n);
CHECK_UNPOISONED_STRING(dest + dest_size, 0);
- char *res = REAL(strncat)(dest, src, n); // NOLINT
+ char *res = REAL(strncat)(dest, src, n);
CopyShadowAndOrigin(dest + dest_size, src, copy_size, &stack);
__msan_unpoison(dest + dest_size + copy_size, 1); // \0
return res;
@@ -437,22 +437,22 @@ INTERCEPTOR(char *, strncat, char *dest, const char *src, SIZE_T n) { // NOLINT
INTERCEPTOR_STRTO_BASE_LOC(ret_type, __##func##_internal, char_type)
#endif
-INTERCEPTORS_STRTO(double, strtod, char) // NOLINT
-INTERCEPTORS_STRTO(float, strtof, char) // NOLINT
-INTERCEPTORS_STRTO(long double, strtold, char) // NOLINT
-INTERCEPTORS_STRTO_BASE(long, strtol, char) // NOLINT
-INTERCEPTORS_STRTO_BASE(long long, strtoll, char) // NOLINT
-INTERCEPTORS_STRTO_BASE(unsigned long, strtoul, char) // NOLINT
-INTERCEPTORS_STRTO_BASE(unsigned long long, strtoull, char) // NOLINT
-INTERCEPTORS_STRTO_BASE(u64, strtouq, char) // NOLINT
-
-INTERCEPTORS_STRTO(double, wcstod, wchar_t) // NOLINT
-INTERCEPTORS_STRTO(float, wcstof, wchar_t) // NOLINT
-INTERCEPTORS_STRTO(long double, wcstold, wchar_t) // NOLINT
-INTERCEPTORS_STRTO_BASE(long, wcstol, wchar_t) // NOLINT
-INTERCEPTORS_STRTO_BASE(long long, wcstoll, wchar_t) // NOLINT
-INTERCEPTORS_STRTO_BASE(unsigned long, wcstoul, wchar_t) // NOLINT
-INTERCEPTORS_STRTO_BASE(unsigned long long, wcstoull, wchar_t) // NOLINT
+INTERCEPTORS_STRTO(double, strtod, char)
+INTERCEPTORS_STRTO(float, strtof, char)
+INTERCEPTORS_STRTO(long double, strtold, char)
+INTERCEPTORS_STRTO_BASE(long, strtol, char)
+INTERCEPTORS_STRTO_BASE(long long, strtoll, char)
+INTERCEPTORS_STRTO_BASE(unsigned long, strtoul, char)
+INTERCEPTORS_STRTO_BASE(unsigned long long, strtoull, char)
+INTERCEPTORS_STRTO_BASE(u64, strtouq, char)
+
+INTERCEPTORS_STRTO(double, wcstod, wchar_t)
+INTERCEPTORS_STRTO(float, wcstof, wchar_t)
+INTERCEPTORS_STRTO(long double, wcstold, wchar_t)
+INTERCEPTORS_STRTO_BASE(long, wcstol, wchar_t)
+INTERCEPTORS_STRTO_BASE(long long, wcstoll, wchar_t)
+INTERCEPTORS_STRTO_BASE(unsigned long, wcstoul, wchar_t)
+INTERCEPTORS_STRTO_BASE(unsigned long long, wcstoull, wchar_t)
#if SANITIZER_NETBSD
#define INTERCEPT_STRTO(func) \
@@ -765,17 +765,24 @@ INTERCEPTOR(char *, fgets_unlocked, char *s, int size, void *stream) {
#define MSAN_MAYBE_INTERCEPT_FGETS_UNLOCKED
#endif
+#define INTERCEPTOR_GETRLIMIT_BODY(func, resource, rlim) \
+ if (msan_init_is_running) \
+ return REAL(getrlimit)(resource, rlim); \
+ ENSURE_MSAN_INITED(); \
+ int res = REAL(func)(resource, rlim); \
+ if (!res) \
+ __msan_unpoison(rlim, __sanitizer::struct_rlimit_sz); \
+ return res
+
INTERCEPTOR(int, getrlimit, int resource, void *rlim) {
- if (msan_init_is_running)
- return REAL(getrlimit)(resource, rlim);
- ENSURE_MSAN_INITED();
- int res = REAL(getrlimit)(resource, rlim);
- if (!res)
- __msan_unpoison(rlim, __sanitizer::struct_rlimit_sz);
- return res;
+ INTERCEPTOR_GETRLIMIT_BODY(getrlimit, resource, rlim);
}
#if !SANITIZER_FREEBSD && !SANITIZER_NETBSD
+INTERCEPTOR(int, __getrlimit, int resource, void *rlim) {
+ INTERCEPTOR_GETRLIMIT_BODY(__getrlimit, resource, rlim);
+}
+
INTERCEPTOR(int, getrlimit64, int resource, void *rlim) {
if (msan_init_is_running) return REAL(getrlimit64)(resource, rlim);
ENSURE_MSAN_INITED();
@@ -806,10 +813,12 @@ INTERCEPTOR(int, prlimit64, int pid, int resource, void *new_rlimit,
return res;
}
+#define MSAN_MAYBE_INTERCEPT___GETRLIMIT INTERCEPT_FUNCTION(__getrlimit)
#define MSAN_MAYBE_INTERCEPT_GETRLIMIT64 INTERCEPT_FUNCTION(getrlimit64)
#define MSAN_MAYBE_INTERCEPT_PRLIMIT INTERCEPT_FUNCTION(prlimit)
#define MSAN_MAYBE_INTERCEPT_PRLIMIT64 INTERCEPT_FUNCTION(prlimit64)
#else
+#define MSAN_MAYBE_INTERCEPT___GETRLIMIT
#define MSAN_MAYBE_INTERCEPT_GETRLIMIT64
#define MSAN_MAYBE_INTERCEPT_PRLIMIT
#define MSAN_MAYBE_INTERCEPT_PRLIMIT64
@@ -1514,13 +1523,12 @@ INTERCEPTOR(wchar_t *, wcscpy, wchar_t *dest, const wchar_t *src) {
return res;
}
-INTERCEPTOR(wchar_t *, wcsncpy, wchar_t *dest, const wchar_t *src,
- SIZE_T n) { // NOLINT
+INTERCEPTOR(wchar_t *, wcsncpy, wchar_t *dest, const wchar_t *src, SIZE_T n) {
ENSURE_MSAN_INITED();
GET_STORE_STACK_TRACE;
SIZE_T copy_size = REAL(wcsnlen)(src, n);
if (copy_size < n) copy_size++; // trailing \0
- wchar_t *res = REAL(wcsncpy)(dest, src, n); // NOLINT
+ wchar_t *res = REAL(wcsncpy)(dest, src, n);
CopyShadowAndOrigin(dest, src, copy_size * sizeof(wchar_t), &stack);
__msan_unpoison(dest + copy_size, (n - copy_size) * sizeof(wchar_t));
return res;
@@ -1620,14 +1628,14 @@ void InitializeInterceptors() {
INTERCEPT_FUNCTION(wmemcpy);
MSAN_MAYBE_INTERCEPT_WMEMPCPY;
INTERCEPT_FUNCTION(wmemmove);
- INTERCEPT_FUNCTION(strcpy); // NOLINT
- MSAN_MAYBE_INTERCEPT_STPCPY; // NOLINT
+ INTERCEPT_FUNCTION(strcpy);
+ MSAN_MAYBE_INTERCEPT_STPCPY;
INTERCEPT_FUNCTION(strdup);
MSAN_MAYBE_INTERCEPT___STRDUP;
- INTERCEPT_FUNCTION(strncpy); // NOLINT
+ INTERCEPT_FUNCTION(strncpy);
MSAN_MAYBE_INTERCEPT_GCVT;
- INTERCEPT_FUNCTION(strcat); // NOLINT
- INTERCEPT_FUNCTION(strncat); // NOLINT
+ INTERCEPT_FUNCTION(strcat);
+ INTERCEPT_FUNCTION(strncat);
INTERCEPT_STRTO(strtod);
INTERCEPT_STRTO(strtof);
INTERCEPT_STRTO(strtold);
@@ -1679,6 +1687,7 @@ void InitializeInterceptors() {
INTERCEPT_FUNCTION(socketpair);
MSAN_MAYBE_INTERCEPT_FGETS_UNLOCKED;
INTERCEPT_FUNCTION(getrlimit);
+ MSAN_MAYBE_INTERCEPT___GETRLIMIT;
MSAN_MAYBE_INTERCEPT_GETRLIMIT64;
MSAN_MAYBE_INTERCEPT_PRLIMIT;
MSAN_MAYBE_INTERCEPT_PRLIMIT64;
diff --git a/lib/msan/msan_linux.cc b/lib/msan/msan_linux.cpp
index 3b6e6cb85f33..d61e9dee3065 100644
--- a/lib/msan/msan_linux.cc
+++ b/lib/msan/msan_linux.cpp
@@ -1,4 +1,4 @@
-//===-- msan_linux.cc -----------------------------------------------------===//
+//===-- msan_linux.cpp ----------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -125,7 +125,7 @@ bool InitShadow(bool init_origins) {
for (unsigned i = 0; i < kMemoryLayoutSize; ++i) {
uptr start = kMemoryLayout[i].start;
uptr end = kMemoryLayout[i].end;
- uptr size= end - start;
+ uptr size = end - start;
MappingDesc::Type type = kMemoryLayout[i].type;
// Check if the segment should be mapped based on platform constraints.
@@ -174,8 +174,8 @@ void InstallAtExitHandler() {
// ---------------------- TSD ---------------- {{{1
-#if SANITIZER_NETBSD || SANITIZER_FREEBSD
-// Thread Static Data cannot be used in early init on NetBSD and FreeBSD.
+#if SANITIZER_NETBSD
+// Thread Static Data cannot be used in early init on NetBSD.
// Reuse the MSan TSD API for compatibility with existing code
// with an alternative implementation.
diff --git a/lib/msan/msan_new_delete.cc b/lib/msan/msan_new_delete.cpp
index 750981eb55eb..d4e95c0f6513 100644
--- a/lib/msan/msan_new_delete.cc
+++ b/lib/msan/msan_new_delete.cpp
@@ -1,4 +1,4 @@
-//===-- msan_new_delete.cc ------------------------------------------------===//
+//===-- msan_new_delete.cpp -----------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -20,7 +20,7 @@
#include <stddef.h>
-using namespace __msan; // NOLINT
+using namespace __msan;
// Fake std::nothrow_t and std::align_val_t to avoid including <new>.
namespace std {
diff --git a/lib/msan/msan_poisoning.cc b/lib/msan/msan_poisoning.cpp
index 5ea01f51a835..ef3c74e0a35a 100644
--- a/lib/msan/msan_poisoning.cc
+++ b/lib/msan/msan_poisoning.cpp
@@ -1,4 +1,4 @@
-//===-- msan_poisoning.cc ---------------------------------------*- C++ -*-===//
+//===-- msan_poisoning.cpp --------------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
diff --git a/lib/msan/msan_report.cc b/lib/msan/msan_report.cpp
index 73bce3972593..e10d9eb62231 100644
--- a/lib/msan/msan_report.cc
+++ b/lib/msan/msan_report.cpp
@@ -1,4 +1,4 @@
-//===-- msan_report.cc ----------------------------------------------------===//
+//===-- msan_report.cpp ---------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
diff --git a/lib/msan/msan_thread.cc b/lib/msan/msan_thread.cpp
index 0ba499350064..0ba499350064 100644
--- a/lib/msan/msan_thread.cc
+++ b/lib/msan/msan_thread.cpp