-
Notifications
You must be signed in to change notification settings - Fork 11.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[libc] Fix msan/asan memcpy reentrancy
This is needed to prevent asan/msan instrumentation to redirect CopyBlock to `__asan_memcpy` (resp. `__msan_memcpy`). These functions would then differ operation to `memcpy` which leads to reentrancy issues. With this patch, `memcpy` is fully instrumented and covered by asan/msan. If this turns out to be too expensive, instrumentation can be selectively or fully disabled through the use of the `__attribute__((no_sanitize(address, memory)))` annotation. Differential Revision: https://reviews.llvm.org/D99598
- Loading branch information
Showing
5 changed files
with
67 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ add_header_library( | |
common | ||
HDRS | ||
common.h | ||
sanitizer_annotations.h | ||
sanitizer.h | ||
) | ||
|
||
add_header_library( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
//===-- Convenient sanitizer macros ---------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_LIBC_SRC_SUPPORT_SANITIZER_H | ||
#define LLVM_LIBC_SRC_SUPPORT_SANITIZER_H | ||
|
||
#ifdef __has_feature | ||
#define LLVM_LIBC_HAVE_FEATURE(f) __has_feature(f) | ||
#else | ||
#define LLVM_LIBC_HAVE_FEATURE(f) 0 | ||
#endif | ||
|
||
// MemorySanitizer (MSan) is a detector of uninitialized reads. It consists of | ||
// a compiler instrumentation module and a run-time library. | ||
#ifdef LLVM_LIBC_HAVE_MEMORY_SANITIZER | ||
#error "LLVM_LIBC_HAVE_MEMORY_SANITIZER cannot be directly set." | ||
#elif defined(MEMORY_SANITIZER) | ||
// The MEMORY_SANITIZER macro is deprecated but we will continue to honor it | ||
// for now. | ||
#define LLVM_LIBC_HAVE_MEMORY_SANITIZER 1 | ||
#elif defined(__SANITIZE_MEMORY__) | ||
#define LLVM_LIBC_HAVE_MEMORY_SANITIZER 1 | ||
#elif !defined(__native_client__) && LLVM_LIBC_HAVE_FEATURE(memory_sanitizer) | ||
#define LLVM_LIBC_HAVE_MEMORY_SANITIZER 1 | ||
#endif | ||
|
||
// AddressSanitizer (ASan) is a fast memory error detector. | ||
#ifdef LLVM_LIBC_HAVE_ADDRESS_SANITIZER | ||
#error "LLVM_LIBC_HAVE_ADDRESS_SANITIZER cannot be directly set." | ||
#elif defined(ADDRESS_SANITIZER) | ||
// The ADDRESS_SANITIZER macro is deprecated but we will continue to honor it | ||
// for now. | ||
#define LLVM_LIBC_HAVE_ADDRESS_SANITIZER 1 | ||
#elif defined(__SANITIZE_ADDRESS__) | ||
#define LLVM_LIBC_HAVE_ADDRESS_SANITIZER 1 | ||
#elif LLVM_LIBC_HAVE_FEATURE(address_sanitizer) | ||
#define LLVM_LIBC_HAVE_ADDRESS_SANITIZER 1 | ||
#endif | ||
|
||
#if LLVM_LIBC_HAVE_MEMORY_SANITIZER | ||
#include <sanitizer/msan_interface.h> | ||
#define SANITIZER_MEMORY_INITIALIZED(addr, size) __msan_unpoison(addr, size) | ||
#else | ||
#define SANITIZER_MEMORY_INITIALIZED(ptr, size) | ||
#endif | ||
|
||
#endif // LLVM_LIBC_SRC_SUPPORT_SANITIZER_H |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters