Extend MemtagNoteTest.

Calling free() during system property init results in premature
allocator initialization. This has been fixed with a Scudo change in
https://r.android.com/2853684. This patch extends MemtagNoteTest to
verify that there are no stray PROT_MTE mappings when MTE is not
enabled in the binary.

Test: adb shell setprop arm64.memtag.bootctl memtag
      adb reboot
      bionic-unit-tests --gtest_filter=MemtagNoteTest.SEGV/*
Bug: 309698651
Change-Id: I6c7733d8799537d898c97b00d494ce6591cf44d9
diff --git a/tests/libs/Android.bp b/tests/libs/Android.bp
index 51f5ac6..5d143f8 100644
--- a/tests/libs/Android.bp
+++ b/tests/libs/Android.bp
@@ -29,6 +29,7 @@
         "-Wl,--rpath,${ORIGIN}",
         "-Wl,--enable-new-dtags",
     ],
+    static_libs: ["libbase"],
     relative_install_path: "bionic-loader-test-libs",
     gtest: false,
     sanitize: {
diff --git a/tests/libs/heap_tagging_helper.cpp b/tests/libs/heap_tagging_helper.cpp
index ed5601a..7aad392 100644
--- a/tests/libs/heap_tagging_helper.cpp
+++ b/tests/libs/heap_tagging_helper.cpp
@@ -16,12 +16,15 @@
 
 #include <signal.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include <sys/auxv.h>
 #include <sys/cdefs.h>
 #include <sys/mman.h>
 #include <unistd.h>
 #include <memory>
 
+#include <android-base/stringprintf.h>
+
 void action(int signo, siginfo_t* info __unused, void*) {
 #ifdef __ANDROID__
   if (signo == 11 && info->si_code == SEGV_MTEAERR) {
@@ -89,6 +92,13 @@
   }
 #endif  // __aarch64__
 
+  // In fact, make sure that there are no tagged mappings at all.
+  auto cmd = android::base::StringPrintf("cat /proc/%d/smaps | grep -E 'VmFlags:.* mt'", getpid());
+  if (system(cmd.c_str()) == 0) {
+    fprintf(stderr, "unexpected PROT_MTE mappings found\n");
+    return 1;
+  }
+
   fprintf(stderr, "normal exit\n");
   return 0;
 }