17142 Commits

Author SHA1 Message Date
Tomasz Kuchta
9875273ad2 [DFSAN] Add support for _tolower
I noticed that in some cases _tolower shows as uninstrumented - I've added it as "functional" in the done_abilist.txt file

Reviewed by: browneee

Differential Revision: https://reviews.llvm.org/D153410
2023-06-22 20:48:14 +00:00
Vitaly Buka
30ac031dd5 [NFC][asan] Add FIXME for a posible optimization 2023-06-22 12:41:41 -07:00
Vitaly Buka
82a6152344 [asan] Don't double poison secondary allocations
Sanitizers allocate shadow and memory as MAP_NORESERVE.

User memory can stay this way and do not increase RSS as long as we
don't store there.

The shadow unpoisoning also can avoid RSS increase for zeroed pages.
However as soon we poison the shadow, we need the page in RSS.

To avoid unnececary RSS increase we should not poison memory just before
unpoisoning them.

Depends on D153497.

Reviewed By: thurston

Differential Revision: https://reviews.llvm.org/D153500
2023-06-22 12:35:21 -07:00
Vitaly Buka
a0509884d9 [asan] Optimize Quarantine of secondary allocations
For the secondary allocation we don't need poison and fill memory if we
skip quarantine, and we don't need to poison after quarantine. In both
cases the secondary allocator will unmap memory and unpoison the shadow
from get_allocator().Deallocate().

Depends on D153496.

Reviewed By: thurston

Differential Revision: https://reviews.llvm.org/D153497
2023-06-22 11:24:08 -07:00
Vitaly Buka
bd4bf4947c [NFC][asan] Add const to QuarantineCallback methods 2023-06-22 10:38:40 -07:00
Vitaly Buka
191c162d6e [NFC][asan] Extract FillChunk 2023-06-22 10:38:29 -07:00
Vitaly Buka
735bcc9279 [NFC][asan] Add QuarantineCallback::{PreQuarantine,RecyclePassThrough}
Reviewed By: thurston

Differential Revision: https://reviews.llvm.org/D153496
2023-06-22 10:28:27 -07:00
Vitaly Buka
10f57cf5db [asan] Don't quarantine large blocks
Almost NFC, as blocks over max quarantine size will trigger immediate
drain anyway. In followup patches we can optimize passthrough case.

Reviewed By: thurston

Differential Revision: https://reviews.llvm.org/D153495
2023-06-22 10:07:45 -07:00
Vitaly Buka
9540f50281 [test][sanitizer] Reformat and print to stderr 2023-06-21 23:21:41 -07:00
Vitaly Buka
9e68b7e0e0 [NFC][sanitizer] Rename internal getters 2023-06-21 21:05:27 -07:00
Vitaly Buka
116b5e1eb4 [test][sanitizer] Pre-commit huge malloc test 2023-06-21 16:20:02 -07:00
Vitaly Buka
bda0a93a91 Revert "[test][sanitizer] Precommit huge malloc test"
Wrong accidental commit.

This reverts commit 1f18c9624b44e763a76742634f0f95432ea7cb23.
2023-06-21 16:17:23 -07:00
Vitaly Buka
1f18c9624b [test][sanitizer] Precommit huge malloc test 2023-06-21 16:14:07 -07:00
Vitaly Buka
758935061c [test] Add llvm-xray into XRAY_TEST_DEPS 2023-06-21 16:13:47 -07:00
Vitaly Buka
2cb547a719 [test] Add lli into ORC_TEST_DEPS 2023-06-21 16:13:47 -07:00
Christopher Ferris
a27c416b89 [scudo] Change overloaded function name append.
The ScopedString class has two functions named append. One takes
a va_list, but on some platforms va_list is typedef'd to char*.
That means that this call:

  std::string value;
  Str.append("print this string %s", value.c_str());

The compiler can incorrectly think this is the va_list function,
leading to crashes when calling this. To fix this, change the name
of the va_list function to be vappend to avoid this.

Fix https://github.com/llvm/llvm-project/issues/62893

Reviewed By: Chia-hungDuan

Differential Revision: https://reviews.llvm.org/D153389
2023-06-21 15:11:47 -07:00
Tomasz Kuchta
d9b3691166 [DFSAN] Add support for strncat
This patch adds a support for the libc strncat() function in DFSAN

Reviewed by: browneee

Differential Revision: https://reviews.llvm.org/D152196
2023-06-21 21:21:13 +00:00
Vitaly Buka
96928abb4d [NFC][sanitizer] Pass user region into OnMapSecondary 2023-06-21 13:50:42 -07:00
Vitaly Buka
38dfcf96df [NFC][sanitizer] Add OnMapSecondary callback
Now it implemented as OnMap everywhere, but in follow up patches
we can optimize Asan handler.
2023-06-21 13:33:41 -07:00
Vitaly Buka
42adbb1b2d [NFC][sanitizer] Remove MapUnmapCallback from sanitizer_flat_map.h
It's used by test only to test "test-only" code.
2023-06-21 13:14:30 -07:00
Vitaly Buka
c172210492 [NFC][asan] Move AsanStats update
Deallocate is a more appropiate place to update free count.
2023-06-21 11:50:45 -07:00
Fangrui Song
e0a6561ec9 [XRay] Make xray_fn_idx entries PC-relative
As mentioned by commit c5d38924dc6688c15b3fa133abeb3626e8f0767c (Apr 2020),
PC-relative entries avoid dynamic relocations and can therefore make the
section read-only.

This is similar to D78082 and D78590. We cannot commit to support
compiler/runtime built at different versions, so just don't play with versions.

For Mach-O support (incomplete yet), we use non-temporary `lxray_fn_idx[0-9]+`
symbols. Label differences are represented as a pair of UNSIGNED and SUBTRACTOR
relocations. The SUBTRACTOR external relocation requires r_extern==1 (needs to
reference a symbol table entry) which can be satisfied by `lxray_fn_idx[0-9]+`.
A `lxray_fn_idx[0-9]+` symbol also serves as the atom for this dead-strippable
section (follow-up to commit b9a134aa629de23a1dcf4be32e946e4e308fc64d).

Differential Revision: https://reviews.llvm.org/D152661
2023-06-20 22:40:56 -07:00
Leonard Grey
55a2c4eb04 [lsan] Remove use_tls=0 from a few tests
The Objective-C runtime now stashes some state in TLS so any
test that indirectly initializes an Objective-C object will
have false positive leaks unless use_tls=1 as is the default.

Differential Revision: https://reviews.llvm.org/D153081
2023-06-20 18:52:11 -04:00
Chia-hung Duan
19c26a7c03 [scudo] Finer lock granularity in Region of SizeClassAllocator64
In this CL, we introduce two new locks, MMLock for MemMap operations and
FLLock for freelist operations.

MMLock will be used when we want to manipulate pages. For example,
mapping more pages through populateFreeList() and releaseToOSMaybe().

FLLock will be used when we want to access the freelist. For example,
pushBlocks() and popBatch().

With the new locks, they increase the parallelism of the operations
mentioned above. For example, populateFreeList() won't block the
pushBlocks() when it's still doing the system call for more pages.

We also enforce lock hierarchy to avoid deadlock, MMLock is required to
be held before FLLock if you have to lock both of them. We don't store
the lock owner, therefore, we rely static thread-safey annotation to
detect any violation.

Differential Revision: https://reviews.llvm.org/D149140
2023-06-20 18:34:48 +00:00
Fangrui Song
f8a4cd0f07 [xray][AArch64] Rewrite trampoline
Optimize (cmp+beq => cbz), duduplicate code (SAVE_REGISTERS/RESTORE_REGISTERS),
improve portability (use ASM_SYMBOL to be compatible with Mach-O), and fix style
issues.
Also, port D37965 (x86 tail call) to __xray_FunctionTailExit.
2023-06-19 23:02:45 -07:00
Fangrui Song
3fa3cb408d [XRay] Make llvm.xray.typedevent parameter type match __xray_typedevent
The Clang built-in function is void __xray_typedevent(size_t, const void *, size_t),
but the LLVM intrinsics has smaller integer types. Since we only allow
64-bit ELF/Mach-O targets, we can change llvm.xray.typedevent to
i64/ptr/i64.

This allows encoding more information and avoids i16 legalization for
many non-X86 targets.

fdrLoggingHandleTypedEvent only supports uint16_t event type.
2023-06-19 20:28:39 -07:00
Fangrui Song
199f7dd421 [XRay][X86] Remove sled version 0 support from patchCustomEvent
This is remnant after D140739.
2023-06-19 15:11:26 -07:00
Fangrui Song
b7a86d03cb [xray][test] Test __xray_typedevent after D43668 2023-06-19 14:53:22 -07:00
Christopher Ferris
5759e3ce6d [scudo] Add mallopt to print stats to the log.
Reviewed By: Chia-hungDuan

Differential Revision: https://reviews.llvm.org/D153094
2023-06-16 13:34:45 -07:00
Fangrui Song
c57c7b7c99 [xray] Use L* instead of .L* for Mach-O
Note: Mach-O support is not yet done and check-xray is not allowed yet.
2023-06-16 12:04:29 -07:00
Roland McGrath
42564f97e8 [fuzzer][fuchsia] Support RISC-V
Reviewed By: phosek

Differential Revision: https://reviews.llvm.org/D153082
2023-06-16 11:39:32 -07:00
Evgenii Stepanov
ed552f2151 [scudo] Disable OddEvenTags by default.
Scudo has zero-tagged headers between any two allocation that will catch
a linear buffer overflow of up to 16 bytes. OddEvenTags extends this
guarantee to one chunk of the given SizeClass at the cost of the reduced
entropy for all heap tags (i.e. lower chance to catch use-after-free and
large overflows).

Given that the first 16 bytes are already deterministic, I feel this is
a bad tradeoff.

Differential Revision: https://reviews.llvm.org/D152984
2023-06-15 16:36:27 -07:00
Leonard Chan
17623e96b5 [compiler-rt] Go back to using the 32-bit allocator for Fuchsia+RISCV64
Due to logic in the 64-bit allocator, the smallest allocation we can
zx_vmar_allocate is 2^37 bytes, but this is too large to allocate for
the standalone lsan allocator on a 39-bit VMA. This leads to the
zx_vmar_allocate call when initially setting up the allocator to fail.
This is similar to what android experiences on a 64-bit system with a
small vma. (See sanitizer_allocator_test.cpp).

This effectively reverts f6c4808d95221a5838e14474d95c6fe85bb1488a and
has Fuchsia use the 32-bit allocator for RISCV.
2023-06-15 23:29:06 +00:00
Kirill Stoimenov
7ebfc36f7e [Sanitizers] Remove unused parameter from COMMON_INTERCEPTOR_MUNMAP_IMPL
This was a result of copy/paste from the MMAP interceptor which uses the parameter to swtich between mmap and mmap64.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D152980
2023-06-15 23:19:04 +00:00
Alfred Persson Forsberg
63eb7c4e66 [scudo] Do not compile timing.cpp if LLVM_LIBC_INCLUDE_SCUDO=on
Temporary hack until LLVM libc supports inttypes.h print format macros

timing.h uses the PRId64 macro which is not included in llvm libc yet

Bug: https://github.com/llvm/llvm-project/issues/63317

Reviewed By: michaelrj, thesamesam, Chia-hungDuan

Differential Revision: https://reviews.llvm.org/D152979
2023-06-16 00:09:39 +01:00
Chia-hung Duan
29aa587f1a [scudo] Group MappedUser/AllocatedUser into PagesInfo (NFC)
Create a new PagesInfo to contain all the information about pages. This
is the preparation of adding new lock for page operations.

Note that primary32 hasn't switched to MemMap. Will add PagesInfo later
when we move to MemMap in primary32.

Differential Revision: https://reviews.llvm.org/D149142
2023-06-15 22:38:48 +00:00
Chia-hung Duan
5beaa7339f [scudo] Group poppedBlocks/pushedBlocks into BlocksInfo (NFC)
Create a new BlocksInfo to contain a list of blocks, poppedBlocks and
pushedBlocks. This is the preparation of adding new lock for operations
on freelist.

Differential Revision: https://reviews.llvm.org/D149143
2023-06-15 22:38:48 +00:00
Christopher Ferris
f95a4a2833 [scudo] Disable new/delete mismatch tests on Android.
Android does not do any checking of new/delete mismatches, so disable
this test when compiling for Android.

Reviewed By: Chia-hungDuan

Differential Revision: https://reviews.llvm.org/D152958
2023-06-14 16:07:50 -07:00
Vitaly Buka
ad1dd78793 [hwasan] Fixup mmap tagging regions
Reviewed By: thurston

Differential Revision: https://reviews.llvm.org/D152893
2023-06-14 15:32:12 -07:00
Vitaly Buka
aeb13a4459 [test][hwasan] Use perror and abort in test 2023-06-14 15:22:12 -07:00
Chia-hung Duan
163f8e1b01 Revert "[scudo] Temporariy dispatch region from RegionBeg"
This reverts commit 9d9a7732e14d7d4c0db7b46d6ebe588e8f43b951.

This was a workaround for some platform and it has been fixed in
bfa02523b2e7ed66368ea61866a474e55ef354a3

Differential Revision: https://reviews.llvm.org/D152964
2023-06-14 21:48:59 +00:00
Christopher Ferris
261d9e58d4 [scudo] Fix MallocIterateBoundary test on 32 bit Android.
On Android, the min alignment is 16 bytes. This test needs
the BlockDelta to match the min alignment, so set this value
differently for Android.

Update the comment in to explain these details.

Reviewed By: Chia-hungDuan

Differential Revision: https://reviews.llvm.org/D152884
2023-06-14 10:35:41 -07:00
Kirill Stoimenov
ceab8e3af7 [HWASAN] Fix bot test failure caused by D152763 by switching to
unaligned memory tagging
2023-06-14 14:55:31 +00:00
Vitaly Buka
c93ca4bcb8 [test][hwasan] Allow test for any platform with tagging 2023-06-14 01:16:54 -07:00
Vitaly Buka
4a69e0a0ad [test][hwasan] Rename constants in test 2023-06-14 01:00:35 -07:00
Kirill Stoimenov
fba9fd1afa [HWASAN] Implement munmap interceptor for HWASAN
Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D152763
2023-06-14 05:36:12 +00:00
Fabio D'Urso
bd96d7b81f [scudo] Fix bound checks in MemMap and ReservedMemory methods
Reviewed By: Chia-hungDuan

Differential Revision: https://reviews.llvm.org/D152690
2023-06-14 03:55:54 +00:00
Wu, Yingcong
f154f10887 [sanitizer] Adjust code path of ChooseExternalSymbolizer for Windows
If `path` is null, `user_path` must also be null. With the current code path, the message of explicitly disabling symbolizer will never be reported. This patch adjusts the if-else structure to make that message can be reported.

Reviewed By: cchen15, MaskRay

Differential Revision: https://reviews.llvm.org/D148907
2023-06-13 14:51:47 -07:00
Vitaly Buka
08dd72de89 [test][asan] Remove XFAIL after D152604 2023-06-13 14:04:13 -07:00
Vitaly Buka
a37bd13744 [test][sanitizer] Fix test on windows 2023-06-13 12:34:26 -07:00