From 1065c2dff43f026e7f9ea924115ebac8b0cebe45 Mon Sep 17 00:00:00 2001 From: relapids Date: Tue, 16 Aug 2022 00:06:02 -0700 Subject: [PATCH] Fix test_uc_hook_cached_uaf for MacOS M1 (aarch64). --- tests/unit/test_ctl.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/tests/unit/test_ctl.c b/tests/unit/test_ctl.c index b96d7cf5..5eef28d0 100644 --- a/tests/unit/test_ctl.c +++ b/tests/unit/test_ctl.c @@ -251,15 +251,22 @@ static void test_uc_hook_cached_uaf(void) uc_hook h; uint64_t count = 0; #ifndef _WIN32 - void *callback = mmap(NULL, 4096, PROT_READ | PROT_WRITE | PROT_EXEC, + // Apple Silicon does not allow RWX pages. + void *callback = mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + TEST_CHECK(callback != (void*)-1); #else void *callback = VirtualAlloc(NULL, 4096, MEM_RESERVE | MEM_COMMIT, PAGE_EXECUTE_READWRITE); + TEST_CHECK(callback != NULL); #endif memcpy(callback, (void *)test_uc_hook_cached_cb, 4096); +#ifndef _WIN32 + TEST_CHECK(mprotect(callback, 4096, PROT_READ | PROT_EXEC) == 0); +#endif + uc_common_setup(&uc, UC_ARCH_X86, UC_MODE_32, code, sizeof(code) - 1); OK(uc_hook_add(uc, &h, UC_HOOK_CODE, (void *)callback, (void *)&count, 1, @@ -273,8 +280,16 @@ static void test_uc_hook_cached_uaf(void) // This will clear deleted hooks and SHOULD clear cache. OK(uc_emu_start(uc, code_start, code_start + sizeof(code) - 1, 0, 0)); +#ifndef _WIN32 + TEST_CHECK(mprotect(callback, 4096, PROT_READ | PROT_WRITE) == 0); +#endif + memset(callback, 0, 4096); +#ifndef _WIN32 + TEST_CHECK(mprotect(callback, 4096, PROT_READ | PROT_EXEC) == 0); +#endif + // Now hooks are deleted and thus this will trigger a UAF OK(uc_emu_start(uc, code_start, code_start + sizeof(code) - 1, 0, 0));