From d01d6ed6dd82d536268b00bd8fdbafa3791c3f04 Mon Sep 17 00:00:00 2001 From: Andrey Kazmin Date: Thu, 14 May 2020 16:57:25 +0300 Subject: [Tizen] Enable ASan annotation of passing to native code buffers Turn on ASan inteceptors while marshaling managed buffers to native code. We could not properly annotate already allocated on heap buffers, so we have to disable pinning of such objects. Current patch affects only pinning of native arrays. --- src/pal/src/memory/local.cpp | 47 ++++++++++++++++++++++++++++++++++++++++++-- src/vm/ilmarshalers.cpp | 3 ++- 2 files changed, 47 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/pal/src/memory/local.cpp b/src/pal/src/memory/local.cpp index 3a0f40f8c4..44d9feb0c5 100644 --- a/src/pal/src/memory/local.cpp +++ b/src/pal/src/memory/local.cpp @@ -26,6 +26,14 @@ Revision History: SET_DEFAULT_DEBUG_CHANNEL(MEM); +#ifdef TIZEN_ASAN_ENVIRONMENT +extern "C" { +extern void __sanitizer_disable_interceptors() __attribute__ ((weak)); +extern void __sanitizer_enable_interceptors() __attribute__ ((weak)); +extern bool __sanitizer_interceptors_are_enabled() __attribute__ ((weak)); +} +#endif + static int AllocFlagsToHeapAllocFlags (IN UINT AllocFlags, @@ -70,7 +78,24 @@ LocalAlloc( goto done; } - lpRetVal = HeapAlloc( GetProcessHeap(), uFlags, uBytes ); +#ifdef TIZEN_ASAN_ENVIRONMENT + if (__sanitizer_interceptors_are_enabled != NULL) + { + bool san_enabled; + san_enabled = __sanitizer_interceptors_are_enabled(); + if (!san_enabled) { + __sanitizer_enable_interceptors(); + } + lpRetVal = HeapAlloc( GetProcessHeap(), uFlags, uBytes ); + if (!san_enabled) { + __sanitizer_disable_interceptors(); + } + } + else +#endif + { + lpRetVal = HeapAlloc( GetProcessHeap(), uFlags, uBytes ); + } done: LOGEXIT( "LocalAlloc returning %p.\n", lpRetVal ); @@ -128,7 +153,25 @@ LocalFree( if ( hMem ) { - bRetVal = HeapFree( GetProcessHeap(), 0, hMem ); +#ifdef TIZEN_ASAN_ENVIRONMENT + if (__sanitizer_interceptors_are_enabled != NULL) + { + bool san_enabled; + san_enabled = __sanitizer_interceptors_are_enabled(); + if (!san_enabled) { + __sanitizer_enable_interceptors(); + } + bRetVal = HeapFree( GetProcessHeap(), 0, hMem ); + if (!san_enabled) { + __sanitizer_disable_interceptors(); + } + } + else +#endif + { + bRetVal = HeapFree( GetProcessHeap(), 0, hMem ); + } + } else { diff --git a/src/vm/ilmarshalers.cpp b/src/vm/ilmarshalers.cpp index a89aeaf2a1..9e7ee17484 100644 --- a/src/vm/ilmarshalers.cpp +++ b/src/vm/ilmarshalers.cpp @@ -3808,11 +3808,12 @@ void ILMngdMarshaler::EmitCallMngdMarshalerMethod(ILCodeStream* pslILEmit, Metho bool ILNativeArrayMarshaler::UsePinnedArraySpecialCase() { +#ifndef TIZEN_ASAN_ENVIRONMENT if (IsCLRToNative(m_dwMarshalFlags) && !IsByref(m_dwMarshalFlags) && (NULL != m_pargs->na.m_pArrayMT) && (NULL == OleVariant::GetMarshalerForVarType(m_pargs->na.m_vt, TRUE))) { return true; } - +#endif return false; } -- cgit v1.2.3