[compiler-rt] 146f4c2 - [scudo] Enable MTE in Trusty

Chia-hung Duan via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 6 17:15:39 PDT 2023


Author: Marco Nelissen
Date: 2023-06-07T00:15:04Z
New Revision: 146f4c26ac5097c4cc145ce3a6f700c3748affd1

URL: https://github.com/llvm/llvm-project/commit/146f4c26ac5097c4cc145ce3a6f700c3748affd1
DIFF: https://github.com/llvm/llvm-project/commit/146f4c26ac5097c4cc145ce3a6f700c3748affd1.diff

LOG: [scudo] Enable MTE in Trusty

Trusty now has MTE support.
Back-ported from https://r.android.com/2332745.

Reviewed By: Chia-hungDuan

Differential Revision: https://reviews.llvm.org/D152219

Added: 
    

Modified: 
    compiler-rt/lib/scudo/standalone/allocator_config.h
    compiler-rt/lib/scudo/standalone/memtag.h
    compiler-rt/lib/scudo/standalone/platform.h
    compiler-rt/lib/scudo/standalone/trusty.cpp

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/scudo/standalone/allocator_config.h b/compiler-rt/lib/scudo/standalone/allocator_config.h
index 1150157e25f63..315a04f7635da 100644
--- a/compiler-rt/lib/scudo/standalone/allocator_config.h
+++ b/compiler-rt/lib/scudo/standalone/allocator_config.h
@@ -271,7 +271,7 @@ struct FuchsiaConfig {
 };
 
 struct TrustyConfig {
-  static const bool MaySupportMemoryTagging = false;
+  static const bool MaySupportMemoryTagging = true;
   template <class A>
   using TSDRegistryT = TSDRegistrySharedT<A, 1U, 1U>; // Shared, max 1 TSD.
 

diff  --git a/compiler-rt/lib/scudo/standalone/memtag.h b/compiler-rt/lib/scudo/standalone/memtag.h
index 7f14a30fee12b..aaed2192ad752 100644
--- a/compiler-rt/lib/scudo/standalone/memtag.h
+++ b/compiler-rt/lib/scudo/standalone/memtag.h
@@ -11,7 +11,7 @@
 
 #include "internal_defs.h"
 
-#if SCUDO_LINUX
+#if SCUDO_CAN_USE_MTE
 #include <sys/auxv.h>
 #include <sys/prctl.h>
 #endif
@@ -25,7 +25,7 @@ namespace scudo {
 // tagging. Not all operating systems enable TBI, so we only claim architectural
 // support for memory tagging if the operating system enables TBI.
 // HWASan uses the top byte for its own purpose and Scudo should not touch it.
-#if SCUDO_LINUX && !defined(SCUDO_DISABLE_TBI) &&                              \
+#if SCUDO_CAN_USE_MTE && !defined(SCUDO_DISABLE_TBI) &&                        \
     !__has_feature(hwaddress_sanitizer)
 inline constexpr bool archSupportsMemoryTagging() { return true; }
 #else
@@ -60,7 +60,7 @@ inline NORETURN uint8_t extractTag(uptr Ptr) {
 
 #if __clang_major__ >= 12 && defined(__aarch64__) && !defined(__ILP32__)
 
-#if SCUDO_LINUX
+#if SCUDO_CAN_USE_MTE
 
 inline bool systemSupportsMemoryTagging() {
 #ifndef HWCAP2_MTE
@@ -106,7 +106,7 @@ inline void enableSystemMemoryTaggingTestOnly() {
         0, 0, 0);
 }
 
-#else // !SCUDO_LINUX
+#else // !SCUDO_CAN_USE_MTE
 
 inline bool systemSupportsMemoryTagging() { return false; }
 
@@ -118,7 +118,7 @@ inline NORETURN void enableSystemMemoryTaggingTestOnly() {
   UNREACHABLE("memory tagging not supported");
 }
 
-#endif // SCUDO_LINUX
+#endif // SCUDO_CAN_USE_MTE
 
 class ScopedDisableMemoryTagChecks {
   uptr PrevTCO;

diff  --git a/compiler-rt/lib/scudo/standalone/platform.h b/compiler-rt/lib/scudo/standalone/platform.h
index aae3b9ab8760a..7c7024ff570e4 100644
--- a/compiler-rt/lib/scudo/standalone/platform.h
+++ b/compiler-rt/lib/scudo/standalone/platform.h
@@ -59,6 +59,10 @@
 #define SCUDO_CAN_USE_PRIMARY64 (SCUDO_WORDSIZE == 64U)
 #endif
 
+#ifndef SCUDO_CAN_USE_MTE
+#define SCUDO_CAN_USE_MTE (SCUDO_LINUX || SCUDO_TRUSTY)
+#endif
+
 #ifndef SCUDO_MIN_ALIGNMENT_LOG
 // We force malloc-type functions to be aligned to std::max_align_t, but there
 // is no reason why the minimum alignment for all other functions can't be 8

diff  --git a/compiler-rt/lib/scudo/standalone/trusty.cpp b/compiler-rt/lib/scudo/standalone/trusty.cpp
index 8d73eeb36767a..3191091e1b965 100644
--- a/compiler-rt/lib/scudo/standalone/trusty.cpp
+++ b/compiler-rt/lib/scudo/standalone/trusty.cpp
@@ -43,6 +43,9 @@ void *map(void *Addr, uptr Size, const char *Name, uptr Flags,
   if (Addr)
     MmapFlags |= MMAP_FLAG_FIXED_NOREPLACE;
 
+  if (Flags & MAP_MEMTAG)
+    MmapFlags |= MMAP_FLAG_PROT_MTE;
+
   void *P = (void *)_trusty_mmap(Addr, Size, MmapFlags, 0);
 
   if (IS_ERR(P)) {


        


More information about the llvm-commits mailing list