Commit Graph

438 Commits

Author SHA1 Message Date
Vitaly Buka 14362bf1b2 [scudo] Don't enabled MTE for small alignment
Differential Revision: https://reviews.llvm.org/D105954
2021-07-14 12:04:16 -07:00
Vitaly Buka c41e67f3f1 [NFC][scudo] Clang format a file 2021-07-12 22:26:54 -07:00
Benjamin Kramer 6f6131815e sanitizer_common: Suppress another thread safety warning
Another follow-up to 0da172b176

compiler-rt/lib/scudo/scudo_tsd_shared.cpp:103:1: error: mutex 'CandidateTSD->Mutex' is not held on every path through here [-Werror,-Wthread-safety-analysis]
}
^
compiler-rt/lib/scudo/scudo_tsd_shared.cpp:95:21: note: mutex acquired here
      CandidateTSD->lock();
                    ^
compiler-rt/lib/scudo/scudo_tsd_shared.cpp:103:1: error: mutex 'TSD->Mutex' is not held on every path through here [-Werror,-Wthread-safety-analysis]
}
^
compiler-rt/lib/scudo/scudo_tsd_shared.cpp:101:8: note: mutex acquired here
  TSD->lock();
       ^
compiler-rt/lib/scudo/scudo_tsd_shared.cpp:103:1: error: mutex 'TSDs[Index].Mutex' is not held on every path through here [-Werror,-Wthread-safety-analysis]
}
^
compiler-rt/lib/scudo/scudo_tsd_shared.cpp:80:23: note: mutex acquired here
      if (TSDs[Index].tryLock()) {
                      ^
2021-07-12 17:57:42 +02:00
Benjamin Kramer 561b9446d6 sanitizer_common: Fix the build for platforms that use shared TSDs
Looks like an oversight in 0da172b176

compiler-rt/lib/scudo/scudo_tsd_shared.inc:53:1: error: mutex 'TSD->Mutex' is not held on every path through here [-Werror,-Wthread-safety-analysis]
}
^
compiler-rt/lib/scudo/scudo_tsd_shared.inc:49:12: note: mutex acquired here
  if (TSD->tryLock())
           ^
2021-07-12 17:49:48 +02:00
Dmitry Vyukov 0da172b176 sanitizer_common: add thread safety annotations
Enable clang Thread Safety Analysis for sanitizers:
https://clang.llvm.org/docs/ThreadSafetyAnalysis.html

Thread Safety Analysis can detect inconsistent locking,
deadlocks and data races. Without GUARDED_BY annotations
it has limited value. But this does all the heavy lifting
to enable analysis and allows to add GUARDED_BY incrementally.

Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D105716
2021-07-12 11:46:49 +02:00
Vitaly Buka db4c25822a [scudo] Check if we use __clang_major__ >= 12
This makes sure we have support for MTE instructions.
Later the check can be extended to support MTE on other compilers.

Reviewed By: pcc

Differential Revision: https://reviews.llvm.org/D105722
2021-07-09 17:48:44 -07:00
Mitch Phillips dd1c4bd09d Name all DEATH tests using 'DeathTest' suffix.
gtest highly recommends this prefix, and runs death tests first
(https://github.com/google/googletest/blob/master/docs/advanced.md#death-test-naming).
This may help with some spurious bot failures like
https://lab.llvm.org/buildbot/#/builders/169/builds/1290/steps/25/logs/stdio.

Reviewed By: cryptoad, vitalybuka

Differential Revision: https://reviews.llvm.org/D105371
2021-07-02 13:51:16 -07:00
Vitaly Buka 07a1f3513e [scudo] Fix test on aarch64 without MTE 2021-07-01 21:40:04 -07:00
Vitaly Buka fe30963600 [scudo] Untag BlockEnd in reallocate
If we get here from reallocate, BlockEnd is tagged. Then we
will storeTag(UntaggedEnd) into the header of the next chunk.

Luckily header tag is 0 so unpatched code still works.

Reviewed By: pcc

Differential Revision: https://reviews.llvm.org/D105261
2021-07-01 13:02:58 -07:00
Vitaly Buka 78e70cee0d [scudo] Remove false DCHECK
MTE Cache.store passes MAP_NOACCESS here.

Reviewed By: pcc, cryptoad

Differential Revision: https://reviews.llvm.org/D105266
2021-07-01 12:06:33 -07:00
Vitaly Buka 33b579c8a5 [NFC][scudo] Exctract getOptionsForConfig in test 2021-07-01 11:59:30 -07:00
Vitaly Buka 39a15b5ae0 [NFC][scudo] Extract MapAllocatorTest for TEST_F 2021-07-01 10:22:55 -07:00
Vitaly Buka b1fd009aab [scudo] GWP_ASAN runs on untagged pointers
It's already covered by multiple tests, but to trigger
this path we need MTE+GWP which disabled.

Reviewed By: hctim, pcc

Differential Revision: https://reviews.llvm.org/D105232
2021-06-30 20:41:30 -07:00
Vitaly Buka a435741110 [scudo] Clang-format tests 2021-06-24 17:33:24 -07:00
Vitaly Buka 35e1dbd189 [scudo] Fix test on arch without MTE 2021-06-24 00:07:24 -07:00
Vitaly Buka 6fd963ab64 [scudo] Avoid ifdef in test 2021-06-23 23:58:09 -07:00
Vitaly Buka 99ec78c0fe [scudo] Fix use of ScopedDisableMemoryTagChecks in test 2021-06-23 23:57:17 -07:00
Vitaly Buka 533abb7ecf [scudo] Enabled MTE before the first allocator
Reviewed By: pcc

Differential Revision: https://reviews.llvm.org/D103726
2021-06-23 23:01:26 -07:00
Evgenii Stepanov d693957e58 [scudo] Handle predefined M_MEMTAG_TUNING_* constants (NFC).
Bionic <malloc.h> may provide the definitions of M_MEMTAG_TUNING_* constants.
Do not redefine them in that case.

Differential Revision: https://reviews.llvm.org/D104758
2021-06-22 17:39:55 -07:00
Kostya Kortchinsky 8b062b6160 [scudo] Ensure proper allocator alignment in TSD test
The `MockAllocator` used in `ScudoTSDTest` wasn't allocated
properly aligned, which resulted in the `TSDs` of the shared
registry not being aligned either. This lead to some failures
like: https://reviews.llvm.org/D103119#2822008

This changes how the `MockAllocator` is allocated, same as
Vitaly did in the combined tests, properly aligning it, which
results in the `TSDs` being aligned as well.

Add a `DCHECK` in the shared registry to check that it is.

Differential Revision: https://reviews.llvm.org/D104402
2021-06-16 14:21:58 -07:00
Daniel Michael 2551053e8d [scudo] Add Scudo support for Trusty OS
trusty.cpp and trusty.h define Trusty implementations of map and other
platform-specific functions. In addition to adding Trusty configurations
in allocator_config.h and size_class_map.h, MapSizeIncrement and
PrimaryEnableRandomOffset are added as configurable options in
allocator_config.h.
Background on Trusty: https://source.android.com/security/trusty

Differential Revision: https://reviews.llvm.org/D103578
2021-06-08 14:02:10 -07:00
Vitaly Buka b41b76b303 [NFC][scudo] Print errno of fork failure
This fork fails sometime on sanitizer-x86_64-linux-qemu bot.
2021-06-07 18:59:35 -07:00
Vitaly Buka 9ff982dbbd [NFC][scudo] Fix sign-compare warning in test 2021-06-04 19:33:42 -07:00
Vitaly Buka 57ba226296 [NFC][scudo] Convert to TYPED more ScudoCombinedTest 2021-06-04 19:26:03 -07:00
Vitaly Buka 70b29213eb [scudo] Remove ScopedString::Length
Differential Revision: https://reviews.llvm.org/D103725
2021-06-04 18:28:51 -07:00
Vitaly Buka df87aeb826 [Scudo] Improve ScopedString constructor
Avoid referencing elements beyond internal vector size.

Reviewed By: cryptoad

Differential Revision: https://reviews.llvm.org/D103718
2021-06-04 18:28:29 -07:00
Vitaly Buka b850798f11 [NFC][scudo] Fix sign-compare warning in test 2021-06-04 18:24:00 -07:00
Kostya Kortchinsky 5019b0a565 [scudo] Fix String DCHECK
This resolves an issue tripping a `DCHECK`, as I was checking for the
capacity and not the size. We don't need to 0-init the Vector as it's
done already, and make sure we only 0-out the string on clear if it's
not empty.

Differential Revision: https://reviews.llvm.org/D103716
2021-06-04 13:41:59 -07:00
Vitaly Buka 1e6d135325 [scudo] Untag pointer in iterateOverChunks
Pointer comparison in Lambda will not work on tagged pointers.

Reviewed By: pcc

Differential Revision: https://reviews.llvm.org/D103496
2021-06-04 12:45:07 -07:00
Vitaly Buka 07c92b2e95 [scudo] Add memtag_test
Differential Revision: https://reviews.llvm.org/D103074
2021-06-04 12:38:29 -07:00
Vitaly Buka 39f928ed01 [scudo] Remove disableMemoryTagChecksTestOnly
And replace with ScopedDisableMemoryTagChecks.

Differential Revision: https://reviews.llvm.org/D103708
2021-06-04 12:38:29 -07:00
Vitaly Buka ba04c7c128 [scudo] Always exclude Tag 0
prepareTaggedChunk uses Tag 0 for header.

Android already PR_MTE_TAG_MASK to 0xfffe,
but with the patch we will not need to deppend
on the system configuration.

Reviewed By: pcc

Differential Revision: https://reviews.llvm.org/D103134
2021-06-04 10:20:32 -07:00
Kostya Kortchinsky 868317b3fd [scudo] Rework Vector/String
Some platforms (eg: Trusty) are extremelly memory constrained, which
doesn't necessarily work well with some of Scudo's current assumptions.

`Vector` by default (and as such `String` and `ScopedString`) maps a
page, which is a bit of a waste. This CL changes `Vector` to use a
buffer local to the class first, then potentially map more memory if
needed (`ScopedString` currently are all stack based so it would be
stack data). We also want to allow a platform to prevent any dynamic
resizing, so I added a `CanGrow` templated parameter that for now is
always `true` but would be set to `false` on Trusty.

Differential Revision: https://reviews.llvm.org/D103641
2021-06-03 18:12:24 -07:00
Vitaly Buka b40908e639 [NFC][scudo] Avoid integer overflow in test
releasePagesToOS may shrink RSS below the value stored on start.
2021-06-03 00:08:41 -07:00
Vitaly Buka 4124bca309 [scudo] Enabled MTE in tests
Reviewed By: pcc, hctim

Differential Revision: https://reviews.llvm.org/D103305
2021-06-01 19:56:57 -07:00
Vitaly Buka bd04d78d64 [cmake][scudo] Add missing headers 2021-05-28 02:06:14 -07:00
Vitaly Buka a6e5a4b464 [NFC][scudo] Re-enable check in the test
It should pass with patched QEMU.
2021-05-28 01:57:55 -07:00
Vitaly Buka 4458e8c4b4 Revert "[scudo] Check if MADV_DONTNEED zeroes memory"
This reverts commit d423509b80.

We are going to use patched QEMU.
2021-05-28 01:53:42 -07:00
Vitaly Buka c261edb277 [NFC][scudo] Check zeros on smaller allocations
1Tb counting was the slowest test under the QEMU with MTE.
2021-05-27 11:14:26 -07:00
Vitaly Buka eb69763ad8 [NFC][scudo] Rename internal function 2021-05-27 10:41:07 -07:00
Mitch Phillips f7c5c0d87b Revert "[Scudo] Make -fsanitize=scudo use standalone. Migrate tests."
This reverts commit 6911114d8c.

Broke the QEMU sanitizer bots due to a missing header dependency. This
actually needs to be fixed on the bot-side, but for now reverting this
patch until I can fix up the bot.
2021-05-26 10:50:26 -07:00
Mitch Phillips 6911114d8c [Scudo] Make -fsanitize=scudo use standalone. Migrate tests.
This patch moves -fsanitize=scudo to link the standalone scudo library,
rather than the original compiler-rt based library. This is one of the
major remaining roadblocks to deleting the compiler-rt based scudo,
which should not be used any more. The standalone Scudo is better in
pretty much every way and is much more suitable for production usage.

As well as patching the litmus tests for checking that the
scudo_standalone lib is linked instead of the scudo lib, this patch also
ports all the scudo lit tests to run under scudo standalone.

This patch also adds a feature to scudo standalone that was under test
in the original scudo - that arguments passed to an aligned operator new
were checked that the alignment was a power of two.

Some lit tests could not be migrated, due to the following issues:
 1. Features that aren't supported in scudo standalone, like the rss
 limit.
 2. Different quarantine implementation where the test needs some more
 thought.
 3. Small bugs in scudo standalone that should probably be fixed, like
 the Secondary allocator having a full page on the LHS of an allocation
 that only contains the chunk header, so underflows by <= a page aren't
 caught.
 4. Slight differences in behaviour that's technically correct, like
 'realloc(malloc(1), 0)' returns nullptr in standalone, but a real
 pointer in old scudo.
 5. Some tests that might be migratable, but not easily.

Tests that are obviously not applicable to scudo standalone (like
testing that no sanitizer symbols made it into the DSO) have been
deleted.

After this patch, the remaining work is:
 1. Update the Scudo documentation. The flags have changed, etc.
 2. Delete the old version of scudo.
 3. Patch up the tests in lit-unmigrated, or fix Scudo standalone.

Reviewed By: cryptoad, vitalybuka

Differential Revision: https://reviews.llvm.org/D102543
2021-05-26 10:03:17 -07:00
Kostya Kortchinsky a45877eea8 [scudo] Get rid of initLinkerInitialized
Now that everything is forcibly linker initialized, it feels like a
good time to get rid of the `init`/`initLinkerInitialized` split.

This allows to get rid of various `memset` construct in `init` that
gcc complains about (this fixes a Fuchsia open issue).

I added various `DCHECK`s to ensure that we would get a zero-inited
object when entering `init`, which required ensuring that
`unmapTestOnly` leaves the object in a good state (tests are currently
the only location where an allocator can be "de-initialized").

Running the tests with `--gtest_repeat=` showed no issue.

Differential Revision: https://reviews.llvm.org/D103119
2021-05-26 09:53:40 -07:00
Vitaly Buka e14696bfd7 [NFC][SCUDO] Fix unittest for -gtest_repeat=10
Reviewed By: cryptoad

Differential Revision: https://reviews.llvm.org/D103122
2021-05-25 15:32:42 -07:00
Vitaly Buka d1e5f046cc Revert "[NFC][scudo] Let disableMemoryTagChecksTestOnly to fail"
This reverts commit 2c212db4ea.

It's not needed.
2021-05-25 11:53:42 -07:00
Vitaly Buka 8e30b55c82 [scudo] Fix CHECK implementation
Cast of signed types to u64 breaks comparison.
Also remove double () around operands.

Reviewed By: cryptoad, hctim

Differential Revision: https://reviews.llvm.org/D103060
2021-05-25 10:55:52 -07:00
Vitaly Buka 6a84d374d7 [scudo] Consistent setting of SCUDO_DEBUG
Make sure that if SCUDO_DEBUG=1 in tests
then we had the same in the scudo
library itself.

Reviewed By: cryptoad, hctim

Differential Revision: https://reviews.llvm.org/D103061
2021-05-25 10:49:01 -07:00
Kostya Kortchinsky 1872283457 [scudo] Rework dieOnMapUnmapError
Said function had a few shortfalls:
- didn't set an abort message on Android
- was logged on several lines
- didn't provide extra information like the size requested if OOM'ing

This improves the function to address those points.

Differential Revision: https://reviews.llvm.org/D103034
2021-05-25 08:27:37 -07:00
Vitaly Buka a0169b2ed1 [NFC][scudo] Add paramenters DCHECKs
Reviewed By: hctim

Differential Revision: https://reviews.llvm.org/D103042
2021-05-24 18:06:21 -07:00
Vitaly Buka f5bde3d476 [NFC][scudo] Avoid cast in test 2021-05-24 17:14:38 -07:00