Commit Graph

552 Commits

Author SHA1 Message Date
David Carlier a4c97e1937 [Sanitizers] prctl interception update for the PR_SET_VMA option case.
Supports on Android but also from Linux 5.17

Reviewers: vitalybuka, eugenis

Reviewed-By: vitalybuka

Differential Revision: https://reviews.llvm.org/D127326
2022-06-09 06:07:26 +01:00
David CARLIER c06ef17359 [Sanitizers] intercept FreeBSD procctl
Reviewers: vitalybuka, emaster

Reviewed-By: viatelybuka

Differential Revision: https://reviews.llvm.org/D127069
2022-06-08 08:55:10 +01:00
Kevin Athey 828c94c0f6 [MSAN] Add interceptor for pthread_getaffinity_np.
Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D127185
2022-06-07 16:27:44 -07:00
Kevin Athey 1a729bce86 [MSAN] add dn_expand intercept.
This interceptor only addresses writes to inputs.  Reads of inputs are not checked.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D126851
2022-06-03 09:49:42 -07:00
Pierre Gousseau 4278b7e16a [sanitizers] Fixes strndup API behaviour when intercepted by sanitizers
Sanitizers ignore flag allocator_may_return_null=1 in strndup() calls.
When OOM is emulated, this causes to the unexpected crash.

Committed by pgousseau on behalf of "Kostyantyn Melnik, kmnls.kmnls@gmail.com"

Reviewed by: pgousseau

Differential Revision: https://reviews.llvm.org/D126452
2022-05-30 17:00:10 +01:00
Mariusz Borsa 8246b2e156 [Sanitizers][Darwin] Replace SANITIZER_MAC with SANITIZER_APPLE in source files
This is a follow up to [Sanitizers][Darwin] Rename Apple macro SANITIZER_MAC -> SANITIZER_APPLE (D125816)

Performed a global search/replace as in title against LLVM sources

Differential Revision: https://reviews.llvm.org/D126263
2022-05-24 12:59:27 -07:00
Kevin Athey e9c8d0ff71 [MSAN] add __b64_pton and __b64_ntop intercepts
Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D122849
2022-04-08 15:22:37 -07:00
Kevin Athey 0713053e4a [MSAN] extend prctl interceptor to support PR_SCHED_CORE
Reviewed By: eugenis

Differential Revision: https://reviews.llvm.org/D122851
2022-04-07 16:49:25 -07:00
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
Tavian Barnes 9a42715ae8 [sanitizer] Always initialize the regex in the regcomp() interceptor
When regcomp() fails, the same regex_t* should be passed to regerror()
for potentially better error messages.  But doing that with msan would
report a use-of-uninitialized-value.

Fixes https://github.com/google/sanitizers/issues/1496

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D120591
2022-03-15 14:30:57 -07: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
Colin Cross e75f1d3c07 [CompilerRT] Fix build of compiler-rt with musl
Use the correct types for OFF_T, __sanitizer_time_t and
__sanitizer_dirent and forward time_t related functions
 to fix using compiler-rt with 32-bit musl libc.

Also redirect the time_t functions that are affected by
https://musl.libc.org/time64.html to use their 64-bit
ABI names.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D119358
2022-03-09 13:41:30 -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
Vitaly Buka 6396a44361 Revert "SIGSEGV in Sanitizer INTERCEPTOR of strstr function."
Breaks Asan on Fuchsia's and ubsan with gcc.

This reverts commit 685c94c6cb.
2022-01-05 21:28:01 -08:00
Bharadwaj, Ritanya B 685c94c6cb SIGSEGV in Sanitizer INTERCEPTOR of strstr function.
This is a segmentation fault in INTERCEPTOR function on a special edge
case of strstr libc call. When 'Haystack'(main string to be examined) is
NULL and 'needle'(sub-string to be searched in 'Haystack') is an empty
string then it hits a SEGV while using sanitizers and as a 'string not
found' case otherwise.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D115919
2022-01-05 00:11:59 -08:00
Azat Khuzhin 856550ca79 [Sanitizer] Fix setbuffer() interceptor (it accept size, not mode)
Fixes: 0c81a62d9d ("[Sanitizer] Adding setvbuf in supported platforms and other stream buffer functions")

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D116176
2021-12-22 22:13:36 -08:00
Dmitry Vyukov 97b4e63117 tsan: fix false positives in dynamic libs with static tls
The added test demonstrates  loading a dynamic library with static TLS.
Such static TLS is a hack that allows a dynamic library to have faster TLS,
but it can be loaded only iff all threads happened to allocate some excess
of static TLS space for whatever reason. If it's not the case loading fails with:

dlopen: cannot load any more object with static TLS

We used to produce a false positive because dlopen will write into TLS
of all existing threads to initialize/zero TLS region for the loaded library.
And this appears to be racing with initialization of TLS in the thread
since we model a write into the whole static TLS region (we don't what part
of it is currently unused):

WARNING: ThreadSanitizer: data race (pid=2317365)
  Write of size 1 at 0x7f1fa9bfcdd7 by main thread:
    0 memset
    1 init_one_static_tls
    2 __pthread_init_static_tls
    [[ this is where main calls dlopen ]]
    3 main
  Previous write of size 8 at 0x7f1fa9bfcdd0 by thread T1:
    0 __tsan_tls_initialization

Fix this by ignoring accesses during dlopen.

Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D114953
2021-12-02 17:47:05 +01:00
Tamir Duberstein f639882be8 [sanitizer] Allow getsockname with NULL addrlen
This is already permitted in getpeername, and returns EFAULT
on Linux (does not crash the program).

Fixes https://github.com/google/sanitizers/issues/1451.

Differential Revision: https://reviews.llvm.org/D113055
2021-11-03 10:23:01 -07:00
Tamir Duberstein 33d9b7b4b2 [sanitizer] Mark before deref in PosixSpawnImpl
Read each pointer in the argv and envp arrays before dereferencing
it; this correctly marks an error when these pointers point into
memory that has been freed.

Differential Revision: https://reviews.llvm.org/D113046
2021-11-03 10:18:06 -07:00
David Carlier 56513e3e42 [sanitizers] remove extra comma for sha2 interceptors 2021-11-02 10:35:44 +00:00
Vitaly Buka 9213202abd [sanitizer] Fix PosixSpawnImpl which fails exitcode test 2021-11-01 21:03:02 -07:00
Vitaly Buka e1240745ef [sanitizer] Add posix_spawn interceptor
To make pid initialized for Msan.

Reviewed By: eugenis

Differential Revision: https://reviews.llvm.org/D112784
2021-10-31 12:10:54 -07:00
David CARLIER bb168f3207 [compiler-rt] update detect_write_exec option for apple devices.
Reviewed By: yln, vitalybuka

Differential Revision: https://reviews.llvm.org/D111390
2021-10-28 17:08:23 +01:00
David Carlier 3675e147a1 [Sanitizers] intercept ttyent api on FreeBSD.
and ttyentpath separately on NetBSD.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D109843
2021-09-24 04:26:05 +01:00
David Carlier 6f9a96e9cd [Sanitizers] intercept clock_getcpuclockid on FreeBSD, and pthread_getcpuclockid.
Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D108884
2021-09-02 22:35:04 +01:00
Michael Jones 4dde7064e7 [compiler-rt][obvious] fix typo, delete paren
I should've deleted a parenthesis on line 4222 in
https://reviews.llvm.org/D108843 and this patch fixes it.

Differential Revision: https://reviews.llvm.org/D108852
2021-08-27 22:55:39 +00:00
Michael Jones 012b664b2e [compiler-rt] fix real strlens that were missed
In reviews.llvm.org/D108316 I missed a few instances of REAL(strlen) and
this change fixes that, as well as restoring one that seems like it
shouldn't have been changed.

Reviewed By: hctim, vitalybuka

Differential Revision: https://reviews.llvm.org/D108843
2021-08-27 22:33:28 +00:00
Vitaly Buka f1bb30a495 [sanitizer] No THREADLOCAL in qsort and bsearch
qsort can reuse qsort_r if available.
bsearch always passes key as the first comparator argument, so we
can use it to wrap the original comparator.

Differential Revision: https://reviews.llvm.org/D108751
2021-08-26 16:55:06 -07:00
Vitaly Buka 39100c82d3 [NFC][sanitizer] Swap qsort_r and qsort code
To simplify future review.
2021-08-26 10:24:59 -07:00
Vitaly Buka 5213f307ab Revert "Problem with realpath interceptor"
Breaks realpath(, nullptr) for all sanitizers.

Somehow INTERCEPT_FUNCTION and INTERCEPT_FUNCTION_VER return
false even if everything seemingly right.

And this is the issue for COMMON_INTERCEPT_FUNCTION_GLIBC_VER_MIN.
There is a check in every sanitlizer:
if (!INTERCEPT_FUNCTION_VER(name, ver) && !INTERCEPT_FUNCTION(name))

For non-versioned interceptors when INTERCEPT_FUNCTION returns false
it's not considered fatal, and it just prints a warning.

However INTERCEPT_FUNCTION_VER in this case will fallback to
INTERCEPT_FUNCTION replacing realpath with wrong version.

We need to investigate that before relanding the patch.

This reverts commit faef0d042f.
2021-08-25 13:55:23 -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 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
Dmitry Vyukov 4a91bbcc93 sanitizer_common: fix format strings
Fix existing -Wformat warnings.

Depends on D107979.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D107980
2021-08-13 13:44:41 +02:00
Dmitry Vyukov faef0d042f Problem with realpath interceptor
tsan in some cases (e.g. after fork from multithreaded program, which arguably is problematic) increments ignore_interceptors and in that case runs just the intercepted functions and not their wrappers.
For realpath the interceptor handles the resolved_path == nullptr case though and so when ignore_interceptors is non-zero, realpath (".", nullptr) will fail instead of succeeding.
This patch uses instead the COMMON_INTERCEPT_FUNCTION_GLIBC_VER_MIN macro to use realpath@@GLIBC_2.3 whenever possible (if not, then it is likely a glibc architecture
with more recent oldest symbol version than 2.3, for which any realpath in glibc will DTRT, or unsupported glibc older than 2.3), which never supported NULL as second argument.

Reviewed By: dvyukov

Differential Revision: https://reviews.llvm.org/D107819
2021-08-10 16:29:42 +02:00
Vitaly Buka f33d51d592 [sanitizer] Intercept sem_open/sem_unlink
Without interceptor implementation may call strlen on internal
buffers causing false msan errors.

Differential Revision: https://reviews.llvm.org/D107615
2021-08-10 01:11:16 -07:00
Florian Mayer 9b74924b6c Revert "[sanitizer] Intercept sem_open/sem_unlink"
This reverts commit 69a909b9fe.
2021-08-09 19:50:31 +01:00
Vitaly Buka 69a909b9fe [sanitizer] Intercept sem_open/sem_unlink
Without interceptor implementation may call strlen on internal
buffers causing false msan errors.

Differential Revision: https://reviews.llvm.org/D107615
2021-08-09 10:57:23 -07:00
Vitaly Buka 7138f1cd13 [NFC][sanitizer] clang-format sem related block 2021-08-05 19:51:19 -07:00
Vitaly Buka 9ab590e3eb [msan] Add bsearch interceptor
Similar to qsort, bsearch can be called from non-instrumented
code of glibc. When it happends tls for arguments can be in uninitialized
state.

Unlike to qsort, bsearch does not move data, so we don't need to
check or initialize searched memory or key. Intrumented comparator will
do that on it's own.

Differential Revision: https://reviews.llvm.org/D107387
2021-08-03 18:39:14 -07:00
Vitaly Buka 735da5f5ad [NFC][sanitizer] Add static to internal functions 2021-08-03 00:12:36 -07:00
David Carlier 2d56e1394b [Sanitizer] Intercepts flopen/flopenat on FreeBSD.
Reviewers: vitalybuka

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D106218
2021-07-19 19:46:35 +01:00
Emily Shi cfa4d112da [compiler-rt] change write order of frexpl & frexpf so it doesn't corrupt stack ids
This was fixed in the past for `frexp`, but was not made for `frexpl` & `frexpf` https://github.com/google/sanitizers/issues/321
This patch copies the fix over to `frexpl` because it caused `frexp_interceptor.cpp` test to fail on iPhone and `frexpf` for consistency.

rdar://79652161

Reviewed By: delcypher, vitalybuka

Differential Revision: https://reviews.llvm.org/D104948
2021-07-16 10:58:12 -07:00
Ilya Leoshkevich bd77f742d6 [TSan] Intercept __tls_get_addr_internal and __tls_get_offset on SystemZ
Reuse the assembly glue code from sanitizer_common_interceptors.inc and
the handling logic from the __tls_get_addr interceptor.

Reviewed By: dvyukov

Differential Revision: https://reviews.llvm.org/D105629
2021-07-15 12:18:48 +02:00
Dmitry Vyukov b3bd885017 sanitizer_common: allow COMMON_INTERCEPTOR_ENTER to use labels
The memcpy interceptor is the only one that uses COMMON_INTERCEPTOR_ENTER
more than once in a single function. This does not allow COMMON_INTERCEPTOR_ENTER
to use labels, because they are global for the whole function (not block scoped).
Don't include COMMON_INTERCEPTOR_ENTER code twice.

Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D105774
2021-07-12 15:54:37 +02:00
Dmitry Vyukov 8bbf2f7a44 sanitizer_common: make sem_trywait as non-blocking
sem_trywait never blocks.
Use REAL instead of COMMON_INTERCEPTOR_BLOCK_REAL.

Reviewed By: melver

Differential Revision: https://reviews.llvm.org/D105775
2021-07-12 13:10:04 +02:00
Dmitry Vyukov c1eaa1168a tsan: mark sigwait as blocking
Add a test case reported in:
https://github.com/google/sanitizers/issues/1401
and fix it.
The code assumes sigwait will process other signals.

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D102057
2021-05-19 13:03:20 +02:00