From da60a148941583b0b587212df59f106f718c2be6 Mon Sep 17 00:00:00 2001 From: "Wu, Yingcong" Date: Tue, 6 Aug 2024 10:25:25 +0800 Subject: [PATCH] exclude shadow from coredump --- source/loader/layers/sanitizer/asan_shadow_setup.cpp | 1 + source/loader/layers/sanitizer/common.hpp | 1 + source/loader/layers/sanitizer/linux/sanitizer_utils.cpp | 6 ++++++ 3 files changed, 8 insertions(+) diff --git a/source/loader/layers/sanitizer/asan_shadow_setup.cpp b/source/loader/layers/sanitizer/asan_shadow_setup.cpp index 37ecbce281..3c037657ac 100644 --- a/source/loader/layers/sanitizer/asan_shadow_setup.cpp +++ b/source/loader/layers/sanitizer/asan_shadow_setup.cpp @@ -29,6 +29,7 @@ ur_result_t SetupShadowMemory(uptr &ShadowBegin, uptr &ShadowEnd) { if (SHADOW_BEGIN == 0) { return UR_RESULT_ERROR_OUT_OF_HOST_MEMORY; } + DontCoredumpRange(SHADOW_BEGIN, SHADOW_SIZE); SHADOW_END = SHADOW_BEGIN + SHADOW_SIZE; IsShadowMemInited = true; return UR_RESULT_SUCCESS; diff --git a/source/loader/layers/sanitizer/common.hpp b/source/loader/layers/sanitizer/common.hpp index 9e8fa93902..cde9c2efed 100644 --- a/source/loader/layers/sanitizer/common.hpp +++ b/source/loader/layers/sanitizer/common.hpp @@ -142,6 +142,7 @@ bool IsInASanContext(); uptr MmapNoReserve(uptr Addr, uptr Size); bool Munmap(uptr Addr, uptr Size); +bool DontCoredumpRange(uptr Addr, uptr Size); void *GetMemFunctionPointer(const char *); diff --git a/source/loader/layers/sanitizer/linux/sanitizer_utils.cpp b/source/loader/layers/sanitizer/linux/sanitizer_utils.cpp index 64704180ad..d0bc038174 100644 --- a/source/loader/layers/sanitizer/linux/sanitizer_utils.cpp +++ b/source/loader/layers/sanitizer/linux/sanitizer_utils.cpp @@ -37,6 +37,12 @@ uptr MmapNoReserve(uptr Addr, uptr Size) { bool Munmap(uptr Addr, uptr Size) { return munmap((void *)Addr, Size) == 0; } +bool DontCoredumpRange(uptr Addr, uptr Size) { + Size = RoundUpTo(Size, EXEC_PAGESIZE); + Addr = RoundDownTo(Addr, EXEC_PAGESIZE); + return madvise((void *)Addr, Size, MADV_DONTDUMP) == 0; +} + void *GetMemFunctionPointer(const char *FuncName) { void *handle = dlopen(LIBC_SO, RTLD_LAZY | RTLD_NOLOAD); if (!handle) {