Commit Graph

881 Commits

Author SHA1 Message Date
Manoj Gupta 1f82d0f795 [msan] Add interceptors for Linux 64-bit stat variants
glibc >= 2.33 uses shared functions for stat family functions.
D111984 added support for non-64 bit variants but they
do not appear to be enough as we have been noticing msan
errors on 64-bit stat variants on Chrome OS.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D121652
2022-03-15 20:22:28 -07:00
Vitaly Buka 43f208e94c [msan] Fix unittest for 9397bdc6
"1.1" is double which can't be represented precicely as a float.
2022-03-10 01:21:30 +00:00
Kevin Athey fc9e07873f Revert "[MSAN] add interceptor for timer_create, timer_settime, timer_gettime"
This reverts commit 0a4dec6cc2.

breaks buildbots
2022-03-09 14:57:05 -08:00
Kevin Athey 0a4dec6cc2 [MSAN] add interceptor for timer_create, timer_settime, timer_gettime
Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D120602
2022-03-09 11:21:16 -08:00
Petr Hosek b0e369501f Revert "[MSAN] add interceptor for timer_create, timer_settime, timer_gettime"
This reverts commit c2aab0d380 due to
a leak in timer.cpp that showed up on several bots.
2022-03-09 10:46:20 -08:00
Kevin Athey c2aab0d380 [MSAN] add interceptor for timer_create, timer_settime, timer_gettime
Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D120602
2022-03-08 16:59:43 -08:00
Stella Laurenzo 38151a08c2 Reapply "[cmake] Prefix gtest and gtest_main with "llvm_"."
This reverts commit 7cdda6b8ce.

Differential Revision: https://reviews.llvm.org/D121020
2022-03-04 13:45:43 -08:00
Stella Laurenzo 7cdda6b8ce Revert "[cmake] Prefix gtest and gtest_main with "llvm_"."
lldb buildbot failure. will investigate and roll forward.

This reverts commit 9f37775472.
2022-03-02 11:13:46 -08:00
Stella Laurenzo 9f37775472 [cmake] Prefix gtest and gtest_main with "llvm_".
The upstream project ships CMake rules for building vanilla gtest/gmock which conflict with the names chosen by LLVM. Since LLVM's build rules here are quite specific to LLVM, prefixing them to avoid collision is the right thing (i.e. there does not appear to be a path to letting someone *replace* LLVM's googletest with one they bring, so co-existence should be the goal).

This allows LLVM to be included with testing enabled within projects that themselves have a dependency on an official gtest release.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D120789
2022-03-02 10:53:32 -08:00
Vitaly Buka c046cff1cf [msan] strsignal interceptor
Reviewed By: kstoimenov

Differential Revision: https://reviews.llvm.org/D120082
2022-02-17 18:13:35 -08:00
Dmitry Vyukov 595d340dce sanitizer_common: make internal/external headers compatible
This is a follow up to 4f3f4d6722
("sanitizer_common: fix __sanitizer_get_module_and_offset_for_pc signature mismatch")
which fixes a similar problem for msan build.

I am getting the following error compiling a unit test for code that
uses sanitizer_common headers and googletest transitively includes
sanitizer interface headers:

In file included from third_party/gwp_sanitizers/singlestep_test.cpp:3:
In file included from sanitizer_common/sanitizer_common.h:19:
sanitizer_interface_internal.h:41:5: error: typedef redefinition with different types
('struct __sanitizer_sandbox_arguments' vs 'struct __sanitizer_sandbox_arguments')
  } __sanitizer_sandbox_arguments;
common_interface_defs.h:39:3: note: previous definition is here
} __sanitizer_sandbox_arguments;

Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D119546
2022-02-11 19:39:44 +01:00
Fangrui Song c80d349859 [msan][tsan] Refine __fxstat{,at}{,64} condition
In glibc before 2.33, include/sys/stat.h defines fstat/fstat64 to
`__fxstat/__fxstat64` and provides `__fxstat/__fxstat64` in libc_nonshared.a.
The symbols are glibc specific and not needed on other systems.

Reviewed By: vitalybuka, #sanitizers

Differential Revision: https://reviews.llvm.org/D118423
2022-01-28 09:15:39 -08:00
Dmitry Vyukov 395f737c33 msan: check that ucontext_t is initialized on signal return
A signal handler can alter ucontext_t to affect execution after
the signal returns. Check that the contents are initialized.
Restoring unitialized values in registers can't be good.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D116209
2022-01-05 13:20:50 +01:00
Dmitry Vyukov 1298273e82 msan: account for AVX state when unpoison ucontext_t
ucontext_t can be larger than its static size if it contains
AVX state and YMM/ZMM registers.
Currently a signal handler that tries to access that state
can produce false positives with random origins on stack.
Account for the additional ucontext_t state.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D116208
2022-01-05 13:20:40 +01:00
Nikita Popov a9bb97e841 [msan] Break optimization in memccpy tests
After D116148 the memccpy gets optimized away and the expected
uninitialized memory access does not occur.

Make sure the call does not get optimized away.
2021-12-22 14:45:20 +01:00
Petr Hosek 458ead66dc [compiler-rt] Use the runtimes build for custom libc++
Some of the compiler-rt runtimes use custom instrumented libc++ build.
Use the runtimes build for building this custom libc++.

Differential Revision: https://reviews.llvm.org/D114922
2021-12-08 12:52:48 -08:00
Vitaly Buka 6318001209 [sanitizer] Support IsRssLimitExceeded in all sanitizers
Reviewed By: kstoimenov

Differential Revision: https://reviews.llvm.org/D115000
2021-12-03 12:45:44 -08:00
Vitaly Buka 323bfad72d [sanitizer] DEFINE_REAL_PTHREAD_FUNCTIONS for hwasan, lsan, msan
It should be NFC, as they already intercept pthread_create.

This will let us to fix BackgroundThread for these sanitizerts.
In in followup patches I will fix MaybeStartBackgroudThread for them
and corresponding tests.

Reviewed By: kstoimenov

Differential Revision: https://reviews.llvm.org/D114935
2021-12-02 10:24:04 -08:00
Vitaly Buka b0ea7ef0d6 [msan] Clang-format the test 2021-11-18 18:30:49 -08:00
Vitaly Buka cda72e9297
[msan] Fix test with GLIBC 2.34
PTHREAD_STACK_MIN is not a constexpr
2021-11-14 20:15:45 -08:00
Vitaly Buka cb0e14ce6d [sanitizer] Switch dlsym hack to internal_allocator
Since glibc 2.34, dlsym does
  1. malloc 1
  2. malloc 2
  3. free pointer from malloc 1
  4. free pointer from malloc 2
These sequence was not handled by trivial dlsym hack.

This fixes https://bugs.llvm.org/show_bug.cgi?id=52278

Reviewed By: eugenis, morehouse

Differential Revision: https://reviews.llvm.org/D112588
2021-11-12 16:11:10 -08:00
Vitaly Buka aa15e426ea [NFC][msan] Clang format includes 2021-11-10 18:17:09 -08:00
Vitaly Buka 651797f488 [NFC][sanitizer] Move GET_MALLOC_STACK_TRACE closer to the use 2021-11-10 15:42:07 -08:00
Vitaly Buka f2c2292fa8 [msan] Block signals in MsanThread::Init
If async signal handler called when we MsanThread::Init
signal handler may trigger false reports.
I failed to reproduce this locally for a test.

Differential Revision: https://reviews.llvm.org/D113328
2021-11-09 18:23:55 -08:00
Vitaly Buka a5b06ad39a Partially revert "[NFC][msan] Split ThreadStart and Init"
I don't know if removing "if (!start_routine_)" from ThreadStart
is NFC.

This reverts commit b3267bb3af.
2021-11-08 19:16:55 -08:00
Vitaly Buka b3267bb3af [NFC][msan] Split ThreadStart and Init 2021-11-08 18:58:33 -08:00
Martin Liska 13a442ca49 Enable -Wformat-pedantic and fix fallout.
Differential Revision: https://reviews.llvm.org/D113172
2021-11-05 13:12:35 +01:00
David Carlier b4fb42300e [sanitizer] msan build fix on non linux platforms 2021-11-01 07:18:43 +00:00
Nikita Malyavin 4e1a6c0705 [msan] Add stat-family interceptors on Linux
Add following interceptors on Linux: stat, lstat, fstat, fstatat.

This fixes use-of-uninitialized value on platforms with GLIBC 2.33+.
In particular: Arch Linux, Ubuntu hirsute/impish.

The tests should have also been failing during the release on the mentioned platforms, but I cannot find any related discussion.

Most likely, the regression was introduced by glibc commit [[ 8ed005daf0 | 8ed005daf0ab03e14250032 ]]:
all stat-family functions are now exported as shared functions.

Before, some of them (namely stat, lstat, fstat, fstatat) were provided as a part of libc_noshared.a and called their __xstat dopplegangers. This is still true for Debian Sid and earlier Ubuntu's. stat interceptors may be safely provided for them, no problem with that.

Closes https://github.com/google/sanitizers/issues/1452.
See also https://jira.mariadb.org/browse/MDEV-24841

Reviewed By: eugenis

Differential Revision: https://reviews.llvm.org/D111984
2021-10-20 17:14:43 -07:00
Vitaly Buka ef85ea9a4f [msan] Print both shadow and user address
before:
00 00 00 00 ff ff ff ff 00 00 00 00 00 00 00 00
Shadow map of [0x211000000005, 0x21100000012e), 297 bytes:
now:
0x2f60d213ac10[0x7f60d213ac10]  00 00 00 00 ff ff ff ff 00 00 00 00 00 00 00 00
Shadow map [0x211000000005, 0x21100000012e) of [0x711000000005, 0x711000000135), 297 bytes:

Differential Revision: https://reviews.llvm.org/D111261
2021-10-07 17:56:46 -07:00
Amy Kwan 83539d73f9 Fix msan/tests/msan_test.cpp due to -Wbitwise-instead-of-logical
The LE Power sanitizer bot fails when testing standalone compiler-rt due to
an MSAN test warning introduced by -Wbitwise-instead-of-logical. As this option
along with -Werror is enabled on the bot, the test failure occurs.
This patch updates msan_test.cpp to fix the warning introduced by the
-Wbitwise-instead-of-logical.
2021-10-04 12:58:12 -05:00
Vitaly Buka 7c1128f3bb [NFC][sanitizer] Return StackDepotStats by value
Differential Revision: https://reviews.llvm.org/D110644
2021-09-28 15:42:21 -07:00
Kazuaki Ishizaki a1e7e401d2 [compiler-rt] NFC: Fix trivial typo
Reviewed By: xgupta

Differential Revision: https://reviews.llvm.org/D77457
2021-09-04 14:12:58 +05:30
Vitaly Buka c92631a59a [sanitizer] Fix VReport of symbol version
Version is already a string and does not need stringizing.
2021-08-25 14:32:15 -07:00
Vitaly Buka 2d743af4e9 [msan] Unpoison trailing nullptr in wordexp interceptor
Differential Revision: https://reviews.llvm.org/D108665
2021-08-24 17:19:11 -07:00
Vitaly Buka 4c699b1cd0 [msan] Don't EXPECT_POISONED beyond the we_wordv
Partially reverts commit 629411d799.

EXPECT_POISONED argument is outside of the allocation so we can't
assume the state of shadow there.
2021-08-24 17:19:10 -07:00
Vitaly Buka 629411d799 [msan] Fix wordexp after D108646
I introduced this bug reformating the patch before commit.
2021-08-24 16:36:28 -07:00
Justin Cady d568e5325c [MSAN] Fix wordexp interception when WRDE_DOOFFS is used
Handle the case of wordexp being invoked with WRDE_DOOFFS and
we.we_offs set to a positive value, which will result in NULL
entries prepended to the result. With this change the entire
result, containing both NULL and actual entries, is unpoisoned.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D108646
2021-08-24 14:30:09 -07:00
Michael Jones 40067b88c0 [compiler-rt] change internal internal libc invariants
llvm-libc is expected to be built with sanitizers and not use interceptors in
the long run. For now though, we have a hybrid process, where functions
implemented in llvm-libc are instrumented, and glibc fills and sanitizer
interceptors fill in the rest.

Current sanitizers have an invariant that the REAL(...) function called from
inside of an interceptor is uninstrumented. A lot of interceptors call strlen()
in order to figure out the size of the region to check/poison. Switch these
callsites over to the internal, unsanitized implementation.

Reviewed By: hctim, vitalybuka

Differential Revision: https://reviews.llvm.org/D108316
2021-08-24 16:41:15 +00:00
Vitaly Buka db0af393f9 [msan] Fix ppc64 format warning 2021-08-14 18:43:24 -07:00
Dmitry Vyukov d26d5a0a3d msan: clean up and enable format string checking
Depends on D107981.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D107982
2021-08-13 13:45:02 +02:00
Dmitry Vyukov 123c58ea26 sanitizer_common: enable format string checking
Enable -Wformat in sanitizer_common now that it's
cleaned up from existing warnings.
But disable it in all sanitizers for now since
they are not cleaned up yet, but inherit sanitizer_common CFLAGS.

Depends on D107980.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D107981
2021-08-13 13:44:52 +02:00
Vitaly Buka c2a3fb303f [msan] Don't track origns in signal handlers
Origin::CreateHeapOrigin is not async-signal-safe and can deadlock.

Differential Revision: https://reviews.llvm.org/D107431
2021-08-05 13:53:20 -07:00
Vitaly Buka 44c83eccf9 [sanitizer] Remove cpplint annotations
cpplint was removed by D107197

Differential Revision: https://reviews.llvm.org/D107198
2021-07-30 18:20:40 -07:00
Dmitry Vyukov 4e15ee2867 sanitizer_common: remove BlockingMutex and RWMutex
Remove the legacy typedefs and use Mutex/Lock types directly.

Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D107043
2021-07-29 12:38:53 +02:00
Dmitry Vyukov 440e936c47 Revert "sanitizers: increase .clang-format columns to 100"
This reverts commit 5d1df6d220.

There is a strong objection to this change:
https://reviews.llvm.org/D106436#2905618

Reviewed By: dblaikie

Differential Revision: https://reviews.llvm.org/D106847
2021-07-28 09:40:21 +02:00
Shu-Chun Weng 4fa989c7b2 Fix TSAN signal interceptor out-of-bound access
signal(2) and sigaction(2) have defined behaviors for invalid signal number
(EINVAL) and some programs rely on it.

The added test case also reveals that MSAN is too strict in this regard.

Test case passed on x86_64 Linux and AArch64 Linux.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D106468
2021-07-22 12:38:07 -07:00
Dmitry Vyukov 5d1df6d220 sanitizers: increase .clang-format columns to 100
The current (default) line length is 80 columns.
That's based on old hardware and historical conventions.
There are no existent reasons to keep line length that small,
especially provided that our coding style uses quite lengthy
identifiers. The Linux kernel recently switched to 100,
let's start with 100 as well.

This change intentionally does not re-format code.
Re-formatting is intended to happen incrementally,
or on dir-by-dir basis separately.

Reviewed By: vitalybuka, melver, MaskRay

Differential Revision: https://reviews.llvm.org/D106436
2021-07-22 11:15:02 +02:00
Vitaly Buka 60c0256ef1 [NFC][msan] Fix assigned-unused warning 2021-06-02 00:09:02 -07:00
Vitaly Buka 2445838f74 Revert "[NFC][msan] Fix warning on sanitizer-ppc64le-linux bot"
This fix breaks the test.

This reverts commit 6a2807bc81.
2021-06-02 00:09:02 -07:00