summaryrefslogtreecommitdiff
path: root/test/scudo
AgeCommit message (Collapse)Author
2017-08-16[scudo] Application & platform compatibility changesKostya Kortchinsky
Summary: This patch changes a few (small) things around for compatibility purposes for the current Android & Fuchsia work: - `realloc`'ing some memory that was not allocated with `malloc`, `calloc` or `realloc`, while UB according to http://pubs.opengroup.org/onlinepubs/009695399/functions/realloc.html is more common that one would think. We now only check this if `DeallocationTypeMismatch` is set; change the "mismatch" error messages to be more homogeneous; - some sketchily written but widely used libraries expect a call to `realloc` to copy the usable size of the old chunk to the new one instead of the requested size. We have to begrundingly abide by this de-facto standard. This doesn't seem to impact security either way, unless someone comes up with something we didn't think about; - the CRC32 intrinsics for 64-bit take a 64-bit first argument. This is misleading as the upper 32 bits end up being ignored. This was also raising `-Wconversion` errors. Change things to take a `u32` as first argument. This also means we were (and are) only using 32 bits of the Cookie - not a big thing, but worth mentioning. - Includes-wise: prefer `stddef.h` to `cstddef`, move `scudo_flags.h` where it is actually needed. - Add tests for the memalign-realloc case, and the realloc-usable-size one. (Edited typos) Reviewers: alekseyshl Reviewed By: alekseyshl Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D36754 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@311018 91177308-0d34-0410-b5e6-96231b3b80d8
2017-07-25[scudo] Check for pvalloc overflowKostya Kortchinsky
Summary: Previously we were rounding up the size passed to `pvalloc` to the next multiple of page size no matter what. There is an overflow possibility that wasn't accounted for. So now, return null in the event of an overflow. The man page doesn't seem to indicate the errno to set in this particular situation, but the glibc unit tests go for ENOMEM (https://code.woboq.org/userspace/glibc/malloc/tst-pvalloc.c.html#54) so we'll do the same. Update the aligned allocation funtions tests to check for properly aligned returned pointers, and the `pvalloc` corner cases. @alekseyshl: do you want me to do the same in the other Sanitizers? Reviewers: alekseyshl Reviewed By: alekseyshl Subscribers: kubamracek, alekseyshl, llvm-commits Differential Revision: https://reviews.llvm.org/D35818 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@309033 91177308-0d34-0410-b5e6-96231b3b80d8
2017-07-24[scudo] Fix QuarantineChunksUpToSize failing test on AArch64Kostya Kortchinsky
Summary: Warm-up the other 2 sizes used by the tests, which should get rid of a failure on AArch64. Reviewers: alekseyshl Reviewed By: alekseyshl Subscribers: aemerson, rengolin, llvm-commits, kristof.beyls Differential Revision: https://reviews.llvm.org/D35806 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@308907 91177308-0d34-0410-b5e6-96231b3b80d8
2017-07-24[scudo] Quarantine overhaulKostya Kortchinsky
Summary: First, some context. The main feedback we get about the quarantine is that it's too memory hungry. A single MB of quarantine will have an impact of 3 to 4MB of PSS/RSS, and things quickly get out of hand in terms of memory usage, and the quarantine ends up disabled. The main objective of the quarantine is to protect from use-after-free exploitation by making it harder for an attacker to reallocate a controlled chunk in place of the targeted freed chunk. This is achieved by not making it available to the backend right away for reuse, but holding it a little while. Historically, what has usually been the target of such attacks was objects, where vtable pointers or other function pointers could constitute a valuable targeti to replace. Those are usually on the smaller side. There is barely any advantage in putting the quarantine several megabytes of RGB data or the like. Now for the patch. This patch introduces a new way the Quarantine behaves in Scudo. First of all, the size of the Quarantine will be defined in KB instead of MB, then we introduce a new option: the size up to which (lower than or equal to) a chunk will be quarantined. This way, we only quarantine smaller chunks, and the size of the quarantine remains manageable. It also prevents someone from triggering a recycle by allocating something huge. We default to 512 bytes on 32-bit and 2048 bytes on 64-bit platforms. In details, the patches includes the following: - introduce `QuarantineSizeKb`, but honor `QuarantineSizeMb` if set to fall back to the old behavior (meaning no threshold in that case); `QuarantineSizeMb` is described as deprecated in the options descriptios; documentation update will follow; - introduce `QuarantineChunksUpToSize`, the new threshold value; - update the `quarantine.cpp` test, and other tests using `QuarantineSizeMb`; - remove `AllocatorOptions::copyTo`, it wasn't used; - slightly change the logic around `quarantineOrDeallocateChunk` to accomodate for the new logic; rename a couple of variables there as well; Rewriting the tests, I found a somewhat annoying bug where non-default aligned chunks would account for more than needed when placed in the quarantine due to `<< MinAlignment` instead of `<< MinAlignmentLog`. This is fixed and tested for now. Reviewers: alekseyshl, kcc Reviewed By: alekseyshl Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D35694 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@308884 91177308-0d34-0410-b5e6-96231b3b80d8
2017-07-14[Sanitizers] Scudo allocator set errno on failure.Alex Shlyapnikov
Summary: Set proper errno code on alloction failure and change pvalloc and posix_memalign implementation to satisfy their man-specified requirements. Reviewers: cryptoad Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D35429 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@308053 91177308-0d34-0410-b5e6-96231b3b80d8
2017-06-29[scudo] Change aligned alloc functions to be more compliant & perf changesKostya Kortchinsky
Summary: We were not following the `man` documented behaviors for invalid arguments to `memalign` and associated functions. Using `CHECK` for those was a bit extreme, so we relax the behavior to return null pointers as expected when this happens. Adapt the associated test. I am using this change also to change a few more minor performance improvements: - mark as `UNLIKELY` a bunch of unlikely conditions; - the current `CHECK` in `__sanitizer::RoundUpTo` is redundant for us in *all* calls. So I am introducing our own version without said `CHECK`. - change our combined allocator `GetActuallyAllocatedSize`. We already know if the pointer is from the Primary or Secondary, so the `PointerIsMine` check is redundant as well, and costly for the 32-bit Primary. So we get the size by directly using the available Primary functions. Finally, change a `int` to `uptr` to avoid a warning/error when compiling on Android. Reviewers: alekseyshl Reviewed By: alekseyshl Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D34782 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@306698 91177308-0d34-0410-b5e6-96231b3b80d8
2017-06-28[Sanitizers] Operator new() interceptors always die on allocation errorAlex Shlyapnikov
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 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@306604 91177308-0d34-0410-b5e6-96231b3b80d8
2017-06-19[scudo] Enabling MIPS support for ScudoSagar Thakur
Adding MIPS 32-bit and 64-bit support for Scudo. Reviewed by cryptoad, sdardis. Differential: D31803 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@305682 91177308-0d34-0410-b5e6-96231b3b80d8
2017-04-24Revert [scudo] Enabling MIPS support for ScudoSagar Thakur
This patch broke the buildbot clang-cmake-mips. Investigating the issue. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@301173 91177308-0d34-0410-b5e6-96231b3b80d8
2017-04-24[scudo] Enabling MIPS support for ScudoSagar Thakur
Adding MIPS 32-bit and 64-bit support for Scudo. Reviewed by cryptoad Differential: D31803 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@301158 91177308-0d34-0410-b5e6-96231b3b80d8
2017-03-23[scudo] Add test exercising pthreadsKostya Kortchinsky
Summary: Scudo didn't have any test using multiple threads. Add one, borrowed from lsan. Reviewers: kcc, alekseyshl Reviewed By: alekseyshl Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D31297 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@298636 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-06[scudo] Fix standalone compiler-rt test breakageKostya Kortchinsky
Summary: Apparently "test standalone compiler-rt" still requires -ldl and -lrt for Scudo even with --gc-sections. I am not entirely sure why, so if anybody has some input, feel free to chime in. In the meantime, add again those two to fix the test. Reviewers: kcc, alekseyshl Reviewed By: kcc Subscribers: Hahnfeld, dberris, llvm-commits Differential Revision: https://reviews.llvm.org/D29527 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@294199 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-03[scudo] Fix buildbot test error on ARMKostya Kortchinsky
Summary: The assumption __sanitizer_get_heap_size() == 0 (introduced in D29341) at the start of a program appears to be incorrect on some ARM machines (SizeClassAllocator32). This should fix the test while I investigate the issue. Reviewers: kcc, alekseyshl Reviewed By: alekseyshl Subscribers: aemerson, rengolin, llvm-commits Differential Revision: https://reviews.llvm.org/D29516 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@294056 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-03[scudo] 32-bit quarantine sizes adjustments and bug fixesKostya Kortchinsky
Summary: The local and global quarantine sizes were not offering a distinction for 32-bit and 64-bit platforms. This is addressed with lower values for 32-bit. When writing additional tests for the quarantine, it was discovered that when calling some of the allocator interface function prior to any allocation operation having occured, the test would crash due to the allocator not being initialized. This was addressed by making sure the allocator is initialized for those scenarios. Relevant tests were added in interface.cpp and quarantine.cpp. Last change being the removal of the extraneous link dependencies for the tests thanks to rL293220, anf the addition of the gc-sections linker flag. Reviewers: kcc, alekseyshl Reviewed By: alekseyshl Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D29341 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@294037 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-25[scudo] Enabling AArch64 support for ScudoKostya Kortchinsky
Summary: Adding ARM64 as a supported architecture for Scudo. The random shuffle is not yet supported for SizeClassAllocator32, which is used by the AArch64 allocator, so disable the associated test for now. Reviewers: kcc, alekseyshl, rengolin Reviewed By: rengolin Subscribers: aemerson, mgorny, llvm-commits Differential Revision: https://reviews.llvm.org/D28960 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@293068 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-20[scudo] Replacing std::atomic with Sanitizer's atomicsKostya Kortchinsky
Summary: In an effort to getting rid of dependencies to external libraries, we are replacing atomic PackedHeader use of std::atomic with Sanitizer's atomic_uint64_t, which allows us to avoid -latomic. Reviewers: kcc, phosek, alekseyshl Reviewed By: alekseyshl Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D28864 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@292630 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-23[scudo] Use the macro get_test_cc_for_arch for the testsKostya Kortchinsky
Summary: The macro was introduced with D26929, use it in Scudo as well. Reviewers: kcc, alekseyshl, kubabrecka Subscribers: llvm-commits, danalbert, srhines, mgorny Differential Revision: https://reviews.llvm.org/D28066 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@290439 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-20[scudo] ARM32 supportKostya Kortchinsky
Summary: With the previous modifications, the code works on ARM32. The random shuffle test is unsupported on 32-bit platforms for the moment and being marked as such. There is no hardware support for the checksum computation yet, this will come at a later point. Reviewers: kcc, alekseyshl Subscribers: llvm-commits, aemerson, rengolin, mgorny Differential Revision: https://reviews.llvm.org/D27957 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@290201 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-14[scudo] Relax the memalign testKostya Kortchinsky
Summary: Now that we are not rounding up the sizes passed to the secondary allocator, the memalign test could run out of aligned addresses to return for larger alignments. We now reduce the size of the quarantine for that test, and allocate less chunks for the larger alignments. Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D27760 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@289665 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-30[scudo] 32-bit and hardware agnostic supportKostya Kortchinsky
Summary: This update introduces i386 support for the Scudo Hardened Allocator, and offers software alternatives for functions that used to require hardware specific instruction sets. This should make porting to new architectures easier. Among the changes: - The chunk header has been changed to accomodate the size limitations encountered on 32-bit architectures. We now fit everything in 64-bit. This was achieved by storing the amount of unused bytes in an allocation rather than the size itself, as one can be deduced from the other with the help of the GetActuallyAllocatedSize function. As it turns out, this header can be used for both 64 and 32 bit, and as such we dropped the requirement for the 128-bit compare and exchange instruction support (cmpxchg16b). - Add 32-bit support for the checksum and the PRNG functions: if the SSE 4.2 instruction set is supported, use the 32-bit CRC32 instruction, and in the XorShift128, use a 32-bit based state instead of 64-bit. - Add software support for CRC32: if SSE 4.2 is not supported, fallback on a software implementation. - Modify tests that were not 32-bit compliant, and expand them to cover more allocation and alignment sizes. The random shuffle test has been deactivated for linux-i386 & linux-i686 as the 32-bit sanitizer allocator doesn't currently randomize chunks. Reviewers: alekseyshl, kcc Subscribers: filcab, llvm-commits, tberghammer, danalbert, srhines, mgorny, modocache Differential Revision: https://reviews.llvm.org/D26358 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@288255 91177308-0d34-0410-b5e6-96231b3b80d8
2016-10-26[scudo] Lay the foundation for 32-bit supportKostya Kortchinsky
Summary: In order to support 32-bit platforms, we have to make some adjustments in multiple locations, one of them being the Scudo chunk header. For it to fit on 64 bits (as a reminder, on x64 it's 128 bits), I had to crunch the space taken by some of the fields. In order to keep the offset field small, the secondary allocator was changed to accomodate aligned allocations for larger alignments, hence making the offset constant for chunks serviced by it. The resulting header candidate has been added, and further modifications to allow 32-bit support will follow. Another notable change is the addition of MaybeStartBackgroudThread() to allow release of the memory to the OS. Reviewers: kcc Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D25688 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@285209 91177308-0d34-0410-b5e6-96231b3b80d8
2016-09-30[scudo] Fix an edge case in the secondary allocatorKostya Kortchinsky
Summary: s/CHECK_LT/CHECK_LE/ in the secondary allocator, as under certain circumstances Ptr + Size can be equal to MapEnd. This edge case was not found by the current tests, so those were extended to be able to catch that. Reviewers: kcc Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D25101 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@282913 91177308-0d34-0410-b5e6-96231b3b80d8
2016-09-20[scudo] Fix a bug in the new Secondary AllocatorKostya Kortchinsky
Summary: GetActuallyAllocatedSize() was not accounting for the last page of the mapping being a guard page, and was returning the wrong number of actually allocated bytes, which in turn would mess up with the realloc logic. Current tests didn't find this as the size exercised was only serviced by the Primary. Correct the issue by subtracting PageSize, and update the realloc test to exercise paths in both the Primary and the Secondary. Reviewers: kcc Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D24787 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@282030 91177308-0d34-0410-b5e6-96231b3b80d8
2016-09-19[scudo] Modify Scudo to use its own Secondary AllocatorKostya Kortchinsky
Summary: The Sanitizer Secondary Allocator was not entirely ideal was Scudo for several reasons: decent amount of unneeded code, redundant checks already performed by the front end, unneeded data structures, difficulty to properly protect the secondary chunks header. Given that the second allocator is pretty straight forward, Scudo will use its own, trimming all the unneeded code off of the Sanitizer one. A significant difference in terms of security is that now each secondary chunk is preceded and followed by a guard page, thus mitigating overflows into and from the chunk. A test was added as well to illustrate the overflow & underflow situations into the guard pages. Reviewers: kcc Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D24737 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@281938 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-26[sanitizer] enable random shuffling the memory chunks inside the allocator, ↵Kostya Serebryany
under a flag. Set this flag for the scudo allocator, add a test. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@279793 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-02[sanitizer] Implement a __asan_default_options() equivalent for ScudoKostya Serebryany
Summary: Currently, the Scudo Hardened Allocator only gets its flags via the SCUDO_OPTIONS environment variable. With this patch, we offer the opportunity for programs to define their own options via __scudo_default_options() which behaves like __asan_default_options() (weak symbol). A relevant test has been added as well, and the documentation updated accordingly. I also used this patch as an opportunity to rename a few variables to comply with the LLVM naming scheme, and replaced a use of Report with dieWithMessage for consistency (and to avoid a callback). Reviewers: llvm-commits, kcc Differential Revision: https://reviews.llvm.org/D23018 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@277536 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-11[compiler-rt] Fix VisualStudio virtual folders layoutEtienne Bergeron
Summary: This patch is a refactoring of the way cmake 'targets' are grouped. It won't affect non-UI cmake-generators. Clang/LLVM are using a structured way to group targets which ease navigation through Visual Studio UI. The Compiler-RT projects differ from the way Clang/LLVM are grouping targets. This patch doesn't contain behavior changes. Reviewers: kubabrecka, rnk Subscribers: wang0109, llvm-commits, kubabrecka, chrisha Differential Revision: http://reviews.llvm.org/D21952 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@275111 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-07[scudo] trying to fix the bot: aligned_alloc is not known there; attempt 3Kostya Serebryany
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@272074 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-07[scudo] trying to fix the bot: aligned_alloc is not known there; attempt 2Kostya Serebryany
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@272051 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-07[scudo] trying to fix the bot: aligned_alloc is not known thereKostya Serebryany
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@272037 91177308-0d34-0410-b5e6-96231b3b80d8
2016-06-07[sanitizer] Initial implementation of a Hardened AllocatorKostya Serebryany
Summary: This is an initial implementation of a Hardened Allocator based on Sanitizer Common's CombinedAllocator. It aims at mitigating heap based vulnerabilities by adding several features to the base allocator, while staying relatively fast. The following were implemented: - additional consistency checks on the allocation function parameters and on the heap chunks; - use of checksum protected chunk header, to detect corruption; - randomness to the allocator base; - delayed freelist (quarantine), to mitigate use after free and overall determinism. Additional mitigations are in the works. Reviewers: eugenis, aizatsky, pcc, krasin, vitalybuka, glider, dvyukov, kcc Subscribers: kubabrecka, filcab, llvm-commits Differential Revision: http://reviews.llvm.org/D20084 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@271968 91177308-0d34-0410-b5e6-96231b3b80d8