Skip to content

Commit 1ec5781

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 7d7ff67 commit 1ec5781

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
@@ -29,19 +29,36 @@ static void _PyMem_DebugCheckAddress(char api_id, const void *p);
2929
static void _PyMem_SetupDebugHooksDomain(PyMemAllocatorDomain domain);
3030

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

4764
#ifdef WITH_PYMALLOC
@@ -1327,7 +1344,9 @@ obmalloc controls. Since this test is needed at every entry point, it's
13271344
extremely desirable that it be this fast.
13281345
*/
13291346

1330-
static bool ATTRIBUTE_NO_ADDRESS_SAFETY_ANALYSIS
1347+
static bool _Py_NO_ADDRESS_SAFETY_ANALYSIS
1348+
_Py_NO_SANITIZE_THREAD
1349+
_Py_NO_SANITIZE_MEMORY
13311350
address_in_range(void *p, poolp pool)
13321351
{
13331352
// Since address_in_range may be reading from memory which was not allocated

0 commit comments

Comments
 (0)