[PATCH] D110575: [gwp-asan] Initialize AllocatorVersionMagic at runtime

Kostya Kortchinsky via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 27 12:32:31 PDT 2021


cryptoad created this revision.
cryptoad added reviewers: hctim, mcgrathr, eugenis.
Herald added a subscriber: phosek.
cryptoad requested review of this revision.
Herald added a project: Sanitizers.
Herald added a subscriber: Sanitizers.

GWP-ASan's `AllocatorState` was recently extended with a
`AllocatorVersionMagic` structure required so that GWP-ASan bug reports
can be understood by tools at different versions.

On Fuchsia, this in included in the `scudo::Allocator` structure, and
by having non-zero initializers, this effectively moved the static
allocator structure from the `.bss` segment to the `.data` segment, thus
increasing (significantly) the size of the libc.

This CL proposes to initialize the structure with its magic numbers at
runtime, allowing for the allocator to go back into the `.bss` segment.

I will work on adding a test on the Scudo side to ensure that this type
of changes get detected early on. Additional work is also needed to
reduce the footprint of the (large) memory-tagging related structures
that are currently part of the allocator.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D110575

Files:
  compiler-rt/lib/gwp_asan/common.h
  compiler-rt/lib/gwp_asan/guarded_pool_allocator.cpp


Index: compiler-rt/lib/gwp_asan/guarded_pool_allocator.cpp
===================================================================
--- compiler-rt/lib/gwp_asan/guarded_pool_allocator.cpp
+++ compiler-rt/lib/gwp_asan/guarded_pool_allocator.cpp
@@ -59,6 +59,11 @@
   SingletonPtr = this;
   Backtrace = Opts.Backtrace;
 
+  State.VersionMagic = {{kAllocatorVersionMagic[0], kAllocatorVersionMagic[1],
+                         kAllocatorVersionMagic[2], kAllocatorVersionMagic[3]},
+                        kAllocatorVersion,
+                        0};
+
   State.MaxSimultaneousAllocations = Opts.MaxSimultaneousAllocations;
 
   const size_t PageSize = getPlatformPageSize();
Index: compiler-rt/lib/gwp_asan/common.h
===================================================================
--- compiler-rt/lib/gwp_asan/common.h
+++ compiler-rt/lib/gwp_asan/common.h
@@ -22,18 +22,22 @@
 
 // Magic header that resides in the AllocatorState so that GWP-ASan bugreports
 // can be understood by tools at different versions. Out-of-process crash
-// handlers, like crashpad on Fuchsia, take the raw conents of the
+// handlers, like crashpad on Fuchsia, take the raw contents of the
 // AllocationMetatada array and the AllocatorState, and shove them into the
 // minidump. Online unpacking of these structs needs to know from which version
 // of GWP-ASan its extracting the information, as the structures are not stable.
 struct AllocatorVersionMagic {
-  const uint8_t Magic[4] = {'A', 'S', 'A', 'N'};
+  uint8_t Magic[4] = {};
   // Update the version number when the AllocatorState or AllocationMetadata
   // change.
-  const uint16_t Version = 1;
-  const uint16_t Reserved = 0;
+  uint16_t Version = 0;
+  uint16_t Reserved = 0;
 };
 
+// Constants for the AllocatorVersionMagic initialization.
+static constexpr uint8_t kAllocatorVersionMagic[4] = {'A', 'S', 'A', 'N'};
+static constexpr uint16_t kAllocatorVersion = 1;
+
 enum class Error : uint8_t {
   UNKNOWN,
   USE_AFTER_FREE,
@@ -99,7 +103,7 @@
 // set of information required for understanding a GWP-ASan crash.
 struct AllocatorState {
   constexpr AllocatorState() {}
-  const AllocatorVersionMagic VersionMagic{};
+  AllocatorVersionMagic VersionMagic{};
 
   // Returns whether the provided pointer is a current sampled allocation that
   // is owned by this pool.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D110575.375368.patch
Type: text/x-patch
Size: 2326 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210927/e1e3687b/attachment.bin>


More information about the llvm-commits mailing list