From fa43b547804496ea2bd7ad42893708f97b4f442c Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Wed, 27 Feb 2019 20:57:07 +0000 Subject: [PATCH 1/3] tests: handle any cmake detected python interpreter --- tests/block_weight/CMakeLists.txt | 2 +- tests/block_weight/block_weight.py | 2 +- tests/block_weight/compare.py | 15 +++++++++++---- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/tests/block_weight/CMakeLists.txt b/tests/block_weight/CMakeLists.txt index b0d716ea0..a59c9c1fc 100644 --- a/tests/block_weight/CMakeLists.txt +++ b/tests/block_weight/CMakeLists.txt @@ -42,4 +42,4 @@ target_link_libraries(block_weight add_test( NAME block_weight - COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/compare.py ${CMAKE_CURRENT_SOURCE_DIR}/block_weight.py ${CMAKE_CURRENT_BINARY_DIR}/block_weight) + COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/compare.py ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/block_weight.py ${CMAKE_CURRENT_BINARY_DIR}/block_weight) diff --git a/tests/block_weight/block_weight.py b/tests/block_weight/block_weight.py index 06aaabb02..d6fd494e3 100755 --- a/tests/block_weight/block_weight.py +++ b/tests/block_weight/block_weight.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python # Simulate a maximal block attack on the Monero network # This uses the scheme proposed by ArticMine # Written by Sarang Nother diff --git a/tests/block_weight/compare.py b/tests/block_weight/compare.py index c6be05206..e058a7079 100755 --- a/tests/block_weight/compare.py +++ b/tests/block_weight/compare.py @@ -3,10 +3,17 @@ import sys import subprocess -print 'running: ', sys.argv[1] -S0 = subprocess.check_output(sys.argv[1], stderr=subprocess.STDOUT) -print 'running: ', sys.argv[2] -S1 = subprocess.check_output(sys.argv[2], stderr=subprocess.STDOUT) +if len(sys.argv) == 4: + first = [sys.argv[1], sys.argv[2]] + second = [sys.argv[3]] +else: + first = [sys.argv[1]] + second = [sys.argv[2]] + +print 'running: ', first +S0 = subprocess.check_output(first, stderr=subprocess.STDOUT) +print 'running: ', second +S1 = subprocess.check_output(second, stderr=subprocess.STDOUT) print 'comparing' if S0 != S1: sys.exit(1) From 89b1630e352cce97dc1bfd62130da577dbdc00d3 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Thu, 28 Feb 2019 23:27:22 +0000 Subject: [PATCH 2/3] gtest: build fix for NetBSD --- tests/gtest/include/gtest/internal/gtest-port-arch.h | 2 ++ tests/gtest/include/gtest/internal/gtest-port.h | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/gtest/include/gtest/internal/gtest-port-arch.h b/tests/gtest/include/gtest/internal/gtest-port-arch.h index 74ab94905..83022c82c 100644 --- a/tests/gtest/include/gtest/internal/gtest-port-arch.h +++ b/tests/gtest/include/gtest/internal/gtest-port-arch.h @@ -88,6 +88,8 @@ # define GTEST_OS_OPENBSD 1 #elif defined __QNX__ # define GTEST_OS_QNX 1 +#elif defined(__NetBSD__) +# define GTEST_OS_NETBSD 1 #endif // __CYGWIN__ #endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_ARCH_H_ diff --git a/tests/gtest/include/gtest/internal/gtest-port.h b/tests/gtest/include/gtest/internal/gtest-port.h index cb0639b4b..2896dfe64 100644 --- a/tests/gtest/include/gtest/internal/gtest-port.h +++ b/tests/gtest/include/gtest/internal/gtest-port.h @@ -790,7 +790,8 @@ using ::std::tuple_size; (GTEST_OS_MAC && !GTEST_OS_IOS) || \ (GTEST_OS_WINDOWS_DESKTOP && _MSC_VER >= 1400) || \ GTEST_OS_WINDOWS_MINGW || GTEST_OS_AIX || GTEST_OS_HPUX || \ - GTEST_OS_OPENBSD || GTEST_OS_QNX || GTEST_OS_FREEBSD) + GTEST_OS_OPENBSD || GTEST_OS_QNX || GTEST_OS_FREEBSD || \ + GTEST_OS_NETBSD) # define GTEST_HAS_DEATH_TEST 1 #endif From 7632dede7b9b3b2be609866c6f814ae4d3aa079b Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Thu, 7 Mar 2019 16:40:48 +0000 Subject: [PATCH 3/3] crypto: fix PaX issue on NetBSD with CNv4 JIT --- src/crypto/CryptonightR_JIT.c | 13 +++++++++++++ src/crypto/slow-hash.c | 20 +++++++++++--------- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/crypto/CryptonightR_JIT.c b/src/crypto/CryptonightR_JIT.c index 68258a959..ee8f3f36f 100644 --- a/src/crypto/CryptonightR_JIT.c +++ b/src/crypto/CryptonightR_JIT.c @@ -4,6 +4,9 @@ #include #include #include +#if !(defined(_MSC_VER) || defined(__MINGW32__)) +#include +#endif #include "int-util.h" #include "hash-ops.h" @@ -58,6 +61,11 @@ int v4_generate_JIT_code(const struct V4_Instruction* code, v4_random_math_JIT_f uint8_t* JIT_code = (uint8_t*) buf; const uint8_t* JIT_code_end = JIT_code + buf_size; +#if !(defined(_MSC_VER) || defined(__MINGW32__)) + if (mprotect((void*)buf, buf_size, PROT_READ | PROT_WRITE)) + return 1; +#endif + APPEND_CODE(prologue, sizeof(prologue)); uint32_t prev_rot_src = 0xFFFFFFFFU; @@ -101,6 +109,11 @@ int v4_generate_JIT_code(const struct V4_Instruction* code, v4_random_math_JIT_f APPEND_CODE(epilogue, sizeof(epilogue)); +#if !(defined(_MSC_VER) || defined(__MINGW32__)) + if (mprotect((void*)buf, buf_size, PROT_READ | PROT_EXEC)) + return 1; +#endif + __builtin___clear_cache((char*)buf, (char*)JIT_code); return 0; diff --git a/src/crypto/slow-hash.c b/src/crypto/slow-hash.c index 6bdc1b28c..a9c776be5 100644 --- a/src/crypto/slow-hash.c +++ b/src/crypto/slow-hash.c @@ -756,10 +756,10 @@ void slow_hash_allocate_state(void) #if defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || \ defined(__DragonFly__) || defined(__NetBSD__) hp_state = mmap(0, MEMORY, PROT_READ | PROT_WRITE, - MAP_PRIVATE | MAP_ANON, 0, 0); + MAP_PRIVATE | MAP_ANON, -1, 0); #else hp_state = mmap(0, MEMORY, PROT_READ | PROT_WRITE, - MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB, 0, 0); + MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB, -1, 0); #endif if(hp_state == MAP_FAILED) hp_state = NULL; @@ -778,11 +778,16 @@ void slow_hash_allocate_state(void) #else #if defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || \ defined(__DragonFly__) || defined(__NetBSD__) - hp_jitfunc_memory = mmap(0, 4096 + 4095, PROT_READ | PROT_WRITE | PROT_EXEC, - MAP_PRIVATE | MAP_ANON, 0, 0); +#ifdef __NetBSD__ +#define RESERVED_FLAGS PROT_MPROTECT(PROT_EXEC) #else - hp_jitfunc_memory = mmap(0, 4096 + 4095, PROT_READ | PROT_WRITE | PROT_EXEC, - MAP_PRIVATE | MAP_ANONYMOUS, 0, 0); +#define RESERVED_FLAGS 0 +#endif + hp_jitfunc_memory = mmap(0, 4096 + 4096, PROT_READ | PROT_WRITE | RESERVED_FLAGS, + MAP_PRIVATE | MAP_ANON, -1, 0); +#else + hp_jitfunc_memory = mmap(0, 4096 + 4096, PROT_READ | PROT_WRITE | PROT_EXEC, + MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); #endif if(hp_jitfunc_memory == MAP_FAILED) hp_jitfunc_memory = NULL; @@ -794,9 +799,6 @@ void slow_hash_allocate_state(void) hp_jitfunc_memory = malloc(4096 + 4095); } hp_jitfunc = (v4_random_math_JIT_func)((size_t)(hp_jitfunc_memory + 4095) & ~4095); -#if !(defined(_MSC_VER) || defined(__MINGW32__)) - mprotect(hp_jitfunc, 4096, PROT_READ | PROT_WRITE | PROT_EXEC); -#endif } /**