Merge changes I6ba4b46a,Ic54579e3
* changes: Disable a few bionic tests under HWASan. Remove timer_delete_multiple test.
This commit is contained in:
commit
2b94f124df
9 changed files with 59 additions and 27 deletions
|
@ -227,6 +227,18 @@ static void VerifyFencepost(uint8_t *buffer) {
|
|||
}
|
||||
}
|
||||
|
||||
// Malloc can return a tagged pointer, which is not accepted in mm system calls like mprotect.
|
||||
// Clear top 8 bits of the address on 64-bit platforms.
|
||||
static int MprotectHeap(void* addr, size_t len, int prot) {
|
||||
#if defined(__LP64__)
|
||||
constexpr uintptr_t mask = (static_cast<uintptr_t>(1) << 56) - 1;
|
||||
void* untagged_addr = reinterpret_cast<void*>(reinterpret_cast<uintptr_t>(addr) & mask);
|
||||
#else
|
||||
void* untagged_addr = addr;
|
||||
#endif
|
||||
return mprotect(untagged_addr, len, prot);
|
||||
}
|
||||
|
||||
void RunSingleBufferAlignTest(
|
||||
size_t max_test_size, void (*test_func)(uint8_t*, size_t),
|
||||
size_t (*set_incr)(size_t)) {
|
||||
|
@ -358,14 +370,14 @@ void RunSingleBufferOverreadTest(void (*test_func)(uint8_t*, size_t)) {
|
|||
memset(memory, 0x23, 2*pagesize);
|
||||
|
||||
// Make the second page unreadable and unwritable.
|
||||
ASSERT_TRUE(mprotect(&memory[pagesize], pagesize, PROT_NONE) == 0);
|
||||
ASSERT_TRUE(MprotectHeap(&memory[pagesize], pagesize, PROT_NONE) == 0);
|
||||
|
||||
for (size_t i = 0; i < pagesize; i++) {
|
||||
uint8_t* buf = &memory[pagesize-i];
|
||||
|
||||
test_func(buf, i);
|
||||
}
|
||||
ASSERT_TRUE(mprotect(&memory[pagesize], pagesize, PROT_READ | PROT_WRITE) == 0);
|
||||
ASSERT_TRUE(MprotectHeap(&memory[pagesize], pagesize, PROT_READ | PROT_WRITE) == 0);
|
||||
free(memory);
|
||||
}
|
||||
|
||||
|
@ -379,7 +391,7 @@ void RunSrcDstBufferOverreadTest(void (*test_func)(uint8_t*, uint8_t*, size_t))
|
|||
memset(memory, 0x23, 2*pagesize);
|
||||
|
||||
// Make the second page unreadable and unwritable.
|
||||
ASSERT_TRUE(mprotect(&memory[pagesize], pagesize, PROT_NONE) == 0);
|
||||
ASSERT_TRUE(MprotectHeap(&memory[pagesize], pagesize, PROT_NONE) == 0);
|
||||
|
||||
uint8_t* dst_buffer = new uint8_t[2*pagesize];
|
||||
// Change the dst alignment as we change the source.
|
||||
|
@ -391,7 +403,7 @@ void RunSrcDstBufferOverreadTest(void (*test_func)(uint8_t*, uint8_t*, size_t))
|
|||
test_func(src, dst, j);
|
||||
}
|
||||
}
|
||||
ASSERT_TRUE(mprotect(&memory[pagesize], pagesize, PROT_READ | PROT_WRITE) == 0);
|
||||
ASSERT_TRUE(MprotectHeap(&memory[pagesize], pagesize, PROT_READ | PROT_WRITE) == 0);
|
||||
free(memory);
|
||||
delete[] dst_buffer;
|
||||
}
|
||||
|
@ -409,7 +421,7 @@ void RunCmpBufferOverreadTest(
|
|||
memset(memory1, 0x23, 2*pagesize);
|
||||
|
||||
// Make the second page unreadable and unwritable.
|
||||
ASSERT_TRUE(mprotect(&memory1[pagesize], pagesize, PROT_NONE) == 0);
|
||||
ASSERT_TRUE(MprotectHeap(&memory1[pagesize], pagesize, PROT_NONE) == 0);
|
||||
|
||||
uint8_t* memory2;
|
||||
ASSERT_TRUE(posix_memalign(reinterpret_cast<void**>(&memory2), pagesize,
|
||||
|
@ -417,7 +429,7 @@ void RunCmpBufferOverreadTest(
|
|||
memset(memory2, 0x23, 2*pagesize);
|
||||
|
||||
// Make the second page unreadable and unwritable.
|
||||
ASSERT_TRUE(mprotect(&memory2[pagesize], pagesize, PROT_NONE) == 0);
|
||||
ASSERT_TRUE(MprotectHeap(&memory2[pagesize], pagesize, PROT_NONE) == 0);
|
||||
|
||||
for (size_t i = 0; i < pagesize; i++) {
|
||||
uint8_t* buf1 = &memory1[pagesize-i];
|
||||
|
@ -445,8 +457,8 @@ void RunCmpBufferOverreadTest(
|
|||
}
|
||||
}
|
||||
|
||||
ASSERT_TRUE(mprotect(&memory1[pagesize], pagesize, PROT_READ | PROT_WRITE) == 0);
|
||||
ASSERT_TRUE(mprotect(&memory2[pagesize], pagesize, PROT_READ | PROT_WRITE) == 0);
|
||||
ASSERT_TRUE(MprotectHeap(&memory1[pagesize], pagesize, PROT_READ | PROT_WRITE) == 0);
|
||||
ASSERT_TRUE(MprotectHeap(&memory2[pagesize], pagesize, PROT_READ | PROT_WRITE) == 0);
|
||||
free(memory1);
|
||||
free(memory2);
|
||||
}
|
||||
|
|
|
@ -136,6 +136,7 @@ TEST(dl, exec_linker_load_self) {
|
|||
|
||||
TEST(dl, preinit_system_calls) {
|
||||
#if defined(__BIONIC__)
|
||||
SKIP_WITH_HWASAN; // hwasan not initialized in preinit_array
|
||||
std::string helper = GetTestlibRoot() +
|
||||
"/preinit_syscall_test_helper/preinit_syscall_test_helper";
|
||||
chmod(helper.c_str(), 0755); // TODO: "x" lost in CTS, b/34945607
|
||||
|
@ -235,6 +236,7 @@ static bool is_debuggable_build() {
|
|||
// whose search paths include the 'ns2/' subdir.
|
||||
TEST(dl, exec_with_ld_config_file) {
|
||||
#if defined(__BIONIC__)
|
||||
SKIP_WITH_HWASAN; // libclang_rt.hwasan is not found with custom ld config
|
||||
if (!is_debuggable_build()) {
|
||||
// LD_CONFIG_FILE is not supported on user build
|
||||
return;
|
||||
|
@ -257,6 +259,7 @@ TEST(dl, exec_with_ld_config_file) {
|
|||
// additional namespaces other than the default namespace.
|
||||
TEST(dl, exec_with_ld_config_file_with_ld_preload) {
|
||||
#if defined(__BIONIC__)
|
||||
SKIP_WITH_HWASAN; // libclang_rt.hwasan is not found with custom ld config
|
||||
if (!is_debuggable_build()) {
|
||||
// LD_CONFIG_FILE is not supported on user build
|
||||
return;
|
||||
|
|
|
@ -20,6 +20,8 @@
|
|||
#include <limits.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
TEST(getcwd, auto_full) {
|
||||
// If we let the library do all the work, everything's fine.
|
||||
errno = 0;
|
||||
|
@ -49,6 +51,7 @@ TEST(getcwd, auto_too_small) {
|
|||
}
|
||||
|
||||
TEST(getcwd, auto_too_large) {
|
||||
SKIP_WITH_HWASAN; // allocation size too large
|
||||
// If we ask the library to allocate an unreasonably large buffer, ERANGE.
|
||||
errno = 0;
|
||||
char* cwd = getcwd(nullptr, static_cast<size_t>(-1));
|
||||
|
|
|
@ -27,11 +27,13 @@ extern "C" __attribute__((weak)) void __cfi_slowpath(uint64_t, void*);
|
|||
static int g_count;
|
||||
|
||||
// Mock a CFI-enabled library without relying on the compiler.
|
||||
extern "C" __attribute__((aligned(4096))) void __cfi_check(uint64_t /*CallSiteTypeId*/,
|
||||
void* /*TargetAddr*/, void* /*Diag*/) {
|
||||
extern "C" __attribute__((no_sanitize("hwaddress"))) __attribute__((aligned(4096)))
|
||||
void __cfi_check(uint64_t /*CallSiteTypeId*/, void* /*TargetAddr*/, void* /*Diag*/) {
|
||||
++g_count;
|
||||
}
|
||||
|
||||
// This code runs before hwasan is initialized.
|
||||
__attribute__((no_sanitize("hwaddress")))
|
||||
void preinit_ctor() {
|
||||
CHECK(g_count == 0);
|
||||
__cfi_slowpath(42, reinterpret_cast<void*>(&preinit_ctor));
|
||||
|
|
|
@ -26,6 +26,8 @@
|
|||
|
||||
#include <procinfo/process_map.h>
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
extern "C" void malloc_disable();
|
||||
extern "C" void malloc_enable();
|
||||
extern "C" int malloc_iterate(uintptr_t base, size_t size, void (*callback)(uintptr_t base,
|
||||
|
@ -130,6 +132,7 @@ static void AllocateSizes(TestDataType* test_data, const std::vector<size_t>& si
|
|||
// Verify that small allocs can be found properly.
|
||||
TEST(malloc_iterate, small_allocs) {
|
||||
#if defined(__BIONIC__)
|
||||
SKIP_WITH_HWASAN;
|
||||
TestDataType test_data;
|
||||
|
||||
// Try to cycle through all of the different small bins.
|
||||
|
@ -153,6 +156,7 @@ TEST(malloc_iterate, small_allocs) {
|
|||
// Verify that large allocs can be found properly.
|
||||
TEST(malloc_iterate, large_allocs) {
|
||||
#if defined(__BIONIC__)
|
||||
SKIP_WITH_HWASAN;
|
||||
TestDataType test_data;
|
||||
|
||||
// Try some larger sizes.
|
||||
|
@ -172,6 +176,7 @@ TEST(malloc_iterate, large_allocs) {
|
|||
// non-allocated pointers.
|
||||
TEST(malloc_iterate, invalid_pointers) {
|
||||
#if defined(__BIONIC__)
|
||||
SKIP_WITH_HWASAN;
|
||||
TestDataType test_data = {};
|
||||
|
||||
// Find all of the maps that are not [anon:libc_malloc].
|
||||
|
@ -192,6 +197,7 @@ TEST(malloc_iterate, invalid_pointers) {
|
|||
|
||||
TEST(malloc_iterate, malloc_disable_prevents_allocs) {
|
||||
#if defined(__BIONIC__)
|
||||
SKIP_WITH_HWASAN;
|
||||
pid_t pid;
|
||||
if ((pid = fork()) == 0) {
|
||||
malloc_disable();
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include <tinyxml2.h>
|
||||
|
||||
#include "private/bionic_config.h"
|
||||
#include "utils.h"
|
||||
|
||||
#if defined(__BIONIC__)
|
||||
#define HAVE_REALLOCARRAY 1
|
||||
|
@ -41,6 +42,7 @@ TEST(malloc, malloc_std) {
|
|||
}
|
||||
|
||||
TEST(malloc, malloc_overflow) {
|
||||
SKIP_WITH_HWASAN;
|
||||
errno = 0;
|
||||
ASSERT_EQ(nullptr, malloc(SIZE_MAX));
|
||||
ASSERT_EQ(ENOMEM, errno);
|
||||
|
@ -59,12 +61,14 @@ TEST(malloc, calloc_std) {
|
|||
}
|
||||
|
||||
TEST(malloc, calloc_illegal) {
|
||||
SKIP_WITH_HWASAN;
|
||||
errno = 0;
|
||||
ASSERT_EQ(nullptr, calloc(-1, 100));
|
||||
ASSERT_EQ(ENOMEM, errno);
|
||||
}
|
||||
|
||||
TEST(malloc, calloc_overflow) {
|
||||
SKIP_WITH_HWASAN;
|
||||
errno = 0;
|
||||
ASSERT_EQ(nullptr, calloc(1, SIZE_MAX));
|
||||
ASSERT_EQ(ENOMEM, errno);
|
||||
|
@ -80,6 +84,7 @@ TEST(malloc, calloc_overflow) {
|
|||
}
|
||||
|
||||
TEST(malloc, memalign_multiple) {
|
||||
SKIP_WITH_HWASAN; // hwasan requires power of 2 alignment.
|
||||
// Memalign test where the alignment is any value.
|
||||
for (size_t i = 0; i <= 12; i++) {
|
||||
for (size_t alignment = 1 << i; alignment < (1U << (i+1)); alignment++) {
|
||||
|
@ -94,10 +99,12 @@ TEST(malloc, memalign_multiple) {
|
|||
}
|
||||
|
||||
TEST(malloc, memalign_overflow) {
|
||||
SKIP_WITH_HWASAN;
|
||||
ASSERT_EQ(nullptr, memalign(4096, SIZE_MAX));
|
||||
}
|
||||
|
||||
TEST(malloc, memalign_non_power2) {
|
||||
SKIP_WITH_HWASAN;
|
||||
void* ptr;
|
||||
for (size_t align = 0; align <= 256; align++) {
|
||||
ptr = memalign(align, 1024);
|
||||
|
@ -280,6 +287,7 @@ TEST(malloc, calloc_multiple_realloc) {
|
|||
}
|
||||
|
||||
TEST(malloc, realloc_overflow) {
|
||||
SKIP_WITH_HWASAN;
|
||||
errno = 0;
|
||||
ASSERT_EQ(nullptr, realloc(nullptr, SIZE_MAX));
|
||||
ASSERT_EQ(ENOMEM, errno);
|
||||
|
|
|
@ -35,6 +35,8 @@
|
|||
#include <limits>
|
||||
#include <string>
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
#if defined(__BIONIC__)
|
||||
#define ALIGNED_ALLOC_AVAILABLE 1
|
||||
#elif defined(__GLIBC_PREREQ)
|
||||
|
@ -191,6 +193,7 @@ TEST(stdlib, mrand48_distribution) {
|
|||
}
|
||||
|
||||
TEST(stdlib, posix_memalign_sweep) {
|
||||
SKIP_WITH_HWASAN;
|
||||
void* ptr;
|
||||
|
||||
// These should all fail.
|
||||
|
@ -230,11 +233,13 @@ TEST(stdlib, posix_memalign_various_sizes) {
|
|||
}
|
||||
|
||||
TEST(stdlib, posix_memalign_overflow) {
|
||||
SKIP_WITH_HWASAN;
|
||||
void* ptr;
|
||||
ASSERT_NE(0, posix_memalign(&ptr, 16, SIZE_MAX));
|
||||
}
|
||||
|
||||
TEST(stdlib, aligned_alloc_sweep) {
|
||||
SKIP_WITH_HWASAN;
|
||||
#if defined(ALIGNED_ALLOC_AVAILABLE)
|
||||
// Verify powers of 2 up to 2048 allocate, and verify that all other
|
||||
// alignment values between the powers of 2 fail.
|
||||
|
@ -259,6 +264,7 @@ TEST(stdlib, aligned_alloc_sweep) {
|
|||
}
|
||||
|
||||
TEST(stdlib, aligned_alloc_overflow) {
|
||||
SKIP_WITH_HWASAN;
|
||||
#if defined(ALIGNED_ALLOC_AVAILABLE)
|
||||
ASSERT_TRUE(aligned_alloc(16, SIZE_MAX) == nullptr);
|
||||
#else
|
||||
|
@ -267,6 +273,7 @@ TEST(stdlib, aligned_alloc_overflow) {
|
|||
}
|
||||
|
||||
TEST(stdlib, aligned_alloc_size_not_multiple_of_alignment) {
|
||||
SKIP_WITH_HWASAN;
|
||||
#if defined(ALIGNED_ALLOC_AVAILABLE)
|
||||
for (size_t size = 1; size <= 2048; size++) {
|
||||
void* ptr = aligned_alloc(2048, size);
|
||||
|
|
|
@ -488,23 +488,6 @@ TEST(time, timer_create_EINVAL) {
|
|||
ASSERT_EQ(EINVAL, errno);
|
||||
}
|
||||
|
||||
TEST(time, timer_delete_multiple) {
|
||||
timer_t timer_id;
|
||||
ASSERT_EQ(0, timer_create(CLOCK_MONOTONIC, nullptr, &timer_id));
|
||||
ASSERT_EQ(0, timer_delete(timer_id));
|
||||
ASSERT_EQ(-1, timer_delete(timer_id));
|
||||
ASSERT_EQ(EINVAL, errno);
|
||||
|
||||
sigevent_t se;
|
||||
memset(&se, 0, sizeof(se));
|
||||
se.sigev_notify = SIGEV_THREAD;
|
||||
se.sigev_notify_function = NoOpNotifyFunction;
|
||||
ASSERT_EQ(0, timer_create(CLOCK_MONOTONIC, &se, &timer_id));
|
||||
ASSERT_EQ(0, timer_delete(timer_id));
|
||||
ASSERT_EQ(-1, timer_delete(timer_id));
|
||||
ASSERT_EQ(EINVAL, errno);
|
||||
}
|
||||
|
||||
TEST(time, timer_create_multiple) {
|
||||
Counter counter1(Counter::CountNotifyFunction);
|
||||
Counter counter2(Counter::CountNotifyFunction);
|
||||
|
|
|
@ -58,6 +58,14 @@ static inline bool have_dl() {
|
|||
return (dlopen("libc.so", 0) != nullptr);
|
||||
}
|
||||
|
||||
extern "C" void __hwasan_init() __attribute__((weak));
|
||||
|
||||
static inline bool running_with_hwasan() {
|
||||
return &__hwasan_init != 0;
|
||||
}
|
||||
|
||||
#define SKIP_WITH_HWASAN if (running_with_hwasan()) { return; }
|
||||
|
||||
#if defined(__linux__)
|
||||
|
||||
#include <sys/sysmacros.h>
|
||||
|
|
Loading…
Reference in a new issue