summaryrefslogtreecommitdiff
path: root/lib/msan/msan_interceptors.cc
AgeCommit message (Collapse)Author
2017-12-14Set of corrections for MSan/NetBSDKamil Rytarowski
Summary: Changes: - Don't attempt to intercept GLIBC specific functions like __strtol_internal. This is required to stop intercepting it as we leak dlerror(3) for dlsym(3) that cannot manage to find a symbol. - Correct interception of fstatat(2). - Don't run a test for fgetgrent_r() that is missing on NetBSD. - Correct link_map location (offset) in Obj_Entry on x86_64 and i386. - Stop intercepting getpshared-like functions in pthread(3). This is feature is not enabled by default on NetBSD as it's unfinished. - Switch intercepting from UTMP to UTMPX functions. Sponsored by <The NetBSD Foundation> Reviewers: joerg, vitalybuka, eugenis, kcc Reviewed By: vitalybuka Subscribers: llvm-commits, srhines, kubamracek, #sanitizers Tags: #sanitizers Differential Revision: https://reviews.llvm.org/D41053 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@320663 91177308-0d34-0410-b5e6-96231b3b80d8
2017-12-06Revert SVN r, 319967Kamil Rytarowski
"Correct atexit(3) support in MSan/NetBSD" This causes failures on Linux. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@319981 91177308-0d34-0410-b5e6-96231b3b80d8
2017-12-06Correct atexit(3) support in MSan/NetBSDKamil Rytarowski
Summary: The NetBSD specific implementation of cxa_atexit() does not preserve the 2nd argument if dso is equal to NULL. Changes: - Split paths of handling intercepted __cxa_atexit() and atexit(3). This affects all supported Operating Systems. - Add a local stack-like structure to hold the __cxa_atexit() context. atexit(3) is documented in the C standard as calling callback from the earliest to the oldest entry. This path also fixes potential ABI problem of passing an argument to a function from the atexit(3) callback mechanism. - Allow usage of global vars with ctors in interceptors. This allows to use Vector without automatic cleaning up the structures. This code has been modeled after TSan implementation for the same functions. Sponsored by <The NetBSD Foundation> Reviewers: joerg, dvyukov, eugenis, vitalybuka, kcc Reviewed By: vitalybuka Subscribers: llvm-commits, #sanitizers Tags: #sanitizers Differential Revision: https://reviews.llvm.org/D40714 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@319967 91177308-0d34-0410-b5e6-96231b3b80d8
2017-12-06Handle NetBSD symbol renaming in msan_interceptors.ccKamil Rytarowski
Summary: NetBSD renames symbols for historical and compat reasons. Add required symbol renames in sanitizer_common_interceptors.inc: - gettimeofday -> __gettimeofday50 - getrusage -> __getrusage50 - shmctl -> __shmctl50 Additionally handle sigaction symbol mangling. Rename the function symbol in the file to SIGACTION_SYMNAME and define it as __sigaction14 for NetBSD and sigaction for !NetBSD. We cannot use simple renaming with the proprocessor, as there are valid fields named sigaction and they must be left intact. Sponsored by <The NetBSD Foundation> Reviewers: joerg, eugenis, vitalybuka, dvyukov Reviewed By: vitalybuka Subscribers: kubamracek, llvm-commits, #sanitizers Tags: #sanitizers Differential Revision: https://reviews.llvm.org/D40766 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@319966 91177308-0d34-0410-b5e6-96231b3b80d8
2017-12-06Fix typo fcvr -> fcvt and attempt to unbreak MSan/!NetBSDKamil Rytarowski
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@319872 91177308-0d34-0410-b5e6-96231b3b80d8
2017-12-06Fix typo gcvr -> gcvt and attempt to unbreak MSan/!NetBSDKamil Rytarowski
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@319871 91177308-0d34-0410-b5e6-96231b3b80d8
2017-12-06Support pthread_key_create symbol alias in MSan/NetBSDKamil Rytarowski
Summary: NetBSD uses indirection symbol for a set of threading functions. Add alias to handle __libc_thr_keycreate the same way as pthread_key_create. Sponsored by <The NetBSD Foundation> Reviewers: joerg, dvyukov, eugenis, vitalybuka Reviewed By: vitalybuka Subscribers: llvm-commits, #sanitizers Tags: #sanitizers Differential Revision: https://reviews.llvm.org/D40767 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@319868 91177308-0d34-0410-b5e6-96231b3b80d8
2017-12-06Disable absent functions in MSan/NetBSD interceptorsKamil Rytarowski
Summary: Disable for NetBSD missing functions missing in this OS: - mempcpy, - __libc_memalign, - malloc_usable_size, - stpcpy, - gcvt, - wmempcpy, - fcvt. Sponsored by <The NetBSD Foundation> Reviewers: joerg, dvyukov, eugenis, vitalybuka, kcc Reviewed By: vitalybuka Subscribers: llvm-commits, #sanitizers Tags: #sanitizers Differential Revision: https://reviews.llvm.org/D40764 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@319866 91177308-0d34-0410-b5e6-96231b3b80d8
2017-12-05[msan] Fix formattingVitaly Buka
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@319844 91177308-0d34-0410-b5e6-96231b3b80d8
2017-12-05[msan] add strtouq msan interceptorVitaly Buka
Summary: Fixes https://github.com/google/sanitizers/issues/892 Reviewers: eugenis Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D40853 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@319843 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-30[msan] Fix return type of mbrtowcVitaly Buka
Summary: Fixes https://github.com/google/oss-fuzz/issues/1009 Reviewers: eugenis Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D40676 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@319484 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-27[msan] Avoid shadowing a variable in common interceptors.Evgeniy Stepanov
"offset" declared in a macro may shadow a variable with the same name in the caller which is used in a macro argument. We are quite lucky that it does not actually happen, but rename the variable anyway to be on the safe side. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@319115 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-11[msan] Fix signal chainingVitaly Buka
Return internally stored handlers only if handlers is set to wrapper git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@317970 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-10[msan] Remove INTERCEPT_FUNCTION for sigaction and signalVitaly Buka
Already done in InitializeSignalInterceptors() git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@317906 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-10[tsan] Use __sanitizer_siginfo from sanitizer_commonVitaly Buka
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@317872 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-10[msan] Deadly signal handler for msanVitaly Buka
Summary: Part of https://github.com/google/sanitizers/issues/637 Reviewers: eugenis, alekseyshl Subscribers: llvm-commits, kubamracek Differential Revision: https://reviews.llvm.org/D39826 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@317864 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-10[msan] Move sigaction_impl and signal_implVitaly Buka
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@317863 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-09[msan] Extract signal_impl and sigaction_implVitaly Buka
Summary: Preparation for using interceptor from sanitizer_common. Reviewers: eugenis Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D39824 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@317844 91177308-0d34-0410-b5e6-96231b3b80d8
2017-10-25[msan] Intercept __strxfrm_l.Evgeniy Stepanov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@316613 91177308-0d34-0410-b5e6-96231b3b80d8
2017-10-25Add NetBSD improvements in sanitizersKamil Rytarowski
Summary: Changes: * Add initial msan stub support. * Handle NetBSD specific pthread_setname_np(3). * NetBSD supports __attribute__((tls_model("initial-exec"))), define it in SANITIZER_TLS_INITIAL_EXEC_ATTRIBUTE. * Add ReExec() specific bits for NetBSD. * Simplify code and add syscall64 and syscall_ptr for !NetBSD. * Correct bunch of syscall wrappers for NetBSD. * Disable test/tsan/map32bit on NetBSD as not applicable. * Port test/tsan/strerror_r to a POSIX-compliant OSes. * Disable __libc_stack_end on NetBSD. * Disable ReadNullSepFileToArray() on NetBSD. * Define struct_ElfW_Phdr_sz, detected missing symbol by msan. * Change type of __sanitizer_FILE from void to char. This helps to reuse this type as an array. Long term it will be properly implemented along with SANITIZER_HAS_STRUCT_FILE setting to 1. * Add initial NetBSD support in lib/tsan/go/buildgo.sh. * Correct referencing stdout and stderr in tsan_interceptors.cc on NetBSD. * Document NetBSD x86_64 specific virtual memory layout in tsan_platform.h. * Port tests/rtl/tsan_test_util_posix.cc to NetBSD. * Enable NetBSD tests in test/msan/lit.cfg. * Enable NetBSD tests in test/tsan/lit.cfg. Sponsored by <The NetBSD Foundation> Reviewers: joerg, vitalybuka, eugenis, kcc, dvyukov Reviewed By: dvyukov Subscribers: #sanitizers, llvm-commits, kubamracek Tags: #sanitizers Differential Revision: https://reviews.llvm.org/D39124 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@316591 91177308-0d34-0410-b5e6-96231b3b80d8
2017-09-06[msan] Remove a stale fixme (NFC).Evgeniy Stepanov
It was fixed in 312576. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@312597 91177308-0d34-0410-b5e6-96231b3b80d8
2017-09-05[msan] Check sigset_t and sigaction arguments.Evgeniy Stepanov
Summary: Check sigset_t arguments in ppoll, sig*wait*, sigprocmask interceptors, and the entire "struct sigaction" in sigaction. This can be done because sigemptyset/sigfullset are intercepted and signal masks should be correctly marked as initialized. Reviewers: vitalybuka Subscribers: kubamracek, llvm-commits Differential Revision: https://reviews.llvm.org/D37367 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@312576 91177308-0d34-0410-b5e6-96231b3b80d8
2017-09-02(NFC) Fix the use of do{}while(0) in a macro.Evgeniy Stepanov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@312396 91177308-0d34-0410-b5e6-96231b3b80d8
2017-07-18[Sanitizers] ASan/MSan/LSan allocators set errno on failure.Alex Shlyapnikov
Summary: ASan/MSan/LSan allocators set errno on allocation failures according to malloc/calloc/etc. expected behavior. MSan allocator was refactored a bit to make its structure more similar with other allocators. Also switch Scudo allocator to the internal errno definitions. TSan allocator changes will follow. Reviewers: eugenis Subscribers: llvm-commits, kubamracek Differential Revision: https://reviews.llvm.org/D35275 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@308344 91177308-0d34-0410-b5e6-96231b3b80d8
2017-07-06[Sanitizers] Consolidate internal errno definitions.Alex Shlyapnikov
Move internal errno definitions to common to be shared by all sanitizers and to be used by allocators. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@307233 91177308-0d34-0410-b5e6-96231b3b80d8
2017-06-27[msan] Intercept wcscat, wcsncat.Evgeniy Stepanov
Also move wcslen, wscnlen to common interceptors. Reviewers: vitalybuka Reviewed By: vitalybuka Subscribers: kubamracek, llvm-commits Differential Revision: https://reviews.llvm.org/D34656 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@306482 91177308-0d34-0410-b5e6-96231b3b80d8
2017-06-05Revert r304285, r304297.Evgeniy Stepanov
r304285 - [sanitizer] Avoid possible deadlock in child process after fork r304297 - [sanitizer] Trying to fix MAC buildbots after r304285 These changes create deadlock when Tcl calls pthread_create from a pthread_atfork child handler. More info in the original review at https://reviews.llvm.org/D33325 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@304735 91177308-0d34-0410-b5e6-96231b3b80d8
2017-06-01[asan] Add strndup/__strndup interceptors.Pierre Gousseau
Recommit of r302781 with Vitaly Buka's fix for non zero terminated strings. Differential Revision: https://reviews.llvm.org/D31457 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@304399 91177308-0d34-0410-b5e6-96231b3b80d8
2017-05-31[sanitizer] Avoid possible deadlock in child process after forkMaxim Ostapenko
This patch addresses https://github.com/google/sanitizers/issues/774. When we fork a multi-threaded process it's possible to deadlock if some thread acquired StackDepot or allocator internal lock just before fork. In this case the lock will never be released in child process causing deadlock on following memory alloc/dealloc routine. While calling alloc/dealloc routines after multi-threaded fork is not allowed, most of modern allocators (Glibc, tcmalloc, jemalloc) are actually fork safe. Let's do the same for sanitizers except TSan that has complex locking rules. Differential Revision: https://reviews.llvm.org/D33325 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@304285 91177308-0d34-0410-b5e6-96231b3b80d8
2017-05-18Revert r302781 and subsequent attempts to disable part of it.Daniel Jasper
The Msan unit tests are still broken and by this point, I think we should start over. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@303339 91177308-0d34-0410-b5e6-96231b3b80d8
2017-05-11[asan] Recommit of r301904: Add strndup/__strndup interceptorsPierre Gousseau
Fix undeclared __interceptor_malloc in esan_interceptors.cc Fix undeclared strnlen on OSX Differential Revision: https://reviews.llvm.org/D31457 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@302781 91177308-0d34-0410-b5e6-96231b3b80d8
2017-05-02Revert r301904 causing tsan test failure in x86_64-linux-autoconfPierre Gousseau
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@301909 91177308-0d34-0410-b5e6-96231b3b80d8
2017-05-02[asan] Add strndup/__strndup interceptors if targeting linux.Pierre Gousseau
Differential Revision: https://reviews.llvm.org/D31457 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@301904 91177308-0d34-0410-b5e6-96231b3b80d8
2017-03-30[sanitizer] Move fread and fwrite interceptors to sanitizer_commonMaxim Ostapenko
{M, T, E}San have fread and fwrite interceptors, let's move them to sanitizer_common to enable ASan checks as well. Differential Revision: https://reviews.llvm.org/D31456 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@299061 91177308-0d34-0410-b5e6-96231b3b80d8
2017-03-14[msan] Intercept wcsncpy, wcsnlen.Evgeniy Stepanov
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@297793 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-27[compiler-rt] Move logic which replace memcpy interceptor with memmove from ↵Vitaly Buka
asan to sanitizer_common. Reviewers: eugenis Subscribers: kubabrecka, dberris, llvm-commits Differential Revision: https://reviews.llvm.org/D28074 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@290626 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-23Fix interceptors setup broken after r290382Vitaly Buka
Summary: We setup these interceptors twice which hangs test on windows. Reviewers: eugenis Subscribers: llvm-commits, kubabrecka Differential Revision: https://reviews.llvm.org/D28070 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@290393 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-22Replace WRAP in interceptors with memset, memmove and memcpy implementationVitaly Buka
Summary: According https://reviews.llvm.org/D27659#625093 WRAP adds confusing stack frame. Reviewers: eugenis Subscribers: kubabrecka, llvm-commits Differential Revision: https://reviews.llvm.org/D28039 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@290382 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-15Revert r289690 "[sanitizer] intercept bstring functions, patch by Kuang-che ↵Hans Wennborg
Wu (https://reviews.llvm.org/D27659)" It breaks programs on Mac. See comments on the code review for details. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@289864 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-14[sanitizer] intercept bstring functions, patch by Kuang-che Wu ↵Kostya Serebryany
(https://reviews.llvm.org/D27659) git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@289690 91177308-0d34-0410-b5e6-96231b3b80d8
2016-09-26[msan] Fix second parameter in MsanReallocate from previous commit.Maxim Ostapenko
It's wrong to pass to MsanReallocate a pointer that MSan allocator doesn't own. Use nullptr instead of ptr to prevent possible (still unlikely) failure. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@282390 91177308-0d34-0410-b5e6-96231b3b80d8
2016-09-26[asan, msan] Fix reallocation logic when IsInDlsymAllocPool(ptr) is true.Maxim Ostapenko
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@282389 91177308-0d34-0410-b5e6-96231b3b80d8
2016-09-23[msan] Prevent initialization failure with newer (2.23+) glibc in use.Maxim Ostapenko
This patch is pretty the same as http://reviews.llvm.org/D20235 that we used for ASan. Using the same hack for MSan fixes its initialization with newer Glibc in use. Differential Revision: https://reviews.llvm.org/D24736 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@282232 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-19Revert "[sanitizer] Move *fstat to the common interceptors"Benjamin Kramer
This reverts commit r269981. Breaks msan tests on linux http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux/builds/24019/steps/test%20standalone%20compiler-rt/logs/stdio git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@270076 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-18[sanitizer] Move *fstat to the common interceptorsMike Aizatsky
Summary: Adds *fstat to the common interceptors. Removes the now-duplicate fstat interceptor from msan/tsan This adds fstat to asan/esan, which previously did not intercept it. Resubmit of http://reviews.llvm.org/D20318 with ios build fixes. Reviewers: eugenis, vitalybuka, aizatsky Subscribers: zaks.anna, kcc, bruening, kubabrecka, srhines, danalbert, tberghammer Differential Revision: http://reviews.llvm.org/D20350 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@269981 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-17Revert "[sanitizer] Move *fstat to the common interceptors"Mike Aizatsky
This reverts commit http://reviews.llvm.org/rL269856 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@269863 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-17[sanitizer] Move *fstat to the common interceptorsMike Aizatsky
Summary: Adds *fstat to the common interceptors. Removes the now-duplicate fstat interceptor from msan/tsan This adds fstat to asan/esan, which previously did not intercept it. Reviewers: eugenis, vitalybuka, aizatsky Subscribers: tberghammer, danalbert, srhines, kubabrecka, bruening, kcc Differential Revision: http://reviews.llvm.org/D20318 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@269856 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-11[sanitizer] Move *stat to the common interceptorsEvgeniy Stepanov
Adds *stat to the common interceptors. Removes the now-duplicate *stat interceptor from msan/tsan/esan. This adds *stat to asan, which previously did not intercept it. Patch by Qin Zhao. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@269223 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-03[sanitizer] Move stat/__xstat to the common interceptorsMike Aizatsky
Summary: Adds stat/__xstat to the common interceptors. Removes the now-duplicate stat/__xstat interceptor from msan/tsan/esan. This adds stat/__xstat to asan, which previously did not intercept it. Resubmit of http://reviews.llvm.org/D19875 with win build fixes. Reviewers: aizatsky, eugenis Subscribers: tberghammer, llvm-commits, danalbert, vitalybuka, bruening, srhines, kubabrecka, kcc Differential Revision: http://reviews.llvm.org/D19890 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@268466 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-03Revert "[sanitizer] Move stat/__xstat to the common interceptors"Mike Aizatsky
This reverts commit 268440 because it breaks the windows bot. http://lab.llvm.org:8011/builders/sanitizer-windows/builds/21425/steps/build%20compiler-rt/logs/stdio git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@268448 91177308-0d34-0410-b5e6-96231b3b80d8