[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
This commit is contained in:
Marco Nelissen 2023-06-07 00:15:02 +00:00 committed by Chia-hung Duan
parent 7056ad7e97
commit 146f4c26ac
4 changed files with 13 additions and 6 deletions

View File

@ -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.

View File

@ -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;

View File

@ -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

View File

@ -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)) {