summaryrefslogtreecommitdiff
path: root/Objects
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2018-11-11 15:44:34 -0800
committerGitHub <noreply@github.com>2018-11-11 15:44:34 -0800
commit1ec5781a097f4d4d988e0dd7f51ee203dc639df2 (patch)
tree49cdd3fbb34cb872e51d9af3dc64b746f23234d4 /Objects
parent7d7ff672dfe93a50053166798cdc0fbc86ea63e3 (diff)
downloadcpython-git-1ec5781a097f4d4d988e0dd7f51ee203dc639df2.tar.gz
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. (cherry picked from commit fd3a91cbf93dd7bd97f01add9c90075d63cd7316) Co-authored-by: Alexey Izbyshev <izbyshev@ispras.ru>
Diffstat (limited to 'Objects')
-rw-r--r--Objects/obmalloc.c43
1 files changed, 31 insertions, 12 deletions
diff --git a/Objects/obmalloc.c b/Objects/obmalloc.c
index 0e485d6211..1b8b5eefe2 100644
--- a/Objects/obmalloc.c
+++ b/Objects/obmalloc.c
@@ -29,19 +29,36 @@ static void _PyMem_DebugCheckAddress(char api_id, const void *p);
static void _PyMem_SetupDebugHooksDomain(PyMemAllocatorDomain domain);
#if defined(__has_feature) /* Clang */
- #if __has_feature(address_sanitizer) /* is ASAN enabled? */
- #define ATTRIBUTE_NO_ADDRESS_SAFETY_ANALYSIS \
+# if __has_feature(address_sanitizer) /* is ASAN enabled? */
+# define _Py_NO_ADDRESS_SAFETY_ANALYSIS \
__attribute__((no_address_safety_analysis))
- #else
- #define ATTRIBUTE_NO_ADDRESS_SAFETY_ANALYSIS
- #endif
-#else
- #if defined(__SANITIZE_ADDRESS__) /* GCC 4.8.x, is ASAN enabled? */
- #define ATTRIBUTE_NO_ADDRESS_SAFETY_ANALYSIS \
+# endif
+# if __has_feature(thread_sanitizer) /* is TSAN enabled? */
+# define _Py_NO_SANITIZE_THREAD __attribute__((no_sanitize_thread))
+# endif
+# if __has_feature(memory_sanitizer) /* is MSAN enabled? */
+# 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))
- #else
- #define ATTRIBUTE_NO_ADDRESS_SAFETY_ANALYSIS
- #endif
+# endif
+ // TSAN is supported since GCC 4.8, but __SANITIZE_THREAD__ macro
+ // 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
#ifdef WITH_PYMALLOC
@@ -1327,7 +1344,9 @@ obmalloc controls. Since this test is needed at every entry point, it's
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)
{
// Since address_in_range may be reading from memory which was not allocated