Skip to content

Commit eff1c98

Browse files
miss-islingtonAlexey Izbyshev
andauthored
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 fd3a91c) Co-authored-by: Alexey Izbyshev <izbyshev@ispras.ru>
1 parent 3f6a0a2 commit eff1c98

File tree

1 file changed

+31
-12
lines changed

1 file changed

+31
-12
lines changed

Objects/obmalloc.c

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,36 @@ static void _PyObject_DebugDumpAddress(const void *p);
2727
static void _PyMem_DebugCheckAddress(char api_id, const void *p);
2828

2929
#if defined(__has_feature) /* Clang */
30-
#if __has_feature(address_sanitizer) /* is ASAN enabled? */
31-
#define ATTRIBUTE_NO_ADDRESS_SAFETY_ANALYSIS \
30+
# if __has_feature(address_sanitizer) /* is ASAN enabled? */
31+
# define _Py_NO_ADDRESS_SAFETY_ANALYSIS \
3232
__attribute__((no_address_safety_analysis))
33-
#else
34-
#define ATTRIBUTE_NO_ADDRESS_SAFETY_ANALYSIS
35-
#endif
36-
#else
37-
#if defined(__SANITIZE_ADDRESS__) /* GCC 4.8.x, is ASAN enabled? */
38-
#define ATTRIBUTE_NO_ADDRESS_SAFETY_ANALYSIS \
33+
# endif
34+
# if __has_feature(thread_sanitizer) /* is TSAN enabled? */
35+
# define _Py_NO_SANITIZE_THREAD __attribute__((no_sanitize_thread))
36+
# endif
37+
# if __has_feature(memory_sanitizer) /* is MSAN enabled? */
38+
# define _Py_NO_SANITIZE_MEMORY __attribute__((no_sanitize_memory))
39+
# endif
40+
#elif defined(__GNUC__)
41+
# if defined(__SANITIZE_ADDRESS__) /* GCC 4.8+, is ASAN enabled? */
42+
# define _Py_NO_ADDRESS_SAFETY_ANALYSIS \
3943
__attribute__((no_address_safety_analysis))
40-
#else
41-
#define ATTRIBUTE_NO_ADDRESS_SAFETY_ANALYSIS
42-
#endif
44+
# endif
45+
// TSAN is supported since GCC 4.8, but __SANITIZE_THREAD__ macro
46+
// is provided only since GCC 7.
47+
# if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
48+
# define _Py_NO_SANITIZE_THREAD __attribute__((no_sanitize_thread))
49+
# endif
50+
#endif
51+
52+
#ifndef _Py_NO_ADDRESS_SAFETY_ANALYSIS
53+
# define _Py_NO_ADDRESS_SAFETY_ANALYSIS
54+
#endif
55+
#ifndef _Py_NO_SANITIZE_THREAD
56+
# define _Py_NO_SANITIZE_THREAD
57+
#endif
58+
#ifndef _Py_NO_SANITIZE_MEMORY
59+
# define _Py_NO_SANITIZE_MEMORY
4360
#endif
4461

4562
#ifdef WITH_PYMALLOC
@@ -1188,7 +1205,9 @@ obmalloc controls. Since this test is needed at every entry point, it's
11881205
extremely desirable that it be this fast.
11891206
*/
11901207

1191-
static bool ATTRIBUTE_NO_ADDRESS_SAFETY_ANALYSIS
1208+
static bool _Py_NO_ADDRESS_SAFETY_ANALYSIS
1209+
_Py_NO_SANITIZE_THREAD
1210+
_Py_NO_SANITIZE_MEMORY
11921211
address_in_range(void *p, poolp pool)
11931212
{
11941213
// Since address_in_range may be reading from memory which was not allocated

0 commit comments

Comments
 (0)