2020-01-30 01:27:31 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2020 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2020-04-23 17:47:19 +02:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
|
|
|
|
#if defined(__BIONIC__)
|
|
|
|
|
2020-01-30 01:27:31 +01:00
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
2020-02-15 04:19:32 +01:00
|
|
|
#include <android-base/macros.h>
|
2020-01-30 01:27:31 +01:00
|
|
|
#include <bionic/mte.h>
|
2020-06-22 18:49:16 +02:00
|
|
|
#include "utils.h"
|
2020-01-30 01:27:31 +01:00
|
|
|
|
|
|
|
__attribute__((no_sanitize("hwaddress")))
|
|
|
|
static void test_tag_mismatch() {
|
|
|
|
std::unique_ptr<int[]> p = std::make_unique<int[]>(4);
|
|
|
|
p[0] = 1;
|
2020-02-15 04:19:32 +01:00
|
|
|
int* mistagged_p ATTRIBUTE_UNUSED =
|
|
|
|
reinterpret_cast<int*>(reinterpret_cast<uintptr_t>(p.get()) + (1ULL << 56));
|
|
|
|
{
|
|
|
|
ScopedDisableMTE x;
|
|
|
|
{ ScopedDisableMTE y; }
|
|
|
|
#if defined(__aarch64__)
|
|
|
|
volatile int load ATTRIBUTE_UNUSED = *mistagged_p;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#if defined(__aarch64__)
|
|
|
|
if (mte_supported()) {
|
|
|
|
EXPECT_DEATH(
|
|
|
|
{
|
|
|
|
volatile int load ATTRIBUTE_UNUSED = *mistagged_p;
|
|
|
|
},
|
|
|
|
"");
|
|
|
|
}
|
2020-01-30 01:27:31 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(mte_test, ScopedDisableMTE) {
|
2020-06-22 18:49:16 +02:00
|
|
|
// With native_bridge, native and emulated parts exchange data, including pointers.
|
|
|
|
// This implies tagging on native and emulated architectures should match, which is
|
|
|
|
// not the case at the moment.
|
|
|
|
SKIP_WITH_NATIVE_BRIDGE;
|
|
|
|
|
2020-01-30 01:27:31 +01:00
|
|
|
test_tag_mismatch();
|
|
|
|
}
|
2020-04-23 17:47:19 +02:00
|
|
|
|
|
|
|
#endif // __BIONIC__
|