summaryrefslogtreecommitdiffstats
path: root/compiler-rt/lib/asan/asan_allocator.cc
Commit message (Collapse)AuthorAgeFilesLines
* compiler-rt: Rename .cc file in lib/asan to .cppNico Weber2019-08-011-1119/+0
| | | | | | Like r367463, but for asan. llvm-svn: 367558
* [sanitizer] Implement reallocarray.Evgeniy Stepanov2019-05-011-0/+11
| | | | | | | | | | | | | | | | Summary: It's a cross of calloc and realloc. Sanitizers implement calloc-like check for size overflow. Reviewers: vitalybuka, kcc Subscribers: kubamracek, #sanitizers, llvm-commits Tags: #sanitizers, #llvm Differential Revision: https://reviews.llvm.org/D61108 llvm-svn: 359708
* Update the file headers across all of the LLVM projects in the monorepoChandler Carruth2019-01-191-4/+3
| | | | | | | | | | | | | | | | | to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
* [Sanitizers] Check alignment != 0 for aligned_alloc and posix_memalignAlex Shlyapnikov2018-06-081-0/+11
| | | | | | | | | | | | | | | Summary: Move the corresponding tests to the common folder (as all of the sanitizer allocators will support this feature soon) and add the checks specific to aligned_alloc to ASan and LSan allocators. Reviewers: vitalybuka Subscribers: srhines, kubamracek, delcypher, #sanitizers, llvm-commits Differential Revision: https://reviews.llvm.org/D47924 llvm-svn: 334316
* [ASan] Report proper ASan error on allocator failures instead of CHECK(0)-ingAlex Shlyapnikov2018-03-281-28/+55
| | | | | | | | | | | | | | | | | | Summary: Currently many allocator specific errors (OOM, for example) are reported as a text message and CHECK(0) termination, not stack, no details, not too helpful nor informative. To improve the situation, ASan detailed errors were defined and reported under the appropriate conditions. Issue: https://github.com/google/sanitizers/issues/887 Reviewers: eugenis Subscribers: kubamracek, delcypher, #sanitizers, llvm-commits Differential Revision: https://reviews.llvm.org/D44404 llvm-svn: 328722
* [Sanitizers] Make common allocator agnostic to failure handling modes.Alex Shlyapnikov2018-01-171-9/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Make common allocator agnostic to failure handling modes and move the decision up to the particular sanitizer's allocator, where the context is available (call stack, parameters, return nullptr/crash mode etc.) It simplifies the common allocator and allows the particular sanitizer's allocator to generate more specific and detailed error reports (which will be implemented later). The behavior is largely the same, except one case, the violation of the common allocator's check for "size + alignment" overflow is now reportied as OOM instead of "bad request". It feels like a worthy tradeoff and "size + alignment" is huge in this case anyway (thus, can be interpreted as not enough memory to satisfy the request). There's also a Report() statement added there. Reviewers: eugenis Subscribers: kubamracek, llvm-commits, #sanitizers Differential Revision: https://reviews.llvm.org/D42198 llvm-svn: 322784
* [asan] Use linker initialization for the allocatorKuba Mracek2017-12-141-3/+3
| | | | | | | | This saves ~2 MB of dirty memory footprint. Can be a big deal on mobile devices especially when running multiple processes with ASan. Differential Revision: https://reviews.llvm.org/D40627 llvm-svn: 320660
* [Sanitizers] ASan: detect new/delete calls with mismatched alignment.Alex Shlyapnikov2017-10-251-14/+40
| | | | | | | | | | | | | | | | | | | ASan allocator stores the requested alignment for new and new[] calls and on delete and delete[] verifies that alignments do match. The representable alignments are: default alignment, 8, 16, 32, 64, 128, 256 and 512 bytes. Alignments > 512 are stored as 512, hence two different alignments > 512 will pass the check (possibly masking the bug), but limited memory requirements deemed to be a resonable tradeoff for relaxed conditions. The feature is controlled by new_delete_type_mismatch flag, the same one protecting new/delete matching size check. Differential revision: https://reviews.llvm.org/D38574 Issue: https://github.com/google/sanitizers/issues/799 llvm-svn: 316595
* [Sanitizers] New sanitizer API to purge allocator quarantine.Alex Shlyapnikov2017-10-231-0/+20
| | | | | | | | | | | | | | | | Summary: Purging allocator quarantine and returning memory to OS might be desired between fuzzer iterations since, most likely, the quarantine is not going to catch bugs in the code under fuzz, but reducing RSS might significantly prolong the fuzzing session. Reviewers: cryptoad Subscribers: kubamracek, llvm-commits Differential Revision: https://reviews.llvm.org/D39153 llvm-svn: 316347
* [asan] Check for pvalloc overlowKostya Kortchinsky2017-08-041-0/+4
| | | | | | | | | | | | | | | | | | | | Summary: Last one of the `pvalloc` overflow checks! `CheckForPvallocOverflow` was introduced with D35818 to detect when `pvalloc` would wrap when rounding up to the next multiple of the page size. Add this check to ASan's `pvalloc` implementation. Reviewers: alekseyshl Reviewed By: alekseyshl Subscribers: llvm-commits, kubamracek Differential Revision: https://reviews.llvm.org/D36257 llvm-svn: 310119
* [Sanitizers] ASan/MSan/LSan allocators set errno on failure.Alex Shlyapnikov2017-07-181-16/+11
| | | | | | | | | | | | | | | | | | | | | 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 llvm-svn: 308344
* [Sanitizers] ASan and LSan allocator set errno on failure.Alex Shlyapnikov2017-07-141-15/+32
| | | | | | | | | | | | | | | | | | | Summary: Set proper errno code on alloction failures and change some implementations to satisfy their man-specified requirements: LSan: valloc and memalign ASan: pvalloc, memalign and posix_memalign Changing both allocators in one patch since LSan depends on ASan allocator in some configurations. Reviewers: vitalybuka Subscribers: kubamracek, llvm-commits Differential Revision: https://reviews.llvm.org/D35440 llvm-svn: 308064
* MergeAlex Shlyapnikov2017-06-291-1/+1
| | | | llvm-svn: 306746
* [Sanitizers] Operator new() interceptors always die on allocation errorAlex Shlyapnikov2017-06-281-4/+7
| | | | | | | | | | | | | | | | | | | | | Summary: Operator new interceptors behavior is now controlled by their nothrow property as well as by allocator_may_return_null flag value: - allocator_may_return_null=* + new() - die on allocation error - allocator_may_return_null=0 + new(nothrow) - die on allocation error - allocator_may_return_null=1 + new(nothrow) - return null Ideally new() should throw std::bad_alloc exception, but that is not trivial to achieve, hence TODO. Reviewers: eugenis Subscribers: kubamracek, llvm-commits Differential Revision: https://reviews.llvm.org/D34731 llvm-svn: 306604
* [Sanitizers] Move cached allocator_may_return_null flag to sanitizer_allocatorAlex Shlyapnikov2017-06-201-8/+9
| | | | | | | | | | | | | | | | | | | | | | | | | Summary: Move cached allocator_may_return_null flag to sanitizer_allocator.cc and provide API to consolidate and unify the behavior of all specific allocators. Make all sanitizers using CombinedAllocator to follow AllocatorReturnNullOrDieOnOOM() rules to behave the same way when OOM happens. When OOM happens, turn allocator_out_of_memory flag on regardless of allocator_may_return_null flag value (it used to not to be set when allocator_may_return_null == true). release_to_os_interval_ms and rss_limit_exceeded will likely be moved to sanitizer_allocator.cc too (later). Reviewers: eugenis Subscribers: srhines, kubamracek, llvm-commits Differential Revision: https://reviews.llvm.org/D34310 llvm-svn: 305858
* [Sanitizer] Remove CombinedAllocator::Allocate's 'cleared' parameterAlex Shlyapnikov2017-06-161-5/+3
| | | | | | | | | | | | | | Summary: CombinedAllocator::Allocate cleared parameter is not used anywhere and seem to be obsolete. Reviewers: eugenis Subscribers: llvm-commits, kubamracek Differential Revision: https://reviews.llvm.org/D34289 llvm-svn: 305590
* [ASan] Move rss_limit_is_exceeded_ flag to ASan.Alex Shlyapnikov2017-06-131-5/+16
| | | | | | | | | | | | | | Summary: Move the OOM decision based on RSS limits out of generic allocator to ASan allocator, where it makes more sense at the moment. Reviewers: eugenis Subscribers: kubamracek, llvm-commits Differential Revision: https://reviews.llvm.org/D34180 llvm-svn: 305342
* Revert r304285, r304297.Evgeniy Stepanov2017-06-051-1/+3
| | | | | | | | | | | 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 llvm-svn: 304735
* [sanitizer] Avoid possible deadlock in child process after forkMaxim Ostapenko2017-05-311-3/+1
| | | | | | | | | | | | | | 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 llvm-svn: 304285
* [asan] Implement "scribble" flags, which overwrite free'd memory with 0x55Kuba Mracek2017-03-301-0/+12
| | | | | | | | This patch implements "Malloc Scribble" in ASan via "max_free_fill_size" and "free_fill_byte" flags, which can be used to overwrite free()'d memory. We also match the behavior of MallocScribble and MallocPreScribble env vars on macOS (see https://developer.apple.com/library/content/documentation/Performance/Conceptual/ManagingMemory/Articles/MallocDebug.html), which is a helpful tool to detect use-after-free bugs that happen in non-instrumented code. Differential Revision: https://reviews.llvm.org/D30101 llvm-svn: 299085
* Add allocator_frees_and_returns_null_on_realloc_zero=false flag for ↵Filipe Cabecinhas2017-03-291-2/+6
| | | | | | | | | | | | | | | | | | | compatibility with allocators which allow a realloc(p, 0) and don't free the pointer. Summary: I know of two implementations that do this (ASan is not protecting against accessing the returned memory for now, just like malloc(0)): SIE libc on the PS4 dlmalloc has a flag for this This allows us to properly support this behaviour. Reviewers: vsk, kcc Subscribers: llvm-commits, kubamracek Differential Revision: https://reviews.llvm.org/D31295 llvm-svn: 299016
* [compiler-rt][asan] Add support for desallocation of unhandled pointersEtienne Bergeron2017-02-211-0/+10
| | | | | | | | | | | | | | Summary: On windows 10, the ucrt DLL is performing allocations before the function hooking and there are multiple allocations not handled by Asan. When a free occur at the end of the process, asan is reporting desallocations not malloc-ed. Reviewers: rnk, kcc Reviewed By: rnk, kcc Subscribers: kcc, llvm-commits, kubamracek, chrisha, dberris Differential Revision: https://reviews.llvm.org/D25946 llvm-svn: 295730
* General definition for weak functionsMarcos Pividori2017-01-291-6/+4
| | | | | | | | | | | | | | | | | | In this diff, I define a general macro for defining weak functions with a default implementation: "SANITIZER_INTERFACE_WEAK_DEF()". This way, we simplify the implementation for different platforms. For example, we cannot define weak functions on Windows, but we can use linker pragmas to create an alias to a default implementation. All of these implementation details are hidden in the new macro. Also, as I modify the name for exported weak symbols on Windows, I needed to temporarily disable "dll_host" test for asan, which checks the list of functions included in asan_win_dll_thunk. Differential Revision: https://reviews.llvm.org/D28596 llvm-svn: 293419
* Repoison the entire ASan chunk if it is not in active use.Alex Shlyapnikov2017-01-111-6/+6
| | | | | | | | | | | | | | | | | | Summary: Repoisoning just the minimal redzones might leave an unpoisoned gap of the size of the actual redzone minus minimal redzone size. After ASan activation the actual redzone might be bigger than the minimal size and ASan allocator assumes that the chunk returned by the common allocator is either entirely poisoned or entirely not poisoned (it's too expensive to check the entire chunk or always poison one). Reviewers: eugenis Subscribers: kubabrecka, llvm-commits Differential Revision: https://reviews.llvm.org/D28577 llvm-svn: 291714
* Improved ASAN allocator and quarantine stats.Evgeniy Stepanov2017-01-051-12/+16
| | | | | | | | | | | | | | Summary: Improved ASAN allocator and quarantine stats. Reviewers: eugenis Patch by Alex Shlyapnikov. Subscribers: llvm-commits, kubabrecka Differential Revision: https://reviews.llvm.org/D28333 llvm-svn: 291183
* Expose thread local quarantine size as ASAN option.Evgeniy Stepanov2016-12-221-8/+4
| | | | | | | | | | | | | | Summary: Make thread local quarantine size an option so it can be turned off to save memory. Reviewers: eugenis Patch by Alex Shlyapnikov. Subscribers: kubabrecka, llvm-commits Differential Revision: https://reviews.llvm.org/D28027 llvm-svn: 290373
* Reduce the size of quarantine cache in ASAN_LOW_MEMORY configuration.Evgeniy Stepanov2016-12-211-1/+6
| | | | | | | | | | | | | | | | Summary: Experiments show that on Android the current values result in too much of the memory consumption for all quarantined chunks. Reviewers: kcc, eugenis Subscribers: mgorny, danalbert, srhines, llvm-commits, kubabrecka Patch by Aleksey Shlyapnikov. Differential Revision: https://reviews.llvm.org/D27873 llvm-svn: 290218
* Return memory to OS right after free (not in the async thread).Evgeniy Stepanov2016-11-291-6/+5
| | | | | | | | | | | | | | | | | | Summary: In order to avoid starting a separate thread to return unused memory to the system (the thread interferes with process startup on Android, Zygota waits for all threads to exit before fork, but this thread never exits), try to return it right after free. Reviewers: eugenis Subscribers: cryptoad, filcab, danalbert, kubabrecka, llvm-commits Patch by Aleksey Shlyapnikov. Differential Revision: https://reviews.llvm.org/D27003 llvm-svn: 288091
* Don't use internal symbolizer if we are in process of reporting Out-of-Memory.Vitaly Buka2016-09-291-4/+3
| | | | | | Reviewed by eugenis offline, as reviews.llvm.org is down. llvm-svn: 282805
* [asan] Re-poison all redzones on activation.Evgeniy Stepanov2016-09-131-0/+34
| | | | | | | | | | | | | When running with start_deactivated=1 in ASAN_OPTIONS, heap redzones are not poisoned until the first instrumented module is loaded. This can cause false negatives even on memory allocated after activation, because redzones are normally poisoned only once when a new allocator region is mapped. This change attempts to fix it by iterating over all existing allocator chunks and poisoning their redzones. llvm-svn: 281364
* [asan] Reify ErrorNewDeleteSizeMismatchFilipe Cabecinhas2016-09-071-1/+1
| | | | | | | | | | | | Summary: Keep reifying other errors. Reviewers: kcc, samsonov Subscribers: llvm-commits, kubabrecka Differential Revision: https://reviews.llvm.org/D23874 llvm-svn: 280812
* [asan] first attempt at releasing free-d memory back to the system using ↵Kostya Serebryany2016-08-261-0/+5
| | | | | | madvise. Requires quite some tuning. llvm-svn: 279887
* [asan] minor fix in the asan memory profileKostya Serebryany2016-08-231-0/+3
| | | | llvm-svn: 279547
* Deal with buildbot fallout from r278917: s/AllocType()/GetAllocType()/ (had ↵Filipe Cabecinhas2016-08-171-2/+2
| | | | | | the same name as the enum) llvm-svn: 278919
* Rename DescribeHeapAddress to DescribeAddressIfHeap and split it into a ↵Filipe Cabecinhas2016-08-171-0/+3
| | | | | | | | | | | | | | | | | function to get all the information about the address, and one to print it. Summary: Replacement for part of D23518 This deals with heap addresses, and renames DescribeHeapAddress. Requires D23520, which moves code around to make it accessible in asan_describers.cc (and still accessible in asan_report.cc if needed). Reviewers: kcc, samsonov Subscribers: kubabrecka, llvm-commits Differential Revision: https://reviews.llvm.org/D23569 llvm-svn: 278917
* In asan on Windows 64-bit, this is one of the broken thingsEtienne Bergeron2016-06-141-1/+1
| | | | | | | | | | | that makes allocation fail. "UL" is 32-bit and shift by 40 will make the value overflow and become 0. Patch by Wei Wang Differential Revision: http://reviews.llvm.org/D21310 llvm-svn: 272689
* [asan] add an interface function __sanitizer_print_memory_profile (a basic ↵Kostya Serebryany2016-06-021-2/+5
| | | | | | memory profiler; asan/Linux-only for now) llvm-svn: 271463
* [asan] Assert in __sanitizer_ptr_{sub,cmp} if one of the pointers was freed.Filipe Cabecinhas2016-04-291-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This (partially) implements the check mentioned at http://kristerw.blogspot.co.uk/2016/04/dangling-pointers-and-undefined-behavior.html (via John Regehr) Quoting: "That the behavior is undefined follows from C11 6.2.4 "Storage durations of objects" The lifetime of an object is the portion of program execution during which storage is guaranteed to be reserved for it. An object exists, has a constant address, and retains its last-stored value throughout its lifetime. If an object is referred to outside of its lifetime, the behavior is undefined. The value of a pointer becomes indeterminate when the object it points to (or just past) reaches the end of its lifetime. and 7.22.3 "Memory management functions" that says that free ends the lifetime of objects The lifetime of an allocated object extends from the allocation until the deallocation. " We can probably implement this for stack variables too, but I think this is a good start to see if there's interest in this check. We can also hide this behind a flag, too. Reviewers: samsonov, kcc, rsmith, regehr Subscribers: kubabrecka, llvm-commits Differential Revision: http://reviews.llvm.org/D19691 llvm-svn: 268097
* [asan] Prefer alloc-dealloc-mismatch to new-delete-type-mismatch.Evgeniy Stepanov2016-04-131-12/+14
| | | | | | | | With -fsized-deallocation, new[] vs delete mismatch is reported as new-delete-type-mismatch. This is technically true, but alloc-dealloc-mismatch describes it better. llvm-svn: 266246
* [asan] Intercept all Heap* related imports from ucrtbase.dllReid Kleckner2016-03-241-1/+1
| | | | | | | | | | | | | | | | | | | | | | ucrtbase.dll appears to be built with some kind of cross-module inlining, because there are calls to imported Heap* routines sprinkled throughout the code. This inlining defeats our attempts to hotpatch malloc, _malloc_base, and related functions. Failing to intercept an allocation or deallocation results in a crash when the program attempts to deallocate or reallocate memory with the wrong allocator. This change patches the IAT of ucrtbase.dll to replace the addresses of the imported Heap* functions with implementations provided by ASan. We don't globally intercept the win32 Heap* functions because they are typically used by system DLLs that run before ASan initializes. Eventually, we may want to intercept them, but for now I think this is the minimal change that will keep ASan stable. Reviewers: samsonov Differential Revision: http://reviews.llvm.org/D18413 llvm-svn: 264327
* [asan] Fix internal CHECK failure on double free in recovery mode.Maxim Ostapenko2016-02-021-5/+13
| | | | | | | | This patches fixes https://github.com/google/sanitizers/issues/639 Differential Revision: http://reviews.llvm.org/D15807 llvm-svn: 259473
* [compiler-rt] Apply modernize-use-nullptr fixes in sanitizersVedant Kumar2015-10-011-11/+11
| | | | | | | | | | | | | | | | | | - Trim spaces. - Use nullptr in place of 0 for pointer variables. - Use '!p' in place of 'p == 0' for null pointer checks. - Add blank lines to separate function definitions. - Add 'extern "C"' or 'namespace foo' comments after the appropriate closing brackets This is a continuation of work from 409b7b82. The focus here is on the various sanitizers (not sanitizer_common, as before). Patch by Eugene Zelenko! Differential Revision: http://reviews.llvm.org/D13225 llvm-svn: 248966
* [ASan] Clean up obsolete stats.Alexey Samsonov2015-06-261-3/+2
| | | | | | | | Remove stats that we no longer collect after the allocator change. Use proper constant SizeClassMap::kNumClasses to fix potential buffer overflow (https://code.google.com/p/address-sanitizer/issues/detail?id=397). llvm-svn: 240816
* [ASan] Bump maximum allowed malloc() size in ASan allocator to 1Tb.Alexey Samsonov2015-06-051-2/+2
| | | | | | 1Tb of RAM ought to be enough for anybody. llvm-svn: 239187
* [asan] add flag quarantine_size_mb, deprecate quarantine_sizeKostya Serebryany2015-01-071-2/+2
| | | | llvm-svn: 225337
* [asan] add a flag soft_rss_limit_mbKostya Serebryany2015-01-061-2/+12
| | | | llvm-svn: 225323
* [ASan] Change activation strategy.Alexey Samsonov2014-12-191-0/+21
| | | | | | | | | | | Now ASan deactivation doesn't modify common or ASan-specific runtime flags. Flags stay constant after initialization, and "deactivation" instead stashes initialized runtime state, and deactivates the runtime. Activation then just restores the original state (possibly, overriden by some activation flags provided in system property on Android). llvm-svn: 224614
* [ASan] Introduce AllocatorOptions to configure allocator behavior.Alexey Samsonov2014-12-191-16/+51
| | | | | | | | | | | | | | | | | | | Summary: Reduce the dependency of allocator code on runtime flags. Instead, pass a bunch of options that configure allocator behavior at initialization or re-initialization. That would allow us to cleaner modify allocator behavior during a program execution when ASan is activated or de-activated. Test Plan: regression test suite Reviewers: kcc Subscribers: llvm-commits, eugenis Differential Revision: http://reviews.llvm.org/D6711 llvm-svn: 224605
* [ASan] Re-structure the allocator code. NFC.Alexey Samsonov2014-12-171-420/+470
| | | | | | | | | | | | | Introduce "Allocator" object, which contains all the bits and pieces ASan allocation machinery actually use: allocator from sanitizer_common, quarantine, fallback allocator and quarantine caches, fallback mutex. This step is a preparation to adding more state to this object. We want to reduce dependency of Allocator on commandline flags and be able to "safely" modify its behavior (such as the size of the redzone) at runtime. llvm-svn: 224406
* Rename asan_allocator2.cc to asan_allocator.ccAlexey Samsonov2014-12-171-0/+793
| | | | llvm-svn: 224396
OpenPOWER on IntegriCloud