Commit Graph

16228 Commits

Author SHA1 Message Date
Vitaly Buka 0d07922d92 [NFC][asan] Simplify parameters check 2022-11-29 10:56:17 -08:00
Vitaly Buka cc27860165 [NFC][asan] Cleanup comments
D132090 is too verbose.
Don't explain obvious.
Add simpler explanation of rounding reasoning.

Differential Revision: https://reviews.llvm.org/D138773
2022-11-29 10:56:17 -08:00
Vitaly Buka 2b026fedca [NFC][asan] Handle non-intersecting case early
Differential Revision: https://reviews.llvm.org/D138772
2022-11-29 10:56:17 -08:00
Vitaly Buka e1657e3229 [asan] Add unaligned double ended container support
Differential Revision: https://reviews.llvm.org/D138771
2022-11-29 10:56:17 -08:00
Roy Sundahl 87d0ff9117
[asan][test] Fix SED issues with macOS (BSD)
SED differs between GNU and BSD in handling semicolon and the use of
'\n' in regex patterns. For macOS we can't use these GNU extensions.

rdar://102686948

Differential Revision: https://reviews.llvm.org/D138824
2022-11-29 09:47:23 -08:00
Vitaly Buka ca3c58f0d1 [lsan] Add logs for debugging 2022-11-28 22:59:38 -08:00
Petr Hosek bec8a372fc [CMake] Use LLVM_TARGET_TRIPLE in runtimes
This variable is derived from LLVM_DEFAULT_TARGET_TRIPLE by default,
but using a separate variable allows additional normalization to be
performed if needed.

Differential Revision: https://reviews.llvm.org/D137451
2022-11-29 04:08:24 +00:00
Teresa Johnson 311801a017 Revert "[MemProf] Defer profile file setup until dump time"
This reverts commit ea1826ee57.

This change is breaking the ability of tests to override the profile
output file. Need to add a mechanism to do that before resubmitting.
2022-11-28 06:29:24 -08:00
Vitaly Buka bc0ae48382 [test][asan] Speedup the test 2022-11-27 23:44:29 -08:00
Vitaly Buka 4880a48ab2 [NFC][asan] Fix typo in names 2022-11-27 23:42:10 -08:00
Vitaly Buka cef078a89d [NFC][asan] Reimplement with FindBadAddress 2022-11-27 23:00:42 -08:00
Vitaly Buka 450ec77037 [NFC][asan] Move a few precondition checks 2022-11-27 23:00:42 -08:00
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