HWASan fixes for ART tests
Bug: 156593692
Test: SANITIZE_TARGET=hwaddress art/tools/run-gtests.sh
Test: SANITIZE_TARGET=hwaddress art/test.py -r --target --64
Change-Id: I24c5afdb4fed5ac94ce3a7b54a10c592f529191f
diff --git a/compiler/common_compiler_test.cc b/compiler/common_compiler_test.cc
index 6b4dbed..4b6a557 100644
--- a/compiler/common_compiler_test.cc
+++ b/compiler/common_compiler_test.cc
@@ -107,7 +107,9 @@
uintptr_t base = RoundDown(data, kPageSize);
uintptr_t limit = RoundUp(data + code_length, kPageSize);
uintptr_t len = limit - base;
- int result = mprotect(reinterpret_cast<void*>(base), len, PROT_READ | PROT_WRITE | PROT_EXEC);
+ // Remove hwasan tag. This is done in kernel in newer versions. This supports older kernels.
+ void* base_ptr = HWASanUntag(reinterpret_cast<void*>(base));
+ int result = mprotect(base_ptr, len, PROT_READ | PROT_WRITE | PROT_EXEC);
CHECK_EQ(result, 0);
CHECK(FlushCpuCaches(reinterpret_cast<void*>(base), reinterpret_cast<void*>(base + len)));
diff --git a/libartbase/base/memory_tool.h b/libartbase/base/memory_tool.h
index aca1201..5ed9cda 100644
--- a/libartbase/base/memory_tool.h
+++ b/libartbase/base/memory_tool.h
@@ -67,11 +67,23 @@
#endif
#if __has_feature(hwaddress_sanitizer)
+# define HWADDRESS_SANITIZER
# define ATTRIBUTE_NO_SANITIZE_HWADDRESS __attribute__((no_sanitize("hwaddress")))
#else
# define ATTRIBUTE_NO_SANITIZE_HWADDRESS
#endif
+// Removes the hwasan tag from the pointer (the top eight bits).
+// Those bits are used for verification by hwasan and they are ignored by normal ARM memory ops.
+template<typename PtrType>
+static inline PtrType* HWASanUntag(PtrType* p) {
+#if __has_feature(hwaddress_sanitizer) && defined(__aarch64__)
+ return reinterpret_cast<PtrType*>(reinterpret_cast<uintptr_t>(p) & ((1ULL << 56) - 1));
+#else
+ return p;
+#endif
+}
+
} // namespace art
#endif // ART_LIBARTBASE_BASE_MEMORY_TOOL_H_
diff --git a/runtime/interpreter/interpreter_switch_impl-inl.h b/runtime/interpreter/interpreter_switch_impl-inl.h
index 863612f..0f15adf 100644
--- a/runtime/interpreter/interpreter_switch_impl-inl.h
+++ b/runtime/interpreter/interpreter_switch_impl-inl.h
@@ -1909,7 +1909,7 @@
};
// Don't inline in ASAN. It would create massive stack frame.
-#ifdef ADDRESS_SANITIZER
+#if defined(ADDRESS_SANITIZER) || defined(HWADDRESS_SANITIZER)
#define ASAN_NO_INLINE NO_INLINE
#else
#define ASAN_NO_INLINE ALWAYS_INLINE
diff --git a/runtime/oat_quick_method_header.h b/runtime/oat_quick_method_header.h
index c8ee9b4..9a1133e 100644
--- a/runtime/oat_quick_method_header.h
+++ b/runtime/oat_quick_method_header.h
@@ -114,7 +114,8 @@
}
bool Contains(uintptr_t pc) const {
- uintptr_t code_start = reinterpret_cast<uintptr_t>(code_);
+ // Remove hwasan tag to make comparison below valid. The PC from the stack does not have it.
+ uintptr_t code_start = reinterpret_cast<uintptr_t>(HWASanUntag(code_));
static_assert(kRuntimeISA != InstructionSet::kThumb2, "kThumb2 cannot be a runtime ISA");
if (kRuntimeISA == InstructionSet::kArm) {
// On Thumb-2, the pc is offset by one.
diff --git a/test/common/gtest_main.cc b/test/common/gtest_main.cc
index 2fb6701..9176001 100644
--- a/test/common/gtest_main.cc
+++ b/test/common/gtest_main.cc
@@ -25,7 +25,7 @@
#include "runtime.h"
extern "C" bool GetInitialArgs(const char*** args, size_t* num_args) {
- static const char* initial_args[] = {"--deadline_threshold_ms=600000",
+ static const char* initial_args[] = {"--deadline_threshold_ms=1200000", // hwasan takes ~10min.
"--slow_threshold_ms=300000"};
*args = initial_args;
*num_args = 2;
diff --git a/test/knownfailures.json b/test/knownfailures.json
index ced5723..070df35 100644
--- a/test/knownfailures.json
+++ b/test/knownfailures.json
@@ -652,6 +652,12 @@
"env_vars": {"SANITIZE_HOST": "address"}
},
{
+ "tests": "175-alloc-big-bignums",
+ "description": "ASAN runs out of memory due to huge allocations.",
+ "variant": "target",
+ "env_vars": {"SANITIZE_TARGET": "hwaddress"}
+ },
+ {
"tests": "202-thread-oome",
"description": "ASAN aborts when large thread stacks are requested.",
"variant": "host",
@@ -718,6 +724,17 @@
"env_vars": {"SANITIZE_TARGET": "address"}
},
{
+ "tests": [
+ "074-gc-thrash"
+ ],
+ "description": [
+ "Interpreter with access checks stack frames are too large and result in",
+ "StackOverFlow errors being thrown."
+ ],
+ "variant": "interp-ac & target",
+ "env_vars": {"SANITIZE_TARGET": "hwaddress"}
+ },
+ {
"tests": "071-dexfile-map-clean",
"description": [ "We use prebuilt zipalign on master-art-host to avoid pulling in a lot",
"of the framework. But a non-sanitized zipalign binary does not work with",