closes bpo-35204: Disable thread and memory sanitizers for address_in_range(). (GH-10442)

This function may access memory which is mapped but is considered
free by libc allocator. It behaves so by design, therefore we
need to suppress sanitizer reports.

GCC doesn't support MSan, so disable only TSan for it.
This commit is contained in:
Alexey Izbyshev 2018-11-12 02:14:51 +03:00 committed by Benjamin Peterson
parent f9ec1b9f52
commit fd3a91cbf9

View File

@ -30,19 +30,36 @@ static void _PyMem_DebugCheckAddress(char api_id, const void *p);
static void _PyMem_SetupDebugHooksDomain(PyMemAllocatorDomain domain); static void _PyMem_SetupDebugHooksDomain(PyMemAllocatorDomain domain);
#if defined(__has_feature) /* Clang */ #if defined(__has_feature) /* Clang */
#if __has_feature(address_sanitizer) /* is ASAN enabled? */ # if __has_feature(address_sanitizer) /* is ASAN enabled? */
#define ATTRIBUTE_NO_ADDRESS_SAFETY_ANALYSIS \ # define _Py_NO_ADDRESS_SAFETY_ANALYSIS \
__attribute__((no_address_safety_analysis)) __attribute__((no_address_safety_analysis))
#else # endif
#define ATTRIBUTE_NO_ADDRESS_SAFETY_ANALYSIS # if __has_feature(thread_sanitizer) /* is TSAN enabled? */
#endif # define _Py_NO_SANITIZE_THREAD __attribute__((no_sanitize_thread))
#else # endif
#if defined(__SANITIZE_ADDRESS__) /* GCC 4.8.x, is ASAN enabled? */ # if __has_feature(memory_sanitizer) /* is MSAN enabled? */
#define ATTRIBUTE_NO_ADDRESS_SAFETY_ANALYSIS \ # define _Py_NO_SANITIZE_MEMORY __attribute__((no_sanitize_memory))
# endif
#elif defined(__GNUC__)
# if defined(__SANITIZE_ADDRESS__) /* GCC 4.8+, is ASAN enabled? */
# define _Py_NO_ADDRESS_SAFETY_ANALYSIS \
__attribute__((no_address_safety_analysis)) __attribute__((no_address_safety_analysis))
#else # endif
#define ATTRIBUTE_NO_ADDRESS_SAFETY_ANALYSIS // TSAN is supported since GCC 4.8, but __SANITIZE_THREAD__ macro
#endif // is provided only since GCC 7.
# if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
# define _Py_NO_SANITIZE_THREAD __attribute__((no_sanitize_thread))
# endif
#endif
#ifndef _Py_NO_ADDRESS_SAFETY_ANALYSIS
# define _Py_NO_ADDRESS_SAFETY_ANALYSIS
#endif
#ifndef _Py_NO_SANITIZE_THREAD
# define _Py_NO_SANITIZE_THREAD
#endif
#ifndef _Py_NO_SANITIZE_MEMORY
# define _Py_NO_SANITIZE_MEMORY
#endif #endif
#ifdef WITH_PYMALLOC #ifdef WITH_PYMALLOC
@ -1301,7 +1318,9 @@ obmalloc controls. Since this test is needed at every entry point, it's
extremely desirable that it be this fast. extremely desirable that it be this fast.
*/ */
static bool ATTRIBUTE_NO_ADDRESS_SAFETY_ANALYSIS static bool _Py_NO_ADDRESS_SAFETY_ANALYSIS
_Py_NO_SANITIZE_THREAD
_Py_NO_SANITIZE_MEMORY
address_in_range(void *p, poolp pool) address_in_range(void *p, poolp pool)
{ {
// Since address_in_range may be reading from memory which was not allocated // Since address_in_range may be reading from memory which was not allocated