Commit Graph

16216 Commits

Author SHA1 Message Date
Vitaly Buka 204cd4e22c [test][asan] Double ended version of TestContainer 2022-11-27 15:26:24 -08:00
Vitaly Buka 8db7768ab8 [NFC][asan] Extract FixUnalignedStorage
And simplify slightly: adjust for unaligned container
only if aligned case poisons different bytes.
2022-11-27 15:26:24 -08:00
Vitaly Buka 4883c91a73 [NFC][asan] Extract kMaxRangeToCheck into a function 2022-11-27 15:26:24 -08:00
Vitaly Buka 09ec58c8d6 [test][asan] Simplify a few expressions 2022-11-27 15:26:24 -08:00
Vitaly Buka 8226ec0e4c [test][asan] Check find_bad_address test
For consistency with future TestDoubleEndedContainer, where calculation
of the expected bad address is complicated.
2022-11-27 15:26:23 -08:00
Vitaly Buka ad663be76f [test][asan] Deduplicate code 2022-11-27 15:26:23 -08:00
Vitaly Buka b6c5875146 [NFC][asan] Rename variables in __sanitizer_annotate_contiguous_container 2022-11-27 15:26:23 -08:00
Dmitry Vyukov fbcdf4a4fb tsan: intercept epoll_pwait2
It's a new syscall similar to epoll_pwait.
Add a similar interceptor for it and add synchronization
annotations in epoll_wait* syscall wrappers.
Testing this is problematic b/c it's not present in glibc
and the syscall itself may not be supported by the kernel.

Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D138574
2022-11-24 07:27:09 +01:00
Snehasish Kumar cf5c53727b [memprof] Fix RAII usage of SpinMutexLock, remove unused headers.
For the RAII lock usage we need to create a local var. There were some headers which clang-tidy identified as unused.

Reviewed By: tejohnson

Differential Revision: https://reviews.llvm.org/D138593
2022-11-23 19:16:13 +00:00
Hans Wennborg 907baeec49 Revert "Make -fsanitize=scudo use scudo_standalone. Delete check-scudo."
It broke the build, see comments on code review.

> Leaves the implementation and tests files in-place for right now, but
> deletes the ability to build the old sanitizer-common based scudo. This
> has been on life-support for a long time, and the newer scudo_standalone
> is much better supported and maintained.
>
> Also patches up some GWP-ASan wording, primarily related to the fact
> that -fsanitize=scudo now is scudo_standalone, and therefore the way to
> reference the GWP-ASan options through the environment variable has
> changed.
>
> Future follow-up patches will delete the original scudo, and migrate all
> its tests over to be part of the scudo_standalone test suite.
>
> Reviewed By: vitalybuka
>
> Differential Revision: https://reviews.llvm.org/D138157

This reverts commit ab1a5991fe.
2022-11-23 16:07:07 +01:00
Fangrui Song 06c74b5e73 Revert D138095 Use InernalAlloc in DemangleCXXABI
Broke 2/3 tests on macOS which seem to be related to
`free(demangled_name)` in DemangleCXXABI.
2022-11-22 16:29:24 -08:00
Mitch Phillips ab1a5991fe Make -fsanitize=scudo use scudo_standalone. Delete check-scudo.
Leaves the implementation and tests files in-place for right now, but
deletes the ability to build the old sanitizer-common based scudo. This
has been on life-support for a long time, and the newer scudo_standalone
is much better supported and maintained.

Also patches up some GWP-ASan wording, primarily related to the fact
that -fsanitize=scudo now is scudo_standalone, and therefore the way to
reference the GWP-ASan options through the environment variable has
changed.

Future follow-up patches will delete the original scudo, and migrate all
its tests over to be part of the scudo_standalone test suite.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D138157
2022-11-22 12:08:30 -08:00
Kirill Stoimenov a2ef44a5d6 [Sanitizer][NFC] Rearranged prototype definitions in lsan_common.h to group them by implementation file.
Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D138335
2022-11-22 17:23:56 +00:00
Youling Tang dcefbce281 [Sanitizer] Fix the implementation of internal_fstat on LoongArch
If `pathname` is an empty string and the AT_EMPTY_PATH flag is specified in `flags`,
statx `pathname` argument is of type `const char *restrict`, so it should be `""`
instead of `0`.

Reviewed By: SixWeining, xen0n, xry111, lixing-star

Differential Revision: https://reviews.llvm.org/D138414
2022-11-22 22:16:11 +08:00
Youling Tang ac84798570 [scudo] Add loongarch64 support for scudo
Enable scudo on LoongArch64 on both clang side and compiler-rt side.

Reviewed By: SixWeining

Differential Revision: https://reviews.llvm.org/D138350
2022-11-22 22:02:31 +08:00
Vitaly Buka a27089101e [test][asan] Another try to fix Windows bot
Update pattern on Linux and Darwin for consistency.
2022-11-21 18:45:40 -08:00
Vitaly Buka 9d09982641 [test][asan] Replace tr with sed
tr is not available on Windows bot.
2022-11-21 17:52:39 -08:00
Vitaly Buka 793ff082da [test][asan] Try to fix Windows bot 2022-11-21 17:37:08 -08: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
Advenam Tacet 1c5ad6d2c0 [1a/3][ASan][compiler-rt] API for double ended containers
This revision is a part of a series of patches extending
AddressSanitizer C++ container overflow detection capabilities by adding
annotations, similar to those existing in std::vector, to std::string
and std::deque collections. These changes allow ASan to detect cases
when the instrumented program accesses memory which is internally
allocated by the collection but is still not in-use (accesses before or
after the stored elements for std::deque, or between the size and
capacity bounds for std::string).

The motivation for the research and those changes was a bug, found by
Trail of Bits, in a real code where an out-of-bounds read could happen
as two strings were compared via a std::equals function that took
iter1_begin, iter1_end, iter2_begin iterators (with a custom comparison
function). When object iter1 was longer than iter2, read out-of-bounds
on iter2 could happen. Container sanitization would detect it.

This revision adds a new compiler-rt ASan sanitization API function
sanitizer_annotate_double_ended_contiguous_container necessary to
sanitize/annotate double ended contiguous containers. Note that that
function annotates a single contiguous memory buffer (for example the
std::deque's internal chunk). Such containers have the beginning of
allocated memory block, beginning of the container in-use data, end of
the container's in-use data and the end of the allocated memory block.
This also adds a new API function to verify if a double ended contiguous
container is correctly annotated
(__sanitizer_verify_double_ended_contiguous_container).

Since we do not modify the ASan's shadow memory encoding values, the
capability of sanitizing/annotating a prefix of the internal contiguous
memory buffer is limited – up to SHADOW_GRANULARITY-1 bytes may not be
poisoned before the container's in-use data. This can cause false
negatives (situations when ASan will not detect memory corruption in
those areas).

On the other hand, API function interfaces are designed to work even if
this caveat would not exist. Therefore implementations using those
functions will poison every byte correctly, if only ASan (and
compiler-rt) is extended to support it. In other words, if ASan was
modified to support annotating/poisoning of objects lying on addresses
unaligned to SHADOW_GRANULARITY (so e.g. prefixes of those blocks),
which would require changing its shadow memory encoding, this would not
require any changes in the libcxx std::string/deque code which is added
in further commits of this patch series.

If you have any questions, please email:
advenam.tacet@trailofbits.com
disconnect3d@trailofbits.com

Differential Revision: https://reviews.llvm.org/D132090
2022-11-21 16:38:52 -08:00
Vitaly Buka 6c87deaa07 [test][asan] Ignore new lines in header 2022-11-21 16:38:52 -08:00
Vitaly Buka 16d3c0c7a4 [test][asan] Limit scope of the var 2022-11-21 16:38:52 -08:00
Fangrui Song db7c82231c Restore global descriptor demangling after D138095 "[asan] Keep Itanium mangled names in global metadata"
This amends commit 00be3578e0 to demangle symbol
names in global descriptors. We keep the mangled name for the `__odr_gen_asan_*`
variables and the runtime __cxa_demangle call site change (which fixed possible
leaks for other scenarios: non-fatal diagnostics).

compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cpp uses
an undefined weak `__cxa_demangle` which does not pull in an archive definition.
A -static-libstdc++ executable link does not get demangled names.

Unfortunately this means we cannot rely on runtime demangling.
See compiler-rt/test/asan/TestCases/global-demangle.cpp
2022-11-21 20:51:52 +00:00
Vitaly Buka 27998d91eb [test][asan] Rename variables for less confusion 2022-11-19 17:19:13 -08:00
Vitaly Buka e37f8e588c [test][asan] Simplify __sanitizer_verify_contiguous_container test 2022-11-19 01:52:22 -08:00
Vitaly Buka 4b4250c757 [test][asan] Simplify loops in test 2022-11-19 01:26:51 -08:00
Vitaly Buka f0fbf51a73 [test][asan] Simplify test
We don't need to iterate off_end, just need to check a granule after the
end.
2022-11-19 00:24:30 -08:00
Fangrui Song 00be3578e0 [asan] Keep Itanium mangled names in global metadata
The runtime calls `MaybeDemangleGlobalName` for error reporting and
`__cxxabiv1::__cxa_demangle` is called if available, so demanging Itanium
mangled names in global metadata is unnecessary and wastes data size.

Add `MaybeDemangleGlobalName` in ODR violation detection to support demangled
names in a suppressions file. `MaybeDemangleGlobalName` may call
`DemangleCXXABI` and leak memory. Use an internal allocation to prevent lsan
leak (in case there is no fatal asan error).

The debug feature `report_globals=2` prints information for all instrumented
global variables. `MaybeDemangleGlobalName` would be slow, so don't do that.
The output looks like `Added Global[0x56448f092d60]: beg=0x56448fa66d60 size=4/32 name=_ZL13test_global_2`
and I think the mangled name is fine.

Other mangled schemes e.g. Windows (see win-string-literal.ll) remain the
current behavior.

Reviewed By: hctim

Differential Revision: https://reviews.llvm.org/D138095
2022-11-19 01:06:26 +00:00
Teresa Johnson ea1826ee57 [MemProf] Defer profile file setup until dump time
With all of the writing of the memprof profile consolidated into one
place, there is no need to set up the profile file (which creates the
file and also redirects all printing from the runtime to it) until we
are ready to dump the profile.

This allows errors and other messages to be dumped to stderr instead of
the profile file, which by default is in a binary format. Additionally,
reset the output file to stderr after dumping the profile so that any
requested memprof allocator statistics are printed to stderr.

Differential Revision: https://reviews.llvm.org/D138175
2022-11-18 15:09:02 -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
Vitaly Buka d13dd10da0 [NFC][asan] Simplify __sanitizer_annotate_contiguous_container 2022-11-18 00:56:33 -08:00
Vitaly Buka 796b1bdd30 [NFC][asan] Rename variables in test 2022-11-17 23:24:39 -08:00
Vitaly Buka d3139730e2 [asan] Simplify the test 2022-11-17 22:32:09 -08:00
usama hameed 7052164f98 [UBSan] Implementation NonUniqueARMRTTIBit __type_name has higher bits set on arm64
Differential Revision: https://reviews.llvm.org/D137518
2022-11-17 13:46:59 -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
Vitaly Buka 605355f0dc [NFC][asan] Reformat macro 2022-11-16 22:45:08 -08:00
Vitaly Buka e7376adbea [NFC][asan] clang-format the test 2022-11-16 22:45:08 -08:00
Vitaly Buka 38b5a37082 [NFC][asan] format __sanitizer_annotate_contiguous_container 2022-11-16 22:45:08 -08:00
Youling Tang 4ae3e13c7d [sanitizer] Add ptrace interceptor support for LoongArch
Add ptrace interceptor support for LoongArch, `ptrace.cpp` has been
tested and passed.

Reviewed By: SixWeining

Differential Revision: https://reviews.llvm.org/D137228
2022-11-17 11:57:32 +08:00
Roy Sundahl b2d9e08c44
[asan][darwin] This test is x86_64 specific, not non-ios in general.
This test was unsupported in iOS when a more accurate test is that the architecture is x86_64. This "fix" is first in a series of updates intended to get asan arm64 tests fully functional.

Reviewed By: thetruestblue, vitalybuka

Differential Revision: https://reviews.llvm.org/D138001
2022-11-15 11:25:54 -08:00
Petr Hosek 9c2700dfa5 [CMake][compiler-rt] Don't load LLVM config in the runtimes build
LLVM runtimes build already loads the LLVM config and sets all
appropriate variables, no need to do it again.

Differential Revision: https://reviews.llvm.org/D137870
2022-11-15 09:01:46 +00:00
Kuba Mracek 32bada2eda [lsan] Fix stack buffer overwrite in SuspendedThreadsListMac::GetRegistersAndSP
The call to the thread_get_state syscall (that fetches the register values for a thread) on arm64 is mistakenly claiming that the buffer to receive the register state is larger that its actual size on the stack -- the struct on the stack is arm_thread_state64_t, but the MACHINE_THREAD_STATE + MACHINE_THREAD_STATE_COUNT refer to the "unified arm state" struct (which is larger).

Fixes https://github.com/llvm/llvm-project/issues/58503.

Differential Revision: https://reviews.llvm.org/D137292
2022-11-12 10:17:52 -08:00
Lang Hames e7707464a3 [ORC-RT][MachO] Unlock JDStatesMutex during push-initializers to avoid deadlock.
During __orc_rt_macho_jit_dlopen the ORC runtime will make a request to the JIT
to push any new initializers. Since this call may add new JD-state to the
runtime (and is expected to in general) we need to unlock the JDStatesMutex
during this operation (and similarly when running initializers and atexits, as
these may call trigger push-initializers recursively).

No testcase yet: I haven't been able to reproduce the deadlock when running
llvm-jitlink in in-process mode, and we don't support out-of-process mode in
regression tests yet.
2022-11-11 16:01:25 -08:00
XingLi 1e2c20fc13 [compiler-rt] Mark $t* as clobbered for Linux/LoongArch syscalls
Linux/LoongArch doesn't preserve temporary registers across syscalls,
so we have to explicitly mark them as clobbered to avoid trashing local variables.

Reviewed By: xry111, xen0n, tangyouling, SixWeining

Differential Revision: https://reviews.llvm.org/D137396
2022-11-11 21:24:07 +08:00
Timm Bäder e1b88c8a09 [clang] Only use major version in resource dir
This causes unnecessary churn for downstreams.

For the full discussion, see https://discourse.llvm.org/t/should-we-continue-embed-the-full-llvm-version-in-lib-clang/62094

Differential Revision: https://reviews.llvm.org/D125860
2022-11-10 15:02:03 +01:00
Simon Pilgrim 261b3f71c0 [X86] Add missing Zen3 model subtypes
This patch adds support for detecting all current Zen/Zen3+ submodels

Based off a mixture of https://github.com/torvalds/linux/blob/master/drivers/hwmon/k10temp.c#L436 and InstLatx64 https://github.com/InstLatx64/InstLatx64/tree/master/AuthenticAMD CPUID dumps and confirmed by @GGanesh

Differential Revision: https://reviews.llvm.org/D137695
2022-11-10 10:36:09 +00:00
Youling Tang 3ba498d145 [fuzzer][test] Add #include <cstdint> for gcc-13
See https://gcc.gnu.org/gcc-13/porting_to.html#header-dep-changes.

Reviewed By: SixWeining

Differential Revision: https://reviews.llvm.org/D137696
2022-11-10 13:44:11 +08:00
Youling Tang 8993f3eed6 [sanitizer] Add symbolizer support for loongarch64
Reviewed By: xry111

Differential Revision: https://reviews.llvm.org/D137383
2022-11-10 13:38:09 +08:00
Youling Tang 91bc4abfdb [sanitizer][test] Fix FastUnwindTest on LoongArch
Fixes the `FastUnwindTest` unit test for LoongArch.
This change is similar to RISCV D90574.

The following test cases pass after applying the patch:
```
$ ./runtimes/runtimes-bins/compiler-rt/lib/sanitizer_common/tests/Sanitizer-loongarch64-Test
...
[  FAILED  ] FastUnwindTest.Basic
[  FAILED  ] FastUnwindTest.FramePointerLoop
[  FAILED  ] FastUnwindTest.MisalignedFramePointer
[  FAILED  ] FastUnwindTest.FPBelowPrevFP
[  FAILED  ] FastUnwindTest.CloseToZeroFrame
```

Reviewed By: SixWeining, xen0n, MaskRay

Differential Revision: https://reviews.llvm.org/D137314
2022-11-10 13:35:52 +08:00
Youling Tang 14cd113e69 [sanitizer] Add the settings of Read and Write flags in SignalContext for LoongArch
The bit-30 in this `__flags` means the address error is due to memory load, and the
bit-31 means the address error is due to memory store. (see SC_ADDRERR_RD
and SC_ADDRERR_WR in kernel arch/loongarch/include/uapi/asm/sigcontext.h).

`illegal_write_test.cpp` and `illegal_read_test.cpp` have been tested and passed.

Reviewed By: SixWeining, xen0n, XiaodongLoong

Differential Revision: https://reviews.llvm.org/D137231
2022-11-10 13:34:22 +08:00