Commit Graph

537 Commits

Author SHA1 Message Date
Petr Hosek 12e20a446e [scudo] Do not consider releasing unallocated pages
We already know that there are no free blocks above Region->AllocatedUser.
This results in a smaller RegionPageMap and faster releaseFreeMemoryToOS.

Patch By: fabio-d
Differential Revision: https://reviews.llvm.org/D138794
2022-11-30 02:34:46 +00:00
Evgenii Stepanov 8add770417 Revert "[scudo] Detect double free when running with MTE."
Mysterious failures on the x86_64-linux-qemu, to be debugged.

This reverts commit 1dd54691b2.
2022-11-21 16:57:14 -08:00
Evgenii Stepanov 1dd54691b2 [scudo] Detect double free when running with MTE.
Try to trigger an MTE fault on double/invalid free by touching the first
byte of the allocation with the provided pointer.

Differential Revision: https://reviews.llvm.org/D137352
2022-11-18 13:18:00 -08:00
Evgenii Stepanov 48dbf35302 [scudo] Extend basic test to cover zero size allocs.
Differential Revision: https://reviews.llvm.org/D137354
2022-11-17 11:22:25 -08:00
Chia-hung Duan 9dc5b322d5 Revert "Revert "[scudo] Fix the calculating of memory group usage""
This reverts commit 69fe7abb39.

Fixed the arguments order while calling batchGroupBase()

Differential Revision: https://reviews.llvm.org/D136995
2022-10-29 06:26:50 +00:00
Chia-hung Duan 69fe7abb39 Revert "[scudo] Fix the calculating of memory group usage"
This reverts commit 6130d67f70.
2022-10-28 22:15:50 +00:00
Chia-hung Duan 6130d67f70 [scudo] Fix the calculating of memory group usage
In SizeClassAllocator64, the boundary of a memory group may not align to
the region begin. Which means the begin addr of a memory group may
smaller than region begin. This leads to wrong judgement of memory group
usage.

Differential Revision: https://reviews.llvm.org/D136898
2022-10-28 20:29:17 +00:00
Chia-hung Duan a1e325ce7c [scudo] Lazy initialize the PageMap while page releasing
We allocate the page map before knowing if there're groups can be
released. This may result in many redundant map()/unmap() operations if
there's no page to release.

Make the page map be lazy initialized.

Differential Revision: https://reviews.llvm.org/D136873
2022-10-28 20:29:17 +00:00
Chia-hung Duan 4383aa0336 [scudo] Fix size of MaxNumCachedHint Trusty Config
Also add a test for TrustyConfig to ensure it'll be awared of any scudo
configuration change.

Differential Revision: https://reviews.llvm.org/D136732
2022-10-26 18:07:22 +00:00
Chia-hung Duan b525392a17 Revert "Revert "[scudo] Support partial page releasing""
This reverts commit 1cf1b36112.

Reviewed By: cferris

Differential Revision: https://reviews.llvm.org/D136027
2022-10-21 22:29:34 +00:00
Chia-hung Duan c0f91856a3 Reland "[scudo] Manage free blocks in BatchGroup."
This is not a pure revert of c929bcb7d8.
It also includes a bug fix.

Differential Revision: https://reviews.llvm.org/D136029
2022-10-21 19:57:28 +00:00
Chia-hung Duan 5de73d27bd [scudo] Change region size from 1 MB to 2 MB in tests
In SizeClassAllocator64, the RegionBeg is determined by RegionBase +
random offset. The offset is n pages, where n is a random number less or
equal to 16. However, on certain platforms which have large page size,
it may end up immediately OOM without mapping any block pages. For
example,

PageSize = 64 KB, RegionSize = 1 MB

Suppose the random number n is 16, then the random offset will be
64 * 16 = 1024 KB which is equal to the RegionSize.

On most platforms we don't have such large page size and we have
different PRNG(pseudo random number generator) behaviors, thus we didn't
hit any failures before. Given that this now only affects the tests,
only increase the region size is enough.

Will revisit the logic of calculating the random offset.

Differential Revision: https://reviews.llvm.org/D136025
2022-10-17 20:22:33 +00:00
Chia-hung Duan 3ead26e65b [scudo] Fix implicitly narrow casting (NFC)
u16 may be promoted to int by arithmetic type conversion. Do an explicit
cast to avoid certain compiler's warning. This fixes the problem
introduced by 0fb2aeef53

Differential Revision: https://reviews.llvm.org/D135985
2022-10-15 03:54:53 +00:00
Kamau Bridgeman c929bcb7d8 Revert "[scudo] Manage free blocks in BatchGroup."
This reverts commit cf9d7f55d3.
2022-10-14 15:11:57 -05:00
Kamau Bridgeman 1cf1b36112 Revert "[scudo] Support partial page releasing"
This reverts commit 9c26f51f5e.
2022-10-14 15:11:44 -05:00
Kamau Bridgeman 5fe6f3e0bc Revert "[scudo] Fix implicitly narrow casting (NFC)"
This reverts commit fd7c7ad4fe.
2022-10-14 15:11:34 -05:00
Chia-hung Duan fd7c7ad4fe [scudo] Fix implicitly narrow casting (NFC)
u16 may be promoted to int by arithmetic type conversion. Do an explicit
cast to avoid certain compiler's warning.

Differential Revision: https://reviews.llvm.org/D135945
2022-10-14 18:59:08 +00:00
Chia-hung Duan 9c26f51f5e [scudo] Support partial page releasing
Block grouping enables us doing partial page releasing so that we can
release the pages in a finer granularity. Which means we don't need to
visit all blocks to determine which pages are unused. Besides, this
means we can do incremental page releasing depends on the number fo free
blocks.

Reviewed By: cryptoad, cferris

Differential Revision: https://reviews.llvm.org/D134226
2022-10-13 23:35:07 +00:00
Chia-hung Duan cf9d7f55d3 [scudo] Manage free blocks in BatchGroup.
Scudo is supposed to allocate any blocks across the entired mapped
pages and each page is equally likely to be selected. Which means Scudo
is leaning to touch as many pages as possible. This brings better
security but it also sacrifices the chance of releasing dirty pages.

To alleviate the unmanagable footprint growing, this CL introduces the
BatchGroup concept. Each blocks will be classified into a BatchGroup
according to its address. While allocation, we are leaning to allocate
blocks in the same group first. Note that the blocks selected from a
group is still random over several pages. At the same time, we have
better prediction of dirty page growing speed. Besides, we are able to
do partial page releasing by examing part of BatchGroups.

Reviewed By: cryptoad, cferris

Differential Revision: https://reviews.llvm.org/D133897
2022-10-13 23:35:06 +00:00
Chia-hung Duan 56dafd024c [scudo] Add PageReleaseContext to convey page usage status.
PageReleaseContext contains all the information needed for determing if
a page can be released. Splitting out the context increases the flexibility
of heterogenous free lists in the future. Also rename PackedCounterArray to
PageMap.

Reviewed By: cryptoad, cferris

Differential Revision: https://reviews.llvm.org/D133895
2022-10-13 23:35:06 +00:00
Chia-hung Duan 0fb2aeef53 Use u16 to store Count/MaxCount
The Count/MaxCount used in TransferBatch and PerClass can be fit in u16 in
current configurations and it's also reasonable to have a u16 limit. The
spare 16 bits will be used for additional status like pages mapping
status in a TransferBatch.

Reviewed By: cryptoad, cferris, vitalybuka

Differential Revision: https://reviews.llvm.org/D133145
2022-10-13 23:35:06 +00:00
Michael Jones b9663ebbf8 [SCUDO] add cmake options for custom sysroot
These options will allow the SCUDO standalone to be built with custom
headers. Specifically, this patch will enable building with the
LLVM-libc headers.

Reviewed By: abrachet

Differential Revision: https://reviews.llvm.org/D135702
2022-10-12 15:03:04 -07:00
Petr Hosek 826693e2b0 [CMake] Use libcxx-abi-* targets for in-tree sanitizer C++ ABI
When in-tree libcxx is selected as the sanitizer C++ ABI, use
libcxx-abi-* targets rather than libcxxabi and libunwind directly.

Differential Revision: https://reviews.llvm.org/D134855
2022-10-09 03:35:59 +00:00
Hans Wennborg 20a269cf77 Revert "[CMake] Use libcxx-abi-* targets for in-tree sanitizer C++ ABI"
It casued some runtimes builds to fail with cmake error

  No target "libcxx-abi-static"

see code review.

> When in-tree libcxx is selected as the sanitizer C++ ABI, use
> libcxx-abi-* targets rather than libcxxabi and libunwind directly.
>
> Differential Revision: https://reviews.llvm.org/D134855

This reverts commit 414f9b7d2f.
2022-10-03 14:56:07 +02:00
Petr Hosek 414f9b7d2f [CMake] Use libcxx-abi-* targets for in-tree sanitizer C++ ABI
When in-tree libcxx is selected as the sanitizer C++ ABI, use
libcxx-abi-* targets rather than libcxxabi and libunwind directly.

Differential Revision: https://reviews.llvm.org/D134855
2022-09-30 20:32:10 +00:00
Alex Brachet 2449f42427 [scudo][Fuchsia] Increase MaxNumCachedHint
This brings the value closer to other platforms and allows
for future improvements, see D133897.
2022-09-29 20:57:10 +00:00
Diana Picus 8342ea6eac [scudo] Try to fix standalone build on armv7
When linking scudo standalone on armv7, it can't find symbols related to
unwinding (e.g. __aeabi_unwind_cpp_pr0). This is because it is passing
--unwindlib=none. This patch hacks around the issue by adding
COMPILER_RT_UNWINDER_LINK_LIBS to the link line.

I don't know anything about scudo, so I'm not sure what the original
intention was.

See also https://github.com/llvm/llvm-project/issues/56900

Differential Revision: https://reviews.llvm.org/D131250
2022-08-08 10:19:12 +02:00
Petr Hosek 6699f55488 [compiler-rt][CMake] Set --unwindlib=none when using LLVM libunwind
We already link libunwind explicitly so avoid trying to link toolchain's
default libunwind which may be missing. This matches what we already do
for libcxx and libcxxabi.

Differential Revision: https://reviews.llvm.org/D129472
2022-07-15 07:25:38 +00:00
Alex Brachet 1039165b96 [scudo][NFC] Clang-format c823cbf699
Ran `git clang-format` but didn't add the changed file...
2022-07-11 17:41:37 +00:00
Alex Brachet c823cbf699 [scudo][Fuchsia] Don't assume MapPlatformData::Vmar is valid
After https://reviews.llvm.org/D129237, the assumption
that any non-null data contains a valid vmar handle is no
longer true. Generally this code here needs cleanup, but
in the meantime this fixes errors on Fuchsia.

Differential Revision: https://reviews.llvm.org/D129331
2022-07-11 17:39:44 +00:00
Dominic Chen ec9907fbf6 [scudo] Satisfy -Wstrict-prototypes
Differential Revision: https://reviews.llvm.org/D129391
2022-07-11 10:28:38 -07:00
Petr Hosek ba007f20bb [CMake] Use explicit header path when using in-tree libc++ for tests
This is a follow up to D118200 which applies a similar cleanup to
headers when using in-tree libc++ to avoid accidentally picking up
the system headers.

Differential Revision: https://reviews.llvm.org/D128035
2022-07-09 06:14:29 +00:00
Petr Hosek 99cc28b705 Revert "[CMake] Use explicit header path when using in-tree libc++ for tests"
This reverts commit 61b410cb8b as this
appears to have broken some sanitizer tests.
2022-07-09 04:27:16 +00:00
Petr Hosek 61b410cb8b [CMake] Use explicit header path when using in-tree libc++ for tests
This is a follow up to D118200 which applies a similar cleanup to
headers when using in-tree libc++ to avoid accidentally picking up
the system headers.

Differential Revision: https://reviews.llvm.org/D128035
2022-07-09 03:18:46 +00:00
Dominic Chen 5f3818c7df [scudo] Add [[no_unique_address]] attribute to new MapPlatformData variables
Differential Revision: https://reviews.llvm.org/D129237
2022-07-07 13:12:55 -07:00
Dominic Chen ff8c0e6eb5 [scudo] Pass MapPlatformData in more calls
Allow platforms to avoid looking up private data by providing private context

Differential Revision: https://reviews.llvm.org/D129237
2022-07-07 10:43:07 -07:00
Petr Hosek 18a1fc8459 [CMake][compiler-rt] Provide a dedicated option for LLVM unwinder
This allows configuring LLVM unwinder separately from the C++ library
matching how we configure it in libcxx.

This also applies changes made to libunwind+libcxxabi+libcxx in D113253
to compiler-rt.

Differential Revision: https://reviews.llvm.org/D115674
2022-06-14 17:26:25 +00:00
Alex Brachet 7df55e5ed7 [scudo] Ensure pointer is not null
Differential revision: https://reviews.llvm.org/D126499
2022-05-31 17:16:49 +00:00
Roland McGrath a27b9139ab [scudo] Clean up Zircon header file uses
Make fuchsia.h and fuchsia.cpp each include what they use.
2022-05-27 21:39:03 -07:00
John Paul Adrian Glaubitz a1ec3c5a88 [scudo] Link against libatomic on all MIPS targets
Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D126418
2022-05-26 00:00:16 -07:00
Leonard Chan 6edbdf80ca Revert "[compiler-rt][scudo] Add missing preprocessor token" and "[compiler-rt][scudo] Simplify TBI checks"
This reverts commit 676eaa2ca9
and f6038cdca0 since builders are still
broken.
2022-05-24 11:30:31 -07:00
Leonard Chan 676eaa2ca9 [compiler-rt][scudo] Add missing preprocessor token
This should fix build errors seen on bots like
https://lab.llvm.org/buildbot/#/builders/57/builds/18263.
2022-05-24 11:12:30 -07:00
Leonard Chan f6038cdca0 [compiler-rt][scudo] Simplify TBI checks
Differential Revision: https://reviews.llvm.org/D111080
2022-05-24 10:53:09 -07:00
Mitch Phillips e831ea6912 [NFCI] clang-format scudo standalone 2022-05-18 14:04:04 -07:00
Dominic Chen fcbca197f2 [scudo] Disable memory tagging on arm64_32
arm64_32 is an ILP32 platform

Differential Revision: https://reviews.llvm.org/D124135
2022-04-21 17:22:10 -07:00
Fangrui Song bbb72122aa [scudo][test] Link with -no-pie to be agnostic of CLANG_DEFAULT_PIE_ON_LINUX
This keeps the test behavior unchanged when CLANG_DEFAULT_PIE_ON_LINUX switches
to ON by default.

Note: current clang --target=mips64el-linux-gnu -fpie -pie -fuse-ld=lld
does not link with C++ exceptions, using -pie would lead to

```
ld.lld: error: cannot preempt symbol: DW.ref.__gxx_personality_v0
...
ld.lld: error: relocation R_MIPS_64 cannot be used against local symbol; recompile with -fPIC
...
```

when linking `ScudoUnitTests`: https://lab.llvm.org/buildbot/#/builders/169/builds/7311/steps/18/logs/stdio
2022-04-08 23:30:07 -07:00
Alex Brachet 016e59bf2c Revert "[Scudo] enabling anonymous named pages on Linux 5.17 and onwards."
This reverts commit 6194992523.
2022-04-05 16:38:49 +00:00
David Carlier 6194992523 [Scudo] enabling anonymous named pages on Linux 5.17 and onwards.
Reviewers: vitalybuka

Reviewed-By: vitalybuka

Differential Revision: https://reviews.llvm.org/D122962
2022-04-05 09:46:02 +01:00
Michał Górny fd1da784ac [compiler-rt] [scudo] Use -mcrc32 on x86 when available
Update the hardware CRC32 logic in scudo to support using `-mcrc32`
instead of `-msse4.2`.  The CRC32 intrinsics use the former flag
in the newer compiler versions, e.g. in clang since 12fa608af4.
With these versions of clang, passing `-msse4.2` is insufficient
to enable the instructions and causes build failures when `-march` does
not enable CRC32 implicitly:

    /var/tmp/portage/sys-libs/compiler-rt-sanitizers-14.0.0/work/compiler-rt/lib/scudo/scudo_crc32.cpp:20:10: error: always_inline function '_mm_crc32_u32' requires target feature 'crc32', but would be inlined into function 'computeHardwareCRC32' that is compiled without support for 'crc32'
      return CRC32_INTRINSIC(Crc, Data);
             ^
    /var/tmp/portage/sys-libs/compiler-rt-sanitizers-14.0.0/work/compiler-rt/lib/scudo/scudo_crc32.h:27:27: note: expanded from macro 'CRC32_INTRINSIC'
    #  define CRC32_INTRINSIC FIRST_32_SECOND_64(_mm_crc32_u32, _mm_crc32_u64)
                              ^
    /var/tmp/portage/sys-libs/compiler-rt-sanitizers-14.0.0/work/compiler-rt/lib/scudo/../sanitizer_common/sanitizer_platform.h:132:36: note: expanded from macro 'FIRST_32_SECOND_64'
    #  define FIRST_32_SECOND_64(a, b) (a)
                                       ^
    1 error generated.

For backwards compatibility, use `-mcrc32` when available and fall back
to `-msse4.2`.  The `<smmintrin.h>` header remains in use as it still
works and is compatible with GCC, while clang's `<crc32intrin.h>`
is not.

Use __builtin_ia32*() rather than _mm_crc32*() when using `-mcrc32`
to preserve compatibility with GCC.  _mm_crc32*() are aliases
to __builtin_ia32*() in both compilers but GCC requires `-msse4.2`
for the former, while both use `-mcrc32` for the latter.

Originally reported in https://bugs.gentoo.org/835870.

Differential Revision: https://reviews.llvm.org/D122789
2022-04-01 13:00:21 +02:00
Nikita Popov 985c717cdb Revert "[compiler-rt] [scudo] Use -mcrc32 on x86 when available"
This reverts commit 09b53121c3.

Breaks the build with GCC 11.2 on x86_64:

In file included from /home/npopov/repos/llvm-project/compiler-rt/lib/scudo/scudo_crc32.h:27,
                 from /home/npopov/repos/llvm-project/compiler-rt/lib/scudo/scudo_crc32.cpp:14:
/usr/lib/gcc/x86_64-redhat-linux/11/include/smmintrin.h: In function ‘__sanitizer::u32 __scudo::computeHardwareCRC32(__sanitizer::u32, __sanitizer::uptr)’:
/usr/lib/gcc/x86_64-redhat-linux/11/include/smmintrin.h:846:1: error: inlining failed in call to ‘always_inline’ ‘long long unsigned int _mm_crc32_u64(long long unsigned int, long long unsigned int)’: target specific option mismatch
  846 | _mm_crc32_u64 (unsigned long long __C, unsigned long long __V)
2022-04-01 09:40:48 +02:00