From: 이형주/MDE Lab(SR)/삼성전자 Date: Tue, 10 Sep 2024 05:39:04 +0000 (+0900) Subject: [Tizen] Revert `TIZEN_ASAN_ENVIRONMENT` (#612) X-Git-Tag: accepted/tizen/unified/20240910.162231^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fheads%2Faccepted%2Ftizen_unified;p=platform%2Fupstream%2Fdotnet%2Fruntime.git [Tizen] Revert `TIZEN_ASAN_ENVIRONMENT` (#612) * Revert "[Tizen] Enable Tizen ASan runtime support" This reverts commit 19d2d657d1746c13febe1567d36c733da1f15018. * Revert "[Tizen] Disable staticfilehost for ASan build" This reverts commit cebb4cff7e883b3409e1432734046626372a2c3c. * Revert "[Tizen] Enable ASan annotation of passing to native code buffers" This reverts commit 26d87cb755de0f518f9582c6e4b627992946433a. * Revert "[Tizen] Add missing copyright to tizen ASan related changes" This reverts commit 331980a310c3bd96f89737bd3946ad1fe7d4ec7c. * Revert "[Tizen] Implement ASan wrapper for Linux ARM32" This reverts commit 0c89701aeadfcaf0764d644edc418001af5647ca. * Revert "[Tizen] Implement ASan wrapper for Linux AMD64" This reverts commit 00bed73747a2ba408feb1f8565f5758fed5035f2. * Revert "[Tizen] Implement detecting of sanitized libraries" This reverts commit 94c3b5b1f5c8e1487b8e488d315eca1942810244. --- diff --git a/eng/native/configurecompiler.cmake b/eng/native/configurecompiler.cmake index c1fbbe2..2a234f0 100644 --- a/eng/native/configurecompiler.cmake +++ b/eng/native/configurecompiler.cmake @@ -111,17 +111,6 @@ elseif (CLR_CMAKE_HOST_UNIX) set(CLR_SANITIZE_CXX_OPTIONS "") set(CLR_SANITIZE_LINK_OPTIONS "") - if(DEFINED ENV{TIZEN_ASAN_ENVIRONMENT}) - if (CLR_CMAKE_TARGET_ARCH_ARM OR CLR_CMAKE_TARGET_ARCH_AMD64) - message(STATUS "TIZEN_ASAN_ENVIRONMENT is enabled.") - # add definitions to enable ASan support for only external libraries (supported only Tizen) - add_definitions(-DTIZEN_ASAN_ENVIRONMENT -DHAS_ADDRESS_SANITIZER) - set(TIZEN_ASAN_ENVIRONMENT 1) - else() - message(STATUS "TIZEN_ASAN_ENVIRONMENT cannot be enabled. Current arch is not supported.") - endif() - endif() - # set the CLANG sanitizer flags for debug build if(UPPERCASE_CMAKE_BUILD_TYPE STREQUAL DEBUG OR UPPERCASE_CMAKE_BUILD_TYPE STREQUAL CHECKED) # obtain settings from running enablesanitizers.sh diff --git a/packaging/coreclr.spec b/packaging/coreclr.spec index 699f9ff..b80e126 100755 --- a/packaging/coreclr.spec +++ b/packaging/coreclr.spec @@ -246,9 +246,7 @@ done export ASAN_OPTIONS=use_sigaltstack=false:`cat /ASAN_OPTIONS` /usr/bin/gcc-unforce-options export LD_LIBRARY_PATH=`pwd`/libicu-57.1 - -# enable ASan support for only external libs -export TIZEN_ASAN_ENVIRONMENT=1 +export CPPFLAGS+=" -DHAS_ADDRESS_SANITIZER " } BASE_FLAGS=" --target=%{_host} -gdwarf-4 " diff --git a/src/coreclr/CMakeLists.txt b/src/coreclr/CMakeLists.txt index ec64a93..12c5b0f 100644 --- a/src/coreclr/CMakeLists.txt +++ b/src/coreclr/CMakeLists.txt @@ -69,7 +69,7 @@ include(components.cmake) #--------------------------- # Build the single file host #--------------------------- -if(NOT CLR_CROSS_COMPONENTS_BUILD AND NOT TIZEN_ASAN_ENVIRONMENT) +if(NOT CLR_CROSS_COMPONENTS_BUILD) set(CLR_SINGLE_FILE_HOST_ONLY 1) add_subdirectory(${CLR_SRC_NATIVE_DIR}/corehost/apphost/static Corehost.Static) add_dependencies(runtime singlefilehost) diff --git a/src/coreclr/pal/inc/pal.h b/src/coreclr/pal/inc/pal.h index 06b5edf..ce317c2 100644 --- a/src/coreclr/pal/inc/pal.h +++ b/src/coreclr/pal/inc/pal.h @@ -2617,14 +2617,6 @@ PAL_GetProcAddressDirect( IN NATIVE_LIBRARY_HANDLE dl_handle, IN LPCSTR lpProcName); -#ifdef TIZEN_ASAN_ENVIRONMENT -PALIMPORT -BOOL -PALAPI -PAL_IsSanitizedLibraryDirect( - IN NATIVE_LIBRARY_HANDLE dl_handle); -#endif - /*++ Function: PAL_LOADLoadPEFile diff --git a/src/coreclr/pal/src/CMakeLists.txt b/src/coreclr/pal/src/CMakeLists.txt index 35ad49c..ba13ab3 100644 --- a/src/coreclr/pal/src/CMakeLists.txt +++ b/src/coreclr/pal/src/CMakeLists.txt @@ -221,12 +221,6 @@ set(SOURCES thread/threadsusp.cpp ) -if (TIZEN_ASAN_ENVIRONMENT) - list(APPEND SOURCES - loader/tizenasanenvmodule.cpp - ) -endif() - if(NOT CLR_CMAKE_USE_SYSTEM_LIBUNWIND) set(LIBUNWIND_OBJECTS $) endif(NOT CLR_CMAKE_USE_SYSTEM_LIBUNWIND) diff --git a/src/coreclr/pal/src/loader/module.cpp b/src/coreclr/pal/src/loader/module.cpp index fe2f4a7..c5196ed 100644 --- a/src/coreclr/pal/src/loader/module.cpp +++ b/src/coreclr/pal/src/loader/module.cpp @@ -55,10 +55,6 @@ SET_DEFAULT_DEBUG_CHANNEL(LOADER); // some headers have code with asserts, so do #include #endif -#ifdef TIZEN_ASAN_ENVIRONMENT -#include "tizenasanenvmodule.h" -#endif // TIZEN_ASAN_ENVIRONMENT - using namespace CorUnix; // In safemath.h, Template SafeInt uses macro _ASSERTE, which need to use variable @@ -793,25 +789,6 @@ PAL_GetProcAddressDirect( return address; } -#ifdef TIZEN_ASAN_ENVIRONMENT -/* -Function: - PAL_IsSanitizedLibraryDirect - - Check whether the native library is sanitized. - - Returns TRUE if the native library is sanitized; FALSE otherwise. -*/ -PALIMPORT -BOOL -PALAPI -PAL_IsSanitizedLibraryDirect( - IN NATIVE_LIBRARY_HANDLE dl_handle) -{ - return is_module_sanitized(dl_handle); -} -#endif // TIZEN_ASAN_ENVIRONMENT - /*++ Function: PAL_RegisterModule diff --git a/src/coreclr/pal/src/loader/tizenasanenvmodule.cpp b/src/coreclr/pal/src/loader/tizenasanenvmodule.cpp deleted file mode 100644 index 8a79afc..0000000 --- a/src/coreclr/pal/src/loader/tizenasanenvmodule.cpp +++ /dev/null @@ -1,163 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2019-2022 Samsung Electronics Co., Ltd. - * - * All rights reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include -#include "pal.h" -#include "llvm/ELF.h" -#include "tizenasanenvmodule.h" - -#if __LP64__ -using Addr = Elf64_Addr; -using Dyn = Elf64_Dyn; -using Sym = Elf64_Sym; -using Rel = Elf64_Rel; -using Rela = Elf64_Rela; -#else -using Addr = Elf32_Addr; -using Dyn = Elf32_Dyn; -using Sym = Elf32_Sym; -using Rel = Elf32_Rel; -using Rela = Elf32_Rela; -#endif - -/* - * Request arguments for dlinfo(). - */ -#define RTLD_DI_LINKMAP 2 /* Obtain link map. */ - -struct link_map { - Addr l_addr; /* Base Address of library */ - const char *l_name; /* Absolute Path to Library */ - Dyn *l_ld; /* Pointer to .dynamic in memory */ - struct link_map *l_next, *l_prev; /* linked list of of mapped libs */ -}; - -extern "C" int dlinfo(void *handle, int request, void *info); - -struct plt_sym_resolver { - Sym *dynsym; // .dynsym section - char *dynstr; // .dynstr section - long reltype; // relocation type - size_t pltrel_size; // size of .rel(a).plt section - void *jmprel; // .rel(a).plt section. Exact relocation - // type is resolved at runtime - - plt_sym_resolver() - : dynsym(nullptr), dynstr(nullptr), reltype(-1), pltrel_size(0), - jmprel(nullptr) - {} - - bool init(void *handle) - { - struct link_map *lmap; - - if (handle == nullptr || dlinfo(handle, RTLD_DI_LINKMAP, &lmap) < 0) - return false; - - if (lmap == nullptr || lmap->l_ld == nullptr) - return false; - - return init_relocation_info(lmap->l_ld); - } - - bool is_symbol_available(const char *sym) const - { - switch (reltype) { - case DT_REL: - return is_symbol_available_in_rtable(reinterpret_cast(jmprel), sym); - case DT_RELA: - return is_symbol_available_in_rtable(reinterpret_cast(jmprel), sym); - default: // no relocations - break; - } - return false; - } - -private: - bool init_relocation_info(Dyn *dynamic) - { - for (Dyn *dyn = dynamic; dyn->d_tag != DT_NULL; ++dyn) { - switch (dyn->d_tag) { - case DT_SYMTAB: - dynsym = reinterpret_cast(dyn->d_un.d_ptr); - break; - case DT_STRTAB: - dynstr = reinterpret_cast(dyn->d_un.d_ptr); - break; - case DT_PLTREL: - reltype = dyn->d_un.d_val; - break; - case DT_PLTRELSZ: - pltrel_size = dyn->d_un.d_val; - break; - case DT_JMPREL: - jmprel = reinterpret_cast(dyn->d_un.d_ptr); - break; - default: - break; - } - } - - if (dynsym == nullptr || - dynstr == nullptr || - jmprel == nullptr || - pltrel_size == 0 || - (reltype != DT_REL && reltype != DT_RELA)) - return false; - - return true; - } - - template - bool is_symbol_available_in_rtable(const Rel *rel_table, const char *sym) const - { - if (rel_table == nullptr || pltrel_size == 0) - return false; - - const size_t rel_cnt = pltrel_size / sizeof(Rel); - const Rel *rel_end = rel_table + rel_cnt; - for (const Rel *rel = rel_table; rel < rel_end; ++rel) { - if (strcmp(sym, rel_to_symname(rel)) == 0) - return true; - } - - return false; - } - - template - inline char *rel_to_symname(const Rel *rel) const - { - return dynstr + dynsym[rel->getSymbol()].st_name; - } -}; - -BOOL is_module_sanitized(void *handle) -{ - plt_sym_resolver psr; - if (!psr.init(handle)) - return FALSE; - return psr.is_symbol_available("__asan_init") ? TRUE : FALSE; -} diff --git a/src/coreclr/pal/src/loader/tizenasanenvmodule.h b/src/coreclr/pal/src/loader/tizenasanenvmodule.h deleted file mode 100644 index 8efd9a1..0000000 --- a/src/coreclr/pal/src/loader/tizenasanenvmodule.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2019-2022 Samsung Electronics Co., Ltd. - * - * All rights reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#ifndef TIZENASANENVMODULE_H_ -#define TIZENASANENVMODULE_H_ - -#include - -BOOL is_module_sanitized(void *handle); - -#endif // TIZENASANENVMODULE_H_ diff --git a/src/coreclr/palrt/comem.cpp b/src/coreclr/palrt/comem.cpp index a683ec5..e56e720 100644 --- a/src/coreclr/palrt/comem.cpp +++ b/src/coreclr/palrt/comem.cpp @@ -10,56 +10,12 @@ #include "common.h" -#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 - STDAPI_(LPVOID) CoTaskMemAlloc(SIZE_T cb) { - LPVOID lpRetVal = NULL; -#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 = malloc(cb); - if (!san_enabled) { - __sanitizer_disable_interceptors(); - } - } - else -#endif - { - lpRetVal = malloc(cb); - } - return lpRetVal; + return malloc(cb); } STDAPI_(void) CoTaskMemFree(LPVOID pv) { -#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(); - } - free(pv); - if (!san_enabled) { - __sanitizer_disable_interceptors(); - } - } - else -#endif - { - free(pv); - } + free(pv); } diff --git a/src/coreclr/vm/CMakeLists.txt b/src/coreclr/vm/CMakeLists.txt index 7c0aa4b..9b10c73 100644 --- a/src/coreclr/vm/CMakeLists.txt +++ b/src/coreclr/vm/CMakeLists.txt @@ -727,14 +727,6 @@ elseif(CLR_CMAKE_TARGET_ARCH_ARM64) endif() else(CLR_CMAKE_TARGET_WIN32) - if (TIZEN_ASAN_ENVIRONMENT) - list(APPEND VM_SOURCES_WKS - tizenasanenv.cpp - ) - list(APPEND VM_HEADERS_WKS - tizenasanenv.h - ) - endif() if(CLR_CMAKE_TARGET_ARCH_AMD64) set(VM_SOURCES_WKS_ARCH_ASM @@ -753,11 +745,6 @@ else(CLR_CMAKE_TARGET_WIN32) ${ARCH_SOURCES_DIR}/umthunkstub.S ${ARCH_SOURCES_DIR}/virtualcallstubamd64.S ) - if (TIZEN_ASAN_ENVIRONMENT) - list(APPEND VM_SOURCES_WKS_ARCH_ASM - ${ARCH_SOURCES_DIR}/tizenasanenv.S - ) - endif() elseif(CLR_CMAKE_TARGET_ARCH_I386) set(VM_SOURCES_WKS_ARCH_ASM ${ARCH_SOURCES_DIR}/ehhelpers.S @@ -775,11 +762,6 @@ else(CLR_CMAKE_TARGET_WIN32) ${ARCH_SOURCES_DIR}/patchedcode.S ${ARCH_SOURCES_DIR}/pinvokestubs.S ) - if (TIZEN_ASAN_ENVIRONMENT) - list(APPEND VM_SOURCES_WKS_ARCH_ASM - ${ARCH_SOURCES_DIR}/tizenasanenv.S - ) - endif() elseif(CLR_CMAKE_TARGET_ARCH_ARM64) set(VM_SOURCES_WKS_ARCH_ASM ${ARCH_SOURCES_DIR}/asmhelpers.S diff --git a/src/coreclr/vm/amd64/cgenamd64.cpp b/src/coreclr/vm/amd64/cgenamd64.cpp index 6dbf288..af91cc3 100644 --- a/src/coreclr/vm/amd64/cgenamd64.cpp +++ b/src/coreclr/vm/amd64/cgenamd64.cpp @@ -25,10 +25,6 @@ #include "clrtocomcall.h" #endif // FEATURE_COMINTEROP -#ifdef TIZEN_ASAN_ENVIRONMENT -#include -#endif // TIZEN_ASAN_ENVIRONMENT - void UpdateRegDisplayFromCalleeSavedRegisters(REGDISPLAY * pRD, CalleeSavedRegisters * pRegs) { LIMITED_METHOD_CONTRACT; @@ -530,10 +526,6 @@ void UMEntryThunkCode::Encode(UMEntryThunkCode *pEntryThunkCodeRX, BYTE* pTarget } CONTRACTL_END; -#ifdef TIZEN_ASAN_ENVIRONMENT - pTargetCode = (BYTE *)TizenASanEnv::CreateWrapperILCode((LPVOID)pTargetCode); -#endif // TIZEN_ASAN_ENVIRONMENT - // padding // CC CC CC CC // mov r10, pUMEntryThunk // 49 ba xx xx xx xx xx xx xx xx // METHODDESC_REGISTER // mov rax, pJmpDest // 48 b8 xx xx xx xx xx xx xx xx // need to ensure this imm64 is qword aligned diff --git a/src/coreclr/vm/amd64/tizenasanenv.S b/src/coreclr/vm/amd64/tizenasanenv.S deleted file mode 100644 index 035398e..0000000 --- a/src/coreclr/vm/amd64/tizenasanenv.S +++ /dev/null @@ -1,170 +0,0 @@ -// -// The MIT License (MIT) -// -// Copyright (c) 2019-2022 Samsung Electronics Co., Ltd. -// -// All rights reserved. -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. -// - -// Scheme of saving registers to the stack -// +--------+----------------------+ -// | | value | -// | offset | size | register name | -// +--------+------+---------------+ -// | 0x00 | 8 | --- | (returnt addr) -// | -0x08 | 8 | rax | -// | -0x10 | 8 | r11 | -// | -0x18 | 8 | r10 | -// | -0x20 | 8 | r9 | -// | -0x28 | 8 | r8 | -// | -0x30 | 8 | rcx | -// | -0x38 | 8 | rdx | -// | -0x40 | 8 | rsi | -// | -0x48 | 8 | rdi | -// | -0x50 | 16 | xmm7 | -// | -0x60 | 16 | xmm6 | -// | -0x70 | 16 | xmm5 | -// | -0x80 | 16 | xmm4 | -// | -0x90 | 16 | xmm3 | -// | -0xa0 | 16 | xmm2 | -// | -0xb0 | 16 | xmm1 | -// | -0xc0 | 16 | xmm0 | - - -#define GENERAL_SAVED_REGS_COUNT 9 -#define GENERAL_SAVED_REGS_SIZE (8 * GENERAL_SAVED_REGS_COUNT) -.macro PUSH_GENERAL_REGS - push %rdi // 1st argument - push %rsi // 2nd argument - push %rdx // 3rd argument, 2nd return register - push %rcx // 4th argument - push %r8 // 5th argument - push %r9 // 6th argument - push %r10 // 1st return register - push %r11 // temporary register - push %rax // temporary register -.endm - -.macro POP_GENERAL_REGS - pop %rax - pop %r11 - pop %r10 - pop %r9 - pop %r8 - pop %rcx - pop %rdx - pop %rsi - pop %rdi -.endm - -#define XMM_SAVED_REGS_COUNT 8 -#define XMM_SAVED_REGS_SIZE (16 * XMM_SAVED_REGS_COUNT) -.macro PUSH_XMM_REGS - sub $XMM_SAVED_REGS_SIZE, %rsp - movaps %xmm0, 0x00(%rsp) - movaps %xmm1, 0x10(%rsp) - movaps %xmm2, 0x20(%rsp) - movaps %xmm3, 0x30(%rsp) - movaps %xmm4, 0x40(%rsp) - movaps %xmm5, 0x50(%rsp) - movaps %xmm6, 0x60(%rsp) - movaps %xmm7, 0x70(%rsp) -.endm - -.macro POP_XMM_REGS - movaps 0x70(%rsp), %xmm7 - movaps 0x60(%rsp), %xmm6 - movaps 0x50(%rsp), %xmm5 - movaps 0x40(%rsp), %xmm4 - movaps 0x30(%rsp), %xmm3 - movaps 0x20(%rsp), %xmm2 - movaps 0x10(%rsp), %xmm1 - movaps 0x00(%rsp), %xmm0 - add $XMM_SAVED_REGS_SIZE, %rsp -.endm - -#define RETADDR_OFFSET (GENERAL_SAVED_REGS_SIZE + XMM_SAVED_REGS_SIZE) -.macro PUSH_REGS - PUSH_GENERAL_REGS - PUSH_XMM_REGS -.endm - -.macro POP_REGS - POP_XMM_REGS - POP_GENERAL_REGS -.endm - - -// Export symbols -.global tizenASanWrapper -.global tizenASanWrapperSize -.global tizenASanWrapperEntryOffset - -.text -.code64 - -tizenASanWrapper: -// !!! ATTENTION !!! -// Don't move this labels (target, pushAddr, popAddr) -// because they mapped to AuxiliaryCalls struct from src/coreclr/vm/tizenasanenv.cpp -target: .quad 0xdeadbeef0badc0de -pushAddr: .quad 0xdeadbeef0badc0de // void pushAddr(LPVOID addr) -popAddr: .quad 0xdeadbeef0badc0de // LPVOID popAddr() - - -entryPointer: - // Save context - PUSH_REGS - - // Save the return address and call 'pre handler' - mov RETADDR_OFFSET(%rsp), %rdi // rdi: get return address - call *pushAddr(%rip) // save the return address - - // Change the return address - call next -next: - pop %rax // rax: get current rip - add $(postLabel - next), %rax // rax: add offset to 'postLabel' - mov %rax, RETADDR_OFFSET(%rsp) // change the return address - - // Restore context - POP_REGS - - // Call original function - jmp *target(%rip) -postLabel: - sub $8, %rsp // add space for the return addr - - // Save context - PUSH_REGS - - // Get the return address and call 'post handler' - call *popAddr(%rip) // rax: get the return address - mov %rax, (RETADDR_OFFSET)(%rsp) // restore the return address - - // Restore context - POP_REGS - - // Return - ret - -tizenASanWrapperSize: .long . - tizenASanWrapper -tizenASanWrapperEntryOffset: .long entryPointer - tizenASanWrapper diff --git a/src/coreclr/vm/arm/stubs.cpp b/src/coreclr/vm/arm/stubs.cpp index cc646f37..6e32957 100644 --- a/src/coreclr/vm/arm/stubs.cpp +++ b/src/coreclr/vm/arm/stubs.cpp @@ -25,10 +25,6 @@ #include "ecall.h" #include "threadsuspend.h" -#if defined(TIZEN_ASAN_ENVIRONMENT) && !defined(CROSS_COMPILE) && !defined(DACCESS_COMPILE) -#include -#endif - // target write barriers EXTERN_C void JIT_WriteBarrier(Object **dst, Object *ref); EXTERN_C void JIT_WriteBarrier_End(); @@ -2021,10 +2017,6 @@ class UMEntryThunk * UMEntryThunk::Decode(void *pCallback) void UMEntryThunkCode::Encode(UMEntryThunkCode *pEntryThunkCodeRX, BYTE* pTargetCode, void* pvSecretParam) { -#if defined(TIZEN_ASAN_ENVIRONMENT) && !defined(CROSS_COMPILE) && !defined(DACCESS_COMPILE) - pTargetCode = (BYTE *)TizenASanEnv::CreateWrapperILCode((LPVOID)pTargetCode); -#endif - // ldr r12, [pc + 8] m_code[0] = 0xf8df; m_code[1] = 0xc008; diff --git a/src/coreclr/vm/arm/tizenasanenv.S b/src/coreclr/vm/arm/tizenasanenv.S deleted file mode 100644 index 2639d35..0000000 --- a/src/coreclr/vm/arm/tizenasanenv.S +++ /dev/null @@ -1,87 +0,0 @@ -// -// The MIT License (MIT) -// -// Copyright (c) 2019-2022 Samsung Electronics Co., Ltd. -// -// All rights reserved. -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. -// - -.macro PUSH_REGS - push {r0-r12} - vpush.64 {d0-d7} -.endm - -.macro POP_REGS - vpop.64 {d0-d7} - pop {r0-r12} -.endm - - -// Export symbols -.global tizenASanWrapper -.global tizenASanWrapperSize -.global tizenASanWrapperEntryOffset - -.text -.arm - -tizenASanWrapper: -// !!! ATTENTION !!! -// Don't move this labels (target, pushAddr, popAddr) -// because they mapped to AuxiliaryCalls struct from src/coreclr/vm/tizenasanenv.cpp -target: .word 0xdeadc0de -pushAddr: .word 0xdeadc0de @ void pushAddr(LPVOID addr) -popAddr: .word 0xdeadc0de @ LPVOID popAddr() - -entryPointer: - // Save context - PUSH_REGS - - // Save the return address and call 'pre handler' - mov r0, lr - ldr r1, pushAddr - blx r1 - - // Restore context - POP_REGS - - // Change the return address - adr lr, postLabel - - // Call original function - ldr pc, target -postLabel: - // Save context - PUSH_REGS - - // Get the return address and call 'post handler' - ldr r0, popAddr - blx r0 - - // Restore the return address - mov lr, r0 - - // Restore context - POP_REGS - bx lr - -tizenASanWrapperSize: .word . - tizenASanWrapper -tizenASanWrapperEntryOffset: .word entryPointer - tizenASanWrapper diff --git a/src/coreclr/vm/dllimport.cpp b/src/coreclr/vm/dllimport.cpp index 8f6640b..925e1f7 100644 --- a/src/coreclr/vm/dllimport.cpp +++ b/src/coreclr/vm/dllimport.cpp @@ -50,10 +50,6 @@ #include "compile.h" #endif // FEATURE_PREJIT -#ifdef TIZEN_ASAN_ENVIRONMENT -#include -#endif // TIZEN_ASAN_ENVIRONMENT - #include "eventtrace.h" namespace @@ -5616,13 +5612,6 @@ namespace LPVOID pvTarget = NDirectGetEntryPoint(pMD, hmod); if (pvTarget) { -#ifdef TIZEN_ASAN_ENVIRONMENT - if (PAL_IsSanitizedLibraryDirect(hmod)) - { - pvTarget = TizenASanEnv::CreateWrapperSanitizedEntryPoint(pvTarget); - } -#endif // TIZEN_ASAN_ENVIRONMENT - pMD->SetNDirectTarget(pvTarget); fSuccess = TRUE; } diff --git a/src/coreclr/vm/ilmarshalers.cpp b/src/coreclr/vm/ilmarshalers.cpp index 14fa3cb..8f34846 100644 --- a/src/coreclr/vm/ilmarshalers.cpp +++ b/src/coreclr/vm/ilmarshalers.cpp @@ -3934,11 +3934,7 @@ bool ILNativeArrayMarshaler::CanMarshalViaPinning() { // We can't pin an array if we have a marshaler for the var type // or if we can't get a method-table representing the array (how we determine the offset to pin). -#ifndef TIZEN_ASAN_ENVIRONMENT return IsCLRToNative(m_dwMarshalFlags) && !IsByref(m_dwMarshalFlags) && (NULL != m_pargs->na.m_pArrayMT) && (NULL == OleVariant::GetMarshalerForVarType(m_pargs->na.m_vt, TRUE)); -#else - return false; -#endif } void ILNativeArrayMarshaler::EmitMarshalViaPinning(ILCodeStream* pslILEmit) diff --git a/src/coreclr/vm/tizenasanenv.cpp b/src/coreclr/vm/tizenasanenv.cpp deleted file mode 100644 index 8a37ae3..0000000 --- a/src/coreclr/vm/tizenasanenv.cpp +++ /dev/null @@ -1,200 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2019-2022 Samsung Electronics Co., Ltd. - * - * All rights reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include -#include "common.h" -#include "tizenasanenv.h" - - -template -class StaticStack { - // We don't create constructor because - // this class is used in a zeroed memory area -public: - void push(Type addr) - { - _ASSERTE(m_pos < STACK_SIZE); - - m_data[m_pos++] = addr; - } - - void pop() - { - _ASSERTE(m_pos > 0); - --m_pos; - } - - Type top() - { - _ASSERTE(m_pos > 0); - - return m_data[m_pos - 1]; - } - - bool empty() - { - return m_pos == 0; - } - -private: - int m_pos; - Type m_data[STACK_SIZE]; -}; - -#include -struct AuxiliaryCalls { - LPVOID target; - void (*pushAddr)(LPVOID addr); - LPVOID (*popAddr)(); -}; - -struct ReturnInfo { - LPVOID addr; - bool isSanitized; -}; - -extern "C" void __sanitizer_disable_interceptors(); -extern "C" void __sanitizer_enable_interceptors(); -extern "C" bool __sanitizer_interceptors_are_enabled(); - -extern LPVOID tizenASanWrapper; -extern UINT32 tizenASanWrapperSize; -extern UINT32 tizenASanWrapperEntryOffset; - -// The maximum nesting of transitions between managed and unmanaged code that we support. -// This number is estimated from the common sense. We think this is enough to check any -// sane code (if it is not recursive) and it won't bloat TLS. We do not use dynamic -// allocation because it complicates the process of memory management in TLS variables. -// It is used only for firmware with ASan and will not affect the release version. -#define MAX_STACK_DEPTH 128 -static __thread StaticStack s_retInfoStack; - - -static void DoEnable() -{ - _ASSERTE(__sanitizer_interceptors_are_enabled() == false); - __sanitizer_enable_interceptors(); -} - -static void DoDisable() -{ - _ASSERTE(__sanitizer_interceptors_are_enabled() == true); - __sanitizer_disable_interceptors(); -} - -static void PushAndEnableASan(LPVOID addr) -{ - _ASSERTE(__sanitizer_interceptors_are_enabled() == false); - - ReturnInfo retInfo = { - .addr = addr, - .isSanitized = false, - }; - - s_retInfoStack.push(retInfo); - DoEnable(); -} - -static LPVOID PopAndDisableASan() -{ - _ASSERTE(__sanitizer_interceptors_are_enabled() == true); - - ReturnInfo retInfo = s_retInfoStack.top(); - s_retInfoStack.pop(); - - _ASSERTE(retInfo.isSanitized == false); - DoDisable(); - - return retInfo.addr; -} - -static void PushAndMayBeDisableASan(LPVOID addr) -{ - ReturnInfo retInfo = { - .addr = addr, - .isSanitized = __sanitizer_interceptors_are_enabled(), - }; - - if (retInfo.isSanitized) - DoDisable(); - - s_retInfoStack.push(retInfo); -} - -static LPVOID PopAndMayBeEnableASan() -{ - _ASSERTE(__sanitizer_interceptors_are_enabled() == false); - - ReturnInfo retInfo = s_retInfoStack.top(); - s_retInfoStack.pop(); - - if (retInfo.isSanitized) - DoEnable(); - - return retInfo.addr; -} - -static LPVOID CreateWrapper(LPVOID target, void (*pushAddr)(LPVOID addr), LPVOID (*popAddr)()) -{ - _ASSERTE(tizenASanWrapperEntryOffset == sizeof(AuxiliaryCalls)); - - LPVOID wrapperSpace = (LPVOID)SystemDomain::GetGlobalLoaderAllocator()->GetExecutableHeap()->AllocMem(S_SIZE_T(tizenASanWrapperSize)); - - AuxiliaryCalls calls = { - .target = target, - .pushAddr = pushAddr, - .popAddr = popAddr, - }; - - // copy auxiliary calls - memcpy(wrapperSpace, &calls, sizeof(calls)); - - LPVOID entryPointer = (LPVOID)((UINT_PTR)wrapperSpace + tizenASanWrapperEntryOffset); - LPVOID wrapperEntryPointer = (LPVOID)((UINT_PTR)&tizenASanWrapper + tizenASanWrapperEntryOffset); - UINT32 wrapperCodeSize = tizenASanWrapperSize - tizenASanWrapperEntryOffset; - - // copy executable code wrapper - memcpy(entryPointer, wrapperEntryPointer, wrapperCodeSize); - - FlushInstructionCache(GetCurrentProcess(), wrapperSpace, tizenASanWrapperSize); - - return entryPointer; -} - - -namespace TizenASanEnv { - -LPVOID CreateWrapperSanitizedEntryPoint(LPVOID target) -{ - return CreateWrapper(target, PushAndEnableASan, PopAndDisableASan); -} - -LPVOID CreateWrapperILCode(LPVOID target) -{ - return CreateWrapper(target, PushAndMayBeDisableASan, PopAndMayBeEnableASan); -} - -} // namespace TizenASanEnv diff --git a/src/coreclr/vm/tizenasanenv.h b/src/coreclr/vm/tizenasanenv.h deleted file mode 100644 index 5f2f9d9..0000000 --- a/src/coreclr/vm/tizenasanenv.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2019-2022 Samsung Electronics Co., Ltd. - * - * All rights reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#ifndef TIZENASANENV_H_ -#define TIZENASANENV_H_ - -namespace TizenASanEnv { - -LPVOID CreateWrapperSanitizedEntryPoint(LPVOID target); -LPVOID CreateWrapperILCode(LPVOID target); - -} // namespace TizenASanEnv - -#endif // TIZENASANENV_H_