Skip to content

[DFSan] [compiler-rt] leave BufferedStackTrace uninit #102252

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

fmayer
Copy link
Contributor

@fmayer fmayer commented Aug 6, 2024

Otherwise we have to memset 2040 bytes (255 * 8) for each call

Created using spr 1.3.4
@llvmbot
Copy link
Member

llvmbot commented Aug 6, 2024

@llvm/pr-subscribers-compiler-rt-sanitizer

Author: Florian Mayer (fmayer)

Changes

Otherwise we have to memset 2040 bytes (255 * 8) for each call


Full diff: https://github.com/llvm/llvm-project/pull/102252.diff

3 Files Affected:

  • (modified) compiler-rt/lib/dfsan/dfsan.cpp (+1-1)
  • (modified) compiler-rt/lib/dfsan/dfsan_allocator.cpp (+9-9)
  • (modified) compiler-rt/lib/dfsan/dfsan_new_delete.cpp (+2-2)
diff --git a/compiler-rt/lib/dfsan/dfsan.cpp b/compiler-rt/lib/dfsan/dfsan.cpp
index 302e3c3032ac5..360288cb88f34 100644
--- a/compiler-rt/lib/dfsan/dfsan.cpp
+++ b/compiler-rt/lib/dfsan/dfsan.cpp
@@ -195,7 +195,7 @@ static dfsan_origin GetOriginIfTainted(uptr addr, uptr size) {
 // random freezes in forking applications as well as in signal handlers.
 // DFSan supports only Linux. So we do not restrict the store context size.
 #define GET_STORE_STACK_TRACE_PC_BP(pc, bp) \
-  BufferedStackTrace stack;                 \
+  UNINITIALIZED BufferedStackTrace stack;                 \
   stack.Unwind(pc, bp, nullptr, true, flags().store_context_size);
 
 #define PRINT_CALLER_STACK_TRACE        \
diff --git a/compiler-rt/lib/dfsan/dfsan_allocator.cpp b/compiler-rt/lib/dfsan/dfsan_allocator.cpp
index 682df8c6e0346..81ea91580a989 100644
--- a/compiler-rt/lib/dfsan/dfsan_allocator.cpp
+++ b/compiler-rt/lib/dfsan/dfsan_allocator.cpp
@@ -95,13 +95,13 @@ static void *DFsanAllocate(uptr size, uptr alignment, bool zeroise) {
              size);
       return nullptr;
     }
-    BufferedStackTrace stack;
+    UNINITIALIZED BufferedStackTrace stack;
     ReportAllocationSizeTooBig(size, max_malloc_size, &stack);
   }
   if (UNLIKELY(IsRssLimitExceeded())) {
     if (AllocatorMayReturnNull())
       return nullptr;
-    BufferedStackTrace stack;
+    UNINITIALIZED BufferedStackTrace stack;
     ReportRssLimitExceeded(&stack);
   }
   DFsanThread *t = GetCurrentThread();
@@ -118,7 +118,7 @@ static void *DFsanAllocate(uptr size, uptr alignment, bool zeroise) {
     SetAllocatorOutOfMemory();
     if (AllocatorMayReturnNull())
       return nullptr;
-    BufferedStackTrace stack;
+    UNINITIALIZED BufferedStackTrace stack;
     ReportOutOfMemory(size, &stack);
   }
   Metadata *meta =
@@ -175,7 +175,7 @@ void *DFsanCalloc(uptr nmemb, uptr size) {
   if (UNLIKELY(CheckForCallocOverflow(size, nmemb))) {
     if (AllocatorMayReturnNull())
       return nullptr;
-    BufferedStackTrace stack;
+    UNINITIALIZED BufferedStackTrace stack;
     ReportCallocOverflow(nmemb, size, &stack);
   }
   return DFsanAllocate(nmemb * size, sizeof(u64), true /*zeroise*/);
@@ -232,7 +232,7 @@ void *dfsan_reallocarray(void *ptr, uptr nmemb, uptr size) {
     errno = errno_ENOMEM;
     if (AllocatorMayReturnNull())
       return nullptr;
-    BufferedStackTrace stack;
+    UNINITIALIZED BufferedStackTrace stack;
     ReportReallocArrayOverflow(nmemb, size, &stack);
   }
   return dfsan_realloc(ptr, nmemb * size);
@@ -249,7 +249,7 @@ void *dfsan_pvalloc(uptr size) {
     errno = errno_ENOMEM;
     if (AllocatorMayReturnNull())
       return nullptr;
-    BufferedStackTrace stack;
+    UNINITIALIZED BufferedStackTrace stack;
     ReportPvallocOverflow(size, &stack);
   }
   // pvalloc(0) should allocate one page.
@@ -262,7 +262,7 @@ void *dfsan_aligned_alloc(uptr alignment, uptr size) {
     errno = errno_EINVAL;
     if (AllocatorMayReturnNull())
       return nullptr;
-    BufferedStackTrace stack;
+    UNINITIALIZED BufferedStackTrace stack;
     ReportInvalidAlignedAllocAlignment(size, alignment, &stack);
   }
   return SetErrnoOnNull(DFsanAllocate(size, alignment, false /*zeroise*/));
@@ -273,7 +273,7 @@ void *dfsan_memalign(uptr alignment, uptr size) {
     errno = errno_EINVAL;
     if (AllocatorMayReturnNull())
       return nullptr;
-    BufferedStackTrace stack;
+    UNINITIALIZED BufferedStackTrace stack;
     ReportInvalidAllocationAlignment(alignment, &stack);
   }
   return SetErrnoOnNull(DFsanAllocate(size, alignment, false /*zeroise*/));
@@ -283,7 +283,7 @@ int dfsan_posix_memalign(void **memptr, uptr alignment, uptr size) {
   if (UNLIKELY(!CheckPosixMemalignAlignment(alignment))) {
     if (AllocatorMayReturnNull())
       return errno_EINVAL;
-    BufferedStackTrace stack;
+    UNINITIALIZED BufferedStackTrace stack;
     ReportInvalidPosixMemalignAlignment(alignment, &stack);
   }
   void *ptr = DFsanAllocate(size, alignment, false /*zeroise*/);
diff --git a/compiler-rt/lib/dfsan/dfsan_new_delete.cpp b/compiler-rt/lib/dfsan/dfsan_new_delete.cpp
index 7ac906e81077d..4482e22951040 100644
--- a/compiler-rt/lib/dfsan/dfsan_new_delete.cpp
+++ b/compiler-rt/lib/dfsan/dfsan_new_delete.cpp
@@ -30,14 +30,14 @@ enum class align_val_t : size_t {};
 #define OPERATOR_NEW_BODY(nothrow)   \
   void *res = dfsan_malloc(size);    \
   if (!nothrow && UNLIKELY(!res)) {  \
-    BufferedStackTrace stack;        \
+    UNINITIALIZED BufferedStackTrace stack;        \
     ReportOutOfMemory(size, &stack); \
   }                                  \
   return res
 #define OPERATOR_NEW_BODY_ALIGN(nothrow)         \
   void *res = dfsan_memalign((uptr)align, size); \
   if (!nothrow && UNLIKELY(!res)) {              \
-    BufferedStackTrace stack;                    \
+    UNINITIALIZED BufferedStackTrace stack;                    \
     ReportOutOfMemory(size, &stack);             \
   }                                              \
   return res;

Created using spr 1.3.4
@fmayer fmayer changed the base branch from users/fmayer/spr/main.dfsan-compiler-rt-leave-bufferedstacktrace-uninit to main August 7, 2024 17:10
@fmayer fmayer changed the base branch from main to users/fmayer/spr/main.dfsan-compiler-rt-leave-bufferedstacktrace-uninit August 7, 2024 20:56
Created using spr 1.3.4
@fmayer fmayer requested a review from vitalybuka August 7, 2024 22:14
fmayer added a commit that referenced this pull request Aug 7, 2024
Otherwise we have to memset 2040 bytes (255 * 8) for each call

Pull Request: #102252
@fmayer fmayer closed this Aug 7, 2024
fmayer added a commit to fmayer/llvm-project that referenced this pull request Sep 13, 2024
Otherwise we have to memset 2040 bytes (255 * 8) for each call

Pull Request: llvm#102252
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants