Commit Graph

55 Commits

Author SHA1 Message Date
Evgeniy Stepanov e109ef854a Release memory to OS only when the requested range covers the entire page
Summary:
The current code was sometimes attempting to release huge chunks of
memory due to undesired RoundUp/RoundDown interaction when the requested
range is fully contained within one memory page.

Reviewers: eugenis

Subscribers: kubabrecka, llvm-commits

Patch by Aleksey Shlyapnikov.

Differential Revision: https://reviews.llvm.org/D27228

llvm-svn: 288271
2016-11-30 20:41:59 +00:00
Dmitry Vyukov 5dc443619e tsan: always define SANITIZER_GO
Currently we either define SANITIZER_GO for Go or don't define it at all for C++.
This works fine with preprocessor (ifdef/ifndef/defined), but does not work
for C++ if statements (e.g. if (SANITIZER_GO) {...}). Also this is different
from majority of SANITIZER_FOO macros which are always defined to either 0 or 1.

Always define SANITIZER_GO to either 0 or 1.
This allows to use SANITIZER_GO in expressions and in flag default values.

Also remove kGoMode and kCppMode, which were meant to be used in expressions,
but they are not defined in sanitizer_common code, so SANITIZER_GO become prevalent.

Also convert some preprocessor checks to C++ if's or ternary expressions.

Majority of this change is done mechanically with:
sed "s#ifdef SANITIZER_GO#if SANITIZER_GO#g"
sed "s#ifndef SANITIZER_GO#if \!SANITIZER_GO#g"
sed "s#defined(SANITIZER_GO)#SANITIZER_GO#g"

llvm-svn: 285443
2016-10-28 20:14:18 +00:00
Evgeniy Stepanov 55f9f18cb2 Fix tsan-go build.
Disable the new abort-in-SIGABRT code under SANITIZER_GO.

llvm-svn: 280980
2016-09-08 19:16:01 +00:00
Evgeniy Stepanov 337e40f157 [sanitizer] Fix a conflict between abort_on_error and handle_abort.
Reset the SIGABRT signal handler before calling abort().

Also, change the error message when catching SIGABRT to say "ABRT"
instead of "SEGV".

llvm-svn: 280885
2016-09-07 23:40:53 +00:00
Kostya Serebryany b72479b84a [asan] first attempt at releasing free-d memory back to the system using madvise. Requires quite some tuning.
llvm-svn: 279887
2016-08-26 23:58:42 +00:00
Derek Bruening 909d32955b [esan] Add handling of large stack size rlimits
Summary:
Adds detection of large stack size rlimits (over 1 TB or unlimited), which
results in an mmap location that our shadow mapping does not support.  We
re-exec the application in this situation.  Adds a test of this behavior.

Adds general detection of mmap regions outside of our app regions.  In the
future we want to try to adaptively handle these but for now we abort.

Moves the existing Linux-specific mmap code into a platform-specific file
where the new rlimit code lives.

Reviewers: eugenis

Subscribers: vitalybuka, zhaoqin, kcc, aizatsky, llvm-commits, kubabrecka

Differential Revision: http://reviews.llvm.org/D20745

llvm-svn: 271079
2016-05-28 00:25:16 +00:00
Kostya Serebryany 3884f1a5bd [sanitizer] add a function MmapNoAccess that mmaps a protected region *somewhere*; use MmapNoAccess in the Allocator when SpaceBeg is not a constant. In this mode the allocator will be a bit more hardened
llvm-svn: 267256
2016-04-23 00:05:24 +00:00
Kostya Serebryany 99ed605799 [sanitizer] rename MmapNoAccess to MmapFixedNoAccess; NFC
llvm-svn: 267253
2016-04-22 23:46:53 +00:00
Kostya Serebryany c2eb17db37 [sanitizer] revert r267203 as it breaks aarch64 bots
llvm-svn: 267251
2016-04-22 23:27:15 +00:00
Kostya Serebryany d4f275cecb [sanitizer] allow zero first parameter in MmapNoAccess; This is a part of r267094 that has been reverted
llvm-svn: 267203
2016-04-22 20:05:52 +00:00
Renato Golin aa673486c4 Revert "[sanitizer] Allow the sanitizer allocator to use a non-fixed address range. An allocator with a non-fixed address range will be attack-resistan. NFC for the sanitizers at this point."
This reverts commit r267094, because it broke a lot of MSAN tests in AArch64.
Being NFC and all, this needs some deeper investigation before it goes in again.

llvm-svn: 267136
2016-04-22 11:18:14 +00:00
Kostya Serebryany d55d0875d2 [sanitizer] Allow the sanitizer allocator to use a non-fixed address range. An allocator with a non-fixed address range will be attack-resistan. NFC for the sanitizers at this point.
llvm-svn: 267094
2016-04-22 01:08:54 +00:00
Anna Zaks c77a080bdb [asan] Add iOS support.
llvm-svn: 259451
2016-02-02 02:01:17 +00:00
Mike Aizatsky 2654299d6a [sanitizers] generating html report on coverage dump
Subscribers: tberghammer, danalbert, srhines

Differential Revision: http://reviews.llvm.org/D16374

llvm-svn: 258999
2016-01-27 23:51:36 +00:00
Mike Aizatsky 48c26de04e [sanitizers] using execv instead of execve with null env.
Differential Revision: http://reviews.llvm.org/D16646

llvm-svn: 258983
2016-01-27 20:35:18 +00:00
Mike Aizatsky 4a93316c8c [sanitizers] extracted process management functions
Differential Revision: http://reviews.llvm.org/D16546

llvm-svn: 258849
2016-01-26 20:10:01 +00:00
Kostya Serebryany 354bbb2ccd [asan] add option: handle_sigill
llvm-svn: 255588
2015-12-15 00:33:45 +00:00
Dmitry Vyukov 110094017c tsan: fix Go build on linux
librt is not linked in in Go build.

llvm-svn: 252877
2015-11-12 11:54:25 +00:00
Kuba Brecka cf41c0c930 Reapply r251918 ("[tsan] Fix build errors for TSan on OS X").
llvm-svn: 251920
2015-11-03 14:33:39 +00:00
Kuba Brecka 646e1bef09 Revert r251918 ("[tsan] Fix build errors for TSan on OS X").
llvm-svn: 251919
2015-11-03 14:30:31 +00:00
Kuba Brecka 350a9aaeda [tsan] Fix build errors for TSan on OS X
This patch moves a few functions from `sanitizer_linux_libcdep.cc` to `sanitizer_posix_libcdep.cc` in order to use them on OS X as well. Plus a few more small build fixes.

This is part of an effort to port TSan to OS X, and it's one the very first steps. Don't expect TSan on OS X to actually work or pass tests at this point.

Differential Revision: http://reviews.llvm.org/D14235

llvm-svn: 251918
2015-11-03 14:26:00 +00:00
Vedant Kumar 552c0111f1 [sanitizer_common] Apply modernize-use-nullptr, other minor fixes
- Trim spaces.
- Use nullptr in place of 0 for pointer variables.
- Use '!p' in place of 'p == 0' for null pointer checks.

Patch by Eugene Zelenko!

Differential Revision: http://reviews.llvm.org/D13310

llvm-svn: 248964
2015-09-30 23:52:54 +00:00
Kostya Serebryany cc9fd3cbe9 [sanitizer] 2-nd attempt. Add the flag handle_sigfpe that is default true to handle SIGFPE crashes same as SIGSEV crashes, patch by Karl Skomski. This time the test is enabled only on x86-64 (it broke on ARM)
llvm-svn: 244234
2015-08-06 17:52:54 +00:00
Renato Golin 4ae2e1f575 Revert "[sanitizer] Add the flag handle_sigfpe that is default true to handle SIGFPE crashes same as SIGSEV crashes, patch by Karl Skomski"
This reverts commit r244136, it was breaking the ARM bots for too long. We should investigate it offline.

llvm-svn: 244210
2015-08-06 12:42:46 +00:00
Kostya Serebryany ce1799a83f [sanitizer] Add the flag handle_sigfpe that is default true to handle SIGFPE crashes same as SIGSEV crashes, patch by Karl Skomski
llvm-svn: 244136
2015-08-05 21:19:11 +00:00
Evgeniy Stepanov 5a268b10b3 [sanitizer] Implement logging to syslog.
Previously, Android target had a logic of duplicating all sanitizer
output to logcat. This change extends it to all posix platforms via
the use of syslog, controlled by log_to_syslog flag. Enabled by
default on Android, off everywhere else.

A bit of cmake magic is required to allow Printf() to call a libc
function. I'm adding a stub implementation to support no-libc builds
like dfsan and safestack.

This is a second attempt. I believe I've fixed all the issues that
prompted the revert: Mac build, and all kinds of non-CMake builds
(there are 3 of those).

llvm-svn: 243051
2015-07-23 22:05:20 +00:00
Evgeniy Stepanov ffbc4ec790 Revert r242975.
Breaks Mac build.

llvm-svn: 242978
2015-07-23 01:29:26 +00:00
Evgeniy Stepanov 4f03227fa2 [sanitizer] Implement logging to syslog.
Previously, Android target had a logic of duplicating all sanitizer
output to logcat. This change extends it to all posix platforms via
the use of syslog, controlled by log_to_syslog flag. Enabled by
default on Android, off everywhere else.

A bit of cmake magic is required to allow Printf() to call a libc
function. I'm adding a stub implementation to support no-libc builds
like dfsan and safestack.

llvm-svn: 242975
2015-07-22 23:57:19 +00:00
Evgeniy Stepanov 1b3d46ec30 [asan] Fix undefined MAP_NORESERVE on FreeBSD.
llvm-svn: 238995
2015-06-04 00:42:15 +00:00
Evgeniy Stepanov 8e9c70be7f Add descriptive names to sanitizer entries in /proc/self/maps. Helps debugging.
This is done by creating a named shared memory region, unlinking it
and setting up a private (i.e. copy-on-write) mapping of that instead
of a regular anonymous mapping. I've experimented with regular
(sparse) files, but they can not be scaled to the size of MSan shadow
mapping, at least on Linux/X86_64 and ext3 fs.

Controlled by a common flag, decorate_proc_maps, disabled by default.

This patch has a few shortcomings:
* not all mappings are annotated, especially in TSan.
* our handling of memset() of shadow via mmap() puts small anonymous
  mappings inside larger named mappings, which looks ugly and can, in
  theory, hit the mapping number limit.

llvm-svn: 238621
2015-05-29 22:31:28 +00:00
Kostya Serebryany b044353bb2 [asan] under handle_abort=1 option intercept SIGABRT in addition to SIGSEGV/SIGBUS. Among other things this will allow to set up a death callback for SIGABRT and thus properly handle assert() in lib/Fuzzer
llvm-svn: 236474
2015-05-05 01:37:33 +00:00
Timur Iskhodzhanov c2c9ea5525 [Sanitizer RT] Get rid of internal_isatty
llvm-svn: 234423
2015-04-08 17:42:57 +00:00
Timur Iskhodzhanov 3745303c5b Move some POSIX-specific functions from sanitizer_libc.h to a new sanitizer_posix.h
llvm-svn: 234418
2015-04-08 17:08:24 +00:00
Alexander Potapenko 0ae78444e7 [ASan] Make the remaining coverage tests pass on Darwin, move them to Posix/
This CL:
 - moves PrepareForSandboxing() to sanitizer_posix_libcdep.cc
 - fixes the coverage tests to use flag substitutions defined in r233802 and not rely on hardcoded shared library names
 - moves those tests to TestCases/Posix so that they can be executed on Darwin

llvm-svn: 233828
2015-04-01 17:56:29 +00:00
Yury Gribov 8f848ff5ed [ASan] Add use_madv_dontdump flag.
Differential Revision: http://reviews.llvm.org/D7294

llvm-svn: 227959
2015-02-03 10:15:15 +00:00
Kostya Serebryany c6338ac943 [asan] use MADV_NOHUGEPAGE for shadow to reduce the actual memory usage
llvm-svn: 226636
2015-01-21 02:05:31 +00:00
Alexey Samsonov 4925fd4b05 Fix -Wcast-qual warnings in sanitizers
llvm-svn: 221936
2014-11-13 22:40:59 +00:00
Alexey Samsonov 1947bf9921 PR20721: Don't let UBSan print inaccessible memory
Summary:
UBSan needs to check if memory snippet it's going to print resides
in addressable memory. Similar check might be helpful in ASan with
dump_instruction_bytes option (see http://reviews.llvm.org/D5167).

Instead of scanning /proc/self/maps manually, delegate this check to
the OS kernel: try to write this memory in a syscall and assume that
memory is inaccessible if the syscall failed (e.g. with EFAULT).

Fixes PR20721.

Test Plan: compiler-rt test suite

Reviewers: eugenis, glider

Reviewed By: glider

Subscribers: emaste, ygribov, llvm-commits, glider, rsmith

Differential Revision: http://reviews.llvm.org/D5253

llvm-svn: 217971
2014-09-17 17:56:15 +00:00
Viktor Kutuzov 1827415be4 Do not assume RLIM_INFINITY is always (rlim_t)-1in sanitizers code
Differential Revision: http://reviews.llvm.org/D5212

llvm-svn: 217308
2014-09-06 07:52:51 +00:00
Alexander Potapenko 9d24aa0fa8 [ASan] allow deadly signals to be received in signal handlers
(previously ASan would just crash upon the second SEGV)
Other tools do not use this code yet.

llvm-svn: 217137
2014-09-04 09:34:22 +00:00
Alexey Samsonov 34e2b280da [TSan] Share the code the setup code calling getrlim/setrlim with sanitizer_common
llvm-svn: 215481
2014-08-12 22:31:19 +00:00
Alexander Potapenko 623c989eea [ASan] Use a non-null altstack.ss_size when disabling sigaltstack on Darwin.
llvm-svn: 207220
2014-04-25 10:39:41 +00:00
Alexey Samsonov a7c602ac29 A set of trivial changes to support sanitizers on FreeBSD.
Patch by Viktor Kutuzov!

llvm-svn: 202801
2014-03-04 08:55:41 +00:00
Joerg Sonnenberger 9d09e2fe90 Reapply r201910. MSVC gets __func__ defined explicitly, even though it
can't build anything here.

llvm-svn: 202297
2014-02-26 20:33:22 +00:00
Reid Kleckner 324eee45a7 Revert "Replace __FUNCTION__ with __func__, the latter being standard C99/C++11."
This reverts commit r201910.

While __func__ may be standard in C++11, it was only recently added to
MSVC in 2013 CTP, and LLVM supports MSVC 2012.  __FUNCTION__ may not be
standard, but it's *very* portable.

llvm-svn: 201916
2014-02-22 00:37:45 +00:00
Joerg Sonnenberger b15779f307 Replace __FUNCTION__ with __func__, the latter being standard C99/C++11.
llvm-svn: 201910
2014-02-21 23:55:15 +00:00
Evgeniy Stepanov 50bef914a6 [asan] Override default sigaltstack setting on Android.
Android libc always sets altstack on non-main threads, but it is too small for
our unwinder. With use_sigaltstack=1, override this setting with a larger one.

llvm-svn: 201557
2014-02-18 11:14:30 +00:00
Alexander Potapenko 36b18dfe64 [libsanitizer] Fix compilation for gotsan.
llvm-svn: 200549
2014-01-31 14:30:12 +00:00
Alexander Potapenko 789e3e1b7c [ASan] Move the SIGSEGV/SIGBUS handling to sanitizer_common
This change is a part of refactoring intended to have common signal handling behavior in all tools.
This particular CL moves InstallSignalHandlers() into sanitizer_common (making it InstallDeadlySignalHandlers()), but doesn't enable default signal handlers for any tool other than ASan.

llvm-svn: 200542
2014-01-31 13:10:07 +00:00
Alexander Potapenko d8d490ed50 [ASan] Move the sigaltstack() bits to sanitizer_common.
This change is a part of refactoring intended to have common signal handling behavior in all tools.
Note that this particular change doesn't enable use_sigaltstack support in every tool.

llvm-svn: 200310
2014-01-28 11:12:29 +00:00