From 4edbcee2c65bd38efae1411a847a6af9b22642fc Mon Sep 17 00:00:00 2001 From: Evgenii Stepanov Date: Fri, 17 Sep 2021 14:59:15 -0700 Subject: [PATCH] Random HWASan cleanups. Makes CtsBionicTestCases pass under HWASan. Bug: 193568145 Test: CtsBionicTestCases Change-Id: I38ee8a8508827c0ffee61ce33bb8c6a3f40388c9 --- tests/dlext_test.cpp | 2 +- tests/heap_tagging_level_test.cpp | 14 +++++++++++++- tests/leak_test.cpp | 10 ++++++++-- tests/malloc_test.cpp | 5 ++++- 4 files changed, 26 insertions(+), 5 deletions(-) diff --git a/tests/dlext_test.cpp b/tests/dlext_test.cpp index e3caf0eb1..47214b85b 100644 --- a/tests/dlext_test.cpp +++ b/tests/dlext_test.cpp @@ -714,7 +714,7 @@ void DlExtRelroSharingTest::SpawnChildrenAndMeasurePss(const char* lib, const ch } std::string DlExtRelroSharingTest::FindMappingName(void* ptr) { - uint64_t addr = reinterpret_cast(ptr); + uint64_t addr = reinterpret_cast(untag_address(ptr)); std::string found_name = ""; EXPECT_TRUE(android::procinfo::ReadMapFile("/proc/self/maps", diff --git a/tests/heap_tagging_level_test.cpp b/tests/heap_tagging_level_test.cpp index 5f5904f9a..edbd995d9 100644 --- a/tests/heap_tagging_level_test.cpp +++ b/tests/heap_tagging_level_test.cpp @@ -52,6 +52,9 @@ TEST(heap_tagging_level, tagged_pointer_dies) { if (mte_supported()) { GTEST_SKIP() << "Tagged pointers are not used on MTE hardware."; } + if (running_with_hwasan()) { + GTEST_SKIP() << "Tagged heap pointers feature is disabled under HWASan."; + } void *x = malloc(1); @@ -119,6 +122,9 @@ TEST(heap_tagging_level, sync_async_bad_accesses_die) { TEST(heap_tagging_level, none_pointers_untagged) { #if defined(__BIONIC__) + if (running_with_hwasan()) { + GTEST_SKIP() << "HWASan is unaffected by heap tagging level."; + } EXPECT_TRUE(SetHeapTaggingLevel(M_HEAP_TAGGING_LEVEL_NONE)); std::unique_ptr p = std::make_unique(4); EXPECT_EQ(untag_address(p.get()), p.get()); @@ -135,7 +141,13 @@ TEST(heap_tagging_level, tagging_level_transitions) { EXPECT_FALSE(SetHeapTaggingLevel(static_cast(12345))); - if (mte_supported() && running_with_mte()) { + if (running_with_hwasan()) { + // NONE -> ... + EXPECT_FALSE(SetHeapTaggingLevel(M_HEAP_TAGGING_LEVEL_TBI)); + EXPECT_FALSE(SetHeapTaggingLevel(M_HEAP_TAGGING_LEVEL_ASYNC)); + EXPECT_FALSE(SetHeapTaggingLevel(M_HEAP_TAGGING_LEVEL_SYNC)); + EXPECT_TRUE(SetHeapTaggingLevel(M_HEAP_TAGGING_LEVEL_NONE)); + } else if (mte_supported() && running_with_mte()) { // ASYNC -> ... EXPECT_FALSE(SetHeapTaggingLevel(M_HEAP_TAGGING_LEVEL_TBI)); EXPECT_TRUE(SetHeapTaggingLevel(M_HEAP_TAGGING_LEVEL_ASYNC)); diff --git a/tests/leak_test.cpp b/tests/leak_test.cpp index 80618e503..0a881e12c 100644 --- a/tests/leak_test.cpp +++ b/tests/leak_test.cpp @@ -112,11 +112,17 @@ std::ostream& operator<<(std::ostream& os, const LeakChecker& lc) { TEST(pthread_leak, join) { SKIP_WITH_NATIVE_BRIDGE; // http://b/37920774 + // Warm up. HWASan allocates an extra page on the first iteration, but never after. + pthread_t thread; + ASSERT_EQ(0, pthread_create( + &thread, nullptr, [](void*) -> void* { return nullptr; }, nullptr)); + ASSERT_EQ(0, pthread_join(thread, nullptr)); + LeakChecker lc; for (int i = 0; i < 100; ++i) { - pthread_t thread; - ASSERT_EQ(0, pthread_create(&thread, nullptr, [](void*) -> void* { return nullptr; }, nullptr)); + ASSERT_EQ(0, pthread_create( + &thread, nullptr, [](void*) -> void* { return nullptr; }, nullptr)); ASSERT_EQ(0, pthread_join(thread, nullptr)); } } diff --git a/tests/malloc_test.cpp b/tests/malloc_test.cpp index eae44ceef..3f220071e 100644 --- a/tests/malloc_test.cpp +++ b/tests/malloc_test.cpp @@ -700,7 +700,10 @@ static void GetAllocatorVersion(bool* allocator_scudo) { FILE* fp = fdopen(tf.fd, "w+"); tf.release(); ASSERT_TRUE(fp != nullptr); - ASSERT_EQ(0, malloc_info(0, fp)); + if (malloc_info(0, fp) != 0) { + *allocator_scudo = false; + return; + } ASSERT_EQ(0, fclose(fp)); std::string contents;