From 3ebcc4c8f593821a64c265af19f4786889d94dc0 Mon Sep 17 00:00:00 2001 From: Dmitry Muhomor Date: Thu, 26 Oct 2023 10:22:55 +0300 Subject: [PATCH] android: add function for disabling MTE at runtime On Android, MTE is always enabled in Zygote, and is disabled after fork for apps that didn't opt-in to MTE. Depends on the slab canary adjustments in the previous commit. --- h_malloc.c | 8 ++++++++ include/h_malloc.h | 1 + 2 files changed, 9 insertions(+) diff --git a/h_malloc.c b/h_malloc.c index 9a3a732..c3ce7e2 100644 --- a/h_malloc.c +++ b/h_malloc.c @@ -2148,3 +2148,11 @@ COLD EXPORT int h_malloc_set_state(UNUSED void *state) { return -2; } #endif + +#ifdef __ANDROID__ +COLD EXPORT void h_malloc_disable_memory_tagging(void) { +#ifdef HAS_ARM_MTE + __is_memtag_enabled = false; +#endif +} +#endif diff --git a/include/h_malloc.h b/include/h_malloc.h index 5824abb..0eee395 100644 --- a/include/h_malloc.h +++ b/include/h_malloc.h @@ -99,6 +99,7 @@ int h_malloc_iterate(uintptr_t base, size_t size, void (*callback)(uintptr_t ptr void *arg); void h_malloc_disable(void); void h_malloc_enable(void); +void h_malloc_disable_memory_tagging(void); #endif // hardened_malloc extensions