17077 Commits

Author SHA1 Message Date
David Carlier
f5a8802fa6 sanitizers: enable pthread_getaffinity_np interception on freebsd.
Reviewers: mevler

Reviewed-By: mevler

Differential Revision: https://reviews.llvm.org/D152735
2023-06-12 19:25:43 +01:00
Vitaly Buka
e7e6088ee5 [test][HWASAN] Trim leading zeros from hex value
Match like [[#T2]] does not include leading zeroes.
2023-06-12 10:59:28 -07:00
Justin Cady
10e1d50809 [test][ASAN] Fix incorrect REQUIRES directive for scandir.c
The missing colon caused the test to run on unintended platforms.

Reviewed By: emaste

Differential Revision: https://reviews.llvm.org/D152711
2023-06-12 11:16:31 -04:00
David Carlier
203078bc14 sanitizers: intercept FreeBSD's cpuset_getaffinity call.
Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D152609
2023-06-12 09:05:31 +01:00
Vitaly Buka
c097c2548e [HWASAN] Fix verbose_threads
Looks like D104248 acidentally moved the code.
2023-06-09 20:56:23 -07:00
Vitaly Buka
5914ae340c [test][HWASAN] Add verbose_threads test 2023-06-09 20:33:39 -07:00
Marco Elver
cf6d7d5f6d Fix "[compiler-rt] Allow 3 simultaneous interceptors on Linux"
Build bots have been failing with:

	/usr/bin/ld: read-only segment has dynamic relocations

Remove support for interceptor trampoline on s390, and revert new
implementation of __tls_get_offset.
2023-06-09 14:34:01 +02:00
Marco Elver
406131b4c2 Fix "[compiler-rt] Introduce asm macros for interceptor trampolines"
Add missing ASM_INTERCEPTOR_TRAMPOLINE(setjmp).
2023-06-09 13:08:13 +02:00
Marco Elver
85d3873a45 Fix "[compiler-rt] Allow 3 simultaneous interceptors on Linux"
Fix inline asm trampoline type. Some architectures will complain:

<inline asm>:8:41: error: expected STT_<TYPE_IN_UPPER_CASE>, '#<type>', '%<type>' or "<type>"
    8 | .type  __interceptor_trampoline_malloc, @function

Just use %function instead, which is what is also used in
sanitizer_asm.h
2023-06-09 12:14:45 +02:00
Marco Elver
37445e96d8 [compiler-rt] Allow 3 simultaneous interceptors on Linux
Rework Linux (and *BSD) interceptors to allow for up to 3 (2 for *BSD)
simultaneous interceptors. See code comments for details.

The main motivation is to support new sampling sanitizers (in the spirit
of GWP-ASan), that have to intercept few functions. Unfortunately, the
reality is that there are user interceptors that exist in the wild.

To support foreign user interceptors, foreign dynamic analysis
interceptors, and compiler-rt interceptors all at the same time,
including any combination of them, this change enables up to 3
interceptors on Linux (2 on *BSD).

v2:
* Revert to to the simpler "weak wrapper -(alias)-> __interceptor"
  scheme on architectures that cannot implement a trampoline efficiently
  due to complexities of resolving a preemptible symbol (PowerPC64
  ELFv2 global entry, and i386 PIC).
* Avoid duplicate intercepted functions in gen_dynamic_list.py, due to
  matching __interceptor_X and ___interceptor_X.
* Fix s390 __tls_get_offset.

Reviewed By: dvyukov, MaskRay, vitalybuka

Differential Revision: https://reviews.llvm.org/D151085
2023-06-09 11:30:41 +02:00
Marco Elver
4d927fc035 [compiler-rt] Reformat interception macros
Reformat interception macros to be more readable.

NFC.
2023-06-09 10:43:37 +02:00
Ellis Hoag
6ebf7cd7ed [InstrProf][compiler-rt] Fix counter section alignment issue
I recently discovered that `.profraw` headers are expected to be 8 byte
aligned.
643ba926c1/llvm/lib/ProfileData/InstrProfReader.cpp (L503-L506)

When function entry coverage mode is used, function counters are single
bytes, so it is likely that the size of the counters section is not 8
byte aligned. We can add padding after the counters section to guarantee
this.

Reviewed By: kyulee, gulfem

Differential Revision: https://reviews.llvm.org/D152479
2023-06-08 17:26:18 -07:00
usama hameed
16946466fd
Revert "[Sanitizers][Darwin] In DlAddrSymbolizer, return only the module file name instead of the comlpete module path during symbolication."
The commit broke asan_symbolize.py script on Darwin which depended on
using the complete module path to symolize crash traces offline.

This reverts commit f6ea869f7c043c70722b8db6be94d9ad4cc9eb92.

rdar://110487521
2023-06-08 16:02:54 -07:00
Marco Elver
84a64df3a0 [memprof] Fix rawprofile test on 32-bit architectures
The first argument of StackTrace constructor is a pointer to uptr. Match
the type accordingly.

This fixes builds on 32-bit architectures.
2023-06-08 13:03:08 +02:00
Marco Elver
90653579c0 [sanitizer_common] Move UNDEFINED attribute outside _MSC_VER guard
The __has_attribute check is sufficient, and if clang-cl is used, the
attribute will be available as well.
2023-06-08 13:03:08 +02:00
usama hameed
e487713a21
[Sanitizers] UUID/Build ID is 16 bytes on Darwin.
https://reviews.llvm.org/D114294 changed the kModuleUUIDSize from 16 to 32 for
all platforms. This is not true for Darwin where the UUID is 16 bytes.

Differential Revision: https://reviews.llvm.org/D152309
rdar://110346025
2023-06-07 14:32:41 -07:00
Mark de Wever
296d867287 [compiler-rt] Fixes Chromium Apple CI.
s/add_asm_sources/set/ at one place it was forgotten in D152102 as
reported by @paulkirth.
2023-06-07 21:24:05 +02:00
usama hameed
5a9498124d
[Sanitizers] Remove BuildId from sanitizers stacktrace on Darwin
On Darwin, we do not want to show the BuildId appended at the end of stack
frames in Sanitizers. The BuildId/UUID can be seen by using the
print_module_map=1 sanitizer option.

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

rdar://108324403
2023-06-07 11:17:25 -07:00
Mark de Wever
42478d1473 [compiler-rt] Removes CMake work-arounds.
CMake older than 3.20.0 is no longer supported.
This removes work-arounds for no longer supported versions.

Reviewed By: phosek

Differential Revision: https://reviews.llvm.org/D152102
2023-06-07 17:42:28 +02:00
Justin Cady
a3a4369ea1 [ASAN] Fix validation size for dirent on FreeBSD
Typically the size required to represent a dirent is stored in `d_reclen`. But
this not always the case for FreeBSD (for example, when walking a directory
over NFS).

This leads to ASAN false positives for `scandir` and similar functions. Because
ASAN uses `d_reclen` for the range to validate, it can overrun when `d_reclen` is
incorrect (too large).

This change adds `__sanitizer_dirsiz` which fixes the dirent size calculation
for FreeBSD. Other platforms continue to use `d_reclen`.

Reviewed By: vitalybuka
Differential Revision: https://reviews.llvm.org/D151583
2023-06-07 10:59:07 -04:00
Martin Storsjö
6853c49164 [compiler-rt] Do not redefine builtins in MinGW configs either
This fixes broken mingw builds since
0a71e25e2448ee471b1ebe74e910c5de9b9c82b4. Clang-cl style builds
were broken similarly, but were fixed in
caa2c1bacbd76c017ebbb4fd13861f0f66770299, with the comment
"Do not redefine builtins on Windows", even if the fix only affected
Clang-cl style builds.
2023-06-07 14:49:57 +03:00
Marco Elver
1cec9f8dc8 [sanitizer_common] Use interception macros for s390 __tls_get_addr declarations
NFC.
2023-06-07 13:09:43 +02:00
Marco Elver
33388d8c0b Revert "[compiler-rt] Allow 3 simultaneous interceptors on Linux"
This reverts commit 57882fe76e1826593cd0e53f73484b184c5007c4.
This reverts commit 74b0ac571b5facee3c8038d21ed71d7a29ee1098.

Breaks various build bots.
2023-06-07 10:16:24 +02:00
Marco Elver
57882fe76e Fix "[compiler-rt] Allow 3 simultaneous interceptors on Linux"
No need to "error" on unsupported architectures, since we technically
only care where the macro is used. If the macro is undefined, and used,
the compiler will producer an error anyway.

This fixes build on Windows, where none of these macros should be used.
2023-06-07 09:17:46 +02:00
Marco Elver
74b0ac571b [compiler-rt] Allow 3 simultaneous interceptors on Linux
Rework Linux (and *BSD) interceptors to allow for up to 3 (2 for *BSD)
simultaneous interceptors. See code comments for details.

The main motivation is to support new sampling sanitizers (in the spirit
of GWP-ASan), that have to intercept few functions. Unfortunately, the
reality is that there are user interceptors that exist in the wild.

To support foreign user interceptors, foreign dynamic analysis
interceptors, and compiler-rt interceptors all at the same time,
including any combination of them, this change enables up to 3
interceptors on Linux (2 on *BSD).

Reviewed By: dvyukov, MaskRay, vitalybuka

Differential Revision: https://reviews.llvm.org/D151085
2023-06-07 09:06:31 +02:00
Florian Mayer
cb49160765 Revert "[Sanitizers] Remove BuildId from sanitizers stacktrace on
Breaks tests.

This reverts commit fdb1a891b64c27522a2386a8025f8ad5c7e02bfb.
2023-06-06 17:25:55 -07:00
Marco Nelissen
146f4c26ac [scudo] Enable MTE in Trusty
Trusty now has MTE support.
Back-ported from https://r.android.com/2332745.

Reviewed By: Chia-hungDuan

Differential Revision: https://reviews.llvm.org/D152219
2023-06-07 00:15:04 +00:00
usama hameed
fdb1a891b6
[Sanitizers] Remove BuildId from sanitizers stacktrace on Darwin
On Darwin, we do not want to show the BuildId appended at the end of stack
frames in Sanitizers. The BuildId/UUID can be seen by using the
print_module_map=1 sanitizer option.

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

rdar://108324403
2023-06-06 16:37:39 -07:00
Arthur Eubanks
f715fa5cd8 Revert "Reland [compiler-rt][CMake] Properly set COMPILER_RT_HAS_LLD"
This reverts commit fffa05a2bcb548d5189e8c2e52d2ed2e7ebb2498.

This seems to cause hwasan tests to run in environments it didn't run in before.
2023-06-06 16:01:05 -07:00
Marco Elver
caa2c1bacb [compiler-rt] Do not redefine builtins on Windows
Build bots are still failing, and getting it to work on Windows should
be done in a separate patch, should this even be technically feasible.

 | lld-link: error:
 | stage2_win_x64/obj/compiler-rt/lib/asan/asan_shared_library.asan_activation.obj:
 | memcpy should not refer to special section 0
2023-06-06 17:33:49 +02:00
Marco Elver
0a71e25e24 [compiler-rt] Avoid memintrinsic calls inserted by the compiler
D135716 introduced -ftrivial-auto-var-init=pattern where supported.
Unfortunately this introduces unwanted memset() for large stack arrays,
as shown by the new tests added for asan and msan (tsan already had this
test).

In general, the problem of compiler-inserted memintrinsic calls
(memset/memcpy/memmove) is not new to compiler-rt, and has been a
problem before.

To avoid introducing unwanted memintrinsic calls, we redefine
memintrinsics as __sanitizer_internal_mem* at the assembly level for
most source files automatically (where sanitizer_common_internal_defs.h
is included).

In few cases, redefining a symbol in this way causes issues for
interceptors, namely the memintrinsic interceptor themselves. For such
source files we have to selectively disable the redefinition.

Other alternatives have been considered, but simply do not work well in
the context of compiler-rt:

	1. Linker --wrap:  this does not work because --wrap only
	   applies to the final link, and would not apply when building
	   sanitizer static libraries.

	2. Changing references to memset() via objcopy:  this may work,
	   but due to the complexities of the build system, introducing
	   such a post-processing step for the right object files (in
	   particular object files defining memset cannot be touched)
	   seems infeasible.

The chosen solution works well (as shown by the tests). Other libraries
have chosen the same solution where nothing else works (see e.g. glibc's
"symbol-hacks.h").

v4:
- Add interface attribute to __sanitizer_internal_mem* declarations as
  well, as otherwise some compilers (MSVC) will complain.
- Add SANITIZER_COMMON_NO_REDEFINE_BUILTINS to source files using
  C++STL, since this could lead to ODR violations (see added comment).

v3:
- Don't use ALIAS() to alias internal_mem*() functions to
  __sanitizer_internal_mem*() functions, but just define them as
  ALWAYS_INLINE functions instead. This will work on darwin and windows.

v2:
- Fix ubsan_minimal build where compiler decides to insert
  memset/memcpy: ubsan_minimal has work without RTSanitizerCommonLibc,
  therefore do not redefine the builtins.
- Fix definition of internal_mem* functions with compilers that want the
  aliased function to already be defined before.
- Fix definition of __sanitizer_internal_mem* functions with compilers
  more pedantic about attribute placement around extern "C".

Reviewed By: vitalybuka, dvyukov

Differential Revision: https://reviews.llvm.org/D151152
2023-06-06 16:10:45 +02:00
usama hameed
f6ea869f7c
[Sanitizers][Darwin] In DlAddrSymbolizer, return only the module file name instead of the comlpete module path during symbolication.
rdar://108858834

Differential Revision: https://reviews.llvm.org/D152029
2023-06-05 16:31:33 -07:00
Florian Mayer
5ac240bbea [hwasan] Properly restore SP tag on exceptions
Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D152036
2023-06-05 15:22:18 -07:00
Arthur Eubanks
fffa05a2bc Reland [compiler-rt][CMake] Properly set COMPILER_RT_HAS_LLD
LLVM_TOOL_LLD_BUILD is a relic of the pre-monorepo times. This causes us to never set COMPILER_RT_HAS_LLD.

Instead, set it from the runtimes build if lld is being built and lld is used as the compiler-rt linker.

Mark a test that requires libstdc++ as requiring Android, as other platforms may not have a libstdc++ lying around.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D144660
2023-06-05 14:35:52 -07:00
Dmitriy Filchenko
94407e1bba [scudo] Change configuration for Trusty, use mmap()
Trusty runs in memory constrained environments, with many apps
having only one page (4KB) of heap memory available. However, we
still want to mmap() multiples of PAGE_SIZE at a time.

Additionally, switch Scudo from using sbrk() to mmap().

Reviewed By: cferris

Differential Revision: https://reviews.llvm.org/D151968
2023-06-05 18:28:10 +00:00
Florian Mayer
b14f95b988 [sanitizer] add new symbolizer symbol 2023-06-05 10:58:19 -07:00
Florian Mayer
9fa938d687 Revert "Properly restore SP tag on exceptions"
This reverts commit 6a2e0cb418175bb985aa898604560110a77c43da.
2023-06-05 10:26:33 -07:00
paperchalice
0beffb8542 [CMake] Ensure CLANG_RESOURCE_DIR is respected.
re-commit of 39aa0f5c434b463520ac39a8dbe933ee8c4c5ea7 with missing file:
cmake/Modules/GetClangResourceDir.cmake.
2023-06-03 04:21:35 -07:00
Martin Storsjö
d072d11022 Revert "[CMake] Ensure CLANG_RESOURCE_DIR is respected."
This reverts commit 39aa0f5c434b463520ac39a8dbe933ee8c4c5ea7.

This is missing the new GetClangResourceDir.cmake that is being included,
so all clang builds are broken.
2023-06-03 11:47:57 +03:00
paperchalice
39aa0f5c43 [CMake] Ensure CLANG_RESOURCE_DIR is respected. 2023-06-02 23:29:44 -07:00
Caslyn Tonelli
0a168131b4 [scudo] Add 'inline' to static secondary.h function
This patches an error flaged by Fuchsia builds e.g.
https://ci.chromium.org/ui/p/turquoise/builders/global.try/core.x64-asan/b8779376650819379137/overview)

```
build failed:

[87176/332302](525) CXX user.libc_x64-asan-ubsan/obj/zircon/system/ulib/c/scudo/gwp-asan-info.gwp_asan_info.cc.o
FAILED: user.libc_x64-asan-ubsan/obj/zircon/system/ulib/c/scudo/gwp-asan-info.gwp_asan_info.cc.o
../../prebuilt/third_party/python3/linux-x64/bin/python3.8 -S ../../build/rbe/cxx_remote_wrapper.py --exec_strategy=remote_local_fallback --  ../../prebuilt/third_party/clang/linux-x64/bin/clang++ -MD -MF user.libc_x64-asan-ubsan/obj/zircon/system/ulib/c/scudo/gwp-asan-info.gwp_asan_info.cc.o.d -o user.libc_x64-asan-ubsan/obj/zircon/system/ulib/c/scudo/gwp-asan-info.gwp_asan_info.cc.o -D_LIBCPP...
In file included from ../../zircon/system/ulib/c/scudo/gwp_asan_info.cc:7:
In file included from ../../third_party/scudo/src/allocator_config.h:12:
In file included from ../../third_party/scudo/src/combined.h:22:
../../third_party/scudo/src/secondary.h:67:13: error: 'static' function 'unmap' declared in header file should be declared 'static inline' [-Werror,-Wunneeded-internal-declaration]
static void unmap(LargeBlock::Header *H) {
            ^
1 error generated.
```

Differential Revision: https://reviews.llvm.org/D152038
2023-06-02 23:47:27 +00:00
Florian Mayer
6a2e0cb418 Properly restore SP tag on exceptions
Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D152036
2023-06-02 15:33:14 -07:00
Vitaly Buka
99dc68387b [NFC][lsan] Use hash table to track root regions
This avoid O(N) in __lsan_unregister_root_region.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D151784
2023-06-02 14:38:01 -07:00
Vitaly Buka
0375a2dc7d [NFC][sanitizer] Avoid O(N^2) algorithm
Usually root_regions size is small so unlikey
this change will provide a noticable difference.

However it's easy to make sure that even with
large number of root_regions it works reasonably
fast.

Differential Revision: https://reviews.llvm.org/D151781
2023-06-02 14:32:03 -07:00
Vitaly Buka
c42e555dc2 [NFC][sanitizer] Delegate ArrayRef constructors 2023-06-02 14:32:03 -07:00
Vitaly Buka
6b3ae49d32 [sanitizer] Calculate Range sets intersection
Will be used to handle Root Regions in LSAN D151781.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D151779
2023-06-02 13:51:00 -07:00
Chia-hung Duan
2f08a08f61 [scudo] Support importing custom configuration
To define custom allocation, you only need to put the configuration in
custom_scudo_config.h and define two required aliases, then you will be
switched to the customized config and the tests will also run with your
configuration.

In this CL, we also have a minor refactor the structure of
configuration. Now the essential fields are put under the associated
hierarchy and which will make the defining new configuration easier.

Reviewed By: cferris

Differential Revision: https://reviews.llvm.org/D150481
2023-06-02 16:28:00 +00:00
Marco Elver
8e54794867 Revert "[compiler-rt] Avoid memintrinsic calls inserted by the compiler"
This reverts commit fc011a72881cdddc95bfa61f3f38916c29b7e362.
This reverts commit 4ad6a0c9a409b19b950a6a2a90d5405cea2e9b89.
This reverts commit 4b1eb4cf0e8eff5f68410720167b4986da597010.

Still causes Windows build bots to fail.
2023-06-02 16:37:38 +02:00
Marco Elver
fc011a7288 Fix "[compiler-rt] Avoid memintrinsic calls inserted by the compiler"
The tests already depend on libc through various dependencies. In
addition, including C++STL inline functions may lead to ODR violations
where one version uses sanitizer_common's internal_mem*() functions, and
the other the normal memintrinsics.
2023-06-02 16:25:32 +02:00
Marco Elver
4ad6a0c9a4 Fix "[compiler-rt] Avoid memintrinsic calls inserted by the compiler"
Add interface attribute to __sanitizer_internal_mem* declarations as
well, as otherwise some compilers (MSVC) will complain.
2023-06-02 15:48:16 +02:00